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     #define SIZEOF_HPTIME_T 4
00079 
00080     INLINE void timer_hw_irq(void)
00081     {
00082         /* Reset counters, this is needed to reset timer and interrupt flags */
00083         uint32_t dummy = PIVR;
00084         (void) dummy;
00085     }
00086 
00087     INLINE bool timer_hw_triggered(void)
00088     {
00089         return PIT_SR & BV(PITS);
00090     }
00091 
00092     INLINE hptime_t timer_hw_hpread(void)
00093     {
00094         /* In the upper part of PIT_PIIR there is unused data */
00095         return PIIR & CPIV_MASK;
00096     }
00097 
00098 #else
00099 
00100     #error Unimplemented value for CONFIG_TIMER
00101 #endif /* CONFIG_TIMER */
00102 
00103 void timer_hw_init(void);
00104 
00105 
00106 #endif /* DRV_TIMER_AT91_H */