Commit 723d2145 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Started work on GPS tracking

For now, I was only testing writing a file to the SD card from the FreeRTOS
apps. It doesn't yet work.
parent 8f196ba0
......@@ -46,6 +46,7 @@ menu_list gps_settings_menu = {
{ SETTING, NULL, { .setting = &setting_gps_sets_time } },
{ APP, &clock_icon, { .app = &set_gmt_ofs } },
{ APP, &clock_icon, { .app = &set_time_fr_gps } },
{ SETTING, NULL, { .setting = &setting_tracking } },
{ END, NULL, { NULL } }
}
};
......
......@@ -36,9 +36,10 @@ setting_t setting_gps_sets_time = { "GPS sets time", 1, 2, 0 };
/* Settings with nrvals == 0 do not wrap around, they are set externally */
setting_t setting_gmt_ofs_hr = { "GMT ofs hrs", 0, 0, 0 };
setting_t setting_gmt_ofs_min = { "GMT ofs mins", 0, 0, 0 };
setting_t setting_tracking = { "Tracking", 1, 2, 0 };
static EE_Variable_TypeDef gps_on, coord_style, gps_sets_time,
gmt_ofs_hr, gmt_ofs_min;
gmt_ofs_hr, gmt_ofs_min, tracking;
void setting_init()
{
......@@ -48,6 +49,7 @@ void setting_init()
EE_DeclareVariable(&gps_sets_time);
EE_DeclareVariable(&gmt_ofs_hr);
EE_DeclareVariable(&gmt_ofs_min);
EE_DeclareVariable(&tracking);
/*
* Place these virtual addresses to the RAM-stored structs, so we can pass
......@@ -58,6 +60,7 @@ void setting_init()
setting_gps_sets_time.fladdr = gps_sets_time.virtualAddress;
setting_gmt_ofs_hr.fladdr = gmt_ofs_hr.virtualAddress;
setting_gmt_ofs_min.fladdr = gmt_ofs_min.virtualAddress;
setting_tracking.fladdr = tracking.virtualAddress;
/*
* EE_Init() fails if the virtual addresses are not found in the flash. If
......@@ -71,12 +74,14 @@ void setting_init()
EE_Write(&gps_sets_time, setting_gps_sets_time.val);
EE_Write(&gmt_ofs_hr, setting_gmt_ofs_hr.val);
EE_Write(&gmt_ofs_min, setting_gmt_ofs_min.val);
EE_Write(&tracking, setting_tracking.val);
} else {
EE_Read(&gps_on, &setting_gps_on.val);
EE_Read(&coord_style, &setting_coord_style.val);
EE_Read(&gps_sets_time, &setting_gps_sets_time.val);
EE_Read(&gmt_ofs_hr, &setting_gmt_ofs_hr.val);
EE_Read(&gmt_ofs_min, &setting_gmt_ofs_min.val);
EE_Read(&tracking, &setting_tracking.val);
}
}
......
......@@ -49,6 +49,7 @@ extern setting_t setting_coord_style;
extern setting_t setting_gmt_ofs_hr;
extern setting_t setting_gmt_ofs_min;
extern setting_t setting_gps_sets_time;
extern setting_t setting_tracking;
void setting_init();
void setting_change(setting_t *setting);
......
......@@ -22,6 +22,7 @@
#include <FreeRTOS.h>
#include <timers.h>
#include <semphr.h>
#include "settings/settings.h"
......@@ -38,13 +39,28 @@
#include "application.h"
#include "clock.h"
#include <ff.h>
#include <microsd.h>
#include <diskio.h>
#define GPSBKGND_TIMER_PERIOD (1000 / portTICK_RATE_MS)
static xTimerHandle timerGps;
extern xSemaphoreHandle mutexSdCardAccess;
static int firstrun, firstfix;
static int cgpson, pgpson;
static int runcnt = 0;
static FIL f;
static FATFS fatfs;
DWORD get_fattime(void)
{
return (28 << 25) | (2 << 21) | (1 << 16);
}
static void gpsbkgnd_task(void *params)
{
(void) params;
......@@ -59,8 +75,6 @@ static void gpsbkgnd_task(void *params)
/* Pulse GPS ON_OFF pin if setting changed */
if ((pgpson != cgpson) && !firstrun)
gps_on_off_pulse();
if (firstrun)
firstrun = 0;
if (!cgpson) {
/* Turn off status bar icon if GPS turns off */
......@@ -93,6 +107,36 @@ static void gpsbkgnd_task(void *params)
if (firstfix) firstfix = 0;
}
/* Track GPS position if setting tells us to */
if (setting_get(&setting_tracking) &&
xSemaphoreTake(mutexSdCardAccess, 0) ) {
if (firstrun) {
MICROSD_Init();
disk_initialize(0);
f_mount(0, &fatfs);
f_open(&f, "hello", FA_CREATE_ALWAYS | FA_WRITE);
f_lseek(&f, 0);
int i;
for (i = 0; i < 10000; i++)
;
}
char buf[32];
int len;
UINT read;
sprintf(buf, "hello, world!\n");
len = strlen(buf);
f_write(&f, buf, len, &read);
if (++runcnt == 4) {
xSemaphoreGive(mutexSdCardAccess);
f_close(&f);
}
}
if (firstrun)
firstrun = 0;
e.type = GPS_TICK;
xQueueSendToBack(appQueue, (void *)&e, 0);
}
......
......@@ -54,6 +54,8 @@
#include <usbdbg.h>
#endif
xSemaphoreHandle mutexSdCardAccess;
int main(void)
{
// Chip errata
......@@ -68,6 +70,8 @@ int main(void)
I2C_Init_TypeDef i2cInit = I2C_INIT_DEFAULT;
I2CDRV_Init(&i2cInit);
mutexSdCardAccess = xSemaphoreCreateMutex();
MSC_Init();
setting_init();
......
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