muele-marlin/Marlin/src/HAL/HAL_LPC1768/persistent_store_impl.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

#ifdef TARGET_LPC1768
2017-06-17 21:19:42 +00:00
2017-09-06 11:28:32 +00:00
#include "../../inc/MarlinConfig.h"
2017-06-17 21:19:42 +00:00
2017-09-06 11:28:32 +00:00
#if ENABLED(EEPROM_SETTINGS)
2017-06-17 21:19:42 +00:00
2017-09-06 11:28:32 +00:00
#include "../persistent_store_api.h"
2017-09-06 11:28:32 +00:00
#include "chanfs/diskio.h"
#include "chanfs/ff.h"
2017-06-17 21:19:42 +00:00
extern uint32_t MSC_Aquire_Lock();
extern uint32_t MSC_Release_Lock();
2017-06-17 21:19:42 +00:00
namespace HAL {
namespace PersistentStore {
FATFS fat_fs;
FIL eeprom_file;
bool access_start() {
MSC_Aquire_Lock();
if(f_mount(&fat_fs, "", 1)){
MSC_Release_Lock();
return false;
}
2017-06-17 21:19:42 +00:00
FRESULT res = f_open(&eeprom_file, "eeprom.dat", FA_OPEN_ALWAYS | FA_WRITE | FA_READ);
if(res) MSC_Release_Lock();
2017-06-17 21:19:42 +00:00
return (res == FR_OK);
}
2017-09-06 11:28:32 +00:00
bool access_finish() {
2017-06-17 21:19:42 +00:00
f_close(&eeprom_file);
f_unmount("");
MSC_Release_Lock();
2017-06-17 21:19:42 +00:00
return true;
}
bool write_data(int &pos, const uint8_t *value, uint16_t size, uint16_t *crc) {
UINT bytes_written = 0;
f_lseek(&eeprom_file, pos);
f_write(&eeprom_file, (void *)value, size, &bytes_written);
crc16(crc, value, size);
pos = pos + size;
return (bytes_written == size);
}
void read_data(int &pos, uint8_t* value, uint16_t size, uint16_t *crc) {
UINT bytes_read = 0;
f_lseek(&eeprom_file, pos);
f_read(&eeprom_file, (void *)value, size, &bytes_read);
crc16(crc, value, size);
pos = pos + size;
}
2017-09-06 11:28:32 +00:00
} // PersistentStore
} // HAL
2017-06-17 21:19:42 +00:00
#endif // EEPROM_SETTINGS
2017-09-06 11:28:32 +00:00
#endif // TARGET_LPC1768