X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=drv%2Fat91%2Ftimer.c;h=a06e44711d6aeecb50b10af60a83c42ab02334be;hb=77c1d6ba65a199f60faa0e0a68e63ef0eb87677c;hp=2b396fa1a56d0cc4e02361b61715ad3701441840;hpb=338e860b340dd66f9f6ec92e692a7aa116b0d6a8;p=bertos.git diff --git a/drv/at91/timer.c b/drv/at91/timer.c old mode 100755 new mode 100644 index 2b396fa1..a06e4471 --- a/drv/at91/timer.c +++ b/drv/at91/timer.c @@ -1,6 +1,31 @@ /** * \file * @@ -12,37 +37,48 @@ * \brief Low-level timer module for Atmel AT91 (inplementation). */ -#include -#include // BV() +#include "timer.h" +#include "at91sam7s.h" +#include "sysirq.h" +#include // BV() +#include #include /** HW dependent timer initialization */ #if (CONFIG_TIMER == TIMER_ON_PIT) - #warning Very untested! - INLINE static void timer_hw_irq(void) + INLINE void timer_hw_irq(void) { - /* Reset counters, this is needed to start timer and interrupt flags */ - volatile uint32_t dummy = PIT_PIVR; + /* Reset counters, this is needed to reset timer and interrupt flags */ + uint32_t dummy = PIVR; + (void) dummy; } + INLINE bool timer_hw_triggered(void) + { + return PIT_SR & BV(PITS); + } - static void timer_hw_init(void) + INLINE void timer_hw_init(void) { cpuflags_t flags; + + MOD_CHECK(sysirq); + IRQ_SAVE_DISABLE(flags); - PIT_MR = CLOCK_FREQ / (16 * TIMER_TICKS_PER_SEC) - 1; + PIT_MR = TIMER_HW_CNT; /* Register system interrupt handler. */ sysirq_setHandler(SYSIRQ_PIT, timer_handler); /* Enable interval timer and interval timer interrupts */ - PIT_MR |= BV(PIT_PITEN); + PIT_MR |= BV(PITEN); sysirq_setEnable(SYSIRQ_PIT, true); /* Reset counters, this is needed to start timer and interrupt flags */ - volatile uint32_t dummy = PIT_PIVR; + uint32_t dummy = PIVR; + (void) dummy; IRQ_RESTORE(flags); } @@ -50,7 +86,7 @@ INLINE hptime_t timer_hw_hpread(void) { /* In the upper part of PIT_PIIR there is unused data */ - return PIT_PIIR & 0xfffff; + return PIIR & CPIV_MASK; } #else