diff options
Diffstat (limited to 'nuttx/arch/c5471/src/up_timerisr.c')
-rw-r--r-- | nuttx/arch/c5471/src/up_timerisr.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/nuttx/arch/c5471/src/up_timerisr.c b/nuttx/arch/c5471/src/up_timerisr.c index b636d1084..ab1155b71 100644 --- a/nuttx/arch/c5471/src/up_timerisr.c +++ b/nuttx/arch/c5471/src/up_timerisr.c @@ -41,7 +41,30 @@ #include <sys/types.h> #include <debug.h> #include <nuttx/arch.h> +#include "clock_internal.h" #include "up_internal.h" +#include "c5471.h" + +/************************************************************ + * Definitions + ************************************************************/ + +/* We want the general purpose timer running at the rate + * MSEC_PER_TICK. The C5471 clock is 47.5MHz and we're using + * a timer PTV value of 3 (3 == divide incoming frequency by + * 16) which then yields a 16 bitCLKS_PER_INT value + * of 29687. + * + * 47500000 / 16 = 2968750 clocks/sec + * 2968750 / 100 = 29687 clocks/ 100Hz interrupt + * + */ + +#define CLKS_PER_INT 29687 +#define CLKS_PER_INT_SHIFT 5 +#define AR 0x00000010 +#define ST 0x00000008 +#define PTV 0x00000003 /************************************************************ * Private Types @@ -91,3 +114,23 @@ int up_timerisr(int irq, uint32 *regs) current_regs = saved_regs; return 0; } + +void up_timerinit(void) +{ + uint32 val; + + up_disable_irq(C5471_IRQ_SYSTIMER); + + /* Start the general purpose timer running in auto-reload mode + * so that an interrupt is generated at the rate MSEC_PER_TICK. + */ + + val = ((CLKS_PER_INT-1) << CLKS_PER_INT_SHIFT) | AR | ST | PTV; + putreg32(val, C5471_TIMER2_CTRL); + + /* Attach and enable the timer interrupt */ + + irq_attach(C5471_IRQ_SYSTIMER, (xcpt_t)up_timerisr); + up_enable_irq(C5471_IRQ_SYSTIMER); +} + |