timer_at91.h

Go to the documentation of this file.
00001 
00040 #ifndef DRV_AT91_TIMER_H
00041 #define DRV_AT91_TIMER_H
00042 
00043 #include <hw/hw_cpufreq.h>     /* CPU_FREQ */
00044 
00045 #include "cfg/cfg_timer.h"     /* CONFIG_TIMER */
00046 #include <cfg/compiler.h>      /* uint8_t */
00047 #include <cfg/macros.h>        /* BV */
00048 
00049 #include <io/arm.h>
00050 
00058 #define TIMER_ON_PIT 1  
00059 
00060 #define TIMER_DEFAULT TIMER_ON_PIT  
00061 
00062 /*
00063  * Hardware dependent timer initialization.
00064  */
00065 #if (CONFIG_TIMER == TIMER_ON_PIT)
00066 
00067     void timer_handler(void);
00068 
00069     #define DEFINE_TIMER_ISR     void timer_handler(void)
00070     #define TIMER_TICKS_PER_SEC  1000
00071     #define TIMER_HW_CNT         (CPU_FREQ / (16 * TIMER_TICKS_PER_SEC) - 1)
00072 
00074     #define TIMER_HW_HPTICKS_PER_SEC (CPU_FREQ / 16)
00075 
00077     typedef uint32_t hptime_t;
00078 
00079     INLINE void timer_hw_irq(void)
00080     {
00081         /* Reset counters, this is needed to reset timer and interrupt flags */
00082         uint32_t dummy = PIVR;
00083         (void) dummy;
00084     }
00085 
00086     INLINE bool timer_hw_triggered(void)
00087     {
00088         return PIT_SR & BV(PITS);
00089     }
00090 
00091     INLINE hptime_t timer_hw_hpread(void)
00092     {
00093         /* In the upper part of PIT_PIIR there is unused data */
00094         return PIIR & CPIV_MASK;
00095     }
00096 
00097 #else
00098 
00099     #error Unimplemented value for CONFIG_TIMER
00100 #endif /* CONFIG_TIMER */
00101 
00102 void timer_hw_init(void);
00103 
00104 
00105 #endif /* DRV_TIMER_AT91_H */