PX4 System change to Remove #ifdefs from the IO timers

Update the comment, to explain how to achive a different perescale
   value.

   Added PX4_IO_TIMER_ALTERNATE_RATE one board agnostic ifdef
   PX4_IO_TIMER_ALTERNATE_RATE that is non board specific.

   N.B.  I would like to eliminate PX4_IO_TIMER_ALTERNATE_RATE
   as well, but I need crazyflie HW to validate that the startup
   script can just set the rate on the PWM to 3921 fast enough to
   not effect the motors.
This commit is contained in:
David Sidrane
2016-11-01 10:30:22 -10:00
committed by Lorenz Meier
parent b2b9a0be9f
commit 2d451991af
2 changed files with 13 additions and 12 deletions
+11 -10
View File
@@ -379,11 +379,15 @@ static int allocate_channel(unsigned channel, io_timer_channel_mode_t mode)
static int timer_set_rate(unsigned timer, unsigned rate) static int timer_set_rate(unsigned timer, unsigned rate)
{ {
#if defined(CONFIG_ARCH_BOARD_CRAZYFLIE) #if defined(PX4_IO_TIMER_ALTERNATE_RATE)
/* configure the timer to update at 328.125 kHz (recommended) */
rARR(timer) = 255; /* Override the rate to a constant that could be provided by the board */
rARR(timer) = PX4_IO_TIMER_ALTERNATE_RATE;
#else #else
/* configure the timer to update at the desired rate */ /* configure the timer to update at the desired rate */
rARR(timer) = 1000000 / rate; rARR(timer) = 1000000 / rate;
#endif #endif
@@ -432,15 +436,12 @@ int io_timer_init_timer(unsigned timer)
rBDTR(timer) = ATIM_BDTR_MOE; rBDTR(timer) = ATIM_BDTR_MOE;
} }
#if defined(CONFIG_ARCH_BOARD_CRAZYFLIE) /* If the timer clock source provided as clock_freq is the STM32_APBx_TIMx_CLKIN
/* configure the timer to free-run at timer frequency */ * then configure the timer to free-run at 1MHz.
rPSC(timer) = 0; * Otherwize, other frequencies are attainable by adjusting .clock_freq accordingly.
#else */
/* configure the timer to free-run at 1MHz */
rPSC(timer) = (io_timers[timer].clock_freq / 1000000) - 1; rPSC(timer) = (io_timers[timer].clock_freq / 1000000) - 1;
#endif
/* /*
* Note we do the Standard PWM Out init here * Note we do the Standard PWM Out init here
+2 -2
View File
@@ -37,8 +37,9 @@
* *
*/ */
#include <nuttx/config.h> #include <px4_config.h>
#include <board_config.h>
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
@@ -60,7 +61,6 @@
#include <drivers/stm32/drv_io_timer.h> #include <drivers/stm32/drv_io_timer.h>
#include <board_config.h>
#if defined(BOARD_HAS_LED_PWM) #if defined(BOARD_HAS_LED_PWM)
#define REG(_tmr, _reg) (*(volatile uint32_t *)(led_pwm_timers[_tmr].base + _reg)) #define REG(_tmr, _reg) (*(volatile uint32_t *)(led_pwm_timers[_tmr].base + _reg))