Update PersistentStore api (#11538)
- Clean up the API to use a `static` class instance to adhere to Marlin convention - Add `const` position data access for read/write - Add Storage capacity to the interface
This commit is contained in:
parent
60f1376798
commit
66d2b48b59
|
@ -1,18 +1,15 @@
|
||||||
#ifdef __AVR__
|
#ifdef __AVR__
|
||||||
|
|
||||||
#include "../persistent_store_api.h"
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#if ENABLED(EEPROM_SETTINGS)
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
|
|
||||||
namespace HAL {
|
#include "../persistent_store_api.h"
|
||||||
namespace PersistentStore {
|
|
||||||
|
|
||||||
bool access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
@ -33,7 +30,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
|
@ -44,7 +41,20 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false; // always assume success for AVR's
|
return false; // always assume success for AVR's
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
|
@ -8,19 +8,16 @@
|
||||||
|
|
||||||
extern void eeprom_flush(void);
|
extern void eeprom_flush(void);
|
||||||
|
|
||||||
namespace HAL {
|
bool PersistentStore::access_start() { return true; }
|
||||||
namespace PersistentStore {
|
|
||||||
|
|
||||||
bool access_start() { return true; }
|
bool PersistentStore::access_finish() {
|
||||||
|
|
||||||
bool access_finish() {
|
|
||||||
#if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
|
#if DISABLED(I2C_EEPROM) && DISABLED(SPI_EEPROM)
|
||||||
eeprom_flush();
|
eeprom_flush();
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
@ -41,7 +38,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
|
@ -52,8 +49,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
#endif // __AVR__
|
#endif // ARDUINO_ARCH_SAM
|
|
@ -43,8 +43,6 @@
|
||||||
#define FALLING 0x03
|
#define FALLING 0x03
|
||||||
#define RISING 0x04
|
#define RISING 0x04
|
||||||
|
|
||||||
#define E2END 0xFFF // EEPROM end address
|
|
||||||
|
|
||||||
typedef uint8_t byte;
|
typedef uint8_t byte;
|
||||||
#define PROGMEM
|
#define PROGMEM
|
||||||
#define PSTR(v) (v)
|
#define PSTR(v) (v)
|
||||||
|
|
|
@ -27,19 +27,17 @@
|
||||||
|
|
||||||
#include "../persistent_store_api.h"
|
#include "../persistent_store_api.h"
|
||||||
|
|
||||||
#include "chanfs/diskio.h"
|
#include <chanfs/diskio.h>
|
||||||
#include "chanfs/ff.h"
|
#include <chanfs/ff.h>
|
||||||
|
|
||||||
extern uint32_t MSC_Aquire_Lock();
|
extern uint32_t MSC_Aquire_Lock();
|
||||||
extern uint32_t MSC_Release_Lock();
|
extern uint32_t MSC_Release_Lock();
|
||||||
|
|
||||||
namespace HAL {
|
|
||||||
namespace PersistentStore {
|
|
||||||
|
|
||||||
FATFS fat_fs;
|
FATFS fat_fs;
|
||||||
FIL eeprom_file;
|
FIL eeprom_file;
|
||||||
|
bool eeprom_file_open = false;
|
||||||
|
|
||||||
bool access_start() {
|
bool PersistentStore::access_start() {
|
||||||
const char eeprom_erase_value = 0xFF;
|
const char eeprom_erase_value = 0xFF;
|
||||||
MSC_Aquire_Lock();
|
MSC_Aquire_Lock();
|
||||||
if (f_mount(&fat_fs, "", 1)) {
|
if (f_mount(&fat_fs, "", 1)) {
|
||||||
|
@ -53,7 +51,7 @@ bool access_start() {
|
||||||
UINT bytes_written;
|
UINT bytes_written;
|
||||||
FSIZE_t file_size = f_size(&eeprom_file);
|
FSIZE_t file_size = f_size(&eeprom_file);
|
||||||
f_lseek(&eeprom_file, file_size);
|
f_lseek(&eeprom_file, file_size);
|
||||||
while (file_size <= E2END && res == FR_OK) {
|
while (file_size < capacity() && res == FR_OK) {
|
||||||
res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written);
|
res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written);
|
||||||
file_size++;
|
file_size++;
|
||||||
}
|
}
|
||||||
|
@ -61,14 +59,16 @@ bool access_start() {
|
||||||
if (res == FR_OK) {
|
if (res == FR_OK) {
|
||||||
f_lseek(&eeprom_file, 0);
|
f_lseek(&eeprom_file, 0);
|
||||||
f_sync(&eeprom_file);
|
f_sync(&eeprom_file);
|
||||||
|
eeprom_file_open = true;
|
||||||
}
|
}
|
||||||
return res == FR_OK;
|
return res == FR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool access_finish() {
|
bool PersistentStore::access_finish() {
|
||||||
f_close(&eeprom_file);
|
f_close(&eeprom_file);
|
||||||
f_unmount("");
|
f_unmount("");
|
||||||
MSC_Release_Lock();
|
MSC_Release_Lock();
|
||||||
|
eeprom_file_open = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,8 @@ bool access_finish() {
|
||||||
// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
||||||
// } FRESULT;
|
// } FRESULT;
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
|
if(!eeprom_file_open) return true;
|
||||||
FRESULT s;
|
FRESULT s;
|
||||||
UINT bytes_written = 0;
|
UINT bytes_written = 0;
|
||||||
|
|
||||||
|
@ -128,7 +129,8 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return (bytes_written != size); // return true for any error
|
return (bytes_written != size); // return true for any error
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
|
if(!eeprom_file_open) return true;
|
||||||
UINT bytes_read = 0;
|
UINT bytes_read = 0;
|
||||||
FRESULT s;
|
FRESULT s;
|
||||||
s = f_lseek(&eeprom_file, pos);
|
s = f_lseek(&eeprom_file, pos);
|
||||||
|
@ -163,8 +165,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return bytes_read != size; // return true for any error
|
return bytes_read != size; // return true for any error
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PersistentStore
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
} // HAL
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return 4096; //4KiB of Emulated EEPROM
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
#endif // TARGET_LPC1768
|
#endif // TARGET_LPC1768
|
|
@ -39,28 +39,23 @@
|
||||||
#include <flash_stm32.h>
|
#include <flash_stm32.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
namespace HAL {
|
// Store settings in the last two pages
|
||||||
namespace PersistentStore {
|
// Flash pages must be erased before writing, so keep track.
|
||||||
|
bool firstWrite = false;
|
||||||
|
uint32_t pageBase = EEPROM_START_ADDRESS;
|
||||||
|
|
||||||
namespace {
|
bool PersistentStore::access_start() {
|
||||||
// Store settings in the last two pages
|
|
||||||
// Flash pages must be erased before writing, so keep track.
|
|
||||||
bool firstWrite = false;
|
|
||||||
uint32_t pageBase = EEPROM_START_ADDRESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool access_start() {
|
|
||||||
firstWrite = true;
|
firstWrite = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool access_finish() {
|
bool PersistentStore::access_finish() {
|
||||||
FLASH_Lock();
|
FLASH_Lock();
|
||||||
firstWrite = false;
|
firstWrite = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
FLASH_Status status;
|
FLASH_Status status;
|
||||||
|
|
||||||
if (firstWrite) {
|
if (firstWrite) {
|
||||||
|
@ -95,7 +90,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
for (uint16_t i = 0; i < size; i++) {
|
for (uint16_t i = 0; i < size; i++) {
|
||||||
byte* accessPoint = (byte*)(pageBase + pos + i);
|
byte* accessPoint = (byte*)(pageBase + pos + i);
|
||||||
uint8_t c = *accessPoint;
|
uint8_t c = *accessPoint;
|
||||||
|
@ -106,8 +101,22 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PersistentStore
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
} // HAL
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS && EEPROM FLASH
|
#endif // EEPROM_SETTINGS && EEPROM FLASH
|
||||||
#endif // __STM32F1__
|
#endif // __STM32F1__
|
||||||
|
|
|
@ -32,24 +32,14 @@
|
||||||
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
|
#if ENABLED(EEPROM_SETTINGS) && DISABLED(FLASH_EEPROM_EMULATION)
|
||||||
|
|
||||||
#include "../persistent_store_api.h"
|
#include "../persistent_store_api.h"
|
||||||
|
|
||||||
//#include "../../core/types.h"
|
|
||||||
//#include "../../core/language.h"
|
|
||||||
//#include "../../core/serial.h"
|
|
||||||
//#include "../../core/utility.h"
|
|
||||||
|
|
||||||
#include "../../sd/cardreader.h"
|
#include "../../sd/cardreader.h"
|
||||||
|
|
||||||
|
|
||||||
namespace HAL {
|
|
||||||
namespace PersistentStore {
|
|
||||||
|
|
||||||
#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";
|
char eeprom_filename[] = "eeprom.dat";
|
||||||
|
|
||||||
bool access_start() {
|
bool PersistentStore::access_start() {
|
||||||
if (!card.cardOK) return false;
|
if (!card.cardOK) return false;
|
||||||
int16_t bytes_read = 0;
|
int16_t bytes_read = 0;
|
||||||
constexpr char eeprom_zero = 0xFF;
|
constexpr char eeprom_zero = 0xFF;
|
||||||
|
@ -62,7 +52,7 @@ bool access_start() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool access_finish() {
|
bool PersistentStore::access_finish() {
|
||||||
if (!card.cardOK) return false;
|
if (!card.cardOK) return false;
|
||||||
card.openFile(eeprom_filename, true);
|
card.openFile(eeprom_filename, true);
|
||||||
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
int16_t bytes_written = card.write(HAL_STM32F1_eeprom_content, HAL_STM32F1_EEPROM_SIZE);
|
||||||
|
@ -70,7 +60,7 @@ bool access_finish() {
|
||||||
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 PersistentStore::write_data(int &pos, const uint8_t *value, size_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);
|
||||||
|
@ -78,7 +68,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
|
uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
|
||||||
if (writing) value[i] = c;
|
if (writing) value[i] = c;
|
||||||
|
@ -88,10 +78,22 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PersistentStore::
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
} // HAL::
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return HAL_STM32F1_EEPROM_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
|
|
||||||
#endif // __STM32F1__
|
#endif // __STM32F1__
|
||||||
|
|
|
@ -29,13 +29,10 @@
|
||||||
|
|
||||||
#if ENABLED(EEPROM_SETTINGS)
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
|
|
||||||
namespace HAL {
|
bool PersistentStore::access_start() { return true; }
|
||||||
namespace PersistentStore {
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
bool access_start() { return true; }
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
bool access_finish() { return true; }
|
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
@ -56,7 +53,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
|
@ -67,8 +64,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PersistentStore
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
} // HAL
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
#endif // STM32F4 || STM32F4xx
|
#endif // STM32F4 || STM32F4xx
|
|
@ -24,19 +24,16 @@
|
||||||
|
|
||||||
#ifdef STM32F7
|
#ifdef STM32F7
|
||||||
|
|
||||||
#include "../persistent_store_api.h"
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#if ENABLED(EEPROM_SETTINGS)
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
|
|
||||||
namespace HAL {
|
#include "../persistent_store_api.h"
|
||||||
namespace PersistentStore {
|
|
||||||
|
|
||||||
bool access_start() { return true; }
|
bool PersistentStore::access_start() { return true; }
|
||||||
bool access_finish() { return true; }
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
@ -57,7 +54,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||||
*value = c;
|
*value = c;
|
||||||
|
@ -68,10 +65,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
#endif // STM32F7
|
#endif // STM32F7
|
||||||
|
|
||||||
|
|
|
@ -5,14 +5,12 @@
|
||||||
#if ENABLED(EEPROM_SETTINGS)
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
|
|
||||||
#include "../persistent_store_api.h"
|
#include "../persistent_store_api.h"
|
||||||
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
namespace HAL {
|
bool PersistentStore::access_start() { return true; }
|
||||||
namespace PersistentStore {
|
bool PersistentStore::access_finish() { return true; }
|
||||||
|
|
||||||
bool access_start() { return true; }
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
||||||
bool access_finish() { return true; }
|
|
||||||
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
@ -33,7 +31,7 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing/*=true*/) {
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
||||||
do {
|
do {
|
||||||
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
uint8_t c = eeprom_read_byte((unsigned char*)pos);
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
|
@ -44,8 +42,21 @@ bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const boo
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // PersistentStore
|
bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
|
||||||
} // HAL
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return write_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
|
||||||
|
int data_pos = pos;
|
||||||
|
uint16_t crc = 0;
|
||||||
|
return read_data(data_pos, value, size, &crc);
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t PersistentStore::capacity() {
|
||||||
|
return E2END + 1;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // EEPROM_SETTINGS
|
#endif // EEPROM_SETTINGS
|
||||||
#endif // __MK64FX512__ || __MK66FX1M0__
|
#endif // __MK64FX512__ || __MK66FX1M0__
|
|
@ -4,15 +4,17 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
namespace HAL {
|
class PersistentStore {
|
||||||
namespace PersistentStore {
|
public:
|
||||||
|
static bool access_start();
|
||||||
|
static bool access_finish();
|
||||||
|
static bool write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc);
|
||||||
|
static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
|
||||||
|
static bool write_data(const int pos, uint8_t* value, size_t size);
|
||||||
|
static bool read_data(const int pos, uint8_t* value, size_t size);
|
||||||
|
static const size_t capacity();
|
||||||
|
};
|
||||||
|
|
||||||
bool access_start();
|
extern PersistentStore persistentStore;
|
||||||
bool access_finish();
|
|
||||||
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc);
|
|
||||||
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc, const bool writing=true);
|
|
||||||
|
|
||||||
} // PersistentStore
|
|
||||||
} // HAL
|
|
||||||
|
|
||||||
#endif // _PERSISTENT_STORE_H_
|
#endif // _PERSISTENT_STORE_H_
|
||||||
|
|
|
@ -1172,7 +1172,7 @@
|
||||||
|
|
||||||
SERIAL_ECHO_START();
|
SERIAL_ECHO_START();
|
||||||
SERIAL_ECHOLNPGM("EEPROM Dump:");
|
SERIAL_ECHOLNPGM("EEPROM Dump:");
|
||||||
for (uint16_t i = 0; i <= E2END; i += 16) {
|
for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) {
|
||||||
if (!(i & 0x3)) idle();
|
if (!(i & 0x3)) idle();
|
||||||
print_hex_word(i);
|
print_hex_word(i);
|
||||||
SERIAL_ECHOPGM(": ");
|
SERIAL_ECHOPGM(": ");
|
||||||
|
|
|
@ -345,14 +345,15 @@ void MarlinSettings::postprocess() {
|
||||||
|
|
||||||
#if ENABLED(EEPROM_SETTINGS)
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
#include "../HAL/persistent_store_api.h"
|
#include "../HAL/persistent_store_api.h"
|
||||||
|
PersistentStore persistentStore;
|
||||||
|
|
||||||
#define DUMMY_PID_VALUE 3000.0f
|
#define DUMMY_PID_VALUE 3000.0f
|
||||||
#define EEPROM_START() int eeprom_index = EEPROM_OFFSET; HAL::PersistentStore::access_start()
|
#define EEPROM_START() int eeprom_index = EEPROM_OFFSET; persistentStore.access_start()
|
||||||
#define EEPROM_FINISH() HAL::PersistentStore::access_finish()
|
#define EEPROM_FINISH() persistentStore.access_finish()
|
||||||
#define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
|
#define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
|
||||||
#define EEPROM_WRITE(VAR) HAL::PersistentStore::write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
#define EEPROM_WRITE(VAR) persistentStore.write_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
||||||
#define EEPROM_READ(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
|
#define EEPROM_READ(VAR) persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc, !validating)
|
||||||
#define EEPROM_READ_ALWAYS(VAR) HAL::PersistentStore::read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
#define EEPROM_READ_ALWAYS(VAR) persistentStore.read_data(eeprom_index, (uint8_t*)&VAR, sizeof(VAR), &working_crc)
|
||||||
#define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START_P(port); SERIAL_ERRORLNPGM_P(port, ERR); eeprom_error = true; }while(0)
|
#define EEPROM_ASSERT(TST,ERR) if (!(TST)) do{ SERIAL_ERROR_START_P(port); SERIAL_ERRORLNPGM_P(port, ERR); eeprom_error = true; }while(0)
|
||||||
|
|
||||||
#if ENABLED(DEBUG_EEPROM_READWRITE)
|
#if ENABLED(DEBUG_EEPROM_READWRITE)
|
||||||
|
@ -1607,6 +1608,10 @@ void MarlinSettings::postprocess() {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const uint16_t MarlinSettings::meshes_end = persistentStore.capacity() - 129; // 128 (+1 because of the change to capacity rather than last valid address)
|
||||||
|
// is a placeholder for the size of the MAT; the MAT will always
|
||||||
|
// live at the very end of the eeprom
|
||||||
|
|
||||||
uint16_t MarlinSettings::meshes_start_index() {
|
uint16_t MarlinSettings::meshes_start_index() {
|
||||||
return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
|
return (datasize() + EEPROM_OFFSET + 32) & 0xFFF8; // Pad the end of configuration data so it can float up
|
||||||
// or down a little bit without disrupting the mesh data
|
// or down a little bit without disrupting the mesh data
|
||||||
|
@ -1627,7 +1632,7 @@ void MarlinSettings::postprocess() {
|
||||||
if (!WITHIN(slot, 0, a - 1)) {
|
if (!WITHIN(slot, 0, a - 1)) {
|
||||||
#if ENABLED(EEPROM_CHITCHAT)
|
#if ENABLED(EEPROM_CHITCHAT)
|
||||||
ubl_invalid_slot(a);
|
ubl_invalid_slot(a);
|
||||||
SERIAL_PROTOCOLPAIR("E2END=", E2END);
|
SERIAL_PROTOCOLPAIR("E2END=", persistentStore.capacity() - 1);
|
||||||
SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
|
SERIAL_PROTOCOLPAIR(" meshes_end=", meshes_end);
|
||||||
SERIAL_PROTOCOLLNPAIR(" slot=", slot);
|
SERIAL_PROTOCOLLNPAIR(" slot=", slot);
|
||||||
SERIAL_EOL();
|
SERIAL_EOL();
|
||||||
|
@ -1638,9 +1643,9 @@ void MarlinSettings::postprocess() {
|
||||||
int pos = mesh_slot_offset(slot);
|
int pos = mesh_slot_offset(slot);
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
|
|
||||||
HAL::PersistentStore::access_start();
|
persistentStore.access_start();
|
||||||
const bool status = HAL::PersistentStore::write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
|
const bool status = persistentStore.write_data(pos, (uint8_t *)&ubl.z_values, sizeof(ubl.z_values), &crc);
|
||||||
HAL::PersistentStore::access_finish();
|
persistentStore.access_finish();
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
SERIAL_PROTOCOLPGM("?Unable to save mesh data.\n");
|
SERIAL_PROTOCOLPGM("?Unable to save mesh data.\n");
|
||||||
|
@ -1676,9 +1681,9 @@ void MarlinSettings::postprocess() {
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
|
uint8_t * const dest = into ? (uint8_t*)into : (uint8_t*)&ubl.z_values;
|
||||||
|
|
||||||
HAL::PersistentStore::access_start();
|
persistentStore.access_start();
|
||||||
const uint16_t status = HAL::PersistentStore::read_data(pos, dest, sizeof(ubl.z_values), &crc);
|
const uint16_t status = persistentStore.read_data(pos, dest, sizeof(ubl.z_values), &crc);
|
||||||
HAL::PersistentStore::access_finish();
|
persistentStore.access_finish();
|
||||||
|
|
||||||
if (status)
|
if (status)
|
||||||
SERIAL_PROTOCOLPGM("?Unable to load mesh data.\n");
|
SERIAL_PROTOCOLPGM("?Unable to load mesh data.\n");
|
||||||
|
|
|
@ -24,6 +24,9 @@
|
||||||
#define CONFIGURATION_STORE_H
|
#define CONFIGURATION_STORE_H
|
||||||
|
|
||||||
#include "../inc/MarlinConfig.h"
|
#include "../inc/MarlinConfig.h"
|
||||||
|
#if ENABLED(EEPROM_SETTINGS)
|
||||||
|
#include "../HAL/persistent_store_api.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
|
#define ADD_PORT_ARG ENABLED(EEPROM_CHITCHAT) && NUM_SERIAL > 1
|
||||||
|
|
||||||
|
@ -98,9 +101,8 @@ class MarlinSettings {
|
||||||
|
|
||||||
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
|
#if ENABLED(AUTO_BED_LEVELING_UBL) // Eventually make these available if any leveling system
|
||||||
// That can store is enabled
|
// That can store is enabled
|
||||||
static constexpr uint16_t meshes_end = E2END - 128; // 128 is a placeholder for the size of the MAT; the MAT will always
|
static const uint16_t meshes_end; // 128 is a placeholder for the size of the MAT; the MAT will always
|
||||||
// live at the very end of the eeprom
|
// live at the very end of the eeprom
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool _load(PORTINIT_SOLO);
|
static bool _load(PORTINIT_SOLO);
|
||||||
|
|
Loading…
Reference in a new issue