diff --git a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp index f1489e70d611774b02c30c5f09e57601c3971fc3..293955937f0ad9d77afb0a0a1e65ed3ba6827c20 100644 --- a/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp @@ -1,3 +1,24 @@ +/** + * 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 + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ #ifdef __AVR__ #include "../../inc/MarlinConfig.h" @@ -41,21 +62,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // __AVR__ diff --git a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp index ad66b7b9206eefd7665c64ea927251be9bcfa127..3bf0f443b377156f947a4ba519647279cad93195 100644 --- a/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp @@ -1,3 +1,25 @@ +/** + * Marlin 3D Printer Firmware + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ #ifdef ARDUINO_ARCH_SAM #include "../persistent_store_api.h" @@ -49,21 +71,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // ARDUINO_ARCH_SAM diff --git a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp index 630ab073eaa4cd3975ee2d822bbe7a4e2063a62c..42264e1ccc5897e239c3548aa1e8236ae826d2f5 100644 --- a/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp @@ -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,8 +99,8 @@ 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) { - if(!eeprom_file_open) return true; +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; @@ -113,7 +114,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return s; } - s = f_write(&eeprom_file, (void *)value, size, &bytes_written); + s = f_write(&eeprom_file, (void*)value, size, &bytes_written); if (s) { SERIAL_PROTOCOLPAIR(" write_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 @@ -129,57 +130,51 @@ 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*/) { - if(!eeprom_file_open) return 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_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful + 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); + s = f_read(&eeprom_file, (void*)value, size, &bytes_read); crc16(crc, value, size); } else { uint8_t temp[size]; - s = f_read(&eeprom_file, (void *)temp, size, &bytes_read); + 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 diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp index c6be9c179d43447ed7922cfa7bdce79d2b6ae5e6..779225d093e90479e36e45cb2f9c3ce79ed9fc66 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp @@ -55,7 +55,7 @@ bool PersistentStore::access_finish() { return true; } -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) { FLASH_Status status; if (firstWrite) { @@ -90,7 +90,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return false; } -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*/) { for (uint16_t i = 0; i < size; i++) { byte* accessPoint = (byte*)(pageBase + pos + i); uint8_t c = *accessPoint; @@ -101,22 +101,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} - +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS && EEPROM FLASH #endif // __STM32F1__ diff --git a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp index b5b4d424a6b20123e784a48a09db6663ee05bfa3..26e011cf1d1b55a6cfddc4ec7e11790956d18829 100644 --- a/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp +++ b/Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp @@ -60,7 +60,7 @@ bool PersistentStore::access_finish() { return (bytes_written == HAL_STM32F1_EEPROM_SIZE); } -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) { for (int i = 0; i < size; i++) HAL_STM32F1_eeprom_content[pos + i] = value[i]; crc16(crc, value, size); @@ -68,7 +68,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui return false; } -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*/) { for (int i = 0; i < size; i++) { uint8_t c = HAL_STM32F1_eeprom_content[pos + i]; if (writing) value[i] = c; @@ -78,21 +78,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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 HAL_STM32F1_EEPROM_SIZE; -} +const size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; } #endif // EEPROM_SETTINGS diff --git a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp index 6d262ae385de567d97a82515fb2dd0235ef18061..33a92f99d3ff914cefdda1f314eaa5584ad2cc84 100644 --- a/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp @@ -64,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // STM32F4 || STM32F4xx diff --git a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp index 19f61153c5cd6124408b91928ad5fdfa88e7dc50..a765d2e68d4608b97e42973dfe3f3dee6daec6ca 100644 --- a/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp @@ -21,7 +21,6 @@ * */ - #ifdef STM32F7 #include "../../inc/MarlinConfig.h" @@ -65,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // STM32F7 diff --git a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp index 453287797d3d587cbcf968166ff0c52ee063c273..871e5887745efd3b6a2c65b1276b013893d9798c 100644 --- a/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp +++ b/Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp @@ -1,3 +1,26 @@ +/** + * Marlin 3D Printer Firmware + * + * 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 + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + #if defined(__MK64FX512__) || defined(__MK66FX1M0__) #include "../../inc/MarlinConfig.h" @@ -42,21 +65,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t 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; -} +const size_t PersistentStore::capacity() { return E2END + 1; } #endif // EEPROM_SETTINGS #endif // __MK64FX512__ || __MK66FX1M0__ diff --git a/Marlin/src/HAL/persistent_store_api.cpp b/Marlin/src/HAL/persistent_store_api.cpp index 303027b37dac58633506685dc14be7c1392b55b7..68afa636202dde5bb3728ca2d8eabfc9aaecbe0c 100644 --- a/Marlin/src/HAL/persistent_store_api.cpp +++ b/Marlin/src/HAL/persistent_store_api.cpp @@ -1,9 +1,10 @@ /** * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 diff --git a/Marlin/src/HAL/persistent_store_api.h b/Marlin/src/HAL/persistent_store_api.h index b8aea044a3a212f9b2f4aeab41ad43f5ee1f5fa5..278e49a8ad1a3160bc891b4679488a29482b9bd2 100644 --- a/Marlin/src/HAL/persistent_store_api.h +++ b/Marlin/src/HAL/persistent_store_api.h @@ -1,9 +1,10 @@ /** * Marlin 3D Printer Firmware - * Copyright (C) 2016 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 @@ -30,9 +31,19 @@ public: 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(); + + static inline bool write_data(const int pos, uint8_t* value, const size_t size) { + int data_pos = pos; + uint16_t crc = 0; + return write_data(data_pos, value, size, &crc); + } + + static inline bool read_data(const int pos, uint8_t* value, const size_t size) { + int data_pos = pos; + uint16_t crc = 0; + return read_data(data_pos, value, size, &crc); + } }; extern PersistentStore persistentStore;