Bootloader restarting with interrupts

Hello all,

I am trying to echo what is being typed over uart0 on uart1 using irq interrupts, but everytime I get a new character on uart0 the bootloader firmware re-boots? My code is below. Could really use some help on this one.

/* Header Files */
//======================================
#include <stdio.h>
#include <string.h>
#include "LPC21xx.h"

//UART0 Debugging
#include "serial.h"
#include "rprintf.h"

/* Global Variables */
//======================================
#define PLOCK 0x400
#define GREEN_LED (1<<11)	//The Red LED is on Port 0-Pin 11
#define RED_LED (1<<2)
#define IRQ_MASK 0x00000080

char message[142];
char message_complete=0;
int message_index;

/* Function Declarations */
//======================================
unsigned enableIRQ(void);
unsigned disableIRQ(void);
unsigned restoreIRQ(unsigned oldCPSR);
void init(void);
void IRQ_Routine (void)   __attribute__ ((interrupt("IRQ")));
void FIQ_Routine (void)   __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void)   __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));
void delay_ms(int count);
void print1(char c[]);

int main(void)
{    
	message_index=0;
    init(); 
    while(1);
}

void IRQ_Routine(void) {
	char val = (char)U0RBR;	
	message[message_index] = val;
	print1(message);
    T0IR = 0x01;                //clear interrupt
    VICVectAddr = 0;            //end of interrupt - dummy write
}
 void print1(char c[]) {
	int counter, length;
	length = strlen(c) + 1;
	counter = 0;
	while(counter < length) {
		while((U1LSR & 0x20) == 0);
		U1THR = c[counter];
		counter = counter + 1;
	}
 }
void init(void) {
	/* Initialize Uart0 Block for Tx and Rx */
	PINSEL0=0x00050005;//Enable Uart0
	U0LCR=0x83;//8 bits, no parity, 1 stop bit, DLAB=1
	U0DLM=0x00;
	U0DLL=0x20; //115200 Baud rate
	U0FCR = 0x07;			//enable & clear FIFOs
	U0LCR=0x3; //DLAB=0
	rprintf_devopen(putc_serial0); //Open Serial port 0
	
	/* Initialize Uart1 Block for Tx and Rx */
	PINSEL1=0x00050000;//Enable Uart0
	U1LCR=0x83;//8 bits, no parity, 1 stop bit, DLAB=1
	U1DLM=0x00;
	U1DLL=0x20; //115200 Baud rate
	U1FCR= 0x01;
	U1LCR=0x03; //DLAB=0
	/*Set output for GPIO pins*/
	IODIR0 |= RED_LED | GREEN_LED;	//Set the Red, Green and Blue LED pins as outputs
	IOSET0 = RED_LED | GREEN_LED;	//Initially turn all of the LED's off 
	
	/* Interrupt*/
	U0IER = 0x01; // enable RDA interrupt
	VICProtection = 0; // disable protection
	VICIntSelect &= 0xFFFFFFBF; // IRQ
	VICVectAddr0 = (unsigned)IRQ_Routine;
	VICVectCntl0 = 0x20 | 6;
	VICIntEnable = 0x00000040; // enable
    enableIRQ();	
}

void FIQ_Routine(void){
    while (1) ; 
}
void SWI_Routine(void){
    while (1) ; 
}
void UNDEF_Routine(void) {
	while (1) ;	
}

 void delay_ms(int count) {
    int i;
    count *= 10000;
    for (i = 0; i < count; i++)	//We are going to count to 10000 "count" number of times
        asm volatile ("nop");		//"nop" means no-operation.  We don't want to do anything during the delay
}

static inline unsigned asm_get_cpsr(void) {
  unsigned long retval;
  asm volatile (" mrs  %0, cpsr" : "=r" (retval) : /* no inputs */  );
  return retval;
}

static inline void asm_set_cpsr(unsigned val) {
  asm volatile (" msr  cpsr, %0" : /* no outputs */ : "r" (val)  );
}

