Semaphore to stop internal time representation incrementing mid-update

master
Richard Meadows 2015-07-14 21:41:04 +00:00
rodzic ea2f7b5c27
commit 1ec501566a
1 zmienionych plików z 20 dodań i 9 usunięć

Wyświetl plik

@ -36,6 +36,8 @@
/* Internal time representation */ /* Internal time representation */
struct tracker_time time = {0}; struct tracker_time time = {0};
uint8_t time_update_semaphore = 0;
/* Pointer to latest datapoint */ /* Pointer to latest datapoint */
struct tracker_datapoint* dp; struct tracker_datapoint* dp;
@ -61,6 +63,8 @@ void read_gps_time(void)
idle(IDLE_WAIT_FOR_GPS); idle(IDLE_WAIT_FOR_GPS);
} }
time_update_semaphore = 1;
/* Time */ /* Time */
struct ubx_nav_timeutc gt = gps_get_nav_timeutc(); struct ubx_nav_timeutc gt = gps_get_nav_timeutc();
time.year = gt.payload.year; time.year = gt.payload.year;
@ -72,6 +76,9 @@ void read_gps_time(void)
time.valid = gt.payload.valid; time.valid = gt.payload.valid;
/* TODO calculate epoch time here */ /* TODO calculate epoch time here */
time_update_semaphore = 0;
} }
/** /**
@ -147,7 +154,7 @@ void do_cron(void)
kick_the_watchdog(); kick_the_watchdog();
read_gps_time(); /* TODO semaphore to stop mid-update increment */ read_gps_time();
} }
} }
@ -156,6 +163,8 @@ void do_cron(void)
*/ */
void cron_tick(void) { void cron_tick(void) {
if (time_update_semaphore == 0) {
/* Update time internally */ /* Update time internally */
time.epoch++; time.second++; time.epoch++; time.second++;
if (time.second >= 60) { if (time.second >= 60) {
@ -167,4 +176,6 @@ void cron_tick(void) {
} }
} }
} }
}
} }