Paparazzi UAS v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
pwm_input_arch.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2014 Gautier Hattenberger
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
29
30#include BOARD_CONFIG
31#include "generated/airframe.h"
32
33#include <libopencm3/stm32/rcc.h>
34#include <libopencm3/stm32/gpio.h>
35#include <libopencm3/stm32/timer.h>
36#include <libopencm3/cm3/nvic.h>
37
38#include "mcu_periph/sys_time.h"
39#include "mcu_periph/gpio.h"
40
41// for timer_get_frequency
42#include "mcu_arch.h"
43
44#define ONE_MHZ_CLK 1000000
45#ifdef NVIC_TIM_IRQ_PRIO
46#define PWM_INPUT_IRQ_PRIO NVIC_TIM_IRQ_PRIO
47#else
48#define PWM_INPUT_IRQ_PRIO 2
49#endif
50
59
61{
62 int i;
63 // initialize the arrays to 0
64 for (i = 0; i < PWM_INPUT_NB; i++) {
69 }
70
76#if USE_PWM_INPUT_TIM1
80#endif
81#if USE_PWM_INPUT_TIM2
85#endif
86#if USE_PWM_INPUT_TIM3
90#endif
91#if USE_PWM_INPUT_TIM4
95#endif
96#if USE_PWM_INPUT_TIM5
100#endif
101#if USE_PWM_INPUT_TIM8
105#endif
106#if USE_PWM_INPUT_TIM9
110#endif
111
112#ifdef USE_PWM_INPUT1
113 /* GPIO configuration as input capture for timer */
115
121#if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
124#elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
127#endif
128
129 /* Select the valid trigger input */
131 /* Configure the slave mode controller in reset mode */
133
134 /* Enable timer Interrupt(s). */
137#ifdef PWM_INPUT1_IRQ2
140#endif
141
142 /* Enable the Capture/Compare and Update interrupt requests. */
144
145 /* Enable capture channel. */
148#endif
149
150#ifdef USE_PWM_INPUT2
151 /* GPIO configuration as input capture for timer */
153
159#if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
162#elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
165#endif
166
167 /* Select the valid trigger input */
169 /* Configure the slave mode controller in reset mode */
171
172 /* Enable timer Interrupt(s). */
175#ifdef PWM_INPUT2_IRQ2
178#endif
179
180 /* Enable the Capture/Compare and Update interrupt requests. */
182
183 /* Enable capture channel. */
186#endif
187
188}
189
190
191#if USE_PWM_INPUT_TIM1
192
193#if defined(STM32F1)
194void tim1_up_isr(void)
195{
196#elif defined(STM32F4)
197void tim1_up_tim10_isr(void) {
198#endif
199 if ((TIM1_SR & TIM_SR_UIF) != 0) {
201 // FIXME clear overflow interrupt but what else ?
202 }
203}
204
205void tim1_cc_isr(void) {
206 if ((TIM1_SR & TIM1_CC_IF_PERIOD) != 0) {
210 }
211 if ((TIM1_SR & TIM1_CC_IF_DUTY) != 0) {
215 }
216}
217
218#endif
219
220#if USE_PWM_INPUT_TIM2
221
222void tim2_isr(void) {
223 if ((TIM2_SR & TIM2_CC_IF_PERIOD) != 0) {
227 }
228 if ((TIM2_SR & TIM2_CC_IF_DUTY) != 0) {
232 }
233 if ((TIM2_SR & TIM_SR_UIF) != 0) {
235 // FIXME clear overflow interrupt but what else ?
236 }
237}
238
239#endif
240
241#if USE_PWM_INPUT_TIM3
242
243void tim3_isr(void) {
244 if ((TIM3_SR & TIM3_CC_IF_PERIOD) != 0) {
248 }
249 if ((TIM3_SR & TIM3_CC_IF_DUTY) != 0) {
253 }
254 if ((TIM3_SR & TIM_SR_UIF) != 0) {
256 // FIXME clear overflow interrupt but what else ?
257 }
258}
259
260#endif
261
262#if USE_PWM_INPUT_TIM4
263
264void tim4_isr(void) {
265 if ((TIM4_SR & TIM4_CC_IF_PERIOD) != 0) {
269 }
270 if ((TIM4_SR & TIM4_CC_IF_DUTY) != 0) {
274 }
275 if ((TIM4_SR & TIM_SR_UIF) != 0) {
277 // FIXME clear overflow interrupt but what else ?
278 }
279}
280
281#endif
282
283#if USE_PWM_INPUT_TIM5
284
285void tim5_isr(void) {
286 if ((TIM5_SR & TIM5_CC_IF_PERIOD) != 0) {
290 }
291 if ((TIM5_SR & TIM5_CC_IF_DUTY) != 0) {
295 }
296 if ((TIM5_SR & TIM_SR_UIF) != 0) {
298 // FIXME clear overflow interrupt but what else ?
299 }
300}
301
302#endif
303
304#if USE_PWM_INPUT_TIM8
305
306#if defined(STM32F1)
307void tim8_up_isr(void)
308{
309#elif defined(STM32F4)
310void tim8_up_tim13_isr(void) {
311#endif
312 if ((TIM8_SR & TIM_SR_UIF) != 0) {
314 // FIXME clear overflow interrupt but what else ?
315 }
316}
317
318void tim8_cc_isr(void) {
319 if ((TIM8_SR & TIM8_CC_IF_PERIOD) != 0) {
323 }
324 if ((TIM8_SR & TIM8_CC_IF_DUTY) != 0) {
328 }
329}
330
331#endif
332
333#if USE_PWM_INPUT_TIM9
334
335// TIM1 break interrupt (which we don't care here) and TIM9 global interrupt
336void tim1_brk_tim9_isr(void) {
337 if ((TIM9_SR & TIM9_CC_IF_PERIOD) != 0) {
341 }
342 if ((TIM9_SR & TIM9_CC_IF_DUTY) != 0) {
346 }
347 if ((TIM9_SR & TIM_SR_UIF) != 0) {
349 // FIXME clear overflow interrupt but what else ?
350 }
351}
352
353#endif
354
#define PWM_INPUT2_GPIO_PORT
Definition board.h:430
#define PWM_INPUT2_GPIO_AF
Definition board.h:432
#define PWM_INPUT2_GPIO_PIN
Definition board.h:431
#define PWM_INPUT2_IRQ
Definition apogee_1.0.h:390
#define PWM_INPUT1_TIMER_INPUT
Definition apogee_1.0.h:365
#define TIM9_PWM_INPUT_IDX
Definition apogee_1.0.h:397
#define PWM_INPUT2_CC_IE
Definition apogee_1.0.h:391
#define TIM9_CC_IF_DUTY
Definition apogee_1.0.h:399
#define TIM1_CCR_PERIOD
Definition apogee_1.0.h:374
#define PWM_INPUT2_SLAVE_TRIG
Definition apogee_1.0.h:389
#define TIM1_CC_IF_PERIOD
Definition apogee_1.0.h:372
#define TIM9_CC_IF_PERIOD
Definition apogee_1.0.h:398
#define PWM_INPUT1_SLAVE_TRIG
Definition apogee_1.0.h:366
#define TIM9_CCR_PERIOD
Definition apogee_1.0.h:400
#define TIM1_CC_IF_DUTY
Definition apogee_1.0.h:373
#define PWM_INPUT1_CHANNEL_PERIOD
Definition apogee_1.0.h:363
#define TIM1_PWM_INPUT_IDX
Definition apogee_1.0.h:371
#define PWM_INPUT1_TIMER
Definition apogee_1.0.h:359
#define PWM_INPUT1_CHANNEL_DUTY
Definition apogee_1.0.h:364
#define PWM_INPUT1_IRQ
Definition apogee_1.0.h:367
#define PWM_INPUT2_CHANNEL_DUTY
Definition apogee_1.0.h:387
#define PWM_INPUT1_CC_IE
Definition apogee_1.0.h:369
#define TIM1_CCR_DUTY
Definition apogee_1.0.h:375
#define PWM_INPUT1_IRQ2
Definition apogee_1.0.h:368
#define PWM_INPUT2_CHANNEL_PERIOD
Definition apogee_1.0.h:386
#define PWM_INPUT2_TIMER_INPUT
Definition apogee_1.0.h:388
#define PWM_INPUT2_TIMER
Definition apogee_1.0.h:382
#define TIM9_CCR_DUTY
Definition apogee_1.0.h:401
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
Definition gpio_arch.c:65
void pwm_input_init(void)
#define ONE_MHZ_CLK
@ PWM_INPUT_NB
#define PWM_INPUT1_GPIO_PORT
#define PWM_INPUT1_GPIO_AF
#define PWM_INPUT1_GPIO_PIN
Some architecture independent helper functions for GPIOs.
uint16_t foo
Definition main_demo5.c:58
volatile uint32_t pwm_input_duty_tics[PWM_INPUT_NB]
Definition pwm_input.c:34
volatile uint8_t pwm_input_period_valid[PWM_INPUT_NB]
Definition pwm_input.c:37
volatile uint8_t pwm_input_duty_valid[PWM_INPUT_NB]
Definition pwm_input.c:35
volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB]
Definition pwm_input.c:36
arch independent PWM input capture API
#define FALSE
Definition std.h:5
uint32_t timer_get_frequency(uint32_t timer_peripheral)
Get Timer clock frequency (before prescaling) Only valid if using the internal clock for the timer.
Definition mcu_arch.c:311
static void pwm_input_set_timer(uint32_t tim, uint32_t ticks_per_usec)
#define PWM_INPUT_IRQ_PRIO
Architecture independent timing functions.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.