David Fletcher / Mbed 2 deprecated cc3100_Test_websock_Camera_CM4F

Dependencies:   mbed

Revision:
19:3dd3e7f30f8b
Parent:
18:3f1b52616d00
--- a/simplelink/cc3100_driver.cpp	Thu Sep 03 20:10:39 2015 +0000
+++ b/simplelink/cc3100_driver.cpp	Thu Sep 10 17:56:09 2015 +0000
@@ -157,7 +157,8 @@
     NULL
 };
 
-#ifndef SL_PLATFORM_MULTI_THREADED
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
 cc3100_driver::cc3100_driver(cc3100_spi &spi, cc3100_nonos &nonos, cc3100_netapp &netapp, cc3100_flowcont &flowcont)
     :  _spi(spi), _nonos(nonos), _netapp(netapp), _flowcont(flowcont)
 {
@@ -230,7 +231,8 @@
     MALLOC_OK_CHECK(g_pCB);
     _SlDrvMemZero(g_pCB, sizeof(_SlDriverCb_t));
     RxIrqCnt = 0;
-#ifndef SL_PLATFORM_MULTI_THREADED
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
     OSI_RET_OK_CHECK( _nonos.sl_SyncObjCreate(&g_pCB->CmdSyncObj, "CmdSyncObj") );
     _nonos.sl_SyncObjClear(&g_pCB->CmdSyncObj);
     OSI_RET_OK_CHECK( _nonos.sl_LockObjCreate(&g_pCB->GlobalLockObj, "GlobalLockObj") );
@@ -251,7 +253,8 @@
     {
         g_pCB->ObjPool[Idx].NextIndex = Idx + 1;
         g_pCB->ObjPool[Idx].AdditionalData = SL_MAX_SOCKETS;
-#ifndef SL_PLATFORM_MULTI_THREADED
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
         OSI_RET_OK_CHECK( _nonos.sl_SyncObjCreate(&g_pCB->ObjPool[Idx].SyncObj, "SyncObj"));
         _nonos.sl_SyncObjClear(&g_pCB->ObjPool[Idx].SyncObj);
 #else
@@ -265,7 +268,8 @@
 
     /* Flow control init */
     g_pCB->FlowContCB.TxPoolCnt = FLOW_CONT_MIN;
-#ifndef SL_PLATFORM_MULTI_THREADED   
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))   
     OSI_RET_OK_CHECK(_nonos.sl_LockObjCreate(&g_pCB->FlowContCB.TxLockObj, "TxLockObj"));
     OSI_RET_OK_CHECK(_nonos.sl_SyncObjCreate(&g_pCB->FlowContCB.TxSyncObj, "TxSyncObj"));
 #else
@@ -284,7 +288,8 @@
     
     /* Flow control de-init */
     g_pCB->FlowContCB.TxPoolCnt = 0;
-#ifndef SL_PLATFORM_MULTI_THREADED    
+//#ifndef SL_PLATFORM_MULTI_THREADED 
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))   
     OSI_RET_OK_CHECK(_nonos.sl_LockObjDelete(&g_pCB->FlowContCB.TxLockObj));
     OSI_RET_OK_CHECK(_nonos.sl_SyncObjDelete(&g_pCB->FlowContCB.TxSyncObj));
     
@@ -330,7 +335,8 @@
     RxIrqCnt++;
     
     if (TRUE == g_pCB->IsCmdRespWaited) {
-#ifndef SL_PLATFORM_MULTI_THREADED      
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))      
         OSI_RET_OK_CHECK( _nonos.sl_SyncObjSignalFromIRQ(&g_pCB->CmdSyncObj) );
 #else        
         OSI_RET_OK_CHECK( sl_SyncObjSignalFromIRQ(&g_pCB->CmdSyncObj) );
@@ -428,7 +434,8 @@
     /* Clear SyncObj for the case it was signalled before TxPoolCnt */
     /* dropped below '1' (last Data buffer was taken)  */
     /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */
-#ifndef SL_PLATFORM_MULTI_THREADED       
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))       
     _nonos.sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj);
 #else    
     sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj);
@@ -475,7 +482,8 @@
         /*  Clear SyncObj for the case it was signalled before TxPoolCnt */
         /*  dropped below '1' (last Data buffer was taken) */
         /* OSI_RET_OK_CHECK( sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj) ); */
-#ifndef SL_PLATFORM_MULTI_THREADED               
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))               
         _nonos.sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj);
 #else        
         sl_SyncObjClear(&g_pCB->FlowContCB.TxSyncObj);
@@ -553,18 +561,18 @@
 
 #ifdef SL_IF_TYPE_UART
     /*  Write long sync pattern */
