|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
/**
|
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
|
* Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
|
*
|
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
|
* Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
|
|
|
|
|
* Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
|
|
|
|
|
* Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
@ -98,7 +99,7 @@ bool PersistentStore::access_finish() {
|
|
|
|
|
// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
|
|
|
|
// } FRESULT;
|
|
|
|
|
|
|
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
|
|
|
|
|
bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
|
|
|
|
|
if (!eeprom_file_open) return true;
|
|
|
|
|
FRESULT s;
|
|
|
|
|
UINT bytes_written = 0;
|
|
|
|
@ -129,19 +130,23 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
|
|
|
|
|
return (bytes_written != size); // return true for any error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
|
|
|
|
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
|
|
|
|
if (!eeprom_file_open) return true;
|
|
|
|
|
UINT bytes_read = 0;
|
|
|
|
|
FRESULT s;
|
|
|
|
|
s = f_lseek(&eeprom_file, pos);
|
|
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
|
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
|
|
|
|
SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
|
|
|
SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
|
SERIAL_PROTOCOL((int)value); // right now to see errors that are happening in the
|
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
|
SERIAL_PROTOCOL(size); // read_data() and write_data() functions
|
|
|
|
|
SERIAL_PROTOCOLLNPGM("...)");
|
|
|
|
|
SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (writing) {
|
|
|
|
|
s = f_read(&eeprom_file, (void*)value, size, &bytes_read);
|
|
|
|
|
crc16(crc, value, size);
|
|
|
|
@ -151,35 +156,25 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
|
|
|
|
|
s = f_read(&eeprom_file, (void*)temp, size, &bytes_read);
|
|
|
|
|
crc16(crc, temp, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (s) {
|
|
|
|
|
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
|
|
|
|
SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
|
|
|
SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
|
SERIAL_PROTOCOL((int)value); // right now to see errors that are happening in the
|
|
|
|
|
SERIAL_PROTOCOLCHAR(',');
|
|
|
|
|
SERIAL_PROTOCOL(size); // read_data() and write_data() functions
|
|
|
|
|
SERIAL_PROTOCOLLNPGM("...)");
|
|
|
|
|
SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
|
|
|
|
|
SERIAL_PROTOCOLPAIR(" size=", size);
|
|
|
|
|
SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pos = pos + size;
|
|
|
|
|
return bytes_read != size; // return true for any error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 4096; //4KiB of Emulated EEPROM
|
|
|
|
|
}
|
|
|
|
|
const size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
|
|
|
|
|
|
|
|
|
|
#endif // EEPROM_SETTINGS
|
|
|
|
|
#endif // TARGET_LPC1768
|
|
|
|
|