1
0
Fork 0
forked from len0rd/rockbox

AS3525: implement tick_start() with TIMER2

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19027 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Rafaël Carré 2008-11-06 14:34:37 +00:00
parent baecdb632c
commit 94c06c7e95
2 changed files with 38 additions and 1 deletions

View file

@ -283,6 +283,14 @@ interface */
#define TIMER1_MIS (*(volatile unsigned long*)(TIMER_BASE + 0x14)) /* 1 bit width */ #define TIMER1_MIS (*(volatile unsigned long*)(TIMER_BASE + 0x14)) /* 1 bit width */
#define TIMER1_BGLOAD (*(volatile unsigned long*)(TIMER_BASE + 0x18)) /* 32-bit width */ #define TIMER1_BGLOAD (*(volatile unsigned long*)(TIMER_BASE + 0x18)) /* 32-bit width */
#define TIMER2_LOAD (*(volatile unsigned long*)(TIMER_BASE + 0x20)) /* 32-bit width */
#define TIMER2_VALUE (*(volatile unsigned long*)(TIMER_BASE + 0x24)) /* 32 bit width */
#define TIMER2_CONTROL (*(volatile unsigned long*)(TIMER_BASE + 0x28)) /* 8 bit width */
#define TIMER2_INTCLR (*(volatile unsigned long*)(TIMER_BASE + 0x2C)) /* clears ir by write access */
#define TIMER2_RIS (*(volatile unsigned long*)(TIMER_BASE + 0x30)) /* 1 bit width */
#define TIMER2_MIS (*(volatile unsigned long*)(TIMER_BASE + 0x34)) /* 1 bit width */
#define TIMER2_BGLOAD (*(volatile unsigned long*)(TIMER_BASE + 0x38)) /* 32-bit width */
/** /**
* Counter/Timer control register bits * Counter/Timer control register bits
**/ **/

View file

@ -21,8 +21,37 @@
#include "config.h" #include "config.h"
#include "system.h" #include "system.h"
#include "kernel.h" #include "kernel.h"
#include "panic.h"
void INT_TIMER2(void)
{
call_tick_tasks(); /* Run through the list of tick tasks */
TIMER2_INTCLR = 0; /* clear interrupt */
}
void tick_start(unsigned int interval_in_ms) void tick_start(unsigned int interval_in_ms)
{ {
(void)interval_in_ms; int phi = 0; /* prescaler bits */
int prescale = 1;
int cycles = 64000 * interval_in_ms; /* pclk is clocked at 64MHz */
while(cycles > 0x10000)
{
phi++;
prescale <<= 4;
cycles >>= 4;
}
if(prescale > 256)
panicf("%s : interval too big", __func__);
CGU_PERI |= CGU_TIMER2_CLOCK_ENABLE; /* enable peripheral */
VIC_INT_ENABLE = INTERRUPT_TIMER2; /* enable interrupt */
TIMER2_LOAD = TIMER2_BGLOAD = cycles; /* timer period */
/* /!\ bit 4 (reserved) must not be modified
* periodic mode, interrupt enabled, 16 bits counter */
TIMER2_CONTROL = (TIMER2_CONTROL & (1<<4)) | 0xe0 | (phi<<2);
} }