Paparazzi UAS  v5.0.5_stable-7-g4b8bbb7
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gps.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2011 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #include "subsystems/gps.h"
28 
29 #include "led.h"
30 
31 #define MSEC_PER_WEEK (1000*60*60*24*7)
32 
33 struct GpsState gps;
34 
36 
37 void gps_init(void) {
39  gps.cacc = 0;
40 #ifdef GPS_LED
41  LED_OFF(GPS_LED);
42 #endif
43 #ifdef GPS_TYPE_H
44  gps_impl_init();
45 #endif
46 }
47 
49 {
50  uint32_t clock_delta;
51  uint32_t time_delta;
52  uint32_t itow_now;
53 
54  if (sys_ticks < gps_time_sync.t0_ticks) {
55  clock_delta = (0xFFFFFFFF - sys_ticks) + gps_time_sync.t0_ticks + 1;
56  } else {
57  clock_delta = sys_ticks - gps_time_sync.t0_ticks;
58  }
59 
60  time_delta = msec_of_sys_time_ticks(clock_delta);
61 
62  itow_now = gps_time_sync.t0_tow + time_delta;
63  if (itow_now > MSEC_PER_WEEK) {
64  itow_now %= MSEC_PER_WEEK;
65  }
66 
67  return itow_now;
68 }
static uint32_t msec_of_sys_time_ticks(uint32_t ticks)
Definition: sys_time.h:147
uint32_t cacc
course accuracy in rad*1e7
Definition: gps.h:75
data structure for GPS time sync
Definition: gps.h:91
#define MSEC_PER_WEEK
Definition: gps.c:31
void gps_impl_init(void)
Definition: gps_ardrone2.c:34
uint8_t fix
status of fix
Definition: gps.h:78
data structure for GPS information
Definition: gps.h:63
uint32_t t0_ticks
hw clock ticks when GPS message is received
Definition: gps.h:94
#define GPS_FIX_NONE
Definition: gps.h:41
Device independent GPS code (interface)
unsigned long uint32_t
Definition: types.h:18
struct GpsTimeSync gps_time_sync
Definition: gps.c:35
uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks)
Convert time in sys_time ticks to GPS time of week.
Definition: gps.c:48
#define LED_OFF(i)
Definition: led_hw.h:29
arch independent LED (Light Emitting Diodes) API
uint32_t t0_tow
GPS time of week in ms from last message.
Definition: gps.h:92
struct GpsState gps
global GPS state
Definition: gps.c:33
void gps_init(void)
initialize the global GPS state
Definition: gps.c:37