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