Flipklok
 
Loading...
Searching...
No Matches
storeLoadMechanicalTime.h File Reference
#include <stdint.h>

Go to the source code of this file.

Functions

void write_SegD (uint32_t value)
 Function to write a 32-bit value to Flash segment D for storing the mechanical time, gets called from main() and at the end of stepperAdvance()
 
uint32_t load_from_flash (void)
 Function to load a 32-bit value from Flash memory segment D used for restoring the mechanical time on startup, gets called from main().
 

Function Documentation

◆ load_from_flash()

uint32_t load_from_flash ( void )

Function to load a 32-bit value from Flash memory segment D used for restoring the mechanical time on startup, gets called from main().

Returns
uint32_t the value that is stored in flash

Definition at line 92 of file storeLoadMechanicalTime.c.

93{
94 uint32_t *Flash_ptr; // Pointer to read from Flash memory
95 uint32_t loaded_value;
96
97 Flash_ptr = (uint32_t *) 0x1000; // Point to the start of Flash segment D
98 loaded_value = *Flash_ptr; // Read the 32-bit value from Flash
99
100 return loaded_value;
101}
uint32_t loaded_value
Definition main.c:33

References loaded_value.

Referenced by main().

◆ write_SegD()

void write_SegD ( uint32_t value)

Function to write a 32-bit value to Flash segment D for storing the mechanical time, gets called from main() and at the end of stepperAdvance()

Parameters
[in]valueThe value to be stored in flash

Definition at line 62 of file storeLoadMechanicalTime.c.

63{
64 uint32_t *Flash_ptr; // Flash pointer
65 unsigned int i;
66
67 Flash_ptr = (uint32_t *) 0x1000; // Initialize Flash pointer (for 32-bit writes)
68 FCTL1 = FWKEY + ERASE; // Set Erase bit
69 FCTL3 = FWKEY; // Clear Lock bit
70 *Flash_ptr = 0; // Dummy write to erase Flash segment
71
72 FCTL1 = FWKEY + WRT; // Set WRT bit for write operation
73
74 *Flash_ptr--;
75 for (i = 0; i < 8; i++) // Write 32-bit value to flash (16 writes per 64 bytes)
76 {
77 *Flash_ptr = value; // Write 32-bit value to flash
78 *Flash_ptr++;
79 }
80
81// *Flash_ptr = value; // Write 32-bit value to flash
82
83 FCTL1 = FWKEY; // Clear WRT bit
84 FCTL3 = FWKEY + LOCK; // Set LOCK bit
85}

Referenced by main(), and stepperAdvance().