From bd4c9a2c047db476ac34649ccf16970ad34343ce Mon Sep 17 00:00:00 2001 From: arighi Date: Fri, 26 Mar 2010 16:12:44 +0000 Subject: [PATCH] lm3s1968: low-level timer driver (systick). git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3279 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/cpu/cortex-m3/drv/timer.c | 80 ++++++++++++++++++++++++++++++++ bertos/cpu/cortex-m3/drv/timer.h | 44 ++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 bertos/cpu/cortex-m3/drv/timer.c create mode 100644 bertos/cpu/cortex-m3/drv/timer.h diff --git a/bertos/cpu/cortex-m3/drv/timer.c b/bertos/cpu/cortex-m3/drv/timer.c new file mode 100644 index 00000000..70135694 --- /dev/null +++ b/bertos/cpu/cortex-m3/drv/timer.c @@ -0,0 +1,80 @@ +/** + * \file + * + * + * \brief Low-level timer driver for LM3S1968. + * + * \author Andrea Righi + */ + +#include +#include +#include "io/lm3s.h" + +#include "irq.h" +#include "timer.h" + +unsigned long ticks; + +INLINE void timer_hw_setPeriod(unsigned long period) +{ + ASSERT(period < (1 << 24)); + HWREG(NVIC_ST_RELOAD) = period; +} + +static void timer_hw_handler(void) +{ + ticks++; +} + +static void timer_hw_enable(void) +{ + HWREG(NVIC_ST_CTRL) |= + NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE | NVIC_ST_CTRL_INTEN; +} + +static void timer_hw_disable(void) +{ + HWREG(NVIC_ST_CTRL) &= ~(NVIC_ST_CTRL_ENABLE | NVIC_ST_CTRL_INTEN); +} + +void timer_hw_init(void) +{ + timer_hw_setPeriod(100000); + sysirq_setHandler(FAULT_SYSTICK, timer_hw_handler); + timer_hw_enable(); +} + +void timer_hw_exit(void) +{ + timer_hw_disable(); + sysirq_freeHandler(FAULT_SYSTICK); +} diff --git a/bertos/cpu/cortex-m3/drv/timer.h b/bertos/cpu/cortex-m3/drv/timer.h new file mode 100644 index 00000000..53fdd02f --- /dev/null +++ b/bertos/cpu/cortex-m3/drv/timer.h @@ -0,0 +1,44 @@ +/** + * \file + * + * + * \brief Low-level timer driver for LM3S1968. + * + * \author Andrea Righi + */ + +#ifndef DRV_CORTEX_M3_TIMER_H +#define DRV_CORTEX_M3_TIMER_H + +void timer_hw_init(void); +void timer_hw_exit(void); + +#endif /* DRV_CORTEX_M3_TIMER_H */ -- 2.25.1