This program utilizes the mcr20 Thread Shield on the FRDM-K64F MCU which is a two-part workspace (HVAC Server (RX)/Probe(TX)) to handle low temperature events read at the probe(s) to prevent pipes from freezing.

Dependencies:   DHT fsl_phy_mcr20a fsl_smac mbed-rtos mbed

Fork of mcr20_wireless_uart by NXP

Committer:
haircules
Date:
Thu Mar 30 20:31:09 2017 +0000
Revision:
29:c49f83ab80bd
Parent:
27:1eb29717bfd9
SmartPipe Probe(TX)

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"
haircules 29:c49f83ab80bd 3 #include "DHT.h"
FSL\B36402 23:6f13fea3cace 4 #include "Phy.h"
cotigac 19:71b793021c78 5 #include "SMAC_Interface.h"
cotigac 19:71b793021c78 6 #include "SMAC_Config.h"
andreikovacs 27:1eb29717bfd9 7 #include "MemManager.h"
andreikovacs 27:1eb29717bfd9 8 #include "circular_buffer.h"
cotigac 19:71b793021c78 9
andreikovacs 27:1eb29717bfd9 10 char * const cu8FreescaleLogo[]={
andreikovacs 27:1eb29717bfd9 11 "\f\r\n",
andreikovacs 27:1eb29717bfd9 12 "\n\r\n\r\n\r #\n",
andreikovacs 27:1eb29717bfd9 13 "\r ###\n",
andreikovacs 27:1eb29717bfd9 14 "\r ### *\n",
andreikovacs 27:1eb29717bfd9 15 "\r # ***\n",
andreikovacs 27:1eb29717bfd9 16 "\r *** #\n",
andreikovacs 27:1eb29717bfd9 17 "\r * ###\n",
andreikovacs 27:1eb29717bfd9 18 "\r ###\n",
andreikovacs 27:1eb29717bfd9 19 "\r * #\n",
andreikovacs 27:1eb29717bfd9 20 "\r ***\n",
andreikovacs 27:1eb29717bfd9 21 "\r *** #\n",
andreikovacs 27:1eb29717bfd9 22 "\r # * ###\n",
andreikovacs 27:1eb29717bfd9 23 "\r ### ###\n",
andreikovacs 27:1eb29717bfd9 24 "\r ### * # F R E E S C A L E\n",
andreikovacs 27:1eb29717bfd9 25 "\r # ***\n",
andreikovacs 27:1eb29717bfd9 26 "\r *** S E M I C O N D U C T O R\n",
andreikovacs 27:1eb29717bfd9 27 "\r # *\n",
andreikovacs 27:1eb29717bfd9 28 "\r ### 2 0 1 5\n",
andreikovacs 27:1eb29717bfd9 29 "\r ###\n",
andreikovacs 27:1eb29717bfd9 30 "\r # Wireless Uart Demo\r\n\n",
andreikovacs 27:1eb29717bfd9 31 NULL
andreikovacs 27:1eb29717bfd9 32 };
andreikovacs 26:56ca40dcfae1 33
FSL\B36402 23:6f13fea3cace 34 #define gMcps_Cnf_EVENT_c (1<<1)
FSL\B36402 23:6f13fea3cace 35 #define gMcps_Ind_EVENT_c (1<<2)
FSL\B36402 23:6f13fea3cace 36 #define gMlme_EdCnf_EVENT_c (1<<3)
FSL\B36402 23:6f13fea3cace 37 #define gMlme_CcaCnf_EVENT_c (1<<4)
FSL\B36402 23:6f13fea3cace 38 #define gMlme_TimeoutInd_EVENT_c (1<<5)
FSL\B36402 23:6f13fea3cace 39 #define gWUSelf_EVENT_c (1<<6)
FSL\B36402 23:6f13fea3cace 40
andreikovacs 27:1eb29717bfd9 41 #define gDefaultBaudRate_UART_c 115200UL
andreikovacs 27:1eb29717bfd9 42
haircules 29:c49f83ab80bd 43 #define BUF_SIZE 3
haircules 29:c49f83ab80bd 44
andreikovacs 27:1eb29717bfd9 45 Serial uart(USBTX, USBRX);
andreikovacs 27:1eb29717bfd9 46 CircularBuffer uartBuf;
haircules 29:c49f83ab80bd 47 DHT tempSensor(D4,DHT22);
andreikovacs 27:1eb29717bfd9 48
cotigac 19:71b793021c78 49 #ifdef VERBOSE
cotigac 19:71b793021c78 50 static bool_t bCCAFailed;
cotigac 19:71b793021c78 51 static bool_t bACKFailed;
cotigac 19:71b793021c78 52 #endif
FSL\B36402 23:6f13fea3cace 53 uint32_t gTaskEventFlags;
cotigac 19:71b793021c78 54 static uint8_t gau8TxDataBuffer[gMaxSmacSDULength_c + sizeof(rxPacket_t)];
sam_grove 25:f40bc034cd8b 55 txPacket_t *gAppTxPacket;
sam_grove 25:f40bc034cd8b 56 rxPacket_t *gAppRxPacket;
cotigac 19:71b793021c78 57 static txContextConfig_t txConfigContext;
cotigac 19:71b793021c78 58
andreikovacs 27:1eb29717bfd9 59
andreikovacs 27:1eb29717bfd9 60 void PrintMenu(char * const pu8Menu[])
andreikovacs 27:1eb29717bfd9 61 {
andreikovacs 27:1eb29717bfd9 62 uint8_t u8Index = 0;
andreikovacs 27:1eb29717bfd9 63 while(pu8Menu[u8Index]){
andreikovacs 27:1eb29717bfd9 64 uart.printf(pu8Menu[u8Index]);
andreikovacs 27:1eb29717bfd9 65 u8Index++;
andreikovacs 27:1eb29717bfd9 66 }
andreikovacs 27:1eb29717bfd9 67 }
andreikovacs 27:1eb29717bfd9 68
andreikovacs 27:1eb29717bfd9 69
cotigac 19:71b793021c78 70 void InitProject(void);
FSL\B36402 23:6f13fea3cace 71 void InitApp(void);
FSL\B36402 23:6f13fea3cace 72
cotigac 19:71b793021c78 73 extern smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance);
cotigac 19:71b793021c78 74 extern smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance);
cotigac 19:71b793021c78 75
andreikovacs 27:1eb29717bfd9 76 DigitalOut led1(LED_GREEN);
haircules 29:c49f83ab80bd 77 DigitalOut led2(LED_RED);
haircules 29:c49f83ab80bd 78 DigitalOut led3(LED_BLUE);
cotigac 18:b02fc0e53df8 79 InterruptIn sw2(SW2);
cotigac 18:b02fc0e53df8 80 uint32_t button_pressed;
haircules 29:c49f83ab80bd 81 uint8_t timer;
cotigac 18:b02fc0e53df8 82 Thread *thread2;
FSL\B36402 23:6f13fea3cace 83 Thread *eventsThread;
haircules 29:c49f83ab80bd 84 Thread *timerThread;
sam_grove 2:3e7685cfb2a7 85
andreikovacs 27:1eb29717bfd9 86 void uartSetBaudRate(uint32_t b)
andreikovacs 27:1eb29717bfd9 87 {
andreikovacs 27:1eb29717bfd9 88 uart.baud(b);
andreikovacs 27:1eb29717bfd9 89 }
andreikovacs 27:1eb29717bfd9 90
haircules 29:c49f83ab80bd 91 /*ISR for sw2*/
haircules 29:c49f83ab80bd 92 /*On sw2 press, spoof HVAC server by sending 30F as current temp*/
cotigac 18:b02fc0e53df8 93 void sw2_press(void)
haircules 29:c49f83ab80bd 94 {
haircules 29:c49f83ab80bd 95 /*Add fake temp to buffer*/
haircules 29:c49f83ab80bd 96 (void)uartBuf.addToBuffer('0');
haircules 29:c49f83ab80bd 97 (void)uartBuf.addToBuffer('3');
haircules 29:c49f83ab80bd 98 (void)uartBuf.addToBuffer('0');
haircules 29:c49f83ab80bd 99
haircules 29:c49f83ab80bd 100 /*Set flags for TX in eventsThread and signal that an event has occured*/
haircules 29:c49f83ab80bd 101 gTaskEventFlags |= gWUSelf_EVENT_c;
haircules 29:c49f83ab80bd 102 thread2->signal_set(0x1);
haircules 29:c49f83ab80bd 103
haircules 29:c49f83ab80bd 104 }
haircules 29:c49f83ab80bd 105
haircules 29:c49f83ab80bd 106 void timer_thread(void const *argument)
cotigac 18:b02fc0e53df8 107 {
haircules 29:c49f83ab80bd 108 char Buffer[BUF_SIZE];
haircules 29:c49f83ab80bd 109 int temp = 0;
haircules 29:c49f83ab80bd 110 int error = 0;
haircules 29:c49f83ab80bd 111
haircules 29:c49f83ab80bd 112 while (true) {
haircules 29:c49f83ab80bd 113
haircules 29:c49f83ab80bd 114 Thread::wait(1000);
haircules 29:c49f83ab80bd 115 timer++;
haircules 29:c49f83ab80bd 116
haircules 29:c49f83ab80bd 117 printf("timer(%d)\n\r",timer);
haircules 29:c49f83ab80bd 118
haircules 29:c49f83ab80bd 119 /*Update temp and load to Buffer every 10 seconds*/
haircules 29:c49f83ab80bd 120 if(timer >= 10)
haircules 29:c49f83ab80bd 121 {
haircules 29:c49f83ab80bd 122 printf("Timer up! Preparing to send temp..\n\r");
haircules 29:c49f83ab80bd 123
haircules 29:c49f83ab80bd 124 /*Reset timer*/
haircules 29:c49f83ab80bd 125 timer = 0;
haircules 29:c49f83ab80bd 126
haircules 29:c49f83ab80bd 127 /*Wait for tempSensor data to be ready*/
haircules 29:c49f83ab80bd 128 error = tempSensor.readData();
haircules 29:c49f83ab80bd 129 while(0 != error)
haircules 29:c49f83ab80bd 130 {
haircules 29:c49f83ab80bd 131 error = tempSensor.readData();
haircules 29:c49f83ab80bd 132 }
haircules 29:c49f83ab80bd 133
haircules 29:c49f83ab80bd 134 temp = (int)tempSensor.ReadTemperature(FARENHEIT);
haircules 29:c49f83ab80bd 135
haircules 29:c49f83ab80bd 136 /*Convert temp to ASCII and add to Buffer*/
haircules 29:c49f83ab80bd 137 Buffer[0] = (temp / 100) + 0x30;//hundreds digit
haircules 29:c49f83ab80bd 138 Buffer[1] = ((temp % 100) / 10) + 0x30;//tens digit
haircules 29:c49f83ab80bd 139 Buffer[2] = ((temp % 100) % 10) + 0x30;//ones digit
haircules 29:c49f83ab80bd 140
haircules 29:c49f83ab80bd 141 /*Buffer gets ASCII conversion of temp*/
haircules 29:c49f83ab80bd 142 for(int i = 0; i < sizeof(Buffer); i++)
haircules 29:c49f83ab80bd 143 {
haircules 29:c49f83ab80bd 144 (void)uartBuf.addToBuffer(Buffer[i]);
haircules 29:c49f83ab80bd 145 }/*end for*/
haircules 29:c49f83ab80bd 146 }/*end if*/
haircules 29:c49f83ab80bd 147 }/*end while*/
cotigac 18:b02fc0e53df8 148 }
sam_grove 2:3e7685cfb2a7 149
cotigac 18:b02fc0e53df8 150 void led_thread(void const *argument)
cotigac 18:b02fc0e53df8 151 {
cotigac 18:b02fc0e53df8 152 while (true) {
cotigac 18:b02fc0e53df8 153 led1 = !led1;
andreikovacs 27:1eb29717bfd9 154 Thread::wait(200);
sam_grove 2:3e7685cfb2a7 155 }
sam_grove 2:3e7685cfb2a7 156 }
sam_grove 2:3e7685cfb2a7 157
cotigac 18:b02fc0e53df8 158 void button_thread(void const *argument)
sam_grove 2:3e7685cfb2a7 159 {
cotigac 18:b02fc0e53df8 160 while (true) {
cotigac 18:b02fc0e53df8 161 Thread::signal_wait(0x1);
cotigac 18:b02fc0e53df8 162 button_pressed++;
cotigac 18:b02fc0e53df8 163 }
sam_grove 2:3e7685cfb2a7 164 }
sam_grove 2:3e7685cfb2a7 165
FSL\B36402 23:6f13fea3cace 166 void events_thread(void const *argument)
FSL\B36402 23:6f13fea3cace 167 {
andreikovacs 27:1eb29717bfd9 168 uint8_t rcvd = 0, c = 0;
FSL\B36402 23:6f13fea3cace 169
FSL\B36402 23:6f13fea3cace 170 while (true)
FSL\B36402 23:6f13fea3cace 171 {
haircules 29:c49f83ab80bd 172 /*Wait for signal*/
FSL\B36402 23:6f13fea3cace 173 Thread::signal_wait(0x1);
haircules 29:c49f83ab80bd 174
haircules 29:c49f83ab80bd 175 /*If packet has been sent, reenable recieving mode*/
FSL\B36402 23:6f13fea3cace 176 if(gMcps_Cnf_EVENT_c == (gTaskEventFlags & gMcps_Cnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 177 {
haircules 29:c49f83ab80bd 178 /*Reenable RX requests*/
FSL\B36402 23:6f13fea3cace 179 MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 180
FSL\B36402 23:6f13fea3cace 181 }
FSL\B36402 23:6f13fea3cace 182
haircules 29:c49f83ab80bd 183 /*If a packet has been recieved, rcvd gets data*/
FSL\B36402 23:6f13fea3cace 184 if(gMcps_Ind_EVENT_c == (gTaskEventFlags & gMcps_Ind_EVENT_c))
FSL\B36402 23:6f13fea3cace 185 {
haircules 29:c49f83ab80bd 186 for(int i = 0; i <= gAppRxPacket->u8DataLength; i++)
haircules 29:c49f83ab80bd 187 {
haircules 29:c49f83ab80bd 188 rcvd = gAppRxPacket->smacPdu.smacPdu[i];
haircules 29:c49f83ab80bd 189 uart.printf("%c", rcvd);
haircules 29:c49f83ab80bd 190 }
haircules 29:c49f83ab80bd 191
haircules 29:c49f83ab80bd 192 /*Reenable RX requests*/
FSL\B36402 23:6f13fea3cace 193 MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 194
andreikovacs 27:1eb29717bfd9 195
FSL\B36402 23:6f13fea3cace 196 }
FSL\B36402 23:6f13fea3cace 197
FSL\B36402 23:6f13fea3cace 198 if(gMlme_TimeoutInd_EVENT_c == (gTaskEventFlags & gMlme_TimeoutInd_EVENT_c))
FSL\B36402 23:6f13fea3cace 199 {
andreikovacs 27:1eb29717bfd9 200 uart.printf("MlmeTimeoutInd: \r\n");
FSL\B36402 23:6f13fea3cace 201 }
FSL\B36402 23:6f13fea3cace 202
FSL\B36402 23:6f13fea3cace 203 if(gMlme_EdCnf_EVENT_c == (gTaskEventFlags & gMlme_EdCnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 204 {
andreikovacs 27:1eb29717bfd9 205 uart.printf("EdCnf: \r\n");
FSL\B36402 23:6f13fea3cace 206 }
FSL\B36402 23:6f13fea3cace 207
FSL\B36402 23:6f13fea3cace 208 if(gMlme_CcaCnf_EVENT_c == (gTaskEventFlags & gMlme_CcaCnf_EVENT_c))
FSL\B36402 23:6f13fea3cace 209 {
andreikovacs 27:1eb29717bfd9 210 uart.printf("CcaCnf: \r\n");
FSL\B36402 23:6f13fea3cace 211 }
FSL\B36402 23:6f13fea3cace 212
haircules 29:c49f83ab80bd 213 /*If there is something on the buffer, load packet and send*/
FSL\B36402 23:6f13fea3cace 214 if(gWUSelf_EVENT_c == (gTaskEventFlags & gWUSelf_EVENT_c))
FSL\B36402 23:6f13fea3cace 215 {
haircules 29:c49f83ab80bd 216
haircules 29:c49f83ab80bd 217 /*Set Data Length to number of items on uartBuf*/
haircules 29:c49f83ab80bd 218 gAppTxPacket->u8DataLength = uartBuf.getCount();
haircules 29:c49f83ab80bd 219
haircules 29:c49f83ab80bd 220 /*Load TX packets until uartBuf is empty*/
haircules 29:c49f83ab80bd 221 for(int i = 0; uartBuf.getCount() > 0; i++)
andreikovacs 27:1eb29717bfd9 222 {
haircules 29:c49f83ab80bd 223 uartBuf.getFromBuffer(&c);
haircules 29:c49f83ab80bd 224 gAppTxPacket->smacPdu.smacPdu[i] = c;
haircules 29:c49f83ab80bd 225 }
haircules 29:c49f83ab80bd 226 /*Disable RX requests (block incoming packets)*/
andreikovacs 27:1eb29717bfd9 227 (void)MLMERXDisableRequest();
haircules 29:c49f83ab80bd 228 /*Generate request to send data packet*/
andreikovacs 27:1eb29717bfd9 229 (void)MCPSDataRequest(gAppTxPacket);
haircules 29:c49f83ab80bd 230
haircules 29:c49f83ab80bd 231 printf("Data Sent\n\r");
haircules 29:c49f83ab80bd 232
haircules 29:c49f83ab80bd 233 /*Toggle Red LED after transmission*/
haircules 29:c49f83ab80bd 234 led2 = !led2;
haircules 29:c49f83ab80bd 235
FSL\B36402 23:6f13fea3cace 236 }
andreikovacs 27:1eb29717bfd9 237
FSL\B36402 23:6f13fea3cace 238 gTaskEventFlags = 0;
FSL\B36402 23:6f13fea3cace 239 }
FSL\B36402 23:6f13fea3cace 240 }
FSL\B36402 23:6f13fea3cace 241
sam_grove 2:3e7685cfb2a7 242 int main()
haircules 29:c49f83ab80bd 243 {
haircules 29:c49f83ab80bd 244 led1 = 1;/*Turn off Green LED*/
haircules 29:c49f83ab80bd 245 led2 = 1;/*Turn off Red LED*/
haircules 29:c49f83ab80bd 246 led3 = 1;/*Turn off Blue LED*/
haircules 29:c49f83ab80bd 247
andreikovacs 26:56ca40dcfae1 248 MEM_Init();
cotigac 18:b02fc0e53df8 249 Thread thread(led_thread);
cotigac 18:b02fc0e53df8 250 thread2 = new Thread(button_thread);
FSL\B36402 23:6f13fea3cace 251 eventsThread = new Thread(events_thread);
haircules 29:c49f83ab80bd 252 timerThread = new Thread(timer_thread);
FSL\B36402 23:6f13fea3cace 253 Phy_Init();
cotigac 19:71b793021c78 254 InitSmac();
andreikovacs 27:1eb29717bfd9 255
andreikovacs 27:1eb29717bfd9 256 uartSetBaudRate(gDefaultBaudRate_UART_c);
andreikovacs 27:1eb29717bfd9 257
FSL\B36402 23:6f13fea3cace 258 //Tell SMAC who to call when it needs to pass a message to the application thread.
FSL\B36402 23:6f13fea3cace 259 Smac_RegisterSapHandlers((SMAC_APP_MCPS_SapHandler_t)smacToAppMcpsSap,(SMAC_APP_MLME_SapHandler_t)smacToAppMlmeSap,0);
FSL\B36402 23:6f13fea3cace 260
FSL\B36402 23:6f13fea3cace 261 InitApp();
andreikovacs 27:1eb29717bfd9 262
andreikovacs 27:1eb29717bfd9 263 PrintMenu(cu8FreescaleLogo);
FSL\B36402 23:6f13fea3cace 264
cotigac 18:b02fc0e53df8 265 button_pressed = 0;
cotigac 18:b02fc0e53df8 266 sw2.fall(&sw2_press);
andreikovacs 27:1eb29717bfd9 267 while (true)
andreikovacs 27:1eb29717bfd9 268 {
haircules 29:c49f83ab80bd 269 /*Set signal for eventsThread if anything on uartBuf to be sent*/
andreikovacs 27:1eb29717bfd9 270 if ( uartBuf.getCount() )
andreikovacs 27:1eb29717bfd9 271 {
andreikovacs 27:1eb29717bfd9 272 gTaskEventFlags |= gWUSelf_EVENT_c;
andreikovacs 27:1eb29717bfd9 273 eventsThread->signal_set(0x1);
haircules 29:c49f83ab80bd 274
andreikovacs 27:1eb29717bfd9 275 }
andreikovacs 27:1eb29717bfd9 276 Thread::yield();
sam_grove 2:3e7685cfb2a7 277 }
sam_grove 2:3e7685cfb2a7 278 }
cotigac 19:71b793021c78 279
FSL\B36402 23:6f13fea3cace 280 void InitApp()
FSL\B36402 23:6f13fea3cace 281 {
FSL\B36402 23:6f13fea3cace 282 gAppTxPacket = (txPacket_t*)gau8TxDataBuffer; //Map TX packet to buffer
FSL\B36402 23:6f13fea3cace 283 gAppRxPacket = (rxPacket_t*)MEM_BufferAlloc(gMaxSmacSDULength_c + sizeof(rxPacket_t));
FSL\B36402 23:6f13fea3cace 284
FSL\B36402 23:6f13fea3cace 285 InitProject();
FSL\B36402 23:6f13fea3cace 286
FSL\B36402 23:6f13fea3cace 287 SMACFillHeader(&(gAppTxPacket->smacHeader), gDefaultAddress_c);
FSL\B36402 23:6f13fea3cace 288
FSL\B36402 23:6f13fea3cace 289 (void)MLMEPAOutputAdjust(gDefaultOutputPower_c);
FSL\B36402 23:6f13fea3cace 290 (void)MLMESetChannelRequest(gDefaultChannelNumber_c);
FSL\B36402 23:6f13fea3cace 291 (void)MLMEConfigureTxContext(&txConfigContext);
FSL\B36402 23:6f13fea3cace 292 //AppDelayTmr = TMR_AllocateTimer();
FSL\B36402 23:6f13fea3cace 293 gAppRxPacket->u8MaxDataLength = gMaxSmacSDULength_c;
FSL\B36402 23:6f13fea3cace 294 (void)MLMERXEnableRequest(gAppRxPacket, 0);
FSL\B36402 23:6f13fea3cace 295 }
FSL\B36402 23:6f13fea3cace 296
FSL\B36402 23:6f13fea3cace 297 /* (Management) Sap handler for managing timeout indication and ED confirm
FSL\B36402 23:6f13fea3cace 298 This is running in INTERRUPT context, so need to send messages to one of the task */
cotigac 19:71b793021c78 299 smacErrors_t smacToAppMlmeSap(smacToAppMlmeMessage_t* pMsg, instanceId_t instance)
cotigac 19:71b793021c78 300 {
cotigac 19:71b793021c78 301 switch(pMsg->msgType)
cotigac 19:71b793021c78 302 {
FSL\B36402 23:6f13fea3cace 303 case gMlmeEdCnf_c:
FSL\B36402 23:6f13fea3cace 304 gTaskEventFlags |= gMlme_EdCnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 305 break;
FSL\B36402 23:6f13fea3cace 306 case gMlmeCcaCnf_c:
FSL\B36402 23:6f13fea3cace 307 gTaskEventFlags |= gMlme_CcaCnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 308 break;
FSL\B36402 23:6f13fea3cace 309 case gMlmeTimeoutInd_c:
FSL\B36402 23:6f13fea3cace 310 gTaskEventFlags |= gMlme_TimeoutInd_EVENT_c;
FSL\B36402 23:6f13fea3cace 311 break;
FSL\B36402 23:6f13fea3cace 312 default:
FSL\B36402 23:6f13fea3cace 313 break;
cotigac 19:71b793021c78 314 }
FSL\B36402 23:6f13fea3cace 315 eventsThread->signal_set(0x1);
cotigac 19:71b793021c78 316 MEM_BufferFree(pMsg);
cotigac 19:71b793021c78 317 return gErrorNoError_c;
cotigac 19:71b793021c78 318 }
cotigac 19:71b793021c78 319
FSL\B36402 23:6f13fea3cace 320 /* (Data) Sap handler for managing data confirm and data indication
FSL\B36402 23:6f13fea3cace 321 This is running in INTERRUPT context, so need to send messages to one of the task */
cotigac 19:71b793021c78 322 smacErrors_t smacToAppMcpsSap(smacToAppDataMessage_t* pMsg, instanceId_t instance)
FSL\B36402 23:6f13fea3cace 323 {
FSL\B36402 23:6f13fea3cace 324 switch(pMsg->msgType)
cotigac 19:71b793021c78 325 {
FSL\B36402 23:6f13fea3cace 326 case gMcpsDataInd_c:
FSL\B36402 23:6f13fea3cace 327 if(pMsg->msgData.dataInd.pRxPacket->rxStatus == rxSuccessStatus_c)
FSL\B36402 23:6f13fea3cace 328 {
FSL\B36402 23:6f13fea3cace 329 gTaskEventFlags |= gMcps_Ind_EVENT_c;
FSL\B36402 23:6f13fea3cace 330 }
FSL\B36402 23:6f13fea3cace 331 break;
FSL\B36402 23:6f13fea3cace 332
FSL\B36402 23:6f13fea3cace 333 case gMcpsDataCnf_c:
FSL\B36402 23:6f13fea3cace 334 #ifdef VERBOSE
FSL\B36402 23:6f13fea3cace 335 if(pMsg->msgData.dataCnf.status == gErrorChannelBusy_c)
FSL\B36402 23:6f13fea3cace 336 {
FSL\B36402 23:6f13fea3cace 337 bCCAFailed = TRUE;
FSL\B36402 23:6f13fea3cace 338 }
FSL\B36402 23:6f13fea3cace 339
FSL\B36402 23:6f13fea3cace 340 if(pMsg->msgData.dataCnf.status == gErrorNoAck_c)
FSL\B36402 23:6f13fea3cace 341 {
FSL\B36402 23:6f13fea3cace 342 bACKFailed = TRUE;
FSL\B36402 23:6f13fea3cace 343 }
cotigac 19:71b793021c78 344 #endif
FSL\B36402 23:6f13fea3cace 345
FSL\B36402 23:6f13fea3cace 346 gTaskEventFlags |= gMcps_Cnf_EVENT_c;
FSL\B36402 23:6f13fea3cace 347 break;
FSL\B36402 23:6f13fea3cace 348
FSL\B36402 23:6f13fea3cace 349 default:
FSL\B36402 23:6f13fea3cace 350 break;
FSL\B36402 23:6f13fea3cace 351 }
FSL\B36402 23:6f13fea3cace 352 eventsThread->signal_set(0x1);
FSL\B36402 23:6f13fea3cace 353 MEM_BufferFree(pMsg);
FSL\B36402 23:6f13fea3cace 354
FSL\B36402 23:6f13fea3cace 355 return gErrorNoError_c;
cotigac 19:71b793021c78 356 }
cotigac 19:71b793021c78 357
cotigac 19:71b793021c78 358 void InitProject(void)
cotigac 19:71b793021c78 359 {
cotigac 19:71b793021c78 360 /*Global Data init*/
cotigac 19:71b793021c78 361 #ifdef VERBOSE
cotigac 19:71b793021c78 362 bACKFailed = FALSE;
cotigac 19:71b793021c78 363 bCCAFailed = FALSE;
cotigac 19:71b793021c78 364 #endif
FSL\B36402 23:6f13fea3cace 365
FSL\B36402 23:6f13fea3cace 366 gTaskEventFlags = 0;
FSL\B36402 23:6f13fea3cace 367
cotigac 19:71b793021c78 368 txConfigContext.autoAck = FALSE;
cotigac 19:71b793021c78 369 txConfigContext.ccaBeforeTx = FALSE;
cotigac 19:71b793021c78 370 txConfigContext.retryCountAckFail = 0;
cotigac 19:71b793021c78 371 txConfigContext.retryCountCCAFail = 0;
FSL\B36402 23:6f13fea3cace 372 }