SimpleLink API Reference Manual  1.11.1
 All Data Structures Files Functions Variables Typedefs Macros Groups
cc3000_common.h
Go to the documentation of this file.
1 /*****************************************************************************
2 *
3 * cc3000_common.h - CC3000 Host Driver Implementation.
4 * Copyright (C) 2011 Texas Instruments Incorporated - https://www.ti.com/
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 *****************************************************************************/
35 #ifndef __COMMON_H__
36 #define __COMMON_H__
37 
38 //******************************************************************************
39 // Include files
40 //******************************************************************************
41 #include <stdlib.h>
42 #include <errno.h>
43 #include <stdint.h>
44 
45 //*****************************************************************************
46 //
47 // If building with a C++ compiler, make all of the definitions in this header
48 // have a C binding.
49 //
50 //*****************************************************************************
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 //*****************************************************************************
56 // ERROR CODES
57 //*****************************************************************************
58 #define ESUCCESS 0
59 #define EFAIL -1
60 #define EERROR EFAIL
61 
62 //*****************************************************************************
63 // COMMON DEFINES
64 //*****************************************************************************
65 #define ERROR_SOCKET_INACTIVE -57
66 
67 #define WLAN_ENABLE (1)
68 #define WLAN_DISABLE (0)
69 
70 #define MAC_ADDR_LEN (6)
71 
72 #define SP_PORTION_SIZE (32)
73 
74 /*Defines for minimal and maximal RX buffer size. This size includes the spi
75  header and hci header.
76  The maximal buffer size derives from:
77  MTU + HCI header + SPI header + sendto() agrs size
78  The minimum buffer size derives from:
79  HCI header + SPI header + max args size
80 
81  This buffer is used for receiving events and data.
82  The packet can not be longer than MTU size and CC3000 does not support
83  fragmentation. Note that the same buffer is used for reception of the data
84  and events from CC3000. That is why the minimum is defined.
85  The calculation for the actual size of buffer for reception is:
86  Given the maximal data size MAX_DATA that is expected to be received by
87  application, the required buffer is:
88  Using recv() or recvfrom():
89 
90  max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
91  + ucArgsize + 1)
92 
93  Using gethostbyname() with minimal buffer size will limit the host name
94  returned to 99 bytes only.
95  The 1 is used for the overrun detection
96 
97  Buffer size increased to 130 following the add_profile() with WEP security
98  which requires TX buffer size of 130 bytes:
99  HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
100  MAX SSID LEN = 32
101  MAX SSID LEN = 13 (with add_profile only ascii key setting is supported,
102  therfore maximum key size is 13)
103 */
104 
105 #define CC3000_MINIMAL_RX_SIZE (130 + 1)
106 #define CC3000_MAXIMAL_RX_SIZE (1519 + 1)
107 
108 /*Defines for minimal and maximal TX buffer size.
109  This buffer is used for sending events and data.
110  The packet can not be longer than MTU size and CC3000 does not support
111  fragmentation. Note that the same buffer is used for transmission of the data
112  and commands. That is why the minimum is defined.
113  The calculation for the actual size of buffer for transmission is:
114  Given the maximal data size MAX_DATA, the required buffer is:
115  Using Sendto():
116 
117  max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
118  + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
119 
120  Using Send():
121 
122  max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
123  + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
124 
125  The 1 is used for the overrun detection */
126 
127 #define CC3000_MINIMAL_TX_SIZE (130 + 1)
128 #define CC3000_MAXIMAL_TX_SIZE (1519 + 1)
129 
130 //TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
131 #ifdef CC3000_TINY_DRIVER
132 #define TINY_CC3000_MAXIMAL_RX_SIZE 44
133 #define TINY_CC3000_MAXIMAL_TX_SIZE 59
134 #endif
135 
136 /*In order to determine your preferred buffer size,
137  change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
138  the minimal and maximal specified above.
139  Note that the buffers are allocated by SPI.
140  In case you change the size of those buffers, you might need also to change
141  the linker file, since for example on MSP430 FRAM devices the buffers are
142  allocated in the FRAM section that is allocated manually and not by IDE.
143 */
144 
145 #ifndef CC3000_TINY_DRIVER
146 
147  #define CC3000_RX_BUFFER_SIZE (CC3000_MINIMAL_RX_SIZE)
148  #define CC3000_TX_BUFFER_SIZE (CC3000_MINIMAL_TX_SIZE)
149 
150 //if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
151 #else
152  #define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE)
153  #define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE)
154 
155 #endif
156 
157 //*****************************************************************************
158 // Compound Types
159 //*****************************************************************************
160 typedef long time_t;
161 typedef unsigned long clock_t;
162 typedef long suseconds_t;
163 
164 typedef struct timeval timeval;
165 
166 struct timeval
167 {
168  time_t tv_sec; /* seconds */
169  suseconds_t tv_usec; /* microseconds */
170 };
171 
172 typedef char *(*tFWPatches)(unsigned long *usLength);
173 
174 typedef char *(*tDriverPatches)(unsigned long *usLength);
175 
176 typedef char *(*tBootLoaderPatches)(unsigned long *usLength);
177 
178 typedef void (*tWlanCB)(long event_type, char * data, unsigned char length );
179 
180 typedef long (*tWlanReadInteruptPin)(void);
181 
182 typedef void (*tWlanInterruptEnable)(void);
183 
184 typedef void (*tWlanInterruptDisable)(void);
185 
186 typedef void (*tWriteWlanPin)(unsigned char val);
187 
188 typedef struct
189 {
190  unsigned short usRxEventOpcode;
191  unsigned short usEventOrDataReceived;
192  unsigned char *pucReceivedData;
193  unsigned char *pucTxCommandBuffer;
194 
203 
204  signed long slTransmitDataError;
205  unsigned short usNumberOfFreeBuffers;
206  unsigned short usSlBufferLength;
207  unsigned short usBufferSize;
208  unsigned short usRxDataPending;
209 
210  unsigned long NumberOfSentPackets;
211  unsigned long NumberOfReleasedPackets;
212 
213  unsigned char InformHostOnTxComplete;
215 
216 extern volatile sSimplLinkInformation tSLInformation;
217 
218 
219 //*****************************************************************************
220 // Prototypes for the APIs.
221 //*****************************************************************************
222 
223 
224 
225 //*****************************************************************************
226 //
236 //
237 //*****************************************************************************
238 
239 extern void SimpleLinkWaitEvent(unsigned short usOpcode, void *pRetParams);
240 
241 //*****************************************************************************
242 //
254 //
255 //*****************************************************************************
256 
257 extern void SimpleLinkWaitData(unsigned char *pBuf, unsigned char *from, unsigned char *fromlen);
258 
259 //*****************************************************************************
260 //
270 //
271 //*****************************************************************************
272 
273 extern unsigned char* UINT32_TO_STREAM_f (unsigned char *p, unsigned long u32);
274 
275 //*****************************************************************************
276 //
286 //
287 //*****************************************************************************
288 
289 extern unsigned char* UINT16_TO_STREAM_f (unsigned char *p, unsigned short u16);
290 
291 //*****************************************************************************
292 //
302 //
303 //*****************************************************************************
304 
305 extern unsigned short STREAM_TO_UINT16_f(char* p, unsigned short offset);
306 
307 //*****************************************************************************
308 //
318 //
319 //*****************************************************************************
320 
321 extern unsigned long STREAM_TO_UINT32_f(char* p, unsigned short offset);
322 
323 
324 //*****************************************************************************
325 // COMMON MACROs
326 //*****************************************************************************
327 
328 
329 //This macro is used for copying 8 bit to stream while converting to little endian format.
330 #define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);}
331 //This macro is used for copying 16 bit to stream while converting to little endian format.
332 #define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16))
333 //This macro is used for copying 32 bit to stream while converting to little endian format.
334 #define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
335 //This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
336 #define ARRAY_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(p)++ = ((unsigned char *) a)[_i];}
337 //This macro is used for copying received stream to 8 bit in little endian format.
338 #define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (unsigned char)(*(_p + _offset));}
339 //This macro is used for copying received stream to 16 bit in little endian format.
340 #define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
341 //This macro is used for copying received stream to 32 bit in little endian format.
342 #define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
343 #define STREAM_TO_STREAM(p, a, l) {register short _i; for (_i = 0; _i < l; _i++) *(a)++= ((unsigned char *) p)[_i];}
344 
345 
346 
347 
348 //*****************************************************************************
349 //
350 // Mark the end of the C bindings section for C++ compilers.
351 //
352 //*****************************************************************************
353 #ifdef __cplusplus
354 }
355 #endif // __cplusplus
356 
357 #endif // __COMMON_H__