prevent modification of GPS position during dump
authorOlivier Matz <zer0@droids-corp.org>
Thu, 10 Jul 2014 16:36:53 +0000 (18:36 +0200)
committerOlivier Matz <zer0@droids-corp.org>
Thu, 10 Jul 2014 16:36:53 +0000 (18:36 +0200)
gps_venus.c
gps_venus.h

index 7119f8c..7150ef2 100644 (file)
@@ -652,13 +652,19 @@ static struct fat_file_struct *open_log_file(void)
        return fd;
 }
 
        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;
 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];
        int16_t len;
        char buf[128];
+       struct gps_pos pos;
 
        if (1) {
                fd = open_log_file();
 
        if (1) {
                fd = open_log_file();
@@ -672,18 +678,24 @@ int gps_loop(void)
                ms = global_ms;
                IRQ_UNLOCK(flags);
 
                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"));
 
                        if (fat_write_file(fd, (unsigned char *)buf, len) != len) {
                                printf_P(PSTR("error writing to file\n"));
index 18327c8..641bcbb 100644 (file)
@@ -37,4 +37,7 @@ struct gps_pos {
 int gps_venus_init(void);
 int gps_loop(void);
 
 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
 #endif