EasyLink_transmit 和 EasyLink_receiveAsync 能正常工作,但EasyLink_receive一直不能正常工作,请帮忙看看。相关代码和运行情况如下:
EasyLink_Status EasyLink_receive(EasyLink_RxPacket *rxPacket)
{
EasyLink_Status status = EasyLink_Status_Rx_Error;
RF_EventMask result;
// rfc_dataEntryGeneral_t *pDataEntry;
if ( (!configured) || suspended)
{
return EasyLink_Status_Config_Error;
}
//Check and take the busyMutex
if (Semaphore_pend(busyMutex, 0) == false)
{
return EasyLink_Status_Busy_Error;
}
memcpy(&EasyLink_cmdRx, &RF_cmdRxHS, sizeof(RF_cmdRxHS));
pReceiveDataEntry = (rfc_dataEntryGeneral_t*) rxBuffer;
//data entry rx buffer includes hdr (len-1Byte), addr (max 8Bytes) and data
pReceiveDataEntry->length = 256+6;
pReceiveDataEntry->status = 0;
dataRxQueue.pCurrEntry = (uint8_t*)pReceiveDataEntry;
dataRxQueue.pLastEntry = NULL;
EasyLink_cmdRx.pOutput = &rxStatistics_hs;
EasyLink_cmdRx.maxPktLen = EASYLINK_MAX_PAYLOAD_LENGTH;
EasyLink_cmdRx.pktConf.bUseCrc = 1;
EasyLink_cmdRx.pktConf.bRepeatOk = 1;
EasyLink_cmdRx.pktConf.bRepeatNok = 1;
EasyLink_cmdRx.rxConf.bAppendTimestamp = 1;
EasyLink_cmdRx.rxConf.bAutoFlushCrcErr = 0;
EasyLink_cmdRx.pQueue = &dataRxQueue; /* Set the Data Entity queue for received data */
if (rxPacket->rxTimeout != 0)
{
EasyLink_cmdRx.endTrigger.triggerType = TRIG_REL_START;
EasyLink_cmdRx.endTrigger.pastTrig = 0;
EasyLink_cmdRx.endTime = RF_getCurrentTime() + rxPacket->rxTimeout;
}
else
{
EasyLink_cmdRx.endTrigger.triggerType = TRIG_NEVER;
EasyLink_cmdRx.endTrigger.pastTrig = 1;
EasyLink_cmdRx.endTime = 0;
}
//Clear the Rx statistics structure
memset(&rxStatistics_hs, 0, sizeof(rfc_propRxOutput_t));
// result = RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdRx, RF_PriorityHigh, 0, 0);
asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&EasyLink_cmdRx, RF_PriorityNormal,0, IRQ_RX_ENTRY_DONE);
/* Wait for Command to complete */
result = RF_pendCmd(rfHandle, asyncCmdHndl, RF_EventLastCmdDone);
if (result & RF_EventLastCmdDone)
{
//Check command status
if (EasyLink_cmdRx.status == PROP_DONE_OK)
{
//Check that data entry status indicates it is finished with
if (pReceiveDataEntry->status != DATA_ENTRY_FINISHED)
{
status = EasyLink_Status_Rx_Error;
}
//check Rx Statistics
else if ( rxStatistics_hs.nRxOk == 1)
{
//copy length from pDataEntry (- addrSize)
rxPacket->len = ((*(uint8_t*)(&pReceiveDataEntry->data + RX_FRAME_HSM_OFFSET_LEN)) |
(*(uint8_t*)(&pReceiveDataEntry->data + (RX_FRAME_HSM_OFFSET_LEN + 1))) << 8);
//copy payload
memcpy(&rxPacket->payload, (&pReceiveDataEntry->data + RX_FRAME_HSM_OFFSET_DATA), rxPacket->len);
rxPacket->rssi = rxStatistics_hs.lastRssi;
status = EasyLink_Status_Success;
// rxPacket->absTime = rxStatistics.timeStamp;
}
else if ( rxStatistics_hs.nRxBufFull == 1)
{
status = EasyLink_Status_Rx_Buffer_Error;
}
else
{
status = EasyLink_Status_Rx_Error;
}
}
else if ( EasyLink_cmdRx.status == PROP_DONE_RXTIMEOUT)
{
status = EasyLink_Status_Rx_Timeout;
}
else
{
status = EasyLink_Status_Rx_Error;
}
}
//Release the busyMutex
Semaphore_post(busyMutex);
return status;
}
EasyLink_cmdRx.status值一直为0x3441
能正常工作的EasyLink_transmit 和 EasyLink_receiveAsync接口实现如下:
EasyLink_Status EasyLink_transmit(EasyLink_TxPacket *txPacket)
{
// RF_CmdHandle cmdHdl;
uint8_t *pu8Data;
EasyLink_Status status = EasyLink_Status_Tx_Error;
if ( (!configured) || suspended)
{
return EasyLink_Status_Config_Error;
}
if (txPacket->len > EASYLINK_MAX_DATA_LENGTH)
{
return EasyLink_Status_Param_Error;
}
//Check and take the busyMutex
if (Semaphore_pend(busyMutex, 0) == false)
{
return EasyLink_Status_Busy_Error;
}
/* Transmit */
pTransmitDataEntry = (rfc_dataEntryGeneral_t*)txBuffer;
pTransmitDataEntry->length = txPacket->len + NUM_APPENDED_BYTES_TX;
pTransmitDataEntry->status = DATA_ENTRY_PENDING;
pTransmitDataEntry->pNextEntry = (uint8_t*)pTransmitDataEntry; // Circle buffer.
dataTxQueue.pCurrEntry = (uint8_t*)pTransmitDataEntry;
dataTxQueue.pLastEntry = NULL;
/* txPaket copy and send. */
pu8Data = &pTransmitDataEntry->data;
memcpy(pu8Data, &txPacket->payload, txPacket->len);
memcpy(&EasyLink_cmdTx, &RF_cmdTxHS, sizeof(RF_cmdTxHS));
EasyLink_cmdTx.pQueue = &dataTxQueue;
EasyLink_cmdTx.startTrigger.triggerType = TRIG_NOW;
EasyLink_cmdTx.startTrigger.pastTrig = 1;
EasyLink_cmdTx.startTime = 0;
// RF_cmdTxHS.startTime = time;
RF_EventMask result = RF_runCmd(rfHandle, (RF_Op*)&EasyLink_cmdTx, RF_PriorityHigh, 0, 0);
// cmdHandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdTxHS, RF_PriorityNormal, &tx_callback, 0);
/* Wait for Command to complete */
// RF_EventMask result = RF_pendCmd(rfHandle, cmdHdl, EASYLINK_RF_EVENT_MASK);
if (result & RF_EventLastCmdDone)
{
status = EasyLink_Status_Success;
}
//Release the busyMutex
Semaphore_post(busyMutex);
return status;
}
EasyLink_Status EasyLink_receiveAsync(EasyLink_ReceiveCb cb, uint32_t absTime,uint32_t endtimeMs)
{
EasyLink_Status status = EasyLink_Status_Rx_Error;
//Check if not configure of already an Async command being performed
if ( (!configured) || suspended)
{
return EasyLink_Status_Config_Error;
}
if (EasyLink_CmdHandle_isValid(asyncCmdHndl))
{
return EasyLink_Status_Busy_Error;
}
//Check and take the busyMutex
if (Semaphore_pend(busyMutex, 0) == false)
{
return EasyLink_Status_Busy_Error;
}
rxCb = cb;
/* Receive */
memcpy(&EasyLink_cmdRx, &RF_cmdRxHS, sizeof(RF_cmdRxHS));
EasyLink_cmdRx.pOutput = &rxStatistics_hs;
EasyLink_cmdRx.pQueue = &dataRxQueue;
EasyLink_cmdRx.maxPktLen = EASYLINK_MAX_PAYLOAD_LENGTH;
EasyLink_cmdRx.pktConf.bUseCrc = 1;
EasyLink_cmdRx.pktConf.bRepeatOk = 0;
EasyLink_cmdRx.pktConf.bRepeatNok = 0;
EasyLink_cmdRx.rxConf.bAppendTimestamp = 1;
//add by yr
EasyLink_cmdRx.endTrigger.triggerType = TRIG_REL_START;
EasyLink_cmdRx.endTrigger.bEnaCmd = 0;
EasyLink_cmdRx.endTrigger.triggerNo = 0;
EasyLink_cmdRx.endTrigger.pastTrig = 0;
EasyLink_cmdRx.endTime = RF_convertMsToRatTicks(endtimeMs);
asyncCmdHndl = RF_postCmd(rfHandle, (RF_Op*)&EasyLink_cmdRx, RF_PriorityHigh, &rxDoneCallback, EASYLINK_RF_EVENT_MASK);
if (EasyLink_CmdHandle_isValid(asyncCmdHndl))
{
status = EasyLink_Status_Success;
}
else
{
//Callback will not be called, release the busyMutex
Semaphore_post(busyMutex);
}
return status;
}