Hello. I'm writing a program for an NE64 board, which reads a series of data over the SCI1 port, and then transmits them over the Ethernet port. Pretty much it's done and works, but due to the amount of data collected on every reading, I have to send out 10-15 packets every time. My problem is that, when the function for UDP transmission is executed, some of the data received on the serial port are skipped and lost. I understand that in order to overcome this I need to implement an Interrupt function for the SCI1 port. I've tried this, but my code gets stuck in an infinite loop when the SCI reading in functions takes place ( SCI1in(); ).
main.c //*********************************** #include "RXFIFO.H" #include "sci.h" #include "MC9S12NE64.h" //...and all other required files/libraries
extern void SCI1_isr_handler (void);
#pragma CODE_SEG BANKED interrupt void SCI1Interrupt (void) { SCI1_isr_handler(); } #pragma CODE_SEG DEFAULT
....
RxFifo.c //************************************ #include "RxFifo.h" /* Number of characters in the Fifo the FIFO is full when it has FifoSize-1 characters */ char static volatile *RxPutPt; /* Pointer of where to put next */ char static volatile *RxGetPt; /* Pointer of where to get next */ /* FIFO is empty if PutPt=GetPt */ /* FIFO is full if PutPt+1=GetPt */ char static RxFifo[RXFIFOSIZE]; /* The statically allocated fifo data */
/*----------RxFifo_Init Initialize fifo to be empty Inputs: none Outputs: none */ void RxFifo_Init(void){unsigned char SaveCCR; /* save previous interrupt enable */ asm tpa asm staa SaveCCR asm sei /* make atomic */ RxPutPt=RxGetPt=&RxFifo[0]; /* Empty when PutPt=GetPt */ asm ldaa SaveCCR asm tap /* end critical section */ }
/*---------RxFifo_Put Enter one character into the fifo Inputs: 8-bit data Outputs: true if data is properly saved Since this is called by interrupt handlers no sei,cli*/ int RxFifo_Put(char data){ char volatile *tempPt; tempPt = RxPutPt; *(tempPt) = data; /* try to Put data into fifo */ tempPt++; if(tempPt == &RxFifo[RXFIFOSIZE]){ /* need to wrap?*/ tempPt = &RxFifo[0]; } if(tempPt == RxGetPt){ return(0); /* Failed, fifo was full */ } else{ RxPutPt = tempPt; /* Success, so update pointer */ return(1); } }
/*-----------------------RxFifo_Get---------------------------- Remove one character from the fifo Inputs: pointer to place to save 8-bit data Outputs: true if data is valid */ int RxFifo_Get(char *datapt){ if(RxPutPt == RxGetPt){ return(0); /* Empty if PutPt=GetPt */ } else{ *datapt = *(RxGetPt); RxGetPt++; if(RxGetPt == &RxFifo[RXFIFOSIZE]){ RxGetPt = &RxFifo[0]; } return(1); } }
sci.c //************************************ #include #include "ne64debug.h" #include "MC9S12NE64.h" #include "sci.h" #include "RXFIFO.H"
unsigned short RxHistogram[RXFIFOSIZE]; // collected before put
void SCI1Init(void){ //Debugt("Initializing my SCI1 function\r\n"); #define ECLK 25000000 //< this is BUSCLK #define BAUD_RATE 9600 PTG_PTG2 = 0; #define BAUD_DIV ECLK/16/BAUD_RATE
SCI1BD= BAUD_DIV; SCI1CR1= 0; SCI1CR2= SCI1CR2_TE_MASK | SCI1CR2_RE_MASK | SCI1CR2_RIE; RxFifo_Init(); asm cli }
//------SCI1 interrupt handler interrupt void SCI1_isr_handler(void){ if(SCI1SR1 & SCI1SR1_RDRF_MASK){ RxHistogram[RxFifo_Size()]++; RxFifo_Put(SCI1DRL); // clears RDRF } }
//-----Start of SCI1In // Wait for new serial port input, return ASCII code for key typed char SCI1In(void){
char letter; while (RxFifo_Get(&letter) == 0){ PTG_PTG0 = 0; // Where my code stucks }; PTG_PTG0 = 1; return(letter); }
My program is based on the Freescale's Connector_App, so similar initilizations take place. I'm new at this, and I had a really hard time finding information and examples using SCI Rx interrupts. Can somebody indicate me what i'm doing wrong please? Your help will be trully appreciated.
Thank you