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