Re: store calibration values
Posted: Wed Sep 26, 2012 10:37 am
You can modify the memory requirements completely. (I guess there is a minimum)
It can even use static memory, no heap.
It can even use static memory, no heap.
ChibiOS Web Boards
https://forum.chibios.org/
Giovanni wrote:The idea is to create an abstract interface for file system, Mabl's wrapper could (and probably will if Mabl agrees) be used as part of the implementation.
Code: Select all
void lld_tpWriteCalibration(struct cal cal) {
FRESULT ferr;
FIL fi;
UINT wr;
ferr = f_open(&fi, "calibration", FA_CREATE_ALWAYS | FA_WRITE);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't open file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
ferr = f_write(&fi, &cal, sizeof(struct cal), &wr);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't write file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
ferr = f_close(&fi);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpWriteCalibration(): could't close file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
return;
#endif
}
}
struct cal lld_tpReadCalibration(void) {
FRESULT ferr;
FIL fi;
UINT br;
uint8_t i;
struct cal cal = { 1, 1, 0, 0 };
ferr = f_open(&fi, "calibration", FA_READ);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't open file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
ferr = f_read(&fi, &cal, sizeof(struct cal), &br);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't read file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
ferr = f_close(&fi);
if(ferr != FR_OK) {
#if DEBUG
chprintf(DEBUG_SERIAL, "lld_tpReadCalibration(): couldn't close file!\r\n");
chprintf(DEBUG_SERIAL, "return code: %d\r\n", ferr);
#endif
return cal;
}
#if DEBUG
if(cal.xm != 1 && cal.ym != 1 && cal.xn != 0 && cal.yn != 0) // check if default or different values
chprintf(DEBUG_SERIAL, "calibration restored from SD card\r\n");
#endif
return cal;
}
Code: Select all
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
ferr = wf_open(&fi, "calib", FA_READ);
if(ferr != FR_OK) {
cal = NULL;
return cal;
}
Code: Select all
cal = (struct cal_t*)chHeapAlloc(NULL, sizeof(struct cal_t));
ferr = wf_open(&fi, "calib", FA_READ);
if(ferr != FR_OK) {
chHeapFree(cal);
return NULL;
}