Pārlūkot izejas kodu

Followup persistent store with heading, const

Scott Lahteine 6 gadus atpakaļ
vecāks
revīzija
865ee5985f

+ 22
- 15
Marlin/src/HAL/HAL_AVR/persistent_store_eeprom.cpp Parādīt failu

@@ -1,3 +1,24 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016, 2017 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
+ */
1 22
 #ifdef __AVR__
2 23
 
3 24
 #include "../../inc/MarlinConfig.h"
@@ -41,21 +62,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
41 62
   return false;  // always assume success for AVR's
42 63
 }
43 64
 
44
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
45
-  int data_pos = pos;
46
-  uint16_t crc = 0;
47
-  return write_data(data_pos, value, size, &crc);
48
-}
49
-
50
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
51
-  int data_pos = pos;
52
-  uint16_t crc = 0;
53
-  return read_data(data_pos, value, size, &crc);
54
-}
55
-
56
-const size_t PersistentStore::capacity() {
57
-  return E2END + 1;
58
-}
65
+const size_t PersistentStore::capacity() { return E2END + 1; }
59 66
 
60 67
 #endif // EEPROM_SETTINGS
61 68
 #endif // __AVR__

+ 23
- 15
Marlin/src/HAL/HAL_DUE/persistent_store_eeprom.cpp Parādīt failu

@@ -1,3 +1,25 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
1 23
 #ifdef ARDUINO_ARCH_SAM
2 24
 
3 25
 #include "../persistent_store_api.h"
@@ -49,21 +71,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
49 71
   return false;
50 72
 }
51 73
 
52
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
53
-  int data_pos = pos;
54
-  uint16_t crc = 0;
55
-  return write_data(data_pos, value, size, &crc);
56
-}
57
-
58
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
59
-  int data_pos = pos;
60
-  uint16_t crc = 0;
61
-  return read_data(data_pos, value, size, &crc);
62
-}
63
-
64
-const size_t PersistentStore::capacity() {
65
-  return E2END + 1;
66
-}
74
+const size_t PersistentStore::capacity() { return E2END + 1; }
67 75
 
68 76
 #endif // EEPROM_SETTINGS
69 77
 #endif // ARDUINO_ARCH_SAM

+ 25
- 30
Marlin/src/HAL/HAL_LPC1768/persistent_store_sdcard.cpp Parādīt failu

@@ -1,9 +1,10 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 3
  *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
7 8
  *
8 9
  * This program is free software: you can redistribute it and/or modify
9 10
  * it under the terms of the GNU General Public License as published by
@@ -98,8 +99,8 @@ bool PersistentStore::access_finish() {
98 99
 //    FR_INVALID_PARAMETER     /* (19) Given parameter is invalid */
99 100
 //  } FRESULT;
100 101
 
101
-bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
102
-  if(!eeprom_file_open) return true;
102
+bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
103
+  if (!eeprom_file_open) return true;
103 104
   FRESULT s;
104 105
   UINT bytes_written = 0;
105 106
 
@@ -113,7 +114,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
113 114
    return s;
114 115
   }
115 116
 
