4M波特率太高了,需要特定的线和接口,你先降低速度看看
【相关推荐】
缓冲队列实现代码
typedef struct
{
MsgCell *msgCell;
ht_uint32_t wPos;
ht_uint32_t rPos;
ht_uint32_t Count;
}cmMsg_t;
/**********************************************************************************************************
*
* 函数名:cmMsgCreate
* 功 能:
* 参 数:
* 返回值:
* 版 本:
*
**********************************************************************************************************/
void* cmMsgCreate(ht_uint32_t wantSize)
{
cmMsg_t *prt=NULL;
prt=(cmMsg_t *)cmMalloc(sizeof(cmMsg_t)) ;
prt->msgCell=(MsgCell *)cmMalloc(sizeof(MsgCell)*wantSize) ;
prt->rPos=0;
prt->wPos=0;
prt->Count=wantSize;
return (void*)prt;
}
/**********************************************************************************************************
*
* 函数名:cmMsgWrite
* 功 能:
* 参 数:
* 返回值:
* 版 本:
*
**********************************************************************************************************/
ht_int32_t cmMsgWrite(void * handle,MsgCell msg)
{
ht_uint32_t iPos,i;
cmMsg_t *prt=(cmMsg_t*)handle;
iPos=(prt->wPos+1)%prt->Count;
if(( iPos!=prt->rPos)&&(msg.MsgLen<=256))//最大长度不超过256字节
{
prt->msgCell[prt->wPos].MsgLen=msg.MsgLen;
prt->msgCell[prt->wPos].prtMsg=(ht_uint8_t *)cmMalloc(msg.MsgLen) ;
for(i=0;i<prt->msgCell[prt->wPos].MsgLen;i++)
{
prt->msgCell[prt->wPos].prtMsg[i]=msg.prtMsg[i];
}
prt->wPos=iPos;
return 1;
}
else
{
return 0;
}
}
/**********************************************************************************************************
*
* 函数名:cmMsgRead
* 功 能:
* 参 数:
* 返回值:
* 版 本:
*
**********************************************************************************************************/
ht_int32_t cmMsgRead(void * handle,MsgCell *msg )
{
ht_uint32_t i;
cmMsg_t *prt=(cmMsg_t*)handle;
if( prt->wPos!=prt->rPos)
{
msg->MsgLen=prt->msgCell[prt->rPos].MsgLen;
for(i=0;i<prt->msgCell[prt->rPos].MsgLen;i++)
{
msg->prtMsg[i]=prt->msgCell[prt->rPos].prtMsg[i];
cmFree(prt->msgCell[prt->rPos].prtMsg);
}
prt->rPos=(prt->rPos+1)%prt->Count;
return 1;
}
return 0;
}