-    _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Long, 2*SYNC_PATTERN_LEN);
+    NWP_IF_WRITE_CHECK(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Long, 2*SYNC_PATTERN_LEN);
 #else
     /*  Write short sync pattern */
-    _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Short, SYNC_PATTERN_LEN);
+    NWP_IF_WRITE_CHECK(g_pCB->FD, (uint8_t *)&g_H2NSyncPattern.Short, SYNC_PATTERN_LEN);
 #endif
     /*  Header */
-    _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_pCB->TempProtocolHeader, _SL_CMD_HDR_SIZE);
+    NWP_IF_WRITE_CHECK(g_pCB->FD, (uint8_t *)&g_pCB->TempProtocolHeader, _SL_CMD_HDR_SIZE);
 
     /*  Descriptors */
     if (pTxRxDescBuff && pCmdCtrl->TxDescLen > 0)
     {
-    	_spi.spi_Write(g_pCB->FD, pTxRxDescBuff, 
+    	NWP_IF_WRITE_CHECK(g_pCB->FD, pTxRxDescBuff, 
                            _SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen));
     }
 
@@ -573,7 +581,7 @@
     /*  transceiver mode */
     if (sendRxPayload == TRUE )
     {
-     	_spi.spi_Write(g_pCB->FD, pCmdExt->pRxPayload, _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->RxPayloadLen));
+     	NWP_IF_WRITE_CHECK(g_pCB->FD, pCmdExt->pRxPayload, _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->RxPayloadLen));
     }
 
     /*  Payload */
@@ -583,7 +591,7 @@
         /*  Otherwise the aligning of arguments will create a gap between arguments and payload. */
         VERIFY_PROTOCOL(_SL_IS_PROTOCOL_ALIGNED_SIZE(pCmdCtrl->TxDescLen));
 
-    	_spi.spi_Write(g_pCB->FD, pCmdExt->pTxPayload, _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen));
+    	NWP_IF_WRITE_CHECK(g_pCB->FD, pCmdExt->pTxPayload, _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen));
     }
 
     _SL_DBG_CNT_INC(MsgCnt.Write);
@@ -672,7 +680,7 @@
 			}
             if (RespPayloadLen > 0)
             {
-                _spi.spi_Read(g_pCB->FD, pAsyncBuf + _SL_RESP_HDR_SIZE, AlignedLengthRecv);
+                NWP_IF_READ_CHECK(g_pCB->FD, pAsyncBuf + _SL_RESP_HDR_SIZE, AlignedLengthRecv);
             }
         /* In case ASYNC RX buffer length is smaller then the received data length, dump the rest */
 			if ((_SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen) > SL_ASYNC_MAX_PAYLOAD_LEN))
@@ -680,7 +688,7 @@
 				AlignedLengthRecv = _SL_PROTOCOL_ALIGN_SIZE(RespPayloadLen) - SL_ASYNC_MAX_PAYLOAD_LEN;
                 while (AlignedLengthRecv > 0)
                 {
-                _spi.spi_Read(g_pCB->FD,TailBuffer,4);
+                NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4);
                 AlignedLengthRecv = AlignedLengthRecv - 4;
                 }
             }
@@ -722,7 +730,7 @@
 
             /*  Read first 4 bytes of Recv/Recvfrom response to get SocketId and actual  */
             /*  response data length */
-            _spi.spi_Read(g_pCB->FD, &uBuf.TempBuf[4], RECV_ARGS_SIZE);
+            NWP_IF_READ_CHECK(g_pCB->FD, &uBuf.TempBuf[4], RECV_ARGS_SIZE);
 
             /*  Validate Socket ID and Received Length value.  */
             VERIFY_PROTOCOL((SD(&uBuf.TempBuf[4])& BSD_SOCKET_ID_MASK) < SL_MAX_SOCKETS);
