芯片:CC2640R2F
工程:simpleperipheral
问题:自己重写NPI模块的发射函数,其中有一段为数据分配内存并加入队列的操作,实际中发现输出的字符与输入不同,加入打印log的函数发现,memcpy失败,想求问题在哪,我看了好久没看出。
以下为程序
void NPITask_sendToHost(uint8_t *pMsg, uint8 size) { ICall_CSState key; NPIUSER_QueueRec *recPtr; NPIUser_msg_t *npiMsg; recPtr = (NPIUSER_QueueRec *)ICall_malloc(sizeof(NPIUSER_QueueRec)); npiMsg = ICall_malloc(sizeof(NPIUSER_QueueRec)+size); if(!recPtr) { return; } if(npiMsg->pBuf) { memcpy(npiMsg->pBuf,pMsg,size); } npiMsg->pBufSize = size; SC_Log_info4("npiMsg data: %02x, %02x, %02x, %02x",\ npiMsg->pBuf[0],npiMsg->pBuf[1],npiMsg->pBuf[2],npiMsg->pBuf[3]); SC_Log_info4("pMsg data: %02x, %02x, %02x, %02x",\ pMsg[0],pMsg[1],pMsg[2],pMsg[3]); recPtr->npiMsg = npiMsg; recPtr->npiMsg->pBufSize = size; SC_Log_info5("recPtr,len: %d, data: %02x, %02x, %02x, %02x",recPtr->npiMsg->pBufSize,\ recPtr->npiMsg->pBuf[0],recPtr->npiMsg->pBuf[1],recPtr->npiMsg->pBuf[2],recPtr->npiMsg->pBuf[3]); // Enter CS to prevent higher priority tasks // from also enqueuing msg at the same time key = ICall_enterCriticalSection(); Queue_put(npiTxQueue, &recPtr->_elem); Event_post(syncEvent, NPITASK_TX_READY_EVENT); ICall_leaveCriticalSection(key); }
输出日志如下:
各位大侠帮忙看看哪里有问题,新手仿写,如果有什么蠢问题,还望大家不吝赐教!