From: batt Date: Fri, 17 Apr 2009 15:15:31 +0000 (+0000) Subject: Refactor timer to not include cpu specific C files. X-Git-Tag: 2.1.0~136 X-Git-Url: https://codewiz.org/gitweb?p=bertos.git;a=commitdiff_plain;h=2c5f3d04467211d59b9387abe73c1f286ea74806 Refactor timer to not include cpu specific C files. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2546 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/drv/timer_at91.c b/bertos/cpu/arm/drv/timer_at91.c index b3db6a0f..f1c2887e 100644 --- a/bertos/cpu/arm/drv/timer_at91.c +++ b/bertos/cpu/arm/drv/timer_at91.c @@ -49,19 +49,8 @@ /** HW dependent timer initialization */ #if (CONFIG_TIMER == TIMER_ON_PIT) - INLINE void timer_hw_irq(void) - { - /* Reset counters, this is needed to reset timer and interrupt flags */ - uint32_t dummy = PIVR; - (void) dummy; - } - - INLINE bool timer_hw_triggered(void) - { - return PIT_SR & BV(PITS); - } - INLINE void timer_hw_init(void) + void timer_hw_init(void) { sysirq_init(); @@ -86,12 +75,6 @@ IRQ_RESTORE(flags); } - INLINE hptime_t timer_hw_hpread(void) - { - /* In the upper part of PIT_PIIR there is unused data */ - return PIIR & CPIV_MASK; - } - #else #error Unimplemented value for CONFIG_TIMER #endif /* CONFIG_TIMER */ diff --git a/bertos/cpu/arm/drv/timer_at91.h b/bertos/cpu/arm/drv/timer_at91.h index eca205c5..54ba6e37 100644 --- a/bertos/cpu/arm/drv/timer_at91.h +++ b/bertos/cpu/arm/drv/timer_at91.h @@ -40,10 +40,13 @@ #ifndef DRV_AT91_TIMER_H #define DRV_AT91_TIMER_H -#include /* CPU_FREQ */ +#include /* CPU_FREQ */ #include "cfg/cfg_timer.h" /* CONFIG_TIMER */ #include /* uint8_t */ +#include /* BV */ + +#include /** * \name Values for CONFIG_TIMER. @@ -70,12 +73,33 @@ /** Frequency of the hardware high-precision timer. */ #define TIMER_HW_HPTICKS_PER_SEC (CPU_FREQ / 16) - /// Type of time expressed in ticks of the hardware high-precision timer + /** Type of time expressed in ticks of the hardware high-precision timer */ typedef uint32_t hptime_t; + + INLINE void timer_hw_irq(void) + { + /* Reset counters, this is needed to reset timer and interrupt flags */ + uint32_t dummy = PIVR; + (void) dummy; + } + + INLINE bool timer_hw_triggered(void) + { + return PIT_SR & BV(PITS); + } + + INLINE hptime_t timer_hw_hpread(void) + { + /* In the upper part of PIT_PIIR there is unused data */ + return PIIR & CPIV_MASK; + } + #else #error Unimplemented value for CONFIG_TIMER #endif /* CONFIG_TIMER */ +void timer_hw_init(void); + #endif /* DRV_TIMER_AT91_H */ diff --git a/bertos/cpu/avr/drv/timer_avr.c b/bertos/cpu/avr/drv/timer_avr.c index 49209347..53a5c007 100644 --- a/bertos/cpu/avr/drv/timer_avr.c +++ b/bertos/cpu/avr/drv/timer_avr.c @@ -48,7 +48,6 @@ #include #include -#include #include #if CPU_AVR_ATMEGA1281 || CPU_AVR_ATMEGA168 @@ -118,7 +117,7 @@ /** HW dependent timer initialization */ #if (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE0) - static void timer_hw_init(void) + void timer_hw_init(void) { cpu_flags_t flags; IRQ_SAVE_DISABLE(flags); @@ -149,14 +148,9 @@ IRQ_RESTORE(flags); } - INLINE hptime_t timer_hw_hpread(void) - { - return TCNT0; - } - #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW1) - static void timer_hw_init(void) + void timer_hw_init(void) { cpu_flags_t flags; IRQ_SAVE_DISABLE(flags); @@ -188,13 +182,8 @@ IRQ_RESTORE(flags); } - INLINE hptime_t timer_hw_hpread(void) - { - return TCNT1; - } - #elif (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE2) - static void timer_hw_init(void) + void timer_hw_init(void) { cpu_flags_t flags; IRQ_SAVE_DISABLE(flags); @@ -225,13 +214,9 @@ IRQ_RESTORE(flags); } - INLINE hptime_t timer_hw_hpread(void) - { - return TCNT2; - } #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW3) - static void timer_hw_init(void) + void timer_hw_init(void) { cpu_flags_t flags; IRQ_SAVE_DISABLE(flags); @@ -264,11 +249,6 @@ IRQ_RESTORE(flags); } - INLINE hptime_t timer_hw_hpread(void) - { - return TCNT3; - } - #else #error Unimplemented value for CONFIG_TIMER #endif /* CONFIG_TIMER */ diff --git a/bertos/cpu/avr/drv/timer_avr.h b/bertos/cpu/avr/drv/timer_avr.h index 96d05082..89d0dd76 100644 --- a/bertos/cpu/avr/drv/timer_avr.h +++ b/bertos/cpu/avr/drv/timer_avr.h @@ -43,12 +43,14 @@ #ifndef DRV_TIMER_AVR_H #define DRV_TIMER_AVR_H -#include /* CPU_FREQ */ +#include /* CPU_FREQ */ -#include "cfg/cfg_timer.h" /* CONFIG_TIMER */ -#include /* uint8_t */ -#include /* DIV_ROUND */ +#include "cfg/cfg_timer.h" /* CONFIG_TIMER */ +#include /* uint8_t */ +#include /* DIV_ROUND */ +#include +#include /** * \name Values for CONFIG_TIMER. @@ -82,6 +84,11 @@ /// Type of time expressed in ticks of the hardware high-precision timer typedef uint8_t hptime_t; + INLINE hptime_t timer_hw_hpread(void) + { + return TCNT0; + } + #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW1) #define TIMER_PRESCALER 1 @@ -94,6 +101,11 @@ /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; + INLINE hptime_t timer_hw_hpread(void) + { + return TCNT1; + } + #elif (CONFIG_TIMER == TIMER_ON_OUTPUT_COMPARE2) #define TIMER_PRESCALER 64 @@ -107,10 +119,14 @@ /** Value for OCR register in output-compare based timers. */ #define TIMER_HW_CNT OCR_DIVISOR - /// Type of time expressed in ticks of the hardware high precision timer typedef uint8_t hptime_t; + INLINE hptime_t timer_hw_hpread(void) + { + return TCNT2; + } + #elif (CONFIG_TIMER == TIMER_ON_OVERFLOW3) #define TIMER_PRESCALER 1 @@ -122,6 +138,12 @@ /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; + + INLINE hptime_t timer_hw_hpread(void) + { + return TCNT3; + } + #else #error Unimplemented value for CONFIG_TIMER @@ -143,5 +165,6 @@ /** Not needed, timer IRQ handler called only for timer source */ #define timer_hw_triggered() (true) +void timer_hw_init(void); #endif /* DRV_TIMER_AVR_H */ diff --git a/bertos/drv/timer.c b/bertos/drv/timer.c index 7e99d78e..694b37ee 100644 --- a/bertos/drv/timer.c +++ b/bertos/drv/timer.c @@ -58,8 +58,6 @@ #if OS_HOSTED //#include OS_CSOURCE(timer) #include -#else - #include CPU_CSOURCE(timer) #endif /*