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