2014-04-30 20:47:50 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* cc3000_common.h - CC3000 Host Driver Implementation.
|
|
|
|
* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
2014-09-26 00:56:45 +01:00
|
|
|
* documentation and/or other materials provided with the
|
2014-04-30 20:47:50 +01:00
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* Neither the name of Texas Instruments Incorporated nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
2014-09-26 00:56:45 +01:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2014-04-30 20:47:50 +01:00
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2014-09-26 00:56:45 +01:00
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2014-04-30 20:47:50 +01:00
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
2014-09-26 00:56:45 +01:00
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
2014-04-30 20:47:50 +01:00
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
2014-09-30 23:25:42 +01:00
|
|
|
#ifndef __CC3000_COMMON_H__
|
|
|
|
#define __CC3000_COMMON_H__
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
#include "data_types.h"
|
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
//******************************************************************************
|
|
|
|
// Include files
|
|
|
|
//******************************************************************************
|
2014-09-26 00:56:45 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-30 23:25:42 +01:00
|
|
|
//*****************************************************************************
|
|
|
|
// Prefix exported names to avoid name clash
|
|
|
|
//*****************************************************************************
|
|
|
|
#define CC3000_EXPORT(name) cc3000_ ## name
|
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
// If building with a C++ compiler, make all of the definitions in this header
|
|
|
|
// have a C binding.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2014-09-30 23:25:42 +01:00
|
|
|
extern int CC3000_EXPORT(errno);
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
//*****************************************************************************
|
|
|
|
// ERROR CODES
|
|
|
|
//*****************************************************************************
|
|
|
|
#define ESUCCESS 0
|
|
|
|
#define EFAIL -1
|
|
|
|
#define EERROR EFAIL
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// COMMON DEFINES
|
|
|
|
//*****************************************************************************
|
2014-09-26 00:56:45 +01:00
|
|
|
#define ERROR_SOCKET_INACTIVE -57
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
#define WLAN_ENABLE (1)
|
2014-04-30 20:47:50 +01:00
|
|
|
#define WLAN_DISABLE (0)
|
|
|
|
|
|
|
|
#define MAC_ADDR_LEN (6)
|
|
|
|
|
|
|
|
#define SP_PORTION_SIZE (32)
|
2014-09-26 00:56:45 +01:00
|
|
|
|
|
|
|
/*Defines for minimal and maximal RX buffer size. This size includes the spi
|
2014-04-30 20:47:50 +01:00
|
|
|
header and hci header.
|
|
|
|
The maximal buffer size derives from:
|
|
|
|
MTU + HCI header + SPI header + sendto() agrs size
|
|
|
|
The minimum buffer size derives from:
|
|
|
|
HCI header + SPI header + max args size
|
|
|
|
|
|
|
|
This buffer is used for receiving events and data.
|
2014-09-26 00:56:45 +01:00
|
|
|
The packet can not be longer than MTU size and CC3000 does not support
|
|
|
|
fragmentation. Note that the same buffer is used for reception of the data
|
|
|
|
and events from CC3000. That is why the minimum is defined.
|
2014-04-30 20:47:50 +01:00
|
|
|
The calculation for the actual size of buffer for reception is:
|
|
|
|
Given the maximal data size MAX_DATA that is expected to be received by
|
|
|
|
application, the required buffer is:
|
|
|
|
Using recv() or recvfrom():
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
|
|
|
|
+ ucArgsize + 1)
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
Using gethostbyname() with minimal buffer size will limit the host name
|
|
|
|
returned to 99 bytes only.
|
2014-09-26 00:56:45 +01:00
|
|
|
The 1 is used for the overrun detection
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
Buffer size increased to 130 following the add_profile() with WEP security
|
2014-09-26 00:56:45 +01:00
|
|
|
which requires TX buffer size of 130 bytes:
|
2014-04-30 20:47:50 +01:00
|
|
|
HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
|
2014-09-26 00:56:45 +01:00
|
|
|
MAX SSID LEN = 32
|
|
|
|
MAX SSID LEN = 13 (with add_profile only ascii key setting is supported,
|
2014-04-30 20:47:50 +01:00
|
|
|
therfore maximum key size is 13)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define CC3000_MINIMAL_RX_SIZE (130 + 1)
|
|
|
|
#define CC3000_MAXIMAL_RX_SIZE (1519 + 1)
|
|
|
|
|
|
|
|
/*Defines for minimal and maximal TX buffer size.
|
|
|
|
This buffer is used for sending events and data.
|
2014-09-26 00:56:45 +01:00
|
|
|
The packet can not be longer than MTU size and CC3000 does not support
|
2014-04-30 20:47:50 +01:00
|
|
|
fragmentation. Note that the same buffer is used for transmission of the data
|
|
|
|
and commands. That is why the minimum is defined.
|
|
|
|
The calculation for the actual size of buffer for transmission is:
|
|
|
|
Given the maximal data size MAX_DATA, the required buffer is:
|
|
|
|
Using Sendto():
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
|
|
|
|
+ SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
Using Send():
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
|
|
|
|
+ HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
|
2014-09-26 00:56:45 +01:00
|
|
|
|
|
|
|
The 1 is used for the overrun detection */
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
#define CC3000_MINIMAL_TX_SIZE (130 + 1)
|
2014-04-30 20:47:50 +01:00
|
|
|
#define CC3000_MAXIMAL_TX_SIZE (1519 + 1)
|
|
|
|
|
|
|
|
//TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
|
|
|
|
#ifdef CC3000_TINY_DRIVER
|
|
|
|
#define TINY_CC3000_MAXIMAL_RX_SIZE 44
|
|
|
|
#define TINY_CC3000_MAXIMAL_TX_SIZE 59
|
|
|
|
#endif
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
/*In order to determine your preferred buffer size,
|
2014-04-30 20:47:50 +01:00
|
|
|
change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
|
2014-09-26 00:56:45 +01:00
|
|
|
the minimal and maximal specified above.
|
2014-04-30 20:47:50 +01:00
|
|
|
Note that the buffers are allocated by SPI.
|
|
|
|
In case you change the size of those buffers, you might need also to change
|
|
|
|
the linker file, since for example on MSP430 FRAM devices the buffers are
|
|
|
|
allocated in the FRAM section that is allocated manually and not by IDE.
|
|
|
|
*/
|
2014-09-26 00:56:45 +01:00
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
#ifndef CC3000_TINY_DRIVER
|
2014-09-26 00:56:45 +01:00
|
|
|
|
|
|
|
#define CC3000_RX_BUFFER_SIZE (CC3000_MAXIMAL_RX_SIZE)
|
|
|
|
#define CC3000_TX_BUFFER_SIZE (CC3000_MAXIMAL_TX_SIZE)
|
|
|
|
|
2014-04-30 20:47:50 +01:00
|
|
|
//if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
|
|
|
|
#else
|
|
|
|
#define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE)
|
|
|
|
#define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE)
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
#endif
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Compound Types
|
|
|
|
//*****************************************************************************
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef INT32 time_t;
|
|
|
|
typedef UINT32 clock_t;
|
|
|
|
typedef INT32 suseconds_t;
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
typedef struct timeval timeval;
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
struct timeval
|
2014-04-30 20:47:50 +01:00
|
|
|
{
|
|
|
|
time_t tv_sec; /* seconds */
|
|
|
|
suseconds_t tv_usec; /* microseconds */
|
|
|
|
};
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef CHAR *(*tFWPatches)(UINT32 *usLength);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef CHAR *(*tDriverPatches)(UINT32 *usLength);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef CHAR *(*tBootLoaderPatches)(UINT32 *usLength);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef void (*tWlanCB)(INT32 event_type, CHAR * data, UINT8 length );
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef INT32 (*tWlanReadInteruptPin)(void);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
typedef void (*tWlanInterruptEnable)(void);
|
|
|
|
|
|
|
|
typedef void (*tWlanInterruptDisable)(void);
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
typedef void (*tWriteWlanPin)(UINT8 val);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2014-09-26 00:56:45 +01:00
|
|
|
UINT16 usRxEventOpcode;
|
|
|
|
UINT16 usEventOrDataReceived;
|
|
|
|
UINT8 *pucReceivedData;
|
|
|
|
UINT8 *pucTxCommandBuffer;
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
tFWPatches sFWPatches;
|
|
|
|
tDriverPatches sDriverPatches;
|
|
|
|
tBootLoaderPatches sBootLoaderPatches;
|
|
|
|
tWlanCB sWlanCB;
|
|
|
|
tWlanReadInteruptPin ReadWlanInterruptPin;
|
|
|
|
tWlanInterruptEnable WlanInterruptEnable;
|
|
|
|
tWlanInterruptDisable WlanInterruptDisable;
|
|
|
|
tWriteWlanPin WriteWlanPin;
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
INT32 slTransmitDataError;
|
|
|
|
UINT16 usNumberOfFreeBuffers;
|
|
|
|
UINT16 usSlBufferLength;
|
|
|
|
UINT16 usBufferSize;
|
|
|
|
UINT16 usRxDataPending;
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
UINT32 NumberOfSentPackets;
|
|
|
|
UINT32 NumberOfReleasedPackets;
|
2014-04-30 20:47:50 +01:00
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
UINT8 InformHostOnTxComplete;
|
2014-04-30 20:47:50 +01:00
|
|
|
}sSimplLinkInformation;
|
|
|
|
|
|
|
|
extern volatile sSimplLinkInformation tSLInformation;
|
|
|
|
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// Prototypes for the APIs.
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! SimpleLinkWaitEvent
|
|
|
|
//!
|
|
|
|
//! @param usOpcode command operation code
|
|
|
|
//! @param pRetParams command return parameters
|
|
|
|
//!
|
|
|
|
//! @return none
|
|
|
|
//!
|
|
|
|
//! @brief Wait for event, pass it to the hci_event_handler and
|
|
|
|
//! update the event opcode in a global variable.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern void SimpleLinkWaitEvent(UINT16 usOpcode, void *pRetParams);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! SimpleLinkWaitData
|
|
|
|
//!
|
|
|
|
//! @param pBuf data buffer
|
|
|
|
//! @param from from information
|
|
|
|
//! @param fromlen from information length
|
|
|
|
//!
|
|
|
|
//! @return none
|
|
|
|
//!
|
|
|
|
//! @brief Wait for data, pass it to the hci_event_handler
|
2014-09-26 00:56:45 +01:00
|
|
|
//! and update in a global variable that there is
|
2014-04-30 20:47:50 +01:00
|
|
|
//! data to read.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! UINT32_TO_STREAM_f
|
|
|
|
//!
|
|
|
|
//! \param p pointer to the new stream
|
|
|
|
//! \param u32 pointer to the 32 bit
|
|
|
|
//!
|
|
|
|
//! \return pointer to the new stream
|
|
|
|
//!
|
|
|
|
//! \brief This function is used for copying 32 bit to stream
|
|
|
|
//! while converting to little endian format.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern UINT8* UINT32_TO_STREAM_f (UINT8 *p, UINT32 u32);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! UINT16_TO_STREAM_f
|
|
|
|
//!
|
|
|
|
//! \param p pointer to the new stream
|
|
|
|
//! \param u32 pointer to the 16 bit
|
|
|
|
//!
|
|
|
|
//! \return pointer to the new stream
|
|
|
|
//!
|
2014-09-26 00:56:45 +01:00
|
|
|
//! \brief This function is used for copying 16 bit to stream
|
2014-04-30 20:47:50 +01:00
|
|
|
//! while converting to little endian format.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern UINT8* UINT16_TO_STREAM_f (UINT8 *p, UINT16 u16);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! STREAM_TO_UINT16_f
|
|
|
|
//!
|
|
|
|
//! \param p pointer to the stream
|
|
|
|
//! \param offset offset in the stream
|
|
|
|
//!
|
|
|
|
//! \return pointer to the new 16 bit
|
|
|
|
//!
|
2014-09-26 00:56:45 +01:00
|
|
|
//! \brief This function is used for copying received stream to
|
2014-04-30 20:47:50 +01:00
|
|
|
//! 16 bit in little endian format.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern UINT16 STREAM_TO_UINT16_f(CHAR* p, UINT16 offset);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
//! STREAM_TO_UINT32_f
|
|
|
|
//!
|
|
|
|
//! \param p pointer to the stream
|
|
|
|
//! \param offset offset in the stream
|
|
|
|
//!
|
|
|
|
//! \return pointer to the new 32 bit
|
|
|
|
//!
|
|
|
|
//! \brief This function is used for copying received stream to
|
|
|
|
//! 32 bit in little endian format.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
|
2014-09-26 00:56:45 +01:00
|
|
|
extern UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset);
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
// COMMON MACROs
|
|
|
|
//*****************************************************************************
|
|
|
|
|
|
|
|
|
|
|
|
//This macro is used for copying 8 bit to stream while converting to little endian format.
|
|
|
|
#define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);}
|
|
|
|
//This macro is used for copying 16 bit to stream while converting to little endian format.
|
|
|
|
#define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16))
|
|
|
|
//This macro is used for copying 32 bit to stream while converting to little endian format.
|
|
|
|
#define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
|
|
|
|
//This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
|
2014-09-26 00:56:45 +01:00
|
|
|
#define ARRAY_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(p)++ = ((UINT8 *) a)[_i];}
|
2014-04-30 20:47:50 +01:00
|
|
|
//This macro is used for copying received stream to 8 bit in little endian format.
|
2014-09-26 00:56:45 +01:00
|
|
|
#define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (UINT8)(*(_p + _offset));}
|
2014-04-30 20:47:50 +01:00
|
|
|
//This macro is used for copying received stream to 16 bit in little endian format.
|
|
|
|
#define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
|
|
|
|
//This macro is used for copying received stream to 32 bit in little endian format.
|
|
|
|
#define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
|
2014-09-26 00:56:45 +01:00
|
|
|
#define STREAM_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(a)++= ((UINT8 *) p)[_i];}
|
2014-04-30 20:47:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//*****************************************************************************
|
|
|
|
//
|
|
|
|
// Mark the end of the C bindings section for C++ compilers.
|
|
|
|
//
|
|
|
|
//*****************************************************************************
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif // __cplusplus
|
|
|
|
|
2014-09-30 23:25:42 +01:00
|
|
|
#endif // __CC3000_COMMON_H__
|