Browse Source

All EEPROM access uses persistentStore

Nils Hasenbanck 6 years ago
parent
commit
577aeb4aa9
2 changed files with 31 additions and 11 deletions
  1. 7
    3
      Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
  2. 24
    8
      Marlin/src/module/printcounter.cpp

+ 7
- 3
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

@@ -29,6 +29,7 @@
29 29
   #include "ubl.h"
30 30
 
31 31
   #include "../../../Marlin.h"
32
+  #include "../../../HAL/persistent_store_api.h"
32 33
   #include "../../../libs/hex_print_routines.h"
33 34
   #include "../../../module/configuration_store.h"
34 35
   #include "../../../lcd/ultralcd.h"
@@ -1167,24 +1168,27 @@
1167 1168
    * right now, it is good to have the extra information. Soon... we prune this.
1168 1169
    */
1169 1170
   void unified_bed_leveling::g29_eeprom_dump() {
1170
-    unsigned char cccc;
1171
-    unsigned int  kkkk;  // Needs to be of unspecfied size to compile clean on all platforms
1171
+    uint8_t cccc;
1172
+    int kkkk;
1173
+    uint16_t crc = 0;
1172 1174
 
1173 1175
     SERIAL_ECHO_START();
1174 1176
     SERIAL_ECHOLNPGM("EEPROM Dump:");
1177
+    persistentStore.access_start();
1175 1178
     for (uint16_t i = 0; i < persistentStore.capacity(); i += 16) {
1176 1179
       if (!(i & 0x3)) idle();
1177 1180
       print_hex_word(i);
1178 1181
       SERIAL_ECHOPGM(": ");
1179 1182
       for (uint16_t j = 0; j < 16; j++) {
1180 1183
         kkkk = i + j;
1181
-        eeprom_read_block(&cccc, (const void *)kkkk, sizeof(unsigned char));
1184
+        persistentStore.read_data(kkkk, &cccc, sizeof(uint8_t), &crc);
1182 1185
         print_hex_byte(cccc);
1183 1186
         SERIAL_ECHO(' ');
1184 1187
       }
1185 1188
       SERIAL_EOL();
1186 1189
     }
1187 1190
     SERIAL_EOL();
1191
+    persistentStore.access_finish();
1188 1192
   }
1189 1193
 
1190 1194
   /**

+ 24
- 8
Marlin/src/module/printcounter.cpp View File

@@ -31,6 +31,7 @@ Stopwatch print_job_timer;      // Global Print Job Timer instance
31 31
 
32 32
 #include "printcounter.h"
33 33
 #include "../Marlin.h"
34
+#include "../HAL/persistent_store_api.h"
34 35
 
35 36
 PrintCounter print_job_timer;   // Global Print Job Timer instance
36 37
 
@@ -73,7 +74,12 @@ void PrintCounter::initStats() {
73 74
   data = { 0, 0, 0, 0, 0.0 };
74 75
 
75 76
   saveStats();
76
-  eeprom_write_byte((uint8_t*)address, 0x16);
77
+  
78
+  uint16_t crc = 0;
79
+  int a = address;
80
+  persistentStore.access_start();
81
+  persistentStore.write_data(a, (uint8_t*)0x16, sizeof(uint8_t), &crc);
82
+  persistentStore.access_finish();
77 83
 }
78 84
 
79 85
 void PrintCounter::loadStats() {
@@ -81,11 +87,18 @@ void PrintCounter::loadStats() {
81 87
     debug(PSTR("loadStats"));
82 88
   #endif
83 89
 
84
-  // Checks if the EEPROM block is initialized
85
-  if (eeprom_read_byte((uint8_t*)address) != 0x16) initStats();
86
-  else eeprom_read_block(&data,
87
-    (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
88
-
90
+  // Check if the EEPROM block is initialized
91
+  uint16_t crc = 0;
92
+  int a = address;
93
+  uint8_t value;
94
+  persistentStore.access_start();
95
+  persistentStore.read_data(a, &value, sizeof(uint8_t), &crc);
96
+  if (value != 0x16) initStats();
97
+  else {
98
+    a = address + sizeof(uint8_t);
99
+    persistentStore.read_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
100
+  }
101
+  persistentStore.access_finish();
89 102
   loaded = true;
90 103
 }
91 104
 
@@ -98,8 +111,11 @@ void PrintCounter::saveStats() {
98 111
   if (!isLoaded()) return;
99 112
 
100 113
   // Saves the struct to EEPROM
101
-  eeprom_update_block(&data,
102
-    (void*)(address + sizeof(uint8_t)), sizeof(printStatistics));
114
+  uint16_t crc = 0;
115
+  int a = (address + sizeof(uint8_t));
116
+  persistentStore.access_start();
117
+  persistentStore.write_data(a, (uint8_t*)&data, sizeof(printStatistics), &crc);
118
+  persistentStore.access_finish();
103 119
 }
104 120
 
105 121
 void PrintCounter::showStats() {

Loading…
Cancel
Save