浏览代码

Avoid watchdog reset in all wired EEPROMs (#21436)

Co-authored-by: Scott Lahteine <github@thinkyhead.com>
Tomas Rimkus 4 年前
父节点
当前提交
8a67846872
没有帐户链接到提交者的电子邮件

+ 3
- 3
Marlin/src/HAL/AVR/eeprom.cpp 查看文件

40
 bool PersistentStore::access_finish() { return true; }
40
 bool PersistentStore::access_finish() { return true; }
41
 
41
 
42
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
42
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
43
+  uint16_t written = 0;
43
   while (size--) {
44
   while (size--) {
44
     uint8_t * const p = (uint8_t * const)pos;
45
     uint8_t * const p = (uint8_t * const)pos;
45
     uint8_t v = *value;
46
     uint8_t v = *value;
46
-    // EEPROM has only ~100,000 write cycles,
47
-    // so only write bytes that have changed!
48
-    if (v != eeprom_read_byte(p)) {
47
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
49
       eeprom_write_byte(p, v);
48
       eeprom_write_byte(p, v);
49
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
50
       if (eeprom_read_byte(p) != v) {
50
       if (eeprom_read_byte(p) != v) {
51
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
51
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
52
         return true;
52
         return true;

+ 3
- 4
Marlin/src/HAL/DUE/eeprom_flash.cpp 查看文件

976
 bool PersistentStore::access_finish() { ee_Flush(); return true; }
976
 bool PersistentStore::access_finish() { ee_Flush(); return true; }
977
 
977
 
978
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
978
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
979
+  uint16_t written = 0;
979
   while (size--) {
980
   while (size--) {
980
     uint8_t * const p = (uint8_t * const)pos;
981
     uint8_t * const p = (uint8_t * const)pos;
981
     uint8_t v = *value;
982
     uint8_t v = *value;
982
-    // EEPROM has only ~100,000 write cycles,
983
-    // so only write bytes that have changed!
984
-    if (v != ee_Read(uint32_t(p))) {
983
+    if (v != ee_Read(uint32_t(p))) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
985
       ee_Write(uint32_t(p), v);
984
       ee_Write(uint32_t(p), v);
986
-      delay(2);
985
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
987
       if (ee_Read(uint32_t(p)) != v) {
986
       if (ee_Read(uint32_t(p)) != v) {
988
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
987
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
989
         return true;
988
         return true;

+ 3
- 4
Marlin/src/HAL/DUE/eeprom_wired.cpp 查看文件

42
 bool PersistentStore::access_finish() { return true; }
42
 bool PersistentStore::access_finish() { return true; }
43
 
43
 
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45
   while (size--) {
46
   while (size--) {
46
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t v = *value;
48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51
       eeprom_write_byte(p, v);
50
       eeprom_write_byte(p, v);
52
-      delay(2);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
53
       if (eeprom_read_byte(p) != v) {
52
       if (eeprom_read_byte(p) != v) {
54
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
55
         return true;
54
         return true;

+ 4
- 8
Marlin/src/HAL/LPC1768/eeprom_wired.cpp 查看文件

42
 bool PersistentStore::access_finish() { return true; }
42
 bool PersistentStore::access_finish() { return true; }
43
 
43
 
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45
   while (size--) {
46
   while (size--) {
46
     uint8_t v = *value;
47
     uint8_t v = *value;
47
-
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
     uint8_t * const p = (uint8_t * const)pos;
48
     uint8_t * const p = (uint8_t * const)pos;
51
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
52
       eeprom_write_byte(p, v);
50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
53
       if (eeprom_read_byte(p) != v) {
52
       if (eeprom_read_byte(p) != v) {
54
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
55
         return true;
54
         return true;
56
       }
55
       }
57
     }
56
     }
58
-
59
     crc16(crc, &v, 1);
57
     crc16(crc, &v, 1);
60
     pos++;
58
     pos++;
61
     value++;
59
     value++;
62
-  };
63
-
60
+  }
64
   return false;
61
   return false;
65
 }
62
 }
66
 
63
 
68
   do {
65
   do {
69
     // Read from external EEPROM
66
     // Read from external EEPROM
70
     const uint8_t c = eeprom_read_byte((uint8_t*)pos);
67
     const uint8_t c = eeprom_read_byte((uint8_t*)pos);
71
-
72
     if (writing) *value = c;
68
     if (writing) *value = c;
73
     crc16(crc, &c, 1);
69
     crc16(crc, &c, 1);
74
     pos++;
70
     pos++;

+ 3
- 2
Marlin/src/HAL/SAMD51/eeprom_wired.cpp 查看文件

41
 bool PersistentStore::access_finish() { return true; }
41
 bool PersistentStore::access_finish() { return true; }
42
 
42
 
43
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
43
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
+  uint16_t written = 0;
44
   while (size--) {
45
   while (size--) {
45
     const uint8_t v = *value;
46
     const uint8_t v = *value;
46
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t * const p = (uint8_t * const)pos;
47
-    if (v != eeprom_read_byte(p)) {
48
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
48
       eeprom_write_byte(p, v);
49
       eeprom_write_byte(p, v);
49
-      delay(2);
50
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
50
       if (eeprom_read_byte(p) != v) {
51
       if (eeprom_read_byte(p) != v) {
51
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
52
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
52
         return true;
53
         return true;

+ 4
- 7
Marlin/src/HAL/STM32/eeprom_wired.cpp 查看文件

43
 bool PersistentStore::access_finish() { return true; }
43
 bool PersistentStore::access_finish() { return true; }
44
 
44
 
45
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
46
+  uint16_t written = 0;
46
   while (size--) {
47
   while (size--) {
47
     uint8_t v = *value;
48
     uint8_t v = *value;
48
-
49
-    // EEPROM has only ~100,000 write cycles,
50
-    // so only write bytes that have changed!
51
     uint8_t * const p = (uint8_t * const)pos;
49
     uint8_t * const p = (uint8_t * const)pos;
52
-    if (v != eeprom_read_byte(p)) {
50
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
53
       eeprom_write_byte(p, v);
51
       eeprom_write_byte(p, v);
52
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
54
       if (eeprom_read_byte(p) != v) {
53
       if (eeprom_read_byte(p) != v) {
55
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
54
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
56
         return true;
55
         return true;
57
       }
56
       }
58
     }
57
     }
59
-
60
     crc16(crc, &v, 1);
58
     crc16(crc, &v, 1);
61
     pos++;
59
     pos++;
62
     value++;
60
     value++;
63
-  };
64
-
61
+  }
65
   return false;
62
   return false;
66
 }
63
 }
67
 
64
 

+ 3
- 6
Marlin/src/HAL/STM32F1/eeprom_bl24cxx.cpp 查看文件

19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
  *
20
  *
21
  */
21
  */
22
+#ifdef __STM32F1__
22
 
23
 
23
 /**
24
 /**
24
  * PersistentStore for Arduino-style EEPROM interface
25
  * PersistentStore for Arduino-style EEPROM interface
25
  * with simple implementations supplied by Marlin.
26
  * with simple implementations supplied by Marlin.
26
  */
27
  */
27
 
28
 
28
-#ifdef __STM32F1__
29
-
30
 #include "../../inc/MarlinConfig.h"
29
 #include "../../inc/MarlinConfig.h"
31
 
30
 
32
 #if ENABLED(IIC_BL24CXX_EEPROM)
31
 #if ENABLED(IIC_BL24CXX_EEPROM)
48
 bool PersistentStore::access_finish() { return true; }
47
 bool PersistentStore::access_finish() { return true; }
49
 
48
 
50
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
49
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
51
-  size_t written = 0;
50
+  uint16_t written = 0;
52
   while (size--) {
51
   while (size--) {
53
     uint8_t v = *value;
52
     uint8_t v = *value;
54
     uint8_t * const p = (uint8_t * const)pos;
53
     uint8_t * const p = (uint8_t * const)pos;
55
-    // EEPROM has only ~100,000 write cycles,
56
-    // so only write bytes that have changed!
57
-    if (v != eeprom_read_byte(p)) {
54
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
58
       eeprom_write_byte(p, v);
55
       eeprom_write_byte(p, v);
59
       if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
56
       if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
60
       if (eeprom_read_byte(p) != v) {
57
       if (eeprom_read_byte(p) != v) {

+ 3
- 3
Marlin/src/HAL/STM32F1/eeprom_wired.cpp 查看文件

52
 }
52
 }
53
 
53
 
54
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
54
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
55
+  uint16_t written = 0;
55
   while (size--) {
56
   while (size--) {
56
     uint8_t * const p = (uint8_t * const)pos;
57
     uint8_t * const p = (uint8_t * const)pos;
57
     uint8_t v = *value;
58
     uint8_t v = *value;
58
-    // EEPROM has only ~100,000 write cycles,
59
-    // so only write bytes that have changed!
60
-    if (v != eeprom_read_byte(p)) {
59
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
61
       eeprom_write_byte(p, v);
60
       eeprom_write_byte(p, v);
61
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
62
       if (eeprom_read_byte(p) != v) {
62
       if (eeprom_read_byte(p) != v) {
63
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
63
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
64
         return true;
64
         return true;

+ 7
- 7
Marlin/src/HAL/TEENSY31_32/eeprom.cpp 查看文件

18
  */
18
  */
19
 #ifdef __MK20DX256__
19
 #ifdef __MK20DX256__
20
 
20
 
21
-#include "../../inc/MarlinConfig.h"
22
-
23
-#if USE_WIRED_EEPROM
24
-
25
 /**
21
 /**
26
  * HAL PersistentStore for Teensy 3.2 (MK20DX256)
22
  * HAL PersistentStore for Teensy 3.2 (MK20DX256)
27
  */
23
  */
28
 
24
 
25
+#include "../../inc/MarlinConfig.h"
26
+
27
+#if USE_WIRED_EEPROM
28
+
29
 #include "../shared/eeprom_api.h"
29
 #include "../shared/eeprom_api.h"
30
 #include <avr/eeprom.h>
30
 #include <avr/eeprom.h>
31
 
31
 
38
 bool PersistentStore::access_finish() { return true; }
38
 bool PersistentStore::access_finish() { return true; }
39
 
39
 
40
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
40
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
41
+  uint16_t written = 0;
41
   while (size--) {
42
   while (size--) {
42
     uint8_t * const p = (uint8_t * const)pos;
43
     uint8_t * const p = (uint8_t * const)pos;
43
     uint8_t v = *value;
44
     uint8_t v = *value;
44
-    // EEPROM has only ~100,000 write cycles,
45
-    // so only write bytes that have changed!
46
-    if (v != eeprom_read_byte(p)) {
45
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
47
       eeprom_write_byte(p, v);
46
       eeprom_write_byte(p, v);
47
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
48
       if (eeprom_read_byte(p) != v) {
48
       if (eeprom_read_byte(p) != v) {
49
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
49
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
50
         return true;
50
         return true;

+ 3
- 3
Marlin/src/HAL/TEENSY35_36/eeprom.cpp 查看文件

42
 bool PersistentStore::access_finish() { return true; }
42
 bool PersistentStore::access_finish() { return true; }
43
 
43
 
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45
   while (size--) {
46
   while (size--) {
46
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t v = *value;
48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51
       eeprom_write_byte(p, v);
50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
52
       if (eeprom_read_byte(p) != v) {
52
       if (eeprom_read_byte(p) != v) {
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
54
         return true;
54
         return true;

+ 7
- 7
Marlin/src/HAL/TEENSY40_41/eeprom.cpp 查看文件

22
  */
22
  */
23
 #ifdef __IMXRT1062__
23
 #ifdef __IMXRT1062__
24
 
24
 
25
-#include "../../inc/MarlinConfig.h"
26
-
27
-#if USE_WIRED_EEPROM
28
-
29
 /**
25
 /**
30
  * HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
26
  * HAL PersistentStore for Teensy 4.0 (IMXRT1062DVL6A) / 4.1 (IMXRT1062DVJ6A)
31
  */
27
  */
32
 
28
 
29
+#include "../../inc/MarlinConfig.h"
30
+
31
+#if USE_WIRED_EEPROM
32
+
33
 #include "../shared/eeprom_api.h"
33
 #include "../shared/eeprom_api.h"
34
 #include <avr/eeprom.h>
34
 #include <avr/eeprom.h>
35
 
35
 
42
 bool PersistentStore::access_finish() { return true; }
42
 bool PersistentStore::access_finish() { return true; }
43
 
43
 
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
44
 bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
45
+  uint16_t written = 0;
45
   while (size--) {
46
   while (size--) {
46
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t * const p = (uint8_t * const)pos;
47
     uint8_t v = *value;
48
     uint8_t v = *value;
48
-    // EEPROM has only ~100,000 write cycles,
49
-    // so only write bytes that have changed!
50
-    if (v != eeprom_read_byte(p)) {
49
+    if (v != eeprom_read_byte(p)) { // EEPROM has only ~100,000 write cycles, so only write bytes that have changed!
51
       eeprom_write_byte(p, v);
50
       eeprom_write_byte(p, v);
51
+      if (++written & 0x7F) delay(2); else safe_delay(2); // Avoid triggering watchdog during long EEPROM writes
52
       if (eeprom_read_byte(p) != v) {
52
       if (eeprom_read_byte(p) != v) {
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
53
         SERIAL_ECHO_MSG(STR_ERR_EEPROM_WRITE);
54
         return true;
54
         return true;

正在加载...
取消
保存