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
sys_time_arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-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 
30 #include "mcu_periph/sys_time.h"
31 
32 #include "libopencm3/cm3/systick.h"
33 
34 #ifdef SYS_TIME_LED
35 #include "led.h"
36 #endif
37 
38 void sys_tick_handler(void);
39 
43 void sys_time_arch_init( void ) {
44  /* run cortex systick timer with 72MHz */
45  systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB);
47 
48  /* cpu ticks per desired sys_time timer step */
50 
51  /* The timer interrupt is activated on the transition from 1 to 0,
52  * therefore it activates every n+1 clock ticks.
53  */
54  systick_set_reload(sys_time.resolution_cpu_ticks-1);
55 
56  systick_interrupt_enable();
57  systick_counter_enable();
58 }
59 
60 
61 // FIXME : nb_tick rollover ???
62 //
63 // 97 days at 512hz
64 // 12 hours at 100khz
65 //
66 void sys_tick_handler(void) {
67  sys_time.nb_tick++;
71  sys_time.nb_sec++;
72 #ifdef SYS_TIME_LED
73  LED_TOGGLE(SYS_TIME_LED);
74 #endif
75  }
76  for (unsigned int i=0; i<SYS_TIME_NB_TIMER; i++) {
77  if (sys_time.timer[i].in_use &&
81  if (sys_time.timer[i].cb) {
82  sys_time.timer[i].cb(i);
83  }
84  }
85  }
86 }
#define AHB_CLK
Definition: apogee_0.99.h:8
void sys_tick_handler(int signum)
Definition: sys_time_arch.c:54
volatile bool_t elapsed
Definition: sys_time.h:63
sys_time_cb cb
Definition: sys_time.h:62
uint32_t cpu_ticks_per_sec
cpu ticks per second
Definition: sys_time.h:77
uint32_t end_time
in SYS_TIME_TICKS
Definition: sys_time.h:64
Architecture independent timing functions.
unsigned long uint32_t
Definition: types.h:18
float resolution
sys_time_timer resolution in seconds
Definition: sys_time.h:74
volatile uint32_t nb_sec_rem
remainder of seconds since startup in CPU_TICKS
Definition: sys_time.h:70
#define LED_TOGGLE(i)
Definition: led_hw.h:30
volatile uint32_t nb_tick
SYS_TIME_TICKS since startup.
Definition: sys_time.h:71
void sys_time_arch_init(void)
#define TRUE
Definition: imu_chimu.h:144
uint32_t duration
in SYS_TIME_TICKS
Definition: sys_time.h:65
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:69
uint32_t resolution_cpu_ticks
sys_time_timer resolution in cpu ticks
Definition: sys_time.h:76
arch independent LED (Light Emitting Diodes) API
#define SYS_TIME_NB_TIMER
Definition: sys_time.h:40
bool_t in_use
Definition: sys_time.h:61
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
Definition: sys_time.h:72