rec to sd card

This commit is contained in:
matt
2020-10-31 11:35:38 +08:00
parent 9e90482753
commit c48b4d80cc
+10 -39
View File
@@ -13,7 +13,6 @@
#ifdef HAL_IMPL #ifdef HAL_IMPL
#include "uart_fifos.h" #include "uart_fifos.h"
#include "param_pre.h" #include "param_pre.h"
#include "fatfs.h"
#endif #endif
/* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */ /* %%%-SFUNWIZ_wrapper_includes_Changes_END --- EDIT HERE TO _BEGIN */
#define y_width 1 #define y_width 1
@@ -23,53 +22,25 @@
* *
*/ */
/* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */ /* %%%-SFUNWIZ_wrapper_externs_Changes_BEGIN --- EDIT HERE TO _END */
int is_fat_rec_init = 0; #define REC_ZONE_LEN (2000)
FIL *rec_pf; extern uint8_t rec_zone[2][REC_ZONE_LEN];
extern int rec_sel;
extern int rec_head[2];
static int FAT_REC_write(uint8_t *buff, const uint16_t len) static int FAT_REC_write(uint8_t *buff, const uint16_t len)
{ {
int rslt; if (rec_head[rec_sel] < REC_ZONE_LEN)
FRESULT res;
if (is_fat_rec_init == 1)
{ {
UINT bw; for (int i=0u;i<len;++i)
res = f_write(rec_pf, buff, len, &bw);
f_sync(rec_pf);
if (res != FR_OK)
{ {
rslt = -1; rec_zone[rec_sel][rec_head[rec_sel]++] = buff[i];
} if (rec_head[rec_sel] >= REC_ZONE_LEN)
else
{ {
rslt = 0; break;
} }
} }
else if (is_fat_rec_init == 0 && ap_U.sens.gps_fixtype >= ENUM_GPS_FIXTYPE_FIX_2D)
{
res = f_mount(&SDFatFS, SDPath, 1);
if (res != FR_OK)
{
is_fat_rec_init = -1;
rslt = -1;
} }
rec_pf = &SDFile; return 0;
long path_len;
char path[80];
strncpy(path, SDPath, 3);
sprintf(&path[3], "R%d.dat", (ap_U.sens.TOW / 1000));
res = f_open(rec_pf, path, FA_OPEN_ALWAYS | FA_WRITE);
if (res == FR_OK)
{
is_fat_rec_init = 1;
rslt = 0;
}
else
{
is_fat_rec_init = -1;
rslt = -1;
}
}
return rslt;
} }
/* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */ /* %%%-SFUNWIZ_wrapper_externs_Changes_END --- EDIT HERE TO _BEGIN */