Simple LED control project using CC3100 as Access Point and socket
Fork of cc3100_Test_Demo by
simplelink/cc3100_driver.cpp@2:b3fd5b3d9860, 2015-02-15 (annotated)
- Committer:
- dflet
- Date:
- Sun Feb 15 11:01:37 2015 +0000
- Revision:
- 2:b3fd5b3d9860
- Parent:
- 0:e89ba455dbcf
Removed more debug comments, defined sl_Free & sl_Malloc. Also remove some duplicate #defines
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:e89ba455dbcf | 1 | /* |
dflet | 0:e89ba455dbcf | 2 | * driver.c - CC31xx/CC32xx Host Driver Implementation |
dflet | 0:e89ba455dbcf | 3 | * |
dflet | 0:e89ba455dbcf | 4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ |
dflet | 0:e89ba455dbcf | 5 | * |
dflet | 0:e89ba455dbcf | 6 | * |
dflet | 0:e89ba455dbcf | 7 | * Redistribution and use in source and binary forms, with or without |
dflet | 0:e89ba455dbcf | 8 | * modification, are permitted provided that the following conditions |
dflet | 0:e89ba455dbcf | 9 | * are met: |
dflet | 0:e89ba455dbcf | 10 | * |
dflet | 0:e89ba455dbcf | 11 | * Redistributions of source code must retain the above copyright |
dflet | 0:e89ba455dbcf | 12 | * notice, this list of conditions and the following disclaimer. |
dflet | 0:e89ba455dbcf | 13 | * |
dflet | 0:e89ba455dbcf | 14 | * Redistributions in binary form must reproduce the above copyright |
dflet | 0:e89ba455dbcf | 15 | * notice, this list of conditions and the following disclaimer in the |
dflet | 0:e89ba455dbcf | 16 | * documentation and/or other materials provided with the |
dflet | 0:e89ba455dbcf | 17 | * distribution. |
dflet | 0:e89ba455dbcf | 18 | * |
dflet | 0:e89ba455dbcf | 19 | * Neither the name of Texas Instruments Incorporated nor the names of |
dflet | 0:e89ba455dbcf | 20 | * its contributors may be used to endorse or promote products derived |
dflet | 0:e89ba455dbcf | 21 | * from this software without specific prior written permission. |
dflet | 0:e89ba455dbcf | 22 | * |
dflet | 0:e89ba455dbcf | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
dflet | 0:e89ba455dbcf | 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
dflet | 0:e89ba455dbcf | 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
dflet | 0:e89ba455dbcf | 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
dflet | 0:e89ba455dbcf | 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
dflet | 0:e89ba455dbcf | 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
dflet | 0:e89ba455dbcf | 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
dflet | 0:e89ba455dbcf | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
dflet | 0:e89ba455dbcf | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
dflet | 0:e89ba455dbcf | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
dflet | 0:e89ba455dbcf | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dflet | 0:e89ba455dbcf | 34 | * |
dflet | 0:e89ba455dbcf | 35 | */ |
dflet | 0:e89ba455dbcf | 36 | |
dflet | 0:e89ba455dbcf | 37 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 38 | /* Include files */ |
dflet | 0:e89ba455dbcf | 39 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 40 | #include "cc3100_simplelink.h" |
dflet | 0:e89ba455dbcf | 41 | #include "cc3100_protocol.h" |
dflet | 0:e89ba455dbcf | 42 | #include "cc3100_driver.h" |
dflet | 0:e89ba455dbcf | 43 | |
dflet | 0:e89ba455dbcf | 44 | #include "fPtr_func.h" |
dflet | 0:e89ba455dbcf | 45 | |
dflet | 0:e89ba455dbcf | 46 | //#include "cc3100_device.h" |
dflet | 0:e89ba455dbcf | 47 | |
dflet | 0:e89ba455dbcf | 48 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 49 | /* Macro declarations */ |
dflet | 0:e89ba455dbcf | 50 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 51 | |
dflet | 0:e89ba455dbcf | 52 | namespace mbed_cc3100 { |
dflet | 0:e89ba455dbcf | 53 | |
dflet | 0:e89ba455dbcf | 54 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 55 | typedef struct { |
dflet | 0:e89ba455dbcf | 56 | uint32_t Align; |
dflet | 0:e89ba455dbcf | 57 | _SlDriverCb_t DriverCB; |
dflet | 0:e89ba455dbcf | 58 | uint8_t AsyncRespBuf[SL_ASYNC_MAX_MSG_LEN]; |
dflet | 0:e89ba455dbcf | 59 | } _SlStatMem_t; |
dflet | 0:e89ba455dbcf | 60 | |
dflet | 0:e89ba455dbcf | 61 | _SlStatMem_t g_StatMem; |
dflet | 0:e89ba455dbcf | 62 | #endif |
dflet | 0:e89ba455dbcf | 63 | |
dflet | 0:e89ba455dbcf | 64 | |
dflet | 0:e89ba455dbcf | 65 | _SlDriverCb_t* g_pCB = NULL; |
dflet | 0:e89ba455dbcf | 66 | |
dflet | 0:e89ba455dbcf | 67 | uint8_t gFirstCmdMode = 0; |
dflet | 0:e89ba455dbcf | 68 | |
dflet | 0:e89ba455dbcf | 69 | const _SlSyncPattern_t g_H2NSyncPattern = H2N_SYNC_PATTERN; |
dflet | 0:e89ba455dbcf | 70 | const _SlSyncPattern_t g_H2NCnysPattern = H2N_CNYS_PATTERN; |
dflet | 0:e89ba455dbcf | 71 | const _SlActionLookup_t _SlActionLookupTable[7] = { |
dflet | 0:e89ba455dbcf | 72 | {ACCEPT_ID, SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE, (_SlSpawnEntryFunc_t) &_sl_HandleAsync_Accept}, |
dflet | 0:e89ba455dbcf | 73 | {CONNECT_ID, SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE,(_SlSpawnEntryFunc_t) &_sl_HandleAsync_Connect}, |
dflet | 0:e89ba455dbcf | 74 | {SELECT_ID, SL_OPCODE_SOCKET_SELECTASYNCRESPONSE,(_SlSpawnEntryFunc_t) &_sl_HandleAsync_Select}, |
dflet | 0:e89ba455dbcf | 75 | {GETHOSYBYNAME_ID, SL_OPCODE_NETAPP_DNSGETHOSTBYNAMEASYNCRESPONSE,(_SlSpawnEntryFunc_t) &_sl_HandleAsync_DnsGetHostByName}, |
dflet | 0:e89ba455dbcf | 76 | {GETHOSYBYSERVICE_ID, SL_OPCODE_NETAPP_MDNSGETHOSTBYSERVICEASYNCRESPONSE,(_SlSpawnEntryFunc_t) &_sl_HandleAsync_DnsGetHostByService}, |
dflet | 0:e89ba455dbcf | 77 | {PING_ID, SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE, (_SlSpawnEntryFunc_t) &_sl_HandleAsync_PingResponse}, |
dflet | 0:e89ba455dbcf | 78 | {START_STOP_ID, SL_OPCODE_DEVICE_STOP_ASYNC_RESPONSE,(_SlSpawnEntryFunc_t) &_sl_HandleAsync_Stop} |
dflet | 0:e89ba455dbcf | 79 | |
dflet | 0:e89ba455dbcf | 80 | }; |
dflet | 0:e89ba455dbcf | 81 | |
dflet | 0:e89ba455dbcf | 82 | cc3100_driver::cc3100_driver(cc3100_nonos &nonos, cc3100_netapp &netapp, cc3100_flowcont &flowcont, cc3100_spi &spi) |
dflet | 0:e89ba455dbcf | 83 | : _nonos(nonos),_netapp(netapp), _flowcont(flowcont), _spi(spi) |
dflet | 0:e89ba455dbcf | 84 | { |
dflet | 0:e89ba455dbcf | 85 | |
dflet | 0:e89ba455dbcf | 86 | } |
dflet | 0:e89ba455dbcf | 87 | |
dflet | 0:e89ba455dbcf | 88 | cc3100_driver::~cc3100_driver() |
dflet | 0:e89ba455dbcf | 89 | { |
dflet | 0:e89ba455dbcf | 90 | |
dflet | 0:e89ba455dbcf | 91 | } |
dflet | 0:e89ba455dbcf | 92 | |
dflet | 0:e89ba455dbcf | 93 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 94 | /* Variables */ |
dflet | 0:e89ba455dbcf | 95 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 96 | |
dflet | 0:e89ba455dbcf | 97 | /********************************************************************************/ |
dflet | 0:e89ba455dbcf | 98 | |
dflet | 0:e89ba455dbcf | 99 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 100 | /* Internal functions */ |
dflet | 0:e89ba455dbcf | 101 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 102 | bool cc3100_driver::_SL_PENDING_RX_MSG(pDriver* pDriverCB){ |
dflet | 0:e89ba455dbcf | 103 | |
dflet | 0:e89ba455dbcf | 104 | if((pDriverCB)->RxIrqCnt != (pDriverCB)->RxDoneCnt){ |
dflet | 0:e89ba455dbcf | 105 | return TRUE; |
dflet | 0:e89ba455dbcf | 106 | }else{ |
dflet | 0:e89ba455dbcf | 107 | return FALSE; |
dflet | 0:e89ba455dbcf | 108 | } |
dflet | 0:e89ba455dbcf | 109 | } |
dflet | 0:e89ba455dbcf | 110 | |
dflet | 0:e89ba455dbcf | 111 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 112 | _SlDrvDriverCBInit - init Driver Control Block |
dflet | 0:e89ba455dbcf | 113 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 114 | void cc3100_driver::_SlDrvDriverCBInit(void) |
dflet | 0:e89ba455dbcf | 115 | { |
dflet | 0:e89ba455dbcf | 116 | |
dflet | 0:e89ba455dbcf | 117 | uint8_t Idx; |
dflet | 0:e89ba455dbcf | 118 | |
dflet | 0:e89ba455dbcf | 119 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 120 | g_pCB = &(g_StatMem.DriverCB); |
dflet | 0:e89ba455dbcf | 121 | #else |
dflet | 0:e89ba455dbcf | 122 | g_pCB = sl_Malloc(sizeof(_SlDriverCb_t)); |
dflet | 0:e89ba455dbcf | 123 | #endif |
dflet | 0:e89ba455dbcf | 124 | |
dflet | 0:e89ba455dbcf | 125 | MALLOC_OK_CHECK(g_pCB); |
dflet | 0:e89ba455dbcf | 126 | memset((g_pCB), 0, sizeof(_SlDriverCb_t)); |
dflet | 0:e89ba455dbcf | 127 | |
dflet | 0:e89ba455dbcf | 128 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjCreate(&g_pCB->CmdSyncObj, "CmdSyncObj") ); |
dflet | 0:e89ba455dbcf | 129 | _nonos.sl_SyncObjClear(&g_pCB->CmdSyncObj); |
dflet | 0:e89ba455dbcf | 130 | |
dflet | 0:e89ba455dbcf | 131 | OSI_RET_OK_CHECK( _nonos.sl_LockObjCreate(&g_pCB->GlobalLockObj, "GlobalLockObj") ); |
dflet | 0:e89ba455dbcf | 132 | |
dflet | 0:e89ba455dbcf | 133 | OSI_RET_OK_CHECK( _nonos.sl_LockObjCreate(&g_pCB->ProtectionLockObj, "ProtectionLockObj") ); |
dflet | 0:e89ba455dbcf | 134 | |
dflet | 0:e89ba455dbcf | 135 | _SlDrvObjInit(); |
dflet | 0:e89ba455dbcf | 136 | for (Idx = 0; Idx < MAX_CONCURRENT_ACTIONS; Idx++) { |
dflet | 0:e89ba455dbcf | 137 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjCreate(&g_pCB->ObjPool[Idx].SyncObj, "SyncObj") ); |
dflet | 0:e89ba455dbcf | 138 | _nonos.sl_SyncObjClear(&g_pCB->ObjPool[Idx].SyncObj); |
dflet | 0:e89ba455dbcf | 139 | } |
dflet | 0:e89ba455dbcf | 140 | _flowcont._SlDrvFlowContInit(); |
dflet | 0:e89ba455dbcf | 141 | gFirstCmdMode = 0; |
dflet | 0:e89ba455dbcf | 142 | } |
dflet | 0:e89ba455dbcf | 143 | |
dflet | 0:e89ba455dbcf | 144 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 145 | _SlDrvDriverCBDeinit - De init Driver Control Block |
dflet | 0:e89ba455dbcf | 146 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 147 | void cc3100_driver::_SlDrvDriverCBDeinit() |
dflet | 0:e89ba455dbcf | 148 | { |
dflet | 0:e89ba455dbcf | 149 | uint8_t Idx; |
dflet | 0:e89ba455dbcf | 150 | _flowcont._SlDrvFlowContDeinit(); |
dflet | 0:e89ba455dbcf | 151 | |
dflet | 0:e89ba455dbcf | 152 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjDelete(&g_pCB->CmdSyncObj, 0) ); |
dflet | 0:e89ba455dbcf | 153 | OSI_RET_OK_CHECK( _nonos.sl_LockObjDelete(&g_pCB->GlobalLockObj, 0) ); |
dflet | 0:e89ba455dbcf | 154 | OSI_RET_OK_CHECK( _nonos.sl_LockObjDelete(&g_pCB->ProtectionLockObj, 0) ); |
dflet | 0:e89ba455dbcf | 155 | for (Idx = 0; Idx < MAX_CONCURRENT_ACTIONS; Idx++) { |
dflet | 0:e89ba455dbcf | 156 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjDelete(&g_pCB->ObjPool[Idx].SyncObj, 0) ); |
dflet | 0:e89ba455dbcf | 157 | } |
dflet | 0:e89ba455dbcf | 158 | |
dflet | 0:e89ba455dbcf | 159 | _SlDrvObjDeInit(); |
dflet | 0:e89ba455dbcf | 160 | |
dflet | 0:e89ba455dbcf | 161 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 162 | g_pCB = NULL; |
dflet | 0:e89ba455dbcf | 163 | #else |
dflet | 0:e89ba455dbcf | 164 | sl_Free(g_pCB); |
dflet | 0:e89ba455dbcf | 165 | #endif |
dflet | 0:e89ba455dbcf | 166 | |
dflet | 0:e89ba455dbcf | 167 | g_pCB = NULL; |
dflet | 0:e89ba455dbcf | 168 | } |
dflet | 0:e89ba455dbcf | 169 | |
dflet | 0:e89ba455dbcf | 170 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 171 | _SlDrvRxIrqHandler - Interrupt handler |
dflet | 0:e89ba455dbcf | 172 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 173 | |
dflet | 0:e89ba455dbcf | 174 | void cc3100_driver::_SlDrvRxIrqHandler(void *pValue) |
dflet | 0:e89ba455dbcf | 175 | { |
dflet | 0:e89ba455dbcf | 176 | |
dflet | 0:e89ba455dbcf | 177 | |
dflet | 0:e89ba455dbcf | 178 | _spi.MaskIntHdlr(); |
dflet | 0:e89ba455dbcf | 179 | g_pCB->RxIrqCnt++; |
dflet | 0:e89ba455dbcf | 180 | if (TRUE == g_pCB->IsCmdRespWaited) { |
dflet | 0:e89ba455dbcf | 181 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjSignalFromIRQ(&g_pCB->CmdSyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE) ); |
dflet | 0:e89ba455dbcf | 182 | } else { |
dflet | 0:e89ba455dbcf | 183 | _nonos._SlNonOsSpawn((_SlSpawnEntryFunc_t)&_SlDrvMsgReadSpawnCtx, NULL, 0); |
dflet | 0:e89ba455dbcf | 184 | } |
dflet | 0:e89ba455dbcf | 185 | } |
dflet | 0:e89ba455dbcf | 186 | |
dflet | 0:e89ba455dbcf | 187 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 188 | _SlDrvCmdOp |
dflet | 0:e89ba455dbcf | 189 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 190 | _SlReturnVal_t cc3100_driver::_SlDrvCmdOp(_SlCmdCtrl_t *pCmdCtrl,void* pTxRxDescBuff, _SlCmdExt_t *pCmdExt) |
dflet | 0:e89ba455dbcf | 191 | { |
dflet | 0:e89ba455dbcf | 192 | |
dflet | 0:e89ba455dbcf | 193 | _SlReturnVal_t RetVal; |
dflet | 0:e89ba455dbcf | 194 | |
dflet | 0:e89ba455dbcf | 195 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 196 | |
dflet | 0:e89ba455dbcf | 197 | g_pCB->IsCmdRespWaited = TRUE; |
dflet | 2:b3fd5b3d9860 | 198 | SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdOp: call _SlDrvMsgWrite"); |
dflet | 0:e89ba455dbcf | 199 | /* send the message */ |
dflet | 0:e89ba455dbcf | 200 | g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; |
dflet | 0:e89ba455dbcf | 201 | g_pCB->FunctionParams.pTxRxDescBuff = (uint8_t*)pTxRxDescBuff; |
dflet | 0:e89ba455dbcf | 202 | g_pCB->FunctionParams.pCmdExt = pCmdExt; |
dflet | 0:e89ba455dbcf | 203 | |
dflet | 0:e89ba455dbcf | 204 | RetVal = _SlDrvMsgWrite(); |
dflet | 0:e89ba455dbcf | 205 | |
dflet | 0:e89ba455dbcf | 206 | if(SL_OS_RET_CODE_OK == RetVal) { |
dflet | 0:e89ba455dbcf | 207 | |
dflet | 0:e89ba455dbcf | 208 | #ifndef SL_IF_TYPE_UART |
dflet | 0:e89ba455dbcf | 209 | /* Waiting for SPI to stabilize after first command */ |
dflet | 0:e89ba455dbcf | 210 | if( 0 == gFirstCmdMode ) { |
dflet | 0:e89ba455dbcf | 211 | gFirstCmdMode = 1; |
dflet | 0:e89ba455dbcf | 212 | wait_ms(2); |
dflet | 0:e89ba455dbcf | 213 | } |
dflet | 0:e89ba455dbcf | 214 | #endif |
dflet | 0:e89ba455dbcf | 215 | |
dflet | 0:e89ba455dbcf | 216 | /* wait for respond */ |
dflet | 0:e89ba455dbcf | 217 | RetVal = _SlDrvMsgReadCmdCtx(); /* will free global lock */ |
dflet | 2:b3fd5b3d9860 | 218 | SL_TRACE0(DBG_MSG, MSG_314, "_SlDrvCmdOp: exited _SlDrvMsgReadCmdCtx"); |
dflet | 0:e89ba455dbcf | 219 | |
dflet | 0:e89ba455dbcf | 220 | } else { |
dflet | 0:e89ba455dbcf | 221 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 222 | } |
dflet | 0:e89ba455dbcf | 223 | return RetVal; |
dflet | 0:e89ba455dbcf | 224 | } |
dflet | 0:e89ba455dbcf | 225 | |
dflet | 0:e89ba455dbcf | 226 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 227 | _SlDrvCmdSend |
dflet | 0:e89ba455dbcf | 228 | Send SL command without waiting for command response |
dflet | 0:e89ba455dbcf | 229 | This function is unprotected and the caller should make |
dflet | 0:e89ba455dbcf | 230 | sure global lock is active |
dflet | 0:e89ba455dbcf | 231 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 232 | _SlReturnVal_t cc3100_driver::_SlDrvCmdSend(_SlCmdCtrl_t *pCmdCtrl, void* pTxRxDescBuff, _SlCmdExt_t *pCmdExt) |
dflet | 0:e89ba455dbcf | 233 | { |
dflet | 0:e89ba455dbcf | 234 | _SlReturnVal_t RetVal; |
dflet | 0:e89ba455dbcf | 235 | |
dflet | 0:e89ba455dbcf | 236 | g_pCB->IsCmdRespWaited = FALSE; |
dflet | 0:e89ba455dbcf | 237 | |
dflet | 0:e89ba455dbcf | 238 | SL_TRACE0(DBG_MSG, MSG_312, "_SlDrvCmdSend: call _SlDrvMsgWrite"); |
dflet | 0:e89ba455dbcf | 239 | /* send the message */ |
dflet | 0:e89ba455dbcf | 240 | g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; |
dflet | 0:e89ba455dbcf | 241 | g_pCB->FunctionParams.pTxRxDescBuff = (uint8_t*)pTxRxDescBuff; |
dflet | 0:e89ba455dbcf | 242 | g_pCB->FunctionParams.pCmdExt = pCmdExt; |
dflet | 0:e89ba455dbcf | 243 | |
dflet | 0:e89ba455dbcf | 244 | RetVal = _SlDrvMsgWrite(); |
dflet | 0:e89ba455dbcf | 245 | |
dflet | 0:e89ba455dbcf | 246 | return RetVal; |
dflet | 0:e89ba455dbcf | 247 | } |
dflet | 0:e89ba455dbcf | 248 | |
dflet | 0:e89ba455dbcf | 249 | /***************************************************************************** |
dflet | 0:e89ba455dbcf | 250 | _SlDrvDataReadOp |
dflet | 0:e89ba455dbcf | 251 | *****************************************************************************/ |
dflet | 0:e89ba455dbcf | 252 | _SlReturnVal_t cc3100_driver::_SlDrvDataReadOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl, void* pTxRxDescBuff, _SlCmdExt_t *pCmdExt) |
dflet | 0:e89ba455dbcf | 253 | { |
dflet | 0:e89ba455dbcf | 254 | _SlReturnVal_t RetVal; |
dflet | 0:e89ba455dbcf | 255 | uint8_t ObjIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 256 | _SlArgsData_t pArgsData; |
dflet | 0:e89ba455dbcf | 257 | |
dflet | 0:e89ba455dbcf | 258 | /* Validate input arguments */ |
dflet | 0:e89ba455dbcf | 259 | VERIFY_PROTOCOL(NULL != pCmdExt->pRxPayload); |
dflet | 0:e89ba455dbcf | 260 | |
dflet | 0:e89ba455dbcf | 261 | /* If zero bytes is requested, return error. */ |
dflet | 0:e89ba455dbcf | 262 | /* This allows us not to fill remote socket's IP address in return arguments */ |
dflet | 0:e89ba455dbcf | 263 | VERIFY_PROTOCOL(0 != pCmdExt->RxPayloadLen); |
dflet | 0:e89ba455dbcf | 264 | |
dflet | 0:e89ba455dbcf | 265 | /* Validate socket */ |
dflet | 0:e89ba455dbcf | 266 | if((Sd & BSD_SOCKET_ID_MASK) >= SL_MAX_SOCKETS) { |
dflet | 0:e89ba455dbcf | 267 | return SL_EBADF; |
dflet | 0:e89ba455dbcf | 268 | } |
dflet | 0:e89ba455dbcf | 269 | |
dflet | 0:e89ba455dbcf | 270 | /*Use Obj to issue the command, if not available try later*/ |
dflet | 0:e89ba455dbcf | 271 | ObjIdx = (uint8_t)_SlDrvWaitForPoolObj(RECV_ID, Sd & BSD_SOCKET_ID_MASK); |
dflet | 0:e89ba455dbcf | 272 | |
dflet | 0:e89ba455dbcf | 273 | if (MAX_CONCURRENT_ACTIONS == ObjIdx) { |
dflet | 0:e89ba455dbcf | 274 | return SL_POOL_IS_EMPTY; |
dflet | 0:e89ba455dbcf | 275 | } |
dflet | 0:e89ba455dbcf | 276 | |
dflet | 0:e89ba455dbcf | 277 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 278 | |
dflet | 0:e89ba455dbcf | 279 | pArgsData.pData = pCmdExt->pRxPayload; |
dflet | 0:e89ba455dbcf | 280 | pArgsData.pArgs = (uint8_t *)pTxRxDescBuff; |
dflet | 0:e89ba455dbcf | 281 | g_pCB->ObjPool[ObjIdx].pRespArgs = (uint8_t *)&pArgsData; |
dflet | 0:e89ba455dbcf | 282 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 283 | |
dflet | 0:e89ba455dbcf | 284 | |
dflet | 0:e89ba455dbcf | 285 | /* Do Flow Control check/update for DataWrite operation */ |
dflet | 0:e89ba455dbcf | 286 | OSI_RET_OK_CHECK( _nonos.sl_LockObjLock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER) ); |
dflet | 0:e89ba455dbcf | 287 | |
dflet | 0:e89ba455dbcf | 288 | /* Clear SyncObj for the case it was signalled before TxPoolCnt */ |
dflet | 0:e89ba455dbcf | 289 | /* dropped below '1' (last Data buffer was taken) */ |
dflet | 0:e89ba455dbcf | 290 | /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ |
dflet | 0:e89ba455dbcf | 291 | _nonos.sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj); |
dflet | 0:e89ba455dbcf | 292 | |
dflet | 0:e89ba455dbcf | 293 | if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN) { |
dflet | 0:e89ba455dbcf | 294 | |
dflet | 0:e89ba455dbcf | 295 | /* If TxPoolCnt was increased by other thread at this moment, |
dflet | 0:e89ba455dbcf | 296 | TxSyncObj won't wait here */ |
dflet | 0:e89ba455dbcf | 297 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjWait(&g_pCB->FlowContCB.TxSyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE, NON_OS_SYNC_OBJ_CLEAR_VALUE, SL_OS_WAIT_FOREVER) ); |
dflet | 0:e89ba455dbcf | 298 | } |
dflet | 0:e89ba455dbcf | 299 | |
dflet | 0:e89ba455dbcf | 300 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 301 | |
dflet | 0:e89ba455dbcf | 302 | VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN); |
dflet | 0:e89ba455dbcf | 303 | g_pCB->FlowContCB.TxPoolCnt--; |
dflet | 0:e89ba455dbcf | 304 | |
dflet | 0:e89ba455dbcf | 305 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 306 | |
dflet | 0:e89ba455dbcf | 307 | /* send the message */ |
dflet | 0:e89ba455dbcf | 308 | g_pCB->TempProtocolHeader.Opcode = pCmdCtrl->Opcode; |
dflet | 0:e89ba455dbcf | 309 | g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt); |
dflet | 0:e89ba455dbcf | 310 | g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; |
dflet | 0:e89ba455dbcf | 311 | g_pCB->FunctionParams.pTxRxDescBuff = (uint8_t *)pTxRxDescBuff; |
dflet | 0:e89ba455dbcf | 312 | g_pCB->FunctionParams.pCmdExt = pCmdExt; |
dflet | 0:e89ba455dbcf | 313 | RetVal = _SlDrvMsgWrite(); |
dflet | 0:e89ba455dbcf | 314 | |
dflet | 0:e89ba455dbcf | 315 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 316 | |
dflet | 0:e89ba455dbcf | 317 | if(SL_OS_RET_CODE_OK == RetVal) { |
dflet | 0:e89ba455dbcf | 318 | /* Wait for response message. Will be signalled by _SlDrvMsgRead. */ |
dflet | 0:e89ba455dbcf | 319 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjWait(&g_pCB->ObjPool[ObjIdx].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE, NON_OS_SYNC_OBJ_CLEAR_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 320 | } |
dflet | 0:e89ba455dbcf | 321 | |
dflet | 0:e89ba455dbcf | 322 | _SlDrvReleasePoolObj(ObjIdx); |
dflet | 0:e89ba455dbcf | 323 | return RetVal; |
dflet | 0:e89ba455dbcf | 324 | } |
dflet | 0:e89ba455dbcf | 325 | |
dflet | 0:e89ba455dbcf | 326 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 327 | /* _SlDrvDataWriteOp */ |
dflet | 0:e89ba455dbcf | 328 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 329 | _SlReturnVal_t cc3100_driver::_SlDrvDataWriteOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl, void* pTxRxDescBuff, _SlCmdExt_t *pCmdExt) |
dflet | 0:e89ba455dbcf | 330 | { |
dflet | 0:e89ba455dbcf | 331 | _SlReturnVal_t RetVal = SL_EAGAIN; /* initiated as SL_EAGAIN for the non blocking mode */ |
dflet | 0:e89ba455dbcf | 332 | while( 1 ) { |
dflet | 0:e89ba455dbcf | 333 | /* Do Flow Control check/update for DataWrite operation */ |
dflet | 0:e89ba455dbcf | 334 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 335 | /* Clear SyncObj for the case it was signalled before TxPoolCnt */ |
dflet | 0:e89ba455dbcf | 336 | /* dropped below '1' (last Data buffer was taken) */ |
dflet | 0:e89ba455dbcf | 337 | /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */ |
dflet | 0:e89ba455dbcf | 338 | _nonos.sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj); |
dflet | 0:e89ba455dbcf | 339 | /* we have indication that the last send has failed - socket is no longer valid for operations */ |
dflet | 0:e89ba455dbcf | 340 | if(g_pCB->SocketTXFailure & (1<<(Sd & BSD_SOCKET_ID_MASK))) { |
dflet | 0:e89ba455dbcf | 341 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 342 | return SL_SOC_ERROR; |
dflet | 0:e89ba455dbcf | 343 | } |
dflet | 2:b3fd5b3d9860 | 344 | |
dflet | 0:e89ba455dbcf | 345 | if(g_pCB->FlowContCB.TxPoolCnt <= FLOW_CONT_MIN + 1) { |
dflet | 0:e89ba455dbcf | 346 | /* we have indication that this socket is set as blocking and we try to */ |
dflet | 0:e89ba455dbcf | 347 | /* unblock it - return an error */ |
dflet | 0:e89ba455dbcf | 348 | if( g_pCB->SocketNonBlocking >> (Sd & BSD_SOCKET_ID_MASK) ) { |
dflet | 0:e89ba455dbcf | 349 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 350 | return RetVal; |
dflet | 0:e89ba455dbcf | 351 | } |
dflet | 0:e89ba455dbcf | 352 | /* If TxPoolCnt was increased by other thread at this moment, */ |
dflet | 0:e89ba455dbcf | 353 | /* TxSyncObj won't wait here */ |
dflet | 0:e89ba455dbcf | 354 | OSI_RET_OK_CHECK( _nonos.sl_SyncObjWait(&g_pCB->FlowContCB.TxSyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE, NON_OS_SYNC_OBJ_CLEAR_VALUE, SL_OS_WAIT_FOREVER) ); |
dflet | 0:e89ba455dbcf | 355 | } |
dflet | 0:e89ba455dbcf | 356 | |
dflet | 0:e89ba455dbcf | 357 | if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ) { |
dflet | 0:e89ba455dbcf | 358 | break; |
dflet | 0:e89ba455dbcf | 359 | } else { |
dflet | 0:e89ba455dbcf | 360 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 361 | } |
dflet | 0:e89ba455dbcf | 362 | } |
dflet | 0:e89ba455dbcf | 363 | OSI_RET_OK_CHECK( _nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER) ); |
dflet | 0:e89ba455dbcf | 364 | |
dflet | 0:e89ba455dbcf | 365 | VERIFY_PROTOCOL(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN + 1 ); |
dflet | 0:e89ba455dbcf | 366 | g_pCB->FlowContCB.TxPoolCnt--; |
dflet | 0:e89ba455dbcf | 367 | |
dflet | 0:e89ba455dbcf | 368 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->FlowContCB.TxLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 369 | |
dflet | 0:e89ba455dbcf | 370 | /* send the message */ |
dflet | 0:e89ba455dbcf | 371 | g_pCB->TempProtocolHeader.Opcode = pCmdCtrl->Opcode; |
dflet | 0:e89ba455dbcf | 372 | g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt); |
dflet | 0:e89ba455dbcf | 373 | g_pCB->FunctionParams.pCmdCtrl = pCmdCtrl; |
dflet | 0:e89ba455dbcf | 374 | g_pCB->FunctionParams.pTxRxDescBuff = (unsigned char*)pTxRxDescBuff; |
dflet | 0:e89ba455dbcf | 375 | g_pCB->FunctionParams.pCmdExt = pCmdExt; |
dflet | 0:e89ba455dbcf | 376 | |
dflet | 0:e89ba455dbcf | 377 | RetVal = _SlDrvMsgWrite(); |
dflet | 0:e89ba455dbcf | 378 | |
dflet | 0:e89ba455dbcf | 379 | OSI_RET_OK_CHECK( _nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE) ); |
dflet | 0:e89ba455dbcf | 380 | |
dflet | 0:e89ba455dbcf | 381 | return RetVal; |
dflet | 0:e89ba455dbcf | 382 | } |
dflet | 0:e89ba455dbcf | 383 | |
dflet | 0:e89ba455dbcf | 384 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 385 | /* _SlDrvMsgWrite */ |
dflet | 0:e89ba455dbcf | 386 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 387 | _SlReturnVal_t cc3100_driver::_SlDrvMsgWrite(void) |
dflet | 0:e89ba455dbcf | 388 | { |
dflet | 0:e89ba455dbcf | 389 | |
dflet | 0:e89ba455dbcf | 390 | VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.pCmdCtrl); |
dflet | 0:e89ba455dbcf | 391 | |
dflet | 0:e89ba455dbcf | 392 | g_pCB->TempProtocolHeader.Opcode = g_pCB->FunctionParams.pCmdCtrl->Opcode; |
dflet | 0:e89ba455dbcf | 393 | g_pCB->TempProtocolHeader.Len = _SL_PROTOCOL_CALC_LEN(g_pCB->FunctionParams.pCmdCtrl, |
dflet | 0:e89ba455dbcf | 394 | g_pCB->FunctionParams.pCmdExt); |
dflet | 0:e89ba455dbcf | 395 | /* */ |
dflet | 0:e89ba455dbcf | 396 | if (g_pCB->RelayFlagsViaRxPayload == TRUE) { |
dflet | 0:e89ba455dbcf | 397 | g_pCB->TempProtocolHeader.Len = g_pCB->TempProtocolHeader.Len + g_pCB->FunctionParams.pCmdExt->RxPayloadLen; |
dflet | 0:e89ba455dbcf | 398 | } |
dflet | 0:e89ba455dbcf | 399 | |
dflet | 0:e89ba455dbcf | 400 | #ifdef SL_START_WRITE_STAT |
dflet | 0:e89ba455dbcf | 401 | sl_IfStartWriteSequence(g_pCB->FD); |
dflet | 0:e89ba455dbcf | 402 | #endif |
dflet | 0:e89ba455dbcf | 403 | |
dflet | 0:e89ba455dbcf | 404 | #ifdef SL_IF_TYPE_UART |
dflet | 0:e89ba455dbcf | 405 | /* Write long sync pattern */ |
dflet | 0:e89ba455dbcf | 406 | _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Long, 2*SYNC_PATTERN_LEN); |
dflet | 0:e89ba455dbcf | 407 | #else |
dflet | 0:e89ba455dbcf | 408 | /* Write short sync pattern */ |
dflet | 0:e89ba455dbcf | 409 | _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Short, SYNC_PATTERN_LEN); |
dflet | 0:e89ba455dbcf | 410 | #endif |
dflet | 0:e89ba455dbcf | 411 | |
dflet | 0:e89ba455dbcf | 412 | /* Header */ |
dflet | 0:e89ba455dbcf | 413 | _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_pCB->TempProtocolHeader, _SL_CMD_HDR_SIZE); |
dflet | 0:e89ba455dbcf | 414 | |
dflet | 0:e89ba455dbcf | 415 | /* Descriptors */ |
dflet | 0:e89ba455dbcf | 416 | if (g_pCB->FunctionParams.pTxRxDescBuff && g_pCB->FunctionParams.pCmdCtrl->TxDescLen > 0) { |
dflet | 0:e89ba455dbcf | 417 | _spi.spi_Write(g_pCB->FD, g_pCB->FunctionParams.pTxRxDescBuff, |
dflet | 0:e89ba455dbcf | 418 | _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->TxDescLen)); |
dflet | 0:e89ba455dbcf | 419 | } |
dflet | 0:e89ba455dbcf | 420 | |
dflet | 0:e89ba455dbcf | 421 | /* A special mode where Rx payload and Rx length are used as Tx as well */ |
dflet | 0:e89ba455dbcf | 422 | /* This mode requires no Rx payload on the response and currently used by fs_Close and sl_Send on */ |
dflet | 0:e89ba455dbcf | 423 | /* transceiver mode */ |
dflet | 0:e89ba455dbcf | 424 | if (g_pCB->RelayFlagsViaRxPayload == TRUE ) { |
dflet | 0:e89ba455dbcf | 425 | g_pCB->RelayFlagsViaRxPayload = FALSE; |
dflet | 0:e89ba455dbcf | 426 | _spi.spi_Write(g_pCB->FD, g_pCB->FunctionParams.pCmdExt->pRxPayload, |
dflet | 0:e89ba455dbcf | 427 | _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdExt->RxPayloadLen)); |
dflet | 0:e89ba455dbcf | 428 | } |
dflet | 0:e89ba455dbcf | 429 | |
dflet | 0:e89ba455dbcf | 430 | /* Payload */ |
dflet | 0:e89ba455dbcf | 431 | if (g_pCB->FunctionParams.pCmdExt && g_pCB->FunctionParams.pCmdExt->TxPayloadLen > 0) { |
dflet | 0:e89ba455dbcf | 432 | /* If the message has payload, it is mandatory that the message's arguments are protocol aligned. */ |
dflet | 0:e89ba455dbcf | 433 | /* Otherwise the aligning of arguments will create a gap between arguments and payload. */ |
dflet | 0:e89ba455dbcf | 434 | VERIFY_PROTOCOL(_SL_IS_PROTOCOL_ALIGNED_SIZE(g_pCB->FunctionParams.pCmdCtrl->TxDescLen)); |
dflet | 0:e89ba455dbcf | 435 | |
dflet | 0:e89ba455dbcf | 436 | _spi.spi_Write(g_pCB->FD, g_pCB->FunctionParams.pCmdExt->pTxPayload, |
dflet | 0:e89ba455dbcf | 437 | _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdExt->TxPayloadLen)); |
dflet | 0:e89ba455dbcf | 438 | } |
dflet | 0:e89ba455dbcf | 439 | |
dflet | 0:e89ba455dbcf | 440 | |
dflet | 0:e89ba455dbcf | 441 | _SL_DBG_CNT_INC(MsgCnt.Write); |
dflet | 0:e89ba455dbcf | 442 | |
dflet | 0:e89ba455dbcf | 443 | #ifdef SL_START_WRITE_STAT |
dflet | 0:e89ba455dbcf | 444 | sl_IfEndWriteSequence(g_pCB->FD); |
dflet | 0:e89ba455dbcf | 445 | #endif |
dflet | 0:e89ba455dbcf | 446 | |
dflet | 0:e89ba455dbcf | 447 | return SL_OS_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 448 | } |
dflet | 0:e89ba455dbcf | 449 | |
dflet | 0:e89ba455dbcf | 450 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 451 | /* _SlDrvMsgRead */ |
dflet | 0:e89ba455dbcf | 452 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 453 | _SlReturnVal_t cc3100_driver::_SlDrvMsgRead(void) |
dflet | 0:e89ba455dbcf | 454 | { |
dflet | 0:e89ba455dbcf | 455 | /* alignment for small memory models */ |
dflet | 0:e89ba455dbcf | 456 | union { |
dflet | 0:e89ba455dbcf | 457 | uint8_t TempBuf[_SL_RESP_HDR_SIZE]; |
dflet | 0:e89ba455dbcf | 458 | uint32_t DummyBuf[2]; |
dflet | 0:e89ba455dbcf | 459 | } uBuf; |
dflet | 0:e89ba455dbcf | 460 | |
dflet | 0:e89ba455dbcf | 461 | uint8_t TailBuffer[4]; |
dflet | 0:e89ba455dbcf | 462 | uint16_t LengthToCopy; |
dflet | 0:e89ba455dbcf | 463 | uint16_t AlignedLengthRecv; |
dflet | 0:e89ba455dbcf | 464 | uint8_t AlignSize; |
dflet | 0:e89ba455dbcf | 465 | |
dflet | 0:e89ba455dbcf | 466 | VERIFY_RET_OK(_SlDrvRxHdrRead((uint8_t*)(uBuf.TempBuf), &AlignSize)); |
dflet | 0:e89ba455dbcf | 467 | |
dflet | 0:e89ba455dbcf | 468 | /* 'Init Compelete' message bears no valid FlowControl info */ |
dflet | 0:e89ba455dbcf | 469 | if(SL_OPCODE_DEVICE_INITCOMPLETE != OPCODE(uBuf.TempBuf)) { |
dflet | 0:e89ba455dbcf | 470 | g_pCB->FlowContCB.TxPoolCnt = ((_SlResponseHeader_t *)uBuf.TempBuf)->TxPoolCnt; |
dflet | 0:e89ba455dbcf | 471 | g_pCB->SocketNonBlocking = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketNonBlocking; |
dflet | 0:e89ba455dbcf | 472 | g_pCB->SocketTXFailure = ((_SlResponseHeader_t *)uBuf.TempBuf)->SocketTXFailure; |
dflet | 0:e89ba455dbcf | 473 | |
dflet | 0:e89ba455dbcf | 474 | if(g_pCB->FlowContCB.TxPoolCnt > FLOW_CONT_MIN) { |
dflet | 0:e89ba455dbcf | 475 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjSignal(&g_pCB->FlowContCB.TxSyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE)); |
dflet | 0:e89ba455dbcf | 476 | } |
dflet | 0:e89ba455dbcf | 477 | } |
dflet | 0:e89ba455dbcf | 478 | |
dflet | 0:e89ba455dbcf | 479 | _SlDrvClassifyRxMsg(OPCODE(uBuf.TempBuf)); |
dflet | 0:e89ba455dbcf | 480 | |
dflet | 0:e89ba455dbcf | 481 | switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) { |
dflet | 0:e89ba455dbcf | 482 | case ASYNC_EVT_CLASS: |
dflet | 0:e89ba455dbcf | 483 | |
dflet | 0:e89ba455dbcf | 484 | VERIFY_PROTOCOL(NULL == g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 485 | |
dflet | 0:e89ba455dbcf | 486 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 487 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = g_StatMem.AsyncRespBuf; |
dflet | 0:e89ba455dbcf | 488 | #else |
dflet | 0:e89ba455dbcf | 489 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = sl_Malloc(SL_ASYNC_MAX_MSG_LEN); |
dflet | 0:e89ba455dbcf | 490 | #endif |
dflet | 0:e89ba455dbcf | 491 | MALLOC_OK_CHECK(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 492 | |
dflet | 0:e89ba455dbcf | 493 | memcpy(g_pCB->FunctionParams.AsyncExt.pAsyncBuf, uBuf.TempBuf, _SL_RESP_HDR_SIZE); |
dflet | 0:e89ba455dbcf | 494 | |
dflet | 0:e89ba455dbcf | 495 | /* This is an Async message. Read the rest of it. */ |
dflet | 0:e89ba455dbcf | 496 | if (_SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) <= SL_ASYNC_MAX_PAYLOAD_LEN) { |
dflet | 0:e89ba455dbcf | 497 | AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)); |
dflet | 0:e89ba455dbcf | 498 | } else { |
dflet | 0:e89ba455dbcf | 499 | AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(SL_ASYNC_MAX_PAYLOAD_LEN); |
dflet | 0:e89ba455dbcf | 500 | } |
dflet | 0:e89ba455dbcf | 501 | |
dflet | 0:e89ba455dbcf | 502 | if (RSP_PAYLOAD_LEN(uBuf.TempBuf) > 0) { |
dflet | 0:e89ba455dbcf | 503 | _spi.spi_Read(g_pCB->FD, g_pCB->FunctionParams.AsyncExt.pAsyncBuf + _SL_RESP_HDR_SIZE, AlignedLengthRecv); |
dflet | 0:e89ba455dbcf | 504 | } |
dflet | 0:e89ba455dbcf | 505 | /* In case ASYNC RX buffer length is smaller then the received data length, dump the rest */ |
dflet | 0:e89ba455dbcf | 506 | if ((_SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) > SL_ASYNC_MAX_PAYLOAD_LEN)) { |
dflet | 0:e89ba455dbcf | 507 | AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(RSP_PAYLOAD_LEN(uBuf.TempBuf)) - SL_ASYNC_MAX_PAYLOAD_LEN; |
dflet | 0:e89ba455dbcf | 508 | while (AlignedLengthRecv > 0) { |
dflet | 0:e89ba455dbcf | 509 | _spi.spi_Read(g_pCB->FD,TailBuffer,4); |
dflet | 0:e89ba455dbcf | 510 | AlignedLengthRecv = AlignedLengthRecv - 4; |
dflet | 0:e89ba455dbcf | 511 | } |
dflet | 0:e89ba455dbcf | 512 | } |
dflet | 0:e89ba455dbcf | 513 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 514 | |
dflet | 0:e89ba455dbcf | 515 | if ((SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE == OPCODE(uBuf.TempBuf)) || (SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE_V6 == OPCODE(uBuf.TempBuf)) || (SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE == OPCODE(uBuf.TempBuf))) { |
dflet | 0:e89ba455dbcf | 516 | /* go over the active list if exist to find obj waiting for this Async event */ |
dflet | 0:e89ba455dbcf | 517 | _SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),(((_SocketResponse_t *)(g_pCB->FunctionParams.AsyncExt.pAsyncBuf + _SL_RESP_HDR_SIZE))->sd) & BSD_SOCKET_ID_MASK); |
dflet | 0:e89ba455dbcf | 518 | } else { |
dflet | 0:e89ba455dbcf | 519 | _SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),SL_MAX_SOCKETS); |
dflet | 0:e89ba455dbcf | 520 | } |
dflet | 0:e89ba455dbcf | 521 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 522 | |
dflet | 0:e89ba455dbcf | 523 | break; |
dflet | 0:e89ba455dbcf | 524 | |
dflet | 0:e89ba455dbcf | 525 | case RECV_RESP_CLASS: { |
dflet | 0:e89ba455dbcf | 526 | uint8_t ExpArgSize; /* Expected size of Recv/Recvfrom arguments */ |
dflet | 0:e89ba455dbcf | 527 | |
dflet | 0:e89ba455dbcf | 528 | switch(OPCODE(uBuf.TempBuf)) { |
dflet | 0:e89ba455dbcf | 529 | case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE: |
dflet | 0:e89ba455dbcf | 530 | ExpArgSize = RECVFROM_IPV4_ARGS_SIZE; |
dflet | 0:e89ba455dbcf | 531 | break; |
dflet | 0:e89ba455dbcf | 532 | case SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6: |
dflet | 0:e89ba455dbcf | 533 | ExpArgSize = RECVFROM_IPV6_ARGS_SIZE; |
dflet | 0:e89ba455dbcf | 534 | break; |
dflet | 0:e89ba455dbcf | 535 | default: |
dflet | 0:e89ba455dbcf | 536 | /* SL_OPCODE_SOCKET_RECVASYNCRESPONSE: */ |
dflet | 0:e89ba455dbcf | 537 | ExpArgSize = RECV_ARGS_SIZE; |
dflet | 0:e89ba455dbcf | 538 | } |
dflet | 0:e89ba455dbcf | 539 | |
dflet | 0:e89ba455dbcf | 540 | /* Read first 4 bytes of Recv/Recvfrom response to get SocketId and actual */ |
dflet | 0:e89ba455dbcf | 541 | /* response data length */ |
dflet | 0:e89ba455dbcf | 542 | _spi.spi_Read(g_pCB->FD, &uBuf.TempBuf[4], RECV_ARGS_SIZE); |
dflet | 0:e89ba455dbcf | 543 | |
dflet | 0:e89ba455dbcf | 544 | /* Validate Socket ID and Received Length value. */ |
dflet | 0:e89ba455dbcf | 545 | VERIFY_PROTOCOL((SD(&uBuf.TempBuf[4])& BSD_SOCKET_ID_MASK) < SL_MAX_SOCKETS); |
dflet | 0:e89ba455dbcf | 546 | |
dflet | 0:e89ba455dbcf | 547 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 548 | |
dflet | 0:e89ba455dbcf | 549 | /* go over the active list if exist to find obj waiting for this Async event */ |
dflet | 0:e89ba455dbcf | 550 | VERIFY_RET_OK(_SlFindAndSetActiveObj(OPCODE(uBuf.TempBuf),SD(&uBuf.TempBuf[4]) & BSD_SOCKET_ID_MASK)); |
dflet | 0:e89ba455dbcf | 551 | |
dflet | 0:e89ba455dbcf | 552 | /* Verify data is waited on this socket. The pArgs should have been set by _SlDrvDataReadOp(). */ |
dflet | 0:e89ba455dbcf | 553 | VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData))->pArgs); |
dflet | 0:e89ba455dbcf | 554 | |
dflet | 0:e89ba455dbcf | 555 | memcpy( ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs, &uBuf.TempBuf[4], RECV_ARGS_SIZE); |
dflet | 0:e89ba455dbcf | 556 | |
dflet | 0:e89ba455dbcf | 557 | if(ExpArgSize > RECV_ARGS_SIZE) { |
dflet | 0:e89ba455dbcf | 558 | _spi.spi_Read(g_pCB->FD, |
dflet | 0:e89ba455dbcf | 559 | ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs + RECV_ARGS_SIZE, |
dflet | 0:e89ba455dbcf | 560 | ExpArgSize - RECV_ARGS_SIZE); |
dflet | 0:e89ba455dbcf | 561 | } |
dflet | 0:e89ba455dbcf | 562 | |
dflet | 0:e89ba455dbcf | 563 | /* Here g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pData contains requested(expected) Recv/Recvfrom DataSize. */ |
dflet | 0:e89ba455dbcf | 564 | /* Overwrite requested DataSize with actual one. */ |
dflet | 0:e89ba455dbcf | 565 | /* If error is received, this information will be read from arguments. */ |
dflet | 0:e89ba455dbcf | 566 | if(ACT_DATA_SIZE(&uBuf.TempBuf[4]) > 0) { |
dflet | 0:e89ba455dbcf | 567 | VERIFY_SOCKET_CB(NULL != ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData); |
dflet | 0:e89ba455dbcf | 568 | |
dflet | 0:e89ba455dbcf | 569 | /* Read 4 bytes aligned from interface */ |
dflet | 0:e89ba455dbcf | 570 | /* therefore check the requested length and read only */ |
dflet | 0:e89ba455dbcf | 571 | /* 4 bytes aligned data. The rest unaligned (if any) will be read */ |
dflet | 0:e89ba455dbcf | 572 | /* and copied to a TailBuffer */ |
dflet | 0:e89ba455dbcf | 573 | LengthToCopy = ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (3); |
dflet | 0:e89ba455dbcf | 574 | AlignedLengthRecv = ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (~3); |
dflet | 0:e89ba455dbcf | 575 | if( AlignedLengthRecv >= 4) { |
dflet | 0:e89ba455dbcf | 576 | _spi.spi_Read(g_pCB->FD,((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData,AlignedLengthRecv ); |
dflet | 0:e89ba455dbcf | 577 | } |
dflet | 0:e89ba455dbcf | 578 | /* copy the unaligned part, if any */ |
dflet | 0:e89ba455dbcf | 579 | if( LengthToCopy > 0) { |
dflet | 0:e89ba455dbcf | 580 | _spi.spi_Read(g_pCB->FD,TailBuffer,4); |
dflet | 0:e89ba455dbcf | 581 | /* copy TailBuffer unaligned part (1/2/3 bytes) */ |
dflet | 0:e89ba455dbcf | 582 | memcpy(((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData + AlignedLengthRecv,TailBuffer,LengthToCopy); |
dflet | 0:e89ba455dbcf | 583 | } |
dflet | 0:e89ba455dbcf | 584 | } |
dflet | 0:e89ba455dbcf | 585 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjSignal(&g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE)); |
dflet | 0:e89ba455dbcf | 586 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 587 | } |
dflet | 0:e89ba455dbcf | 588 | break; |
dflet | 0:e89ba455dbcf | 589 | |
dflet | 0:e89ba455dbcf | 590 | case CMD_RESP_CLASS: |
dflet | 0:e89ba455dbcf | 591 | |
dflet | 0:e89ba455dbcf | 592 | /* Some commands pass a maximum arguments size. */ |
dflet | 0:e89ba455dbcf | 593 | /* In this case Driver will send extra dummy patterns to NWP if */ |
dflet | 0:e89ba455dbcf | 594 | /* the response message is smaller than maximum. */ |
dflet | 0:e89ba455dbcf | 595 | /* When RxDescLen is not exact, using RxPayloadLen is forbidden! */ |
dflet | 0:e89ba455dbcf | 596 | /* If such case cannot be avoided - parse message here to detect */ |
dflet | 0:e89ba455dbcf | 597 | /* arguments/payload border. */ |
dflet | 0:e89ba455dbcf | 598 | _spi.spi_Read(g_pCB->FD, g_pCB->FunctionParams.pTxRxDescBuff, _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->RxDescLen)); |
dflet | 0:e89ba455dbcf | 599 | |
dflet | 0:e89ba455dbcf | 600 | if((NULL != g_pCB->FunctionParams.pCmdExt) && (0 != g_pCB->FunctionParams.pCmdExt->RxPayloadLen)) { |
dflet | 0:e89ba455dbcf | 601 | /* Actual size of command's response payload: <msg_payload_len> - <rsp_args_len> */ |
dflet | 0:e89ba455dbcf | 602 | int16_t ActDataSize = RSP_PAYLOAD_LEN(uBuf.TempBuf) - g_pCB->FunctionParams.pCmdCtrl->RxDescLen; |
dflet | 0:e89ba455dbcf | 603 | |
dflet | 0:e89ba455dbcf | 604 | g_pCB->FunctionParams.pCmdExt->ActualRxPayloadLen = ActDataSize; |
dflet | 0:e89ba455dbcf | 605 | |
dflet | 0:e89ba455dbcf | 606 | /* Check that the space prepared by user for the response data is sufficient. */ |
dflet | 0:e89ba455dbcf | 607 | if(ActDataSize <= 0) { |
dflet | 0:e89ba455dbcf | 608 | g_pCB->FunctionParams.pCmdExt->RxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 609 | } else { |
dflet | 0:e89ba455dbcf | 610 | /* In case the user supplied Rx buffer length which is smaller then the received data length, copy according to user length */ |
dflet | 0:e89ba455dbcf | 611 | if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) { |
dflet | 0:e89ba455dbcf | 612 | LengthToCopy = g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (3); |
dflet | 0:e89ba455dbcf | 613 | AlignedLengthRecv = g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3); |
dflet | 0:e89ba455dbcf | 614 | } else { |
dflet | 0:e89ba455dbcf | 615 | LengthToCopy = ActDataSize & (3); |
dflet | 0:e89ba455dbcf | 616 | AlignedLengthRecv = ActDataSize & (~3); |
dflet | 0:e89ba455dbcf | 617 | } |
dflet | 0:e89ba455dbcf | 618 | /* Read 4 bytes aligned from interface */ |
dflet | 0:e89ba455dbcf | 619 | /* therefore check the requested length and read only */ |
dflet | 0:e89ba455dbcf | 620 | /* 4 bytes aligned data. The rest unaligned (if any) will be read */ |
dflet | 0:e89ba455dbcf | 621 | /* and copied to a TailBuffer */ |
dflet | 0:e89ba455dbcf | 622 | |
dflet | 0:e89ba455dbcf | 623 | if( AlignedLengthRecv >= 4) { |
dflet | 0:e89ba455dbcf | 624 | _spi.spi_Read(g_pCB->FD, |
dflet | 0:e89ba455dbcf | 625 | g_pCB->FunctionParams.pCmdExt->pRxPayload, |
dflet | 0:e89ba455dbcf | 626 | AlignedLengthRecv ); |
dflet | 0:e89ba455dbcf | 627 | |
dflet | 0:e89ba455dbcf | 628 | } |
dflet | 0:e89ba455dbcf | 629 | /* copy the unaligned part, if any */ |
dflet | 0:e89ba455dbcf | 630 | if( LengthToCopy > 0) { |
dflet | 0:e89ba455dbcf | 631 | _spi.spi_Read(g_pCB->FD,TailBuffer,4); |
dflet | 0:e89ba455dbcf | 632 | /* copy TailBuffer unaligned part (1/2/3 bytes) */ |
dflet | 0:e89ba455dbcf | 633 | memcpy(g_pCB->FunctionParams.pCmdExt->pRxPayload + AlignedLengthRecv, |
dflet | 0:e89ba455dbcf | 634 | TailBuffer, |
dflet | 0:e89ba455dbcf | 635 | LengthToCopy); |
dflet | 0:e89ba455dbcf | 636 | ActDataSize = ActDataSize-4; |
dflet | 0:e89ba455dbcf | 637 | } |
dflet | 0:e89ba455dbcf | 638 | /* In case the user supplied Rx buffer length which is smaller then the received data length, dump the rest */ |
dflet | 0:e89ba455dbcf | 639 | if (ActDataSize > g_pCB->FunctionParams.pCmdExt->RxPayloadLen) { |
dflet | 0:e89ba455dbcf | 640 | /* calculate the rest of the data size to dump */ |
dflet | 0:e89ba455dbcf | 641 | AlignedLengthRecv = ActDataSize - (g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3)); |
dflet | 0:e89ba455dbcf | 642 | while( AlignedLengthRecv > 0) { |
dflet | 0:e89ba455dbcf | 643 | _spi.spi_Read(g_pCB->FD,TailBuffer, 4 ); |
dflet | 0:e89ba455dbcf | 644 | AlignedLengthRecv = AlignedLengthRecv - 4; |
dflet | 0:e89ba455dbcf | 645 | } |
dflet | 0:e89ba455dbcf | 646 | } |
dflet | 0:e89ba455dbcf | 647 | } |
dflet | 0:e89ba455dbcf | 648 | } |
dflet | 0:e89ba455dbcf | 649 | break; |
dflet | 0:e89ba455dbcf | 650 | |
dflet | 0:e89ba455dbcf | 651 | default: |
dflet | 0:e89ba455dbcf | 652 | /* DUMMY_MSG_CLASS: Flow control message has no payload. */ |
dflet | 0:e89ba455dbcf | 653 | break; |
dflet | 0:e89ba455dbcf | 654 | } |
dflet | 0:e89ba455dbcf | 655 | |
dflet | 0:e89ba455dbcf | 656 | if(AlignSize > 0) { |
dflet | 0:e89ba455dbcf | 657 | _spi.spi_Read(g_pCB->FD, uBuf.TempBuf, AlignSize); |
dflet | 0:e89ba455dbcf | 658 | } |
dflet | 0:e89ba455dbcf | 659 | |
dflet | 0:e89ba455dbcf | 660 | _SL_DBG_CNT_INC(MsgCnt.Read); |
dflet | 0:e89ba455dbcf | 661 | |
dflet | 0:e89ba455dbcf | 662 | /* Unmask Interrupt call */ |
dflet | 0:e89ba455dbcf | 663 | _spi.UnMaskIntHdlr(); |
dflet | 0:e89ba455dbcf | 664 | |
dflet | 0:e89ba455dbcf | 665 | return SL_OS_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 666 | } |
dflet | 0:e89ba455dbcf | 667 | |
dflet | 0:e89ba455dbcf | 668 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 669 | /* _SlAsyncEventGenericHandler */ |
dflet | 0:e89ba455dbcf | 670 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 671 | void cc3100_driver::_SlAsyncEventGenericHandler(void) |
dflet | 0:e89ba455dbcf | 672 | { |
dflet | 0:e89ba455dbcf | 673 | _SlResponseHeader_t *pHdr = (_SlResponseHeader_t *)g_pCB->FunctionParams.AsyncExt.pAsyncBuf; |
dflet | 0:e89ba455dbcf | 674 | SlWlanEvent_t wlanEvent; |
dflet | 0:e89ba455dbcf | 675 | SlNetAppEvent_t netAppEvent; |
dflet | 0:e89ba455dbcf | 676 | SlSockEvent_t sockAppEvent; |
dflet | 0:e89ba455dbcf | 677 | |
dflet | 0:e89ba455dbcf | 678 | if (NULL != g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler) { |
dflet | 0:e89ba455dbcf | 679 | switch(pHdr->GenHeader.Opcode) { |
dflet | 0:e89ba455dbcf | 680 | |
dflet | 0:e89ba455dbcf | 681 | case SL_OPCODE_WLAN_P2P_DEV_FOUND: { |
dflet | 0:e89ba455dbcf | 682 | slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 683 | wlanEvent.Event = SL_WLAN_P2P_DEV_FOUND_EVENT; |
dflet | 0:e89ba455dbcf | 684 | memcpy(wlanEvent.EventData.P2PModeDevFound.mac,pResp->mac, 6); |
dflet | 0:e89ba455dbcf | 685 | memcpy(wlanEvent.EventData.P2PModeDevFound.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 686 | wlanEvent.EventData.P2PModeDevFound.go_peer_device_name_len = pResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 687 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 688 | |
dflet | 0:e89ba455dbcf | 689 | break; |
dflet | 0:e89ba455dbcf | 690 | } |
dflet | 0:e89ba455dbcf | 691 | |
dflet | 0:e89ba455dbcf | 692 | case SL_OPCODE_WLAN_P2P_NEG_REQ_RECEIVED: { |
dflet | 0:e89ba455dbcf | 693 | slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 694 | wlanEvent.Event = SL_WLAN_P2P_NEG_REQ_RECEIVED_EVENT; |
dflet | 0:e89ba455dbcf | 695 | memcpy(wlanEvent.EventData.P2PModeNegReqReceived.mac,pResp->mac, 6); |
dflet | 0:e89ba455dbcf | 696 | memcpy(wlanEvent.EventData.P2PModeNegReqReceived.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 697 | wlanEvent.EventData.P2PModeNegReqReceived.go_peer_device_name_len = pResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 698 | wlanEvent.EventData.P2PModeNegReqReceived.wps_dev_password_id = pResp->wps_dev_password_id; |
dflet | 0:e89ba455dbcf | 699 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 700 | |
dflet | 0:e89ba455dbcf | 701 | break; |
dflet | 0:e89ba455dbcf | 702 | } |
dflet | 0:e89ba455dbcf | 703 | case SL_OPCODE_WLAN_CONNECTION_FAILED: { |
dflet | 0:e89ba455dbcf | 704 | slWlanConnFailureAsyncResponse_t* pResp = (slWlanConnFailureAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 705 | wlanEvent.Event = SL_WLAN_CONNECTION_FAILED_EVENT; |
dflet | 0:e89ba455dbcf | 706 | wlanEvent.EventData.P2PModewlanConnectionFailure.status = pResp->status; |
dflet | 0:e89ba455dbcf | 707 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 708 | |
dflet | 0:e89ba455dbcf | 709 | break; |
dflet | 0:e89ba455dbcf | 710 | } |
dflet | 0:e89ba455dbcf | 711 | |
dflet | 0:e89ba455dbcf | 712 | case SL_OPCODE_WLAN_WLANASYNCCONNECTEDRESPONSE: { |
dflet | 0:e89ba455dbcf | 713 | slWlanConnectAsyncResponse_t *pWlanResp = (slWlanConnectAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 714 | memset(&wlanEvent.EventData.STAandP2PModeWlanConnected,0,sizeof(slWlanConnectAsyncResponse_t)); |
dflet | 0:e89ba455dbcf | 715 | wlanEvent.Event = SL_WLAN_CONNECT_EVENT; |
dflet | 0:e89ba455dbcf | 716 | wlanEvent.EventData.STAandP2PModeWlanConnected.connection_type = pWlanResp->connection_type; |
dflet | 0:e89ba455dbcf | 717 | memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.bssid, pWlanResp->bssid, 6); |
dflet | 0:e89ba455dbcf | 718 | memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.go_peer_device_name,pWlanResp->go_peer_device_name,pWlanResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 719 | memcpy(wlanEvent.EventData.STAandP2PModeWlanConnected.ssid_name, pWlanResp->ssid_name, pWlanResp->ssid_len); |
dflet | 0:e89ba455dbcf | 720 | wlanEvent.EventData.STAandP2PModeWlanConnected.ssid_len = pWlanResp->ssid_len; |
dflet | 0:e89ba455dbcf | 721 | wlanEvent.EventData.STAandP2PModeWlanConnected.go_peer_device_name_len = pWlanResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 722 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 723 | |
dflet | 0:e89ba455dbcf | 724 | break; |
dflet | 0:e89ba455dbcf | 725 | } |
dflet | 0:e89ba455dbcf | 726 | case SL_OPCODE_WLAN_WLANASYNCDISCONNECTEDRESPONSE: { |
dflet | 0:e89ba455dbcf | 727 | slWlanConnectAsyncResponse_t *pWlanResp = (slWlanConnectAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 728 | memset(&wlanEvent.EventData.STAandP2PModeDisconnected,0,sizeof(slWlanConnectAsyncResponse_t)); |
dflet | 0:e89ba455dbcf | 729 | wlanEvent.Event = SL_WLAN_DISCONNECT_EVENT; |
dflet | 0:e89ba455dbcf | 730 | wlanEvent.EventData.STAandP2PModeDisconnected.connection_type = pWlanResp->connection_type; |
dflet | 0:e89ba455dbcf | 731 | memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.bssid, pWlanResp->bssid, 6); |
dflet | 0:e89ba455dbcf | 732 | memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.go_peer_device_name,pWlanResp->go_peer_device_name,pWlanResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 733 | memcpy(wlanEvent.EventData.STAandP2PModeDisconnected.ssid_name, pWlanResp->ssid_name, pWlanResp->ssid_len); |
dflet | 0:e89ba455dbcf | 734 | wlanEvent.EventData.STAandP2PModeDisconnected.ssid_len = pWlanResp->ssid_len; |
dflet | 0:e89ba455dbcf | 735 | wlanEvent.EventData.STAandP2PModeDisconnected.reason_code = pWlanResp->reason_code; |
dflet | 0:e89ba455dbcf | 736 | wlanEvent.EventData.STAandP2PModeDisconnected.go_peer_device_name_len = pWlanResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 737 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 738 | |
dflet | 0:e89ba455dbcf | 739 | break; |
dflet | 0:e89ba455dbcf | 740 | } |
dflet | 0:e89ba455dbcf | 741 | case SL_OPCODE_NETAPP_IPACQUIRED: { |
dflet | 0:e89ba455dbcf | 742 | SlIpV4AcquiredAsync_t *pIpV4 = (SlIpV4AcquiredAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 743 | netAppEvent.Event = SL_NETAPP_IPV4_IPACQUIRED_EVENT; |
dflet | 0:e89ba455dbcf | 744 | netAppEvent.EventData.ipAcquiredV4.ip = pIpV4->ip; |
dflet | 0:e89ba455dbcf | 745 | netAppEvent.EventData.ipAcquiredV4.gateway = pIpV4->gateway; |
dflet | 0:e89ba455dbcf | 746 | netAppEvent.EventData.ipAcquiredV4.dns = pIpV4->dns; |
dflet | 0:e89ba455dbcf | 747 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler((SlNetAppEvent_t*)&netAppEvent); |
dflet | 0:e89ba455dbcf | 748 | |
dflet | 0:e89ba455dbcf | 749 | } |
dflet | 0:e89ba455dbcf | 750 | break; |
dflet | 0:e89ba455dbcf | 751 | case SL_OPCODE_NETAPP_IPACQUIRED_V6: { |
dflet | 0:e89ba455dbcf | 752 | SlIpV6AcquiredAsync_t *pIpV6 = (SlIpV6AcquiredAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 753 | netAppEvent.Event = SL_NETAPP_IPV6_IPACQUIRED_EVENT; |
dflet | 0:e89ba455dbcf | 754 | memcpy((void *)&netAppEvent.EventData.ipAcquiredV6.ip[0],(void *)&pIpV6->ip[0],sizeof(pIpV6->ip[0])*4); |
dflet | 0:e89ba455dbcf | 755 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); |
dflet | 0:e89ba455dbcf | 756 | |
dflet | 0:e89ba455dbcf | 757 | } |
dflet | 0:e89ba455dbcf | 758 | break; |
dflet | 0:e89ba455dbcf | 759 | |
dflet | 0:e89ba455dbcf | 760 | case SL_OPCODE_NETAPP_IP_LEASED: { |
dflet | 0:e89ba455dbcf | 761 | SlIpLeasedAsync_t *pIpV4 = (SlIpLeasedAsync_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 762 | netAppEvent.Event = SL_NETAPP_IP_LEASED_EVENT; |
dflet | 0:e89ba455dbcf | 763 | netAppEvent.EventData.ipLeased.ip_address = pIpV4->ip_address; |
dflet | 0:e89ba455dbcf | 764 | netAppEvent.EventData.ipLeased.lease_time = pIpV4->lease_time; |
dflet | 0:e89ba455dbcf | 765 | memcpy(netAppEvent.EventData.ipLeased.mac, pIpV4->mac, 6); |
dflet | 0:e89ba455dbcf | 766 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); |
dflet | 0:e89ba455dbcf | 767 | } |
dflet | 0:e89ba455dbcf | 768 | break; |
dflet | 0:e89ba455dbcf | 769 | |
dflet | 0:e89ba455dbcf | 770 | case SL_OPCODE_NETAPP_IP_RELEASED: { |
dflet | 0:e89ba455dbcf | 771 | SlIpReleasedAsync_t *pIpV4 = (SlIpReleasedAsync_t *)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 772 | netAppEvent.Event = SL_NETAPP_IP_RELEASED_EVENT; |
dflet | 0:e89ba455dbcf | 773 | netAppEvent.EventData.ipReleased.ip_address = pIpV4->ip_address; |
dflet | 0:e89ba455dbcf | 774 | netAppEvent.EventData.ipReleased.reason = pIpV4->reason; |
dflet | 0:e89ba455dbcf | 775 | memcpy(netAppEvent.EventData.ipReleased.mac, pIpV4->mac, 6); |
dflet | 0:e89ba455dbcf | 776 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&netAppEvent); |
dflet | 0:e89ba455dbcf | 777 | } |
dflet | 0:e89ba455dbcf | 778 | break; |
dflet | 0:e89ba455dbcf | 779 | |
dflet | 0:e89ba455dbcf | 780 | case SL_OPCODE_SOCKET_TXFAILEDASYNCRESPONSE: { |
dflet | 0:e89ba455dbcf | 781 | SlSockEventData_t *txfailparams = (SlSockEventData_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 782 | sockAppEvent.Event = SL_SOCKET_TX_FAILED_EVENT; |
dflet | 0:e89ba455dbcf | 783 | memcpy((void *)&sockAppEvent.EventData,(void *)txfailparams,sizeof(SlSockEventData_t)); |
dflet | 0:e89ba455dbcf | 784 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&sockAppEvent); |
dflet | 0:e89ba455dbcf | 785 | |
dflet | 0:e89ba455dbcf | 786 | } |
dflet | 0:e89ba455dbcf | 787 | break; |
dflet | 0:e89ba455dbcf | 788 | |
dflet | 0:e89ba455dbcf | 789 | case SL_OPCODE_SOCKET_SOCKETASYNCEVENT: { |
dflet | 0:e89ba455dbcf | 790 | SlSockEventData_t *socketAsyncEvent = (SlSockEventData_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 791 | sockAppEvent.Event = SL_SOCKET_ASYNC_EVENT; |
dflet | 0:e89ba455dbcf | 792 | sockAppEvent.EventData.socketAsyncEvent.sd = socketAsyncEvent->socketAsyncEvent.sd; |
dflet | 0:e89ba455dbcf | 793 | sockAppEvent.EventData.socketAsyncEvent.type = socketAsyncEvent->socketAsyncEvent.type; /* one of the possible types of socket */ |
dflet | 0:e89ba455dbcf | 794 | sockAppEvent.EventData.socketAsyncEvent.val = socketAsyncEvent->socketAsyncEvent.val; |
dflet | 0:e89ba455dbcf | 795 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&sockAppEvent); |
dflet | 0:e89ba455dbcf | 796 | |
dflet | 0:e89ba455dbcf | 797 | } |
dflet | 0:e89ba455dbcf | 798 | break; |
dflet | 0:e89ba455dbcf | 799 | |
dflet | 0:e89ba455dbcf | 800 | case SL_OPCODE_WLAN_SMART_CONFIG_START_ASYNC_RESPONSE: { |
dflet | 0:e89ba455dbcf | 801 | slSmartConfigStartAsyncResponse_t *pResp = (slSmartConfigStartAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 802 | |
dflet | 0:e89ba455dbcf | 803 | wlanEvent.Event = SL_WLAN_SMART_CONFIG_COMPLETE_EVENT; |
dflet | 0:e89ba455dbcf | 804 | wlanEvent.EventData.smartConfigStartResponse.status = pResp->status; |
dflet | 0:e89ba455dbcf | 805 | wlanEvent.EventData.smartConfigStartResponse.ssid_len = pResp->ssid_len; |
dflet | 0:e89ba455dbcf | 806 | wlanEvent.EventData.smartConfigStartResponse.private_token_len = pResp->private_token_len; |
dflet | 0:e89ba455dbcf | 807 | memset(wlanEvent.EventData.smartConfigStartResponse.ssid, 0x00, sizeof(wlanEvent.EventData.smartConfigStartResponse.ssid)); |
dflet | 0:e89ba455dbcf | 808 | memcpy(wlanEvent.EventData.smartConfigStartResponse.ssid, pResp->ssid, pResp->ssid_len); |
dflet | 0:e89ba455dbcf | 809 | /* if private data exist */ |
dflet | 0:e89ba455dbcf | 810 | if (pResp->private_token_len) { |
dflet | 0:e89ba455dbcf | 811 | memset(wlanEvent.EventData.smartConfigStartResponse.private_token, 0x00, sizeof(wlanEvent.EventData.smartConfigStartResponse.private_token)); |
dflet | 0:e89ba455dbcf | 812 | memcpy(wlanEvent.EventData.smartConfigStartResponse.private_token, pResp->private_token, pResp->private_token_len); |
dflet | 0:e89ba455dbcf | 813 | } |
dflet | 0:e89ba455dbcf | 814 | |
dflet | 0:e89ba455dbcf | 815 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 816 | } |
dflet | 0:e89ba455dbcf | 817 | break; |
dflet | 0:e89ba455dbcf | 818 | |
dflet | 0:e89ba455dbcf | 819 | case SL_OPCODE_WLAN_SMART_CONFIG_STOP_ASYNC_RESPONSE: { |
dflet | 0:e89ba455dbcf | 820 | slSmartConfigStopAsyncResponse_t *pResp = (slSmartConfigStopAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 821 | wlanEvent.Event = SL_WLAN_SMART_CONFIG_STOP_EVENT; |
dflet | 0:e89ba455dbcf | 822 | wlanEvent.EventData.smartConfigStopResponse.status = pResp->status; |
dflet | 0:e89ba455dbcf | 823 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 824 | |
dflet | 0:e89ba455dbcf | 825 | } |
dflet | 0:e89ba455dbcf | 826 | break; |
dflet | 0:e89ba455dbcf | 827 | |
dflet | 0:e89ba455dbcf | 828 | case SL_OPCODE_WLAN_STA_CONNECTED: { |
dflet | 0:e89ba455dbcf | 829 | slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 830 | memset(&wlanEvent.EventData.APModeStaConnected,0,sizeof(slPeerInfoAsyncResponse_t)); |
dflet | 0:e89ba455dbcf | 831 | wlanEvent.Event = SL_WLAN_STA_CONNECTED_EVENT; |
dflet | 0:e89ba455dbcf | 832 | memcpy(wlanEvent.EventData.APModeStaConnected.mac,pResp->mac, 6); |
dflet | 0:e89ba455dbcf | 833 | memcpy(wlanEvent.EventData.APModeStaConnected.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 834 | wlanEvent.EventData.APModeStaConnected.go_peer_device_name_len = pResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 835 | memcpy(wlanEvent.EventData.APModeStaConnected.own_ssid,pResp->own_ssid,pResp->own_ssid_len); |
dflet | 0:e89ba455dbcf | 836 | wlanEvent.EventData.APModeStaConnected.own_ssid_len = pResp->own_ssid_len; |
dflet | 0:e89ba455dbcf | 837 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 838 | |
dflet | 0:e89ba455dbcf | 839 | } |
dflet | 0:e89ba455dbcf | 840 | break; |
dflet | 0:e89ba455dbcf | 841 | |
dflet | 0:e89ba455dbcf | 842 | case SL_OPCODE_WLAN_STA_DISCONNECTED: { |
dflet | 0:e89ba455dbcf | 843 | slPeerInfoAsyncResponse_t* pResp = (slPeerInfoAsyncResponse_t*)_SL_RESP_ARGS_START(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 844 | memset(&wlanEvent.EventData.APModestaDisconnected,0,sizeof(slPeerInfoAsyncResponse_t)); |
dflet | 0:e89ba455dbcf | 845 | wlanEvent.Event = SL_WLAN_STA_DISCONNECTED_EVENT; |
dflet | 0:e89ba455dbcf | 846 | memcpy(wlanEvent.EventData.APModestaDisconnected.mac,pResp->mac, 6); |
dflet | 0:e89ba455dbcf | 847 | memcpy(wlanEvent.EventData.APModestaDisconnected.go_peer_device_name,pResp->go_peer_device_name,pResp->go_peer_device_name_len); |
dflet | 0:e89ba455dbcf | 848 | wlanEvent.EventData.APModestaDisconnected.go_peer_device_name_len = pResp->go_peer_device_name_len; |
dflet | 0:e89ba455dbcf | 849 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(&wlanEvent); |
dflet | 0:e89ba455dbcf | 850 | } |
dflet | 0:e89ba455dbcf | 851 | break; |
dflet | 0:e89ba455dbcf | 852 | |
dflet | 0:e89ba455dbcf | 853 | case SL_OPCODE_NETAPP_PINGREPORTREQUESTRESPONSE: { |
dflet | 0:e89ba455dbcf | 854 | _sl_HandleAsync_PingResponse((void *)g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 855 | } |
dflet | 0:e89ba455dbcf | 856 | break; |
dflet | 0:e89ba455dbcf | 857 | |
dflet | 0:e89ba455dbcf | 858 | |
dflet | 0:e89ba455dbcf | 859 | default: |
dflet | 0:e89ba455dbcf | 860 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 861 | break; |
dflet | 0:e89ba455dbcf | 862 | } |
dflet | 0:e89ba455dbcf | 863 | } |
dflet | 0:e89ba455dbcf | 864 | } |
dflet | 0:e89ba455dbcf | 865 | |
dflet | 0:e89ba455dbcf | 866 | |
dflet | 0:e89ba455dbcf | 867 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 868 | /* _SlDrvMsgReadCmdCtx */ |
dflet | 0:e89ba455dbcf | 869 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 870 | _SlReturnVal_t cc3100_driver::_SlDrvMsgReadCmdCtx(void) |
dflet | 0:e89ba455dbcf | 871 | { |
dflet | 0:e89ba455dbcf | 872 | |
dflet | 0:e89ba455dbcf | 873 | /* after command response is received and isCmdRespWaited */ |
dflet | 0:e89ba455dbcf | 874 | /* flag is set FALSE, it is necessary to read out all */ |
dflet | 0:e89ba455dbcf | 875 | /* Async messages in Commands context, because ssiDma_IsrHandleSignalFromSlave */ |
dflet | 0:e89ba455dbcf | 876 | /* could have dispatched some Async messages to g_NwpIf.CmdSyncObj */ |
dflet | 0:e89ba455dbcf | 877 | /* after command response but before this response has been processed */ |
dflet | 0:e89ba455dbcf | 878 | /* by spi_singleRead and isCmdRespWaited was set FALSE. */ |
dflet | 0:e89ba455dbcf | 879 | |
dflet | 0:e89ba455dbcf | 880 | while (TRUE == g_pCB->IsCmdRespWaited) { |
dflet | 0:e89ba455dbcf | 881 | |
dflet | 0:e89ba455dbcf | 882 | if(_SL_PENDING_RX_MSG(g_pCB)) { |
dflet | 0:e89ba455dbcf | 883 | |
dflet | 2:b3fd5b3d9860 | 884 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;/* buffer must be allocated by _SlDrvMsgRead */ |
dflet | 2:b3fd5b3d9860 | 885 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = NULL; |
dflet | 0:e89ba455dbcf | 886 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = (_SlRxMsgClass_e)(-1);/* init to illegal value and verify it's overwritten with the valid one */ |
dflet | 0:e89ba455dbcf | 887 | |
dflet | 0:e89ba455dbcf | 888 | VERIFY_RET_OK(_SlDrvMsgRead()); |
dflet | 0:e89ba455dbcf | 889 | g_pCB->RxDoneCnt++; |
dflet | 0:e89ba455dbcf | 890 | |
dflet | 0:e89ba455dbcf | 891 | if (CMD_RESP_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) { |
dflet | 0:e89ba455dbcf | 892 | g_pCB->IsCmdRespWaited = FALSE; |
dflet | 0:e89ba455dbcf | 893 | |
dflet | 0:e89ba455dbcf | 894 | /* In case CmdResp has been read without waiting on CmdSyncObj - that */ |
dflet | 0:e89ba455dbcf | 895 | /* Sync object. That to prevent old signal to be processed. */ |
dflet | 0:e89ba455dbcf | 896 | _nonos.sl_SyncObjClear(&g_pCB->CmdSyncObj); |
dflet | 0:e89ba455dbcf | 897 | } else if (ASYNC_EVT_CLASS == g_pCB->FunctionParams.AsyncExt.RxMsgClass) { |
dflet | 0:e89ba455dbcf | 898 | /* If Async event has been read in CmdResp context, check whether */ |
dflet | 0:e89ba455dbcf | 899 | /* there is a handler for this event. If there is, spawn specific */ |
dflet | 0:e89ba455dbcf | 900 | /* handler. Otherwise free the event's buffer. */ |
dflet | 0:e89ba455dbcf | 901 | /* This way there will be no "dry shots" from CmdResp context to */ |
dflet | 0:e89ba455dbcf | 902 | /* temporary context, i.e less waste of CPU and faster buffer */ |
dflet | 0:e89ba455dbcf | 903 | /* release. */ |
dflet | 0:e89ba455dbcf | 904 | _SlAsyncEventGenericHandler(); |
dflet | 0:e89ba455dbcf | 905 | |
dflet | 0:e89ba455dbcf | 906 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 907 | |
dflet | 0:e89ba455dbcf | 908 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; |
dflet | 0:e89ba455dbcf | 909 | #else |
dflet | 0:e89ba455dbcf | 910 | free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 911 | #endif |
dflet | 0:e89ba455dbcf | 912 | } |
dflet | 0:e89ba455dbcf | 913 | } else { |
dflet | 0:e89ba455dbcf | 914 | /* CmdSyncObj will be signaled by IRQ */ |
dflet | 0:e89ba455dbcf | 915 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjWait(&g_pCB->CmdSyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE, NON_OS_SYNC_OBJ_CLEAR_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 916 | } |
dflet | 0:e89ba455dbcf | 917 | } |
dflet | 0:e89ba455dbcf | 918 | |
dflet | 0:e89ba455dbcf | 919 | /* If there are more pending Rx Msgs after CmdResp is received, */ |
dflet | 0:e89ba455dbcf | 920 | /* that means that these are Async, Dummy or Read Data Msgs. */ |
dflet | 0:e89ba455dbcf | 921 | /* Spawn _SlDrvMsgReadSpawnCtx to trigger reading these messages from */ |
dflet | 0:e89ba455dbcf | 922 | /* Temporary context. */ |
dflet | 0:e89ba455dbcf | 923 | /* sl_Spawn is activated, using a different context */ |
dflet | 0:e89ba455dbcf | 924 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 925 | |
dflet | 0:e89ba455dbcf | 926 | if(_SL_PENDING_RX_MSG(g_pCB)) { |
dflet | 0:e89ba455dbcf | 927 | _nonos._SlNonOsSpawn((_SlSpawnEntryFunc_t)&_SlDrvMsgReadSpawnCtx, NULL, 0); |
dflet | 0:e89ba455dbcf | 928 | } |
dflet | 0:e89ba455dbcf | 929 | |
dflet | 0:e89ba455dbcf | 930 | return SL_OS_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 931 | } |
dflet | 0:e89ba455dbcf | 932 | |
dflet | 0:e89ba455dbcf | 933 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 934 | /* _SlDrvMsgReadSpawnCtx */ |
dflet | 0:e89ba455dbcf | 935 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 936 | |
dflet | 0:e89ba455dbcf | 937 | _SlReturnVal_t cc3100_driver::_SlDrvMsgReadSpawnCtx_(void *pValue) |
dflet | 0:e89ba455dbcf | 938 | { |
dflet | 0:e89ba455dbcf | 939 | |
dflet | 0:e89ba455dbcf | 940 | #ifdef SL_POLLING_MODE_USED |
dflet | 0:e89ba455dbcf | 941 | int16_t retCode = OSI_OK; |
dflet | 0:e89ba455dbcf | 942 | // for polling based systems |
dflet | 0:e89ba455dbcf | 943 | do { |
dflet | 0:e89ba455dbcf | 944 | retCode = sl_LockObjLock(&g_pCB->GlobalLockObj, 0); |
dflet | 0:e89ba455dbcf | 945 | if ( OSI_OK != retCode ) { |
dflet | 0:e89ba455dbcf | 946 | if (TRUE == g_pCB->IsCmdRespWaited) { |
dflet | 0:e89ba455dbcf | 947 | OSI_RET_OK_CHECK( sl_SyncObjSignal(&g_pCB->CmdSyncObj) ); |
dflet | 0:e89ba455dbcf | 948 | return SL_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 949 | } |
dflet | 0:e89ba455dbcf | 950 | } |
dflet | 0:e89ba455dbcf | 951 | |
dflet | 0:e89ba455dbcf | 952 | } while (OSI_OK != retCode); |
dflet | 0:e89ba455dbcf | 953 | |
dflet | 0:e89ba455dbcf | 954 | #else |
dflet | 0:e89ba455dbcf | 955 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER) ); |
dflet | 0:e89ba455dbcf | 956 | #endif |
dflet | 0:e89ba455dbcf | 957 | |
dflet | 0:e89ba455dbcf | 958 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL;// buffer must be allocated by _SlDrvMsgRead |
dflet | 0:e89ba455dbcf | 959 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = NULL; |
dflet | 0:e89ba455dbcf | 960 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS;// init to illegal value and verify it's overwritten with the valid one |
dflet | 0:e89ba455dbcf | 961 | |
dflet | 0:e89ba455dbcf | 962 | // Messages might have been read by CmdResp context. Therefore after |
dflet | 0:e89ba455dbcf | 963 | // getting LockObj, check again where the Pending Rx Msg is still present. |
dflet | 0:e89ba455dbcf | 964 | if(FALSE == (_SL_PENDING_RX_MSG(g_pCB))) { |
dflet | 0:e89ba455dbcf | 965 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 966 | return SL_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 967 | } |
dflet | 0:e89ba455dbcf | 968 | |
dflet | 0:e89ba455dbcf | 969 | VERIFY_RET_OK(_SlDrvMsgRead()); |
dflet | 0:e89ba455dbcf | 970 | |
dflet | 0:e89ba455dbcf | 971 | g_pCB->RxDoneCnt++; |
dflet | 0:e89ba455dbcf | 972 | |
dflet | 0:e89ba455dbcf | 973 | switch(g_pCB->FunctionParams.AsyncExt.RxMsgClass) { |
dflet | 0:e89ba455dbcf | 974 | case ASYNC_EVT_CLASS: |
dflet | 0:e89ba455dbcf | 975 | // If got here and protected by LockObj a message is waiting |
dflet | 0:e89ba455dbcf | 976 | // to be read |
dflet | 0:e89ba455dbcf | 977 | VERIFY_PROTOCOL(NULL != g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 978 | |
dflet | 0:e89ba455dbcf | 979 | _SlAsyncEventGenericHandler(); |
dflet | 0:e89ba455dbcf | 980 | |
dflet | 0:e89ba455dbcf | 981 | #if (SL_MEMORY_MGMT == SL_MEMORY_MGMT_STATIC) |
dflet | 0:e89ba455dbcf | 982 | g_pCB->FunctionParams.AsyncExt.pAsyncBuf = NULL; |
dflet | 0:e89ba455dbcf | 983 | #else |
dflet | 0:e89ba455dbcf | 984 | sl_Free(g_pCB->FunctionParams.AsyncExt.pAsyncBuf); |
dflet | 0:e89ba455dbcf | 985 | #endif |
dflet | 0:e89ba455dbcf | 986 | break; |
dflet | 0:e89ba455dbcf | 987 | case DUMMY_MSG_CLASS: |
dflet | 0:e89ba455dbcf | 988 | case RECV_RESP_CLASS: |
dflet | 0:e89ba455dbcf | 989 | // These types are legal in this context. Do nothing |
dflet | 0:e89ba455dbcf | 990 | break; |
dflet | 0:e89ba455dbcf | 991 | case CMD_RESP_CLASS: |
dflet | 0:e89ba455dbcf | 992 | // Command response is illegal in this context. |
dflet | 0:e89ba455dbcf | 993 | // No 'break' here: Assert! |
dflet | 0:e89ba455dbcf | 994 | default: |
dflet | 0:e89ba455dbcf | 995 | VERIFY_PROTOCOL(0); |
dflet | 0:e89ba455dbcf | 996 | } |
dflet | 0:e89ba455dbcf | 997 | |
dflet | 0:e89ba455dbcf | 998 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->GlobalLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 999 | |
dflet | 0:e89ba455dbcf | 1000 | return(SL_RET_CODE_OK); |
dflet | 0:e89ba455dbcf | 1001 | } |
dflet | 0:e89ba455dbcf | 1002 | |
dflet | 0:e89ba455dbcf | 1003 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1004 | /* _SlDrvClassifyRxMsg */ |
dflet | 0:e89ba455dbcf | 1005 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1006 | void cc3100_driver::_SlDrvClassifyRxMsg(_SlOpcode_t Opcode) |
dflet | 0:e89ba455dbcf | 1007 | { |
dflet | 0:e89ba455dbcf | 1008 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = NULL; |
dflet | 0:e89ba455dbcf | 1009 | |
dflet | 0:e89ba455dbcf | 1010 | |
dflet | 0:e89ba455dbcf | 1011 | /* Async event has received */ |
dflet | 0:e89ba455dbcf | 1012 | if (0 == (SL_OPCODE_SYNC & Opcode)) { |
dflet | 0:e89ba455dbcf | 1013 | if (SL_OPCODE_DEVICE_DEVICEASYNCDUMMY == Opcode) { |
dflet | 0:e89ba455dbcf | 1014 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = DUMMY_MSG_CLASS; |
dflet | 0:e89ba455dbcf | 1015 | } else if ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) ) { |
dflet | 0:e89ba455dbcf | 1016 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = RECV_RESP_CLASS; |
dflet | 0:e89ba455dbcf | 1017 | } else { |
dflet | 0:e89ba455dbcf | 1018 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = ASYNC_EVT_CLASS; |
dflet | 0:e89ba455dbcf | 1019 | |
dflet | 0:e89ba455dbcf | 1020 | /* set silo handler */ |
dflet | 0:e89ba455dbcf | 1021 | if (SL_OPCODE_SILO_DEVICE == (Opcode & SL_OPCODE_SILO_MASK)) { |
dflet | 0:e89ba455dbcf | 1022 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)&_SlDrvDeviceEventHandler; |
dflet | 0:e89ba455dbcf | 1023 | } else if (SL_OPCODE_SILO_WLAN == (Opcode & SL_OPCODE_SILO_MASK)) { |
dflet | 0:e89ba455dbcf | 1024 | #ifdef sl_WlanEvtHdlr |
dflet | 0:e89ba455dbcf | 1025 | |
dflet | 0:e89ba455dbcf | 1026 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)&sl_WlanEvtHdlr; |
dflet | 0:e89ba455dbcf | 1027 | #endif |
dflet | 0:e89ba455dbcf | 1028 | } else if (SL_OPCODE_SILO_SOCKET == (Opcode & SL_OPCODE_SILO_MASK)) { |
dflet | 0:e89ba455dbcf | 1029 | |
dflet | 0:e89ba455dbcf | 1030 | #ifdef sl_SockEvtHdlr |
dflet | 0:e89ba455dbcf | 1031 | |
dflet | 0:e89ba455dbcf | 1032 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)&sl_SockEvtHdlr; |
dflet | 0:e89ba455dbcf | 1033 | #endif |
dflet | 0:e89ba455dbcf | 1034 | } else if (SL_OPCODE_SILO_NETAPP == (Opcode & SL_OPCODE_SILO_MASK)) { |
dflet | 0:e89ba455dbcf | 1035 | |
dflet | 0:e89ba455dbcf | 1036 | if ((SL_OPCODE_NETAPP_HTTPGETTOKENVALUE == Opcode) || (SL_OPCODE_NETAPP_HTTPPOSTTOKENVALUE == Opcode)) { |
dflet | 0:e89ba455dbcf | 1037 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)&_SlDrvNetAppEventHandler; |
dflet | 0:e89ba455dbcf | 1038 | } |
dflet | 0:e89ba455dbcf | 1039 | #ifdef sl_NetAppEvtHdlr |
dflet | 0:e89ba455dbcf | 1040 | else { |
dflet | 0:e89ba455dbcf | 1041 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = (_SlSpawnEntryFunc_t)&sl_NetAppEvtHdlr; |
dflet | 0:e89ba455dbcf | 1042 | } |
dflet | 0:e89ba455dbcf | 1043 | #endif |
dflet | 0:e89ba455dbcf | 1044 | } |
dflet | 0:e89ba455dbcf | 1045 | /* else if (SL_OPCODE_SILO_NVMEM == (Opcode & SL_OPCODE_SILO_MASK)) */ |
dflet | 0:e89ba455dbcf | 1046 | /* { */ |
dflet | 0:e89ba455dbcf | 1047 | /* } */ |
dflet | 0:e89ba455dbcf | 1048 | /* else if (SL_OPCODE_SILO_NETCFG == (Opcode & SL_OPCODE_SILO_MASK)) */ |
dflet | 0:e89ba455dbcf | 1049 | /* { */ |
dflet | 0:e89ba455dbcf | 1050 | /* } */ |
dflet | 0:e89ba455dbcf | 1051 | else { |
dflet | 2:b3fd5b3d9860 | 1052 | SL_ERROR_TRACE2(MSG_311, "ASSERT: _SlDrvClassifyRxMsg : invalid opcode = 0x%x = %i", Opcode, Opcode); |
dflet | 0:e89ba455dbcf | 1053 | } |
dflet | 0:e89ba455dbcf | 1054 | } |
dflet | 0:e89ba455dbcf | 1055 | } else { |
dflet | 0:e89ba455dbcf | 1056 | /* These may be Command responses only */ |
dflet | 0:e89ba455dbcf | 1057 | g_pCB->FunctionParams.AsyncExt.RxMsgClass = CMD_RESP_CLASS; |
dflet | 0:e89ba455dbcf | 1058 | } |
dflet | 0:e89ba455dbcf | 1059 | } |
dflet | 0:e89ba455dbcf | 1060 | |
dflet | 0:e89ba455dbcf | 1061 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1062 | /* _SlDrvShiftDWord */ |
dflet | 0:e89ba455dbcf | 1063 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1064 | void cc3100_driver::_SlDrvShiftDWord(uint8_t *pBuf) |
dflet | 0:e89ba455dbcf | 1065 | { |
dflet | 0:e89ba455dbcf | 1066 | uint8_t ShiftIdx; |
dflet | 0:e89ba455dbcf | 1067 | for(ShiftIdx = 0; ShiftIdx< 7; ShiftIdx++) { |
dflet | 0:e89ba455dbcf | 1068 | pBuf[ShiftIdx] = pBuf[ShiftIdx+1]; |
dflet | 0:e89ba455dbcf | 1069 | } |
dflet | 0:e89ba455dbcf | 1070 | pBuf[7] = 0; |
dflet | 0:e89ba455dbcf | 1071 | } |
dflet | 0:e89ba455dbcf | 1072 | |
dflet | 0:e89ba455dbcf | 1073 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1074 | /* _SlDrvRxHdrRead */ |
dflet | 0:e89ba455dbcf | 1075 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1076 | _SlReturnVal_t cc3100_driver::_SlDrvRxHdrRead(uint8_t *pBuf, uint8_t *pAlignSize) |
dflet | 0:e89ba455dbcf | 1077 | { |
dflet | 0:e89ba455dbcf | 1078 | uint32_t SyncCnt = 0; |
dflet | 0:e89ba455dbcf | 1079 | |
dflet | 0:e89ba455dbcf | 1080 | #ifndef SL_IF_TYPE_UART |
dflet | 0:e89ba455dbcf | 1081 | /* 1. Write CNYS pattern to NWP when working in SPI mode only */ |
dflet | 0:e89ba455dbcf | 1082 | _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN); |
dflet | 0:e89ba455dbcf | 1083 | #endif |
dflet | 0:e89ba455dbcf | 1084 | |
dflet | 0:e89ba455dbcf | 1085 | /* 2. Read 4 bytes (protocol aligned) */ |
dflet | 0:e89ba455dbcf | 1086 | _spi.spi_Read(g_pCB->FD, &pBuf[0], 4); |
dflet | 0:e89ba455dbcf | 1087 | _SL_DBG_SYNC_LOG(SyncCnt,pBuf); |
dflet | 0:e89ba455dbcf | 1088 | |
dflet | 0:e89ba455dbcf | 1089 | /* Wait for SYNC_PATTERN_LEN from the device */ |
dflet | 0:e89ba455dbcf | 1090 | while ( ! N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) { |
dflet | 0:e89ba455dbcf | 1091 | /* 3. Debug limit of scan */ |
dflet | 0:e89ba455dbcf | 1092 | VERIFY_PROTOCOL(SyncCnt < SL_SYNC_SCAN_THRESHOLD); |
dflet | 0:e89ba455dbcf | 1093 | |
dflet | 0:e89ba455dbcf | 1094 | /* 4. Read next 4 bytes to Low 4 bytes of buffer */ |
dflet | 0:e89ba455dbcf | 1095 | if(0 == (SyncCnt % (uint32_t)SYNC_PATTERN_LEN)) { |
dflet | 0:e89ba455dbcf | 1096 | _spi.spi_Read(g_pCB->FD, &pBuf[4], 4); |
dflet | 0:e89ba455dbcf | 1097 | _SL_DBG_SYNC_LOG(SyncCnt,pBuf); |
dflet | 0:e89ba455dbcf | 1098 | } |
dflet | 0:e89ba455dbcf | 1099 | |
dflet | 0:e89ba455dbcf | 1100 | /* 5. Shift Buffer Up for checking if the sync is shifted */ |
dflet | 0:e89ba455dbcf | 1101 | _SlDrvShiftDWord(pBuf); |
dflet | 0:e89ba455dbcf | 1102 | |
dflet | 0:e89ba455dbcf | 1103 | SyncCnt++; |
dflet | 0:e89ba455dbcf | 1104 | } |
dflet | 0:e89ba455dbcf | 1105 | |
dflet | 0:e89ba455dbcf | 1106 | /* 5. Sync pattern found. If needed, complete number of read bytes to multiple of 4 (protocol align) */ |
dflet | 0:e89ba455dbcf | 1107 | SyncCnt %= SYNC_PATTERN_LEN; |
dflet | 0:e89ba455dbcf | 1108 | |
dflet | 0:e89ba455dbcf | 1109 | if(SyncCnt > 0) { |
dflet | 0:e89ba455dbcf | 1110 | *(uint32_t *)&pBuf[0] = *(uint32_t *)&pBuf[4]; |
dflet | 0:e89ba455dbcf | 1111 | _spi.spi_Read(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN - SyncCnt], (uint16_t)SyncCnt); |
dflet | 0:e89ba455dbcf | 1112 | } else { |
dflet | 0:e89ba455dbcf | 1113 | _spi.spi_Read(g_pCB->FD, &pBuf[0], 4); |
dflet | 0:e89ba455dbcf | 1114 | } |
dflet | 0:e89ba455dbcf | 1115 | |
dflet | 0:e89ba455dbcf | 1116 | /* 6. Scan for Double pattern. */ |
dflet | 0:e89ba455dbcf | 1117 | while ( N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) { |
dflet | 0:e89ba455dbcf | 1118 | _SL_DBG_CNT_INC(Work.DoubleSyncPattern); |
dflet | 0:e89ba455dbcf | 1119 | _spi.spi_Read(g_pCB->FD, &pBuf[0], SYNC_PATTERN_LEN); |
dflet | 0:e89ba455dbcf | 1120 | } |
dflet | 0:e89ba455dbcf | 1121 | g_pCB->TxSeqNum++; |
dflet | 0:e89ba455dbcf | 1122 | |
dflet | 0:e89ba455dbcf | 1123 | /* 7. Here we've read Generic Header (4 bytes). Read the Resp Specific header (4 more bytes). */ |
dflet | 0:e89ba455dbcf | 1124 | _spi.spi_Read(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN], _SL_RESP_SPEC_HDR_SIZE); |
dflet | 0:e89ba455dbcf | 1125 | |
dflet | 0:e89ba455dbcf | 1126 | /* 8. Here we've read the entire Resp Header. */ |
dflet | 0:e89ba455dbcf | 1127 | /* Return number bytes needed to be sent after read for NWP Rx 4-byte alignment (protocol alignment) */ |
dflet | 0:e89ba455dbcf | 1128 | *pAlignSize = (uint8_t)((SyncCnt > 0) ? (SYNC_PATTERN_LEN - SyncCnt) : 0); |
dflet | 0:e89ba455dbcf | 1129 | |
dflet | 0:e89ba455dbcf | 1130 | return SL_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 1131 | } |
dflet | 0:e89ba455dbcf | 1132 | |
dflet | 0:e89ba455dbcf | 1133 | /* ***************************************************************************** */ |
dflet | 0:e89ba455dbcf | 1134 | /* _SlDrvBasicCmd */ |
dflet | 0:e89ba455dbcf | 1135 | /* ***************************************************************************** */ |
dflet | 0:e89ba455dbcf | 1136 | typedef union { |
dflet | 0:e89ba455dbcf | 1137 | _BasicResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 1138 | } _SlBasicCmdMsg_u; |
dflet | 0:e89ba455dbcf | 1139 | |
dflet | 0:e89ba455dbcf | 1140 | int16_t cc3100_driver::_SlDrvBasicCmd(_SlOpcode_t Opcode) |
dflet | 0:e89ba455dbcf | 1141 | { |
dflet | 0:e89ba455dbcf | 1142 | _SlBasicCmdMsg_u Msg = {0}; |
dflet | 0:e89ba455dbcf | 1143 | _SlCmdCtrl_t CmdCtrl; |
dflet | 0:e89ba455dbcf | 1144 | |
dflet | 0:e89ba455dbcf | 1145 | CmdCtrl.Opcode = Opcode; |
dflet | 0:e89ba455dbcf | 1146 | CmdCtrl.TxDescLen = 0; |
dflet | 0:e89ba455dbcf | 1147 | CmdCtrl.RxDescLen = sizeof(_BasicResponse_t); |
dflet | 0:e89ba455dbcf | 1148 | |
dflet | 0:e89ba455dbcf | 1149 | |
dflet | 0:e89ba455dbcf | 1150 | VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL)); |
dflet | 0:e89ba455dbcf | 1151 | |
dflet | 0:e89ba455dbcf | 1152 | return (int16_t)Msg.Rsp.status; |
dflet | 0:e89ba455dbcf | 1153 | } |
dflet | 0:e89ba455dbcf | 1154 | |
dflet | 0:e89ba455dbcf | 1155 | /* ***************************************************************************** */ |
dflet | 0:e89ba455dbcf | 1156 | /* _SlDrvWaitForPoolObj */ |
dflet | 0:e89ba455dbcf | 1157 | /* ***************************************************************************** */ |
dflet | 0:e89ba455dbcf | 1158 | int16_t cc3100_driver::_SlDrvWaitForPoolObj(uint32_t ActionID, uint8_t SocketID) |
dflet | 0:e89ba455dbcf | 1159 | { |
dflet | 0:e89ba455dbcf | 1160 | uint8_t CurrObjIndex = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1161 | |
dflet | 0:e89ba455dbcf | 1162 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 1163 | |
dflet | 0:e89ba455dbcf | 1164 | /* Get free object */ |
dflet | 0:e89ba455dbcf | 1165 | if (MAX_CONCURRENT_ACTIONS > g_pCB->FreePoolIdx) { |
dflet | 0:e89ba455dbcf | 1166 | /* save the current obj index */ |
dflet | 0:e89ba455dbcf | 1167 | CurrObjIndex = g_pCB->FreePoolIdx; |
dflet | 0:e89ba455dbcf | 1168 | /* set the new free index */ |
dflet | 0:e89ba455dbcf | 1169 | if (MAX_CONCURRENT_ACTIONS > g_pCB->ObjPool[CurrObjIndex].NextIndex) { |
dflet | 0:e89ba455dbcf | 1170 | g_pCB->FreePoolIdx = g_pCB->ObjPool[CurrObjIndex].NextIndex; |
dflet | 0:e89ba455dbcf | 1171 | } else { |
dflet | 0:e89ba455dbcf | 1172 | /* No further free actions available */ |
dflet | 0:e89ba455dbcf | 1173 | g_pCB->FreePoolIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1174 | } |
dflet | 0:e89ba455dbcf | 1175 | } else { |
dflet | 0:e89ba455dbcf | 1176 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 1177 | return CurrObjIndex; |
dflet | 0:e89ba455dbcf | 1178 | } |
dflet | 0:e89ba455dbcf | 1179 | g_pCB->ObjPool[CurrObjIndex].ActionID = (uint8_t)ActionID; |
dflet | 0:e89ba455dbcf | 1180 | if (SL_MAX_SOCKETS > SocketID) { |
dflet | 0:e89ba455dbcf | 1181 | g_pCB->ObjPool[CurrObjIndex].AdditionalData = SocketID; |
dflet | 0:e89ba455dbcf | 1182 | } |
dflet | 0:e89ba455dbcf | 1183 | /*In case this action is socket related, SocketID bit will be on |
dflet | 0:e89ba455dbcf | 1184 | In case SocketID is set to SL_MAX_SOCKETS, the socket is not relevant to the action. In that case ActionID bit will be on */ |
dflet | 0:e89ba455dbcf | 1185 | while ( ( (SL_MAX_SOCKETS > SocketID) && (g_pCB->ActiveActionsBitmap & (1<<SocketID)) ) || ( (g_pCB->ActiveActionsBitmap & (1<<ActionID)) && (SL_MAX_SOCKETS == SocketID) ) ) { |
dflet | 0:e89ba455dbcf | 1186 | //action in progress - move to pending list |
dflet | 0:e89ba455dbcf | 1187 | g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->PendingPoolIdx; |
dflet | 0:e89ba455dbcf | 1188 | g_pCB->PendingPoolIdx = CurrObjIndex; |
dflet | 0:e89ba455dbcf | 1189 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 1190 | //wait for action to be free |
dflet | 0:e89ba455dbcf | 1191 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjWait(&g_pCB->ObjPool[CurrObjIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE, NON_OS_SYNC_OBJ_CLEAR_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 1192 | //set params and move to active (remove from pending list at _SlDrvReleasePoolObj) |
dflet | 0:e89ba455dbcf | 1193 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 1194 | } |
dflet | 0:e89ba455dbcf | 1195 | /*mark as active. Set socket as active if action is on socket, otherwise mark action as active*/ |
dflet | 0:e89ba455dbcf | 1196 | if (SL_MAX_SOCKETS > SocketID) { |
dflet | 0:e89ba455dbcf | 1197 | g_pCB->ActiveActionsBitmap |= (1<<SocketID); |
dflet | 0:e89ba455dbcf | 1198 | } else { |
dflet | 0:e89ba455dbcf | 1199 | g_pCB->ActiveActionsBitmap |= (1<<ActionID); |
dflet | 0:e89ba455dbcf | 1200 | } |
dflet | 0:e89ba455dbcf | 1201 | /* move to active list */ |
dflet | 0:e89ba455dbcf | 1202 | g_pCB->ObjPool[CurrObjIndex].NextIndex = g_pCB->ActivePoolIdx; |
dflet | 0:e89ba455dbcf | 1203 | g_pCB->ActivePoolIdx = CurrObjIndex; |
dflet | 0:e89ba455dbcf | 1204 | /* unlock */ |
dflet | 0:e89ba455dbcf | 1205 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 1206 | return CurrObjIndex; |
dflet | 0:e89ba455dbcf | 1207 | } |
dflet | 0:e89ba455dbcf | 1208 | |
dflet | 0:e89ba455dbcf | 1209 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1210 | /* _SlDrvReleasePoolObj */ |
dflet | 0:e89ba455dbcf | 1211 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1212 | void cc3100_driver::_SlDrvReleasePoolObj(uint8_t ObjIdx) |
dflet | 0:e89ba455dbcf | 1213 | { |
dflet | 0:e89ba455dbcf | 1214 | uint8_t PendingIndex; |
dflet | 0:e89ba455dbcf | 1215 | |
dflet | 0:e89ba455dbcf | 1216 | OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE, NON_OS_LOCK_OBJ_LOCK_VALUE, SL_OS_WAIT_FOREVER)); |
dflet | 0:e89ba455dbcf | 1217 | |
dflet | 0:e89ba455dbcf | 1218 | /* go over the pending list and release other pending action if needed */ |
dflet | 0:e89ba455dbcf | 1219 | PendingIndex = g_pCB->PendingPoolIdx; |
dflet | 0:e89ba455dbcf | 1220 | while(MAX_CONCURRENT_ACTIONS > PendingIndex) { |
dflet | 0:e89ba455dbcf | 1221 | /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ |
dflet | 0:e89ba455dbcf | 1222 | if ( (g_pCB->ObjPool[PendingIndex].ActionID == g_pCB->ObjPool[ObjIdx].ActionID) && |
dflet | 0:e89ba455dbcf | 1223 | ( (SL_MAX_SOCKETS == (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK)) || |
dflet | 0:e89ba455dbcf | 1224 | ((SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) && ( (g_pCB->ObjPool[PendingIndex].AdditionalData & BSD_SOCKET_ID_MASK) == (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK) ))) ) { |
dflet | 0:e89ba455dbcf | 1225 | /* remove from pending list */ |
dflet | 0:e89ba455dbcf | 1226 | _SlRemoveFromList(&g_pCB->PendingPoolIdx, PendingIndex); |
dflet | 0:e89ba455dbcf | 1227 | OSI_RET_OK_CHECK(_nonos.sl_SyncObjSignal(&g_pCB->ObjPool[PendingIndex].SyncObj, NON_OS_SYNC_OBJ_SIGNAL_VALUE)); |
dflet | 0:e89ba455dbcf | 1228 | break; |
dflet | 0:e89ba455dbcf | 1229 | } |
dflet | 0:e89ba455dbcf | 1230 | PendingIndex = g_pCB->ObjPool[PendingIndex].NextIndex; |
dflet | 0:e89ba455dbcf | 1231 | } |
dflet | 0:e89ba455dbcf | 1232 | |
dflet | 0:e89ba455dbcf | 1233 | if (SL_MAX_SOCKETS > (g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)) { |
dflet | 0:e89ba455dbcf | 1234 | /* unset socketID */ |
dflet | 0:e89ba455dbcf | 1235 | g_pCB->ActiveActionsBitmap &= ~(1<<(g_pCB->ObjPool[ObjIdx].AdditionalData & BSD_SOCKET_ID_MASK)); |
dflet | 0:e89ba455dbcf | 1236 | } else { |
dflet | 0:e89ba455dbcf | 1237 | /* unset actionID */ |
dflet | 0:e89ba455dbcf | 1238 | g_pCB->ActiveActionsBitmap &= ~(1<<g_pCB->ObjPool[ObjIdx].ActionID); |
dflet | 0:e89ba455dbcf | 1239 | } |
dflet | 0:e89ba455dbcf | 1240 | |
dflet | 0:e89ba455dbcf | 1241 | /* delete old data */ |
dflet | 0:e89ba455dbcf | 1242 | g_pCB->ObjPool[ObjIdx].pRespArgs = NULL; |
dflet | 0:e89ba455dbcf | 1243 | g_pCB->ObjPool[ObjIdx].ActionID = 0; |
dflet | 0:e89ba455dbcf | 1244 | g_pCB->ObjPool[ObjIdx].AdditionalData = SL_MAX_SOCKETS; |
dflet | 0:e89ba455dbcf | 1245 | |
dflet | 0:e89ba455dbcf | 1246 | /* remove from active list */ |
dflet | 0:e89ba455dbcf | 1247 | _SlRemoveFromList(&g_pCB->ActivePoolIdx, ObjIdx); |
dflet | 0:e89ba455dbcf | 1248 | /* move to free list */ |
dflet | 0:e89ba455dbcf | 1249 | g_pCB->ObjPool[ObjIdx].NextIndex = g_pCB->FreePoolIdx; |
dflet | 0:e89ba455dbcf | 1250 | g_pCB->FreePoolIdx = ObjIdx; |
dflet | 0:e89ba455dbcf | 1251 | |
dflet | 0:e89ba455dbcf | 1252 | OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj, NON_OS_LOCK_OBJ_UNLOCK_VALUE)); |
dflet | 0:e89ba455dbcf | 1253 | } |
dflet | 0:e89ba455dbcf | 1254 | |
dflet | 0:e89ba455dbcf | 1255 | |
dflet | 0:e89ba455dbcf | 1256 | |
dflet | 0:e89ba455dbcf | 1257 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1258 | /* _SlDrvObjInit */ |
dflet | 0:e89ba455dbcf | 1259 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1260 | void cc3100_driver::_SlDrvObjInit(void) |
dflet | 0:e89ba455dbcf | 1261 | { |
dflet | 0:e89ba455dbcf | 1262 | uint8_t Idx; |
dflet | 0:e89ba455dbcf | 1263 | |
dflet | 0:e89ba455dbcf | 1264 | memset(&g_pCB->ObjPool[0],0,MAX_CONCURRENT_ACTIONS*sizeof(_SlPoolObj_t)); |
dflet | 0:e89ba455dbcf | 1265 | /* place all Obj in the free list */ |
dflet | 0:e89ba455dbcf | 1266 | g_pCB->FreePoolIdx = 0; |
dflet | 0:e89ba455dbcf | 1267 | for (Idx = 0 ; Idx < MAX_CONCURRENT_ACTIONS ; Idx++) { |
dflet | 0:e89ba455dbcf | 1268 | g_pCB->ObjPool[Idx].NextIndex = Idx + 1; |
dflet | 0:e89ba455dbcf | 1269 | g_pCB->ObjPool[Idx].AdditionalData = SL_MAX_SOCKETS; |
dflet | 0:e89ba455dbcf | 1270 | } |
dflet | 0:e89ba455dbcf | 1271 | |
dflet | 0:e89ba455dbcf | 1272 | g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1273 | g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1274 | |
dflet | 0:e89ba455dbcf | 1275 | } |
dflet | 0:e89ba455dbcf | 1276 | |
dflet | 0:e89ba455dbcf | 1277 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1278 | /* _SlDrvObjDeInit */ |
dflet | 0:e89ba455dbcf | 1279 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1280 | void cc3100_driver::_SlDrvObjDeInit(void) |
dflet | 0:e89ba455dbcf | 1281 | { |
dflet | 0:e89ba455dbcf | 1282 | g_pCB->FreePoolIdx = 0; |
dflet | 0:e89ba455dbcf | 1283 | g_pCB->PendingPoolIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1284 | g_pCB->ActivePoolIdx = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1285 | |
dflet | 0:e89ba455dbcf | 1286 | } |
dflet | 0:e89ba455dbcf | 1287 | |
dflet | 0:e89ba455dbcf | 1288 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1289 | /* _SlRemoveFromList */ |
dflet | 0:e89ba455dbcf | 1290 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1291 | void cc3100_driver::_SlRemoveFromList(uint8_t *ListIndex, uint8_t ItemIndex) |
dflet | 0:e89ba455dbcf | 1292 | { |
dflet | 0:e89ba455dbcf | 1293 | uint8_t Idx; |
dflet | 0:e89ba455dbcf | 1294 | /* only one item in the list */ |
dflet | 0:e89ba455dbcf | 1295 | if (MAX_CONCURRENT_ACTIONS == g_pCB->ObjPool[*ListIndex].NextIndex) { |
dflet | 0:e89ba455dbcf | 1296 | *ListIndex = MAX_CONCURRENT_ACTIONS; |
dflet | 0:e89ba455dbcf | 1297 | } |
dflet | 0:e89ba455dbcf | 1298 | /* need to remove the first item in the list and therefore update the global which holds this index */ |
dflet | 0:e89ba455dbcf | 1299 | else if (*ListIndex == ItemIndex) { |
dflet | 0:e89ba455dbcf | 1300 | *ListIndex = g_pCB->ObjPool[ItemIndex].NextIndex; |
dflet | 0:e89ba455dbcf | 1301 | } else { |
dflet | 0:e89ba455dbcf | 1302 | Idx = *ListIndex; |
dflet | 0:e89ba455dbcf | 1303 | while(MAX_CONCURRENT_ACTIONS > Idx) { |
dflet | 0:e89ba455dbcf | 1304 | /* remove from list */ |
dflet | 0:e89ba455dbcf | 1305 | if (g_pCB->ObjPool[Idx].NextIndex == ItemIndex) { |
dflet | 0:e89ba455dbcf | 1306 | g_pCB->ObjPool[Idx].NextIndex = g_pCB->ObjPool[ItemIndex].NextIndex; |
dflet | 0:e89ba455dbcf | 1307 | break; |
dflet | 0:e89ba455dbcf | 1308 | } |
dflet | 0:e89ba455dbcf | 1309 | Idx = g_pCB->ObjPool[Idx].NextIndex; |
dflet | 0:e89ba455dbcf | 1310 | } |
dflet | 0:e89ba455dbcf | 1311 | } |
dflet | 0:e89ba455dbcf | 1312 | } |
dflet | 0:e89ba455dbcf | 1313 | |
dflet | 0:e89ba455dbcf | 1314 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1315 | /* _SlFindAndSetActiveObj */ |
dflet | 0:e89ba455dbcf | 1316 | /* ******************************************************************************/ |
dflet | 0:e89ba455dbcf | 1317 | _SlReturnVal_t cc3100_driver::_SlFindAndSetActiveObj(_SlOpcode_t Opcode, uint8_t Sd) |
dflet | 0:e89ba455dbcf | 1318 | { |
dflet | 0:e89ba455dbcf | 1319 | uint8_t ActiveIndex; |
dflet | 0:e89ba455dbcf | 1320 | |
dflet | 0:e89ba455dbcf | 1321 | ActiveIndex = g_pCB->ActivePoolIdx; |
dflet | 0:e89ba455dbcf | 1322 | /* go over the active list if exist to find obj waiting for this Async event */ |
dflet | 0:e89ba455dbcf | 1323 | while (MAX_CONCURRENT_ACTIONS > ActiveIndex) { |
dflet | 0:e89ba455dbcf | 1324 | /* unset the Ipv4\IPv6 bit in the opcode if family bit was set */ |
dflet | 0:e89ba455dbcf | 1325 | if (g_pCB->ObjPool[ActiveIndex].AdditionalData & SL_NETAPP_FAMILY_MASK) { |
dflet | 0:e89ba455dbcf | 1326 | Opcode &= ~SL_OPCODE_IPV6; |
dflet | 0:e89ba455dbcf | 1327 | } |
dflet | 0:e89ba455dbcf | 1328 | |
dflet | 0:e89ba455dbcf | 1329 | if ((g_pCB->ObjPool[ActiveIndex].ActionID == RECV_ID) && (Sd == g_pCB->ObjPool[ActiveIndex].AdditionalData) && |
dflet | 0:e89ba455dbcf | 1330 | ( (SL_OPCODE_SOCKET_RECVASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE == Opcode) || (SL_OPCODE_SOCKET_RECVFROMASYNCRESPONSE_V6 == Opcode) ) ) { |
dflet | 0:e89ba455dbcf | 1331 | g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; |
dflet | 0:e89ba455dbcf | 1332 | return SL_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 1333 | } |
dflet | 0:e89ba455dbcf | 1334 | /* In case this action is socket related, SocketID is in use, otherwise will be set to SL_MAX_SOCKETS */ |
dflet | 0:e89ba455dbcf | 1335 | if ( (_SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].ActionAsyncOpcode == Opcode) && |
dflet | 0:e89ba455dbcf | 1336 | ( ((Sd == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK) ) && (SL_MAX_SOCKETS > Sd)) || (SL_MAX_SOCKETS == (g_pCB->ObjPool[ActiveIndex].AdditionalData & BSD_SOCKET_ID_MASK)) ) ) { |
dflet | 0:e89ba455dbcf | 1337 | /* set handler */ |
dflet | 0:e89ba455dbcf | 1338 | g_pCB->FunctionParams.AsyncExt.AsyncEvtHandler = _SlActionLookupTable[ g_pCB->ObjPool[ActiveIndex].ActionID - MAX_SOCKET_ENUM_IDX].AsyncEventHandler; |
dflet | 0:e89ba455dbcf | 1339 | g_pCB->FunctionParams.AsyncExt.ActionIndex = ActiveIndex; |
dflet | 0:e89ba455dbcf | 1340 | return SL_RET_CODE_OK; |
dflet | 0:e89ba455dbcf | 1341 | } |
dflet | 0:e89ba455dbcf | 1342 | ActiveIndex = g_pCB->ObjPool[ActiveIndex].NextIndex; |
dflet | 0:e89ba455dbcf | 1343 | } |
dflet | 0:e89ba455dbcf | 1344 | |
dflet | 0:e89ba455dbcf | 1345 | return SL_RET_CODE_SELF_ERROR; |
dflet | 0:e89ba455dbcf | 1346 | } |
dflet | 0:e89ba455dbcf | 1347 | |
dflet | 0:e89ba455dbcf | 1348 | }//namespace mbed_cc3100 |
dflet | 0:e89ba455dbcf | 1349 | |
dflet | 0:e89ba455dbcf | 1350 |