38 #include <libopencm3/stm32/rcc.h>
39 #include <libopencm3/stm32/gpio.h>
40 #include <libopencm3/stm32/timer.h>
41 #include <libopencm3/cm3/nvic.h>
48 #define ONE_MHZ_CLK 1000000
49 #ifdef NVIC_TIM_IRQ_PRIO
50 #define PPM_IRQ_PRIO NVIC_TIM_IRQ_PRIO
52 #define PPM_IRQ_PRIO 2
62 #define PPM_TIMER TIM1
63 #define RCC_TIM_PPM RCC_TIM1
64 #define RST_TIM_PPM RST_TIM1
69 #define PPM_TIMER TIM2
70 #define RCC_TIM_PPM RCC_TIM2
71 #define RST_TIM_PPM RST_TIM2
76 #define PPM_TIMER TIM3
77 #define RCC_TIM_PPM RCC_TIM3
78 #define RST_TIM_PPM RST_TIM3
83 #define PPM_TIMER TIM4
84 #define RCC_TIM_PPM RCC_TIM4
85 #define RST_TIM_PPM RST_TIM4
90 #define PPM_TIMER TIM5
91 #define RCC_TIM_PPM RCC_TIM5
92 #define RST_TIM_PPM RST_TIM5
97 #define PPM_TIMER TIM8
98 #define RCC_TIM_PPM RCC_TIM8
99 #define RST_TIM_PPM RST_TIM8
104 #define PPM_TIMER TIM9
105 #define RCC_TIM_PPM RCC_TIM9
106 #define RST_TIM_PPM RST_TIM9
111 #define PPM_TIMER TIM12
112 #define RCC_TIM_PPM RCC_TIM12
113 #define RST_TIM_PPM RST_TIM12
116 #error Unknown PPM input timer configuration.
122 rcc_periph_clock_enable(RCC_TIM_PPM);
128 rcc_periph_reset_pulse(RST_TIM_PPM);
129 timer_set_mode(
PPM_TIMER, TIM_CR1_CKD_CK_INT,
130 TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
138 #if defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_POSITIVE
140 #elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
143 #error "Unknown PPM_PULSE_TYPE"
179 }
else if ((TIM2_SR & TIM_SR_UIF) != 0) {
181 timer_clear_flag(TIM2, TIM_SR_UIF);
195 }
else if ((TIM3_SR & TIM_SR_UIF) != 0) {
197 timer_clear_flag(TIM3, TIM_SR_UIF);
210 }
else if ((TIM4_SR & TIM_SR_UIF) != 0) {
212 timer_clear_flag(TIM4, TIM_SR_UIF);
225 }
else if ((TIM5_SR & TIM_SR_UIF) != 0) {
227 timer_clear_flag(TIM5, TIM_SR_UIF);
235 void tim1_up_isr(
void)
237 #elif defined(STM32F4)
238 void tim1_up_tim10_isr(
void) {
240 if ((TIM1_SR & TIM_SR_UIF) != 0) {
242 timer_clear_flag(TIM1, TIM_SR_UIF);
246 void tim1_cc_isr(
void) {
258 void tim8_up_isr(
void) {
259 #elif defined(STM32F4)
260 void tim8_up_tim13_isr(
void) {
262 if ((TIM8_SR & TIM_SR_UIF) != 0) {
264 timer_clear_flag(TIM8, TIM_SR_UIF);
268 void tim8_cc_isr(
void) {
277 #elif USE_PPM_TIM9 && defined(STM32F4)
279 void tim1_brk_tim9_isr(
void)
287 }
else if ((TIM9_SR & TIM_SR_UIF) != 0) {
289 timer_clear_flag(TIM9, TIM_SR_UIF);
293 #elif USE_PPM_TIM12 && defined(STM32F4)
295 void tim8_brk_tim12_isr(
void)
303 }
else if ((TIM12_SR & TIM_SR_UIF) != 0) {
305 timer_clear_flag(TIM12, TIM_SR_UIF);
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.
void ppm_arch_init(void)
Architecture dependant code.
Some architecture independent helper functions for GPIOs.
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame from global timer value.
Generic interface for radio control modules.
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.
static uint32_t timer_rollover_cnt
#define RC_PPM_TICKS_PER_USEC
The ppm counter is set-up to have 1/6 us resolution.
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.