MotorController
data_storage.c
1 /******************************************************************************/
2 /* Includes */
3 /******************************************************************************/
4 #include "data_storage.h"
5 #include "flash.h"
6 #include "settings.h"
7 
8 /******************************************************************************/
9 /* Constants */
10 /******************************************************************************/
11 #define DATAPAGE_ID 31 /** Id of the flash page used for data storage */
12 
13 #define DATAPAGE_START 0x0800F800U /** Base address of the non-volatile data storage */
14 
15 /******************************************************************************/
16 /* Public functions */
17 /******************************************************************************/
19  settings = *(robot_settings_t*)DATAPAGE_START;
20 }
21 
22 int32_t store_data_in_flash(void) {
23  int32_t status;
24 
25  status = flashPageErase(DATAPAGE_ID);
26 
27  if (FLASH_RETURN_SUCCESS == status) {
28  status = flashWrite(DATAPAGE_START, (const char *)&settings, sizeof(robot_settings_t));
29  }
30 
31  return status;
32 }
void load_data_from_flash(void)
Load configuration data from flash.
Definition: data_storage.c:18
int32_t store_data_in_flash(void)
Save configuration data in flash.
Definition: data_storage.c:22
volatile robot_settings_t settings
Global variable used to store the configuration in use.
Definition: settings.c:9