DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

The MAXREFDES155# is an internet-of-things (IoT) embedded-security reference design, built to authenticate and control a sensing node using elliptic-curve-based public-key cryptography with control and notification from a web server.

The hardware includes an ARM® mbed™ shield and attached sensor endpoint. The shield contains a DS2476 DeepCover® ECDSA/SHA-2 coprocessor, Wifi communication, LCD push-button controls, and status LEDs. The sensor endpoint is attached to the shield using a 300mm cable and contains a DS28C36 DeepCover ECDSA/SHA-2 authenticator, IR-thermal sensor, and aiming laser for the IR sensor. The MAXREFDES155# is equipped with a standard Arduino® form-factor shield connector for immediate testing using an mbed board such as the MAX32600MBED#. The combination of these two devices represent an IoT device. Communication to the web server is accomplished with the shield Wifi circuitry. Communication from the shield to the attached sensor module is accomplished over I2C . The sensor module represents an IoT endpoint that generates small data with a requirement for message authenticity/integrity and secure on/off operational control.

The design is hierarchical with each mbed platform and shield communicating data from the sensor node to a web server that maintains a centralized log and dispatches notifications as necessary. The simplicity of this design enables rapid integration into any star-topology IoT network to provide security with the low overhead and cost provided by the ECDSA-P256 asymmetric-key and SHA-256 symmetric-key algorithms.

More information about the MAXREFDES155# is available on the Maxim Integrated website.

