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();
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"));