Quellcode durchsuchen

Better EEPROM read/write error handling

Scott Lahteine vor 8 Jahren
Ursprung
Commit
492b68f8e3
1 geänderte Dateien mit 26 neuen und 15 gelöschten Zeilen
  1. 26
    15
      Marlin/configuration_store.cpp

+ 26
- 15
Marlin/configuration_store.cpp Datei anzeigen

@@ -188,10 +188,11 @@ void Config_Postprocess() {
188 188
       value++;
189 189
     };
190 190
   }
191
+  bool eeprom_read_error;
191 192
   void _EEPROM_readData(int &pos, uint8_t* value, uint8_t size) {
192 193
     do {
193 194
       uint8_t c = eeprom_read_byte((unsigned char*)pos);
194
-      *value = c;
195
+      if (!eeprom_read_error) *value = c;
195 196
       eeprom_checksum += c;
196 197
       pos++;
197 198
       value++;
@@ -203,6 +204,7 @@ void Config_Postprocess() {
203 204
   #define EEPROM_SKIP(VAR) eeprom_index += sizeof(VAR)
204 205
   #define EEPROM_WRITE(VAR) _EEPROM_writeData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
205 206
   #define EEPROM_READ(VAR) _EEPROM_readData(eeprom_index, (uint8_t*)&VAR, sizeof(VAR))
207
+  #define EEPROM_ASSERT(TST,ERR) if () do{ SERIAL_ERROR_START; SERIAL_ERRORLNPGM(ERR); eeprom_read_error |= true; }while(0)
206 208
 
207 209
   /**
208 210
    * M500 - Store Configuration
@@ -371,17 +373,21 @@ void Config_Postprocess() {
371 373
       EEPROM_WRITE(dummy);
372 374
     }
373 375
 
374
-    uint16_t final_checksum = eeprom_checksum,
375
-             eeprom_size = eeprom_index;
376
+    if (!eeprom_write_error) {
376 377
 
377
-    eeprom_index = EEPROM_OFFSET;
378
-    EEPROM_WRITE(version);
379
-    EEPROM_WRITE(final_checksum);
378
+      uint16_t final_checksum = eeprom_checksum,
379
+               eeprom_size = eeprom_index;
380 380
 
381
-    // Report storage size
382
-    SERIAL_ECHO_START;
383
-    SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
384
-    SERIAL_ECHOLNPGM(" bytes)");
381
+      // Write the EEPROM header
382
+      eeprom_index = EEPROM_OFFSET;
383
+      EEPROM_WRITE(version);
384
+      EEPROM_WRITE(final_checksum);
385
+
386
+      // Report storage size
387
+      SERIAL_ECHO_START;
388
+      SERIAL_ECHOPAIR("Settings Stored (", eeprom_size);
389
+      SERIAL_ECHOLNPGM(" bytes)");
390
+    }
385 391
   }
386 392
 
387 393
   /**
@@ -390,6 +396,7 @@ void Config_Postprocess() {
390 396
   void Config_RetrieveSettings() {
391 397
 
392 398
     EEPROM_START();
399
+    eeprom_read_error = false; // If set EEPROM_READ won't write into RAM
393 400
 
394 401
     char stored_ver[4];
395 402
     EEPROM_READ(stored_ver);
@@ -568,11 +575,15 @@ void Config_Postprocess() {
568 575
       }
569 576
 
570 577
       if (eeprom_checksum == stored_checksum) {
571
-        Config_Postprocess();
572
-        SERIAL_ECHO_START;
573
-        SERIAL_ECHO(version);
574
-        SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index);
575
-        SERIAL_ECHOLNPGM(" bytes)");
578
+        if (eeprom_read_error)
579
+          Config_ResetDefault();
580
+        else {
581
+          Config_Postprocess();
582
+          SERIAL_ECHO_START;
583
+          SERIAL_ECHO(version);
584
+          SERIAL_ECHOPAIR(" stored settings retrieved (", eeprom_index);
585
+          SERIAL_ECHOLNPGM(" bytes)");
586
+        }
576 587
       }
577 588
       else {
578 589
         SERIAL_ERROR_START;

Laden…
Abbrechen
Speichern