EmbeddedRelated.com
Forums

Interruption with the timer for a LPC2214

Started by charlesvallerand June 1, 2006
Hi everybody,

I'm trying to do an interruption routine with the timer0
wiht a LPC2214. The setting of the timer work but when it's time to
enter in my interruption function it doesn't work. This is a section
of my code, I use gnu arm like compiler :

===================================

static void timerInit(){
/*
* init timer 0
*
* timer is incremented every micro second
*/
T0PR = 59;
/* timer generate an interrupt every T0MR0 micro seconds*/
T0MR0 = 500000;
/* enable interrupt when timer match T0MR0,
reset the timer when match occurs*/
T0MCR = 0x03;

asm("MSR CPSR_c, #0X53");

/*
* init VIC
*
* set interrupt vector's address
*/
VICIntSelect = 0x00000000; //(all are IRQ)
/* enable IT at the output of the VIC */
VICIntEnable = VICIntEnable | 0x10;


VICVectAddr0 = (unsigned int)&IRQ_ISR_Handler;
/* interrupt source Int4 (also called TIMER0) is associated to the
vector 0 of the VIC and this vector is enabled */
VICVectCntl0 = 0x20 | 0x04;


/*clear interrupt*/
T0IR = 0xFF;
/* enable timer 0 */
T0TCR = 0x01;
}

void IRQ_ISR_Handler() {

// Code to be done ... for test, I want to light the led.
ledOn();

}

Here is my part of code in assembler :

.section .startup,"ax"
.code 32
.align 0