116
-  s = f_write(&eeprom_file, (void *)value, size, &bytes_written);
117
+  s = f_write(&eeprom_file, (void*)value, size, &bytes_written);
117 118
   if (s) {
118 119
    SERIAL_PROTOCOLPAIR(" write_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
119 120
    SERIAL_PROTOCOLPAIR(",", (int)value);            // right now to see errors that are happening in the
@@ -129,57 +130,51 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
129 130
   return (bytes_written != size);  // return true for any error
130 131
 }
131 132
 
132
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
133
-  if(!eeprom_file_open) return true;
133
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
134
+  if (!eeprom_file_open) return true;
134 135
   UINT bytes_read = 0;
135 136
   FRESULT s;
136 137
   s = f_lseek(&eeprom_file, pos);
138
+
137 139
   if (s) {
138
-   SERIAL_PROTOCOLPAIR(" read_data(", pos);          // This extra chit-chat goes away soon.  But it is helpful
139
-   SERIAL_PROTOCOLPAIR(",", (int)value);            // right now to see errors that are happening in the
140
-   SERIAL_PROTOCOLPAIR(",", size);             // read_data() and write_data() functions
140
+   SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
141
+   SERIAL_PROTOCOLCHAR(',');
142
+   SERIAL_PROTOCOL((int)value);                     // right now to see errors that are happening in the
143
+   SERIAL_PROTOCOLCHAR(',');
144
+   SERIAL_PROTOCOL(size);                           // read_data() and write_data() functions
141 145
    SERIAL_PROTOCOLLNPGM("...)");
142 146
    SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
143 147
    return true;
144 148
   }
149
+
145 150
   if (writing) {
146
-    s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
151
+    s = f_read(&eeprom_file, (void*)value, size, &bytes_read);
147 152
     crc16(crc, value, size);
148 153
   }
149 154
   else {
150 155
     uint8_t temp[size];
151
-    s = f_read(&eeprom_file, (void *)temp, size, &bytes_read);
156
+    s = f_read(&eeprom_file, (void*)temp, size, &bytes_read);
152 157
     crc16(crc, temp, size);
153 158
   }
159
+
154 160
   if (s) {
155 161
    SERIAL_PROTOCOLPAIR(" read_data(", pos);         // This extra chit-chat goes away soon.  But it is helpful
156
-   SERIAL_PROTOCOLPAIR(",", (int)value);           // right now to see errors that are happening in the
157
-   SERIAL_PROTOCOLPAIR(",", size);            // read_data() and write_data() functions
162
+   SERIAL_PROTOCOLCHAR(',');
163
+   SERIAL_PROTOCOL((int)value);                     // right now to see errors that are happening in the
164
+   SERIAL_PROTOCOLCHAR(',');
165
+   SERIAL_PROTOCOL(size);                           // read_data() and write_data() functions
158 166
    SERIAL_PROTOCOLLNPGM("...)");
159 167
    SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
160 168
    SERIAL_PROTOCOLPAIR(" size=", size);
161 169
    SERIAL_PROTOCOLLNPAIR("\n bytes_read=",  bytes_read);
162 170
    return true;
163 171
   }
172
+
164 173
   pos = pos + size;
165 174
   return bytes_read != size;  // return true for any error
166 175
 }
167 176
 
168
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
169
-  int data_pos = pos;
170
-  uint16_t crc = 0;
171
-  return write_data(data_pos, value, size, &crc);
172
-}
173
-
174
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
175
-  int data_pos = pos;
176
-  uint16_t crc = 0;
177
-  return read_data(data_pos, value, size, &crc);
178
-}
179
-
180
-const size_t PersistentStore::capacity() {
181
-  return 4096; //4KiB of Emulated EEPROM
182
-}
177
+const size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
183 178
 
184 179
 #endif // EEPROM_SETTINGS
185 180
 #endif // TARGET_LPC1768

+ 3
- 18
Marlin/src/HAL/HAL_STM32F1/persistent_store_flash.cpp Parādīt failu

@@ -55,7 +55,7 @@ bool PersistentStore::access_finish() {
55 55
   return true;
56 56
 }
57 57
 
58
-bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
58
+bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
59 59
   FLASH_Status status;
60 60
 
61 61
   if (firstWrite) {
@@ -90,7 +90,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
90 90
   return false;
91 91
 }
92 92
 
93
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
93
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
94 94
   for (uint16_t i = 0; i < size; i++) {
95 95
     byte* accessPoint = (byte*)(pageBase + pos + i);
96 96
     uint8_t c = *accessPoint;
@@ -101,22 +101,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
101 101
   return false;
102 102
 }
103 103
 
