From 5b8c7d324c8934f7686aeb4c23454cebbfd1f83f Mon Sep 17 00:00:00 2001 From: arighi Date: Tue, 30 Mar 2010 10:38:45 +0000 Subject: [PATCH] lm3s1968: integrate the hardware timer driver into the main timer module. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3323 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/timer_lm3s.c | 13 +++------ bertos/cpu/cortex-m3/drv/timer_lm3s.h | 33 +++++++++++++++++++++++ bertos/cpu/irq.h | 5 ++++ examples/lm3s1968/lm3s1968.c | 39 ++++++++++++++++++--------- examples/lm3s1968/lm3s1968.mk | 6 ++++- 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/bertos/cpu/cortex-m3/drv/timer_lm3s.c b/bertos/cpu/cortex-m3/drv/timer_lm3s.c index 2d6ee89a..ed432e9f 100644 --- a/bertos/cpu/cortex-m3/drv/timer_lm3s.c +++ b/bertos/cpu/cortex-m3/drv/timer_lm3s.c @@ -42,17 +42,12 @@ #include "irq_lm3s.h" #include "timer_lm3s.h" -unsigned long ticks; +ISR_PROTO_CONTEXT_SWITCH(timer_handler); INLINE void timer_hw_setPeriod(unsigned long period) { ASSERT(period < (1 << 24)); - HWREG(NVIC_ST_RELOAD) = period; -} - -static void timer_hw_handler(void) -{ - ticks++; + HWREG(NVIC_ST_RELOAD) = period - 1; } static void timer_hw_enable(void) @@ -68,8 +63,8 @@ static void timer_hw_disable(void) void timer_hw_init(void) { - timer_hw_setPeriod(1000000); - sysirq_setHandler(FAULT_SYSTICK, timer_hw_handler); + timer_hw_setPeriod(CPU_FREQ / TIMER_TICKS_PER_SEC); + sysirq_setHandler(FAULT_SYSTICK, timer_handler); timer_hw_enable(); } diff --git a/bertos/cpu/cortex-m3/drv/timer_lm3s.h b/bertos/cpu/cortex-m3/drv/timer_lm3s.h index 53fdd02f..e14cf390 100644 --- a/bertos/cpu/cortex-m3/drv/timer_lm3s.h +++ b/bertos/cpu/cortex-m3/drv/timer_lm3s.h @@ -38,6 +38,39 @@ #ifndef DRV_CORTEX_M3_TIMER_H #define DRV_CORTEX_M3_TIMER_H +#include + +/* Ticks frequency (HZ) */ +#define TIMER_TICKS_PER_SEC 1000 + +/* Frequency of the hardware high-precision timer. */ +#define TIMER_HW_HPTICKS_PER_SEC (CPU_FREQ) + +/* Maximum value of the high-precision hardware counter register */ +#define TIMER_HW_CNT (CPU_FREQ / TIMER_TICKS_PER_SEC) + +/** Type of time expressed in ticks of the hardware high-precision timer */ +typedef uint32_t hptime_t; +#define SIZEOF_HPTIME_T 4 + +/* Timer ISR prototype */ +#define DEFINE_TIMER_ISR void timer_handler(void); \ + void timer_handler(void) + +INLINE void timer_hw_irq(void) +{ +} + +INLINE bool timer_hw_triggered(void) +{ + return true; +} + +INLINE hptime_t timer_hw_hpread(void) +{ + return HWREG(NVIC_ST_CURRENT); +} + void timer_hw_init(void); void timer_hw_exit(void); diff --git a/bertos/cpu/irq.h b/bertos/cpu/irq.h index 462034fe..3a2dab5b 100644 --- a/bertos/cpu/irq.h +++ b/bertos/cpu/irq.h @@ -95,6 +95,11 @@ #define IRQ_ENABLED() (!CPU_READ_FLAGS()) + /* TODO: context switch is not yet supported */ + #define DECLARE_ISR_CONTEXT_SWITCH(func) void func(void) + + /* TODO: context switch is not yet supported */ + #define ISR_PROTO_CONTEXT_SWITCH(func) void func(void) #elif CPU_ARM #ifdef __IAR_SYSTEMS_ICC__ diff --git a/examples/lm3s1968/lm3s1968.c b/examples/lm3s1968/lm3s1968.c index bb9d231d..9dfaf006 100644 --- a/examples/lm3s1968/lm3s1968.c +++ b/examples/lm3s1968/lm3s1968.c @@ -36,16 +36,11 @@ */ #include +#include #include "io/lm3s.h" -#include "drv/timer_lm3s.h" -extern unsigned long ticks; - -int main(void) +static void led_init(void) { - kdbg_init(); - timer_hw_init(); - /* Enable the GPIO port that is used for the on-board LED */ SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOG; /* @@ -56,14 +51,32 @@ int main(void) /* Enable the GPIO pin for the LED */ GPIO_PORTG_DIR_R = 0x04; GPIO_PORTG_DEN_R = 0x04; +} + +static void led_on(void) +{ + GPIO_PORTG_DATA_R |= 0x04; +} + +static void led_off(void) +{ + GPIO_PORTG_DATA_R &= ~0x04; +} + +int main(void) +{ + IRQ_ENABLE; + kdbg_init(); + timer_init(); + led_init(); while(1) { - /* Turn on the LED */ - if ((ticks & 0x04) == 0x04) - GPIO_PORTG_DATA_R |= 0x04; - /* Turn off the LED */ - else if ((ticks & 0x04) == 0) - GPIO_PORTG_DATA_R &= ~0x04; + kputs("STATUS LED: on \r"); + led_on(); + timer_delay(1000); + kputs("STATUS LED: off\r"); + led_off(); + timer_delay(1000); } } diff --git a/examples/lm3s1968/lm3s1968.mk b/examples/lm3s1968/lm3s1968.mk index f3feafb5..b96e7bc9 100644 --- a/examples/lm3s1968/lm3s1968.mk +++ b/examples/lm3s1968/lm3s1968.mk @@ -17,6 +17,10 @@ TRG += lm3s1968 lm3s1968_CSRC = \ examples/lm3s1968/lm3s1968.c \ + bertos/mware/formatwr.c \ + bertos/mware/hex.c \ + bertos/mware/sprintf.c \ + bertos/drv/timer.c \ bertos/cpu/cortex-m3/drv/irq_lm3s.c \ bertos/cpu/cortex-m3/drv/timer_lm3s.c \ bertos/cpu/cortex-m3/drv/clock_lm3s.c \ @@ -27,7 +31,7 @@ lm3s1968_CSRC = \ lm3s1968_PREFIX = arm-none-eabi- lm3s1968_CPPAFLAGS = -O0 -g -gdwarf-2 -g -gen-debug -mthumb -fno-strict-aliasing -fwrapv -lm3s1968_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_LM3S1968__ -D'CPU_FREQ=(50000000L)' -g3 -gdwarf-2 -fverbose-asm -mthumb -Iexamples/lm3s1968 -Ibertos/cpu/cortex-m3 -fno-strict-aliasing -fwrapv +lm3s1968_CPPFLAGS = -O0 -D'ARCH=0' -D__ARM_LM3S1968__ -D'CPU_FREQ=(50000000L)' -D'WIZ_AUTOGEN' -g3 -gdwarf-2 -fverbose-asm -mthumb -Iexamples/lm3s1968 -Ibertos/cpu/cortex-m3 -fno-strict-aliasing -fwrapv lm3s1968_LDFLAGS = -nostartfiles -T bertos/cpu/cortex-m3/scripts/lm3s1968_rom.ld -Wl,--no-warn-mismatch -fno-strict-aliasing -fwrapv lm3s1968_CPU = cortex-m3 -- 2.25.1