|
@ -44,37 +44,35 @@ |
|
|
namespace HAL { |
|
|
namespace HAL { |
|
|
namespace PersistentStore { |
|
|
namespace PersistentStore { |
|
|
|
|
|
|
|
|
#define CONFIG_FILE_NAME "eeprom.dat" |
|
|
|
|
|
#define HAL_STM32F1_EEPROM_SIZE 4096 |
|
|
#define HAL_STM32F1_EEPROM_SIZE 4096 |
|
|
char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE]; |
|
|
char HAL_STM32F1_eeprom_content[HAL_STM32F1_EEPROM_SIZE]; |
|
|
|
|
|
|
|
|
|
|
|
char eeprom_filename[] = "eeprom.dat"; |
|
|
|
|
|
|
|
|
bool access_start() { |
|
|
bool access_start() { |
|
|
if (!card.cardOK) return false; |
|
|
if (!card.cardOK) return false; |
|
|
int16_t bytes_read = 0; |
|
|
int16_t bytes_read = 0; |
|
|
const char eeprom_zero = 0xFF; |
|
|
constexpr char eeprom_zero = 0xFF; |
|
|
card.openFile((char *)CONFIG_FILE_NAME,true); |
|
|
card.openFile(eeprom_filename, true); |
|
|
bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
bytes_read = card.read(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
if (bytes_read == -1) return false; |
|
|
if (bytes_read < 0) return false; |
|
|
for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) { |
|
|
for (; bytes_read < HAL_STM32F1_EEPROM_SIZE; bytes_read++) |
|
|
HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero; |
|
|
HAL_STM32F1_eeprom_content[bytes_read] = eeprom_zero; |
|
|
} |
|
|
|
|
|
card.closefile(); |
|
|
card.closefile(); |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool access_finish() { |
|
|
bool access_finish() { |
|
|
if (!card.cardOK) return false; |
|
|
if (!card.cardOK) return false; |
|
|
int16_t bytes_written = 0; |
|
|
card.openFile(eeprom_filename, true); |
|
|
card.openFile((char *)CONFIG_FILE_NAME,true); |
|
|
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
bytes_written = card.write (HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE); |
|
|
|
|
|
card.closefile(); |
|
|
card.closefile(); |
|
|
return (bytes_written == HAL_STM32F1_EEPROM_SIZE); |
|
|
return (bytes_written == HAL_STM32F1_EEPROM_SIZE); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { |
|
|
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) { |
|
|
for (int i = 0; i < size; i++) { |
|
|
for (int i = 0; i < size; i++) |
|
|
HAL_STM32F1_eeprom_content[pos + i] = value[i]; |
|
|
HAL_STM32F1_eeprom_content[pos + i] = value[i]; |
|
|
} |
|
|
|
|
|
crc16(crc, value, size); |
|
|
crc16(crc, value, size); |
|
|
pos += size; |
|
|
pos += size; |
|
|
return false; |
|
|
return false; |
|
|