cc3100_Socket_Wifi_Server with Ethernet Interface not working

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of cc3100_Test_Demo by David Fletcher

Committer:
dflet
Date:
Tue Feb 10 12:09:29 2015 +0000
Revision:
0:e89ba455dbcf
Child:
2:b3fd5b3d9860
For test only! Not much has been tested, but the 2 demo apps run ok. Alot more work needs to be done!

Who changed what in which revision?

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