Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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) 2015 Gautier Hattenberger <gautier.hattenberger@enac.fr>
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 
28 #include "mcu_periph/pwm_input_arch.h"
29 #include "mcu_periph/gpio.h"
30 #include "hal.h"
31 
32 #define ONE_MHZ_CLK 1000000
33 
34 #ifdef USE_PWM_INPUT1
35 static void input1_period_cb(ICUDriver *icup) {
36  pwm_input_period_tics[PWM_INPUT1] = icuGetPeriodX(icup);
38 }
39 
40 static void input1_width_cb(ICUDriver *icup) {
41  pwm_input_duty_tics[PWM_INPUT1] = icuGetWidthX(icup);
43 }
44 
45 static ICUConfig pwm_input1_cfg = {
46 #if USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_LOW
47  ICU_INPUT_ACTIVE_LOW,
48 #elif USE_PWM_INPUT1 == PWM_PULSE_TYPE_ACTIVE_HIGH
49  ICU_INPUT_ACTIVE_HIGH,
50 #else
51 #error "Unknown PWM_INPUT1_PULSE_TYPE"
52 #endif
54  input1_width_cb,
55  input1_period_cb,
56  NULL,
58  0
59 };
60 #endif
61 
62 #ifdef USE_PWM_INPUT2
63 static void input2_period_cb(ICUDriver *icup) {
64  pwm_input_period_tics[PWM_INPUT2] = icuGetPeriodX(icup);
66 }
67 
68 static void input2_width_cb(ICUDriver *icup) {
69  pwm_input_duty_tics[PWM_INPUT2] = icuGetWidthX(icup);
71 }
72 
73 static ICUConfig pwm_input2_cfg = {
74 #if USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_LOW
75  ICU_INPUT_ACTIVE_LOW,
76 #elif USE_PWM_INPUT2 == PWM_PULSE_TYPE_ACTIVE_HIGH
77  ICU_INPUT_ACTIVE_HIGH,
78 #else
79 #error "Unknown PWM_INPUT2_PULSE_TYPE"
80 #endif
82  input2_width_cb,
83  input2_period_cb,
84  NULL,
86  0
87 };
88 #endif
89 
90 void pwm_input_init(void)
91 {
92  int i;
93  // initialize the arrays to 0
94  for (i = 0; i < PWM_INPUT_NB; i++) {
95  pwm_input_duty_tics[i] = 0;
96  pwm_input_duty_valid[i] = 0;
97  pwm_input_period_tics[i] = 0;
99  }
100 
101 #ifdef USE_PWM_INPUT1
102  icuStart(&PWM_INPUT1_ICU, &pwm_input1_cfg);
104  icuStartCapture(&PWM_INPUT1_ICU);
105  icuEnableNotifications(&PWM_INPUT1_ICU);
106 #endif
107 
108 #ifdef USE_PWM_INPUT2
109  icuStart(&PWM_INPUT2_ICU, &pwm_input2_cfg);
111  icuStartCapture(&PWM_INPUT2_ICU);
112  icuEnableNotifications(&PWM_INPUT2_ICU);
113 #endif
114 
115 }
116 
119 }
120 
123 }
124 
void pwm_input_init(void)
#define PWM_INPUT_TICKS_PER_USEC
The default pwm counter is set-up to have 1/6 us resolution.
volatile uint32_t pwm_input_duty_tics[PWM_INPUT_NB]
Definition: pwm_input.c:29
#define PWM_INPUT1_GPIO_PIN
Definition: board.h:928
Some architecture independent helper functions for GPIOs.
#define PWM_INPUT2_GPIO_AF
Definition: board.h:939
volatile uint8_t pwm_input_period_valid[PWM_INPUT_NB]
Definition: pwm_input.c:32
#define PWM_INPUT2_ICU
Definition: board.h:935
volatile uint8_t pwm_input_duty_valid[PWM_INPUT_NB]
Definition: pwm_input.c:30
#define ONE_MHZ_CLK
#define TRUE
Definition: std.h:4
#define PWM_INPUT1_GPIO_PORT
Definition: board.h:927
#define PWM_INPUT1_GPIO_AF
Definition: board.h:929
unsigned long uint32_t
Definition: types.h:18
volatile uint32_t pwm_input_period_tics[PWM_INPUT_NB]
Definition: pwm_input.c:31
#define PWM_INPUT1_ICU
Definition: board.h:924
#define PWM_INPUT2_CHANNEL
Definition: board.h:936
uint32_t get_pwm_input_duty_in_usec(uint32_t channel)
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af)
Setup a gpio for input or output with alternate function.
Definition: gpio_arch.c:61
#define PWM_INPUT2_GPIO_PORT
Definition: board.h:937
#define PWM_INPUT2_GPIO_PIN
Definition: board.h:938
uint32_t get_pwm_input_period_in_usec(uint32_t channel)
#define PWM_INPUT1_CHANNEL
Definition: board.h:925
static uint8_t channel
Definition: ADS8344.c:80