timer_cm3.c

Go to the documentation of this file.
00001 
00038 #include <cfg/debug.h>
00039 #include <cpu/irq.h>
00040 #include <drv/irq_cm3.h>
00041 #include "timer_cm3.h"
00042 
00043 INLINE void timer_hw_setPeriod(unsigned long period)
00044 {
00045     ASSERT(period < (1 << 24));
00046     NVIC_ST_RELOAD_R = period - 1;
00047 }
00048 
00049 static void timer_hw_enable(void)
00050 {
00051     NVIC_ST_CTRL_R |=
00052         NVIC_ST_CTRL_CLK_SRC | NVIC_ST_CTRL_ENABLE | NVIC_ST_CTRL_INTEN;
00053 }
00054 
00055 static void timer_hw_disable(void)
00056 {
00057     NVIC_ST_CTRL_R &= ~(NVIC_ST_CTRL_ENABLE | NVIC_ST_CTRL_INTEN);
00058 }
00059 
00060 void timer_hw_init(void)
00061 {
00062     timer_hw_setPeriod(CPU_FREQ / TIMER_TICKS_PER_SEC);
00063     sysirq_setHandler(FAULT_SYSTICK, timer_handler);
00064     timer_hw_enable();
00065 }
00066 
00067 void timer_hw_exit(void)
00068 {
00069     timer_hw_disable();
00070     sysirq_freeHandler(FAULT_SYSTICK);
00071 }