unsigned enableIRQ(void) {
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr(_cpsr & ~IRQ_MASK);
  return _cpsr;
}

unsigned disableIRQ(void) {
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr(_cpsr | IRQ_MASK);
  return _cpsr;
}

unsigned restoreIRQ(unsigned oldCPSR) {
  unsigned _cpsr;

  _cpsr = asm_get_cpsr();
  asm_set_cpsr((_cpsr & ~IRQ_MASK) | (oldCPSR & IRQ_MASK));
  return _cpsr;
}

Using IAR’s C, build in ARM mode for LPC21xx, here’s what I use to initialize UART 0. UART1 is about the same.

Vectored interrupt. Using the transmit and receive FIFOs (tricky).

Here’s code unique to UART0 rather than UART1

  switch (uartNo)  {
    case 0:      
        // pointer to hardware registers for a UART
        uartBuf->VIC_IEbit = (1<<VIC_UART0); // UART0 Interrupt enable bit
        VICIntEnClear = uartBuf->VIC_IEbit; // disable UARTn interrupt
        PINSEL0 |= (1<<0); // _bit.P0_0 = 1;  //Uart0 TX function select pins 0,1
        PINSEL0 |= (1<<2); // _bit.P0_1 = 1;  //Uart0 RX function select       
        // setup VIC for interrupts from UART
        VICIntSelect &= ~(1<<VIC_UART0); // mark as vectored, not FIQ
        VICVectAddresses[vectorNo] = (unsigned int)&UART0_isr; // Install ISR in VIC addr slot 
        VICVectControls[vectorNo] = 0x20 | VIC_UART0;        // IRQ type, int enabled
        break;

Here’s initialization common to both UARTS

  // Code in common with all UART numbers...
 // this is part of the ring-buffer I use for the UARTs. The ISR itself, and the non-ISR part, is not listed here.
  uartBuf->ASCIImode = 0;
  uartBuf->TXhead = uartBuf->TXtail = 0;
  uartBuf->RXhead = uartBuf->RXtail = 0;  
  uartBuf->TXcount = uartBuf->RXcount = 0;
  uartBuf->thre = 1;
  
  // UART hardware config. See LPC 210x manual table 81
  uartio->IER = 0; // no interrupts yet  
  uartio->TER = 0; // no TX enable
  uartio->FCR = (3<<1);   // reset TX and RX FIFOs
  uartio->FCR = 0; // unreset, change again below...
  
  uartio->LCR |= (3<<0) | (0<<2) | (0<<3);   // 8 bits, 1 stop bit, no parity

  // set baud rate
  uartio->LCR |= (1<<7);   // DLAB enables changing divisor
  uartio->DLL = UART_BAUD(baudRate) & 0xFF; // macro call fpr low 8
  uartio->DLM = (UART_BAUD(baudRate) >> 8);   // again for high 8
  uartio->LCR &= ~(1<<7);   // DLAB=0 

  uartio->FCR |= (7) | (RXFIFO_TRIGGER_code<<6); // FIFO reset/enable, RX FIFO depth code
  //uartio->FCR |= (6) | (RXFIFO_TRIGGER_code<<6); // FIFO reset/enable, RX FIFO depth code

  
  uartio->IER = (3<<0); // enable TX and RX interrupts, no line change interrupts
  uartio->TER = (1<<7); // TX enable
  
  VICIntEnable =  uartBuf->VIC_IEbit;   // UARTn Interrupt enable bit

and the ISRs

__irq __arm void UART0_isr(void)
{
  UART_isr(0);
}  
__irq __arm void UART1_isr(void)
{
  UART_isr(1);
}

This is the header for the ISR common to both UARTS.

__arm void UART_isr(unsigned char uartNo)
{ 

//common UART ISR code is here, then

VICVectAddr = 0;    // Clear interrupt in VIC.
}