#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)
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();
}
#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);
#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__
*/
#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;
/*
/* 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);
}
}
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 \
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