Avoid watchdog reset in all wired EEPROMs (#21436)
Co-authored-by: Scott Lahteine <github@thinkyhead.com>
This commit is contained in:
parent
e817db62a4
commit
8d73a6c4e2
@ -40,13 +40,13 @@ bool PersistentStore::access_start() { return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -976,14 +976,13 @@ bool PersistentStore::access_start() { ee_Init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { ee_Flush(); return true; }
|
bool PersistentStore::access_finish() { ee_Flush(); 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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != ee_Read(uint32_t(p))) {
|
|
||||||
ee_Write(uint32_t(p), v);
|
ee_Write(uint32_t(p), v);
|
||||||
delay(2);
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (ee_Read(uint32_t(p)) != v) {
|
if (ee_Read(uint32_t(p)) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -42,14 +42,13 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
delay(2);
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -42,25 +42,22 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
|
||||||
// EEPROM has only ~100,000 write cycles,
|
|
||||||
// so only write bytes that have changed!
|
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
if (v != eeprom_read_byte(p)) {
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crc16(crc, &v, 1);
|
crc16(crc, &v, 1);
|
||||||
pos++;
|
pos++;
|
||||||
value++;
|
value++;
|
||||||
};
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +65,6 @@ bool PersistentStore::read_data(int &pos, uint8_t *value, size_t size, uint16_t
|
|||||||
do {
|
do {
|
||||||
// Read from external EEPROM
|
// Read from external EEPROM
|
||||||
const uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
const uint8_t c = eeprom_read_byte((uint8_t*)pos);
|
||||||
|
|
||||||
if (writing) *value = c;
|
if (writing) *value = c;
|
||||||
crc16(crc, &c, 1);
|
crc16(crc, &c, 1);
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -41,12 +41,13 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
const uint8_t v = *value;
|
const uint8_t v = *value;
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
if (v != eeprom_read_byte(p)) {
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
delay(2);
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -43,25 +43,22 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
|
|
||||||
// EEPROM has only ~100,000 write cycles,
|
|
||||||
// so only write bytes that have changed!
|
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
if (v != eeprom_read_byte(p)) {
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
crc16(crc, &v, 1);
|
crc16(crc, &v, 1);
|
||||||
pos++;
|
pos++;
|
||||||
value++;
|
value++;
|
||||||
};
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,13 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
#ifdef __STM32F1__
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PersistentStore for Arduino-style EEPROM interface
|
* PersistentStore for Arduino-style EEPROM interface
|
||||||
* with simple implementations supplied by Marlin.
|
* with simple implementations supplied by Marlin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __STM32F1__
|
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
#if ENABLED(IIC_BL24CXX_EEPROM)
|
#if ENABLED(IIC_BL24CXX_EEPROM)
|
||||||
@ -48,13 +47,11 @@ bool PersistentStore::access_start() { eeprom_init(); return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
size_t written = 0;
|
uint16_t written = 0;
|
||||||
while (size--) {
|
while (size--) {
|
||||||
uint8_t v = *value;
|
uint8_t v = *value;
|
||||||
uint8_t * const p = (uint8_t * const)pos;
|
uint8_t * const p = (uint8_t * const)pos;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
|
@ -52,13 +52,13 @@ bool PersistentStore::access_start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -18,14 +18,14 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef __MK20DX256__
|
#ifdef __MK20DX256__
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if USE_WIRED_EEPROM
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HAL PersistentStore for Teensy 3.2 (MK20DX256)
|
* HAL PersistentStore for Teensy 3.2 (MK20DX256)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if USE_WIRED_EEPROM
|
||||||
|
|
||||||
#include "../shared/eeprom_api.h"
|
#include "../shared/eeprom_api.h"
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
@ -38,13 +38,13 @@ bool PersistentStore::access_start() { return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -42,13 +42,13 @@ bool PersistentStore::access_start() { return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
@ -22,14 +22,14 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef __IMXRT1062__
|
#ifdef __IMXRT1062__
|
||||||
|
|
||||||
#include "../../inc/MarlinConfig.h"
|
|
||||||
|
|
||||||
#if USE_WIRED_EEPROM
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
|
* HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "../../inc/MarlinConfig.h"
|
||||||
|
|
||||||
|
#if USE_WIRED_EEPROM
|
||||||
|
|
||||||
#include "../shared/eeprom_api.h"
|
#include "../shared/eeprom_api.h"
|
||||||
#include <avr/eeprom.h>
|
#include <avr/eeprom.h>
|
||||||
|
|
||||||
@ -42,13 +42,13 @@ bool PersistentStore::access_start() { return true; }
|
|||||||
bool PersistentStore::access_finish() { return true; }
|
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, size_t size, uint16_t *crc) {
|
||||||
|
uint16_t written = 0;
|
||||||
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;
|
||||||
// EEPROM has only ~100,000 write cycles,
|
if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
|
||||||
// so only write bytes that have changed!
|
|
||||||
if (v != eeprom_read_byte(p)) {
|
|
||||||
eeprom_write_byte(p, v);
|
eeprom_write_byte(p, v);
|
||||||
|
if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
|
||||||
if (eeprom_read_byte(p) != v) {
|
if (eeprom_read_byte(p) != v) {
|
||||||
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user