mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-06-05 15:30:08 +08:00
[sys_time] replace SYS_TIME_RESOLUTION with SYS_TIME_FREQUENCY
This commit is contained in:
@@ -105,11 +105,7 @@
|
|||||||
void sys_time_arch_init( void ) {
|
void sys_time_arch_init( void ) {
|
||||||
sys_time.cpu_ticks_per_sec = PCLK / T0_PCLK_DIV;
|
sys_time.cpu_ticks_per_sec = PCLK / T0_PCLK_DIV;
|
||||||
/* 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 * 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);
|
|
||||||
|
|
||||||
/* setup Timer 0 to count forever */
|
/* setup Timer 0 to count forever */
|
||||||
/* reset & disable timer 0 */
|
/* reset & disable timer 0 */
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
void sys_time_arch_init( void ) {
|
void sys_time_arch_init( void ) {
|
||||||
// simulate 1us cpu ticks
|
// simulate 1us cpu ticks
|
||||||
sys_time.cpu_ticks_per_sec = 1e6;
|
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 ) {
|
void sys_tick_handler( void ) {
|
||||||
|
|||||||
@@ -44,11 +44,7 @@ void sys_time_arch_init( void ) {
|
|||||||
sys_time.cpu_ticks_per_sec = AHB_CLK;
|
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 * 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);
|
|
||||||
|
|
||||||
/* The timer interrupt is activated on the transition from 1 to 0,
|
/* The timer interrupt is activated on the transition from 1 to 0,
|
||||||
* therefore it activates every n+1 clock ticks.
|
* therefore it activates every n+1 clock ticks.
|
||||||
|
|||||||
@@ -30,9 +30,9 @@
|
|||||||
#include "mcu_periph/sys_time.h"
|
#include "mcu_periph/sys_time.h"
|
||||||
#include "mcu.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) {
|
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_sec_rem = 0;
|
||||||
sys_time.nb_tick = 0;
|
sys_time.nb_tick = 0;
|
||||||
|
|
||||||
sys_time.resolution_sec = SYS_TIME_RESOLUTION;
|
sys_time.ticks_per_sec = SYS_TIME_FREQUENCY;
|
||||||
sys_time.ticks_per_sec = 1.0 / sys_time.resolution_sec;
|
sys_time.resolution = 1.0 / sys_time.ticks_per_sec;
|
||||||
|
|
||||||
for (unsigned int i=0; i<SYS_TIME_NB_TIMER; i++) {
|
for (unsigned int i=0; i<SYS_TIME_NB_TIMER; i++) {
|
||||||
sys_time.timer[i].in_use = FALSE;
|
sys_time.timer[i].in_use = FALSE;
|
||||||
|
|||||||
@@ -40,12 +40,16 @@
|
|||||||
#define SYS_TIME_NB_TIMER 8
|
#define SYS_TIME_NB_TIMER 8
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** system time resolution in seconds */
|
|
||||||
#ifndef SYS_TIME_RESOLUTION
|
/**
|
||||||
|
* (Default) sys_time timer frequency in Hz.
|
||||||
|
* sys_time.resolution is set from this define.
|
||||||
|
*/
|
||||||
|
#ifndef SYS_TIME_FREQUENCY
|
||||||
#if defined PERIODIC_FREQUENCY
|
#if defined PERIODIC_FREQUENCY
|
||||||
#define SYS_TIME_RESOLUTION ( 1./(2*PERIODIC_FREQUENCY) )
|
#define SYS_TIME_FREQUENCY (2 * PERIODIC_FREQUENCY)
|
||||||
#else
|
#else
|
||||||
#define SYS_TIME_RESOLUTION ( 1./1000. )
|
#define SYS_TIME_FREQUENCY 1000
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -67,9 +71,9 @@ struct sys_time {
|
|||||||
volatile uint32_t nb_tick; ///< SYS_TIME_TICKS since startup
|
volatile uint32_t nb_tick; ///< SYS_TIME_TICKS since startup
|
||||||
struct sys_time_timer timer[SYS_TIME_NB_TIMER];
|
struct sys_time_timer timer[SYS_TIME_NB_TIMER];
|
||||||
|
|
||||||
float resolution_sec; ///< sys_time_timer resolution in seconds
|
float resolution; ///< sys_time_timer resolution in seconds
|
||||||
|
uint32_t ticks_per_sec; ///< sys_time ticks per second (SYS_TIME_FREQUENCY)
|
||||||
uint32_t resolution_cpu_ticks; ///< sys_time_timer resolution in cpu ticks
|
uint32_t resolution_cpu_ticks; ///< sys_time_timer resolution in cpu ticks
|
||||||
uint32_t ticks_per_sec; ///< sys_time ticks per second
|
|
||||||
uint32_t cpu_ticks_per_sec; ///< cpu ticks per second
|
uint32_t cpu_ticks_per_sec; ///< cpu ticks per second
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -137,7 +141,7 @@ static inline uint32_t sys_time_ticks_of_usec(uint32_t usec) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline float sec_of_sys_time_ticks(uint32_t ticks) {
|
static inline float sec_of_sys_time_ticks(uint32_t ticks) {
|
||||||
return (float)ticks * sys_time.resolution_sec;
|
return (float)ticks * sys_time.resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32_t msec_of_sys_time_ticks(uint32_t ticks) {
|
static inline uint32_t msec_of_sys_time_ticks(uint32_t ticks) {
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ extern struct GpsTimeSync gps_time_sync;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert time in sys_time ticks to GPS time of week.
|
* Convert time in sys_time ticks to GPS time of week.
|
||||||
* The resolution depends on #SYS_TIME_RESOLUTION
|
* The resolution is sys_time.resolution
|
||||||
* @return GPS tow in ms
|
* @return GPS tow in ms
|
||||||
*/
|
*/
|
||||||
extern uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks);
|
extern uint32_t gps_tow_from_sys_ticks(uint32_t sys_ticks);
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
#include "nps_flightgear.h"
|
#include "nps_flightgear.h"
|
||||||
|
|
||||||
#include "mcu_periph/sys_time.h"
|
#include "mcu_periph/sys_time.h"
|
||||||
#define SIM_DT (SYS_TIME_RESOLUTION)
|
#define SIM_DT (1./SYS_TIME_FREQUENCY)
|
||||||
#define DISPLAY_DT (1./30.)
|
#define DISPLAY_DT (1./30.)
|
||||||
#define HOST_TIMEOUT_MS 40
|
#define HOST_TIMEOUT_MS 40
|
||||||
#define HOST_TIME_FACTOR 1.
|
#define HOST_TIME_FACTOR 1.
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ static void sim_init(void) {
|
|||||||
// main AP init (feed the sensors once before ?)
|
// main AP init (feed the sensors once before ?)
|
||||||
sim_autopilot_init();
|
sim_autopilot_init();
|
||||||
|
|
||||||
printf("sys_time resolution: %f\n", SYS_TIME_RESOLUTION);
|
printf("sys_time frequency: %f\n", SYS_TIME_FREQUENCY);
|
||||||
printf("sys_time period in msec: %d\n", SYSTIME_PERIOD);
|
printf("sys_time period in msec: %d\n", SYSTIME_PERIOD);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#define DT (JSBSIM_PERIOD*1e-3) ///< JSBSim timestep in seconds
|
#define DT (JSBSIM_PERIOD*1e-3) ///< JSBSim timestep in seconds
|
||||||
|
|
||||||
#define SYSTIME_PERIOD ((uint32_t)(SYS_TIME_RESOLUTION * 1000)) ///< in msec
|
#define SYSTIME_PERIOD ((uint32_t)(1000. / SYS_TIME_FREQUENCY)) ///< in msec
|
||||||
|
|
||||||
#define RAD2DEG 57.29578
|
#define RAD2DEG 57.29578
|
||||||
#define FT2M 0.3048
|
#define FT2M 0.3048
|
||||||
|
|||||||
Reference in New Issue
Block a user