Commit 81a5945e authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

Add GPS background `task' and make changes accordingly

Two more events were added to the event type (event.h)
- GPS_TICK -- tick from GPS background task
- GPS_OFF  -- to signal the status bar that the GPS was turned off,
so it can remove the icon

The status bar and GPS coordinate app were changed to react to the
proper events, i.e., both events above in the case of the status bar
and the GPS_TICK event in the case of the GPS coordinate app.
parent 35205273
...@@ -69,7 +69,7 @@ void LEUART0_IRQHandler() ...@@ -69,7 +69,7 @@ void LEUART0_IRQHandler()
} }
} }
void gps_init() void gps_init(int pulse_onoff)
{ {
int i; int i;
...@@ -78,9 +78,12 @@ void gps_init() ...@@ -78,9 +78,12 @@ void gps_init()
GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 1); GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 1);
GPIO_PinModeSet(gpioPortA, 1, gpioModeInput, 0); GPIO_PinModeSet(gpioPortA, 1, gpioModeInput, 0);
GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0); GPIO_PinModeSet(gpioPortE, 13, gpioModePushPull, 0);
for (i = 0; i < 100000; i++)
if (pulse_onoff) {
for (i = 0; i < 100000; i++)
; ;
gps_on_off_pulse(); gps_on_off_pulse();
}
/* LEUART0 config */ /* LEUART0 config */
LEUART_Init_TypeDef init = LEUART_INIT_DEFAULT; LEUART_Init_TypeDef init = LEUART_INIT_DEFAULT;
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
/*=============*/ /*=============*/
/* GPS defines */ /* GPS defines */
/*=============*/ /*=============*/
#define GPS_DBG 1 #define GPS_DBG 1
#define GPS_OK_TO_SEND "$PSRF150,1*3E\r\n" #define GPS_OK_TO_SEND "$PSRF150,1*3E\r\n"
...@@ -70,7 +70,7 @@ struct gps_utc { ...@@ -70,7 +70,7 @@ struct gps_utc {
/*=====================*/ /*=====================*/
/* Function prototypes */ /* Function prototypes */
/*=====================*/ /*=====================*/
void gps_init(); void gps_init(int pulse_onoff);
void gps_on_off_pulse(); void gps_on_off_pulse();
void gps_reset(int val); void gps_reset(int val);
int gps_get_framerdy(); int gps_get_framerdy();
......
...@@ -37,7 +37,9 @@ enum event_type { ...@@ -37,7 +37,9 @@ enum event_type {
BUTTON_PRESSED, BUTTON_PRESSED,
SENSOR_INT, SENSOR_INT,
RTC_TICK, RTC_TICK,
BATTERY_STATUS BATTERY_STATUS,
GPS_TICK,
GPS_OFF
}; };
/** /**
......
...@@ -213,6 +213,7 @@ src/apps/reset.c \ ...@@ -213,6 +213,7 @@ src/apps/reset.c \
src/main.c \ src/main.c \
src/battery_task.c \ src/battery_task.c \
src/blight_task.c \ src/blight_task.c \
src/gpsbkgnd_task.c \
src/irq_dispatcher.c \ src/irq_dispatcher.c \
src/low_power_tick_management.c \ src/low_power_tick_management.c \
src/state.c src/state.c
......
...@@ -174,7 +174,7 @@ extern "C" { ...@@ -174,7 +174,7 @@ extern "C" {
#define INCLUDE_eTaskGetState ( 0 ) #define INCLUDE_eTaskGetState ( 0 )
/* Default value of CPU clock (RC)*/ /* Default value of CPU clock (RC)*/
#define configCPU_CLOCK_HZ (( unsigned long ) 14000000) #define configCPU_CLOCK_HZ (( unsigned long ) 48000000)
/* Defines used in energy modes */ /* Defines used in energy modes */
#if ( ( configSLEEP_MODE == 2 ) && ( ( configUSE_SLEEP_MODE_IN_IDLE == 1 ) || ( configUSE_TICKLESS_IDLE == 1 ) ) ) #if ( ( configSLEEP_MODE == 2 ) && ( ( configUSE_SLEEP_MODE_IN_IDLE == 1 ) || ( configUSE_TICKLESS_IDLE == 1 ) ) )
......
...@@ -110,7 +110,7 @@ static void gps_redraw(struct ui_widget *w) ...@@ -110,7 +110,7 @@ static void gps_redraw(struct ui_widget *w)
static void gps_event(struct ui_widget *w, const struct event *evt) static void gps_event(struct ui_widget *w, const struct event *evt)
{ {
if (evt->type == RTC_TICK) if (evt->type == GPS_TICK)
w->flags |= WF_DIRTY; w->flags |= WF_DIRTY;
} }
...@@ -168,7 +168,7 @@ void gpscoord_main(void *params) ...@@ -168,7 +168,7 @@ void gpscoord_main(void *params)
gpsscreen %= 2; gpsscreen %= 2;
} }
break; break;
case RTC_TICK: case GPS_TICK:
ui_update(&evt); ui_update(&evt);
default: default:
break; break;
......
...@@ -45,26 +45,30 @@ static bool charging; ...@@ -45,26 +45,30 @@ static bool charging;
static struct rle_bitmap gps_ico; static struct rle_bitmap gps_ico;
static int gps_ico_blink = 0; static int gps_ico_blink = 0;
static int cgpson, pgpson;
static void status_bar_event(struct ui_widget *w, const struct event *evt) static void status_bar_event(struct ui_widget *w, const struct event *evt)
{ {
switch(evt->type) { switch(evt->type) {
case RTC_TICK: case GPS_TICK:
if (setting_gps_on.val) { if (gps_fixed()) {
if (gps_fixed()) { memcpy(&gps_ico, &gps_receiving,
memcpy(&gps_ico, &gps_receiving, sizeof(struct rle_bitmap));
sizeof(struct rle_bitmap)); } else {
gps_ico_blink ^= 1;
if (gps_ico_blink) {
memcpy(&gps_ico, &gps_searching,
sizeof(struct rle_bitmap));
} else { } else {
gps_ico_blink ^= 1; memcpy(&gps_ico, 0, sizeof(struct rle_bitmap));
if (gps_ico_blink) {
memcpy(&gps_ico, &gps_searching,
sizeof(struct rle_bitmap));
} else {
memcpy(&gps_ico, 0, sizeof(struct rle_bitmap));
}
} }
w->flags |= WF_DIRTY;
} }
w->flags |= WF_DIRTY;
break;
case GPS_OFF:
memcpy(&gps_ico, 0, sizeof(struct rle_bitmap));
w->flags |= WF_DIRTY;
// fall-through // fall-through
case BATTERY_STATUS: case BATTERY_STATUS:
......
/*
* Copyright (C) 2014 Julian Lewis
* @author Theodor Stana <theodor.stana@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <FreeRTOS.h>
#include <timers.h>
#include "settings/settings.h"
#include <drivers/gps.h>
#include <event.h>
#include <usbdbg.h>
#include <stdio.h>
#include "application.h"
#define GPSBKGND_TIMER_PERIOD (1000 / portTICK_RATE_MS)
static xTimerHandle timerGps;
static int firstrun;
static int cgpson, pgpson;
static void gpsbkgnd_task(void *params)
{
(void) params;
struct event e;
/* Previous and current state of GPS on setting at timer tick */
pgpson = cgpson;
cgpson = setting_gps_on.val;
/* 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 */
if (pgpson) {
e.type = GPS_OFF;
xQueueSendToBack(appQueue, (void *)&e, 0);
}
return;
}
e.type = GPS_TICK;
xQueueSendToBack(appQueue, (void *)&e, 0);
}
void gpsbkgnd_init()
{
firstrun = 1;
timerGps = xTimerCreate((signed char *)"timerGps",
GPSBKGND_TIMER_PERIOD, pdTRUE,
(void *)0, gpsbkgnd_task);
xTimerStart(timerGps, 0);
}
/*
* Copyright (C) 2014 Julian Lewis
* @author Theodor Stana <theodor.stana@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef GPSBKGND_H
#define GPSBKGND_H
void gpsbkgnd_init();
#endif
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include "battery_task.h" #include "battery_task.h"
#include "blight_task.h" #include "blight_task.h"
#include "state.h" #include "state.h"
#include "gpsbkgnd_task.h"
int main(void) int main(void)
{ {
...@@ -52,6 +53,7 @@ int main(void) ...@@ -52,6 +53,7 @@ int main(void)
CHIP_Init(); CHIP_Init();
// Enable clocks // Enable clocks
//CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFXO);
CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_HFPER, true);
CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable(cmuClock_GPIO, true);
...@@ -66,12 +68,13 @@ int main(void) ...@@ -66,12 +68,13 @@ int main(void)
vibra_init(); vibra_init();
rtc_init(); rtc_init();
lcd_init(); lcd_init();
gps_init(); gps_init(setting_gps_on.val);
ui_init(); ui_init();
auto_backlight_init(); auto_backlight_init();
battery_monitor_init(); battery_monitor_init();
state_init(); state_init();
gpsbkgnd_init();
// Initialize SLEEP driver, no callbacks are used // Initialize SLEEP driver, no callbacks are used
SLEEP_Init(NULL, NULL); SLEEP_Init(NULL, NULL);
......
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