Commit e18ed9d9 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

GPS parsing in task almost working

parent d8f1e42f
......@@ -49,11 +49,7 @@
#include <usbconfig.h>
#include <usbdbg.h>
#define GPS_OK_TO_SEND "$PSRF150,1*3E\r\n"
#define RXBUFSIZE 128
static char rxbuf[RXBUFSIZE];
static char rxbuf[GPS_RXBUF_SIZE];
static volatile int idx = 0;
static volatile int frame_rdy = 0;
......@@ -69,6 +65,7 @@ void LEUART0_IRQHandler()
rxbuf[idx] = '\0';
idx = 0;
frame_rdy = 1;
// gps_parse_nmea(rxbuf);
}
}
}
......@@ -141,11 +138,17 @@ void gps_reset(int val)
val ? GPIO_PinOutClear(gpioPortF, 5) : GPIO_PinOutSet(gpioPortF, 5);
}
void gps_parse_nmea()
int gps_frame_rdy()
{
return frame_rdy;
}
void gps_parse_nmea(char *buf)
{
// TODO: check return of nmea_parse
nmea_parse(&parser, rxbuf, strlen(rxbuf), &info);
usbdbg_puts(rxbuf);
nmea_parse(&parser, buf, strlen(rxbuf), &info);
usbdbg_puts(buf);
frame_rdy = 0;
}
int gps_fixed()
......
......@@ -39,6 +39,17 @@
#ifndef __GPS_H_
#define __GPS_H_
/*=============*/
/* GPS defines */
/*=============*/
#define GPS_OK_TO_SEND "$PSRF150,1*3E\r\n"
#define GPS_RXBUF_SIZE 128
/*=================*/
/* Data structures */
/*=================*/
struct gps_coord {
double lat;
double lon;
......@@ -60,7 +71,8 @@ struct gps_utc {
void gps_init();
void gps_on_off_pulse();
void gps_reset(int val);
void gps_parse_nmea();
int gps_frame_rdy();
void gps_parse_nmea(char *buf);
int gps_fixed();
void gps_get_utc(struct gps_utc *utc);
void gps_get_coord(struct gps_coord *coord, int format);
......
......@@ -33,9 +33,7 @@
enum event_type {
BUTTON_PRESSED,
SENSOR,
RTC_TICK,
GPS_FRAME_RDY,
GPS_PARSE_RDY
RTC_TICK
};
/**
......
......@@ -30,6 +30,7 @@
#include <FreeRTOS.h>
#include <task.h>
#include <queue.h>
#include <semphr.h>
#include <em_gpio.h>
#include <udelay.h>
......
......@@ -27,6 +27,8 @@
#include "application.h"
#include <usbdbg.h>
#define dbg() \
int i; \
GPIO_PinOutSet(gpioPortE, 11); \
......@@ -34,19 +36,18 @@
; \
GPIO_PinOutClear(gpioPortE, 11);
extern volatile char gps_rxbuf[GPS_RXBUF_SIZE];
extern xSemaphoreHandle sem_gps;
void gpsbkgrnd_main(void *params)
{
(void)params;
struct event evt;
/* suppress compiler warning */
(void) params;
while (1) {
if (xQueueReceive(appQueue, &evt, portMAX_DELAY)) {
if (evt.type == GPS_FRAME_RDY) {
gps_parse_nmea();
evt.type = GPS_PARSE_RDY;
xQueueSendToBack(appQueue, &evt, 0);
}
if (xSemaphoreTake(sem_gps, portMAX_DELAY)) {
gps_parse_nmea(gps_rxbuf);
}
}
}
......
......@@ -106,7 +106,7 @@ static void gps_redraw(struct ui_widget *w)
static void gps_event(struct ui_widget *w, const struct event *evt)
{
if (evt->type == GPS_PARSE_RDY)
if (evt->type == RTC_TICK)
w->flags |= WF_DIRTY;
}
......@@ -128,6 +128,9 @@ static struct ui_widget gps_screen = {
void gpscoord_main(void *params)
{
/* suppress compiler warning */
(void) params;
struct event evt;
int i = 0;
......@@ -161,7 +164,7 @@ void gpscoord_main(void *params)
gpsscreen %= 2;
}
break;
case GPS_PARSE_RDY:
case RTC_TICK:
ui_update(&evt);
default:
break;
......
......@@ -36,7 +36,7 @@ static int gps_ico_blink = 0;
static void status_bar_event(struct ui_widget *w, const struct event *evt)
{
if (evt->type == GPS_PARSE_RDY) {
if (evt->type == RTC_TICK) {
w->flags |= WF_DIRTY;
if (gps_fixed()) {
memcpy(&gps_ico, &gps_receiving,
......
......@@ -29,6 +29,7 @@
#include <event.h>
#include <drivers/rtc.h>
#include <drivers/gps/gps.h>
#include <em_device.h>
#include <em_gpio.h>
......@@ -110,24 +111,21 @@ void HardFault_Handler(void)
SCB->AIRCR = 0x05FA0004;
}
#define RXBUFSIZE 128
static char rxbuf[RXBUFSIZE];
volatile char gps_rxbuf[GPS_RXBUF_SIZE];
static volatile int idx = 0;
extern xSemaphoreHandle sem_gps;
void LEUART0_IRQHandler(void)
{
portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
// Fill the event data
struct event evt;
evt.type = GPS_FRAME_RDY;
if (LEUART0->IF & LEUART_IF_RXDATAV) {
rxbuf[idx++] = LEUART_Rx(LEUART0);
if ((rxbuf[idx-2] == '\r') && (rxbuf[idx-1] == '\n')) {
rxbuf[idx] = '\0';
gps_rxbuf[idx++] = LEUART_Rx(LEUART0);
if ((gps_rxbuf[idx-2] == '\r') && (gps_rxbuf[idx-1] == '\n')) {
gps_rxbuf[idx] = '\0';
idx = 0;
xQueueSendFromISR(appQueue, &evt, &xHigherPriorityTaskWoken);
xSemaphoreGiveFromISR(sem_gps, &xHigherPriorityTaskWoken);
}
}
......
......@@ -36,6 +36,8 @@
#include <gfx/ui.h>
#include <drivers/gps/gps.h>
xSemaphoreHandle sem_gps;
int main(void)
{
// Chip errata
......@@ -64,9 +66,10 @@ int main(void)
startMain(&menu);
vSemaphoreCreateBinary(sem_gps);
/* Create background task for GPS */
if (xTaskCreate(gpsbkgrnd.main, (const signed char *)gpsbkgrnd.name,
APP_STACK_SIZE, NULL, BKGRND_APP_PRIORITY, NULL) != pdPASS) {
APP_STACK_SIZE, NULL, APP_PRIORITY, NULL) != pdPASS) {
// TODO oops..
}
......
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