EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

How to setup a second timer interupt callback function?

Started by cyril_dunand July 5, 2006
Dear lpc2000 Group,
I have setup an interupt fonction with the timer0 of an lpc2124
witch work fine. The callback fonction is use on each timer0
interupt. When I try to had a second timer interupt callback
fonction it doesnt work. Is anybody can help me to solve my error
code.

The code for init timer0 is:

void Init_Timer0(void)
{
REG(TIMER0_TCR) = 2;
REG(TIMER0_PR) = 0;
REG(TIMER0_MR0) = 14740000;
REG(TIMER0_MCR) = 0x03;
REG(TIMER0_IR) = 0xFF;
REG(TIMER0_TCR) = 1;
REG(VICIntEnable) = 0x10;
}
The code for the callback timer0 fonction is:
void TimerInterrupt0(void)
{
REG(TIMER0_IR) = 0xFF;
myfunction();
}
The startup code to handle timer0 interupt is:
ldr r0, =VIC_ADDR0_REG_ADDR
ldr r1, =do_timer0
str r1, [r0]
ldr r0, =VEC_ADDR_REG_ADDR
ldr r1, =do_timer0
str r1, [r0]
ldr r0, =VIC_CTRL0_REG_ADDR
mov r1, #0x24
str r1, [r0]

do_timer0:
stmfd r13!, {r12, r14}
mrs r12, spsr
stmfd r13!, {r12}
msr cpsr_c, #0x93
stmfd r13!, {r0-r3, r14}
msr cpsr_c, #0x13
bl TimerInterrupt0
msr cpsr_c, #0x93
ldmfd r13!, {r0-r3, r14}
msr cpsr_c, #0x92
ldmfd r13!, {r12}
msr spsr_cxsf, r12
ldmfd r13!, {r12, r14}
stmfd r13!, {r0-r1}
ldr r0, =VEC_ADDR_REG_ADDR
mov r1, #0xff
str r1, [r0]
ldmfd r13!, {r0-r1}
subs pc, lr, #0x4

/////This work fine but not if I add this code///
Code for init timer1 is:
void Init_Timer1(void)
{
REG(TIMER1_TCR) = 2;
REG(TIMER1_PR) = 0;
REG(TIMER1_MR0) = 14740000;
REG(TIMER1_MCR) = 0x03;
REG(TIMER1_IR) = 0xFF;
REG(TIMER1_TCR) = 1;
REG(VICIntEnable) = 0x10;
}
The code for the callback timer1 fonction is:
void TimerInterrupt1(void)
{
REG(TIMER0_IR) = 0xFF;
myfunction1();
}
The startup code to handle timer1 interupt is:
ldr r0, =VIC_ADDR1_REG_ADDR
ldr r1, =do_timer1
str r1, [r0]
ldr r0, =VEC_ADDR_REG_ADDR
ldr r1, =do_timer1
str r1, [r0]
ldr r0, =VIC_CTRL1_REG_ADDR
mov r1, #0x24
str r1, [r0]

do_timer1:
stmfd r13!, {r12, r14}
mrs r12, spsr
stmfd r13!, {r12}
msr cpsr_c, #0x93
stmfd r13!, {r0-r3, r14}
msr cpsr_c, #0x13
bl TimerInterrupt1
msr cpsr_c, #0x93
ldmfd r13!, {r0-r3, r14}
msr cpsr_c, #0x92
ldmfd r13!, {r12}
msr spsr_cxsf, r12
ldmfd r13!, {r12, r14}
stmfd r13!, {r0-r1}
ldr r0, =VEC_ADDR_REG_ADDR
mov r1, #0xff
str r1, [r0]
ldmfd r13!, {r0-r1}
subs pc, lr, #0x4

With this code my second callback fonction is never call,
like if I was using the same interrupt.

Thank you for any suggest or correction.
Reguards
Cyril

An Engineer's Guide to the LPC2100 Series

In void TimerInterrupt1(void) are you clearing the wrong interrupt flag?

All that assembly code seems like the long way around but I don't know
what platform you are using.

For GCC, the interrupt handler prototype is:

void T0ISR(void) __attribute__ ((interrupt));

The handler itself might look like:

void T0ISR(void) // interrupt handler - see timer.h
{
CurrentTime++;
T0IR = 0x01;
VICVectAddr = 0xFF;
}

And the initialization might look like:

