|
@@ -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 TARGET_LPC1768
|
2
|
23
|
|
3
|
24
|
#include "../../inc/MarlinConfig.h"
|
|
@@ -19,8 +40,6 @@ FATFS fat_fs;
|
19
|
40
|
FIL eeprom_file;
|
20
|
41
|
|
21
|
42
|
bool access_start() {
|
22
|
|
- UINT file_size = 0,
|
23
|
|
- bytes_written = 0;
|
24
|
43
|
const char eeprom_erase_value = 0xFF;
|
25
|
44
|
MSC_Aquire_Lock();
|
26
|
45
|
if (f_mount(&fat_fs, "", 1)) {
|
|
@@ -30,9 +49,8 @@ bool access_start() {
|
30
|
49
|
FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
|
31
|
50
|
if (res) MSC_Release_Lock();
|
32
|
51
|
|
33
|
|
- if (res == FR_OK) file_size = f_size(&eeprom_file);
|
34
|
|
-
|
35
|
52
|
if (res == FR_OK) {
|
|
53
|
+ uint16_t bytes_written, file_size = f_size(&eeprom_file);
|
36
|
54
|
f_lseek(&eeprom_file, file_size);
|
37
|
55
|
while (file_size <= E2END && res == FR_OK) {
|
38
|
56
|
res = f_write(&eeprom_file, &eeprom_erase_value, 1, &bytes_written);
|
|
@@ -56,53 +74,52 @@ bool access_finish() {
|
56
|
74
|
// File function return codes for type FRESULT This goes away soon. But it is helpful right now to see
|
57
|
75
|
// the different errors the read_data() and write_data() functions are seeing.
|
58
|
76
|
//
|
59
|
|
-//typedef enum {
|
60
|
|
-// FR_OK = 0, /* (0) Succeeded */
|
61
|
|
-// FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
62
|
|
-// FR_INT_ERR, /* (2) Assertion failed */
|
63
|
|
-// FR_NOT_READY, /* (3) The physical drive cannot work */
|
64
|
|
-// FR_NO_FILE, /* (4) Could not find the file */
|
65
|
|
-// FR_NO_PATH, /* (5) Could not find the path */
|
66
|
|
-// FR_INVALID_NAME, /* (6) The path name format is invalid */
|
67
|
|
-// FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
68
|
|
-// FR_EXIST, /* (8) Access denied due to prohibited access */
|
69
|
|
-// FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
70
|
|
-// FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
71
|
|
-// FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
72
|
|
-// FR_NOT_ENABLED, /* (12) The volume has no work area */
|
73
|
|
-// FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
74
|
|
-// FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
75
|
|
-// FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
76
|
|
-// FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
77
|
|
-// FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
78
|
|
-// FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
79
|
|
-// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
80
|
|
-//} FRESULT;
|
|
77
|
+// typedef enum {
|
|
78
|
+// FR_OK = 0, /* (0) Succeeded */
|
|
79
|
+// FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
|
|
80
|
+// FR_INT_ERR, /* (2) Assertion failed */
|
|
81
|
+// FR_NOT_READY, /* (3) The physical drive cannot work */
|
|
82
|
+// FR_NO_FILE, /* (4) Could not find the file */
|
|
83
|
+// FR_NO_PATH, /* (5) Could not find the path */
|
|
84
|
+// FR_INVALID_NAME, /* (6) The path name format is invalid */
|
|
85
|
+// FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
|
|
86
|
+// FR_EXIST, /* (8) Access denied due to prohibited access */
|
|
87
|
+// FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
|
|
88
|
+// FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
|
|
89
|
+// FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
|
|
90
|
+// FR_NOT_ENABLED, /* (12) The volume has no work area */
|
|
91
|
+// FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
|
|
92
|
+// FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */
|
|
93
|
+// FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
|
|
94
|
+// FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
|
|
95
|
+// FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
|
|
96
|
+// FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */
|
|
97
|
+// FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
|
|
98
|
+// } FRESULT;
|
81
|
99
|
|
82
|
100
|
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
83
|
101
|
FRESULT s;
|
84
|
|
- UINT bytes_written = 0;
|
|
102
|
+ uint16_t bytes_written = 0;
|
|
103
|
+
|
85
|
104
|
s = f_lseek(&eeprom_file, pos);
|
86
|
|
- if ( s ) {
|
|
105
|
+ if (s) {
|
87
|
106
|
SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
88
|
|
- SERIAL_PROTOCOLPAIR(",", (int) value); // right now to see errors that are happening in the
|
89
|
|
- SERIAL_PROTOCOLPAIR(",", (int) size); // read_data() and write_data() functions
|
|
107
|
+ SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
108
|
+ SERIAL_PROTOCOLPAIR(",", (int)size); // read_data() and write_data() functions
|
90
|
109
|
SERIAL_PROTOCOL("...)\n");
|
91
|
|
- SERIAL_PROTOCOLPAIR(" f_lseek()=", (int) s);
|
92
|
|
- SERIAL_PROTOCOL("\n");
|
|
110
|
+ SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
93
|
111
|
return s;
|
94
|
112
|
}
|
|
113
|
+
|
95
|
114
|
s = f_write(&eeprom_file, (void *)value, size, &bytes_written);
|
96
|
|
- if ( s ) {
|
|
115
|
+ if (s) {
|
97
|
116
|
SERIAL_PROTOCOLPAIR(" write_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
98
|
|
- SERIAL_PROTOCOLPAIR(",", (int) value); // right now to see errors that are happening in the
|
99
|
|
- SERIAL_PROTOCOLPAIR(",", (int) size); // read_data() and write_data() functions
|
100
|
|
- SERIAL_PROTOCOL("...)\n");
|
101
|
|
- SERIAL_PROTOCOLPAIR(" f_write()=", (int) s);
|
102
|
|
- SERIAL_PROTOCOL("\n");
|
103
|
|
- SERIAL_PROTOCOLPAIR(" size=", (int) size);
|
104
|
|
- SERIAL_PROTOCOLPAIR("\n bytes_written=", (int) bytes_written);
|
105
|
|
- SERIAL_PROTOCOL("\n");
|
|
117
|
+ SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
118
|
+ SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
|
119
|
+ SERIAL_PROTOCOLLN("...)");
|
|
120
|
+ SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
|
|
121
|
+ SERIAL_PROTOCOLPAIR(" size=", size);
|
|
122
|
+ SERIAL_PROTOCOLLNPAIR("\n bytes_written=", bytes_written);
|
106
|
123
|
return s;
|
107
|
124
|
}
|
108
|
125
|
crc16(crc, value, size);
|
|
@@ -111,29 +128,26 @@ bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
|
111
|
128
|
}
|
112
|
129
|
|
113
|
130
|
bool read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
|
114
|
|
- UINT bytes_read = 0;
|
|
131
|
+ uint16_t bytes_read = 0;
|
115
|
132
|
FRESULT s;
|
116
|
133
|
s = f_lseek(&eeprom_file, pos);
|
117
|
134
|
if ( s ) {
|
118
|
135
|
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
119
|
|
- SERIAL_PROTOCOLPAIR(",", (int) value); // right now to see errors that are happening in the
|
120
|
|
- SERIAL_PROTOCOLPAIR(",", (int) size); // read_data() and write_data() functions
|
121
|
|
- SERIAL_PROTOCOL("...)\n");
|
122
|
|
- SERIAL_PROTOCOLPAIR(" f_lseek()=", (int) s);
|
123
|
|
- SERIAL_PROTOCOL("\n");
|
|
136
|
+ SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
137
|
+ SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
|
138
|
+ SERIAL_PROTOCOLLN("...)");
|
|
139
|
+ SERIAL_PROTOCOLLNPAIR(" f_lseek()=", (int)s);
|
124
|
140
|
return true;
|
125
|
141
|
}
|
126
|
142
|
s = f_read(&eeprom_file, (void *)value, size, &bytes_read);
|
127
|
|
- if ( s ) {
|
|
143
|
+ if (s) {
|
128
|
144
|
SERIAL_PROTOCOLPAIR(" read_data(", pos); // This extra chit-chat goes away soon. But it is helpful
|
129
|
|
- SERIAL_PROTOCOLPAIR(",", (int) value); // right now to see errors that are happening in the
|
130
|
|
- SERIAL_PROTOCOLPAIR(",", (int) size); // read_data() and write_data() functions
|
131
|
|
- SERIAL_PROTOCOL("...)\n");
|
132
|
|
- SERIAL_PROTOCOLPAIR(" f_write()=", (int) s);
|
133
|
|
- SERIAL_PROTOCOL("\n");
|
134
|
|
- SERIAL_PROTOCOLPAIR(" size=", (int) size);
|
135
|
|
- SERIAL_PROTOCOLPAIR("\n bytes_read=", (int) bytes_read);
|
136
|
|
- SERIAL_PROTOCOL("\n");
|
|
145
|
+ SERIAL_PROTOCOLPAIR(",", (int)value); // right now to see errors that are happening in the
|
|
146
|
+ SERIAL_PROTOCOLPAIR(",", size); // read_data() and write_data() functions
|
|
147
|
+ SERIAL_PROTOCOLLN("...)");
|
|
148
|
+ SERIAL_PROTOCOLLNPAIR(" f_write()=", (int)s);
|
|
149
|
+ SERIAL_PROTOCOLPAIR(" size=", size);
|
|
150
|
+ SERIAL_PROTOCOLLNPAIR("\n bytes_read=", bytes_read);
|
137
|
151
|
return true;
|
138
|
152
|
}
|
139
|
153
|
crc16(crc, value, size);
|