|
@@ -19,14 +19,31 @@ FATFS fat_fs;
|
19
|
19
|
FIL eeprom_file;
|
20
|
20
|
|
21
|
21
|
bool access_start() {
|
|
22
|
+ UINT file_size = 0,
|
|
23
|
+ bytes_written = 0;
|
|
24
|
+ const char eeprom_zero = 0xFF;
|
22
|
25
|
MSC_Aquire_Lock();
|
23
|
|
- if(f_mount(&fat_fs, "", 1)){
|
|
26
|
+ if (f_mount(&fat_fs, "", 1)) {
|
24
|
27
|
MSC_Release_Lock();
|
25
|
28
|
return false;
|
26
|
29
|
}
|
27
|
30
|
FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
|
28
|
|
- if(res) MSC_Release_Lock();
|
29
|
|
- return (res == FR_OK);
|
|
31
|
+ if (res) MSC_Release_Lock();
|
|
32
|
+
|
|
33
|
+ if (res == FR_OK) file_size = f_size(&eeprom_file);
|
|
34
|
+
|
|
35
|
+ if (res == FR_OK) {
|
|
36
|
+ f_lseek(&eeprom_file, file_size);
|
|
37
|
+ while (file_size < E2END && res == FR_OK) {
|
|
38
|
+ res = f_write(&eeprom_file, &eeprom_zero, 1, &bytes_written);
|
|
39
|
+ file_size++;
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+ if (res == FR_OK) {
|
|
43
|
+ f_lseek(&eeprom_file, 0);
|
|
44
|
+ f_sync(&eeprom_file);
|
|
45
|
+ }
|
|
46
|
+ return res == FR_OK;
|
30
|
47
|
}
|
31
|
48
|
|
32
|
49
|
bool access_finish() {
|