104
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
105
-  int data_pos = pos;
106
-  uint16_t crc = 0;
107
-  return write_data(data_pos, value, size, &crc);
108
-}
109
-
110
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
111
-  int data_pos = pos;
112
-  uint16_t crc = 0;
113
-  return read_data(data_pos, value, size, &crc);
114
-}
115
-
116
-const size_t PersistentStore::capacity() {
117
-  return E2END + 1;
118
-}
119
-
104
+const size_t PersistentStore::capacity() { return E2END + 1; }
120 105
 
121 106
 #endif // EEPROM_SETTINGS && EEPROM FLASH
122 107
 #endif // __STM32F1__

+ 3
- 17
Marlin/src/HAL/HAL_STM32F1/persistent_store_sdcard.cpp Parādīt failu

@@ -60,7 +60,7 @@ bool PersistentStore::access_finish() {
60 60
   return (bytes_written == HAL_STM32F1_EEPROM_SIZE);
61 61
 }
62 62
 
63
-bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc) {
63
+bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t size, uint16_t *crc) {
64 64
   for (int i = 0; i < size; i++)
65 65
     HAL_STM32F1_eeprom_content[pos + i] = value[i];
66 66
   crc16(crc, value, size);
@@ -68,7 +68,7 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, size_t size, ui
68 68
   return false;
69 69
 }
70 70
 
71
-bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing/*=true*/) {
71
+bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
72 72
   for (int i = 0; i < size; i++) {
73 73
     uint8_t c = HAL_STM32F1_eeprom_content[pos + i];
74 74
     if (writing) value[i] = c;
@@ -78,21 +78,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
78 78
   return false;
79 79
 }
80 80
 
81
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
82
-  int data_pos = pos;
83
-  uint16_t crc = 0;
84
-  return write_data(data_pos, value, size, &crc);
85
-}
86
-
87
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
88
-  int data_pos = pos;
89
-  uint16_t crc = 0;
90
-  return read_data(data_pos, value, size, &crc);
91
-}
92
-
93
-const size_t PersistentStore::capacity() {
94
-  return HAL_STM32F1_EEPROM_SIZE;
95
-}
81
+const size_t PersistentStore::capacity() { return HAL_STM32F1_EEPROM_SIZE; }
96 82
 
97 83
 #endif // EEPROM_SETTINGS
98 84
 

+ 1
- 15
Marlin/src/HAL/HAL_STM32F4/persistent_store_eeprom.cpp Parādīt failu

@@ -64,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
64 64
   return false;
65 65
 }
66 66
 
67
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
68
-  int data_pos = pos;
69
-  uint16_t crc = 0;
70
-  return write_data(data_pos, value, size, &crc);
71
-}
72
-
73
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
74
-  int data_pos = pos;
75
-  uint16_t crc = 0;
76
-  return read_data(data_pos, value, size, &crc);
77
-}
78
-
79
-const size_t PersistentStore::capacity() {
80
-  return E2END + 1;
81
-}
67
+const size_t PersistentStore::capacity() { return E2END + 1; }
82 68
 
83 69
 #endif // EEPROM_SETTINGS
84 70
 #endif // STM32F4 || STM32F4xx

+ 1
- 16
Marlin/src/HAL/HAL_STM32F7/persistent_store_eeprom.cpp Parādīt failu

@@ -21,7 +21,6 @@
21 21
  *
22 22
  */
23 23
 
24
-
25 24
 #ifdef STM32F7
26 25
 
27 26
 #include "../../inc/MarlinConfig.h"
@@ -65,21 +64,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
65 64
   return false;
66 65
 }
67 66
 
68
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
69
-  int data_pos = pos;
70
-  uint16_t crc = 0;
71
-  return write_data(data_pos, value, size, &crc);
72
-}
73
-
74
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
75
-  int data_pos = pos;
76
-  uint16_t crc = 0;
77
-  return read_data(data_pos, value, size, &crc);
78
-}
79
-
80
-const size_t PersistentStore::capacity() {
81
-  return E2END + 1;
82
-}
67
+const size_t PersistentStore::capacity() { return E2END + 1; }
83 68
 
