#define gpd0con *(volatile unsigned *)0xe02000a0
#define tcfg0 *(volatile unsigned *)0xe2500000
#define tcfg1 *(volatile unsigned *)0xe2500004
#define tcntb0 *(volatile unsigned *)0xe250000c
#define tcmpb0 *(volatile unsigned *)0xe2500010
#define tint_cstat *(volatile unsigned *)0xe2500044
#define tcon *(volatile unsigned *)0xe2500008
#define vic0intselect *(volatile unsigned *)0xf200000c
#define vic0intenable *(volatile unsigned *)0xf2000010
#define vic0vectaddr21 *(volatile unsigned *)0xf2000154
#define vic0address *(volatile unsigned *)0xf2000f00
void timer0_init(void);
void vic0_init(void);
void cpu_int_on(void);
void clear_int(void);
__attribute__((interrupt)) void isr(void);
int i = 1;
void _start(void)
{
timer0_init();
vic0_init();
cpu_int_on();
}
void timer0_init(void)
{
gpd0con = gpd0con & ~0xf | 0x2;
tint_cstat |= 0x1;
tcfg0 = 131;
tcfg1 &= ~0xf;
tcntb0 = 1200;
tcmpb0 = 1;
tcon = tcon & ~(0x1 << 3) | (0x1 << 1);
tcon = tcon & ~(0x1 << 1) | (0x1 << 3) | 0x1;
}
void vic0_init(void)
{
vic0intselect &= ~(0x1 << 21);
vic0intenable |= (0x1 << 21);
vic0vectaddr21 = isr;
}
void cpu_int_on(void)
{
__asm__ __volatile__(
"mrs r0,cpsr\n"
"bic r0,r0,#0x80\n"
"msr cpsr,r0\n"
:
:);
}
void clear_int(void)
{
vic0address = 1;
tint_cstat |= (0x1 << 5);
}
__attribute__((interrupt)) void isr(void)
{
tcmpb0 = tcntb0 * (i % 1200) / 1200;
i++;
clear_int();
}