From b885fd97f69a2aaa25ba2ae68003f4aee730e453 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Wed, 19 Apr 2017 18:23:03 -1000 Subject: [PATCH] oneshot:trigger exit early in no chan in oneshot --- src/drivers/stm32/drv_io_timer.c | 33 +++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/drivers/stm32/drv_io_timer.c b/src/drivers/stm32/drv_io_timer.c index 59263eabe7..304f1ae74f 100644 --- a/src/drivers/stm32/drv_io_timer.c +++ b/src/drivers/stm32/drv_io_timer.c @@ -478,30 +478,33 @@ static inline void io_timer_set_PWM_mode(unsigned timer) void io_timer_trigger(void) { int oneshots = io_timer_get_mode_channels(IOTimerChanMode_OneShot); - uint32_t action_cache[MAX_IO_TIMERS] = {0}; - int actions = 0; - /* Pre-calculate the list of timers to Trigger */ + if (oneshots != 0) { + uint32_t action_cache[MAX_IO_TIMERS] = {0}; + int actions = 0; - for (int timer = 0; timer < MAX_IO_TIMERS; timer++) { - if (validate_timer_index(timer) == 0) { - int channels = get_timer_channels(timer); + /* Pre-calculate the list of timers to Trigger */ - if (oneshots & channels) { - action_cache[actions++] = io_timers[timer].base; + for (int timer = 0; timer < MAX_IO_TIMERS; timer++) { + if (validate_timer_index(timer) == 0) { + int channels = get_timer_channels(timer); + + if (oneshots & channels) { + action_cache[actions++] = io_timers[timer].base; + } } } - } - /* Now do them all wit the shortest delay in between */ + /* Now do them all wit the shortest delay in between */ - irqstate_t flags = px4_enter_critical_section(); + irqstate_t flags = px4_enter_critical_section(); - for (actions = 0; action_cache[actions] != 0 && actions < MAX_IO_TIMERS; actions++) { - _REG32(action_cache[actions], STM32_GTIM_EGR_OFFSET) |= GTIM_EGR_UG; - } + for (actions = 0; action_cache[actions] != 0 && actions < MAX_IO_TIMERS; actions++) { + _REG32(action_cache[actions], STM32_GTIM_EGR_OFFSET) |= GTIM_EGR_UG; + } - px4_leave_critical_section(flags); + px4_leave_critical_section(flags); + } } int io_timer_init_timer(unsigned timer)