Browse Source

Merge pull request #11526 from hasenbanck/eeprom-cleanup

[2.0.x] Change direct eeprom access to HAL::PersistentStore
Scott Lahteine 6 years ago
parent
commit
cc0a60453f
No account linked to committer's email address

+ 29
- 0
Marlin/src/HAL/persistent_store_api.cpp View File

@@ -0,0 +1,29 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#include "../inc/MarlinConfigPre.h"
23
+
24
+#if ENABLED(EEPROM_SETTINGS)
25
+
26
+  #include "persistent_store_api.h"
27
+  PersistentStore persistentStore;
28
+
29
+#endif

+ 22
- 4
Marlin/src/HAL/persistent_store_api.h View File

@@ -1,5 +1,25 @@
1
-#ifndef _PERSISTENT_STORE_H_
2
-#define _PERSISTENT_STORE_H_
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+#pragma once
3 23
 
4 24
 #include <stddef.h>
5 25
 #include <stdint.h>
@@ -16,5 +36,3 @@ public:
16 36
 };
17 37
 
18 38
 extern PersistentStore persistentStore;
19
-
20
-#endif // _PERSISTENT_STORE_H_

+ 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
   /**

+ 0
- 1
Marlin/src/module/configuration_store.cpp View File

@@ -345,7 +345,6 @@ void MarlinSettings::postprocess() {
345 345
 
346 346
 #if ENABLED(EEPROM_SETTINGS)
347 347
   #include "../HAL/persistent_store_api.h"
348
-  PersistentStore persistentStore;
349 348
 
350 349
   #define DUMMY_PID_VALUE 3000.0f
351 350
   #define EEPROM_START() int eeprom_index = EEPROM_OFFSET; persistentStore.access_start()

+ 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