BeRTOS
timer_at91.c
Go to the documentation of this file.
00001 
00038 #include "timer_at91.h"
00039 #include <io/arm.h>
00040 #include "sysirq_at91.h"
00041 
00042 #include <cfg/macros.h> // BV()
00043 #include <cfg/module.h>
00044 #include <cpu/irq.h>
00045 #include <cpu/types.h>
00046 
00047 
00049 #if (CONFIG_TIMER == TIMER_ON_PIT)
00050 
00051     ISR_PROTO_CONTEXT_SWITCH(timer_handler);
00052 
00053     void timer_hw_init(void)
00054     {
00055         sysirq_init();
00056 
00057         cpu_flags_t flags;
00058 
00059         MOD_CHECK(sysirq);
00060 
00061         IRQ_SAVE_DISABLE(flags);
00062 
00063         PIT_MR = TIMER_HW_CNT;
00064         /* Register system interrupt handler. */
00065         sysirq_setHandler(SYSIRQ_PIT, timer_handler);
00066 
00067         /* Enable interval timer and interval timer interrupts */
00068         PIT_MR |= BV(PITEN);
00069         sysirq_setEnable(SYSIRQ_PIT, true);
00070 
00071         /* Reset counters, this is needed to start timer and interrupt flags */
00072         uint32_t dummy = PIVR;
00073         (void) dummy;
00074 
00075         IRQ_RESTORE(flags);
00076     }
00077 
00078 #else
00079     #error Unimplemented value for CONFIG_TIMER
00080 #endif /* CONFIG_TIMER */