@@ -739,7 +747,7 @@
 
             if(ExpArgSize > RECV_ARGS_SIZE)
             {
-                _spi.spi_Read(g_pCB->FD,
+                NWP_IF_READ_CHECK(g_pCB->FD,
                     ((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pArgs + RECV_ARGS_SIZE,
                     ExpArgSize - RECV_ARGS_SIZE);
             }
@@ -759,12 +767,12 @@
                 AlignedLengthRecv = ACT_DATA_SIZE(&uBuf.TempBuf[4]) & (~3);
                 if( AlignedLengthRecv >= 4)
                 {
-                    _spi.spi_Read(g_pCB->FD,((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData,AlignedLengthRecv );                      
+                    NWP_IF_READ_CHECK(g_pCB->FD,((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData,AlignedLengthRecv );                      
                 }
                 /*  copy the unaligned part, if any */
                 if( LengthToCopy > 0) 
                 {
-                    _spi.spi_Read(g_pCB->FD,TailBuffer,4);
+                    NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4);
                     /*  copy TailBuffer unaligned part (1/2/3 bytes) */
                     memcpy(((_SlArgsData_t *)(g_pCB->ObjPool[g_pCB->FunctionParams.AsyncExt.ActionIndex].pRespArgs))->pData + AlignedLengthRecv,TailBuffer,LengthToCopy);                    
                 }                  
@@ -782,7 +790,7 @@
             /*  When RxDescLen is not exact, using RxPayloadLen is forbidden! */
             /*  If such case cannot be avoided - parse message here to detect */
             /*  arguments/payload border. */
-            _spi.spi_Read(g_pCB->FD, g_pCB->FunctionParams.pTxRxDescBuff, _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->RxDescLen));
+            NWP_IF_READ_CHECK(g_pCB->FD, g_pCB->FunctionParams.pTxRxDescBuff, _SL_PROTOCOL_ALIGN_SIZE(g_pCB->FunctionParams.pCmdCtrl->RxDescLen));
 
             if((NULL != g_pCB->FunctionParams.pCmdExt) && (0 != g_pCB->FunctionParams.pCmdExt->RxPayloadLen)) {
                 /*  Actual size of command's response payload: <msg_payload_len> - <rsp_args_len> */
@@ -808,14 +816,14 @@
                     /*  and copied to a TailBuffer  */
 
                     if( AlignedLengthRecv >= 4) {
-                        _spi.spi_Read(g_pCB->FD,
+                        NWP_IF_READ_CHECK(g_pCB->FD,
                                           g_pCB->FunctionParams.pCmdExt->pRxPayload,
                                           AlignedLengthRecv );
 
                     }
                     /*  copy the unaligned part, if any */
                     if( LengthToCopy > 0) {
-                        _spi.spi_Read(g_pCB->FD,TailBuffer,4);
+                        NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer,4);
                         /*  copy TailBuffer unaligned part (1/2/3 bytes) */
                         memcpy(g_pCB->FunctionParams.pCmdExt->pRxPayload + AlignedLengthRecv,
                                   TailBuffer,
@@ -827,7 +835,7 @@
                         /* calculate the rest of the data size to dump */
                         AlignedLengthRecv = ActDataSize - (g_pCB->FunctionParams.pCmdExt->RxPayloadLen & (~3));
                         while( AlignedLengthRecv > 0) {
-                            _spi.spi_Read(g_pCB->FD,TailBuffer, 4 );
+                            NWP_IF_READ_CHECK(g_pCB->FD,TailBuffer, 4 );
                             AlignedLengthRecv = AlignedLengthRecv - 4;
                         }
                     }
@@ -841,7 +849,7 @@
     }
 
     if(AlignSize > 0) {
-        _spi.spi_Read(g_pCB->FD, uBuf.TempBuf, AlignSize);
+        NWP_IF_READ_CHECK(g_pCB->FD, uBuf.TempBuf, AlignSize);
     }
 
     _SL_DBG_CNT_INC(MsgCnt.Read);
@@ -927,7 +935,8 @@
 
                 /*  In case CmdResp has been read without  waiting on CmdSyncObj -  that */
                 /*  Sync object. That to prevent old signal to be processed. */
-#ifndef SL_PLATFORM_MULTI_THREADED               
+//#ifndef SL_PLATFORM_MULTI_THREADED 
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))              
                 _nonos.sl_SyncObjClear(&g_pCB->CmdSyncObj);
 #else                
                 sl_SyncObjClear(&g_pCB->CmdSyncObj);
@@ -961,7 +970,8 @@
     _SlDrvObjUnLock(&g_pCB->GlobalLockObj);
     
     if(_SL_PENDING_RX_MSG(g_pCB)) {
-#ifndef SL_PLATFORM_MULTI_THREADED      
+//#ifndef SL_PLATFORM_MULTI_THREADED 
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))     
       _nonos._SlNonOsSpawn((_SlSpawnEntryFunc_t)&_SlDrvMsgReadSpawnCtx, NULL, 0);
 #else
       sl_Spawn((_SlSpawnEntryFunc_t)&_SlDrvMsgReadSpawnCtx, NULL, 0);
@@ -1104,11 +1114,11 @@
     
 #ifndef SL_IF_TYPE_UART
     /*  1. Write CNYS pattern to NWP when working in SPI mode only  */
-    _spi.spi_Write(g_pCB->FD, (uint8_t *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN);
+    NWP_IF_WRITE_CHECK(g_pCB->FD, (uint8_t *)&g_H2NCnysPattern.Short, SYNC_PATTERN_LEN);
 #endif
   
     /*  2. Read 4 bytes (protocol aligned) */
-    _spi.spi_Read(g_pCB->FD, &pBuf[0], 4);
+    NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], 4);
     _SL_DBG_SYNC_LOG(SyncCnt,pBuf);
  
     /* Wait for SYNC_PATTERN_LEN from the device */
@@ -1121,7 +1131,7 @@
 
         /*  4. Read next 4 bytes to Low 4 bytes of buffer */
         if(0 == (SyncCnt % (uint32_t)SYNC_PATTERN_LEN)) {
-            _spi.spi_Read(g_pCB->FD, &pBuf[4], 4);
+            NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[4], 4);
             _SL_DBG_SYNC_LOG(SyncCnt,pBuf);
         }
 
@@ -1140,20 +1150,20 @@
 
     if(SyncCnt > 0) {
         *(uint32_t *)&pBuf[0] = *(uint32_t *)&pBuf[4];
-        _spi.spi_Read(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN - SyncCnt], (uint16_t)SyncCnt);
+        NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN - SyncCnt], (uint16_t)SyncCnt);
     } else {
-        _spi.spi_Read(g_pCB->FD, &pBuf[0], 4);
+        NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], 4);
     }
 
     /*  6. Scan for Double pattern. */
     while ( N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum) ) {
         _SL_DBG_CNT_INC(Work.DoubleSyncPattern);
-        _spi.spi_Read(g_pCB->FD, &pBuf[0], SYNC_PATTERN_LEN);
+        NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[0], SYNC_PATTERN_LEN);
     }
     g_pCB->TxSeqNum++;
 
     /*  7. Here we've read Generic Header (4 bytes). Read the Resp Specific header (4 more bytes). */
