software:firmware
MakAir Firmware
eeprom.h
Go to the documentation of this file.
1 
8 #pragma once
9 #ifdef EEPROM_ENABLED // EEPROM support is not finished yet
10 
11 #include <Arduino.h>
12 
13 // declare here all types of data stored in eeprom
14 // Beware : this is only a 2Kbit EEPROM. 255 bytes maximum ! Last 5 bytes are reserved to detect
15 // virgin status and corruption error.
16 // Beware : do not write too often. 1 million write cycle is the limit during product lifetime.
17 // Beware : read about C struct alignement and padding on a 32 bits
18 // system, and check sizeof(struct). Reserved bytes :
19 // - 0xFF : 0XFF if virgin, 0xAB if not.
20 // - 0xFB, 0xFC, OxFD, 0xFE : CRC32 of EEPROM_Content
21 typedef struct {
22  int16_t language;
23  int32_t makair_minuteCounter;
24  int32_t MFM_expi_minuteCounter;
25  int32_t MFM_inspi_minuteCounter;
26  char stuffc[62];
27  char stuffc2[62];
28  char stuffc3[62];
29 } EEProm_Content_t;
30 
31 // define default values if needed
32 EEProm_Content_t EEProm_Content = {
33  .language = -1,
34  .makair_minuteCounter = -1,
35  .stuffc = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
36  .stuffc2 = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
37  .stuffc3 = "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"};
38 
39 // this works like an assertion. (that does not allocate memory, it is just a typedef)
40 // it will fail to compile if EEProm_Content size is greater than 250
41 typedef char assertMaxEepromSize__LINE__[(sizeof(EEProm_Content) < 251) ? 1 : -1];
42 
43 // error code: read or write function did not succeed
44 #define EEPROM_ERROR_UNABLE_TO_RW 1
45 
46 // error code: the eeprom is virgin. EEProm_Content was not overriden.
47 #define EEPROM_ERROR_READ_VIRGIN 42
48 
49 // error code: the eeprom is corrupted. EEProm_Content contains what was read.
50 #define EEPROM_ERROR_CORRUPTED 0xAA
51 
59 int32_t eeprom_write(void);
60 
69 int32_t eeprom_read(void);
70 
71 #endif