SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.46
Simplifies the implementation of Internet connectivity
device.c
1 /*
2  * device.c - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the
17  * distribution.
18  *
19  * Neither the name of Texas Instruments Incorporated nor the names of
20  * its contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  */
36 
37 /*****************************************************************************/
38 /* Include files */
39 /*****************************************************************************/
40 #include <ti/drivers/net/wifi/simplelink.h>
41 #include <ti/drivers/net/wifi/source/protocol.h>
42 #include <ti/drivers/net/wifi/source/driver.h>
43 #include <ti/drivers/net/wifi/source/flowcont.h>
44 
45 /*****************************************************************************/
46 /* Internal functions */
47 /*****************************************************************************/
48 
49 static _i16 _SlDeviceGetStartResponseConvert(_i32 Status);
50 void _SlDeviceHandleResetRequestInternally(void);
51 void _SlDeviceResetRequestInitCompletedCB(_u32 Status, SlDeviceInitInfo_t *DeviceInitInfo);
52 
53 #define RESET_REQUEST_STOP_TIMEOUT (300)
54 
55 #ifndef SL_IF_OPEN_FLAGS
56 #define SL_IF_OPEN_FLAGS (0x0)
57 #endif
58 
59 #ifndef SL_IF_UART_REOPEN_FLAGS
60 #define SL_IF_UART_REOPEN_FLAGS (0x1)
61 #endif
62 
63 typedef struct
64 {
65  const void *pIfHdl; /* Holds the last opened interface handle */
66  _i8 *pDevName; /* Holds the last opened interface parameters */
67  _u32 ResetRequestSessionNumber; /* Special session number to be verified upon every reset request during provisioning */
68 } _SlDeviceCb_t;
69 
70 _SlDeviceCb_t DeviceCB; /* the device control block */
71 
72 static const _i16 StartResponseLUT[16] =
73 {
74  ROLE_RESERVED,
75  ROLE_STA,
76  SL_ERROR_ROLE_STA_ERR,
77  ROLE_AP,
78  SL_ERROR_ROLE_AP_ERR,
79  ROLE_P2P,
80  SL_ERROR_ROLE_P2P_ERR,
81  SL_ERROR_CALIB_FAIL,
82  SL_ERROR_FS_CORRUPTED_ERR,
83  SL_ERROR_FS_ALERT_ERR,
84  SL_ERROR_RESTORE_IMAGE_COMPLETE,
85  SL_ERROR_INCOMPLETE_PROGRAMMING,
86  ROLE_TAG,
87  SL_ERROR_ROLE_TAG_ERR,
88  SL_ERROR_FIPS_ERR,
89  SL_ERROR_GENERAL_ERR
90 };
91 
92 static _i16 _SlDeviceGetStartResponseConvert(_i32 Status)
93 {
94  return StartResponseLUT[Status & 0xF];
95 }
96 
97 /*****************************************************************************/
98 /* API Functions */
99 /*****************************************************************************/
100 
101 /*****************************************************************************/
102 /* sl_Task */
103 /*****************************************************************************/
104 #if _SL_INCLUDE_FUNC(sl_Task)
105 void* sl_Task(void* pEntry)
106 {
107 #ifdef _SlTaskEntry
108  return (void*)_SlTaskEntry();
109 #else
110  return (void*)0;
111 #endif
112 }
113 #endif
114 
115 /*****************************************************************************/
116 /* sl_Start */
117 /*****************************************************************************/
118 #if _SL_INCLUDE_FUNC(sl_Start)
119 _i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack)
120 {
121  _u8 ObjIdx = MAX_CONCURRENT_ACTIONS;
122  InitComplete_t AsyncRsp;
123 
124  _SlDrvMemZero(&AsyncRsp, sizeof(InitComplete_t));
125 
126  /* verify no error handling in progress. if in progress than
127  ignore the API execution and return immediately with an error */
128  VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
129  if (SL_IS_DEVICE_STARTED)
130  {
131  return SL_RET_CODE_DEV_ALREADY_STARTED;
132  }
133  /* Perform any preprocessing before enable networking services */
134 #ifdef sl_DeviceEnablePreamble
135  sl_DeviceEnablePreamble();
136 #endif
137 
138  /* ControlBlock init */
139  (void)_SlDrvDriverCBInit();
140 
141  /* open the interface: usually SPI or UART */
142  if (NULL == pIfHdl)
143  {
144  g_pCB->FD = sl_IfOpen((void *)pDevName, SL_IF_OPEN_FLAGS);
145  }
146  else
147  {
148  g_pCB->FD = (_SlFd_t)pIfHdl;
149  }
150 
151  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
152 
153  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
154  {
155  return SL_POOL_IS_EMPTY;
156  }
157 
158  if( g_pCB->FD >= (_SlFd_t)0)
159  {
160  /* store the interface parameters for the internal call of the
161  sl_start to be called upon reset request handling */
162  DeviceCB.pIfHdl = pIfHdl;
163  DeviceCB.pDevName = pDevName;
164 
165  /* Mark that device is in progress! */
166  SL_SET_DEVICE_START_IN_PROGRESS;
167 
168  sl_DeviceDisable();
169 
170  sl_IfRegIntHdlr((SL_P_EVENT_HANDLER)_SlDrvRxIrqHandler, NULL);
171 
172  g_pCB->pInitCallback = pInitCallBack;
173  sl_DeviceEnable();
174 
175  if (NULL == pInitCallBack)
176  {
177 
178  VERIFY_RET_OK(_SlDrvWaitForInternalAsyncEvent(ObjIdx, INIT_COMPLETE_TIMEOUT, SL_OPCODE_DEVICE_INITCOMPLETE));
179 
180  SL_UNSET_DEVICE_START_IN_PROGRESS;
181 
182  SL_SET_DEVICE_STARTED;
183 
184  /* release Pool Object */
185  _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
186  return _SlDeviceGetStartResponseConvert(AsyncRsp.Status);
187  }
188  else
189  {
190  return SL_RET_CODE_OK;
191  }
192  }
193  return SL_BAD_INTERFACE;
194 }
195 #endif
196 
197 /***************************************************************************
198 _SlDeviceHandleAsync_InitComplete - handles init complete signalling to
199 a waiting object
200 ****************************************************************************/
201 _SlReturnVal_t _SlDeviceHandleAsync_InitComplete(void *pVoidBuf)
202 {
203  InitComplete_t *pMsgArgs = (InitComplete_t *)_SL_RESP_ARGS_START(pVoidBuf);
204  SlDeviceInitInfo_t DeviceInitInfo;
205 
206  SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
207 
208  if(g_pCB->pInitCallback)
209  {
210  DeviceInitInfo.ChipId = pMsgArgs->ChipId;
211  DeviceInitInfo.MoreData = pMsgArgs->MoreData;
212  g_pCB->pInitCallback(_SlDeviceGetStartResponseConvert(pMsgArgs->Status), &DeviceInitInfo);
213  }
214  else
215  {
216  sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(InitComplete_t));
217  SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
218  }
219 
220  SL_DRV_PROTECTION_OBJ_UNLOCK();
221  if(g_pCB->pInitCallback)
222  {
223  SL_SET_DEVICE_STARTED;
224  SL_UNSET_DEVICE_START_IN_PROGRESS;
225  _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
226  }
227 
228  return SL_OS_RET_CODE_OK;
229  }
230 
231 
232 /***************************************************************************
233 _SlDeviceHandleAsync_Stop - handles stop signalling to
234 a waiting object
235 ****************************************************************************/
236 void _SlDeviceHandleAsync_Stop(void *pVoidBuf)
237 {
238  _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
239 
240  VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
241 
242  SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
243 
244  if (g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs != NULL)
245  {
246  sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
247  SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
248  }
249 
250  SL_DRV_PROTECTION_OBJ_UNLOCK();
251 
252  return;
253 }
254 
255 
256 /*****************************************************************************
257 sl_stop
258 ******************************************************************************/
259 typedef union
260 {
262  _BasicResponse_t Rsp;
263 }_SlStopMsg_u;
264 
265 static const _SlCmdCtrl_t _SlStopCmdCtrl =
266 {
267  SL_OPCODE_DEVICE_STOP_COMMAND,
268  (_SlArgSize_t)sizeof(SlDeviceStopCommand_t),
269  (_SlArgSize_t)sizeof(_BasicResponse_t)
270 };
271 
272 #if _SL_INCLUDE_FUNC(sl_Stop)
273 _i16 sl_Stop(const _u16 Timeout)
274 {
275  _i16 RetVal=0;
276  _SlStopMsg_u Msg;
277  _BasicResponse_t AsyncRsp;
278  _u8 ObjIdx = MAX_CONCURRENT_ACTIONS;
279  _u8 ReleasePoolObject = FALSE;
280  _u8 IsProvInProgress = FALSE;
281 
282  /* NOTE: don't check VERIFY_API_ALLOWED(), this command is not
283  * filtered in error handling and also not filtered in NWP lock state.
284  * If we are in the middle of assert handling than ignore stopping
285  * the device with timeout and force immediate shutdown as we would like
286  * to avoid any additional commands to the NWP */
287  if( (Timeout != 0) && (SL_IS_DEVICE_STARTED)
288  && (!SL_IS_RESTART_REQUIRED))
289  {
290  /* Clear the Async response structure */
291  _SlDrvMemZero(&AsyncRsp, sizeof(_BasicResponse_t));
292 
293  /* let the device make the shutdown using the defined timeout */
294  Msg.Cmd.Timeout = Timeout;
295 
296  IsProvInProgress = SL_IS_PROVISIONING_IN_PROGRESS;
297 
298  /* if provisioning in progress do not take pool object as we are not going to wait for it */
299  if (!IsProvInProgress)
300  {
301  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
302  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
303  {
304  return SL_POOL_IS_EMPTY;
305  }
306 
307  ReleasePoolObject = TRUE;
308  }
309 
310  /* Set the stop-in-progress flag */
311  SL_SET_DEVICE_STOP_IN_PROGRESS;
312 
313  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlStopCmdCtrl, &Msg, NULL));
314 
315  /* Do not wait for stop async event if provisioning is in progress */
316  if((SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status) && (!(IsProvInProgress)))
317  {
318  /* Wait for sync object to be signaled */
319  VERIFY_RET_OK(_SlDrvWaitForInternalAsyncEvent(ObjIdx, STOP_DEVICE_TIMEOUT, SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE));
320  Msg.Rsp.status = AsyncRsp.status;
321  RetVal = Msg.Rsp.status;
322  }
323 
324  /* Release pool object only if taken */
325  if (ReleasePoolObject == TRUE)
326  {
327  _SlDrvReleasePoolObj(ObjIdx);
328  }
329 
330  /* This macro wait for the NWP to raise a ready for shutdown indication.
331  * This function is unique for the CC32XX family, and expected to return
332  * in less than 600 mSec, which is the time takes for NWP to gracefully shutdown. */
333  WAIT_NWP_SHUTDOWN_READY;
334  }
335  else
336  {
337  if ((!SL_IS_DEVICE_STARTED)
338  && (!SL_IS_RESTART_REQUIRED))
339  {
340  sl_DeviceDisable();
341  return SL_RET_CODE_DEV_NOT_STARTED;
342  }
343  /* Set the stop-in-progress flag */
344  SL_SET_DEVICE_STOP_IN_PROGRESS;
345  }
346  /* Release (signal) all active and pending commands */
347  _SlDrvReleaseAllActivePendingPoolObj();
348 
349 #ifdef SL_PLATFORM_MULTI_THREADED
350  /* Do not continue until all sync object deleted (in relevant context) */
351  while (g_pCB->NumOfDeletedSyncObj < MAX_CONCURRENT_ACTIONS)
352  {
353  usleep(100000);
354  }
355 #endif
356 
357  /* Lock during stopping the interface */
358  SL_DRV_LOCK_GLOBAL_LOCK_FOREVER(GLOBAL_LOCK_FLAGS_NONE);
359 
360  sl_IfRegIntHdlr(NULL, NULL);
361  sl_DeviceDisable();
362  RetVal = sl_IfClose(g_pCB->FD);
363 
364  (void)_SlDrvDriverCBDeinit();
365 
366  /* clear the stop-in-progress flag */
367  SL_UNSET_DEVICE_STOP_IN_PROGRESS;
368 
369  /* clear the device started flag */
370  SL_UNSET_DEVICE_STARTED;
371 
372  SL_DRV_LOCK_GLOBAL_UNLOCK(FALSE);
373 
374  return RetVal;
375 }
376 #endif
377 
378 
379 /*****************************************************************************
380 sl_DeviceEventMaskSet
381 *****************************************************************************/
382 typedef union
383 {
385  _BasicResponse_t Rsp;
386 }_SlEventMaskSetMsg_u;
387 
388 
389 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskSet)
390 
391 static const _SlCmdCtrl_t _SlEventMaskSetCmdCtrl =
392 {
393  SL_OPCODE_DEVICE_EVENTMASKSET,
394  (_SlArgSize_t)sizeof(SlDeviceMaskEventSetCommand_t),
395  (_SlArgSize_t)sizeof(_BasicResponse_t)
396 };
397 
398 
399 _i16 sl_DeviceEventMaskSet(const _u8 EventClass ,const _u32 Mask)
400 {
401  _SlEventMaskSetMsg_u Msg;
402 
403  /* verify that this api is allowed. if not allowed then
404  ignore the API execution and return immediately with an error */
405  VERIFY_API_ALLOWED(SL_OPCODE_SILO_DEVICE);
406 
407  Msg.Cmd.Group = EventClass;
408  Msg.Cmd.Mask = Mask;
409 
410  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskSetCmdCtrl, &Msg, NULL));
411 
412  return (_i16)Msg.Rsp.status;
413 }
414 #endif
415 
416 /******************************************************************************
417 sl_EventMaskGet
418 ******************************************************************************/
419 typedef union
420 {
423 }_SlEventMaskGetMsg_u;
424 
425 
426 
427 #if _SL_INCLUDE_FUNC(sl_DeviceEventMaskGet)
428 
429 static const _SlCmdCtrl_t _SlEventMaskGetCmdCtrl =
430 {
431  SL_OPCODE_DEVICE_EVENTMASKGET,
432  (_SlArgSize_t)sizeof(SlDeviceMaskEventGetCommand_t),
433  (_SlArgSize_t)sizeof(SlDeviceMaskEventGetResponse_t)
434 };
435 
436 
437 _i16 sl_DeviceEventMaskGet(const _u8 EventClass,_u32 *pMask)
438 {
439  _SlEventMaskGetMsg_u Msg;
440 
441  /* verify that this api is allowed. if not allowed then
442  ignore the API execution and return immediately with an error */
443  VERIFY_API_ALLOWED(SL_OPCODE_SILO_DEVICE);
444 
445  Msg.Cmd.Group = EventClass;
446 
447  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskGetCmdCtrl, &Msg, NULL));
448 
449  *pMask = Msg.Rsp.Mask;
450 
451  return SL_RET_CODE_OK;
452 }
453 #endif
454 
455 
456 
457 /******************************************************************************
458 sl_DeviceGet
459 ******************************************************************************/
460 
461 typedef union
462 {
463  SlDeviceSetGet_t Cmd;
464  SlDeviceSetGet_t Rsp;
465 }_SlDeviceMsgGet_u;
466 
467 
468 
469 #if _SL_INCLUDE_FUNC(sl_DeviceGet)
470 
471 static const _SlCmdCtrl_t _SlDeviceGetCmdCtrl =
472 {
473  SL_OPCODE_DEVICE_DEVICEGET,
474  (_SlArgSize_t)sizeof(SlDeviceSetGet_t),
475  (_SlArgSize_t)sizeof(SlDeviceSetGet_t)
476 };
477 
478 _i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption,_u16 *pConfigLen, _u8 *pValues)
479 {
480  _SlDeviceMsgGet_u Msg;
481  _SlCmdExt_t CmdExt;
482 
483  /* verify that this api is allowed. if not allowed then
484  ignore the API execution and return immediately with an error */
485  VERIFY_API_ALLOWED(SL_OPCODE_SILO_DEVICE);
486 
487  if (*pConfigLen == 0)
488  {
489  return SL_EZEROLEN;
490  }
491 
492  if( pOption )
493  {
494 
495  _SlDrvResetCmdExt(&CmdExt);
496  CmdExt.RxPayloadLen = (_i16)*pConfigLen;
497  CmdExt.pRxPayload = (_u8 *)pValues;
498 
499  Msg.Cmd.DeviceSetId = DeviceGetId;
500 
501  Msg.Cmd.Option = (_u16)*pOption;
502 
503  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceGetCmdCtrl, &Msg, &CmdExt));
504 
505  if( pOption )
506  {
507  *pOption = (_u8)Msg.Rsp.Option;
508  }
509 
510  if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
511  {
512  *pConfigLen = (_u16)CmdExt.RxPayloadLen;
513 
514  return SL_ESMALLBUF;
515  }
516  else
517  {
518  *pConfigLen = (_u16)CmdExt.ActualRxPayloadLen;
519  }
520 
521  return (_i16)Msg.Rsp.Status;
522  }
523  else
524  {
525  return SL_RET_CODE_INVALID_INPUT;
526  }
527 }
528 #endif
529 
530 /******************************************************************************
531 sl_DeviceSet
532 ******************************************************************************/
533 typedef union
534 {
535  SlDeviceSetGet_t Cmd;
536  _BasicResponse_t Rsp;
537 }_SlDeviceMsgSet_u;
538 
539 
540 
541 #if _SL_INCLUDE_FUNC(sl_DeviceSet)
542 
543 static const _SlCmdCtrl_t _SlDeviceSetCmdCtrl =
544 {
545  SL_OPCODE_DEVICE_DEVICESET,
546  (_SlArgSize_t)sizeof(SlDeviceSetGet_t),
547  (_SlArgSize_t)sizeof(_BasicResponse_t)
548 };
549 
550 _i16 sl_DeviceSet(const _u8 DeviceSetId ,const _u8 Option,const _u16 ConfigLen,const _u8 *pValues)
551 {
552  _SlDeviceMsgSet_u Msg;
553  _SlCmdExt_t CmdExt;
554 
555  /* verify that this api is allowed. if not allowed then
556  ignore the API execution and return immediately with an error */
557  VERIFY_API_ALLOWED(SL_OPCODE_SILO_DEVICE);
558 
559  _SlDrvResetCmdExt(&CmdExt);
560 
561  CmdExt.TxPayload1Len = (ConfigLen+3) & (~3);
562  CmdExt.pTxPayload1 = (_u8 *)pValues;
563 
564  Msg.Cmd.DeviceSetId = DeviceSetId;
565  Msg.Cmd.ConfigLen = ConfigLen;
566  Msg.Cmd.Option = Option;
567 
568  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceSetCmdCtrl, &Msg, &CmdExt));
569 
570  return (_i16)Msg.Rsp.status;
571 }
572 #endif
573 
574 
575 /******************************************************************************
576 _SlDeviceEventHandler - handles internally device async events
577 ******************************************************************************/
578 _SlReturnVal_t _SlDeviceEventHandler(void* pEventInfo)
579 {
580  DeviceEventInfo_t* pInfo = (DeviceEventInfo_t*)pEventInfo;
581  _SlResponseHeader_t* pHdr = (_SlResponseHeader_t *)pInfo->pAsyncMsgBuff;
582  _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
583  SlDeviceEvent_t DeviceEvent;
584 
585  _SlDrvMemZero(&DeviceEvent, sizeof(DeviceEvent));
586 
587  switch(pHdr->GenHeader.Opcode)
588  {
589  case SL_OPCODE_DEVICE_INITCOMPLETE:
590  _SlDeviceHandleAsync_InitComplete(pHdr);
591  break;
592  case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
593  _SlDeviceHandleAsync_Stop(pHdr);
594  break;
595  case SL_OPCODE_DEVICE_RESET_REQUEST_ASYNC_EVENT:
596  {
597  SlDeviceResetRequestData_t *pResetRequestData = (SlDeviceResetRequestData_t*)pMsgArgs;
598 
599 #if defined(slcb_DeviceGeneralEvtHdlr) || defined (EXT_LIB_REGISTERED_GENERAL_EVENTS)
600  if (pResetRequestData->Caller == SL_DEVICE_RESET_REQUEST_CALLER_PROVISIONING_EXTERNAL_CONFIGURATION)
601  {
602  /* call the registered events handlers (application/external lib) */
603  DeviceEvent.Id = SL_DEVICE_EVENT_RESET_REQUEST;
604  DeviceEvent.Data.ResetRequest.Status = 0;
605  DeviceEvent.Data.ResetRequest.Caller = pResetRequestData->Caller;
606  _SlDrvHandleGeneralEvents(&DeviceEvent);
607  break;
608  }
609 #endif
610 
611  if (!_SlDrvIsApiInProgress() && SL_IS_PROVISIONING_IN_PROGRESS)
612  {
613  if (pResetRequestData->SessionNumber != DeviceCB.ResetRequestSessionNumber)
614  {
615  /* store the last session number */
616  DeviceCB.ResetRequestSessionNumber = pResetRequestData->SessionNumber;
617 
618  /* perform the reset request */
619  _SlDeviceHandleResetRequestInternally();
620  }
621  }
622  }
623  break;
624 
625  case SL_OPCODE_DEVICE_ABORT:
626  {
627  /* release global lock of cmd context */
628  if (pInfo->bInCmdContext == TRUE)
629  {
630  SL_DRV_LOCK_GLOBAL_UNLOCK(TRUE);
631  }
632 
633  _SlDrvHandleFatalError(SL_DEVICE_EVENT_FATAL_DEVICE_ABORT,
634  *((_u32*)pMsgArgs - 1), /* Abort type */
635  *((_u32*)pMsgArgs)); /* Abort data */
636  }
637  break;
638 
639  case SL_OPCODE_DEVICE_DEVICE_ASYNC_GENERAL_ERROR:
640  {
641 #if defined(slcb_DeviceGeneralEvtHdlr) || defined (EXT_LIB_REGISTERED_GENERAL_EVENTS)
642 
643  DeviceEvent.Id = SL_DEVICE_EVENT_ERROR;
644  DeviceEvent.Data.Error.Code = pMsgArgs->status;
645  DeviceEvent.Data.Error.Source = (SlDeviceSource_e)pMsgArgs->sender;
646  _SlDrvHandleGeneralEvents(&DeviceEvent);
647 #endif
648  }
649  break;
650 
651  case SL_OPCODE_DEVICE_FLOW_CTRL_ASYNC_EVENT:
652  _SlFlowContSet((void *)pHdr);
653  break;
654  default:
655  SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDeviceEventHandler : invalid opcode = 0x%x = %1", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
656  }
657 
658  return SL_OS_RET_CODE_OK;
659 }
660 
661 
662 void _SlDeviceResetRequestInitCompletedCB(_u32 Status, SlDeviceInitInfo_t *DeviceInitInfo)
663 {
664  /* Do nothing...*/
665 }
666 
667 
668 void _SlDeviceHandleResetRequestInternally(void)
669 {
670  _u8 irqCountLast = RxIrqCnt;
671 #if (defined(slcb_GetTimestamp))
672  _SlTimeoutParams_t TimeoutInfo={0};
673 
674  _SlDrvStartMeasureTimeout(&TimeoutInfo, 2*RESET_REQUEST_STOP_TIMEOUT);
675 #endif
676 
677  /* Here we send stop command with timeout, but the API will not blocked
678  Till the stop complete event is received as we in the middle of async event handling */
679  sl_Stop(RESET_REQUEST_STOP_TIMEOUT);
680 
681  /* wait till the stop complete cmd & async
682  event messages are received (2 Irqs) */
683  do
684  {
685 #if (defined(slcb_GetTimestamp))
686  if (_SlDrvIsTimeoutExpired(&TimeoutInfo))
687  {
688  break;
689  }
690 #endif
691  }
692  while((RxIrqCnt - irqCountLast) < 2);
693 
694  /* start the device again */
695  sl_Start(DeviceCB.pIfHdl, DeviceCB.pDevName ,_SlDeviceResetRequestInitCompletedCB);
696 
697 }
698 
699 
700 /******************************************************************************
701 sl_DeviceUartSetMode
702 ******************************************************************************/
703 #ifdef SL_IF_TYPE_UART
704 typedef union
705 {
708 }_SlUartSetModeMsg_u;
709 
710 
711 #if _SL_INCLUDE_FUNC(sl_DeviceUartSetMode)
712 
713 
714 const _SlCmdCtrl_t _SlUartSetModeCmdCtrl =
715 {
716  SL_OPCODE_DEVICE_SETUARTMODECOMMAND,
717  (_SlArgSize_t)sizeof(SlDeviceUartSetModeCommand_t),
718  (_SlArgSize_t)sizeof(SlDeviceUartSetModeResponse_t)
719 };
720 
722 {
723  _SlUartSetModeMsg_u Msg;
724  _u32 magicCode = (_u32)0xFFFFFFFF;
725 
726  Msg.Cmd.BaudRate = pUartParams->BaudRate;
727  Msg.Cmd.FlowControlEnable = pUartParams->FlowControlEnable;
728 
729 
730  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlUartSetModeCmdCtrl, &Msg, NULL));
731 
732  /* cmd response OK, we can continue with the handshake */
733  if (SL_RET_CODE_OK == Msg.Rsp.status)
734  {
735  sl_IfMaskIntHdlr();
736 
737  /* Close the comm port */
738  sl_IfClose(g_pCB->FD);
739 
740  /* Re-open the comm port */
741  sl_IfOpen((void * )pUartParams, SL_IF_UART_REOPEN_FLAGS);
742 
743  sl_IfUnMaskIntHdlr();
744 
745  /* send the magic code and wait for the response */
746  sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
747 
748  magicCode = UART_SET_MODE_MAGIC_CODE;
749  sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
750 
751  /* clear magic code */
752  magicCode = 0;
753 
754  /* wait (blocking) till the magic code to be returned from device */
755  sl_IfRead(g_pCB->FD, (_u8* )&magicCode, 4);
756 
757  /* check for the received magic code matching */
758  if (UART_SET_MODE_MAGIC_CODE != magicCode)
759  {
760  _SL_ASSERT(0);
761  }
762  }
763 
764  return (_i16)Msg.Rsp.status;
765 }
766 #endif
767 #endif
768 
_i16 sl_DeviceEventMaskSet(const _u8 EventClass, const _u32 Mask)
Set asynchronous event mask.
Definition: device.c:399
_i16 sl_DeviceGet(const _u8 DeviceGetId, _u8 *pOption, _u16 *pConfigLen, _u8 *pValues)
Internal function for getting device configurations.
Definition: device.c:478
void * sl_Task(void *pEntry)
The SimpleLink task entry.
Definition: device.c:105
_i16 sl_DeviceSet(const _u8 DeviceSetId, const _u8 Option, const _u16 ConfigLen, const _u8 *pValues)
Setting device configurations.
Definition: device.c:550
_i16 sl_Stop(const _u16 Timeout)
Stop the SimpleLink device.
Definition: device.c:273
_i16 sl_DeviceEventMaskGet(const _u8 EventClass, _u32 *pMask)
Get current event mask of the device.
Definition: device.c:437
_i16 sl_DeviceUartSetMode(const SlDeviceUartIfParams_t *pUartParams)
Setting the internal uart mode.
Definition: device.c:721
_i16 sl_Start(const void *pIfHdl, _i8 *pDevName, const P_INIT_CALLBACK pInitCallBack)
Start the SimpleLink device.
Definition: device.c:119