[stm32][sys_time][ppm] run cortex systick timer at full AHB freq again, ppm at AHB/9

This commit is contained in:
Felix Ruess
2013-02-26 19:42:19 +01:00
parent 924956fb76
commit 523e2dabea
4 changed files with 13 additions and 17 deletions
@@ -35,7 +35,7 @@
* *
*/ */
#define RC_PPM_TICKS_OF_USEC(_v) cpu_ticks_of_usec((_v)) #define RC_PPM_TICKS_OF_USEC(_v) cpu_ticks_of_usec((_v))
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v) * sys_time.cpu_ticks_per_sec * 1e-6) #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) ((_v) * sys_time.cpu_ticks_per_sec * 1e-6)
#define USEC_OF_RC_PPM_TICKS(_v) usec_of_cpu_ticks((_v)) #define USEC_OF_RC_PPM_TICKS(_v) usec_of_cpu_ticks((_v))
#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL #define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL
@@ -37,12 +37,11 @@
/** Initialize SysTick. /** Initialize SysTick.
* Generate SysTick interrupt every sys_time.resolution_cpu_ticks * Generate SysTick interrupt every sys_time.resolution_cpu_ticks
* The timer interrupt is activated on the transition from 1 to 0,
* therefore it activates every n+1 clock ticks.
*/ */
void sys_time_arch_init( void ) { void sys_time_arch_init( void ) {
/* 72MHz / 8 => 9000000 counts per second */ /* run cortex systick timer with 72MHz */
sys_time.cpu_ticks_per_sec = AHB_CLK / 8; systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB);
sys_time.cpu_ticks_per_sec = AHB_CLK;
/* cpu ticks per desired sys_time timer step */ /* cpu ticks per desired sys_time timer step */
sys_time.resolution_cpu_ticks = (uint32_t)(sys_time.resolution_sec * sys_time.cpu_ticks_per_sec + 0.5); sys_time.resolution_cpu_ticks = (uint32_t)(sys_time.resolution_sec * sys_time.cpu_ticks_per_sec + 0.5);
@@ -51,10 +50,9 @@ void sys_time_arch_init( void ) {
sys_time.resolution_sec = (float)sys_time.resolution_cpu_ticks / sys_time.cpu_ticks_per_sec; sys_time.resolution_sec = (float)sys_time.resolution_cpu_ticks / sys_time.cpu_ticks_per_sec;
sys_time.ticks_per_sec = (uint32_t)(sys_time.cpu_ticks_per_sec / sys_time.resolution_cpu_ticks + 0.5); sys_time.ticks_per_sec = (uint32_t)(sys_time.cpu_ticks_per_sec / sys_time.resolution_cpu_ticks + 0.5);
/* set clock for cortex systick to AHB_CLK / 8 */ /* The timer interrupt is activated on the transition from 1 to 0,
systick_set_clocksource(STK_CTRL_CLKSOURCE_AHB_DIV8); * therefore it activates every n+1 clock ticks.
*/
/* 8999 would be one interrupt every 1ms */
systick_set_reload(sys_time.resolution_cpu_ticks-1); systick_set_reload(sys_time.resolution_cpu_ticks-1);
systick_interrupt_enable(); systick_interrupt_enable();
@@ -97,8 +97,8 @@ void ppm_arch_init ( void ) {
timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT, timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT,
TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP); TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
timer_set_period(PPM_TIMER, 0xFFFF); timer_set_period(PPM_TIMER, 0xFFFF);
/* run ppm timer at cpu freq / 8 */ /* run ppm timer at cpu freq / 9 = 8MHz */
timer_set_prescaler(PPM_TIMER, 7); timer_set_prescaler(PPM_TIMER, 8);
/* TIM configuration: Input Capture mode --------------------- /* TIM configuration: Input Capture mode ---------------------
The Rising edge is used as active edge, The Rising edge is used as active edge,
@@ -33,13 +33,11 @@
#include "mcu_periph/sys_time.h" #include "mcu_periph/sys_time.h"
/** /**
* While the ppm counter is currently running at the same speed as * The ppm counter is running at cpu freq / 9
* the systick counter, there is no reason for this to be true.
* Let's add a pair of macros to make it possible for them to be different.
*/ */
#define RC_PPM_TICKS_OF_USEC(_v) cpu_ticks_of_usec((_v)) #define RC_PPM_TICKS_OF_USEC(_v) ((_v) * (AHB_CLK / 9000000))
#define RC_PPM_SIGNED_TICKS_OF_USEC(_v) (int32_t)((_v) * sys_time.cpu_ticks_per_sec * 1e-6) #define RC_PPM_SIGNED_TICKS_OF_USEC(_v) ((_v) * (AHB_CLK / 9000000))
#define USEC_OF_RC_PPM_TICKS(_v) usec_of_cpu_ticks((_v)) #define USEC_OF_RC_PPM_TICKS(_v) ((_v) / (AHB_CLK / 9000000))
#define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL #define PPM_NB_CHANNEL RADIO_CONTROL_NB_CHANNEL