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;
}