CC3000  1.14
 All Classes Functions Groups
cc3000_common.h
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 #include "data_types.h"
39 #include "error_codes.h"
40 
41 //******************************************************************************
42 // Include files
43 //******************************************************************************
44 #include <stdlib.h>
45 #include <errno.h>
46 #include <stdint.h>
47 
48 //*****************************************************************************
49 //
50 // If building with a C++ compiler, make all of the definitions in this header
51 // have a C binding.
52 //
53 //*****************************************************************************
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 //*****************************************************************************
59 // ERROR CODES
60 //*****************************************************************************
61 #define ESUCCESS 0
62 #define EFAIL -1
63 #define EERROR EFAIL
64 
65 //*****************************************************************************
66 // COMMON DEFINES
67 //*****************************************************************************
68 #define WLAN_ENABLE (1)
69 #define WLAN_DISABLE (0)
70 
71 #define MAC_ADDR_LEN (6)
72 
73 #define SP_PORTION_SIZE (32)
74 
75 /*Defines for minimal and maximal RX buffer size. This size includes the spi
76  header and hci header.
77  The maximal buffer size derives from:
78  MTU + HCI header + SPI header + sendto() agrs size
79  The minimum buffer size derives from:
80  HCI header + SPI header + max args size
81 
82  This buffer is used for receiving events and data.
83  The packet can not be longer than MTU size and CC3000 does not support
84  fragmentation. Note that the same buffer is used for reception of the data
85  and events from CC3000. That is why the minimum is defined.
86  The calculation for the actual size of buffer for reception is:
87  Given the maximal data size MAX_DATA that is expected to be received by
88  application, the required buffer is:
89  Using recv() or recvfrom():
90 
91  max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
92  + ucArgsize + 1)
93 
94  Using gethostbyname() with minimal buffer size will limit the host name
95  returned to 99 bytes only.
96  The 1 is used for the overrun detection
97 
98  Buffer size increased to 130 following the add_profile() with WEP security
99  which requires TX buffer size of 130 bytes:
100  HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
101  MAX SSID LEN = 32
102  MAX SSID LEN = 13 (with add_profile only ascii key setting is supported,
103  therfore maximum key size is 13)
104 */
105 
106 #define CC3000_MINIMAL_RX_SIZE (130 + 1)
107 #define CC3000_MAXIMAL_RX_SIZE (511 + 1)
108 
109 /*Defines for minimal and maximal TX buffer size.
110  This buffer is used for sending events and data.
111  The packet can not be longer than MTU size and CC3000 does not support
112  fragmentation. Note that the same buffer is used for transmission of the data
113  and commands. That is why the minimum is defined.
114  The calculation for the actual size of buffer for transmission is:
115  Given the maximal data size MAX_DATA, the required buffer is:
116  Using Sendto():
117 
118  max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
119  + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
120 
121  Using Send():
122 
123  max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
124  + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
125 
126  The 1 is used for the overrun detection */
127 
128 #define CC3000_MINIMAL_TX_SIZE (130 + 1)
129 #define CC3000_MAXIMAL_TX_SIZE (511 + 1)
130 
131 //TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
132 #ifdef CC3000_TINY_DRIVER
133 #define TINY_CC3000_MAXIMAL_RX_SIZE 44
134 #define TINY_CC3000_MAXIMAL_TX_SIZE 59
135 #endif
136 
137 /*In order to determine your preferred buffer size,
138  change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
139  the minimal and maximal specified above.
140  Note that the buffers are allocated by SPI.
141  In case you change the size of those buffers, you might need also to change
142  the linker file, since for example on MSP430 FRAM devices the buffers are
143  allocated in the FRAM section that is allocated manually and not by IDE.
144 */
145 
146 #ifndef CC3000_TINY_DRIVER
147 
148 #ifdef MDNS_ADVERTISE_HOST
149  #define CC3000_RX_BUFFER_SIZE (CC3000_MAXIMAL_RX_SIZE)
150  #define CC3000_TX_BUFFER_SIZE (CC3000_MAXIMAL_TX_SIZE)
151 #else
152  #define CC3000_RX_BUFFER_SIZE (CC3000_MINIMAL_RX_SIZE)
153  #define CC3000_TX_BUFFER_SIZE (CC3000_MINIMAL_TX_SIZE)
154 #endif
155 
156 //if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
157 #else
158  #define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE)
159  #define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE)
160 
161 #endif
162 
163 //*****************************************************************************
164 // Compound Types
165 //*****************************************************************************
166 typedef INT32 time_t;
167 typedef UINT32 clock_t;
168 typedef INT32 suseconds_t;
169 
170 typedef struct timeval timeval;
171 
172 struct timeval
173 {
174  time_t tv_sec; /* seconds */
175  suseconds_t tv_usec; /* microseconds */
176 };
177 
178 typedef CHAR *(*tFWPatches)(UINT32 *usLength);
179 
180 typedef CHAR *(*tDriverPatches)(UINT32 *usLength);
181 
182 typedef CHAR *(*tBootLoaderPatches)(UINT32 *usLength);
183 
184 typedef void (*tWlanCB)(INT32 event_type, CHAR * data, UINT8 length );
185 
186 typedef INT32 (*tWlanReadInteruptPin)(void);
187 
188 typedef void (*tWlanInterruptEnable)(void);
189 
190 typedef void (*tWlanInterruptDisable)(void);
191 
192 typedef void (*tWriteWlanPin)(UINT8 val);
193 
194 typedef struct
195 {
196  UINT16 usRxEventOpcode;
197  UINT16 usEventOrDataReceived;
198  UINT8 *pucReceivedData;
199  UINT8 *pucTxCommandBuffer;
200 
201  tFWPatches sFWPatches;
202  tDriverPatches sDriverPatches;
203  tBootLoaderPatches sBootLoaderPatches;
204  tWlanCB sWlanCB;
205  tWlanReadInteruptPin ReadWlanInterruptPin;
206  tWlanInterruptEnable WlanInterruptEnable;
207  tWlanInterruptDisable WlanInterruptDisable;
208  tWriteWlanPin WriteWlanPin;
209 
210  INT32 slTransmitDataError;
211  UINT16 usNumberOfFreeBuffers;
212  UINT16 usSlBufferLength;
213  UINT16 usBufferSize;
214  UINT16 usRxDataPending;
215 
216  UINT32 NumberOfSentPackets;
217  UINT32 NumberOfReleasedPackets;
218 
219  UINT8 InformHostOnTxComplete;
221 
222 extern volatile sSimplLinkInformation tSLInformation;
223 
224 
225 //*****************************************************************************
226 // Prototypes for the APIs.
227 //*****************************************************************************
228 
229 
230 
231 //*****************************************************************************
232 //
242 //
243 //*****************************************************************************
244 
245 extern void SimpleLinkWaitEvent(UINT16 usOpcode, void *pRetParams);
246 
247 //*****************************************************************************
248 //
260 //
261 //*****************************************************************************
262 
263 extern void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen);
264 
265 //*****************************************************************************
266 //
276 //
277 //*****************************************************************************
278 
279 extern UINT8* UINT32_TO_STREAM_f (UINT8 *p, UINT32 u32);
280 
281 //*****************************************************************************
282 //
292 //
293 //*****************************************************************************
294 
295 extern UINT8* UINT16_TO_STREAM_f (UINT8 *p, UINT16 u16);
296 
297 //*****************************************************************************
298 //
308 //
309 //*****************************************************************************
310 
311 extern UINT16 STREAM_TO_UINT16_f(CHAR* p, UINT16 offset);
312 
313 //*****************************************************************************
314 //
324 //
325 //*****************************************************************************
326 
327 extern UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset);
328 
329 
330 //*****************************************************************************
331 // COMMON MACROs
332 //*****************************************************************************
333 
334 
335 //This macro is used for copying 8 bit to stream while converting to little endian format.
336 #define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);}
337 //This macro is used for copying 16 bit to stream while converting to little endian format.
338 #define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16))
339 //This macro is used for copying 32 bit to stream while converting to little endian format.
340 #define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
341 //This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
342 #define ARRAY_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(p)++ = ((UINT8 *) a)[_i];}
343 //This macro is used for copying received stream to 8 bit in little endian format.
344 #define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (UINT8)(*(_p + _offset));}
345 //This macro is used for copying received stream to 16 bit in little endian format.
346 #define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
347 //This macro is used for copying received stream to 32 bit in little endian format.
348 #define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
349 #define STREAM_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(a)++= ((UINT8 *) p)[_i];}
350 
351 
352 
353 
354 //*****************************************************************************
355 //
356 // Mark the end of the C bindings section for C++ compilers.
357 //
358 //*****************************************************************************
359 #ifdef __cplusplus
360 }
361 #endif // __cplusplus
362 
363 #endif // __COMMON_H__
void SimpleLinkWaitEvent(UINT16 usOpcode, void *pRetParams)
Wait for event, pass it to the hci_event_handler and update the event opcode in a global variable...
Definition: evnt_handler.c:829
UINT8 * UINT32_TO_STREAM_f(UINT8 *p, UINT32 u32)
This function is used for copying 32 bit to stream while converting to little endian format...
Definition: cc3000_common.c:84
UINT32 STREAM_TO_UINT32_f(CHAR *p, UINT16 offset)
This function is used for copying received stream to 32 bit in little endian format.
Definition: cc3000_common.c:148
void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen)
Wait for data, pass it to the hci_event_handler and update in a global variable that there is data to...
Definition: evnt_handler.c:853
Definition: cc3000_common.h:172
UINT8 * UINT16_TO_STREAM_f(UINT8 *p, UINT16 u16)
This function is used for copying 16 bit to stream while converting to little endian format...
Definition: cc3000_common.c:107
UINT16 STREAM_TO_UINT16_f(CHAR *p, UINT16 offset)
This function is used for copying received stream to 16 bit in little endian format.
Definition: cc3000_common.c:128