From: Olivier Matz Date: Thu, 10 Jul 2014 16:36:53 +0000 (+0200) Subject: prevent modification of GPS position during dump X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=b80b5b2fa35d632456556f9940314b565a60e802;p=protos%2Fimu.git prevent modification of GPS position during dump --- diff --git a/gps_venus.c b/gps_venus.c index 7119f8c..7150ef2 100644 --- a/gps_venus.c +++ b/gps_venus.c @@ -652,13 +652,19 @@ static struct fat_file_struct *open_log_file(void) return fd; } +void gps_get_pos(struct gps_pos *pos) +{ + memcpy(pos, &gps_pos, sizeof(*pos)); +} + int gps_loop(void) { struct fat_file_struct *fd = NULL; uint32_t ms; - uint8_t flags; + uint8_t flags, prio; int16_t len; char buf[128]; + struct gps_pos pos; if (1) { fd = open_log_file(); @@ -672,18 +678,24 @@ int gps_loop(void) ms = global_ms; IRQ_UNLOCK(flags); - if (fd != NULL) { + /* get position (prevent modification of gps pos during copy) */ + prio = callout_mgr_set_prio(&imuboard.intr_cm, GPS_PRIO); + gps_get_pos(&pos); + callout_mgr_restore_prio(&imuboard.intr_cm, prio); - /* XXX copy */ - len = snprintf(buf, sizeof(buf), - "%"PRIu32" " - "svnum %.2X lat %3.5f long %3.5f " - "alt %3.5f sea_alt %3.5f\n", - ms, gps_pos.sv_num, - (double)gps_pos.latitude/10000000., - (double)gps_pos.longitude/10000000., - (double)gps_pos.altitude/100., - (double)gps_pos.sea_altitude/100.); + /* XXX copy */ + len = snprintf(buf, sizeof(buf), + "%"PRIu32" " + "svnum %.2X lat %3.5f long %3.5f " + "alt %3.5f sea_alt %3.5f\n", + ms, gps_pos.sv_num, + (double)gps_pos.latitude/10000000., + (double)gps_pos.longitude/10000000., + (double)gps_pos.altitude/100., + (double)gps_pos.sea_altitude/100.); + + + if (fd != NULL) { if (fat_write_file(fd, (unsigned char *)buf, len) != len) { printf_P(PSTR("error writing to file\n")); diff --git a/gps_venus.h b/gps_venus.h index 18327c8..641bcbb 100644 --- a/gps_venus.h +++ b/gps_venus.h @@ -37,4 +37,7 @@ struct gps_pos { int gps_venus_init(void); int gps_loop(void); +/* does not lock intr, must be done by user */ +void gps_get_pos(struct gps_pos *pos); + #endif