|
@@ -42,10 +42,12 @@
|
42
|
42
|
namespace HAL {
|
43
|
43
|
namespace PersistentStore {
|
44
|
44
|
|
45
|
|
-// Store settings in the last two pages
|
46
|
|
-// Flash pages must be erased before writing, so keep track.
|
47
|
|
-bool firstWrite = false;
|
48
|
|
-uint32_t pageBase = EEPROM_START_ADDRESS;
|
|
45
|
+namespace {
|
|
46
|
+ // Store settings in the last two pages
|
|
47
|
+ // Flash pages must be erased before writing, so keep track.
|
|
48
|
+ bool firstWrite = false;
|
|
49
|
+ uint32_t pageBase = EEPROM_START_ADDRESS;
|
|
50
|
+}
|
49
|
51
|
|
50
|
52
|
bool access_start() {
|
51
|
53
|
firstWrite = true;
|
|
@@ -64,9 +66,9 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
64
|
66
|
if (firstWrite) {
|
65
|
67
|
FLASH_Unlock();
|
66
|
68
|
status = FLASH_ErasePage(EEPROM_PAGE0_BASE);
|
67
|
|
- if (status != FLASH_COMPLETE) return false;
|
|
69
|
+ if (status != FLASH_COMPLETE) return true;
|
68
|
70
|
status = FLASH_ErasePage(EEPROM_PAGE1_BASE);
|
69
|
|
- if (status != FLASH_COMPLETE) return false;
|
|
71
|
+ if (status != FLASH_COMPLETE) return true;
|
70
|
72
|
firstWrite = false;
|
71
|
73
|
}
|
72
|
74
|
|
|
@@ -76,7 +78,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
76
|
78
|
uint16_t* wordBuffer = (uint16_t *)value;
|
77
|
79
|
while (wordsToWrite) {
|
78
|
80
|
status = FLASH_ProgramHalfWord(pageBase + pos + (i * 2), wordBuffer[i]);
|
79
|
|
- if (status != FLASH_COMPLETE) return false;
|
|
81
|
+ if (status != FLASH_COMPLETE) return true;
|
80
|
82
|
wordsToWrite--;
|
81
|
83
|
i++;
|
82
|
84
|
}
|
|
@@ -85,15 +87,15 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
85
|
87
|
if (size & 1) {
|
86
|
88
|
uint16_t temp = value[size - 1];
|
87
|
89
|
status = FLASH_ProgramHalfWord(pageBase + pos + i, temp);
|
88
|
|
- if (status != FLASH_COMPLETE) return false;
|
|
90
|
+ if (status != FLASH_COMPLETE) return true;
|
89
|
91
|
}
|
90
|
92
|
|
91
|
93
|
crc16(crc, value, size);
|
92
|
94
|
pos += ((size + 1) & ~1);
|
93
|
|
- return true;
|
|
95
|
+ return false;
|
94
|
96
|
}
|
95
|
97
|
|
96
|
|
-void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
|
98
|
+bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
97
|
99
|
for (uint16_t i = 0; i < size; i++) {
|
98
|
100
|
byte* accessPoint = (byte*)(pageBase + pos + i);
|
99
|
101
|
uint8_t c = *accessPoint;
|
|
@@ -101,6 +103,7 @@ void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
101
|
103
|
crc16(crc, &c, 1);
|
102
|
104
|
}
|
103
|
105
|
pos += ((size + 1) & ~1);
|
|
106
|
+ return false;
|
104
|
107
|
}
|
105
|
108
|
|
106
|
109
|
} // PersistentStore
|