-    _spi.spi_Read(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN], _SL_RESP_SPEC_HDR_SIZE);
+    NWP_IF_READ_CHECK(g_pCB->FD, &pBuf[SYNC_PATTERN_LEN], _SL_RESP_SPEC_HDR_SIZE);
 
     /*  8. Here we've read the entire Resp Header. */
     /*     Return number bytes needed to be sent after read for NWP Rx 4-byte alignment (protocol alignment) */
@@ -1433,7 +1443,8 @@
 
 void  cc3100_driver::_SlDrvSyncObjWaitForever(_SlSyncObj_t *pSyncObj)
 {
-#ifndef SL_PLATFORM_MULTI_THREADED   
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))   
     OSI_RET_OK_CHECK(_nonos.sl_SyncObjWait(pSyncObj, SL_OS_WAIT_FOREVER));
 #else    
     OSI_RET_OK_CHECK(sl_SyncObjWait(pSyncObj, SL_OS_WAIT_FOREVER));
@@ -1442,7 +1453,8 @@
 
 void  cc3100_driver::_SlDrvSyncObjSignal(_SlSyncObj_t *pSyncObj)
 {
-#ifndef SL_PLATFORM_MULTI_THREADED   
+//#ifndef SL_PLATFORM_MULTI_THREADED 
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))  
     OSI_RET_OK_CHECK(_nonos.sl_SyncObjSignal(pSyncObj));
 #else    
     OSI_RET_OK_CHECK(sl_SyncObjSignal(pSyncObj));
@@ -1451,7 +1463,8 @@
 
 void cc3100_driver::_SlDrvObjLockWaitForever(_SlLockObj_t *pLockObj)
 {
-#ifndef SL_PLATFORM_MULTI_THREADED  
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))  
     OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(pLockObj, SL_OS_WAIT_FOREVER));
 #else    
     OSI_RET_OK_CHECK(sl_LockObjLock(pLockObj, SL_OS_WAIT_FOREVER));
@@ -1460,7 +1473,8 @@
 
 void cc3100_driver::_SlDrvProtectionObjLockWaitForever()
 {
-#ifndef SL_PLATFORM_MULTI_THREADED    
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))    
     OSI_RET_OK_CHECK(_nonos.sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));
 #else
     OSI_RET_OK_CHECK(sl_LockObjLock(&g_pCB->ProtectionLockObj, SL_OS_WAIT_FOREVER));
@@ -1469,7 +1483,8 @@
 
 void cc3100_driver::_SlDrvObjUnLock(_SlLockObj_t *pLockObj)
 {
-#ifndef SL_PLATFORM_MULTI_THREADED    
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))    
     OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(pLockObj));
 #else    
     OSI_RET_OK_CHECK(sl_LockObjUnlock(pLockObj));
@@ -1478,7 +1493,8 @@
 
 void cc3100_driver::_SlDrvProtectionObjUnLock()
 {
-#ifndef SL_PLATFORM_MULTI_THREADED   
+//#ifndef SL_PLATFORM_MULTI_THREADED
+#if (!defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))   
     OSI_RET_OK_CHECK(_nonos.sl_LockObjUnlock(&g_pCB->ProtectionLockObj));
 #else    
     OSI_RET_OK_CHECK(sl_LockObjUnlock(&g_pCB->ProtectionLockObj));