Paparazzi UAS  v4.2.2_stable-4-gcc32f65
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
sys_time_arch.c
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (C) 2009-2011 The Paparazzi Team
4  *
5  * This file is part of paparazzi.
6  *
7  * paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, write to
19  * the Free Software Foundation, 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22 
29 #include "mcu_periph/sys_time.h"
30 
31 #include "armVIC.h"
32 
33 #ifdef SYS_TIME_LED
34 #include "led.h"
35 #endif
36 
37 #define SYS_TICK_IT TIR_MR0I
38 
39 #if defined ACTUATORS && ( defined SERVOS_4017 || defined SERVOS_4015_MAT || defined SERVOS_PPM_MAT)
40 #include ACTUATORS
41 #else
42 #define ACTUATORS_IT 0x00
43 #endif /* ACTUATORS */
44 
45 #if defined RADIO_CONTROL && defined RADIO_CONTROL_TYPE_PPM
47 #else
48 #define PPM_IT 0x00
49 #endif
50 
51 #ifdef MB_SCALE
52 #include "mb_scale.h"
53 #else
54 #define MB_SCALE_IT 0x00
55 #endif
56 
57 #ifdef MB_TACHO
58 #include "mb_tacho.h"
59 #else
60 #define MB_TACHO_IT 0x00
61 #endif
62 
63 #ifdef USE_PWM_INPUT
64 #include "mcu_periph/pwm_input.h"
65 #endif
66 #ifndef USE_PWM_INPUT1
67 #define PWM_INPUT_IT1 0x00
68 #endif
69 #ifndef USE_PWM_INPUT2
70 #define PWM_INPUT_IT2 0x00
71 #endif
72 
73 #ifdef USE_AMI601
74 #include "peripherals/ami601.h"
75 #else
76 #define AMI601_IT 0x00
77 #endif
78 
79 #ifdef TRIGGER_EXT
80 #include "core/trigger_ext_hw.h"
81 #else
82 #define TRIGGER_IT 0x00
83 #endif
84 
85 #define TIMER0_IT_MASK (SYS_TICK_IT | \
86  ACTUATORS_IT | \
87  PPM_IT | \
88  TRIGGER_IT | \
89  MB_SCALE_IT | \
90  MB_TACHO_IT | \
91  PWM_INPUT_IT1 | \
92  PWM_INPUT_IT2 | \
93  AMI601_IT)
94 
95 
96 void sys_time_arch_init( void ) {
97  /* setup Timer 0 to count forever */
98  /* reset & disable timer 0 */
99  T0TCR = TCR_RESET;
100  /* set the prescale divider */
101  T0PR = T0_PCLK_DIV - 1;
102  /* enable interrupt on match0 for sys_ticks */
103  T0MCR = TMCR_MR0_I;
104  /* disable capture registers */
105  T0CCR = 0;
106  /* disable external match register */
107  T0EMR = 0;
108 
109  /* set first sys tick interrupt */
111 
112  /* enable timer 0 */
113  T0TCR = TCR_ENABLE;
114 
115  /* select TIMER0 as IRQ */
117  /* enable TIMER0 interrupt */
119  /* on slot vic slot 1 */
121  /* address of the ISR */
123 }
124 
125 
126 // FIXME : nb_tick rollover ???
127 //
128 // 97 days at 512hz
129 // 12 hours at 100khz
130 //
131 static inline void sys_tick_irq_handler(void) {
132  /* set match register for next interrupt */
134 
135  sys_time.nb_tick++;
139  sys_time.nb_sec++;
140 #ifdef SYS_TIME_LED
141  LED_TOGGLE(SYS_TIME_LED);
142 #endif
143  }
144  for (unsigned int i=0; i<SYS_TIME_NB_TIMER; i++) {
145  if (sys_time.timer[i].in_use &&
148  sys_time.timer[i].elapsed = TRUE;
149  if (sys_time.timer[i].cb) sys_time.timer[i].cb(i);
150  }
151  }
152 }
153 
154 void TIMER0_ISR ( void ) {
155  ISR_ENTRY();
156 
157  while (T0IR & TIMER0_IT_MASK) {
158 
159  if (T0IR&SYS_TICK_IT) {
161  T0IR = SYS_TICK_IT;
162  }
163 
164 #if defined ACTUATORS && ( defined SERVOS_4017 || defined SERVOS_4015_MAT || defined SERVOS_PPM_MAT)
165  if (T0IR&ACTUATORS_IT) {
166 #ifdef SERVOS_4017
167  SERVOS_4017_ISR();
168 #endif
169 #ifdef SERVOS_4015_MAT
171 #endif
172 #ifdef SERVOS_PPM_MAT
174 #endif
175  T0IR = ACTUATORS_IT;
176  }
177 #endif /* ACTUATORS && (SERVOS_4017 || SERVOS_4015_MAT || SERVOS_PPM_MAT) */
178 
179 #if defined RADIO_CONTROL && defined RADIO_CONTROL_TYPE_PPM
180  if (T0IR&PPM_IT) {
181  PPM_ISR();
182  T0IR = PPM_IT;
183  }
184 #endif
185 #ifdef TRIGGER_EXT
186  if (T0IR&TRIGGER_IT) {
187  TRIG_ISR();
188  T0IR = TRIGGER_IT;
189  LED_TOGGLE(3);
190  }
191 #endif
192 #ifdef MB_SCALE
193  if (T0IR&MB_SCALE_IT) {
194  MB_SCALE_ICP_ISR();
195  T0IR = MB_SCALE_IT;
196  }
197 #endif
198 #ifdef MB_TACHO
199  if (T0IR&MB_TACHO_IT) {
200  MB_TACHO_ISR();
201  T0IR = MB_TACHO_IT;
202  }
203 #endif
204 #ifdef USE_PWM_INPUT1
205  if (T0IR&PWM_INPUT_IT1) {
206  PWM_INPUT_ISR_1();
208  }
209 #endif
210 #ifdef USE_PWM_INPUT2
211  if (T0IR&PWM_INPUT_IT2) {
212  PWM_INPUT_ISR_2();
214  }
215 #endif
216 #ifdef USE_AMI601
217  if (T0IR&AMI601_IT) {
218  AMI601_ISR();
219  T0IR = AMI601_IT;
220  }
221 #endif
222  }
223  VICVectAddr = 0x00000000;
224  ISR_EXIT();
225 }
#define VICIntSelect
Definition: LPC21xx.h:398
#define T0CCR
Definition: LPC21xx.h:60
volatile bool_t elapsed
Definition: sys_time.h:49
sys_time_cb cb
Definition: sys_time.h:48
#define T0MCR
Definition: LPC21xx.h:55
#define TCR_RESET
Definition: lpcTMR.h:55
#define _VIC_CNTL(idx)
Definition: armVIC.h:19
arch independent PWM input capture API
#define SYS_TIME_RESOLUTION_CPU_TICKS
Definition: sys_time.h:114
#define T0TCR
Definition: LPC21xx.h:51
uint32_t end_time
in SYS_TICKS
Definition: sys_time.h:50
#define _VIC_ADDR(idx)
Definition: armVIC.h:20
#define TIMER0_IT_MASK
Definition: sys_time_arch.c:85
void TIMER0_ISR(void)
#define T0PR
Definition: LPC21xx.h:53
Architecture independent timing functions.
#define T0IR
Definition: LPC21xx.h:50
#define VIC_TIMER0
Definition: lpcVIC.h:72
#define VICVectAddr
Definition: LPC21xx.h:404
unsigned long uint32_t
Definition: types.h:18
#define TCR_ENABLE
Definition: lpcTMR.h:54
#define PPM_IT
Definition: sys_time_arch.c:48
#define MB_SCALE_IT
Definition: sys_time_arch.c:54
#define SERVOS_4017_ISR()
#define PWM_INPUT_IT2
Definition: sys_time_arch.c:70
#define T0MR0
Definition: LPC21xx.h:56
#define T0EMR
Definition: LPC21xx.h:65
#define AMI601_ISR()
Definition: ami601.h:30
volatile uint32_t nb_sec_rem
remainder of second in CPU_TICKS
Definition: sys_time.h:56
#define LED_TOGGLE(i)
Definition: led_hw.h:30
volatile uint32_t nb_tick
in SYS_TICKS with SYS_TIME_RESOLUTION
Definition: sys_time.h:57
void sys_time_arch_init(void)
Definition: sys_time_arch.c:96
#define PPM_ISR()
Definition: ppm_arch.h:47
#define VIC_BIT(chan)
Definition: lpcVIC.h:105
#define TRIGGER_IT
Definition: sys_time_arch.c:82
#define TRUE
Definition: imu_chimu.h:144
#define ServosPPMMat_ISR()
Definition: servos_ppm_hw.h:56
#define ACTUATORS_IT
Definition: sys_time_arch.c:42
uint32_t duration
in SYS_TICKS
Definition: sys_time.h:51
#define ISR_EXIT()
Definition: armVIC.h:61
#define TIMER0_VIC_SLOT
Definition: sys_time_arch.h:58
static void sys_tick_irq_handler(void)
#define VICIntEnable
Definition: LPC21xx.h:399
volatile uint32_t nb_sec
full seconds since startup
Definition: sys_time.h:55
void TRIG_ISR()
arch independent LED (Light Emitting Diodes) API
#define SYS_TIME_NB_TIMER
Definition: sys_time.h:40
#define CPU_TICKS_PER_SEC
Definition: sys_time.h:107
#define TMCR_MR0_I
Definition: lpcTMR.h:59
#define SYS_TICK_IT
Definition: sys_time_arch.c:37
#define MB_TACHO_IT
Definition: sys_time_arch.c:60
#define AMI601_IT
Definition: sys_time_arch.c:76
bool_t in_use
Definition: sys_time.h:47
struct sys_time_timer timer[SYS_TIME_NB_TIMER]
Definition: sys_time.h:58
#define PWM_INPUT_IT1
Definition: sys_time_arch.c:67
#define ISR_ENTRY()
Definition: armVIC.h:40
#define VIC_ENABLE
Definition: lpcVIC.h:102
#define Servos4015Mat_ISR()