timer_at91.c

Go to the documentation of this file.
00001 
00040 #include "timer_at91.h"
00041 #include <io/arm.h>
00042 #include "sysirq_at91.h"
00043 
00044 #include <cfg/macros.h> // BV()
00045 #include <cfg/module.h>
00046 #include <cpu/irq.h>
00047 #include <cpu/types.h>
00048 
00049 
00051 #if (CONFIG_TIMER == TIMER_ON_PIT)
00052     INLINE void timer_hw_irq(void)
00053     {
00054         /* Reset counters, this is needed to reset timer and interrupt flags */
00055         uint32_t dummy = PIVR;
00056         (void) dummy;
00057     }
00058 
00059     INLINE bool timer_hw_triggered(void)
00060     {
00061         return PIT_SR & BV(PITS);
00062     }
00063 
00064     INLINE void timer_hw_init(void)
00065     {
00066         cpuflags_t flags;
00067 
00068         MOD_CHECK(sysirq);
00069 
00070         IRQ_SAVE_DISABLE(flags);
00071 
00072         PIT_MR = TIMER_HW_CNT;
00073         /* Register system interrupt handler. */
00074         sysirq_setHandler(SYSIRQ_PIT, timer_handler);
00075 
00076         /* Enable interval timer and interval timer interrupts */
00077         PIT_MR |= BV(PITEN);
00078         sysirq_setEnable(SYSIRQ_PIT, true);
00079 
00080         /* Reset counters, this is needed to start timer and interrupt flags */
00081         uint32_t dummy = PIVR;
00082         (void) dummy;
00083 
00084         IRQ_RESTORE(flags);
00085     }
00086 
00087     INLINE hptime_t timer_hw_hpread(void)
00088     {
00089         /* In the upper part of PIT_PIIR there is unused data */
00090         return PIIR & CPIV_MASK;
00091     }
00092 
00093 #else
00094     #error Unimplemented value for CONFIG_TIMER
00095 #endif /* CONFIG_TIMER */