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