Open FFBoard
Open source force feedback firmware
eeprom.h
Go to the documentation of this file.
1
47/* Define to prevent recursive inclusion -------------------------------------*/
48#ifndef __EEPROM_H
49#define __EEPROM_H
50
51/* Includes ------------------------------------------------------------------*/
52#include "constants.h"
53//#include "eeprom_addresses.h"
54#ifdef USE_EEPROM_EMULATION
55
56#ifdef STM32F4
57#include "stm32f4xx_hal.h"
58#endif
59/* Exported constants --------------------------------------------------------*/
60/* EEPROM emulation firmware error codes */
61#define EE_OK (uint32_t)HAL_OK
62#define EE_ERROR (uint32_t)HAL_ERROR
63#define EE_BUSY (uint32_t)HAL_BUSY
64#define EE_TIMEOUT (uint32_t)HAL_TIMEOUT
65
66
67
68/* Device voltage range supposed to be [2.7V to 3.6V], the operation will
69 be done by word */
70#define VOLTAGE_RANGE (uint8_t)VOLTAGE_RANGE_3
71
72
73/* EEPROM start address in Flash
74 * Moved to target constants */
75//#define EEPROM_START_ADDRESS ((uint32_t)0x08008000)
76/* EEPROM emulation start address: Flash memory */
77/* Define the size of the sectors to be used */
78//#define PAGE_SIZE (uint32_t)0x4000 /* Page size = 16KByte */
79
80
81/* Pages 0 and 1 base and end addresses */
82#define PAGE0_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + 0x0000))
83#define PAGE0_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (PAGE_SIZE - 1)))
84#ifndef PAGE0_ID
85#define PAGE0_ID FLASH_SECTOR_1
86#endif
87
88#define PAGE1_BASE_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + PAGE_SIZE))
89#define PAGE1_END_ADDRESS ((uint32_t)(EEPROM_START_ADDRESS + (2 * PAGE_SIZE - 1)))
90#ifndef PAGE1_ID
91#define PAGE1_ID FLASH_SECTOR_2
92#endif
93
94/* Used Flash pages for EEPROM emulation */
95#define PAGE0 ((uint16_t)0x0000)
96#define PAGE1 ((uint16_t)0x0001) /* Page nb between PAGE0_BASE_ADDRESS & PAGE1_BASE_ADDRESS*/
97
98/* No valid page define */
99#define NO_VALID_PAGE ((uint16_t)0x00AB)
100
101/* Page status definitions */
102#define ERASED ((uint16_t)0xFFFF) /* Page is empty */
103#define RECEIVE_DATA ((uint16_t)0xEEEE) /* Page is marked to receive data */
104#define VALID_PAGE ((uint16_t)0x0000) /* Page containing valid data */
105
106/* Valid pages in read and write defines */
107#define READ_FROM_VALID_PAGE ((uint8_t)0x00)
108#define WRITE_IN_VALID_PAGE ((uint8_t)0x01)
109
110/* Page full define */
111#define PAGE_FULL ((uint8_t)0x80)
112
113/* Variables' number */
114//#define NB_OF_VAR ((uint8_t)0x03)
115
116/* Exported types ------------------------------------------------------------*/
117/* Exported macro ------------------------------------------------------------*/
118/* Exported functions ------------------------------------------------------- */
119uint16_t EE_Init(void);
120uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t* Data);
121uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data);
122HAL_StatusTypeDef EE_Format();
123#endif
124#endif /* __EEPROM_H */
125
126/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
uint16_t EE_ReadVariable(uint16_t VirtAddress, uint16_t *Data)
Returns the last stored variable data, if found, which correspond to the passed virtual address.
Definition: eeprom.c:370
uint16_t EE_WriteVariable(uint16_t VirtAddress, uint16_t Data)
Writes/upadtes variable data in EEPROM.
Definition: eeprom.c:429
HAL_StatusTypeDef EE_Format()
Erases PAGE and PAGE1 and writes VALID_PAGE header to PAGE.
Definition: eeprom.c:453
uint16_t EE_Init(void)
Restore the pages to a known good state in case of page's status corruption after a power loss.
Definition: eeprom.c:79