Seems pretty straight forward, is 'data' only ever a short length, or can it get quite long?.
Data length is decided by the len in the frame.It can have max of 255 bytes of data.
Following is my code is this fine
#define INDEXSTART 0
#define MAX_DATA 16
#define DEBUG_FLAG //if debug is set
#define END_OF_PACKET 13
#define STX 2
#define MIN_RX_DATA 2 //Least bytes in a frame
#define VALID_DATA TRUE
#define INVALID_DATA FALSE
#define CMD 2
PUBLIC void Uart1ServiceInterrupt(uint32 u32Device, uint32 u32ItemBitmap)
{
char ReadData;
//uint8 RcvStatus;
/* Read received character from UART and
stop multiple receive interrupts */
vLedControl(0x00, TRUE);
#ifdef DEBUG_FLAG
vPrintf("\n\rIn ISR");
#endif
if(u8AHI_UartReadLineStatus(E_AHI_UART_1)&E_AHI_UART_LS_DR)
{
ReadData = u8AHI_UartReadData(E_AHI_UART_1);
if(ReadData == END_OF_PACKET)
{
if(Index > MIN_RX_DATA)
{
SendBuff[Index] = '\0';
Index = INDEXSTART;
vLedControl(0x01, TRUE);
#ifdef DEBUG_FLAG
vPrintf("\n\rRcvd string:%s",SendBuff);
#endif
RCVDATA = VALID_DATA;
}
else
{
RCVDATA = INVALID_DATA;
#ifdef DEBUG_FLAG
vPrintf("\n\rBufferUnderRun");
#endif
}
}
else
{
#ifdef DEBUG_FLAG
vPrintf("\n\rRcvd:%c",ReadData);
#endif
if((ReadData==STX)&&(Index==0))
{
#ifdef DEBUG_FLAG
vPrintf("\n\rRcvd:SOP");
#endif
Index++;
}
else
SendBuff[Index++] = ReadData;
}
}
if(MAX_DATA==Index)
{
RCVDATA = INVALID_DATA;
#ifdef DEBUG_FLAG
vPrintf("\n\rBufferOverRun");
#endif
Index = INDEXSTART;
}
//Send the status of the received data.
bBosCreateTimer(Bos_UART1ACK_handler_handler,"Hello", 12, 2, &TimerID_Ack);
//while (*pcstring)
//{
// vAHI_UartWriteData(E_AHI_UART_0, *pcstring);
// pcstring++;
// }
}