TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_driver.h Source File

cc3100_driver.h

00001 /*
00002  * driver.h - CC31xx/CC32xx Host Driver Implementation
00003  *
00004  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00005  *
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *    Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  *    Neither the name of Texas Instruments Incorporated nor the names of
00020  *    its contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036 
00037 #ifndef DRIVER_INT_H_
00038 #define DRIVER_INT_H_
00039 
00040 #include "mbed.h"
00041 #include "cc3100_simplelink.h"
00042 
00043 #include "cc3100_protocol.h"
00044 #include "cc3100_spi.h"
00045 #include "cc3100_netapp.h"
00046 
00047 #ifdef SL_PLATFORM_MULTI_THREADED
00048 #include "osi.h"
00049 #endif
00050 
00051 /*****************************************************************************/
00052 /* Macro declarations                                                        */
00053 /*****************************************************************************/
00054 
00055 /*  2 LSB of the N2H_SYNC_PATTERN are for sequence number
00056 only in SPI interface
00057 support backward sync pattern */
00058 #define N2H_SYNC_PATTERN_SEQ_NUM_BITS            ((uint32_t)0x00000003) /* Bits 0..1    - use the 2 LBS for seq num */
00059 #define N2H_SYNC_PATTERN_SEQ_NUM_EXISTS          ((uint32_t)0x00000004) /* Bit  2       - sign that sequence number exists in the sync pattern */
00060 #define N2H_SYNC_PATTERN_MASK                    ((uint32_t)0xFFFFFFF8) /* Bits 3..31   - constant SYNC PATTERN */
00061 #define N2H_SYNC_SPI_BUGS_MASK                   ((uint32_t)0x7FFF7F7F) /* Bits 7,15,31 - ignore the SPI (8,16,32 bites bus) error bits  */
00062 #define BUF_SYNC_SPIM(pBuf)                      ((*(uint32_t *)(pBuf)) & N2H_SYNC_SPI_BUGS_MASK)
00063 #define N2H_SYNC_SPIM                            (N2H_SYNC_PATTERN    & N2H_SYNC_SPI_BUGS_MASK)
00064 #define N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum)         ((N2H_SYNC_SPIM & N2H_SYNC_PATTERN_MASK) | N2H_SYNC_PATTERN_SEQ_NUM_EXISTS | ((TxSeqNum) & (N2H_SYNC_PATTERN_SEQ_NUM_BITS)))
00065 #define MATCH_WOUT_SEQ_NUM(pBuf)                 ( BUF_SYNC_SPIM(pBuf) ==  N2H_SYNC_SPIM )
00066 #define MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum)       ( BUF_SYNC_SPIM(pBuf) == (N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum)) )
00067 #define N2H_SYNC_PATTERN_MATCH(pBuf, TxSeqNum) \
00068     ( \
00069     (  (*((uint32_t *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ) )  || \
00070     ( !(*((uint32_t *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WOUT_SEQ_NUM(pBuf          ) ) )     \
00071     )
00072 
00073 #define OPCODE(_ptr)          (((_SlResponseHeader_t *)(_ptr))->GenHeader.Opcode)
00074 #define RSP_PAYLOAD_LEN(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Len - _SL_RESP_SPEC_HDR_SIZE)
00075 #define SD(_ptr)              (((_SocketAddrResponse_u *)(_ptr))->IpV4.sd)
00076 /*  Actual size of Recv/Recvfrom response data  */
00077 #define ACT_DATA_SIZE(_ptr)   (((_SocketAddrResponse_u *)(_ptr))->IpV4.statusOrLen)
00078 
00079 #define _SL_PROTOCOL_ALIGN_SIZE(msgLen)             (((msgLen)+3) & (~3))
00080 #define _SL_IS_PROTOCOL_ALIGNED_SIZE(msgLen)        (!((msgLen) & 3))
00081 #define _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt)     ((pCmdExt) ? \
00082                                                      (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen) + _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen)) : \
00083                                                      (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen)))
00084                                                      
00085 
00086 namespace mbed_cc3100 {
00087     
00088 //class cc3100;
00089     
00090 /*****************************************************************************/
00091 /* Structure/Enum declarations                                               */
00092 /*****************************************************************************/
00093 //typedef void(*_SlSpawnEntryFunc_t)(void* pValue);
00094 
00095 typedef struct {
00096     _SlOpcode_t      Opcode;
00097     _SlArgSize_t     TxDescLen;
00098     _SlArgSize_t     RxDescLen;
00099 } _SlCmdCtrl_t;
00100 
00101 typedef struct {
00102     uint16_t  TxPayloadLen;
00103     int16_t   RxPayloadLen;
00104     int16_t   ActualRxPayloadLen;
00105     uint8_t   *pTxPayload;
00106     uint8_t   *pRxPayload;
00107 } _SlCmdExt_t;
00108 
00109 
00110 typedef struct _SlArgsData_t {
00111     uint8_t  *pArgs;
00112     uint8_t  *pData;
00113 } _SlArgsData_t;
00114 
00115 typedef struct {
00116     _SlSyncObj_t          SyncObj;
00117     uint8_t               *pRespArgs;
00118     uint8_t               ActionID;
00119     uint8_t               AdditionalData; /* use for socketID and one bit which indicate supprt IPV6 or not (1=support, 0 otherwise) */
00120     uint8_t               NextIndex;
00121 
00122 } _SlPoolObj_t;
00123 
00124 
00125 typedef enum {
00126     SOCKET_0,
00127     SOCKET_1,
00128     SOCKET_2,
00129     SOCKET_3,
00130     SOCKET_4,
00131     SOCKET_5,
00132     SOCKET_6,
00133     SOCKET_7,
00134     MAX_SOCKET_ENUM_IDX,
00135 #ifndef SL_TINY_EXT    
00136     ACCEPT_ID = MAX_SOCKET_ENUM_IDX,
00137     CONNECT_ID,
00138 #else
00139     CONNECT_ID = MAX_SOCKET_ENUM_IDX,
00140 #endif
00141 #ifndef SL_TINY_EXT    
00142     SELECT_ID,
00143 #endif
00144     GETHOSYBYNAME_ID,
00145 #ifndef SL_TINY_EXT    
00146     GETHOSYBYSERVICE_ID,
00147     PING_ID,
00148 #endif  
00149     START_STOP_ID,
00150     RECV_ID
00151 } _SlActionID_e;
00152 
00153 typedef struct _SlActionLookup_t {
00154     uint8_t                 ActionID;
00155     uint16_t                ActionAsyncOpcode;
00156     _SlSpawnEntryFunc_t     AsyncEventHandler;
00157 
00158 } _SlActionLookup_t;
00159 
00160 
00161 typedef struct {
00162     uint8_t         TxPoolCnt;
00163     _SlLockObj_t    TxLockObj;
00164     _SlSyncObj_t    TxSyncObj;
00165 } _SlFlowContCB_t;
00166 
00167 typedef enum {
00168     RECV_RESP_CLASS,
00169     CMD_RESP_CLASS,
00170     ASYNC_EVT_CLASS,
00171     DUMMY_MSG_CLASS
00172 } _SlRxMsgClass_e;
00173 
00174 typedef struct {
00175     uint8_t                 *pAsyncBuf;         /* place to write pointer to buffer with CmdResp's Header + Arguments */
00176     uint8_t                 ActionIndex;
00177     _SlSpawnEntryFunc_t     AsyncEvtHandler;    /* place to write pointer to AsyncEvent handler (calc-ed by Opcode)   */
00178     _SlRxMsgClass_e         RxMsgClass;         /* type of Rx message                                                 */
00179 } AsyncExt_t;
00180 
00181 typedef struct {
00182     _SlCmdCtrl_t         *pCmdCtrl;
00183     uint8_t              *pTxRxDescBuff;
00184     _SlCmdExt_t          *pCmdExt;
00185     AsyncExt_t           AsyncExt;
00186 } _SlFunctionParams_t;
00187 
00188 typedef void (*P_INIT_CALLBACK)(uint32_t Status);
00189 
00190 typedef struct {
00191     _SlFd_t                    FD;
00192     _SlLockObj_t               GlobalLockObj;
00193     _SlCommandHeader_t         TempProtocolHeader;
00194     P_INIT_CALLBACK            pInitCallback;
00195 
00196     _SlPoolObj_t               ObjPool[MAX_CONCURRENT_ACTIONS];
00197     uint8_t                    FreePoolIdx;
00198     uint8_t                    PendingPoolIdx;
00199     uint8_t                    ActivePoolIdx;
00200     uint32_t                   ActiveActionsBitmap;
00201     _SlLockObj_t               ProtectionLockObj;
00202 
00203     _SlSyncObj_t               CmdSyncObj;
00204     uint8_t                    IsCmdRespWaited;
00205     _SlFlowContCB_t            FlowContCB;
00206     uint8_t                    TxSeqNum;
00207     uint8_t                    RxDoneCnt;
00208     uint8_t                    SocketNonBlocking;
00209     uint8_t                    SocketTXFailure;
00210     /* for stack reduction the parameters are globals */
00211     _SlFunctionParams_t        FunctionParams;
00212 
00213     uint8_t                    ActionIndex;
00214 }_SlDriverCb_t;
00215 
00216 extern volatile uint8_t RxIrqCnt;
00217 
00218 extern _SlDriverCb_t* g_pCB;
00219 typedef uint8_t _SlSd_t;
00220 
00221 class cc3100_driver
00222 {
00223 
00224 public:
00225 
00226 #ifndef SL_PLATFORM_MULTI_THREADED
00227     cc3100_driver(cc3100_spi &spi, cc3100_nonos &nonos, cc3100_netapp &netapp, cc3100_flowcont &flowcont);
00228 #else 
00229     cc3100_driver(cc3100_spi &spi, cc3100_netapp &netapp, cc3100_flowcont &flowcont);
00230 #endif
00231     ~cc3100_driver();
00232 
00233 
00234     /*****************************************************************************/
00235     /* Function prototypes                                                       */
00236     /*****************************************************************************/
00237     typedef _SlDriverCb_t pDriver;
00238     
00239     uint8_t _SlDrvProtectAsyncRespSetting(uint8_t *pAsyncRsp, uint8_t ActionID, uint8_t SocketID);
00240     
00241     bool _SL_PENDING_RX_MSG(pDriver* pDriverCB);
00242     
00243     void _SlDrvDriverCBInit(void);
00244 
00245     void _SlDrvDriverCBDeinit(void);
00246 
00247     void _SlDrvRxIrqHandler(void *pValue);
00248 
00249     _SlReturnVal_t  _SlDrvCmdOp(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00250 
00251     _SlReturnVal_t  _SlDrvCmdSend(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00252 
00253     _SlReturnVal_t  _SlDrvDataReadOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00254 
00255     _SlReturnVal_t  _SlDrvDataWriteOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00256 #ifndef SL_TINY_EXT
00257     int16_t  _SlDrvBasicCmd(_SlOpcode_t Opcode);
00258 #endif
00259     uint8_t _SlDrvWaitForPoolObj(uint8_t ActionID, uint8_t SocketID);
00260 
00261     void _SlDrvReleasePoolObj(uint8_t pObj);
00262 
00263 //    void _SlDrvObjInit(void);
00264 
00265     _SlReturnVal_t   _SlDrvMsgRead(void);
00266     
00267     _SlReturnVal_t   _SlDrvMsgWrite(_SlCmdCtrl_t  *pCmdCtrl,_SlCmdExt_t  *pCmdExt, uint8_t *pTxRxDescBuff);
00268 
00269  //   _SlReturnVal_t   _SlDrvMsgWrite(void);
00270 
00271     _SlReturnVal_t   _SlDrvMsgReadCmdCtx(void);
00272 
00273     _SlReturnVal_t   _SlDrvMsgReadSpawnCtx_(void *pValue);
00274 
00275     void             _SlDrvClassifyRxMsg(_SlOpcode_t Opcode );
00276 
00277     _SlReturnVal_t   _SlDrvRxHdrRead(uint8_t *pBuf, uint8_t *pAlignSize);
00278 
00279     void             _SlDrvShiftDWord(uint8_t *pBuf);
00280 
00281     void             _SlAsyncEventGenericHandler(void);
00282 
00283     void             _SlDrvObjDeInit(void);
00284 
00285     void             _SlRemoveFromList(uint8_t* ListIndex, uint8_t ItemIndex);
00286 
00287     _SlReturnVal_t   _SlFindAndSetActiveObj(_SlOpcode_t  Opcode, uint8_t Sd);
00288     
00289     uint16_t _SlDrvAlignSize(uint16_t msgLen); 
00290     void  _SlDrvSyncObjWaitForever(_SlSyncObj_t *pSyncObj);
00291     void  _SlDrvSyncObjSignal(_SlSyncObj_t *pSyncObj);
00292     void  _SlDrvObjLock(_SlLockObj_t *pLockObj, _SlTime_t Timeout);
00293     void  _SlDrvObjLockWaitForever(_SlLockObj_t *pLockObj);
00294     void  _SlDrvObjUnLock(_SlLockObj_t *pLockObj);    
00295     void  _SlDrvProtectionObjLockWaitForever();
00296     void  _SlDrvProtectionObjUnLock();
00297     void  _SlDrvMemZero(void* Addr, uint16_t size);
00298     void  _SlDrvResetCmdExt(_SlCmdExt_t* pCmdExt);
00299 
00300 
00301 private:
00302 
00303     cc3100_spi        &_spi;
00304 #ifndef SL_PLATFORM_MULTI_THREADED    
00305     cc3100_nonos      &_nonos;
00306 #endif    
00307     cc3100_netapp     &_netapp;
00308     cc3100_flowcont   &_flowcont;
00309 
00310 };//class
00311 
00312 
00313 
00314 }//namespace mbed_cc3100
00315 
00316 #endif /* __DRIVER_INT_H__ */
00317