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 
00053     ISR_PROTO_CONTEXT_SWITCH(timer_handler);
00054 
00055     void timer_hw_init(void)
00056     {
00057         sysirq_init();
00058 
00059         cpu_flags_t flags;
00060 
00061         MOD_CHECK(sysirq);
00062 
00063         IRQ_SAVE_DISABLE(flags);
00064 
00065         PIT_MR = TIMER_HW_CNT;
00066         /* Register system interrupt handler. */
00067         sysirq_setHandler(SYSIRQ_PIT, timer_handler);
00068 
00069         /* Enable interval timer and interval timer interrupts */
00070         PIT_MR |= BV(PITEN);
00071         sysirq_setEnable(SYSIRQ_PIT, true);
00072 
00073         /* Reset counters, this is needed to start timer and interrupt flags */
00074         uint32_t dummy = PIVR;
00075         (void) dummy;
00076 
00077         IRQ_RESTORE(flags);
00078     }
00079 
00080 #else
00081     #error Unimplemented value for CONFIG_TIMER
00082 #endif /* CONFIG_TIMER */