A Port of TI's Webserver for the CC3000

Dependencies:   mbed

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 #define WLAN_DISABLE     (0)
00069 
00070 #define MAC_ADDR_LEN    (6)
00071 
00072 #define SP_PORTION_SIZE (32)
00073   
00074 /*Defines for minimal and maximal RX buffer size. This size includes the spi 
00075   header and hci header.
00076   The maximal buffer size derives from:
00077     MTU + HCI header + SPI header + sendto() agrs size
00078   The minimum buffer size derives from:
00079     HCI header + SPI header + max args size
00080 
00081   This buffer is used for receiving events and data.
00082   The packet can not be longer than MTU size and CC3000 does not support 
00083   fragmentation. Note that the same buffer is used for reception of the data 
00084   and events from CC3000. That is why the minimum is defined. 
00085   The calculation for the actual size of buffer for reception is:
00086   Given the maximal data size MAX_DATA that is expected to be received by
00087   application, the required buffer is:
00088   Using recv() or recvfrom():
00089  
00090     max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
00091     + ucArgsize + 1)
00092  
00093   Using gethostbyname() with minimal buffer size will limit the host name
00094   returned to 99 bytes only.
00095   The 1 is used for the overrun detection 
00096 
00097   Buffer size increased to 130 following the add_profile() with WEP security
00098   which requires TX buffer size of 130 bytes: 
00099   HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
00100   MAX SSID LEN = 32 
00101   MAX SSID LEN = 13 (with add_profile only ascii key setting is supported, 
00102   therfore maximum key size is 13)
00103 */
00104 
00105 #define CC3000_MINIMAL_RX_SIZE      (130 + 1)
00106 #define CC3000_MAXIMAL_RX_SIZE      (1519 + 1)
00107 
00108 /*Defines for minimal and maximal TX buffer size.
00109   This buffer is used for sending events and data.
00110   The packet can not be longer than MTU size and CC3000 does not support 
00111   fragmentation. Note that the same buffer is used for transmission of the data
00112   and commands. That is why the minimum is defined.
00113   The calculation for the actual size of buffer for transmission is:
00114   Given the maximal data size MAX_DATA, the required buffer is:
00115   Using Sendto():
00116  
00117    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00118    + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00119  
00120   Using Send():
00121  
00122    max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
00123    + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
00124  
00125   The 1 is used for the overrun detection */ 
00126 
00127 #define CC3000_MINIMAL_TX_SIZE      (130 + 1)  
00128 #define CC3000_MAXIMAL_TX_SIZE      (1519 + 1)
00129 
00130 //TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
00131 #ifdef CC3000_TINY_DRIVER
00132 #define TINY_CC3000_MAXIMAL_RX_SIZE 44
00133 #define TINY_CC3000_MAXIMAL_TX_SIZE 59
00134 #endif
00135 
00136 /*In order to determine your preferred buffer size, 
00137   change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
00138   the minimal and maximal specified above. 
00139   Note that the buffers are allocated by SPI.
00140   In case you change the size of those buffers, you might need also to change
00141   the linker file, since for example on MSP430 FRAM devices the buffers are
00142   allocated in the FRAM section that is allocated manually and not by IDE.
00143 */
00144   
00145 #ifndef CC3000_TINY_DRIVER
00146   
00147     #define CC3000_RX_BUFFER_SIZE   (CC3000_MAXIMAL_RX_SIZE)
00148     #define CC3000_TX_BUFFER_SIZE   (CC3000_MAXIMAL_TX_SIZE)
00149   
00150 //if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
00151 #else
00152     #define CC3000_RX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_RX_SIZE)
00153     #define CC3000_TX_BUFFER_SIZE   (TINY_CC3000_MAXIMAL_TX_SIZE)
00154 
00155 #endif  
00156 
00157 //*****************************************************************************
00158 //                  Compound Types
00159 //*****************************************************************************
00160 typedef long time_t_;
00161 typedef unsigned long clock_t_;
00162 typedef long suseconds_t;
00163 
00164 typedef struct timeval timeval;
00165 
00166 struct timeval 
00167 {
00168     time_t_        tv_sec;                  /* seconds */
00169     suseconds_t    tv_usec;                 /* microseconds */
00170 };
00171 
00172 typedef char *(*tFWPatches)(unsigned long *usLength);
00173 
00174 typedef char *(*tDriverPatches)(unsigned long *usLength);
00175 
00176 typedef char *(*tBootLoaderPatches)(unsigned long *usLength);
00177 
00178 typedef void (*tWlanCB)(long event_type, char * data, unsigned char length );
00179 
00180 typedef int (*tWlanReadInteruptPin)(void);
00181 
00182 typedef void (*tWlanInterruptEnable)(void);
00183 
00184 typedef void (*tWlanInterruptDisable)(void);
00185 
00186 typedef void (*tWriteWlanPin)(unsigned char val);
00187 
00188 typedef struct
00189 {
00190     unsigned short   usRxEventOpcode;
00191     unsigned short   usEventOrDataReceived;
00192     unsigned char   *pucReceivedData;
00193     unsigned char   *pucTxCommandBuffer;
00194 
00195     tFWPatches          sFWPatches;
00196     tDriverPatches      sDriverPatches;
00197     tBootLoaderPatches  sBootLoaderPatches;
00198     tWlanCB             sWlanCB;
00199     tWlanReadInteruptPin  ReadWlanInterruptPin;
00200     tWlanInterruptEnable  WlanInterruptEnable;
00201     tWlanInterruptDisable WlanInterruptDisable;
00202     tWriteWlanPin         WriteWlanPin;
00203 
00204     signed long      slTransmitDataError;
00205     unsigned short   usNumberOfFreeBuffers;
00206     unsigned short   usSlBufferLength;
00207     unsigned short   usBufferSize;
00208     unsigned short   usRxDataPending;
00209 
00210     unsigned long    NumberOfSentPackets;
00211     unsigned long    NumberOfReleasedPackets;
00212 
00213     unsigned char    InformHostOnTxComplete;
00214 }sSimplLinkInformation;
00215 
00216 extern volatile sSimplLinkInformation tSLInformation;
00217 
00218 
00219 //*****************************************************************************
00220 // Prototypes for the APIs.
00221 //*****************************************************************************
00222 
00223 
00224 
00225 //*****************************************************************************
00226 //
00227 //!  SimpleLinkWaitEvent
00228 //!
00229 //!  @param  usOpcode      command operation code
00230 //!  @param  pRetParams    command return parameters
00231 //!
00232 //!  @return               none
00233 //!
00234 //!  @brief                Wait for event, pass it to the hci_event_handler and
00235 //!                        update the event opcode in a global variable.
00236 //
00237 //*****************************************************************************
00238 
00239 extern void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams);
00240 
00241 //*****************************************************************************
00242 //
00243 //!  SimpleLinkWaitData
00244 //!
00245 //!  @param  pBuf       data buffer
00246 //!  @param  from       from information
00247 //!  @param  fromlen      from information length
00248 //!
00249 //!  @return               none
00250 //!
00251 //!  @brief                Wait for data, pass it to the hci_event_handler
00252 //!                        and update in a global variable that there is 
00253 //!                        data to read.
00254 //
00255 //*****************************************************************************
00256 
00257 extern void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
00258 
00259 //*****************************************************************************
00260 //
00261 //!  UINT32_TO_STREAM_f
00262 //!
00263 //!  \param  p       pointer to the new stream
00264 //!  \param  u32     pointer to the 32 bit
00265 //!
00266 //!  \return               pointer to the new stream
00267 //!
00268 //!  \brief                This function is used for copying 32 bit to stream
00269 //!                        while converting to little endian format.
00270 //
00271 //*****************************************************************************
00272 
00273 extern unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32);
00274 
00275 //*****************************************************************************
00276 //
00277 //!  UINT16_TO_STREAM_f
00278 //!
00279 //!  \param  p       pointer to the new stream
00280 //!  \param  u32     pointer to the 16 bit
00281 //!
00282 //!  \return               pointer to the new stream
00283 //!
00284 //!  \brief               This function is used for copying 16 bit to stream 
00285 //!                       while converting to little endian format.
00286 //
00287 //*****************************************************************************
00288 
00289 extern unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16);
00290 
00291 //*****************************************************************************
00292 //
00293 //!  STREAM_TO_UINT16_f
00294 //!
00295 //!  \param  p          pointer to the stream
00296 //!  \param  offset     offset in the stream
00297 //!
00298 //!  \return               pointer to the new 16 bit
00299 //!
00300 //!  \brief               This function is used for copying received stream to 
00301 //!                       16 bit in little endian format.
00302 //
00303 //*****************************************************************************
00304 
00305 extern unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset);
00306 
00307 //*****************************************************************************
00308 //
00309 //!  STREAM_TO_UINT32_f
00310 //!
00311 //!  \param  p          pointer to the stream
00312 //!  \param  offset     offset in the stream
00313 //!
00314 //!  \return               pointer to the new 32 bit
00315 //!
00316 //!  \brief               This function is used for copying received stream to
00317 //!                       32 bit in little endian format.
00318 //
00319 //*****************************************************************************
00320 
00321 extern unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset);
00322 
00323 
00324 //*****************************************************************************
00325 //                    COMMON MACROs
00326 //*****************************************************************************
00327 
00328 
00329 //This macro is used for copying 8 bit to stream while converting to little endian format.
00330 #define UINT8_TO_STREAM(_p, _val)   {*(_p)++ = (_val);}
00331 //This macro is used for copying 16 bit to stream while converting to little endian format.
00332 #define UINT16_TO_STREAM(_p, _u16)  (UINT16_TO_STREAM_f(_p, _u16))
00333 //This macro is used for copying 32 bit to stream while converting to little endian format.
00334 #define UINT32_TO_STREAM(_p, _u32)  (UINT32_TO_STREAM_f(_p, _u32))
00335 //This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
00336 #define ARRAY_TO_STREAM(p, a, l)    {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((unsigned char *) a)[_i];}
00337 //This macro is used for copying received stream to 8 bit in little endian format.
00338 #define STREAM_TO_UINT8(_p, _offset, _u8)   {_u8 = (unsigned char)(*(_p + _offset));}
00339 //This macro is used for copying received stream to 16 bit in little endian format.
00340 #define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
00341 //This macro is used for copying received stream to 32 bit in little endian format.
00342 #define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
00343 #define STREAM_TO_STREAM(p, a, l)   {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((unsigned char *) p)[_i];}
00344 
00345 
00346 
00347 
00348 //*****************************************************************************
00349 //
00350 // Mark the end of the C bindings section for C++ compilers.
00351 //
00352 //*****************************************************************************
00353 #ifdef  __cplusplus
00354 }
00355 #endif // __cplusplus
00356 
00357 #endif // __COMMON_H__
00358