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         sysirq_init();
00067 
00068         cpu_flags_t flags;
00069 
00070         MOD_CHECK(sysirq);
00071 
00072         IRQ_SAVE_DISABLE(flags);
00073 
00074         PIT_MR = TIMER_HW_CNT;
00075         /* Register system interrupt handler. */
00076         sysirq_setHandler(SYSIRQ_PIT, timer_handler);
00077 
00078         /* Enable interval timer and interval timer interrupts */
00079         PIT_MR |= BV(PITEN);
00080         sysirq_setEnable(SYSIRQ_PIT, true);
00081 
00082         /* Reset counters, this is needed to start timer and interrupt flags */
00083         uint32_t dummy = PIVR;
00084         (void) dummy;
00085 
00086         IRQ_RESTORE(flags);
00087     }
00088 
00089     INLINE hptime_t timer_hw_hpread(void)
00090     {
00091         /* In the upper part of PIT_PIIR there is unused data */
00092         return PIIR & CPIV_MASK;
00093     }
00094 
00095 #else
00096     #error Unimplemented value for CONFIG_TIMER
00097 #endif /* CONFIG_TIMER */