Committer:
IanBenzMaxim
Date:
Thu Oct 03 11:40:13 2019 -0500
Revision:
16:a004191a79ab
Parent:
simplelink/source/device.c@0:33d4e66780c0
Updated MaximInterface to version 2.0. Updated mbed-os to version 5.5.7. Cleaned up code styling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
IanBenzMaxim 0:33d4e66780c0 1 /*
IanBenzMaxim 0:33d4e66780c0 2 * device.c - CC31xx/CC32xx Host Driver Implementation
IanBenzMaxim 0:33d4e66780c0 3 *
IanBenzMaxim 0:33d4e66780c0 4 * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com/
IanBenzMaxim 0:33d4e66780c0 5 *
IanBenzMaxim 0:33d4e66780c0 6 *
IanBenzMaxim 0:33d4e66780c0 7 * Redistribution and use in source and binary forms, with or without
IanBenzMaxim 0:33d4e66780c0 8 * modification, are permitted provided that the following conditions
IanBenzMaxim 0:33d4e66780c0 9 * are met:
IanBenzMaxim 0:33d4e66780c0 10 *
IanBenzMaxim 0:33d4e66780c0 11 * Redistributions of source code must retain the above copyright
IanBenzMaxim 0:33d4e66780c0 12 * notice, this list of conditions and the following disclaimer.
IanBenzMaxim 0:33d4e66780c0 13 *
IanBenzMaxim 0:33d4e66780c0 14 * Redistributions in binary form must reproduce the above copyright
IanBenzMaxim 0:33d4e66780c0 15 * notice, this list of conditions and the following disclaimer in the
IanBenzMaxim 0:33d4e66780c0 16 * documentation and/or other materials provided with the
IanBenzMaxim 0:33d4e66780c0 17 * distribution.
IanBenzMaxim 0:33d4e66780c0 18 *
IanBenzMaxim 0:33d4e66780c0 19 * Neither the name of Texas Instruments Incorporated nor the names of
IanBenzMaxim 0:33d4e66780c0 20 * its contributors may be used to endorse or promote products derived
IanBenzMaxim 0:33d4e66780c0 21 * from this software without specific prior written permission.
IanBenzMaxim 0:33d4e66780c0 22 *
IanBenzMaxim 0:33d4e66780c0 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
IanBenzMaxim 0:33d4e66780c0 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
IanBenzMaxim 0:33d4e66780c0 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
IanBenzMaxim 0:33d4e66780c0 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
IanBenzMaxim 0:33d4e66780c0 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
IanBenzMaxim 0:33d4e66780c0 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
IanBenzMaxim 0:33d4e66780c0 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
IanBenzMaxim 0:33d4e66780c0 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
IanBenzMaxim 0:33d4e66780c0 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
IanBenzMaxim 0:33d4e66780c0 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
IanBenzMaxim 0:33d4e66780c0 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
IanBenzMaxim 0:33d4e66780c0 34 *
IanBenzMaxim 0:33d4e66780c0 35 */
IanBenzMaxim 0:33d4e66780c0 36
IanBenzMaxim 0:33d4e66780c0 37
IanBenzMaxim 0:33d4e66780c0 38
IanBenzMaxim 0:33d4e66780c0 39 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 40 /* Include files */
IanBenzMaxim 0:33d4e66780c0 41 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 42 #include "simplelink.h"
IanBenzMaxim 0:33d4e66780c0 43 #include "protocol.h"
IanBenzMaxim 0:33d4e66780c0 44 #include "flowcont.h"
IanBenzMaxim 0:33d4e66780c0 45 #include "driver.h"
IanBenzMaxim 0:33d4e66780c0 46 #include "wlan.h"
IanBenzMaxim 0:33d4e66780c0 47
IanBenzMaxim 0:33d4e66780c0 48
IanBenzMaxim 0:33d4e66780c0 49 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 50 /* Internal functions */
IanBenzMaxim 0:33d4e66780c0 51 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 52
IanBenzMaxim 0:33d4e66780c0 53 static SlWlanMode_e _sl_GetStartResponseConvert(_i32 Status);
IanBenzMaxim 0:33d4e66780c0 54
IanBenzMaxim 0:33d4e66780c0 55
IanBenzMaxim 0:33d4e66780c0 56 static const SlWlanMode_e StartResponseLUT[8] =
IanBenzMaxim 0:33d4e66780c0 57 {
IanBenzMaxim 0:33d4e66780c0 58 ROLE_UNKNOWN,
IanBenzMaxim 0:33d4e66780c0 59 ROLE_STA,
IanBenzMaxim 0:33d4e66780c0 60 ROLE_STA_ERR,
IanBenzMaxim 0:33d4e66780c0 61 ROLE_AP,
IanBenzMaxim 0:33d4e66780c0 62 ROLE_AP_ERR,
IanBenzMaxim 0:33d4e66780c0 63 ROLE_P2P,
IanBenzMaxim 0:33d4e66780c0 64 ROLE_P2P_ERR,
IanBenzMaxim 0:33d4e66780c0 65 INIT_CALIB_FAIL
IanBenzMaxim 0:33d4e66780c0 66 };
IanBenzMaxim 0:33d4e66780c0 67
IanBenzMaxim 0:33d4e66780c0 68
IanBenzMaxim 0:33d4e66780c0 69 static SlWlanMode_e _sl_GetStartResponseConvert(_i32 Status)
IanBenzMaxim 0:33d4e66780c0 70 {
IanBenzMaxim 0:33d4e66780c0 71 return StartResponseLUT[Status & 0x7];
IanBenzMaxim 0:33d4e66780c0 72 }
IanBenzMaxim 0:33d4e66780c0 73
IanBenzMaxim 0:33d4e66780c0 74
IanBenzMaxim 0:33d4e66780c0 75 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 76 /* API Functions */
IanBenzMaxim 0:33d4e66780c0 77 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 78
IanBenzMaxim 0:33d4e66780c0 79
IanBenzMaxim 0:33d4e66780c0 80
IanBenzMaxim 0:33d4e66780c0 81 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 82 /* sl_Task */
IanBenzMaxim 0:33d4e66780c0 83 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 84 #if _SL_INCLUDE_FUNC(sl_Task)
IanBenzMaxim 0:33d4e66780c0 85 void sl_Task(void)
IanBenzMaxim 0:33d4e66780c0 86 {
IanBenzMaxim 0:33d4e66780c0 87 #ifdef _SlTaskEntry
IanBenzMaxim 0:33d4e66780c0 88 (void)_SlTaskEntry();
IanBenzMaxim 0:33d4e66780c0 89 #endif
IanBenzMaxim 0:33d4e66780c0 90 }
IanBenzMaxim 0:33d4e66780c0 91 #endif
IanBenzMaxim 0:33d4e66780c0 92
IanBenzMaxim 0:33d4e66780c0 93 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 94 /* sl_Start */
IanBenzMaxim 0:33d4e66780c0 95 /*****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 96 #if _SL_INCLUDE_FUNC(sl_Start)
IanBenzMaxim 0:33d4e66780c0 97 _i16 sl_Start(const void* pIfHdl, _i8* pDevName, const P_INIT_CALLBACK pInitCallBack)
IanBenzMaxim 0:33d4e66780c0 98 {
IanBenzMaxim 0:33d4e66780c0 99 _u8 ObjIdx = MAX_CONCURRENT_ACTIONS;
IanBenzMaxim 0:33d4e66780c0 100 InitComplete_t AsyncRsp;
IanBenzMaxim 0:33d4e66780c0 101
IanBenzMaxim 0:33d4e66780c0 102 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 103 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 104 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 105 /* Perform any preprocessing before enable networking services */
IanBenzMaxim 0:33d4e66780c0 106 #ifdef sl_DeviceEnablePreamble
IanBenzMaxim 0:33d4e66780c0 107 sl_DeviceEnablePreamble();
IanBenzMaxim 0:33d4e66780c0 108 #endif
IanBenzMaxim 0:33d4e66780c0 109
IanBenzMaxim 0:33d4e66780c0 110 /* ControlBlock init */
IanBenzMaxim 0:33d4e66780c0 111 (void)_SlDrvDriverCBInit();
IanBenzMaxim 0:33d4e66780c0 112
IanBenzMaxim 0:33d4e66780c0 113 /* open the interface: usually SPI or UART */
IanBenzMaxim 0:33d4e66780c0 114 if (NULL == pIfHdl)
IanBenzMaxim 0:33d4e66780c0 115 {
IanBenzMaxim 0:33d4e66780c0 116 g_pCB->FD = sl_IfOpen((void *)pDevName, 0);
IanBenzMaxim 0:33d4e66780c0 117 }
IanBenzMaxim 0:33d4e66780c0 118 else
IanBenzMaxim 0:33d4e66780c0 119 {
IanBenzMaxim 0:33d4e66780c0 120 g_pCB->FD = (_SlFd_t)pIfHdl;
IanBenzMaxim 0:33d4e66780c0 121 }
IanBenzMaxim 0:33d4e66780c0 122
IanBenzMaxim 0:33d4e66780c0 123 ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
IanBenzMaxim 0:33d4e66780c0 124
IanBenzMaxim 0:33d4e66780c0 125 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
IanBenzMaxim 0:33d4e66780c0 126 {
IanBenzMaxim 0:33d4e66780c0 127 return SL_POOL_IS_EMPTY;
IanBenzMaxim 0:33d4e66780c0 128 }
IanBenzMaxim 0:33d4e66780c0 129
IanBenzMaxim 0:33d4e66780c0 130 if( g_pCB->FD >= (_SlFd_t)0)
IanBenzMaxim 0:33d4e66780c0 131 {
IanBenzMaxim 0:33d4e66780c0 132 sl_DeviceDisable();
IanBenzMaxim 0:33d4e66780c0 133
IanBenzMaxim 0:33d4e66780c0 134 sl_IfRegIntHdlr((SL_P_EVENT_HANDLER)_SlDrvRxIrqHandler, NULL);
IanBenzMaxim 0:33d4e66780c0 135
IanBenzMaxim 0:33d4e66780c0 136 g_pCB->pInitCallback = pInitCallBack;
IanBenzMaxim 0:33d4e66780c0 137
IanBenzMaxim 0:33d4e66780c0 138 sl_DeviceEnable();
IanBenzMaxim 0:33d4e66780c0 139
IanBenzMaxim 0:33d4e66780c0 140 if (NULL == pInitCallBack)
IanBenzMaxim 0:33d4e66780c0 141 {
IanBenzMaxim 0:33d4e66780c0 142 #ifdef SL_TINY_EXT
IanBenzMaxim 0:33d4e66780c0 143 _SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
IanBenzMaxim 0:33d4e66780c0 144 #else
IanBenzMaxim 0:33d4e66780c0 145 _SlReturnVal_t retVal;
IanBenzMaxim 0:33d4e66780c0 146 retVal = _SlDrvSyncObjWaitTimeout(&g_pCB->ObjPool[ObjIdx].SyncObj,
IanBenzMaxim 0:33d4e66780c0 147 INIT_COMPLETE_TIMEOUT,
IanBenzMaxim 0:33d4e66780c0 148 SL_DRIVER_API_DEVICE_SL_START);
IanBenzMaxim 0:33d4e66780c0 149 if (retVal)
IanBenzMaxim 0:33d4e66780c0 150 {
IanBenzMaxim 0:33d4e66780c0 151 return SL_API_ABORTED;
IanBenzMaxim 0:33d4e66780c0 152 }
IanBenzMaxim 0:33d4e66780c0 153 #endif
IanBenzMaxim 0:33d4e66780c0 154
IanBenzMaxim 0:33d4e66780c0 155
IanBenzMaxim 0:33d4e66780c0 156 /* release Pool Object */
IanBenzMaxim 0:33d4e66780c0 157 _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
IanBenzMaxim 0:33d4e66780c0 158 return _sl_GetStartResponseConvert(AsyncRsp.Status);
IanBenzMaxim 0:33d4e66780c0 159 }
IanBenzMaxim 0:33d4e66780c0 160 else
IanBenzMaxim 0:33d4e66780c0 161 {
IanBenzMaxim 0:33d4e66780c0 162 return SL_RET_CODE_OK;
IanBenzMaxim 0:33d4e66780c0 163 }
IanBenzMaxim 0:33d4e66780c0 164 }
IanBenzMaxim 0:33d4e66780c0 165 return SL_BAD_INTERFACE;
IanBenzMaxim 0:33d4e66780c0 166 }
IanBenzMaxim 0:33d4e66780c0 167 #endif
IanBenzMaxim 0:33d4e66780c0 168
IanBenzMaxim 0:33d4e66780c0 169 /***************************************************************************
IanBenzMaxim 0:33d4e66780c0 170 _sl_HandleAsync_InitComplete - handles init complete signalling to
IanBenzMaxim 0:33d4e66780c0 171 a waiting object
IanBenzMaxim 0:33d4e66780c0 172 ****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 173 _SlReturnVal_t _sl_HandleAsync_InitComplete(void *pVoidBuf)
IanBenzMaxim 0:33d4e66780c0 174 {
IanBenzMaxim 0:33d4e66780c0 175 InitComplete_t *pMsgArgs = (InitComplete_t *)_SL_RESP_ARGS_START(pVoidBuf);
IanBenzMaxim 0:33d4e66780c0 176
IanBenzMaxim 0:33d4e66780c0 177 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
IanBenzMaxim 0:33d4e66780c0 178
IanBenzMaxim 0:33d4e66780c0 179 if(g_pCB->pInitCallback)
IanBenzMaxim 0:33d4e66780c0 180 {
IanBenzMaxim 0:33d4e66780c0 181 g_pCB->pInitCallback(_sl_GetStartResponseConvert(pMsgArgs->Status));
IanBenzMaxim 0:33d4e66780c0 182 }
IanBenzMaxim 0:33d4e66780c0 183 else
IanBenzMaxim 0:33d4e66780c0 184 {
IanBenzMaxim 0:33d4e66780c0 185 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(InitComplete_t));
IanBenzMaxim 0:33d4e66780c0 186 SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
IanBenzMaxim 0:33d4e66780c0 187 }
IanBenzMaxim 0:33d4e66780c0 188
IanBenzMaxim 0:33d4e66780c0 189 SL_DRV_PROTECTION_OBJ_UNLOCK();
IanBenzMaxim 0:33d4e66780c0 190
IanBenzMaxim 0:33d4e66780c0 191 if(g_pCB->pInitCallback)
IanBenzMaxim 0:33d4e66780c0 192 {
IanBenzMaxim 0:33d4e66780c0 193 _SlDrvReleasePoolObj(g_pCB->FunctionParams.AsyncExt.ActionIndex);
IanBenzMaxim 0:33d4e66780c0 194 }
IanBenzMaxim 0:33d4e66780c0 195
IanBenzMaxim 0:33d4e66780c0 196
IanBenzMaxim 0:33d4e66780c0 197 return SL_RET_CODE_OK;
IanBenzMaxim 0:33d4e66780c0 198 }
IanBenzMaxim 0:33d4e66780c0 199
IanBenzMaxim 0:33d4e66780c0 200 /***************************************************************************
IanBenzMaxim 0:33d4e66780c0 201 _sl_HandleAsync_Stop - handles stop signalling to
IanBenzMaxim 0:33d4e66780c0 202 a waiting object
IanBenzMaxim 0:33d4e66780c0 203 ****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 204 void _sl_HandleAsync_Stop(void *pVoidBuf)
IanBenzMaxim 0:33d4e66780c0 205 {
IanBenzMaxim 0:33d4e66780c0 206 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pVoidBuf);
IanBenzMaxim 0:33d4e66780c0 207
IanBenzMaxim 0:33d4e66780c0 208 VERIFY_SOCKET_CB(NULL != g_pCB->StopCB.pAsyncRsp);
IanBenzMaxim 0:33d4e66780c0 209
IanBenzMaxim 0:33d4e66780c0 210 SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
IanBenzMaxim 0:33d4e66780c0 211
IanBenzMaxim 0:33d4e66780c0 212 sl_Memcpy(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs, pMsgArgs, sizeof(_BasicResponse_t));
IanBenzMaxim 0:33d4e66780c0 213
IanBenzMaxim 0:33d4e66780c0 214 SL_DRV_SYNC_OBJ_SIGNAL(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj);
IanBenzMaxim 0:33d4e66780c0 215 SL_DRV_PROTECTION_OBJ_UNLOCK();
IanBenzMaxim 0:33d4e66780c0 216
IanBenzMaxim 0:33d4e66780c0 217 return;
IanBenzMaxim 0:33d4e66780c0 218 }
IanBenzMaxim 0:33d4e66780c0 219
IanBenzMaxim 0:33d4e66780c0 220
IanBenzMaxim 0:33d4e66780c0 221 /*****************************************************************************
IanBenzMaxim 0:33d4e66780c0 222 sl_stop
IanBenzMaxim 0:33d4e66780c0 223 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 224 typedef union
IanBenzMaxim 0:33d4e66780c0 225 {
IanBenzMaxim 0:33d4e66780c0 226 _DevStopCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 227 _BasicResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 228 }_SlStopMsg_u;
IanBenzMaxim 0:33d4e66780c0 229
IanBenzMaxim 0:33d4e66780c0 230 static const _SlCmdCtrl_t _SlStopCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 231 {
IanBenzMaxim 0:33d4e66780c0 232 SL_OPCODE_DEVICE_STOP_COMMAND,
IanBenzMaxim 0:33d4e66780c0 233 (_SlArgSize_t)sizeof(_DevStopCommand_t),
IanBenzMaxim 0:33d4e66780c0 234 (_SlArgSize_t)sizeof(_BasicResponse_t)
IanBenzMaxim 0:33d4e66780c0 235 };
IanBenzMaxim 0:33d4e66780c0 236
IanBenzMaxim 0:33d4e66780c0 237 #if _SL_INCLUDE_FUNC(sl_Stop)
IanBenzMaxim 0:33d4e66780c0 238 _i16 sl_Stop(const _u16 timeout)
IanBenzMaxim 0:33d4e66780c0 239 {
IanBenzMaxim 0:33d4e66780c0 240 _i16 RetVal=0;
IanBenzMaxim 0:33d4e66780c0 241 _SlStopMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 242 _BasicResponse_t AsyncRsp;
IanBenzMaxim 0:33d4e66780c0 243 _u8 ObjIdx = MAX_CONCURRENT_ACTIONS;
IanBenzMaxim 0:33d4e66780c0 244
IanBenzMaxim 0:33d4e66780c0 245 /* If we are in the middle of assert handling then ignore stopping
IanBenzMaxim 0:33d4e66780c0 246 * the device with timeout and force immediate shutdown as we would like
IanBenzMaxim 0:33d4e66780c0 247 * to avoid any additional commands to the NWP */
IanBenzMaxim 0:33d4e66780c0 248 if( (timeout != 0)
IanBenzMaxim 0:33d4e66780c0 249 #ifndef SL_TINY_EXT
IanBenzMaxim 0:33d4e66780c0 250 && ((_u8)FALSE == g_bDeviceRestartIsRequired)
IanBenzMaxim 0:33d4e66780c0 251 #endif
IanBenzMaxim 0:33d4e66780c0 252 )
IanBenzMaxim 0:33d4e66780c0 253 {
IanBenzMaxim 0:33d4e66780c0 254 /* let the device make the shutdown using the defined timeout */
IanBenzMaxim 0:33d4e66780c0 255 Msg.Cmd.Timeout = timeout;
IanBenzMaxim 0:33d4e66780c0 256
IanBenzMaxim 0:33d4e66780c0 257 ObjIdx = _SlDrvProtectAsyncRespSetting((_u8 *)&AsyncRsp, START_STOP_ID, SL_MAX_SOCKETS);
IanBenzMaxim 0:33d4e66780c0 258 if (MAX_CONCURRENT_ACTIONS == ObjIdx)
IanBenzMaxim 0:33d4e66780c0 259 {
IanBenzMaxim 0:33d4e66780c0 260 return SL_POOL_IS_EMPTY;
IanBenzMaxim 0:33d4e66780c0 261 }
IanBenzMaxim 0:33d4e66780c0 262
IanBenzMaxim 0:33d4e66780c0 263 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlStopCmdCtrl, &Msg, NULL));
IanBenzMaxim 0:33d4e66780c0 264
IanBenzMaxim 0:33d4e66780c0 265 if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
IanBenzMaxim 0:33d4e66780c0 266 {
IanBenzMaxim 0:33d4e66780c0 267
IanBenzMaxim 0:33d4e66780c0 268 #ifdef SL_TINY_EXT
IanBenzMaxim 0:33d4e66780c0 269 _SlDrvSyncObjWaitForever(&g_pCB->ObjPool[ObjIdx].SyncObj);
IanBenzMaxim 0:33d4e66780c0 270 /* Wait for sync object to be signaled */
IanBenzMaxim 0:33d4e66780c0 271 #else
IanBenzMaxim 0:33d4e66780c0 272 SL_DRV_SYNC_OBJ_WAIT_TIMEOUT(&g_pCB->ObjPool[ObjIdx].SyncObj,
IanBenzMaxim 0:33d4e66780c0 273 STOP_DEVICE_TIMEOUT,
IanBenzMaxim 0:33d4e66780c0 274 SL_DRIVER_API_DEVICE_SL_STOP);
IanBenzMaxim 0:33d4e66780c0 275 #endif
IanBenzMaxim 0:33d4e66780c0 276
IanBenzMaxim 0:33d4e66780c0 277 Msg.Rsp.status = AsyncRsp.status;
IanBenzMaxim 0:33d4e66780c0 278 RetVal = Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 279 }
IanBenzMaxim 0:33d4e66780c0 280 _SlDrvReleasePoolObj(ObjIdx);
IanBenzMaxim 0:33d4e66780c0 281 }
IanBenzMaxim 0:33d4e66780c0 282
IanBenzMaxim 0:33d4e66780c0 283 sl_IfRegIntHdlr(NULL, NULL);
IanBenzMaxim 0:33d4e66780c0 284 sl_DeviceDisable();
IanBenzMaxim 0:33d4e66780c0 285 RetVal = sl_IfClose(g_pCB->FD);
IanBenzMaxim 0:33d4e66780c0 286
IanBenzMaxim 0:33d4e66780c0 287 (void)_SlDrvDriverCBDeinit();
IanBenzMaxim 0:33d4e66780c0 288
IanBenzMaxim 0:33d4e66780c0 289 #ifndef SL_TINY_EXT
IanBenzMaxim 0:33d4e66780c0 290 /* Clear the restart device flag */
IanBenzMaxim 0:33d4e66780c0 291 g_bDeviceRestartIsRequired = FALSE;
IanBenzMaxim 0:33d4e66780c0 292 #endif
IanBenzMaxim 0:33d4e66780c0 293
IanBenzMaxim 0:33d4e66780c0 294 return RetVal;
IanBenzMaxim 0:33d4e66780c0 295 }
IanBenzMaxim 0:33d4e66780c0 296 #endif
IanBenzMaxim 0:33d4e66780c0 297
IanBenzMaxim 0:33d4e66780c0 298
IanBenzMaxim 0:33d4e66780c0 299 /*****************************************************************************
IanBenzMaxim 0:33d4e66780c0 300 sl_EventMaskSet
IanBenzMaxim 0:33d4e66780c0 301 *****************************************************************************/
IanBenzMaxim 0:33d4e66780c0 302 typedef union
IanBenzMaxim 0:33d4e66780c0 303 {
IanBenzMaxim 0:33d4e66780c0 304 _DevMaskEventSetCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 305 _BasicResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 306 }_SlEventMaskSetMsg_u;
IanBenzMaxim 0:33d4e66780c0 307
IanBenzMaxim 0:33d4e66780c0 308
IanBenzMaxim 0:33d4e66780c0 309
IanBenzMaxim 0:33d4e66780c0 310
IanBenzMaxim 0:33d4e66780c0 311 #if _SL_INCLUDE_FUNC(sl_EventMaskSet)
IanBenzMaxim 0:33d4e66780c0 312
IanBenzMaxim 0:33d4e66780c0 313 static const _SlCmdCtrl_t _SlEventMaskSetCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 314 {
IanBenzMaxim 0:33d4e66780c0 315 SL_OPCODE_DEVICE_EVENTMASKSET,
IanBenzMaxim 0:33d4e66780c0 316 (_SlArgSize_t)sizeof(_DevMaskEventSetCommand_t),
IanBenzMaxim 0:33d4e66780c0 317 (_SlArgSize_t)sizeof(_BasicResponse_t)
IanBenzMaxim 0:33d4e66780c0 318 };
IanBenzMaxim 0:33d4e66780c0 319
IanBenzMaxim 0:33d4e66780c0 320
IanBenzMaxim 0:33d4e66780c0 321 _i16 sl_EventMaskSet(const _u8 EventClass ,const _u32 Mask)
IanBenzMaxim 0:33d4e66780c0 322 {
IanBenzMaxim 0:33d4e66780c0 323 _SlEventMaskSetMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 324
IanBenzMaxim 0:33d4e66780c0 325 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 326 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 327 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 328
IanBenzMaxim 0:33d4e66780c0 329 Msg.Cmd.group = EventClass;
IanBenzMaxim 0:33d4e66780c0 330 Msg.Cmd.mask = Mask;
IanBenzMaxim 0:33d4e66780c0 331
IanBenzMaxim 0:33d4e66780c0 332 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskSetCmdCtrl, &Msg, NULL));
IanBenzMaxim 0:33d4e66780c0 333
IanBenzMaxim 0:33d4e66780c0 334 return (_i16)Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 335 }
IanBenzMaxim 0:33d4e66780c0 336 #endif
IanBenzMaxim 0:33d4e66780c0 337
IanBenzMaxim 0:33d4e66780c0 338 /******************************************************************************
IanBenzMaxim 0:33d4e66780c0 339 sl_EventMaskGet
IanBenzMaxim 0:33d4e66780c0 340 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 341 typedef union
IanBenzMaxim 0:33d4e66780c0 342 {
IanBenzMaxim 0:33d4e66780c0 343 _DevMaskEventGetCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 344 _DevMaskEventGetResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 345 }_SlEventMaskGetMsg_u;
IanBenzMaxim 0:33d4e66780c0 346
IanBenzMaxim 0:33d4e66780c0 347
IanBenzMaxim 0:33d4e66780c0 348
IanBenzMaxim 0:33d4e66780c0 349 #if _SL_INCLUDE_FUNC(sl_EventMaskGet)
IanBenzMaxim 0:33d4e66780c0 350
IanBenzMaxim 0:33d4e66780c0 351 static const _SlCmdCtrl_t _SlEventMaskGetCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 352 {
IanBenzMaxim 0:33d4e66780c0 353 SL_OPCODE_DEVICE_EVENTMASKGET,
IanBenzMaxim 0:33d4e66780c0 354 (_SlArgSize_t)sizeof(_DevMaskEventGetCommand_t),
IanBenzMaxim 0:33d4e66780c0 355 (_SlArgSize_t)sizeof(_DevMaskEventGetResponse_t)
IanBenzMaxim 0:33d4e66780c0 356 };
IanBenzMaxim 0:33d4e66780c0 357
IanBenzMaxim 0:33d4e66780c0 358
IanBenzMaxim 0:33d4e66780c0 359 _i16 sl_EventMaskGet(const _u8 EventClass,_u32 *pMask)
IanBenzMaxim 0:33d4e66780c0 360 {
IanBenzMaxim 0:33d4e66780c0 361 _SlEventMaskGetMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 362
IanBenzMaxim 0:33d4e66780c0 363 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 364 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 365 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 366 Msg.Cmd.group = EventClass;
IanBenzMaxim 0:33d4e66780c0 367
IanBenzMaxim 0:33d4e66780c0 368 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlEventMaskGetCmdCtrl, &Msg, NULL));
IanBenzMaxim 0:33d4e66780c0 369
IanBenzMaxim 0:33d4e66780c0 370 *pMask = Msg.Rsp.mask;
IanBenzMaxim 0:33d4e66780c0 371 return SL_RET_CODE_OK;
IanBenzMaxim 0:33d4e66780c0 372 }
IanBenzMaxim 0:33d4e66780c0 373 #endif
IanBenzMaxim 0:33d4e66780c0 374
IanBenzMaxim 0:33d4e66780c0 375
IanBenzMaxim 0:33d4e66780c0 376
IanBenzMaxim 0:33d4e66780c0 377 /******************************************************************************
IanBenzMaxim 0:33d4e66780c0 378 sl_DevGet
IanBenzMaxim 0:33d4e66780c0 379 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 380
IanBenzMaxim 0:33d4e66780c0 381 typedef union
IanBenzMaxim 0:33d4e66780c0 382 {
IanBenzMaxim 0:33d4e66780c0 383 _DeviceSetGet_t Cmd;
IanBenzMaxim 0:33d4e66780c0 384 _DeviceSetGet_t Rsp;
IanBenzMaxim 0:33d4e66780c0 385 }_SlDeviceMsgGet_u;
IanBenzMaxim 0:33d4e66780c0 386
IanBenzMaxim 0:33d4e66780c0 387
IanBenzMaxim 0:33d4e66780c0 388
IanBenzMaxim 0:33d4e66780c0 389 #if _SL_INCLUDE_FUNC(sl_DevGet)
IanBenzMaxim 0:33d4e66780c0 390
IanBenzMaxim 0:33d4e66780c0 391 static const _SlCmdCtrl_t _SlDeviceGetCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 392 {
IanBenzMaxim 0:33d4e66780c0 393 SL_OPCODE_DEVICE_DEVICEGET,
IanBenzMaxim 0:33d4e66780c0 394 (_SlArgSize_t)sizeof(_DeviceSetGet_t),
IanBenzMaxim 0:33d4e66780c0 395 (_SlArgSize_t)sizeof(_DeviceSetGet_t)
IanBenzMaxim 0:33d4e66780c0 396 };
IanBenzMaxim 0:33d4e66780c0 397
IanBenzMaxim 0:33d4e66780c0 398 _i32 sl_DevGet(const _u8 DeviceGetId,_u8 *pOption,_u8 *pConfigLen, _u8 *pValues)
IanBenzMaxim 0:33d4e66780c0 399 {
IanBenzMaxim 0:33d4e66780c0 400 _SlDeviceMsgGet_u Msg;
IanBenzMaxim 0:33d4e66780c0 401 _SlCmdExt_t CmdExt;
IanBenzMaxim 0:33d4e66780c0 402 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 403 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 404 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 405
IanBenzMaxim 0:33d4e66780c0 406 if (*pConfigLen == 0)
IanBenzMaxim 0:33d4e66780c0 407 {
IanBenzMaxim 0:33d4e66780c0 408 return SL_EZEROLEN;
IanBenzMaxim 0:33d4e66780c0 409 }
IanBenzMaxim 0:33d4e66780c0 410
IanBenzMaxim 0:33d4e66780c0 411 if( pOption )
IanBenzMaxim 0:33d4e66780c0 412 {
IanBenzMaxim 0:33d4e66780c0 413
IanBenzMaxim 0:33d4e66780c0 414 _SlDrvResetCmdExt(&CmdExt);
IanBenzMaxim 0:33d4e66780c0 415 CmdExt.RxPayloadLen = (_i16)*pConfigLen;
IanBenzMaxim 0:33d4e66780c0 416 CmdExt.pRxPayload = (_u8 *)pValues;
IanBenzMaxim 0:33d4e66780c0 417
IanBenzMaxim 0:33d4e66780c0 418 Msg.Cmd.DeviceSetId = DeviceGetId;
IanBenzMaxim 0:33d4e66780c0 419
IanBenzMaxim 0:33d4e66780c0 420 Msg.Cmd.Option = (_u16)*pOption;
IanBenzMaxim 0:33d4e66780c0 421
IanBenzMaxim 0:33d4e66780c0 422 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceGetCmdCtrl, &Msg, &CmdExt));
IanBenzMaxim 0:33d4e66780c0 423
IanBenzMaxim 0:33d4e66780c0 424 if( pOption )
IanBenzMaxim 0:33d4e66780c0 425 {
IanBenzMaxim 0:33d4e66780c0 426 *pOption = (_u8)Msg.Rsp.Option;
IanBenzMaxim 0:33d4e66780c0 427 }
IanBenzMaxim 0:33d4e66780c0 428
IanBenzMaxim 0:33d4e66780c0 429 if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
IanBenzMaxim 0:33d4e66780c0 430 {
IanBenzMaxim 0:33d4e66780c0 431 *pConfigLen = (_u8)CmdExt.RxPayloadLen;
IanBenzMaxim 0:33d4e66780c0 432 return SL_ESMALLBUF;
IanBenzMaxim 0:33d4e66780c0 433 }
IanBenzMaxim 0:33d4e66780c0 434 else
IanBenzMaxim 0:33d4e66780c0 435 {
IanBenzMaxim 0:33d4e66780c0 436 *pConfigLen = (_u8)CmdExt.ActualRxPayloadLen;
IanBenzMaxim 0:33d4e66780c0 437 }
IanBenzMaxim 0:33d4e66780c0 438
IanBenzMaxim 0:33d4e66780c0 439 return (_i16)Msg.Rsp.Status;
IanBenzMaxim 0:33d4e66780c0 440 }
IanBenzMaxim 0:33d4e66780c0 441 else
IanBenzMaxim 0:33d4e66780c0 442 {
IanBenzMaxim 0:33d4e66780c0 443 return -1;
IanBenzMaxim 0:33d4e66780c0 444 }
IanBenzMaxim 0:33d4e66780c0 445 }
IanBenzMaxim 0:33d4e66780c0 446 #endif
IanBenzMaxim 0:33d4e66780c0 447
IanBenzMaxim 0:33d4e66780c0 448 /******************************************************************************
IanBenzMaxim 0:33d4e66780c0 449 sl_DevSet
IanBenzMaxim 0:33d4e66780c0 450 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 451 typedef union
IanBenzMaxim 0:33d4e66780c0 452 {
IanBenzMaxim 0:33d4e66780c0 453 _DeviceSetGet_t Cmd;
IanBenzMaxim 0:33d4e66780c0 454 _BasicResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 455 }_SlDeviceMsgSet_u;
IanBenzMaxim 0:33d4e66780c0 456
IanBenzMaxim 0:33d4e66780c0 457
IanBenzMaxim 0:33d4e66780c0 458
IanBenzMaxim 0:33d4e66780c0 459 #if _SL_INCLUDE_FUNC(sl_DevSet)
IanBenzMaxim 0:33d4e66780c0 460
IanBenzMaxim 0:33d4e66780c0 461 static const _SlCmdCtrl_t _SlDeviceSetCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 462 {
IanBenzMaxim 0:33d4e66780c0 463 SL_OPCODE_DEVICE_DEVICESET,
IanBenzMaxim 0:33d4e66780c0 464 (_SlArgSize_t)sizeof(_DeviceSetGet_t),
IanBenzMaxim 0:33d4e66780c0 465 (_SlArgSize_t)sizeof(_BasicResponse_t)
IanBenzMaxim 0:33d4e66780c0 466 };
IanBenzMaxim 0:33d4e66780c0 467
IanBenzMaxim 0:33d4e66780c0 468 _i32 sl_DevSet(const _u8 DeviceSetId ,const _u8 Option,const _u8 ConfigLen,const _u8 *pValues)
IanBenzMaxim 0:33d4e66780c0 469 {
IanBenzMaxim 0:33d4e66780c0 470 _SlDeviceMsgSet_u Msg;
IanBenzMaxim 0:33d4e66780c0 471 _SlCmdExt_t CmdExt;
IanBenzMaxim 0:33d4e66780c0 472
IanBenzMaxim 0:33d4e66780c0 473 /* verify no erorr handling in progress. if in progress than
IanBenzMaxim 0:33d4e66780c0 474 ignore the API execution and return immediately with an error */
IanBenzMaxim 0:33d4e66780c0 475 VERIFY_NO_ERROR_HANDLING_IN_PROGRESS();
IanBenzMaxim 0:33d4e66780c0 476
IanBenzMaxim 0:33d4e66780c0 477 _SlDrvResetCmdExt(&CmdExt);
IanBenzMaxim 0:33d4e66780c0 478
IanBenzMaxim 0:33d4e66780c0 479 CmdExt.TxPayloadLen = (ConfigLen+3) & (~3);
IanBenzMaxim 0:33d4e66780c0 480 CmdExt.pTxPayload = (_u8 *)pValues;
IanBenzMaxim 0:33d4e66780c0 481
IanBenzMaxim 0:33d4e66780c0 482 Msg.Cmd.DeviceSetId = DeviceSetId;
IanBenzMaxim 0:33d4e66780c0 483 Msg.Cmd.ConfigLen = ConfigLen;
IanBenzMaxim 0:33d4e66780c0 484 Msg.Cmd.Option = Option;
IanBenzMaxim 0:33d4e66780c0 485
IanBenzMaxim 0:33d4e66780c0 486 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlDeviceSetCmdCtrl, &Msg, &CmdExt));
IanBenzMaxim 0:33d4e66780c0 487
IanBenzMaxim 0:33d4e66780c0 488 return (_i16)Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 489 }
IanBenzMaxim 0:33d4e66780c0 490 #endif
IanBenzMaxim 0:33d4e66780c0 491
IanBenzMaxim 0:33d4e66780c0 492
IanBenzMaxim 0:33d4e66780c0 493 /******************************************************************************
IanBenzMaxim 0:33d4e66780c0 494 _SlDrvDeviceEventHandler - handles internally device async events
IanBenzMaxim 0:33d4e66780c0 495 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 496 _SlReturnVal_t _SlDrvDeviceEventHandler(void* pEventInfo)
IanBenzMaxim 0:33d4e66780c0 497 {
IanBenzMaxim 0:33d4e66780c0 498 DeviceEventInfo_t* pInfo = (DeviceEventInfo_t*)pEventInfo;
IanBenzMaxim 0:33d4e66780c0 499 _SlResponseHeader_t* pHdr = (_SlResponseHeader_t *)pInfo->pAsyncMsgBuff;
IanBenzMaxim 0:33d4e66780c0 500 _BasicResponse_t *pMsgArgs = (_BasicResponse_t *)_SL_RESP_ARGS_START(pHdr);
IanBenzMaxim 0:33d4e66780c0 501
IanBenzMaxim 0:33d4e66780c0 502 switch(pHdr->GenHeader.Opcode)
IanBenzMaxim 0:33d4e66780c0 503 {
IanBenzMaxim 0:33d4e66780c0 504 case SL_OPCODE_DEVICE_INITCOMPLETE:
IanBenzMaxim 0:33d4e66780c0 505 _sl_HandleAsync_InitComplete(pHdr);
IanBenzMaxim 0:33d4e66780c0 506 break;
IanBenzMaxim 0:33d4e66780c0 507 case SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE:
IanBenzMaxim 0:33d4e66780c0 508 _sl_HandleAsync_Stop(pHdr);
IanBenzMaxim 0:33d4e66780c0 509 break;
IanBenzMaxim 0:33d4e66780c0 510
IanBenzMaxim 0:33d4e66780c0 511
IanBenzMaxim 0:33d4e66780c0 512 case SL_OPCODE_DEVICE_ABORT:
IanBenzMaxim 0:33d4e66780c0 513 {
IanBenzMaxim 0:33d4e66780c0 514 /* release global lock of cmd context */
IanBenzMaxim 0:33d4e66780c0 515 if (pInfo->bInCmdContext == TRUE)
IanBenzMaxim 0:33d4e66780c0 516 {
IanBenzMaxim 0:33d4e66780c0 517 SL_DRV_LOCK_GLOBAL_UNLOCK();
IanBenzMaxim 0:33d4e66780c0 518 }
IanBenzMaxim 0:33d4e66780c0 519
IanBenzMaxim 0:33d4e66780c0 520 #ifndef SL_TINY_EXT
IanBenzMaxim 0:33d4e66780c0 521 _SlDriverHandleError(SL_DEVICE_ABORT_ERROR_EVENT,
IanBenzMaxim 0:33d4e66780c0 522 *((_u32*)pMsgArgs), /* Abort type */
IanBenzMaxim 0:33d4e66780c0 523 *((_u32*)pMsgArgs + 1)); /* Abort data */
IanBenzMaxim 0:33d4e66780c0 524 #endif
IanBenzMaxim 0:33d4e66780c0 525 }
IanBenzMaxim 0:33d4e66780c0 526 break;
IanBenzMaxim 0:33d4e66780c0 527
IanBenzMaxim 0:33d4e66780c0 528 case SL_OPCODE_DEVICE_ASYNC_GENERAL_ERROR:
IanBenzMaxim 0:33d4e66780c0 529 {
IanBenzMaxim 0:33d4e66780c0 530 SlDeviceEvent_t devHandler;
IanBenzMaxim 0:33d4e66780c0 531 devHandler.Event = SL_DEVICE_GENERAL_ERROR_EVENT;
IanBenzMaxim 0:33d4e66780c0 532 devHandler.EventData.deviceEvent.status = pMsgArgs->status & 0xFF;
IanBenzMaxim 0:33d4e66780c0 533 devHandler.EventData.deviceEvent.sender = (SlErrorSender_e)((pMsgArgs->status >> 8) & 0xFF);
IanBenzMaxim 0:33d4e66780c0 534 _SlDrvHandleGeneralEvents(&devHandler);
IanBenzMaxim 0:33d4e66780c0 535 }
IanBenzMaxim 0:33d4e66780c0 536
IanBenzMaxim 0:33d4e66780c0 537 break;
IanBenzMaxim 0:33d4e66780c0 538 default:
IanBenzMaxim 0:33d4e66780c0 539 SL_ERROR_TRACE2(MSG_306, "ASSERT: _SlDrvDeviceEventHandler : invalid opcode = 0x%x = %1", pHdr->GenHeader.Opcode, pHdr->GenHeader.Opcode);
IanBenzMaxim 0:33d4e66780c0 540 }
IanBenzMaxim 0:33d4e66780c0 541
IanBenzMaxim 0:33d4e66780c0 542 return SL_OS_RET_CODE_OK;
IanBenzMaxim 0:33d4e66780c0 543 }
IanBenzMaxim 0:33d4e66780c0 544
IanBenzMaxim 0:33d4e66780c0 545
IanBenzMaxim 0:33d4e66780c0 546 /******************************************************************************
IanBenzMaxim 0:33d4e66780c0 547 sl_UartSetMode
IanBenzMaxim 0:33d4e66780c0 548 ******************************************************************************/
IanBenzMaxim 0:33d4e66780c0 549 #ifdef SL_IF_TYPE_UART
IanBenzMaxim 0:33d4e66780c0 550 typedef union
IanBenzMaxim 0:33d4e66780c0 551 {
IanBenzMaxim 0:33d4e66780c0 552 _DevUartSetModeCommand_t Cmd;
IanBenzMaxim 0:33d4e66780c0 553 _DevUartSetModeResponse_t Rsp;
IanBenzMaxim 0:33d4e66780c0 554 }_SlUartSetModeMsg_u;
IanBenzMaxim 0:33d4e66780c0 555
IanBenzMaxim 0:33d4e66780c0 556
IanBenzMaxim 0:33d4e66780c0 557 #if _SL_INCLUDE_FUNC(sl_UartSetMode)
IanBenzMaxim 0:33d4e66780c0 558
IanBenzMaxim 0:33d4e66780c0 559
IanBenzMaxim 0:33d4e66780c0 560 const _SlCmdCtrl_t _SlUartSetModeCmdCtrl =
IanBenzMaxim 0:33d4e66780c0 561 {
IanBenzMaxim 0:33d4e66780c0 562 SL_OPCODE_DEVICE_SETUARTMODECOMMAND,
IanBenzMaxim 0:33d4e66780c0 563 (_SlArgSize_t)sizeof(_DevUartSetModeCommand_t),
IanBenzMaxim 0:33d4e66780c0 564 (_SlArgSize_t)sizeof(_DevUartSetModeResponse_t)
IanBenzMaxim 0:33d4e66780c0 565 };
IanBenzMaxim 0:33d4e66780c0 566
IanBenzMaxim 0:33d4e66780c0 567 _i16 sl_UartSetMode(const SlUartIfParams_t* pUartParams)
IanBenzMaxim 0:33d4e66780c0 568 {
IanBenzMaxim 0:33d4e66780c0 569 _SlUartSetModeMsg_u Msg;
IanBenzMaxim 0:33d4e66780c0 570 _u32 magicCode = (_u32)0xFFFFFFFF;
IanBenzMaxim 0:33d4e66780c0 571
IanBenzMaxim 0:33d4e66780c0 572 Msg.Cmd.BaudRate = pUartParams->BaudRate;
IanBenzMaxim 0:33d4e66780c0 573 Msg.Cmd.FlowControlEnable = pUartParams->FlowControlEnable;
IanBenzMaxim 0:33d4e66780c0 574
IanBenzMaxim 0:33d4e66780c0 575
IanBenzMaxim 0:33d4e66780c0 576 VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlUartSetModeCmdCtrl, &Msg, NULL));
IanBenzMaxim 0:33d4e66780c0 577
IanBenzMaxim 0:33d4e66780c0 578 /* cmd response OK, we can continue with the handshake */
IanBenzMaxim 0:33d4e66780c0 579 if (SL_RET_CODE_OK == Msg.Rsp.status)
IanBenzMaxim 0:33d4e66780c0 580 {
IanBenzMaxim 0:33d4e66780c0 581 sl_IfMaskIntHdlr();
IanBenzMaxim 0:33d4e66780c0 582
IanBenzMaxim 0:33d4e66780c0 583 /* Close the comm port */
IanBenzMaxim 0:33d4e66780c0 584 sl_IfClose(g_pCB->FD);
IanBenzMaxim 0:33d4e66780c0 585
IanBenzMaxim 0:33d4e66780c0 586 /* Re-open the comm port */
IanBenzMaxim 0:33d4e66780c0 587 sl_IfOpen((void * )pUartParams, UART_IF_OPEN_FLAG_RE_OPEN);
IanBenzMaxim 0:33d4e66780c0 588
IanBenzMaxim 0:33d4e66780c0 589 sl_IfUnMaskIntHdlr();
IanBenzMaxim 0:33d4e66780c0 590
IanBenzMaxim 0:33d4e66780c0 591 /* send the magic code and wait for the response */
IanBenzMaxim 0:33d4e66780c0 592 sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
IanBenzMaxim 0:33d4e66780c0 593
IanBenzMaxim 0:33d4e66780c0 594 magicCode = UART_SET_MODE_MAGIC_CODE;
IanBenzMaxim 0:33d4e66780c0 595 sl_IfWrite(g_pCB->FD, (_u8* )&magicCode, 4);
IanBenzMaxim 0:33d4e66780c0 596
IanBenzMaxim 0:33d4e66780c0 597 /* clear magic code */
IanBenzMaxim 0:33d4e66780c0 598 magicCode = 0;
IanBenzMaxim 0:33d4e66780c0 599
IanBenzMaxim 0:33d4e66780c0 600 /* wait (blocking) till the magic code to be returned from device */
IanBenzMaxim 0:33d4e66780c0 601 sl_IfRead(g_pCB->FD, (_u8* )&magicCode, 4);
IanBenzMaxim 0:33d4e66780c0 602
IanBenzMaxim 0:33d4e66780c0 603 /* check for the received magic code matching */
IanBenzMaxim 0:33d4e66780c0 604 if (UART_SET_MODE_MAGIC_CODE != magicCode)
IanBenzMaxim 0:33d4e66780c0 605 {
IanBenzMaxim 0:33d4e66780c0 606 _SL_ASSERT(0);
IanBenzMaxim 0:33d4e66780c0 607 }
IanBenzMaxim 0:33d4e66780c0 608 }
IanBenzMaxim 0:33d4e66780c0 609
IanBenzMaxim 0:33d4e66780c0 610 return (_i16)Msg.Rsp.status;
IanBenzMaxim 0:33d4e66780c0 611 }
IanBenzMaxim 0:33d4e66780c0 612 #endif
IanBenzMaxim 0:33d4e66780c0 613 #endif
IanBenzMaxim 0:33d4e66780c0 614
IanBenzMaxim 0:33d4e66780c0 615