diff options
Diffstat (limited to 'nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c')
-rw-r--r-- | nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c b/nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c index 16de968b2..8308200ba 100644 --- a/nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c +++ b/nuttx/arch/arm/src/lpc214x/lpc214x_timerisr.c @@ -41,14 +41,29 @@ #include <sys/types.h> #include <debug.h> #include <nuttx/arch.h> +#include <arch/board/board.h> + #include "clock_internal.h" #include "up_internal.h" #include "up_arch.h" +#include "lpc214x_timer.h" +#include "lpc214x_vic.h" + /************************************************************ * Definitions ************************************************************/ +#define PCLKFREQ (LPC214X_FOSC/4) /* PCLK must be FOSC/4 */ + +#define tmr_getreg8(o) getreg8(LPC214X_TMR0_BASE+(o)) +#define tmr_getreg16(o) getreg16(LPC214X_TMR0_BASE+(o)) +#define tmr_getreg32(o) getreg32(LPC214X_TMR0_BASE+(o)) + +#define tmr_putreg8(o,v) putreg8((v), LPC214X_TMR0_BASE+(o)) +#define tmr_putreg16(o,v) putreg16((v), LPC214X_TMR0_BASE+(o)) +#define tmr_putreg32(o,v) putreg32((v), LPC214X_TMR0_BASE+(o)) + /************************************************************ * Private Types ************************************************************/ @@ -70,11 +85,25 @@ * ************************************************************/ +#ifdef CONFIG_VECTORED_INTERRUPTS +int up_timerisr(uint32 *regs) +#else int up_timerisr(int irq, uint32 *regs) +#endif { /* Process timer interrupt */ sched_process_timer(); + + /* Clear the MR0 match interrupt */ + + tmr_putreg8(LPC214X_TMR_IR_MR0I, LPC214X_TMR_IR_OFFSET); + + /* Reset the VIC as well */ + +#ifdef CONFIG_VECTORED_INTERRUPTS + vic_putreg(0, LPC214X_VIC_VECTADDR_OFFSET); +#endif return 0; } @@ -89,6 +118,45 @@ int up_timerisr(int irq, uint32 *regs) void up_timerinit(void) { -#warning "Not implemented" -} + uint16 mcr; + + /* Clear all match and capture event interrupts */ + + tmr_putreg8(LPC214X_TMR_IR_ALLI, LPC214X_TMR_IR_OFFSET); + + /* Clear the timer counter */ + tmr_putreg32(0, LPC214X_TMR_TC_OFFSET); + + /* No pre-scaler */ + + tmr_putreg32(0, LPC214X_TMR_PR_OFFSET); + + /* Set timer match registger to get a TICK_PER_SEC rate + * See arch/board.h and sched/os_internal.h + */ + + tmr_putreg32(LPC214X_PCLKFREQ/TICK_PER_SEC, LPC214X_TMR_MR0_OFFSET); + + /* Reset timer counter regiser and interrupt on match */ + mcr = tmr_getreg16(LPC214X_TMR_MCR_OFFSET); + mcr &= ~LPC214X_TMR_MCR_MR1I; + mcr |= (LPC214X_TMR_MCR_MR0I | LPC214X_TMR_MCR_MR0R); + tmr_putreg16(mcr, LPC214X_TMR_MCR_OFFSET); + + /* Enable counting */ + + tmr_putreg8(LPC214X_TMR_CR_ENABLE, LPC214X_TMR_TCR_OFFSET); + + /* Attach the timer interrupt vector */ + +#ifdef CONFIG_VECTORED_INTERRUPTS + up_attach_vector(LPC214X_IRQ_SYSTIMER, LPC214X_SYSTEMER_VEC, (vic_vector_t)up_timerisr); +#else + (void)irq_attach(LPC214X_IRQ_SYSTIMER, (xcpt_t)up_timerisr); +#endif + + /* And enable the timer interrupt */ + + up_enable_irq(LPC214X_IRQ_SYSTIMER); +} |