Thread UART
Dependencies: fsl_phy_mcr20a fsl_smac mbed-rtos mbed
Fork of mcr20_wireless_uart by
Diff: main.cpp
- Revision:
- 19:71b793021c78
- Parent:
- 18:b02fc0e53df8
- Child:
- 23:6f13fea3cace
diff -r b02fc0e53df8 -r 71b793021c78 main.cpp --- a/main.cpp Fri Apr 03 05:23:33 2015 +0000 +++ b/main.cpp Sat Apr 04 22:14:14 2015 +0000 @@ -1,6 +1,28 @@ #include "mbed.h" #include "rtos.h" +#include "SMAC_Interface.h" +#include "SMAC_Config.h" + +static uint8_t mAppSer; +static uint8_t timePassed; +#ifdef VERBOSE +static bool_t bCCAFailed; +static bool_t bACKFailed; +#endif +static bool_t bTxDone; +static bool_t bRxDone; +static bool_t evKeyPressed; +static bool_t bTxInProgress; +static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)]; +static txPacket_t *gAppTxPacket; +static rxPacket_t *gAppRxPacket; +static txContextConfig_t txConfigContext; + +void InitProject(void); +extern smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance); +extern smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance); + DigitalOut led1(LED1); InterruptIn sw2(SW2); uint32_t button_pressed; @@ -31,7 +53,23 @@ { Thread thread(led_thread); thread2 = new Thread(button_thread); + + InitSmac(); + Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0); + + InitProject(); + gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer + gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t)); + + SMACFillHeader(&(gAppTxPacket->smacHeader), gDefaultAddress_c); + + (void)MLMEPAOutputAdjust(gDefaultOutputPower_c); + (void)MLMESetChannelRequest(gDefaultChannelNumber_c); + (void)MLMEConfigureTxContext(&txConfigContext); + gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c; + (void)MLMERXEnableRequest(gAppRxPacket, 0); + button_pressed = 0; sw2.fall(&sw2_press); while (true) { @@ -41,3 +79,75 @@ button_pressed = 0; } } + +smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance) +{ + switch(pMsg->msgType) + { + case gMlmeEdCnf_c: + printf("EdCnf: \r\n"); + //(void)OSA_EventSet(&gTaskEvent, gMlme_EdCnf_EVENT_c); + break; + case gMlmeCcaCnf_c: + printf("CcaCnf: \r\n"); + //(void)OSA_EventSet(&gTaskEvent, gMlme_CcaCnf_EVENT_c); + break; + case gMlmeTimeoutInd_c: + printf("MlmeTimeoutInd: \r\n"); + //(void)OSA_EventSet(&gTaskEvent, gMlme_TimeoutInd_EVENT_c); + break; + default: + break; + } + MEM_BufferFree(pMsg); + return gErrorNoError_c; +} + +//(Data) Sap handler for managing data confirm and data indication +smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance) +{ + switch(pMsg->msgType) + { + case gMcpsDataInd_c: + if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c) + { + printf("McpsDataInd: \r\n"); + //(void)OSA_EventSet(&gTaskEvent, gMcps_Ind_EVENT_c); + } + break; + case gMcpsDataCnf_c: +#ifdef VERBOSE + if(pMsg->msgData.dataCnf.status == gErrorChannelBusy_c) + { + bCCAFailed = TRUE; + } + if(pMsg->msgData.dataCnf.status == gErrorNoAck_c) + { + bACKFailed = TRUE; + } +#endif + printf("McpsDataCnf: \r\n"); + //(void)OSA_EventSet(&gTaskEvent, gMcps_Cnf_EVENT_c); + break; + default: + break; + } + MEM_BufferFree(pMsg); + return gErrorNoError_c; +} + +void InitProject(void) +{ + /*Global Data init*/ +#ifdef VERBOSE + bACKFailed = FALSE; + bCCAFailed = FALSE; +#endif + bTxInProgress = FALSE; + bTxDone = FALSE; + evKeyPressed = FALSE; + txConfigContext.autoAck = FALSE; + txConfigContext.ccaBeforeTx = FALSE; + txConfigContext.retryCountAckFail = 0; + txConfigContext.retryCountCCAFail = 0; +} \ No newline at end of file