Hi,
I've been trying to get a simple timer interrupt working without any success. It's very possible that I've coded it incorrectly as I have just been blindly following an example. However, it is quite simple.
All I do is set up Timer0 to fire an interrupt every X cycles. I'm using the serial port to print the value of the T0TC register and you can see it incrementing up until the first interrupt fires. Thereafter, the ISR runs indefinately and the program never returns to the main loop.
I've either set up my ISR incorrectly and somehow the result is that it never exits properly, or something else funny is happening. I've disabled the only other interrupt that was enabled and you can see, that as the ISR is called the first time, the relevant bit in the VICRawIntr register is set (VICRawIntr[4]). Every time after that it is not set. So what is calling my ISR?
Thanks, Shareef.
#include "mbed.h"
Serial pc(USBTX, USBRX);
DigitalOut myLed(LED1);
void tmr0_isr (void) __irq {
pc.printf("\nInside Timer0 ISR.\n");
pc.printf("VICRawIntr register is %x\n", VICRawIntr);
pc.printf("VICIntEnable reg is 0x%x\n", VICIntEnable);
pc.printf("T0TC is %x\n", T0TC);
pc.printf("Reseting Timer0\n");
T0TCR = 2;
pc.printf("T0TC is %x\n", T0TC);
T0IR = 1; // Clear MR0 interrupt flag
myLed = ~myLed;
pc.printf("T0TC is %x\n", T0TC);
pc.printf("Enabling Timer0\n");
T0TCR = 1;
pc.printf("T0TC is %x\n", T0TC);
}
int main() {
// Read the clock configuration
pc.printf("Reg CLKSRCSEL is 0x%x\n", CLKSRCSEL);
pc.printf("Reg PLLCON is 0x%x\n", PLLCON);
pc.printf("Reg PLLCFG is 0x%x\n", PLLCFG);
pc.printf("Reg PLLSTAT is 0x%x\n", PLLSTAT);
pc.printf("Reg CCLKCFG is 0x%x\n", CCLKCFG);
pc.printf("Reg USBCLKCFG is 0x%x\n", USBCLKCFG);
pc.printf("Reg PCLKSEL0 is 0x%x\n", PCLKSEL0);
pc.printf("Reg PCLKSEL1 is 0x%x\n", PCLKSEL1);
pc.printf("Reg PCON is 0x%x\n", PCON);
pc.printf("Reg INTWAKE is 0x%x\n", INTWAKE);
pc.printf("Reg PCONP is 0x%x\n", PCONP);
// Set up a timer0
T0PR = 0x3; // Timer0 prescale value
T0MR0 = 0x00FFFFFF; // Set Match Register
T0MCR = 7; // Interrupt, stop and reset on match
T0TCR = 2; // Reset prescale and counter registers.
// Enable interrupts
VICVectAddr4 = (unsigned long)tmr0_isr;
VICVectCntl4 = 0;
VICIntEnable = 1 << 4;
VICIntEnClr = 1 << 2;
pc.printf("VICRawIntr reg is 0x%x\n", VICRawIntr);
pc.printf("VICIntEnable reg is 0x%x\n", VICIntEnable);
pc.printf("VICIRQStatus reg is 0x%x\n", VICIRQStatus);
pc.printf("VICFIQStatus reg is 0x%x\n", VICFIQStatus);
pc.printf("VICVectAddr4 reg is 0x%x\n", VICVectAddr4);
pc.printf("T0IR is %x\n", T0IR);
pc.printf("T0TCR is %x\n", T0TCR);
pc.printf("T0TC is %x\n", T0TC);
pc.printf("T0MR0 is %x\n", T0MR0);
// Enable Timer0
T0TCR = 1;
while(1) {
pc.printf("main.c: T0TC is %x\n", T0TC);
}
}
Hi,
I've been trying to get a simple timer interrupt working without any success. It's very possible that I've coded it incorrectly as I have just been blindly following an example. However, it is quite simple.
All I do is set up Timer0 to fire an interrupt every X cycles. I'm using the serial port to print the value of the T0TC register and you can see it incrementing up until the first interrupt fires. Thereafter, the ISR runs indefinately and the program never returns to the main loop.
I've either set up my ISR incorrectly and somehow the result is that it never exits properly, or something else funny is happening. I've disabled the only other interrupt that was enabled and you can see, that as the ISR is called the first time, the relevant bit in the VICRawIntr register is set (VICRawIntr[4]). Every time after that it is not set. So what is calling my ISR?
Thanks, Shareef.