CC3000HostDriver for device TI CC3000 some changes were made due to mbed compiler and the use of void*

Dependents:   CC3000Test

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3000_common.h Source File

cc3000_common.h

00001 /*****************************************************************************
00002 *
00003 *  cc3000_common.h  - CC3000 Host Driver Implementation.
00004 *  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
00005 *
00006 *  Redistribution and use in source and binary forms, with or without
00007 *  modification, are permitted provided that the following conditions
00008 *  are met:
00009 *
00010 *    Redistributions of source code must retain the above copyright
00011 *    notice, this list of conditions and the following disclaimer.
00012 *
00013 *    Redistributions in binary form must reproduce the above copyright
00014 *    notice, this list of conditions and the following disclaimer in the
00015 *    documentation and/or other materials provided with the   
00016 *    distribution.
00017 *
00018 *    Neither the name of Texas Instruments Incorporated nor the names of
00019 *    its contributors may be used to endorse or promote products derived
00020 *    from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00026 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 *
00034 *****************************************************************************/
00035 #ifndef __COMMON_H__
00036 #define __COMMON_H__
00037 
00038 //******************************************************************************
00039 // Include files
00040 //******************************************************************************
00041 //#include <stdlib.h>
00042 #include <errno.h>
00043 //#include <stdint.h>
00044 
00045 //*****************************************************************************
00046 //
00047 // If building with a C++ compiler, make all of the definitions in this header
00048 // have a C binding.
00049 //
00050 //*****************************************************************************
00051 #ifdef  __cplusplus
00052 extern "C" {
00053 #endif
00054 
00055 //*****************************************************************************
00056 //                  ERROR CODES
00057 //*****************************************************************************
00058 #define ESUCCESS        0
00059 #define EFAIL          -1
00060 #define EERROR          EFAIL
00061 
00062 //*****************************************************************************
00063 //                  COMMON DEFINES
00064 //*****************************************************************************
00065 #define ERROR_SOCKET_INACTIVE   -57 
00066 
00067 #define WLAN_ENABLE      (1) 
00068  
00069 #define WLAN_DISABLE     (0)
00070 
00071 #define    MAC_ADDR_LEN    (6)
00072 
00073 #define    SP_PORTION_SIZE    (32)
00074   
00075 /*Defines for minimal and maximal RX buffer size. This size includes the spi 
00076   header and hci header.
00077   The maximal buffer size derives from:
00078     MTU + HCI header + SPI header + sendto() agrs size
00079   The minimum buffer size derives from:
00080     HCI header + SPI header + max args size
00081 
00082   This buffer is used for receiving events and data.
00083   The packet can not be longer than MTU size and CC3000 does not support 
00084   fragmentation. Note that the same buffer is used for reception of the data 
00085   and events from CC3000. That is why the minimum is defined. 
00086   The calculation for the actual size of buffer for reception is:
00087   Given the maximal data size MAX_DATA that is expected to be received by
00088   application, the required buffer is:
00089   Using recv() or recvfrom():
00090  
00091     max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
00092     + ucArgsize + 1)
00093  
00094   Using gethostbyname() with minimal buffer size will limit the host name
00095   returned to 99 bytes only.
00096   The 1 is used for the overrun detection 
00097 
00098   Buffer size increased to 130 following the add_profile() with WEP security
00099   which requires TX buffer size of 130 bytes: 
00100   HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
00101   MAX SSID LEN = 32 
00102   MAX SSID LEN = 13 (with add_profile only ascii key setting is supported, 
00103   therfore maximum key size is 13)
00104 */
00105 
00106 #define CC3000_MINIMAL_RX_SIZE      (130 + 1)
00107 #define CC3000_MAXIMAL_RX_SIZE      (1519 + 1)
00108 
00109 /*Defines for minimal and maximal TX buffer size.
00110   This buffer is used for sending events and data.
00111   The packet can not be longer than MTU size and CC3000 does not support 
00112   fragmentation. Note that the same buffer is used for transmission of the data
00113   and commands. That is why the minimum is defined.
00114   The calculation for the actual size of buffer for transmission is:
00115   Given the maximal data size MAX_DATA, the required buffer is:
00116   Using Sendto():
00117  
00118    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00119    + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00120  
00121   Using Send():
00122  
00123    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00124    + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00125  
00126   The 1 is used for the overrun detection */ 
00127 
00128 #define    CC3000_MINIMAL_TX_SIZE      (130 + 1)  
00129 #define    CC3000_MAXIMAL_TX_SIZE      (1519 + 1)
00130 
00131 //TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
00132 #ifdef CC3000_TINY_DRIVER
00133 #define TINY_CC3000_MAXIMAL_RX_SIZE 44
00134 #define TINY_CC3000_MAXIMAL_TX_SIZE 59
00135 #endif
00136 
00137 /*In order to determine your preferred buffer size, 
00138   change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
00139   the minimal and maximal specified above. 
00140   Note that the buffers are allocated by SPI.
00141   In case you change the size of those buffers, you might need also to change
00142   the linker file, since for example on MSP430 FRAM devices the buffers are
00143   allocated in the FRAM section that is allocated manually and not by IDE.
00144 */
00145   
00146 #ifndef CC3000_TINY_DRIVER
00147   
00148     #define CC3000_RX_BUFFER_SIZE   (CC3000_MAXIMAL_RX_SIZE)
00149     #define CC3000_TX_BUFFER_SIZE   (CC3000_MAXIMAL_TX_SIZE)
00150   
00151 //if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
00152 #else
00153     #define CC3000_RX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_RX_SIZE)
00154     #define CC3000_TX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_TX_SIZE)
00155 
00156 #endif  
00157 
00158 //*****************************************************************************
00159 //                  Compound Types
00160 //*****************************************************************************
00161 typedef long time_t_;
00162 typedef unsigned long clock_t_;
00163 typedef long suseconds_t;
00164 
00165 typedef struct timeval timeval;
00166 
00167 struct timeval 
00168 {
00169     time_t_         tv_sec;                  /* seconds */
00170     suseconds_t    tv_usec;                 /* microseconds */
00171 };
00172 
00173 typedef char *(*tFWPatches)(unsigned long *usLength);
00174 
00175 typedef char *(*tDriverPatches)(unsigned long *usLength);
00176 
00177 typedef char *(*tBootLoaderPatches)(unsigned long *usLength);
00178 
00179 typedef void (*tWlanCB)(long event_type, char * data, unsigned char length );
00180 
00181 typedef long (*tWlanReadInteruptPin)(void);
00182 
00183 typedef void (*tWlanInterruptEnable)(void);
00184 
00185 typedef void (*tWlanInterruptDisable)(void);
00186 
00187 typedef void (*tWriteWlanPin)(unsigned char val);
00188 
00189 typedef struct
00190 {
00191     unsigned short     usRxEventOpcode;
00192     unsigned short     usEventOrDataReceived;
00193     unsigned char     *pucReceivedData;
00194     unsigned char     *pucTxCommandBuffer;
00195 
00196     tFWPatches             sFWPatches;
00197     tDriverPatches         sDriverPatches;
00198     tBootLoaderPatches     sBootLoaderPatches;
00199     tWlanCB                 sWlanCB;
00200     tWlanReadInteruptPin  ReadWlanInterruptPin;
00201     tWlanInterruptEnable  WlanInterruptEnable;
00202     tWlanInterruptDisable WlanInterruptDisable;
00203     tWriteWlanPin         WriteWlanPin;
00204 
00205     signed long         slTransmitDataError;
00206     unsigned short     usNumberOfFreeBuffers;
00207     unsigned short     usSlBufferLength;
00208     unsigned short     usBufferSize;
00209     unsigned short     usRxDataPending;
00210 
00211     unsigned long    NumberOfSentPackets;
00212     unsigned long    NumberOfReleasedPackets;
00213 
00214     unsigned char     InformHostOnTxComplete;
00215 }sSimplLinkInformation;
00216 
00217 extern volatile sSimplLinkInformation tSLInformation;
00218 
00219 
00220 //*****************************************************************************
00221 // Prototypes for the APIs.
00222 //*****************************************************************************
00223 
00224 
00225 
00226 //*****************************************************************************
00227 //
00228 //!  SimpleLinkWaitEvent
00229 //!
00230 //!  @param  usOpcode      command operation code
00231 //!  @param  pRetParams    command return parameters
00232 //!
00233 //!  @return               none
00234 //!
00235 //!  @brief                Wait for event, pass it to the hci_event_handler and
00236 //!                        update the event opcode in a global variable.
00237 //
00238 //*****************************************************************************
00239 
00240 extern void SimpleLinkWaitEvent(unsigned short usOpcode, long *pRetParams);
00241 
00242 //*****************************************************************************
00243 //
00244 //!  SimpleLinkWaitData
00245 //!
00246 //!  @param  pBuf       data buffer
00247 //!  @param  from       from information
00248 //!  @param  fromlen      from information length
00249 //!
00250 //!  @return               none
00251 //!
00252 //!  @brief                Wait for data, pass it to the hci_event_handler
00253 //!                        and update in a global variable that there is 
00254 //!                           data to read.
00255 //
00256 //*****************************************************************************
00257 
00258 extern void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
00259 
00260 //*****************************************************************************
00261 //
00262 //!  UINT32_TO_STREAM_f
00263 //!
00264 //!  \param  p       pointer to the new stream
00265 //!  \param  u32     pointer to the 32 bit
00266 //!
00267 //!  \return               pointer to the new stream
00268 //!
00269 //!  \brief                This function is used for copying 32 bit to stream
00270 //!                           while converting to little endian format.
00271 //
00272 //*****************************************************************************
00273 
00274 extern unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32);
00275 
00276 //*****************************************************************************
00277 //
00278 //!  UINT16_TO_STREAM_f
00279 //!
00280 //!  \param  p       pointer to the new stream
00281 //!  \param  u32     pointer to the 16 bit
00282 //!
00283 //!  \return               pointer to the new stream
00284 //!
00285 //!  \brief               This function is used for copying 16 bit to stream 
00286 //!                       while converting to little endian format.
00287 //
00288 //*****************************************************************************
00289 
00290 extern unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16);
00291 
00292 //*****************************************************************************
00293 //
00294 //!  STREAM_TO_UINT16_f
00295 //!
00296 //!  \param  p          pointer to the stream
00297 //!  \param  offset     offset in the stream
00298 //!
00299 //!  \return               pointer to the new 16 bit
00300 //!
00301 //!  \brief               This function is used for copying received stream to 
00302 //!                       16 bit in little endian format.
00303 //
00304 //*****************************************************************************
00305 
00306 extern unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset);
00307 
00308 //*****************************************************************************
00309 //
00310 //!  STREAM_TO_UINT32_f
00311 //!
00312 //!  \param  p          pointer to the stream
00313 //!  \param  offset     offset in the stream
00314 //!
00315 //!  \return               pointer to the new 32 bit
00316 //!
00317 //!  \brief               This function is used for copying received stream to
00318 //!                       32 bit in little endian format.
00319 //
00320 //*****************************************************************************
00321 
00322 extern unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset);
00323 
00324 
00325 //*****************************************************************************
00326 //                    COMMON MACROs
00327 //*****************************************************************************
00328 
00329 
00330 //This macro is used for copying 8 bit to stream while converting to little endian format.
00331 #define UINT8_TO_STREAM(_p, _val)    {*(_p)++ = (_val);}
00332 //This macro is used for copying 16 bit to stream while converting to little endian format.
00333 #define UINT16_TO_STREAM(_p, _u16)    (UINT16_TO_STREAM_f(_p, _u16))
00334 //This macro is used for copying 32 bit to stream while converting to little endian format.
00335 #define UINT32_TO_STREAM(_p, _u32)    (UINT32_TO_STREAM_f(_p, _u32))
00336 //This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
00337 #define ARRAY_TO_STREAM(p, a, l)     {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((unsigned char *) a)[_i];}
00338 //This macro is used for copying received stream to 8 bit in little endian format.
00339 #define STREAM_TO_UINT8(_p, _offset, _u8)    {_u8 = (unsigned char)(*(_p + _offset));}
00340 //This macro is used for copying received stream to 16 bit in little endian format.
00341 #define STREAM_TO_UINT16(_p, _offset, _u16)    {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
00342 //This macro is used for copying received stream to 32 bit in little endian format.
00343 #define STREAM_TO_UINT32(_p, _offset, _u32)    {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
00344 #define STREAM_TO_STREAM(p, a, l)     {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((unsigned char *) p)[_i];}
00345 
00346 
00347 
00348 
00349 //*****************************************************************************
00350 //
00351 // Mark the end of the C bindings section for C++ compilers.
00352 //
00353 //*****************************************************************************
00354 #ifdef  __cplusplus
00355 }
00356 #endif // __cplusplus
00357 
00358 #endif // __COMMON_H__
00359