void T0_init(void)
{
T0TC = 0; // clear the timer count
T0PR = 1; // prescale divide by 2
T0MR0 = 7500; // divide by 7500
T0MCR = 0x03; // interrupt on match, reset on match
T0TCR = 0x01; // start the timer
VICVectCntl3 = 0x00000024; // set priority 3 for Timer 0
VICVectAddr3 = (unsigned long) T0ISR;
VICIntEnable = 0x00000010; // enable interrupt
T0EMR = 0x30; // toggle external match pin
}

Richard

--- In l..., "cyril_dunand" wrote:
>
> Dear lpc2000 Group,
> I have setup an interupt fonction with the timer0 of an lpc2124
> witch work fine. The callback fonction is use on each timer0
> interupt. When I try to had a second timer interupt callback
> fonction it doesnt work. Is anybody can help me to solve my error
> code.
>
> The code for init timer0 is:
>
> void Init_Timer0(void)
> {
> REG(TIMER0_TCR) = 2;
> REG(TIMER0_PR) = 0;
> REG(TIMER0_MR0) = 14740000;
> REG(TIMER0_MCR) = 0x03;
> REG(TIMER0_IR) = 0xFF;
> REG(TIMER0_TCR) = 1;
> REG(VICIntEnable) = 0x10;
> }
> The code for the callback timer0 fonction is:
> void TimerInterrupt0(void)
> {
> REG(TIMER0_IR) = 0xFF;
> myfunction();
> }
> The startup code to handle timer0 interupt is:
> ldr r0, =VIC_ADDR0_REG_ADDR
> ldr r1, =do_timer0
> str r1, [r0]
> ldr r0, =VEC_ADDR_REG_ADDR
> ldr r1, =do_timer0
> str r1, [r0]
> ldr r0, =VIC_CTRL0_REG_ADDR
> mov r1, #0x24
> str r1, [r0]
>
> do_timer0:
> stmfd r13!, {r12, r14}
> mrs r12, spsr
> stmfd r13!, {r12}
> msr cpsr_c, #0x93
> stmfd r13!, {r0-r3, r14}
> msr cpsr_c, #0x13
> bl TimerInterrupt0
> msr cpsr_c, #0x93
> ldmfd r13!, {r0-r3, r14}
> msr cpsr_c, #0x92
> ldmfd r13!, {r12}
> msr spsr_cxsf, r12
> ldmfd r13!, {r12, r14}
> stmfd r13!, {r0-r1}
> ldr r0, =VEC_ADDR_REG_ADDR
> mov r1, #0xff
> str r1, [r0]
> ldmfd r13!, {r0-r1}
> subs pc, lr, #0x4
>
> /////This work fine but not if I add this code///
> Code for init timer1 is:
> void Init_Timer1(void)
> {
> REG(TIMER1_TCR) = 2;
> REG(TIMER1_PR) = 0;
> REG(TIMER1_MR0) = 14740000;
> REG(TIMER1_MCR) = 0x03;
> REG(TIMER1_IR) = 0xFF;
> REG(TIMER1_TCR) = 1;
> REG(VICIntEnable) = 0x10;
> }
> The code for the callback timer1 fonction is:
> void TimerInterrupt1(void)
> {
> REG(TIMER0_IR) = 0xFF;
> myfunction1();
> }
> The startup code to handle timer1 interupt is:
> ldr r0, =VIC_ADDR1_REG_ADDR
> ldr r1, =do_timer1
> str r1, [r0]
> ldr r0, =VEC_ADDR_REG_ADDR
> ldr r1, =do_timer1
> str r1, [r0]
> ldr r0, =VIC_CTRL1_REG_ADDR
> mov r1, #0x24
> str r1, [r0]
>
> do_timer1:
> stmfd r13!, {r12, r14}
> mrs r12, spsr
> stmfd r13!, {r12}
> msr cpsr_c, #0x93
> stmfd r13!, {r0-r3, r14}
> msr cpsr_c, #0x13
> bl TimerInterrupt1
> msr cpsr_c, #0x93
> ldmfd r13!, {r0-r3, r14}
> msr cpsr_c, #0x92
> ldmfd r13!, {r12}
> msr spsr_cxsf, r12
> ldmfd r13!, {r12, r14}
> stmfd r13!, {r0-r1}
> ldr r0, =VEC_ADDR_REG_ADDR
> mov r1, #0xff
> str r1, [r0]
> ldmfd r13!, {r0-r1}
> subs pc, lr, #0x4
>
> With this code my second callback fonction is never call,
> like if I was using the same interrupt.
>
> Thank you for any suggest or correction.
> Reguards
> Cyril
>


The 2024 Embedded Online Conference