Interrupt Service Routine UART, Burst of data
Hallo I need a solution to this problem, since I have already cover MY options.
Problem Environment: The software is written in C, using the software driver library. A device (slave) sends data to another device (master) and then to a personal computer (host). Both master and slave devices are the LM3S1968 evaluation boards connected with UART 0. Host connects with UART 1. Problem definition: Each UART has two FIFOS (Tx, Rx), each 16 byte deep. By sending continuously data to Rx FIFO, its filled up quickly and data sended remain unavailable.
There are two strategies to cope with the problem: 1. Arrange the FEN (FIFO ENABLE) bit 4 of UART Line control register (UARTLCRH) to 0 so that FIFO's are disabled and perform the interrupt routine in a byte oriented way. This method failed to work properly.
2. A simpler strategy was to implement burst of data, with sufficient idle time between the bursts. In other words: If a device sends 100 chars, I need a method to receive them. Note: The interrupt routine sometimes needs two activations in order to operate. Any idea to optimize it?
Lets show my code: /*******************************************************************************/ Global variables:
char StrMessage[100]; /*Temporary location for each burst of data*/ int ExitState = 0; /*This is the state of interrupt: 0 if no interrupt serviced*/ /*Structure for holding data of each burst*/ struct AcquiredData { char Data[100]; } Channel[18];
/*******************************************************************************/ Routines:
/*Interrupt service routine: once activated, will sample the input burst. Limitations: Sometimes will trigger, on the second burst*/ void FunctionUARTIntHandler(void) { unsigned long Status; int Index = 0; /*Check if there is interrupt*/ Status = UARTIntStatus(UART0_BASE, UART_INT_RX | UART_INT_RT); /*Disactivate interrupt*/ UARTIntClear(UART0_BASE, Status); /*Loop while there are characters in the receive FIFO.*/ while(UARTCharsAvail(UART0_BASE)) { // Read the next character from the UART and write it back to the UART. StrMessage[Index++] = UARTCharGetNonBlocking(UART0_BASE); } ExitState = 1; /*Interrupt Serviced*/ return; }
/*Routine for reception of data*/ void FunctionReceiveData(void) { int Index = 0; /*Counts the Channels*/ int minorIndex; /*Delay*/ FunctionEnableStatusLed(1); UARTCharPut(UART0_BASE, 'D'); /*Trigger Slave to send burst of data*/ do { while(ExitState == 0) { if(ExitState == 1) { strcpy(Channel[Index].Data, StrMessage); break; } } ExitState = 0; /*Disactivate interrupt flag*/ Index++; /*point to the next element with index*/ } while(Index<18); for(Index = 0; Index<18; Index++) { FunctionSendStringToMaster(Channel[Index].Data, UART1_BASE); /*A delay in order to flush properly the TxFIFO*/ for(minorIndex = 0; minorIndex<10000; minorIndex++); UARTCharPutNonBlocking(UART1_BASE, 0x86); /*burst separator*/ } UARTCharPutNonBlocking(UART1_BASE, 0xA7); /*end stream seperator*/ FunctionEnableStatusLed(0); return; }
Thanks for any effort. Chris
There is always light at the end of a Tunnel. Or a Train --Anonymous
login or register to reply
|