From d949b2f3d46c99157ad74d03c31182ba73a35d84 Mon Sep 17 00:00:00 2001 From: Pascal Brisset Date: Tue, 10 Feb 2009 15:14:56 +0000 Subject: [PATCH] chrono macros added --- sw/airborne/arm7/sys_time_hw.c | 3 +++ sw/airborne/arm7/sys_time_hw.h | 35 +++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/sw/airborne/arm7/sys_time_hw.c b/sw/airborne/arm7/sys_time_hw.c index 0dc006aaab..9fbca934cd 100644 --- a/sw/airborne/arm7/sys_time_hw.c +++ b/sw/airborne/arm7/sys_time_hw.c @@ -4,6 +4,9 @@ uint32_t cpu_time_ticks; uint32_t last_periodic_event; +uint32_t sys_time_chrono_start; /* T0TC ticks */ +uint32_t sys_time_chrono; /* T0TC ticks */ + #if defined ACTUATORS #include ACTUATORS #endif /* ACTUATORS */ diff --git a/sw/airborne/arm7/sys_time_hw.h b/sw/airborne/arm7/sys_time_hw.h index 924b00f198..d7b1a2a0e9 100644 --- a/sw/airborne/arm7/sys_time_hw.h +++ b/sw/airborne/arm7/sys_time_hw.h @@ -34,6 +34,7 @@ #include "LPC21xx.h" #include CONFIG #include "led.h" +#include "armVIC.h" extern uint32_t cpu_time_ticks; extern uint32_t last_periodic_event; @@ -44,20 +45,40 @@ void TIMER0_ISR ( void ) __attribute__((naked)); #if (PCLK == 15000000) #define T0_PCLK_DIV 1 -#else -#if (PCLK == 30000000) +#elif (PCLK == 30000000) #define T0_PCLK_DIV 2 -#else -#if (PCLK == 60000000) +#elif (PCLK == 60000000) #define T0_PCLK_DIV 4 -#else +#else #error unknown PCLK frequency #endif -#endif -#endif + +extern uint32_t sys_time_chrono_start; /* T0TC ticks */ +extern uint32_t sys_time_chrono; /* T0TC ticks,frequency: PCLK / T0PCLK_DIV */ +/* A division by SYS_TICS_OF_USEC(1) to get microseconds is too expensive + for time measurement: about 2us */ + +#define SysTimeChronoStart() { sys_time_chrono_start = T0TC; } +#define SysTimeChronoStop() { sys_time_chrono = (T0TC - sys_time_chrono_start); } +/** Usage example, disabling IRQ and scaling to us to send + disableIRQ(); SysTimeChronoStart(); + + SysTimeChronoStop(); enableIRQ(); + sys_time_chrono /=SYS_TICS_OF_USEC(1); + DOWNLINK_SEND_CHRONO(42, &sys_time_chrono); +**/ +#define SysTimeChronoStartDisableIRQ() { disableIRQ(); SysTimeChronoStart(); } +#define SysTimeChronoStopEnableIRQAndSendUS(_tag) { \ + SysTimeChronoStop(); \ + enableIRQ(); \ + sys_time_chrono /=SYS_TICS_OF_USEC(1); \ + DOWNLINK_SEND_CHRONO(_tag, &sys_time_chrono); \ +} + + static inline void sys_time_init( void ) { /* setup Timer 0 to count forever */