From 8baedd5c716fca8f63e9c9b2e64071f12c29dc9d Mon Sep 17 00:00:00 2001 From: batt Date: Wed, 2 Sep 2009 15:16:09 +0000 Subject: [PATCH] Fix error on short hptime_t CPU. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@2863 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/arm/drv/timer_at91.h | 1 + bertos/cpu/avr/drv/timer_avr.h | 4 ++++ bertos/drv/timer.h | 2 ++ bertos/drv/timer_test.c | 4 +++- bertos/emul/timer_qt.h | 1 + bertos/os/hptime.h | 2 ++ 6 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bertos/cpu/arm/drv/timer_at91.h b/bertos/cpu/arm/drv/timer_at91.h index 54ba6e37..8666893c 100644 --- a/bertos/cpu/arm/drv/timer_at91.h +++ b/bertos/cpu/arm/drv/timer_at91.h @@ -75,6 +75,7 @@ /** Type of time expressed in ticks of the hardware high-precision timer */ typedef uint32_t hptime_t; + #define SIZEOF_HPTIME_T 4 INLINE void timer_hw_irq(void) { diff --git a/bertos/cpu/avr/drv/timer_avr.h b/bertos/cpu/avr/drv/timer_avr.h index 89d0dd76..1288057f 100644 --- a/bertos/cpu/avr/drv/timer_avr.h +++ b/bertos/cpu/avr/drv/timer_avr.h @@ -83,6 +83,7 @@ /// Type of time expressed in ticks of the hardware high-precision timer typedef uint8_t hptime_t; + #define SIZEOF_HPTIME_T 1 INLINE hptime_t timer_hw_hpread(void) { @@ -100,6 +101,7 @@ /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; + #define SIZEOF_HPTIME_T 2 INLINE hptime_t timer_hw_hpread(void) { @@ -121,6 +123,7 @@ /// Type of time expressed in ticks of the hardware high precision timer typedef uint8_t hptime_t; + #define SIZEOF_HPTIME_T 1 INLINE hptime_t timer_hw_hpread(void) { @@ -138,6 +141,7 @@ /// Type of time expressed in ticks of the hardware high precision timer typedef uint16_t hptime_t; + #define SIZEOF_HPTIME_T 2 INLINE hptime_t timer_hw_hpread(void) { diff --git a/bertos/drv/timer.h b/bertos/drv/timer.h index a81b96f3..40802b54 100644 --- a/bertos/drv/timer.h +++ b/bertos/drv/timer.h @@ -70,6 +70,8 @@ #include CPU_HEADER(timer) #endif +STATIC_ASSERT(sizeof(hptime_t) == SIZEOF_HPTIME_T); + #include "cfg/cfg_timer.h" #include #include diff --git a/bertos/drv/timer_test.c b/bertos/drv/timer_test.c index 19522768..c3414d79 100644 --- a/bertos/drv/timer_test.c +++ b/bertos/drv/timer_test.c @@ -68,7 +68,9 @@ static void timer_test_constants(void) kprintf("ticks_to_us(10000) = %lu\n", (unsigned long)ticks_to_us(10000)); kprintf("\n"); kprintf("hptime_to_us(100) = %lu\n", (unsigned long)hptime_to_us(100)); - kprintf("hptime_to_us(10000)= %lu\n", (unsigned long)hptime_to_us(10000)); + #if (SIZEOF_HPTIME_T > 1) + kprintf("hptime_to_us(10000)= %lu\n", (unsigned long)hptime_to_us(10000)); + #endif kprintf("us_to_hptime(100) = %lu\n", (unsigned long)us_to_hptime(100)); kprintf("us_to_hptime(10000)= %lu\n", (unsigned long)us_to_hptime(10000)); } diff --git a/bertos/emul/timer_qt.h b/bertos/emul/timer_qt.h index bf02773c..70650bae 100644 --- a/bertos/emul/timer_qt.h +++ b/bertos/emul/timer_qt.h @@ -47,6 +47,7 @@ /// Type of time expressed in ticks of the hardware high-precision timer. typedef unsigned int hptime_t; +#define SIZEOF_HPTIME_T 4 /// Frequency of the hardware high-precision timer. #define TIMER_HW_HPTICKS_PER_SEC 1000 diff --git a/bertos/os/hptime.h b/bertos/os/hptime.h index 0592bd3b..d7699d0e 100644 --- a/bertos/os/hptime.h +++ b/bertos/os/hptime.h @@ -45,6 +45,7 @@ extern "C" { /** our type for "high precision absolute time" */ typedef __int64 hptime_t; + #define SIZEOF_HPTIME_T 8 #define HPTIME_TICKS_PER_SECOND (10000000I64) #define HPTIME_TICKS_PER_MILLISEC (10000I64) @@ -63,6 +64,7 @@ extern "C" { /** Type for "high precision absolute time". */ typedef int64_t hptime_t; + #define SIZEOF_HPTIME_T 8 #define HPTIME_TICKS_PER_SECOND (1000000LL) #define HPTIME_TICKS_PER_MILLISEC (1000LL) -- 2.25.1