2008-02-05 04:43:19 +00:00
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "avic-imx31.h"
|
2007-09-21 15:51:53 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
extern void (*tick_funcs[MAX_NUM_TICK_TASKS])(void);
|
|
|
|
|
2008-02-05 04:43:19 +00:00
|
|
|
static __attribute__((interrupt("IRQ"))) void EPIT1_HANDLER(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
EPITSR1 = 1; /* Clear the pending status */
|
|
|
|
|
2007-09-21 15:51:53 +00:00
|
|
|
/* Run through the list of tick tasks */
|
2008-02-05 04:43:19 +00:00
|
|
|
for(i = 0;i < MAX_NUM_TICK_TASKS;i++)
|
2007-09-21 15:51:53 +00:00
|
|
|
{
|
|
|
|
if(tick_funcs[i])
|
|
|
|
tick_funcs[i]();
|
|
|
|
}
|
|
|
|
|
|
|
|
current_tick++;
|
|
|
|
}
|
2008-02-05 04:43:19 +00:00
|
|
|
|
|
|
|
void tick_start(unsigned int interval_in_ms)
|
|
|
|
{
|
2008-02-08 02:20:05 +00:00
|
|
|
CLKCTL_CGR0 |= (3 << 6); /* EPIT1 module clock ON - before writing regs! */
|
|
|
|
EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable the counter */
|
2008-02-05 04:43:19 +00:00
|
|
|
CLKCTL_WIMR0 &= ~(1 << 23); /* Clear wakeup mask */
|
|
|
|
|
|
|
|
/* NOTE: This isn't really accurate yet but it's close enough to work
|
|
|
|
* with for the moment */
|
|
|
|
|
|
|
|
/* CLKSRC=32KHz, EPIT Output Disconnected, Enabled
|
|
|
|
* prescale 1/32, Reload from modulus register, Compare interrupt enabled,
|
|
|
|
* Count from load value */
|
2008-02-08 02:20:05 +00:00
|
|
|
EPITCR1 = (3 << 24) | (1 << 19) | (32 << 4) |
|
2008-02-05 04:43:19 +00:00
|
|
|
(1 << 3) | (1 << 2) | (1 << 1);
|
|
|
|
|
2008-02-08 02:20:05 +00:00
|
|
|
EPITLR1 = interval_in_ms; /* Count down from interval */
|
|
|
|
EPITCMPR1 = 0; /* Event when counter reaches 0 */
|
|
|
|
EPITSR1 = 1; /* Clear any pending interrupt */
|
|
|
|
avic_enable_int(EPIT1, IRQ, 7, EPIT1_HANDLER);
|
2008-02-05 04:43:19 +00:00
|
|
|
EPITCR1 |= (1 << 0); /* Enable the counter */
|
|
|
|
}
|
2008-02-08 02:20:05 +00:00
|
|
|
|
|
|
|
#ifdef BOOTLOADER
|
|
|
|
void tick_stop(void)
|
|
|
|
{
|
|
|
|
avic_disable_int(EPIT1); /* Disable insterrupt */
|
|
|
|
EPITCR1 &= ~((1 << 2) | (1 << 0)); /* Disable counter */
|
|
|
|
CLKCTL_CGR0 &= ~(3 << 6); /* EPIT1 module clock OFF */
|
|
|
|
}
|
|
|
|
#endif
|