The MCR20A Wireless UART application functions as an wireless UART bridge between two (one-to-one) or several (one to many) boards. The application can be used with both a TERM, or with software that is capable of opening a serial port and writing to or reading from it. The characters sent or received are not necessarily ASCII printable characters.

Dependencies:   fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_wireless_uart by Freescale

By default, the application uses broadcast addresses for OTA communication. This way, the application can be directly downloaded and run without any user intervention. The following use case assumes no changes have been done to the project.

  • Two (or more) MCR20A platforms (plugged into the FRDM-K64F Freescale Freedom Development platform) have to be connected to the PC using the mini/micro-USB cables.
  • The code must be downloaded on the platforms via CMSIS-DAP (or other means).
  • After that, two or more TERM applications must be opened, and the serial ports must be configured with the same baud rate as the one in the project (default baud rate is 115200). Other necessary serial configurations are 8 bit, no parity, and 1 stop bit.
  • To start the setup, each platform must be reset, and one of the (user) push buttons found on the MCR20A platform must be pressed. The user can press any of the non-reset buttons on the FRDM-K64F Freescale Freedom Development platform as well. *This initiates the state machine of the application so user can start.

Documentation

SMAC Demo Applications User Guide

Committer:
FSL\B36402
Date:
Sat Apr 25 01:10:45 2015 -0500
Revision:
24:088286081619
Parent:
23:6f13fea3cace
Child:
25:f40bc034cd8b
minor updates, IAR working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sam_grove 0:01fb291427ce 1 #include "mbed.h"
cotigac 18:b02fc0e53df8 2 #include "rtos.h"
sam_grove 2:3e7685cfb2a7 3
FSL\B36402 23:6f13fea3cace 4 #include "Phy.h"
cotigac 19:71b793021c78 5 #include "SMAC_Interface.h"
cotigac 19:71b793021c78 6 #include "SMAC_Config.h"
cotigac 19:71b793021c78 7
FSL\B36402 23:6f13fea3cace 8 #define gMcps_Cnf_EVENT_c (1<<1)
FSL\B36402 23:6f13fea3cace 9 #define gMcps_Ind_EVENT_c (1<<2)
FSL\B36402 23:6f13fea3cace 10 #define gMlme_EdCnf_EVENT_c (1<<3)
FSL\B36402 23:6f13fea3cace 11 #define gMlme_CcaCnf_EVENT_c (1<<4)
FSL\B36402 23:6f13fea3cace 12 #define gMlme_TimeoutInd_EVENT_c (1<<5)
FSL\B36402 23:6f13fea3cace 13 #define gWUSelf_EVENT_c (1<<6)
FSL\B36402 23:6f13fea3cace 14
cotigac 19:71b793021c78 15 #ifdef VERBOSE
cotigac 19:71b793021c78 16 static bool_t bCCAFailed;
cotigac 19:71b793021c78 17 static bool_t bACKFailed;
cotigac 19:71b793021c78 18 #endif
FSL\B36402 23:6f13fea3cace 19 uint32_t gTaskEventFlags;
cotigac 19:71b793021c78 20 static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)];
cotigac 19:71b793021c78 21 static txPacket_t *gAppTxPacket;
cotigac 19:71b793021c78 22 static rxPacket_t *gAppRxPacket;
cotigac 19:71b793021c78 23 static txContextConfig_t txConfigContext;
cotigac 19:71b793021c78 24
cotigac 19:71b793021c78 25 void InitProject(void);
FSL\B36402 23:6f13fea3cace 26 void InitApp(void);
FSL\B36402 23:6f13fea3cace 27
cotigac 19:71b793021c78 28 extern smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance);
cotigac 19:71b793021c78 29 extern smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance);
cotigac 19:71b793021c78 30
cotigac 18:b02fc0e53df8 31 DigitalOut led1(LED1);
cotigac 18:b02fc0e53df8 32 InterruptIn sw2(SW2);
cotigac 18:b02fc0e53df8 33 uint32_t button_pressed;
cotigac 18:b02fc0e53df8 34 Thread *thread2;
FSL\B36402 23:6f13fea3cace 35 Thread *eventsThread;
sam_grove 2:3e7685cfb2a7 36
cotigac 18:b02fc0e53df8 37 void sw2_press(void)
cotigac 18:b02fc0e53df8 38 {
cotigac 18:b02fc0e53df8 39 thread2->signal_set(0x1);
cotigac 18:b02fc0e53df8 40 }
sam_grove 2:3e7685cfb2a7 41
cotigac 18:b02fc0e53df8 42 void led_thread(void const *argument)
cotigac 18:b02fc0e53df8 43 {
cotigac 18:b02fc0e53df8 44 while (true) {
cotigac 18:b02fc0e53df8 45 led1 = !led1;
cotigac 18:b02fc0e53df8 46 Thread::wait(1000);
sam_grove 2:3e7685cfb2a7 47 }
sam_grove 2:3e7685cfb2a7 48 }
sam_grove 2:3e7685cfb2a7 49
cotigac 18:b02fc0e53df8 50 void button_thread(void const *argument)
sam_grove 2:3e7685cfb2a7 51 {
cotigac 18:b02fc0e53df8 52 while (true) {
cotigac 18:b02fc0e53df8 53 Thread::signal_wait(0x1);
cotigac 18:b02fc0e53df8 54 button_pressed++;
cotigac 18:b02fc0e53df8 55 }
sam_grove 2:3e7685cfb2a7 56 }
sam_grove 2:3e7685cfb2a7 57
FSL\B36402 23:6f13fea3cace 58 void events_thread(void const *argument)
FSL\B36402 23:6f13fea3cace 59 {
FSL\B36402 23:6f13fea3cace 60 uint8_t rcvd = 0;
FSL\B36402 23:6f13fea3cace 61
FSL\B36402 23:6f13fea3cace 62 while (true)
FSL\B36402 23:6f13fea3cace 63 {
FSL\B36402 23:6f13fea3cace 64 Thread::signal_wait(0x1);
FSL\B36402 23:6f13fea3cace 65
FSL\B36402 23:6f13fea3cace 66 if(gMcps_Cnf_EVENT_c == (gTaskEventFlags & gMcps_Cnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 67 {
FSL\B36402 23:6f13fea3cace 68 //get back in RX
FSL\B36402 23:6f13fea3cace 69 MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 70
FSL\B36402 23:6f13fea3cace 71 //printf("McpsDataCnf: Packet sent\r\n");
FSL\B36402 24:088286081619 72 //fflush(stdout);
FSL\B36402 23:6f13fea3cace 73 }
FSL\B36402 23:6f13fea3cace 74
FSL\B36402 23:6f13fea3cace 75 if(gMcps_Ind_EVENT_c == (gTaskEventFlags & gMcps_Ind_EVENT_c))
FSL\B36402 23:6f13fea3cace 76 {
FSL\B36402 23:6f13fea3cace 77 rcvd = gAppRxPacket->smacPdu.smacPdu[0];
FSL\B36402 23:6f13fea3cace 78
FSL\B36402 23:6f13fea3cace 79 //get back in RX
FSL\B36402 23:6f13fea3cace 80 //gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
FSL\B36402 23:6f13fea3cace 81 //gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
FSL\B36402 23:6f13fea3cace 82 MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 83
FSL\B36402 23:6f13fea3cace 84 printf("McpsDataInd: Received %d\r\n", rcvd);
FSL\B36402 24:088286081619 85 fflush(stdout);
FSL\B36402 23:6f13fea3cace 86 }
FSL\B36402 23:6f13fea3cace 87
FSL\B36402 23:6f13fea3cace 88 if(gMlme_TimeoutInd_EVENT_c == (gTaskEventFlags & gMlme_TimeoutInd_EVENT_c))
FSL\B36402 23:6f13fea3cace 89 {
FSL\B36402 24:088286081619 90 printf("MlmeTimeoutInd: \r\n");
FSL\B36402 24:088286081619 91 fflush(stdout);
FSL\B36402 23:6f13fea3cace 92 }
FSL\B36402 23:6f13fea3cace 93
FSL\B36402 23:6f13fea3cace 94 if(gMlme_EdCnf_EVENT_c == (gTaskEventFlags & gMlme_EdCnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 95 {
FSL\B36402 24:088286081619 96 printf("EdCnf: \r\n");
FSL\B36402 24:088286081619 97 fflush(stdout);
FSL\B36402 23:6f13fea3cace 98 }
FSL\B36402 23:6f13fea3cace 99
FSL\B36402 23:6f13fea3cace 100 if(gMlme_CcaCnf_EVENT_c == (gTaskEventFlags & gMlme_CcaCnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 101 {
FSL\B36402 24:088286081619 102 printf("CcaCnf: \r\n");
FSL\B36402 24:088286081619 103 fflush(stdout);
FSL\B36402 23:6f13fea3cace 104 }
FSL\B36402 23:6f13fea3cace 105
FSL\B36402 23:6f13fea3cace 106 if(gWUSelf_EVENT_c == (gTaskEventFlags & gWUSelf_EVENT_c))
FSL\B36402 23:6f13fea3cace 107 {
FSL\B36402 23:6f13fea3cace 108
FSL\B36402 23:6f13fea3cace 109 }
FSL\B36402 23:6f13fea3cace 110
FSL\B36402 23:6f13fea3cace 111 gTaskEventFlags = 0;
FSL\B36402 23:6f13fea3cace 112 }
FSL\B36402 23:6f13fea3cace 113 }
FSL\B36402 23:6f13fea3cace 114
sam_grove 2:3e7685cfb2a7 115 int main()
sam_grove 2:3e7685cfb2a7 116 {
cotigac 18:b02fc0e53df8 117 Thread thread(led_thread);
cotigac 18:b02fc0e53df8 118 thread2 = new Thread(button_thread);
FSL\B36402 23:6f13fea3cace 119 eventsThread = new Thread(events_thread);
FSL\B36402 23:6f13fea3cace 120
FSL\B36402 23:6f13fea3cace 121 Phy_Init();
cotigac 19:71b793021c78 122 InitSmac();
cotigac 19:71b793021c78 123
FSL\B36402 23:6f13fea3cace 124 //Tell SMAC who to call when it needs to pass a message to the application thread.
FSL\B36402 23:6f13fea3cace 125 Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0);
FSL\B36402 23:6f13fea3cace 126
FSL\B36402 23:6f13fea3cace 127 InitApp();
FSL\B36402 23:6f13fea3cace 128
cotigac 18:b02fc0e53df8 129 button_pressed = 0;
cotigac 18:b02fc0e53df8 130 sw2.fall(&sw2_press);
cotigac 18:b02fc0e53df8 131 while (true) {
cotigac 18:b02fc0e53df8 132 Thread::wait(5000);
FSL\B36402 24:088286081619 133
FSL\B36402 23:6f13fea3cace 134 gAppTxPacket->smacPdu.smacPdu[0] = (uint8_t)button_pressed;
FSL\B36402 23:6f13fea3cace 135 gAppTxPacket->u8DataLength = 1;
FSL\B36402 23:6f13fea3cace 136 (void)MLMERXDisableRequest();
FSL\B36402 23:6f13fea3cace 137 (void)MCPSDataRequest(gAppTxPacket);
FSL\B36402 24:088286081619 138
cotigac 18:b02fc0e53df8 139 printf("SW2 was pressed (last 5 seconds): %d \r\n", button_pressed);
cotigac 18:b02fc0e53df8 140 fflush(stdout);
cotigac 18:b02fc0e53df8 141 button_pressed = 0;
sam_grove 2:3e7685cfb2a7 142 }
sam_grove 2:3e7685cfb2a7 143 }
cotigac 19:71b793021c78 144
FSL\B36402 23:6f13fea3cace 145 void InitApp()
FSL\B36402 23:6f13fea3cace 146 {
FSL\B36402 23:6f13fea3cace 147 gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer
FSL\B36402 23:6f13fea3cace 148 gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
FSL\B36402 23:6f13fea3cace 149
FSL\B36402 23:6f13fea3cace 150 InitProject();
FSL\B36402 23:6f13fea3cace 151
FSL\B36402 23:6f13fea3cace 152 SMACFillHeader(&(gAppTxPacket->smacHeader), gDefaultAddress_c);
FSL\B36402 23:6f13fea3cace 153
FSL\B36402 23:6f13fea3cace 154 (void)MLMEPAOutputAdjust(gDefaultOutputPower_c);
FSL\B36402 23:6f13fea3cace 155 (void)MLMESetChannelRequest(gDefaultChannelNumber_c);
FSL\B36402 23:6f13fea3cace 156 (void)MLMEConfigureTxContext(&txConfigContext);
FSL\B36402 23:6f13fea3cace 157 //AppDelayTmr = TMR_AllocateTimer();
FSL\B36402 23:6f13fea3cace 158 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
FSL\B36402 23:6f13fea3cace 159 (void)MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 160 }
FSL\B36402 23:6f13fea3cace 161
FSL\B36402 23:6f13fea3cace 162 /* (Management) Sap handler for managing timeout indication and ED confirm
FSL\B36402 23:6f13fea3cace 163 This is running in INTERRUPT context, so need to send messages to one of the task */
cotigac 19:71b793021c78 164 smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance)
cotigac 19:71b793021c78 165 {
cotigac 19:71b793021c78 166 switch(pMsg->msgType)
cotigac 19:71b793021c78 167 {
FSL\B36402 23:6f13fea3cace 168 case gMlmeEdCnf_c:
FSL\B36402 23:6f13fea3cace 169 gTaskEventFlags |= gMlme_EdCnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 170 break;
FSL\B36402 23:6f13fea3cace 171 case gMlmeCcaCnf_c:
FSL\B36402 23:6f13fea3cace 172 gTaskEventFlags |= gMlme_CcaCnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 173 break;
FSL\B36402 23:6f13fea3cace 174 case gMlmeTimeoutInd_c:
FSL\B36402 23:6f13fea3cace 175 gTaskEventFlags |= gMlme_TimeoutInd_EVENT_c;
FSL\B36402 23:6f13fea3cace 176 break;
FSL\B36402 23:6f13fea3cace 177 default:
FSL\B36402 23:6f13fea3cace 178 break;
cotigac 19:71b793021c78 179 }
FSL\B36402 23:6f13fea3cace 180 eventsThread->signal_set(0x1);
cotigac 19:71b793021c78 181 MEM_BufferFree(pMsg);
cotigac 19:71b793021c78 182 return gErrorNoError_c;
cotigac 19:71b793021c78 183 }
cotigac 19:71b793021c78 184
FSL\B36402 23:6f13fea3cace 185 /* (Data) Sap handler for managing data confirm and data indication
FSL\B36402 23:6f13fea3cace 186 This is running in INTERRUPT context, so need to send messages to one of the task */
cotigac 19:71b793021c78 187 smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance)
FSL\B36402 23:6f13fea3cace 188 {
FSL\B36402 23:6f13fea3cace 189 switch(pMsg->msgType)
cotigac 19:71b793021c78 190 {
FSL\B36402 23:6f13fea3cace 191 case gMcpsDataInd_c:
FSL\B36402 23:6f13fea3cace 192 if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c)
FSL\B36402 23:6f13fea3cace 193 {
FSL\B36402 23:6f13fea3cace 194 gTaskEventFlags |= gMcps_Ind_EVENT_c;
FSL\B36402 23:6f13fea3cace 195 }
FSL\B36402 23:6f13fea3cace 196 break;
FSL\B36402 23:6f13fea3cace 197
FSL\B36402 23:6f13fea3cace 198 case gMcpsDataCnf_c:
FSL\B36402 23:6f13fea3cace 199 #ifdef VERBOSE
FSL\B36402 23:6f13fea3cace 200 if(pMsg->msgData.dataCnf.status == gErrorChannelBusy_c)
FSL\B36402 23:6f13fea3cace 201 {
FSL\B36402 23:6f13fea3cace 202 bCCAFailed = TRUE;
FSL\B36402 23:6f13fea3cace 203 }
FSL\B36402 23:6f13fea3cace 204
FSL\B36402 23:6f13fea3cace 205 if(pMsg->msgData.dataCnf.status == gErrorNoAck_c)
FSL\B36402 23:6f13fea3cace 206 {
FSL\B36402 23:6f13fea3cace 207 bACKFailed = TRUE;
FSL\B36402 23:6f13fea3cace 208 }
cotigac 19:71b793021c78 209 #endif
FSL\B36402 23:6f13fea3cace 210
FSL\B36402 23:6f13fea3cace 211 gTaskEventFlags |= gMcps_Cnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 212 break;
FSL\B36402 23:6f13fea3cace 213
FSL\B36402 23:6f13fea3cace 214 default:
FSL\B36402 23:6f13fea3cace 215 break;
FSL\B36402 23:6f13fea3cace 216 }
FSL\B36402 23:6f13fea3cace 217
FSL\B36402 23:6f13fea3cace 218 eventsThread->signal_set(0x1);
FSL\B36402 23:6f13fea3cace 219 MEM_BufferFree(pMsg);
FSL\B36402 23:6f13fea3cace 220
FSL\B36402 23:6f13fea3cace 221 return gErrorNoError_c;
cotigac 19:71b793021c78 222 }
cotigac 19:71b793021c78 223
cotigac 19:71b793021c78 224 void InitProject(void)
cotigac 19:71b793021c78 225 {
cotigac 19:71b793021c78 226 /*Global Data init*/
cotigac 19:71b793021c78 227 #ifdef VERBOSE
cotigac 19:71b793021c78 228 bACKFailed = FALSE;
cotigac 19:71b793021c78 229 bCCAFailed = FALSE;
cotigac 19:71b793021c78 230 #endif
FSL\B36402 23:6f13fea3cace 231
FSL\B36402 23:6f13fea3cace 232 gTaskEventFlags = 0;
FSL\B36402 23:6f13fea3cace 233
cotigac 19:71b793021c78 234 txConfigContext.autoAck = FALSE;
cotigac 19:71b793021c78 235 txConfigContext.ccaBeforeTx = FALSE;
cotigac 19:71b793021c78 236 txConfigContext.retryCountAckFail = 0;
cotigac 19:71b793021c78 237 txConfigContext.retryCountCCAFail = 0;
FSL\B36402 23:6f13fea3cace 238 }