|
@@ -44,37 +44,35 @@
|
44
|
44
|
namespace HAL {
|
45
|
45
|
namespace PersistentStore {
|
46
|
46
|
|
47
|
|
-#define CONFIG_FILE_NAME "eeprom.dat"
|
48
|
47
|
#define HAL_STM32F1_EEPROM_SIZE 4096
|
49
|
48
|
char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE];
|
50
|
49
|
|
|
50
|
+char eeprom_filename[] = "eeprom.dat";
|
|
51
|
+
|
51
|
52
|
bool access_start() {
|
52
|
53
|
if (!card.cardOK) return false;
|
53
|
54
|
int16_t bytes_read = 0;
|
54
|
|
- const char eeprom_zero = 0xFF;
|
55
|
|
- card.openFile((char *)CONFIG_FILE_NAME,true);
|
56
|
|
- bytes_read = card.read (HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
57
|
|
- if (bytes_read == -1) return false;
|
58
|
|
- for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) {
|
|
55
|
+ constexpr char eeprom_zero = 0xFF;
|
|
56
|
+ card.openFile(eeprom_filename, true);
|
|
57
|
+ bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
|
58
|
+ if (bytes_read < 0) return false;
|
|
59
|
+ for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++)
|
59
|
60
|
HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero;
|
60
|
|
- }
|
61
|
61
|
card.closefile();
|
62
|
62
|
return true;
|
63
|
63
|
}
|
64
|
64
|
|
65
|
|
-bool access_finish(){
|
|
65
|
+bool access_finish() {
|
66
|
66
|
if (!card.cardOK) return false;
|
67
|
|
- int16_t bytes_written = 0;
|
68
|
|
- card.openFile((char *)CONFIG_FILE_NAME,true);
|
69
|
|
- bytes_written = card.write (HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
|
67
|
+ card.openFile(eeprom_filename, true);
|
|
68
|
+ int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
70
|
69
|
card.closefile();
|
71
|
70
|
return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
|
72
|
71
|
}
|
73
|
72
|
|
74
|
73
|
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
75
|
|
- for (int i = 0; i < size; i++) {
|
76
|
|
- HAL_STM32F1_eeprom_content [pos + i] = value[i];
|
77
|
|
- }
|
|
74
|
+ for (int i = 0; i < size; i++)
|
|
75
|
+ HAL_STM32F1_eeprom_content[pos + i] = value[i];
|
78
|
76
|
crc16(crc, value, size);
|
79
|
77
|
pos += size;
|
80
|
78
|
return false;
|