This repository has been archived on 2020-06-14. You can view files and clone it, but cannot push or open issues or pull requests.

103 lines
4.0 KiB
C

/**********************************************************************
* NAME: eeprom.h *
* AUTHOR: Philip Johansson *
* PURPOSE: Virtual EEPROM driver *
* INFORMATION: *
* This file mainly has two functions of which one brings the settings *
* from EEPROM and the other stores them *
* *
* All values we want in EEPROM have to be added to the EEPROM_ID_t *
* struct as well as defined in eeprom_Arr with a pointer to the data *
* *
* GLOBAL VARIABLES: *
* Variable Type Description *
* -------- ---- ----------- *
* *
**********************************************************************/
#ifndef CONFIG_EEPROM_H_
#define CONFIG_EEPROM_H_
#include "stm32f4xx.h"
/* Defines where emulated EEPROM starts from - OBS! Also defined in LinkerScript.id */
#define EEPROM_BASE_ADDR 0x080E0000
/* The size in bytes of the profile buffers. The error handler will be called if this is too small */
#define EEPROM_PROFILE_SIZE 200
/* The profiles one can choose from */
typedef enum {
PROFILE_1 = 1,
PROFILE_2,
PROFILE_3
} ACTIVE_PROFILE;
/* List of all header EEPROM values */
typedef enum {
EEPROM_VERSION = 0,
/* Counts the amount of system settings */
EEPROM_HEADER_COUNT
} EEPROM_HEADER_ID_t;
/* List of all system EEPROM values */
typedef enum {
EEPROM_ACTIVE_PROFILE = 0,
EEPROM_ADC_SCALES,
EEPROM_UART1_RX_INV,
/* Counts the amount of system settings */
EEPROM_SYS_COUNT
} EEPROM_SYS_ID_t;
/* List of all profile EEPROM values */
typedef enum {
EEPROM_PID_ROLL_KP = 0,
/* Counts the amount of settings in profile */
EEPROM_PROFILE_COUNT
} EEPROM_PROFILE_ID_t;
/* List of all footer EEPROM values */
typedef enum {
EEPROM_CRC = 0,
/* Counts the amount of system settings */
EEPROM_FOOTER_COUNT
} EEPROM_FOOTER_ID_t;
/***********************************************************************
* BRIEF: Writes EEPROM data to FLASH. Requires the next active profile *
* to be selected (current profile can be used as input) *
* INFORMATION: passes all data directly from where they are defined *
***********************************************************************/
void writeEEPROM(ACTIVE_PROFILE new_active_profile);
/***********************************************************************
* BRIEF: Writes EEPROM data to FLASH without the need of setting next *
* active profile *
* INFORMATION: Keeps the current profile active *
***********************************************************************/
void saveEEPROM();
/***********************************************************************
* BRIEF: Reads EEPROM data from FLASH *
* INFORMATION: passes all data directly to where they are defined *
***********************************************************************/
bool readEEPROM();
/***********************************************************************
* BRIEF: Choose a profile between 1 .. 3 *
* INFORMATION: The current changes will be saved *
***********************************************************************/
void setActiveProfile(ACTIVE_PROFILE profile);
/***********************************************************************
* BRIEF: Writes current profile values to all EEPROM profiles *
* INFORMATION: used when EEPROM is corrupt or there is a version *
* mismatch *
***********************************************************************/
void resetEEPROM(void);
#endif /* CONFIG_EEPROM_H_ */