TI's CC3100. A test demo with very little testing done!

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 "cc3100_simplelink.h"
00041 
00042 #include "cc3100_protocol.h"
00043 #include "cc3100_nonos.h"
00044 #include "cc3100_spi.h"
00045 #include "cc3100_netapp.h"
00046 #include "cc3100.h"
00047 
00048 
00049 /*****************************************************************************/
00050 /* Macro declarations                                                        */
00051 /*****************************************************************************/
00052 
00053 /*  2 LSB of the N2H_SYNC_PATTERN are for sequence number
00054 only in SPI interface
00055 support backward sync pattern */
00056 #define N2H_SYNC_PATTERN_SEQ_NUM_BITS            ((uint32_t)0x00000003) /* Bits 0..1    - use the 2 LBS for seq num */
00057 #define N2H_SYNC_PATTERN_SEQ_NUM_EXISTS          ((uint32_t)0x00000004) /* Bit  2       - sign that sequence number exists in the sync pattern */
00058 #define N2H_SYNC_PATTERN_MASK                    ((uint32_t)0xFFFFFFF8) /* Bits 3..31   - constant SYNC PATTERN */
00059 #define N2H_SYNC_SPI_BUGS_MASK                   ((uint32_t)0x7FFF7F7F) /* Bits 7,15,31 - ignore the SPI (8,16,32 bites bus) error bits  */
00060 #define BUF_SYNC_SPIM(pBuf)                      ((*(uint32_t *)(pBuf)) & N2H_SYNC_SPI_BUGS_MASK)
00061 #define N2H_SYNC_SPIM                            (N2H_SYNC_PATTERN    & N2H_SYNC_SPI_BUGS_MASK)
00062 #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)))
00063 #define MATCH_WOUT_SEQ_NUM(pBuf)                 ( BUF_SYNC_SPIM(pBuf) ==  N2H_SYNC_SPIM )
00064 #define MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum)       ( BUF_SYNC_SPIM(pBuf) == (N2H_SYNC_SPIM_WITH_SEQ(TxSeqNum)) )
00065 #define N2H_SYNC_PATTERN_MATCH(pBuf, TxSeqNum) \
00066     ( \
00067     (  (*((uint32_t *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WITH_SEQ_NUM(pBuf, TxSeqNum) ) )  || \
00068     ( !(*((uint32_t *)pBuf) & N2H_SYNC_PATTERN_SEQ_NUM_EXISTS) && ( MATCH_WOUT_SEQ_NUM(pBuf          ) ) )     \
00069     )
00070 
00071 #define OPCODE(_ptr)          (((_SlResponseHeader_t *)(_ptr))->GenHeader.Opcode)
00072 #define RSP_PAYLOAD_LEN(_ptr) (((_SlResponseHeader_t *)(_ptr))->GenHeader.Len - _SL_RESP_SPEC_HDR_SIZE)
00073 #define SD(_ptr)              (((_SocketAddrResponse_u *)(_ptr))->IpV4.sd)
00074 /*  Actual size of Recv/Recvfrom response data  */
00075 #define ACT_DATA_SIZE(_ptr)   (((_SocketAddrResponse_u *)(_ptr))->IpV4.statusOrLen)
00076 
00077 #define _SL_PROTOCOL_ALIGN_SIZE(msgLen)             (((msgLen)+3) & (~3))
00078 #define _SL_IS_PROTOCOL_ALIGNED_SIZE(msgLen)        (!((msgLen) & 3))
00079 #define _SL_PROTOCOL_CALC_LEN(pCmdCtrl,pCmdExt)     ((pCmdExt) ? \
00080                                                      (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen) + _SL_PROTOCOL_ALIGN_SIZE(pCmdExt->TxPayloadLen)) : \
00081                                                      (_SL_PROTOCOL_ALIGN_SIZE(pCmdCtrl->TxDescLen)))
00082                                                      
00083 
00084 namespace mbed_cc3100 {
00085     
00086 class cc3100;
00087     
00088 /*****************************************************************************/
00089 /* Structure/Enum declarations                                               */
00090 /*****************************************************************************/
00091 //typedef void(*_SlSpawnEntryFunc_t)(void* pValue);
00092 
00093 typedef struct {
00094     _SlOpcode_t      Opcode;
00095     _SlArgSize_t     TxDescLen;
00096     _SlArgSize_t     RxDescLen;
00097 } _SlCmdCtrl_t;
00098 
00099 typedef struct {
00100     uint16_t  TxPayloadLen;
00101     int16_t   RxPayloadLen;
00102     int16_t   ActualRxPayloadLen;
00103     uint8_t   *pTxPayload;
00104     uint8_t   *pRxPayload;
00105 } _SlCmdExt_t;
00106 
00107 
00108 typedef struct _SlArgsData_t {
00109     uint8_t  *pArgs;
00110     uint8_t  *pData;
00111 } _SlArgsData_t;
00112 
00113 
00114 typedef struct _SlPoolObj_t {
00115     _SlSyncObj_t          SyncObj;
00116     uint8_t               *pRespArgs;
00117     uint8_t               ActionID;
00118     uint8_t               AdditionalData; /* use for socketID and one bit which indicate supprt IPV6 or not (1=support, 0 otherwise) */
00119     uint8_t               NextIndex;
00120 
00121 } _SlPoolObj_t;
00122 
00123 
00124 typedef enum {
00125     SOCKET_0,
00126     SOCKET_1,
00127     SOCKET_2,
00128     SOCKET_3,
00129     SOCKET_4,
00130     SOCKET_5,
00131     SOCKET_6,
00132     SOCKET_7,
00133     MAX_SOCKET_ENUM_IDX,
00134 #ifndef SL_TINY_EXT    
00135     ACCEPT_ID = MAX_SOCKET_ENUM_IDX,
00136     CONNECT_ID,
00137 #else
00138     CONNECT_ID = MAX_SOCKET_ENUM_IDX,
00139 #endif
00140 #ifndef SL_TINY_EXT    
00141     SELECT_ID,
00142 #endif
00143     GETHOSYBYNAME_ID,
00144 #ifndef SL_TINY_EXT    
00145     GETHOSYBYSERVICE_ID,
00146     PING_ID,
00147 #endif  
00148     START_STOP_ID,
00149     RECV_ID
00150 } _SlActionID_e;
00151 
00152 typedef struct _SlActionLookup_t {
00153     uint8_t                 ActionID;
00154     uint16_t                ActionAsyncOpcode;
00155     _SlSpawnEntryFunc_t     AsyncEventHandler;
00156 
00157 } _SlActionLookup_t;
00158 
00159 
00160 typedef struct {
00161     uint8_t         TxPoolCnt;
00162     _SlLockObj_t    TxLockObj;
00163     _SlSyncObj_t    TxSyncObj;
00164 } _SlFlowContCB_t;
00165 
00166 typedef enum {
00167     RECV_RESP_CLASS,
00168     CMD_RESP_CLASS,
00169     ASYNC_EVT_CLASS,
00170     DUMMY_MSG_CLASS
00171 } _SlRxMsgClass_e;
00172 
00173 typedef struct {
00174     uint8_t                 *pAsyncBuf;         /* place to write pointer to buffer with CmdResp's Header + Arguments */
00175     uint8_t                 ActionIndex;
00176     _SlSpawnEntryFunc_t     AsyncEvtHandler;    /* place to write pointer to AsyncEvent handler (calc-ed by Opcode)   */
00177     _SlRxMsgClass_e         RxMsgClass;         /* type of Rx message                                                 */
00178 } AsyncExt_t;
00179 
00180 typedef struct {
00181     _SlCmdCtrl_t         *pCmdCtrl;
00182     uint8_t              *pTxRxDescBuff;
00183     _SlCmdExt_t          *pCmdExt;
00184     AsyncExt_t           AsyncExt;
00185 } _SlFunctionParams_t;
00186 
00187 typedef void (*P_INIT_CALLBACK)(uint32_t Status);
00188 
00189 typedef struct {
00190     _SlFd_t                    FD;
00191     _SlLockObj_t               GlobalLockObj;
00192     _SlCommandHeader_t         TempProtocolHeader;
00193     P_INIT_CALLBACK            pInitCallback;
00194 
00195     _SlPoolObj_t               ObjPool[MAX_CONCURRENT_ACTIONS];
00196     uint8_t                    FreePoolIdx;
00197     uint8_t                    PendingPoolIdx;
00198     uint8_t                    ActivePoolIdx;
00199     uint32_t                   ActiveActionsBitmap;
00200     _SlLockObj_t               ProtectionLockObj;
00201 
00202     _SlSyncObj_t               CmdSyncObj;
00203     uint8_t                    IsCmdRespWaited;
00204     _SlFlowContCB_t            FlowContCB;
00205     uint8_t                    TxSeqNum;
00206     uint8_t                    RxDoneCnt;
00207     uint8_t                    SocketNonBlocking;
00208     uint8_t                    SocketTXFailure;
00209     /* for stack reduction the parameters are globals */
00210     _SlFunctionParams_t        FunctionParams;
00211 
00212     uint8_t                    ActionIndex;
00213 }_SlDriverCb_t;
00214 
00215 extern volatile uint8_t RxIrqCnt;
00216 
00217 extern _SlDriverCb_t* g_pCB;
00218 typedef uint8_t _SlSd_t;
00219 
00220 class cc3100_driver
00221 {
00222 
00223 public:
00224 
00225     cc3100_driver(cc3100_nonos &nonos, cc3100_netapp &netapp, cc3100_flowcont &flowcont, cc3100_spi &spi);
00226 
00227     ~cc3100_driver();
00228 
00229 
00230     /*****************************************************************************/
00231     /* Function prototypes                                                       */
00232     /*****************************************************************************/
00233     typedef _SlDriverCb_t pDriver;
00234     
00235     uint8_t _SlDrvProtectAsyncRespSetting(uint8_t *pAsyncRsp, uint8_t ActionID, uint8_t SocketID);
00236     
00237     bool _SL_PENDING_RX_MSG(pDriver* pDriverCB);
00238     
00239     void _SlDrvDriverCBInit(void);
00240 
00241     void _SlDrvDriverCBDeinit(void);
00242 
00243     void _SlDrvRxIrqHandler(void *pValue);
00244 
00245     _SlReturnVal_t  _SlDrvCmdOp(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00246 
00247     _SlReturnVal_t  _SlDrvCmdSend(_SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00248 
00249     _SlReturnVal_t  _SlDrvDataReadOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00250 
00251     _SlReturnVal_t  _SlDrvDataWriteOp(_SlSd_t Sd, _SlCmdCtrl_t *pCmdCtrl , void* pTxRxDescBuff , _SlCmdExt_t* pCmdExt);
00252 #ifndef SL_TINY_EXT
00253     int16_t  _SlDrvBasicCmd(_SlOpcode_t Opcode);
00254 #endif
00255     uint8_t _SlDrvWaitForPoolObj(uint8_t ActionID, uint8_t SocketID);
00256 
00257     void _SlDrvReleasePoolObj(uint8_t pObj);
00258 
00259 //    void _SlDrvObjInit(void);
00260 
00261     _SlReturnVal_t   _SlDrvMsgRead(void);
00262     
00263     _SlReturnVal_t   _SlDrvMsgWrite(_SlCmdCtrl_t  *pCmdCtrl,_SlCmdExt_t  *pCmdExt, uint8_t *pTxRxDescBuff);
00264 
00265  //   _SlReturnVal_t   _SlDrvMsgWrite(void);
00266 
00267     _SlReturnVal_t   _SlDrvMsgReadCmdCtx(void);
00268 
00269     _SlReturnVal_t   _SlDrvMsgReadSpawnCtx_(void *pValue);
00270 
00271     void             _SlDrvClassifyRxMsg(_SlOpcode_t Opcode );
00272 
00273     _SlReturnVal_t   _SlDrvRxHdrRead(uint8_t *pBuf, uint8_t *pAlignSize);
00274 
00275     void             _SlDrvShiftDWord(uint8_t *pBuf);
00276 
00277     void             _SlAsyncEventGenericHandler(void);
00278 
00279     void             _SlDrvObjDeInit(void);
00280 
00281     void             _SlRemoveFromList(uint8_t* ListIndex, uint8_t ItemIndex);
00282 
00283     _SlReturnVal_t   _SlFindAndSetActiveObj(_SlOpcode_t  Opcode, uint8_t Sd);
00284     
00285     uint16_t _SlDrvAlignSize(uint16_t msgLen); 
00286     void  _SlDrvSyncObjWaitForever(_SlSyncObj_t *pSyncObj);
00287     void  _SlDrvSyncObjSignal(_SlSyncObj_t *pSyncObj);
00288     void  _SlDrvObjLock(_SlLockObj_t *pLockObj, _SlTime_t Timeout);
00289     void  _SlDrvObjLockWaitForever(_SlLockObj_t *pLockObj);
00290     void  _SlDrvProtectionObjLockWaitForever();
00291     void  _SlDrvObjUnLock(_SlLockObj_t *pLockObj);
00292     void  _SlDrvProtectionObjUnLock();
00293     void  _SlDrvMemZero(void* Addr, uint16_t size);
00294     void  _SlDrvResetCmdExt(_SlCmdExt_t* pCmdExt);
00295 
00296 
00297 private:
00298 
00299     cc3100_nonos      &_nonos;
00300     cc3100_netapp     &_netapp;
00301     cc3100_flowcont   &_flowcont;
00302     cc3100_spi        &_spi;
00303 
00304 };//class
00305 
00306 }//namespace mbed_cc3100
00307 
00308 #endif /* __DRIVER_INT_H__ */
00309