/********************************************************************************
*Function name: sQInit *
*Parameters: pq: pointer to queue structure to be initialized *
* start: start address of ring buffer *
* size: the size of the ring buffer *
*Description: initialize a queue structure *
********************************************************************************/
void sQInit(QUEUE *pq,unsigned char *pStart,unsigned int wSize)
{
pq->pIn = pStart;
pq->pOut = pStart;
pq->pStart = pStart;
pq->bLength = 0;
pq->wSize = wSize;
}
/********************************************************************************
*Function name: sQDataIn *
*Parameters: pq: pointer to queue structure to be initialized *
* data: the data to be inserted into the queue *
*Returns: cQBufNormal: data has been inserted into the queue *
* cQBufFull: the buffer is full *
*Description: insert a data into the queue *
********************************************************************************/
unsigned char sQDataIn(QUEUE *pq,unsigned char bData)
{
if(pq->bLength == pq->wSize)
{
if(pq->pIn == pq->pStart)
{
*(pq->pStart + pq->wSize) = bData;
}
else
{
*(pq->pIn-1) = bData;
}
return(cQBufFull);
}
else
{
*(pq->pIn) = bData;
pq->bLength++;
if(pq->pIn == pq->pStart + pq->wSize - 1)
{
pq->pIn = pq->pStart;
}
else
{
pq->pIn++;
}
return(cQBufNormal);
}
}
/********************************************************************************
*Function name: sQDataOut *
*Parameters: pq: pointer to queue structure to be initialized *
* pdata: the address to save the data *
*Returns: cQBufNormal: data has been inserted into the queue *
* cQBufEmpty: the buffer is empty *
*Description: Get a data from the queue *
********************************************************************************/
unsigned char sQDataOut(QUEUE *pq,unsigned char *pData)
{
if(pq->bLength == 0)
{
return(cQBufEmpty);
}
*pData = *(pq->pOut);
pq->bLength--;
if(pq->pOut == pq->pStart + pq->wSize - 1)
{
pq->pOut = pq->pStart;
}
else
{
pq->pOut++;
}
return(cQBufNormal);
}
/********************************************************************************
*Function Name: sInitialSci *
*Parameters: bSciId: sci id *
* *bRxBuf: receive buffer start address *
* wRxSize: receive buffer length *
* bTxBuf: transmit buffer start address *
* wTxSize: transmit buffer length *
* type: sci type *
*Descriptions: assign and initialize the sci control struct to sci *
********************************************************************************/
void sInitialSci(unsigned int wRxSize,unsigned char bType)
{
QUEUE *pq;
SciStruct *pSci;
/********************************************************************************
*Function Name: sSciRead *
*Parameters: bSciId: sci id *
* *pBuf: address to save data received *
*Returns: cSciRxBufEmpty: receive buffer is empty *
* cSciRxRdy: get one byte data successfully *
*Description: This function is executed in AP *
********************************************************************************/
unsigned char sSciRead(unsigned char *pBuf)
{
QUEUE *pq;
unsigned char bTemp;
SciStruct *pSci;
/********************************************************************************
*Function Name: sSciWrite *
*Parameters: bSciId: sci id *
* *pstart: start address of data to be sent *
* wLength: the length of data to be send *
*Returns: cSciTxBufFull: transmit buffer is empty *
* cSciTxRdy: send one byte data successfully *
*Description: This function is executed in AP *
********************************************************************************/
unsigned char sSciWrite(unsigned char *pStart,unsigned int wLength)
{
SciStruct *pSci;