This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Resetting Code / Timer Interrupt

Hey all. We are having a weird issue on an LPC2148 part. Code here:

Main source file:

#include <LPC214X.h>
#include "event.h"
#include "timer.h"
#include "PJstate.h"
#include "led.h"
#include "buffer.h"
#include "pc.h"

EVENTGROUP pjEvent = 0;
EVENTGROUP ioEvent = 0;

void UARTS_Init(void)
{
//      int irqID;
// Fpclk = 15.000.000 MHz
// DLM,DLH = Fpclk / (9600*16) = 98 = 0x62
        PINSEL0 |= 0x00050000;  // Select UART1 RXD/TXD & UART0 RXD/TXD

        // UART1 - PC side
        U1FCR = 7;                              // Enable and clear FIFO's
        U1LCR = 0x83;                   // 8N1, enable Divisor latch bit
        U1DLL = 0x62;
        U1DLM = 0;                              // baud rate fixed to 9600 @ PCLK = 15 Mhz
        U1LCR = 3;                              // Disable Divisor latch bit
        U1IER = 0x00;                   // Disable(d) RBR Interrupt
}

void Timer0_Init(void)
{
        T0CTCR = 0x00;          // Timer Mode
        T0TCR = 0x01;           // Enable Counter
        T0MCR = 0x03;           // Interrupt and Reset when TC = T0MR0
        //T0MR0 = 0x00003A98;   // 1ms = 15k
    T0MR0 = 0x00003a98;
}

__irq void IRQ_Timer(void)
{
        T0IR = 0x01;                                    // Clear Timer Interrupt
    VICVectAddr = (unsigned long)0;
}

void Interrupt_Init(void)
{
        VICVectCntl0 = 0x00000024;
        VICVectAddr0 = (unsigned long)&IRQ_Timer;

        VICIntSelect = 0x00000000;
        VICIntEnable = 0x00000010;
}

void DebounceSwitch3(void)
{
}

void ServIO(void)
{
        setEvent(DEBOUNCE, &ioEvent);
        if (chkEvent(DEBOUNCE, &ioEvent))
        {
                //DebounceSwitch3();
        }
}

int main (void)
{
        int running = 0;

        Timer0_Init();
    UARTS_Init();
    Interrupt_Init();

    U1THR = 'X';
    while (1)
    {
        PJFsmMain();
        ServIO();
    }

} // main

Other source file (hdr with prototype not included):


void PJFsmMain(void)
{ PJPowerOn();
} void PJPowerOn(void)
{ }

The program when compiled endlessly spits 'X' out on the serial port. It is continuously crashing/resetting.

Modifying pretty much any line within the code makes it so it does not crash. Simply removing the DebounceSwitch3() function that is not called will make the code not crash. Remove the calls to PJFsmMain() that simply calls another empty function and everything seems fine. Really looks to me like something is getting corrupted somewhere but from a code perspective, I do not see where.

Our startup.s was modified to leave the processor in supervisor mode. irq stack = 0x80bytes, supervisor stack = 0x400bytes.

I think the problem must be related to interrupt/stack corruption issues however i am at a bit of a loss as to what to look for next/how to prove it.

Thanks for any suggestions,
Ryan

Parents Reply Children