BeRTOS
timer_lpc2.h
Go to the documentation of this file.
00001 
00038 #ifndef DRV_LPC2_TIMER_H
00039 #define DRV_LPC2_TIMER_H
00040 
00041 #include <hw/hw_cpufreq.h>     /* CPU_FREQ */
00042 
00043 #include "cfg/cfg_timer.h"     /* CONFIG_TIMER */
00044 #include <cfg/compiler.h>      /* uint8_t */
00045 #include <cfg/macros.h>        /* BV */
00046 
00047 #include <io/lpc23xx.h>
00048 
00056 #define TIMER0_COMPARE0 0  ///< System timer on Timer0 Compare match0
00057 
00058 #define TIMER_DEFAULT TIMER0_COMPARE0  ///< Default system timer
00059 
00060 /*
00061  * Hardware dependent timer initialization.
00062  */
00063 #if (CONFIG_TIMER == TIMER0_COMPARE0)
00064     ISR_PROTO_CONTEXT_SWITCH(timer_handler);
00065     #define DEFINE_TIMER_ISR     DECLARE_ISR_CONTEXT_SWITCH(timer_handler)
00066 
00067     #define TIMER_TICKS_PER_SEC  1000
00068     #define TIMER_HW_CNT         (CPU_FREQ / TIMER_TICKS_PER_SEC - 1)
00069 
00071     #define TIMER_HW_HPTICKS_PER_SEC (CPU_FREQ)
00072 
00074     typedef uint32_t hptime_t;
00075     #define SIZEOF_HPTIME_T 4
00076 
00077     INLINE void timer_hw_irq(void)
00078     {
00079         /* Reset The match0 irq flag */
00080         T0IR = 0x01;
00081         /* Signal the VIC we have completed the ISR */
00082         VICVectAddr = 0;    
00083     }
00084 
00085     INLINE bool timer_hw_triggered(void)
00086     {
00087         return true;
00088     }
00089 
00090     INLINE hptime_t timer_hw_hpread(void)
00091     {
00092         return T0TC;
00093     }
00094 
00095 #else
00096 
00097     #error Unimplemented value for CONFIG_TIMER
00098 #endif /* CONFIG_TIMER */
00099 
00100 void timer_hw_init(void);
00101 
00102 
00103 #endif /* DRV_LPC2_TIMER_H */