b start
b undefined_instruction_exception
b software_interrupt_exception
b prefetch_abort_exception
b data_abort_exception
nop
LDR PC,[PC,#-0xFF0] /* Load the VICVector */
nop

=====================

The interruption from timer0 work but when it's time to enter in the
function the system stop, so the interruption occur !? We want this
timer interruption to do an heartbeat function for a RTOS. Any helps
are welcome !
Charles Gouin-Vallerand,
Master student, Computer Science
Universitde Sherbrooke, Canada





An Engineer's Guide to the LPC2100 Series

Charles,

See the following for an example of working code that generates a
regular timer "tick" interrupt.

http://groups.yahoo.com/group/lpc2000/message/16144

Note that it assumes the existence of an assembler pre- and post-
amble to save context etc. See the following for a very good
explanation of this (in particular, the example in section 3.10):

http://www.ovro.caltech.edu/~dwh/ucos/project_AR1803.pdf

Amongst the problems with the code below is that you don't seem to
acknowledge the timer interrupt source or reset the VIC in the
interrupt handler.

Hopefully between these two examples refernced above, you should get
something working. Both contain a reasonable amount of comments to
show what's going on. I'm sure there's other examples out there too:
it's always easiest to start with something that works and modify it
to suit your exact needs than attempt to do everything from scratch.

Hopefully, this will be of some help to you.

Brendan

--- In l..., "charlesvallerand"
wrote:
>
> Hi everybody,
>
> I'm trying to do an interruption routine with the timer0
> wiht a LPC2214. The setting of the timer work but when it's time to
> enter in my interruption function it doesn't work. This is a
section
> of my code, I use gnu arm like compiler :
>
> ===================================
>
> static void timerInit(){
> /*
> * init timer 0
> *
> * timer is incremented every micro second
> */
> T0PR = 59;
> /* timer generate an interrupt every T0MR0 micro seconds*/
> T0MR0 = 500000;
> /* enable interrupt when timer match T0MR0,
> reset the timer when match occurs*/
> T0MCR = 0x03;
>
> asm("MSR CPSR_c, #0X53");
>
> /*
> * init VIC
> *
> * set interrupt vector's address
> */
> VICIntSelect = 0x00000000; //(all are IRQ)
> /* enable IT at the output of the VIC */
> VICIntEnable = VICIntEnable | 0x10;
>
>
> VICVectAddr0 = (unsigned int)&IRQ_ISR_Handler;
> /* interrupt source Int4 (also called TIMER0) is associated
to the
> vector 0 of the VIC and this vector is enabled */
> VICVectCntl0 = 0x20 | 0x04;
>
>
> /*clear interrupt*/
> T0IR = 0xFF;
> /* enable timer 0 */
> T0TCR = 0x01;
> }
>
> void IRQ_ISR_Handler() {
>
> // Code to be done ... for test, I want to light the led.
> ledOn();
>
> }
>
> Here is my part of code in assembler :
>
> .section .startup,"ax"
> .code 32
> .align 0
>
> b start
> b undefined_instruction_exception
> b software_interrupt_exception
> b prefetch_abort_exception
> b data_abort_exception
> nop
> LDR PC,[PC,#-0xFF0] /* Load the VICVector */
> nop
>
> =====================
>
> The interruption from timer0 work but when it's time to enter in
the
> function the system stop, so the interruption occur !? We want this
> timer interruption to do an heartbeat function for a RTOS. Any
helps
> are welcome !
>
>
> Charles Gouin-Vallerand,
> Master student, Computer Science
> Universitde Sherbrooke, Canada
>





charlesvallerand wrote:

>Hi everybody,
>
> I'm trying to do an interruption routine with the timer0
>wiht a LPC2214. The setting of the timer work but when it's time to
>enter in my interruption function it doesn't work. This is a section
>of my code, I use gnu arm like compiler :
>
>===================================
>
>static void timerInit(){
> /*
> * init timer 0
> *
> * timer is incremented every micro second
> */
> T0PR = 59;
> /* timer generate an interrupt every T0MR0 micro seconds*/
> T0MR0 = 500000;
> /* enable interrupt when timer match T0MR0,
> reset the timer when match occurs*/
> T0MCR = 0x03;
>
> asm("MSR CPSR_c, #0X53");
>
> /*
> * init VIC
> *
> * set interrupt vector's address
> */
> VICIntSelect = 0x00000000; //(all are IRQ)
> /* enable IT at the output of the VIC */
> VICIntEnable = VICIntEnable | 0x10;
>
>
> VICVectAddr0 = (unsigned int)&IRQ_ISR_Handler;
> /* interrupt source Int4 (also called TIMER0) is associated to the
>vector 0 of the VIC and this vector is enabled */
> VICVectCntl0 = 0x20 | 0x04;
>
>
> /*clear interrupt*/
> T0IR = 0xFF;
> /* enable timer 0 */
> T0TCR = 0x01;
>}
>
>void IRQ_ISR_Handler() {
>
> // Code to be done ... for test, I want to light the led.
> ledOn();
>
>}
>
>Here is my part of code in assembler :
>
>.section .startup,"ax"
> .code 32
> .align 0
>
> b start
> b undefined_instruction_exception
> b software_interrupt_exception
> b prefetch_abort_exception
> b data_abort_exception
> nop
> LDR PC,[PC,#-0xFF0] /* Load the VICVector */
> nop
>
>=====================
>
>The interruption from timer0 work but when it's time to enter in the
>function the system stop, so the interruption occur !? We want this
>timer interruption to do an heartbeat function for a RTOS. Any helps
>are welcome !
>
>
>

Look at this code:

=============== begin system.h ==================
#ifndef INC_SYSTEM_H
#define INC_SYSTEM_H

void timer0ISR(void) __attribute__((interrupt));

#endif
================= snip ======================

================ begin RTFuncs.c ================

#define T0_MS_DIV 29491 // value @ 29MHz PCLK.

static void startMsTimer (void)
{// tick timer, 1ms heartbeat for the system.
// connect VIC to Timer0
Timer0VectAddr = (uint32_t)timer0ISR; // address of the ISR
Timer0VectCntl = VIC_ENABLE | VIC_TIMER0;
VICIntSelect &= ~VIC_BIT(VIC_TIMER0); // Timer0 selected as IRQ
VICIntEnable = VIC_BIT(VIC_TIMER0); // Timer0 interrupt enabled
T0TCR = TCR_RESET; // reset & disable timer 0
T0PC = T0PR = 0;
T0CCR = 0; // timer mode.
T0EMR = 0; // no external match.
T0MCR = 3; // reset and interrupt on terminal count.
T0MR0 = T0_MS_DIV;
T0TCR = TCR_ENABLE;
// init the system ticks.
systemTickCounter = 0;
// init RS485 transmit pre-charge timers.
DelayTx2 = DelayTx3 = 0;
}
=================== snip ====================

================ begin timer0ISR.c ===============
void timer0ISR(void)
{// maintain system heartbeat timer.
// ack the timer's interrupt source.
T0IR = 1;
// form the 10ms timer.
if (!(--tickPrescale)) {
tickPrescale = 10;
systemTickCounter++;
}
// service the push button.
serviceAckButton();
//
// and so on...
//
VICVectAddr = 0x00000000; // clear this interrupt from
the VIC
}
=================== snip ====================
If you look that code over and refer to the manual, the timer section
may make more sense to you? Make sure you have the interrupt attribute
defined for the timer0ISR function, gcc will generate code to save the
registers and restore when the function exits.

Regards,

TomW

--
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------