lm3s1968: integrate the hardware timer driver into the main timer module.
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 10:38:45 +0000 (10:38 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Tue, 30 Mar 2010 10:38:45 +0000 (10:38 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3323 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/cpu/cortex-m3/drv/timer_lm3s.c
bertos/cpu/cortex-m3/drv/timer_lm3s.h
bertos/cpu/irq.h
examples/lm3s1968/lm3s1968.c
examples/lm3s1968/lm3s1968.mk

index 2d6ee89ac554519d29e6a5455a6da83548ee0235..ed432e9f6e7b1ef4fa42464997b50159a9d910e2 100644 (file)
 #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();
 }
 
index 53fdd02ffa68f1b82bdfa3ac8a4feb10e35b51ac..e14cf3907fab0e871ee43e681058de00ef0db6d3 100644 (file)
 #ifndef DRV_CORTEX_M3_TIMER_H
 #define DRV_CORTEX_M3_TIMER_H
 
+#include <io/lm3s.h>
+
+/* 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);
 
index 462034fe669e700099ec2c93f37830dae5f34a77..3a2dab5b21beb26aebf7c0c4b3c68269a348fe90 100644 (file)
 
        #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__
index bb9d231dc44c15af21099527b85b16352d88b9ff..9dfaf006a868f1cdb86b2fc2c0ae950c4ffc6466 100644 (file)
  */
 
 #include <cpu/irq.h>
+#include <drv/timer.h>
 #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);
        }
 }
index f3feafb5a06b5cebf9d2e572942f33a45ff2e407..b96e7bc99d349bb2356b66fd62eda28255dc334c 100644 (file)
@@ -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