84 69
 #endif // EEPROM_SETTINGS
85 70
 #endif // STM32F7

+ 24
- 15
Marlin/src/HAL/HAL_TEENSY35_36/persistent_store_eeprom.cpp Parādīt failu

@@ -1,3 +1,26 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ *
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
8
+ *
9
+ * This program is free software: you can redistribute it and/or modify
10
+ * it under the terms of the GNU General Public License as published by
11
+ * the Free Software Foundation, either version 3 of the License, or
12
+ * (at your option) any later version.
13
+ *
14
+ * This program is distributed in the hope that it will be useful,
15
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+ * GNU General Public License for more details.
18
+ *
19
+ * You should have received a copy of the GNU General Public License
20
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
+ *
22
+ */
23
+
1 24
 #if defined(__MK64FX512__) || defined(__MK66FX1M0__)
2 25
 
3 26
 #include "../../inc/MarlinConfig.h"
@@ -42,21 +65,7 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, size_t size, uint16_t
42 65
   return false;
43 66
 }
44 67
 
45
-bool PersistentStore::write_data(const int pos, uint8_t* value, size_t size) {
46
-  int data_pos = pos;
47
-  uint16_t crc = 0;
48
-  return write_data(data_pos, value, size, &crc);
49
-}
50
-
51
-bool PersistentStore::read_data(const int pos, uint8_t* value, size_t size) {
52
-  int data_pos = pos;
53
-  uint16_t crc = 0;
54
-  return read_data(data_pos, value, size, &crc);
55
-}
56
-
57
-const size_t PersistentStore::capacity() {
58
-  return E2END + 1;
59
-}
68
+const size_t PersistentStore::capacity() { return E2END + 1; }
60 69
 
61 70
 #endif // EEPROM_SETTINGS
62 71
 #endif // __MK64FX512__ || __MK66FX1M0__

+ 4
- 3
Marlin/src/HAL/persistent_store_api.cpp Parādīt failu

@@ -1,9 +1,10 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 3
  *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
7 8
  *
8 9
  * This program is free software: you can redistribute it and/or modify
9 10
  * it under the terms of the GNU General Public License as published by

+ 16
- 5
Marlin/src/HAL/persistent_store_api.h Parādīt failu

@@ -1,9 +1,10 @@
1 1
 /**
2 2
  * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4 3
  *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
4
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
5
+ * Copyright (c) 2016 Bob Cousins bobcousins42@googlemail.com
6
+ * Copyright (c) 2015-2016 Nico Tonnhofer wurstnase.reprap@gmail.com
7
+ * Copyright (c) 2016 Victor Perez victor_pv@hotmail.com
7 8
  *
8 9
  * This program is free software: you can redistribute it and/or modify
9 10
  * it under the terms of the GNU General Public License as published by
@@ -30,9 +31,19 @@ public:
30 31
   static bool access_finish();
31 32
   static bool write_data(int &pos, const uint8_t *value, size_t size, uint16_t *crc);
32 33
   static bool read_data(int &pos, uint8_t* value, size_t size, uint16_t *crc, const bool writing=true);
33
-  static bool write_data(const int pos, uint8_t* value, size_t size);
34
-  static bool read_data(const int pos, uint8_t* value, size_t size);
35 34
   static const size_t capacity();
35
+
36
+  static inline bool write_data(const int pos, uint8_t* value, const size_t size) {
37
+    int data_pos = pos;
38
+    uint16_t crc = 0;
39
+    return write_data(data_pos, value, size, &crc);
40
+  }
41
+
42
+  static inline bool read_data(const int pos, uint8_t* value, const size_t size) {
43
+    int data_pos = pos;
44
+    uint16_t crc = 0;
45
+    return read_data(data_pos, value, size, &crc);
46
+  }
36 47
 };
37 48
 
38 49
 extern PersistentStore persistentStore;

Notiek ielāde…
Atcelt
Saglabāt