kopia lustrzana https://github.com/bristol-seds/pico-tracker
Semaphore to stop internal time representation incrementing mid-update
rodzic
ea2f7b5c27
commit
1ec501566a
|
@ -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,15 +163,19 @@ void do_cron(void)
|
||||||
*/
|
*/
|
||||||
void cron_tick(void) {
|
void cron_tick(void) {
|
||||||
|
|
||||||
/* Update time internally */
|
if (time_update_semaphore == 0) {
|
||||||
time.epoch++; time.second++;
|
|
||||||
if (time.second >= 60) {
|
/* Update time internally */
|
||||||
time.second = 0; time.minute++;
|
time.epoch++; time.second++;
|
||||||
if (time.minute >= 60) {
|
if (time.second >= 60) {
|
||||||
time.minute = 0; time.hour++;
|
time.second = 0; time.minute++;
|
||||||
if (time.hour >= 24) {
|
if (time.minute >= 60) {
|
||||||
time.hour = 0;
|
time.minute = 0; time.hour++;
|
||||||
|
if (time.hour >= 24) {
|
||||||
|
time.hour = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue