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