Commit 367c5f6f authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Work towards reliable GPS trace storage, not there yet.

work:
- configured FatFs to support long file names
- configured FreeRTOS for max sleep mode = EM1 (this makes the GPS work with the
  OS putting the MCU in sleep mode)
- set optimization level to -O0, to make the accelerometer and compass work
- fooling around in GPS background task to try to store GPS trace
parent e5c3c436
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
/ Locale and Namespace Configurations / Locale and Namespace Configurations
/----------------------------------------------------------------------------*/ /----------------------------------------------------------------------------*/
#define _CODE_PAGE 932 #define _CODE_PAGE 437
/* The _CODE_PAGE specifies the OEM code page to be used on the target system. /* The _CODE_PAGE specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure. / Incorrect setting of the code page can cause a file open failure.
/ /
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
*/ */
#define _USE_LFN 0 /* 0 to 3 */ #define _USE_LFN 1 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */ #define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support. /* The _USE_LFN option switches the LFN support.
/ /
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
/ 1258 Vietnam (OEM, Windows) / 1258 Vietnam (OEM, Windows)
*/ */
#include "../ff.h" #include "../../inc/ff.h"
#if _CODE_PAGE == 437 #if _CODE_PAGE == 437
......
...@@ -177,6 +177,7 @@ C_SRC += \ ...@@ -177,6 +177,7 @@ C_SRC += \
../common/gfx/ui.c \ ../common/gfx/ui.c \
../common/reptile/fatfs/src/diskio.c \ ../common/reptile/fatfs/src/diskio.c \
../common/reptile/fatfs/src/ff.c \ ../common/reptile/fatfs/src/ff.c \
../common/reptile/fatfs/src/option/ccsbcs.c \
../common/sincos.c \ ../common/sincos.c \
../common/eeprom_emulation.c \ ../common/eeprom_emulation.c \
../common/usb/src/em_usbd.c \ ../common/usb/src/em_usbd.c \
...@@ -261,7 +262,7 @@ all: debug ...@@ -261,7 +262,7 @@ all: debug
debug: CFLAGS += -DDEBUG -O0 -g -DDEBUG_EFM debug: CFLAGS += -DDEBUG -O0 -g -DDEBUG_EFM
debug: $(EXE_DIR)/$(PROJECTNAME).bin debug: $(EXE_DIR)/$(PROJECTNAME).bin
release: CFLAGS += -DNDEBUG -O1 release: CFLAGS += -DNDEBUG -O0
release: $(EXE_DIR)/$(PROJECTNAME).bin release: $(EXE_DIR)/$(PROJECTNAME).bin
# Create objects from C SRC files # Create objects from C SRC files
......
...@@ -89,7 +89,7 @@ extern "C" { ...@@ -89,7 +89,7 @@ extern "C" {
/* Available options when configUSE_TICKLESS_IDLE set to 1 /* Available options when configUSE_TICKLESS_IDLE set to 1
* or configUSE_SLEEP_MODE_IN_IDLE set to 1 : * or configUSE_SLEEP_MODE_IN_IDLE set to 1 :
* 1 - EM1, 2 - EM2, 3 - EM3, timer in EM3 is not very accurate*/ * 1 - EM1, 2 - EM2, 3 - EM3, timer in EM3 is not very accurate*/
#define configSLEEP_MODE ( 2 ) #define configSLEEP_MODE ( 1 )
/* Definition used only if configUSE_TICKLESS_IDLE == 0 */ /* Definition used only if configUSE_TICKLESS_IDLE == 0 */
#define configUSE_SLEEP_MODE_IN_IDLE ( 1 ) #define configUSE_SLEEP_MODE_IN_IDLE ( 1 )
......
...@@ -54,6 +54,7 @@ static int firstrun, firstfix; ...@@ -54,6 +54,7 @@ static int firstrun, firstfix;
static int gpson, pgpson; static int gpson, pgpson;
static int track, ptrack; static int track, ptrack;
static int open = 0; static int open = 0;
static int mutexours = 0;
static FIL f; static FIL f;
static FATFS fatfs; static FATFS fatfs;
...@@ -71,8 +72,10 @@ static void gpsbkgnd_task(void *params) ...@@ -71,8 +72,10 @@ static void gpsbkgnd_task(void *params)
struct gps_utc gpstime; struct gps_utc gpstime;
struct gps_coord gpscoord; struct gps_coord gpscoord;
char buf[80]; char buf[80];
char fname[64];
UINT dummy;
/* Previous and current state of settings */ /* Previous and current state of GPS ON setting */
pgpson = gpson; pgpson = gpson;
gpson = setting_get(&setting_gps_on); gpson = setting_get(&setting_gps_on);
...@@ -116,32 +119,49 @@ static void gpsbkgnd_task(void *params) ...@@ -116,32 +119,49 @@ static void gpsbkgnd_task(void *params)
track = setting_get(&setting_tracking); track = setting_get(&setting_tracking);
if (track) { if (track) {
/* Init stuff & take semaphore so that only we write to SD */ /*
if (firstrun || !ptrack) { * On first run or tracking setting change, init stuff & take semaphore
xSemaphoreTake(mutexSdCardAccess, 0); * so that only we write to SD; also retry getting the mutex if we
MICROSD_Init(); * couldn't on the previous run.
disk_initialize(0); */
f_mount(0, &fatfs); if (firstrun || !ptrack || !mutexours) {
f_open(&f, "blah", FA_CREATE_ALWAYS | FA_WRITE); if (xSemaphoreTake(mutexSdCardAccess, 0)) {
f_lseek(&f, 0); mutexours = 1;
open = 1; MICROSD_Init();
disk_initialize(0);
f_mount(0, &fatfs);
open = 1;
}
} }
/* Write to file if gps is fixed */ /* Write to file if gps is fixed and mutex tells us we can write to SD */
if (gps_fixed()) { if (gps_fixed() && mutexours) {
// if (open) { if (open) {
// open = 0; /*
// gps_get_utc(&gpstime); * We open the file here so that we can give it a name according
// sprintf(buf, "track_%d-%d-%d_%dh%dm", 1900 + gpstime.yr, * to current time
// 1 + gpstime.mon, gpstime.day, */
// gpstime.hr + setting_get(&setting_gmt_ofs_hr), gps_get_utc(&gpstime);
// gpstime.min + setting_get(&setting_gmt_ofs_min)); sprintf(fname, "track_%d-%02d-%02d_%02dh%02dm%02ds.txt",
// f_open(&f, buf, FA_CREATE_ALWAYS | FA_WRITE); 1900 + gpstime.yr, 1 + gpstime.mon, gpstime.day,
// f_lseek(&f, 0); gpstime.hr + setting_get(&setting_gmt_ofs_hr),
// } gpstime.min + setting_get(&setting_gmt_ofs_min),
gps_get_coord(&gpscoord, 2); gpstime.sec);
sprintf(buf, "%3.7f,%3.7f\n", gpscoord.lat, gpscoord.lon); open = f_open(&f, fname, FA_CREATE_ALWAYS | FA_WRITE);
f_write(&f, buf, strlen(buf), NULL); if (!open)
f_lseek(&f, 0);
} else {
/*
* When we've opened (f_open() returns 0 on success), start
* putting coords into file
*/
gps_get_coord(&gpscoord, 2);
sprintf(buf, "%3.7f,%3.7f\n", gpscoord.lat, gpscoord.lon);
usbdbg_puts(buf);
FRESULT r = f_write(&f, buf, strlen(buf), &dummy);
sprintf(buf, "r=%d\r\n", r);
usbdbg_puts(buf);
}
} }
} else if (!track && ptrack) { } else if (!track && ptrack) {
...@@ -151,13 +171,14 @@ static void gpsbkgnd_task(void *params) ...@@ -151,13 +171,14 @@ static void gpsbkgnd_task(void *params)
*/ */
f_close(&f); f_close(&f);
MICROSD_Deinit(); MICROSD_Deinit();
open = 1; mutexours = 0;
xSemaphoreGive(mutexSdCardAccess); xSemaphoreGive(mutexSdCardAccess);
} }
if (firstrun) if (firstrun)
firstrun = 0; firstrun = 0;
/* Tickle tasks waiting for the GPS */
e.type = GPS_TICK; e.type = GPS_TICK;
xQueueSendToBack(appQueue, (void *)&e, 0); xQueueSendToBack(appQueue, (void *)&e, 0);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment