From 70fc079e670a8f14587859ddcc8933671ba7ed29 Mon Sep 17 00:00:00 2001 From: Felix Ruess Date: Tue, 26 Feb 2013 20:27:01 +0100 Subject: [PATCH] [sys_time] replace SYS_TIME_RESOLUTION with SYS_TIME_FREQUENCY --- .../arch/lpc21/mcu_periph/sys_time_arch.c | 6 +----- .../arch/sim/mcu_periph/sys_time_arch.c | 2 +- .../arch/stm32/mcu_periph/sys_time_arch.c | 6 +----- sw/airborne/mcu_periph/sys_time.c | 8 ++++---- sw/airborne/mcu_periph/sys_time.h | 18 +++++++++++------- sw/airborne/subsystems/gps.h | 2 +- sw/simulator/nps/nps_main.c | 2 +- sw/simulator/sim_ac_jsbsim.c | 2 +- sw/simulator/sim_ac_jsbsim.h | 2 +- 9 files changed, 22 insertions(+), 26 deletions(-) diff --git a/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c b/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c index 195bad1636b..8e5229298c0 100644 --- a/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c +++ b/sw/airborne/arch/lpc21/mcu_periph/sys_time_arch.c @@ -105,11 +105,7 @@ void sys_time_arch_init( void ) { sys_time.cpu_ticks_per_sec = PCLK / T0_PCLK_DIV; /* 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); - - /* set final sys_time resolution in seconds from resolution in cpu_ticks */ - 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.resolution_cpu_ticks = (uint32_t)(sys_time.resolution * sys_time.cpu_ticks_per_sec + 0.5); /* setup Timer 0 to count forever */ /* reset & disable timer 0 */ diff --git a/sw/airborne/arch/sim/mcu_periph/sys_time_arch.c b/sw/airborne/arch/sim/mcu_periph/sys_time_arch.c index 236e6438b1a..b261ab76b6b 100644 --- a/sw/airborne/arch/sim/mcu_periph/sys_time_arch.c +++ b/sw/airborne/arch/sim/mcu_periph/sys_time_arch.c @@ -31,7 +31,7 @@ void sys_time_arch_init( void ) { // simulate 1us cpu ticks sys_time.cpu_ticks_per_sec = 1e6; - 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 * sys_time.cpu_ticks_per_sec + 0.5); } void sys_tick_handler( void ) { diff --git a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c index b550da16e4f..ca03d417c0c 100644 --- a/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c +++ b/sw/airborne/arch/stm32/mcu_periph/sys_time_arch.c @@ -44,11 +44,7 @@ void sys_time_arch_init( void ) { sys_time.cpu_ticks_per_sec = AHB_CLK; /* 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); - - /* set final sys_time resolution in seconds from resolution in cpu_ticks */ - 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.resolution_cpu_ticks = (uint32_t)(sys_time.resolution * sys_time.cpu_ticks_per_sec + 0.5); /* The timer interrupt is activated on the transition from 1 to 0, * therefore it activates every n+1 clock ticks. diff --git a/sw/airborne/mcu_periph/sys_time.c b/sw/airborne/mcu_periph/sys_time.c index 92e4d6eee6b..81c3e583986 100644 --- a/sw/airborne/mcu_periph/sys_time.c +++ b/sw/airborne/mcu_periph/sys_time.c @@ -30,9 +30,9 @@ #include "mcu_periph/sys_time.h" #include "mcu.h" -struct sys_time sys_time; +PRINT_CONFIG_VAR(SYS_TIME_FREQUENCY) -PRINT_CONFIG_VAR(SYS_TIME_RESOLUTION) +struct sys_time sys_time; int sys_time_register_timer(float duration, sys_time_cb cb) { @@ -72,8 +72,8 @@ void sys_time_init( void ) { sys_time.nb_sec_rem = 0; sys_time.nb_tick = 0; - sys_time.resolution_sec = SYS_TIME_RESOLUTION; - sys_time.ticks_per_sec = 1.0 / sys_time.resolution_sec; + sys_time.ticks_per_sec = SYS_TIME_FREQUENCY; + sys_time.resolution = 1.0 / sys_time.ticks_per_sec; for (unsigned int i=0; i