|
@@ -22,11 +22,13 @@
|
22
|
22
|
*/
|
23
|
23
|
#ifdef TARGET_LPC1768
|
24
|
24
|
|
25
|
|
-#include "../../inc/MarlinConfig.h"
|
|
25
|
+#include "../../inc/MarlinConfigPre.h"
|
26
|
26
|
|
27
|
27
|
#if ENABLED(EEPROM_SETTINGS)
|
28
|
28
|
|
29
|
|
-#include "../persistent_store_api.h"
|
|
29
|
+#include "persistent_store_api.h"
|
|
30
|
+
|
|
31
|
+#if DISABLED(FLASH_EEPROM)
|
30
|
32
|
|
31
|
33
|
#include <chanfs/diskio.h>
|
32
|
34
|
#include <chanfs/ff.h>
|
|
@@ -73,8 +75,31 @@ bool PersistentStore::access_finish() {
|
73
|
75
|
return true;
|
74
|
76
|
}
|
75
|
77
|
|
76
|
|
-// File function return codes for type FRESULT This goes away soon. But it is helpful right now to see
|
77
|
|
-// the different errors the read_data() and write_data() functions are seeing.
|
|
78
|
+// This extra chit-chat goes away soon, but is helpful for now
|
|
79
|
+// to see errors that are happening in read_data / write_data
|
|
80
|
+static void debug_rw(const bool write, int &pos, const uint8_t *value, const size_t size, const FRESULT s, const size_t total=0) {
|
|
81
|
+ const char * const rw_str = write ? PSTR("write") : PSTR("read");
|
|
82
|
+ SERIAL_PROTOCOLCHAR(' ');
|
|
83
|
+ serialprint_PGM(rw_str);
|
|
84
|
+ SERIAL_PROTOCOLPAIR("_data(", pos);
|
|
85
|
+ SERIAL_PROTOCOLPAIR(",", (int)value);
|
|
86
|
+ SERIAL_PROTOCOLPAIR(",", (int)size);
|
|
87
|
+ SERIAL_PROTOCOLLNPGM(", ...)");
|
|
88
|
+ if (total) {
|
|
89
|
+ SERIAL_PROTOCOLPGM(" f_");
|
|
90
|
+ serialprint_PGM(rw_str);
|
|
91
|
+ SERIAL_PROTOCOLPAIR("()=", (int)s);
|
|
92
|
+ SERIAL_PROTOCOLPAIR("\n size=", size);
|
|
93
|
+ SERIAL_PROTOCOLPGM("\n bytes_");
|
|
94
|
+ serialprint_PGM(write ? PSTR("written=") : PSTR("read="));
|
|
95
|
+ SERIAL_PROTOCOLLN(total);
|
|
96
|
+ }
|
|
97
|
+ else
|
|
98
|
+ SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
|
99
|
+}
|
|
100
|
+
|
|
101
|
+// File function return codes for type FRESULT. This goes away soon, but
|
|
102
|
+// is helpful right now to see any errors in read_data and write_data.
|
78
|
103
|
//
|
79
|
104
|
// typedef enum {
|
80
|
105
|
// FR_OK = 0, /* (0) Succeeded */
|
|
@@ -106,28 +131,18 @@ bool PersistentStore::write_data(int &pos, const uint8_t *value, const size_t si
|
106
|
131
|
|
107
|
132
|
s = f_lseek(&eeprom_file, pos);
|
108
|
133
|
if (s) {
|
109
|
|
- SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
110
|
|
- SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
111
|
|
- SERIAL_PROTOCOLPAIR(",", (int)size); // read_data() and write_data() functions
|
112
|
|
- SERIAL_PROTOCOLLNPGM("...)");
|
113
|
|
- SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
114
|
|
- return s;
|
|
134
|
+ debug_rw(true, pos, value, size, s);
|
|
135
|
+ return s;
|
115
|
136
|
}
|
116
|
137
|
|
117
|
138
|
s = f_write(&eeprom_file, (void*)value, size, &bytes_written);
|
118
|
139
|
if (s) {
|
119
|
|
- SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
120
|
|
- SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
121
|
|
- SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
122
|
|
- SERIAL_PROTOCOLLNPGM("...)");
|
123
|
|
- SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
|
124
|
|
- SERIAL_PROTOCOLPAIR(" size=", size);
|
125
|
|
- SERIAL_PROTOCOLLNPAIR("\n bytes_written=", bytes_written);
|
126
|
|
- return s;
|
|
140
|
+ debug_rw(true, pos, value, size, s, bytes_written);
|
|
141
|
+ return s;
|
127
|
142
|
}
|
128
|
143
|
crc16(crc, value, size);
|
129
|
|
- pos = pos + size;
|
130
|
|
- return (bytes_written != size); // return true for any error
|
|
144
|
+ pos += size;
|
|
145
|
+ return bytes_written != size; // return true for any error
|
131
|
146
|
}
|
132
|
147
|
|
133
|
148
|
bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uint16_t *crc, const bool writing/*=true*/) {
|
|
@@ -137,14 +152,8 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
|
137
|
152
|
s = f_lseek(&eeprom_file, pos);
|
138
|
153
|
|
139
|
154
|
if (s) {
|
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
|
145
|
|
- SERIAL_PROTOCOLLNPGM("...)");
|
146
|
|
- SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
147
|
|
- return true;
|
|
155
|
+ debug_rw(false, pos, value, size, s);
|
|
156
|
+ return true;
|
148
|
157
|
}
|
149
|
158
|
|
150
|
159
|
if (writing) {
|
|
@@ -158,23 +167,16 @@ bool PersistentStore::read_data(int &pos, uint8_t* value, const size_t size, uin
|
158
|
167
|
}
|
159
|
168
|
|
160
|
169
|
if (s) {
|
161
|
|
- SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
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
|
166
|
|
- SERIAL_PROTOCOLLNPGM("...)");
|
167
|
|
- SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
|
168
|
|
- SERIAL_PROTOCOLPAIR(" size=", size);
|
169
|
|
- SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read);
|
170
|
|
- return true;
|
|
170
|
+ debug_rw(false, pos, value, size, s, bytes_read);
|
|
171
|
+ return true;
|
171
|
172
|
}
|
172
|
173
|
|
173
|
|
- pos = pos + size;
|
|
174
|
+ pos += size;
|
174
|
175
|
return bytes_read != size; // return true for any error
|
175
|
176
|
}
|
176
|
177
|
|
177
|
178
|
const size_t PersistentStore::capacity() { return 4096; } // 4KiB of Emulated EEPROM
|
178
|
179
|
|
|
180
|
+#endif // !FLASH_EEPROM
|
179
|
181
|
#endif // EEPROM_SETTINGS
|
180
|
182
|
#endif // TARGET_LPC1768
|