cc3000_common.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*****************************************************************************
  2. *
  3. * cc3000_common.h - CC3000 Host Driver Implementation.
  4. * Copyright (C) 2011 Texas Instruments Incorporated - http://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 __CC3000_COMMON_H__
  36. #define __CC3000_COMMON_H__
  37. #include "data_types.h"
  38. //******************************************************************************
  39. // Include files
  40. //******************************************************************************
  41. #include <stdlib.h>
  42. #include <stdint.h>
  43. //*****************************************************************************
  44. // Prefix exported names to avoid name clash
  45. //*****************************************************************************
  46. #define CC3000_EXPORT(name) cc3000_ ## name
  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. extern int CC3000_EXPORT(errno);
  57. //*****************************************************************************
  58. // ERROR CODES
  59. //*****************************************************************************
  60. #define ESUCCESS 0
  61. #define EFAIL -1
  62. #define EERROR EFAIL
  63. //*****************************************************************************
  64. // COMMON DEFINES
  65. //*****************************************************************************
  66. #define ERROR_SOCKET_INACTIVE -57
  67. #define WLAN_ENABLE (1)
  68. #define WLAN_DISABLE (0)
  69. #define MAC_ADDR_LEN (6)
  70. #define SP_PORTION_SIZE (32)
  71. /*Defines for minimal and maximal RX buffer size. This size includes the spi
  72. header and hci header.
  73. The maximal buffer size derives from:
  74. MTU + HCI header + SPI header + sendto() agrs size
  75. The minimum buffer size derives from:
  76. HCI header + SPI header + max args size
  77. This buffer is used for receiving events and data.
  78. The packet can not be longer than MTU size and CC3000 does not support
  79. fragmentation. Note that the same buffer is used for reception of the data
  80. and events from CC3000. That is why the minimum is defined.
  81. The calculation for the actual size of buffer for reception is:
  82. Given the maximal data size MAX_DATA that is expected to be received by
  83. application, the required buffer is:
  84. Using recv() or recvfrom():
  85. max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen
  86. + ucArgsize + 1)
  87. Using gethostbyname() with minimal buffer size will limit the host name
  88. returned to 99 bytes only.
  89. The 1 is used for the overrun detection
  90. Buffer size increased to 130 following the add_profile() with WEP security
  91. which requires TX buffer size of 130 bytes:
  92. HEADERS_SIZE_EVNT + WLAN_ADD_PROFILE_WEP_PARAM_LEN + MAX SSID LEN + 4 * MAX KEY LEN = 130
  93. MAX SSID LEN = 32
  94. MAX SSID LEN = 13 (with add_profile only ascii key setting is supported,
  95. therfore maximum key size is 13)
  96. */
  97. #define CC3000_MINIMAL_RX_SIZE (130 + 1)
  98. #define CC3000_MAXIMAL_RX_SIZE (1519 + 1)
  99. /*Defines for minimal and maximal TX buffer size.
  100. This buffer is used for sending events and data.
  101. The packet can not be longer than MTU size and CC3000 does not support
  102. fragmentation. Note that the same buffer is used for transmission of the data
  103. and commands. That is why the minimum is defined.
  104. The calculation for the actual size of buffer for transmission is:
  105. Given the maximal data size MAX_DATA, the required buffer is:
  106. Using Sendto():
  107. max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
  108. + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
  109. Using Send():
  110. max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
  111. + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
  112. The 1 is used for the overrun detection */
  113. #define CC3000_MINIMAL_TX_SIZE (130 + 1)
  114. #define CC3000_MAXIMAL_TX_SIZE (1519 + 1)
  115. //TX and RX buffer sizes, allow to receive and transmit maximum data at length 8.
  116. #ifdef CC3000_TINY_DRIVER
  117. #define TINY_CC3000_MAXIMAL_RX_SIZE 44
  118. #define TINY_CC3000_MAXIMAL_TX_SIZE 59
  119. #endif
  120. /*In order to determine your preferred buffer size,
  121. change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
  122. the minimal and maximal specified above.
  123. Note that the buffers are allocated by SPI.
  124. In case you change the size of those buffers, you might need also to change
  125. the linker file, since for example on MSP430 FRAM devices the buffers are
  126. allocated in the FRAM section that is allocated manually and not by IDE.
  127. */
  128. #ifndef CC3000_TINY_DRIVER
  129. #define CC3000_RX_BUFFER_SIZE (CC3000_MAXIMAL_RX_SIZE)
  130. #define CC3000_TX_BUFFER_SIZE (CC3000_MAXIMAL_TX_SIZE)
  131. //if defined TINY DRIVER we use smaller RX and TX buffer in order to minimize RAM consumption
  132. #else
  133. #define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE)
  134. #define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE)
  135. #endif
  136. //*****************************************************************************
  137. // Compound Types
  138. //*****************************************************************************
  139. typedef INT32 time_t;
  140. typedef UINT32 clock_t;
  141. typedef INT32 suseconds_t;
  142. typedef struct cc3000_timeval cc3000_timeval;
  143. struct cc3000_timeval
  144. {
  145. time_t tv_sec; /* seconds */
  146. suseconds_t tv_usec; /* microseconds */
  147. };
  148. typedef CHAR *(*tFWPatches)(UINT32 *usLength);
  149. typedef CHAR *(*tDriverPatches)(UINT32 *usLength);
  150. typedef CHAR *(*tBootLoaderPatches)(UINT32 *usLength);
  151. typedef void (*tWlanCB)(INT32 event_type, CHAR * data, UINT8 length );
  152. typedef INT32 (*tWlanReadInteruptPin)(void);
  153. typedef void (*tWlanInterruptEnable)(void);
  154. typedef void (*tWlanInterruptDisable)(void);
  155. typedef void (*tWriteWlanPin)(UINT8 val);
  156. typedef struct
  157. {
  158. UINT16 usRxEventOpcode;
  159. UINT16 usEventOrDataReceived;
  160. UINT8 *pucReceivedData;
  161. UINT8 *pucTxCommandBuffer;
  162. tFWPatches sFWPatches;
  163. tDriverPatches sDriverPatches;
  164. tBootLoaderPatches sBootLoaderPatches;
  165. tWlanCB sWlanCB;
  166. tWlanReadInteruptPin ReadWlanInterruptPin;
  167. tWlanInterruptEnable WlanInterruptEnable;
  168. tWlanInterruptDisable WlanInterruptDisable;
  169. tWriteWlanPin WriteWlanPin;
  170. INT32 slTransmitDataError;
  171. UINT16 usNumberOfFreeBuffers;
  172. UINT16 usSlBufferLength;
  173. UINT16 usBufferSize;
  174. UINT16 usRxDataPending;
  175. UINT32 NumberOfSentPackets;
  176. UINT32 NumberOfReleasedPackets;
  177. UINT8 InformHostOnTxComplete;
  178. }sSimplLinkInformation;
  179. extern volatile sSimplLinkInformation tSLInformation;
  180. //*****************************************************************************
  181. // Prototypes for the APIs.
  182. //*****************************************************************************
  183. //*****************************************************************************
  184. //
  185. //! SimpleLinkWaitEvent
  186. //!
  187. //! @param usOpcode command operation code
  188. //! @param pRetParams command return parameters
  189. //!
  190. //! @return none
  191. //!
  192. //! @brief Wait for event, pass it to the hci_event_handler and
  193. //! update the event opcode in a global variable.
  194. //
  195. //*****************************************************************************
  196. extern void SimpleLinkWaitEvent(UINT16 usOpcode, void *pRetParams);
  197. //*****************************************************************************
  198. //
  199. //! SimpleLinkWaitData
  200. //!
  201. //! @param pBuf data buffer
  202. //! @param from from information
  203. //! @param fromlen from information length
  204. //!
  205. //! @return none
  206. //!
  207. //! @brief Wait for data, pass it to the hci_event_handler
  208. //! and update in a global variable that there is
  209. //! data to read.
  210. //
  211. //*****************************************************************************
  212. extern void SimpleLinkWaitData(UINT8 *pBuf, UINT8 *from, UINT8 *fromlen);
  213. //*****************************************************************************
  214. //
  215. //! UINT32_TO_STREAM_f
  216. //!
  217. //! \param p pointer to the new stream
  218. //! \param u32 pointer to the 32 bit
  219. //!
  220. //! \return pointer to the new stream
  221. //!
  222. //! \brief This function is used for copying 32 bit to stream
  223. //! while converting to little endian format.
  224. //
  225. //*****************************************************************************
  226. extern UINT8* UINT32_TO_STREAM_f (UINT8 *p, UINT32 u32);
  227. //*****************************************************************************
  228. //
  229. //! UINT16_TO_STREAM_f
  230. //!
  231. //! \param p pointer to the new stream
  232. //! \param u32 pointer to the 16 bit
  233. //!
  234. //! \return pointer to the new stream
  235. //!
  236. //! \brief This function is used for copying 16 bit to stream
  237. //! while converting to little endian format.
  238. //
  239. //*****************************************************************************
  240. extern UINT8* UINT16_TO_STREAM_f (UINT8 *p, UINT16 u16);
  241. //*****************************************************************************
  242. //
  243. //! STREAM_TO_UINT16_f
  244. //!
  245. //! \param p pointer to the stream
  246. //! \param offset offset in the stream
  247. //!
  248. //! \return pointer to the new 16 bit
  249. //!
  250. //! \brief This function is used for copying received stream to
  251. //! 16 bit in little endian format.
  252. //
  253. //*****************************************************************************
  254. extern UINT16 STREAM_TO_UINT16_f(CHAR* p, UINT16 offset);
  255. //*****************************************************************************
  256. //
  257. //! STREAM_TO_UINT32_f
  258. //!
  259. //! \param p pointer to the stream
  260. //! \param offset offset in the stream
  261. //!
  262. //! \return pointer to the new 32 bit
  263. //!
  264. //! \brief This function is used for copying received stream to
  265. //! 32 bit in little endian format.
  266. //
  267. //*****************************************************************************
  268. extern UINT32 STREAM_TO_UINT32_f(CHAR* p, UINT16 offset);
  269. //*****************************************************************************
  270. // COMMON MACROs
  271. //*****************************************************************************
  272. //This macro is used for copying 8 bit to stream while converting to little endian format.
  273. #define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);}
  274. //This macro is used for copying 16 bit to stream while converting to little endian format.
  275. #define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16))
  276. //This macro is used for copying 32 bit to stream while converting to little endian format.
  277. #define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
  278. //This macro is used for copying a specified value length bits (l) to stream while converting to little endian format.
  279. #define ARRAY_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(p)++ = ((UINT8 *) a)[_i];}
  280. //This macro is used for copying received stream to 8 bit in little endian format.
  281. #define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (UINT8)(*(_p + _offset));}
  282. //This macro is used for copying received stream to 16 bit in little endian format.
  283. #define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
  284. //This macro is used for copying received stream to 32 bit in little endian format.
  285. #define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
  286. #define STREAM_TO_STREAM(p, a, l) {register INT16 _i; for (_i = 0; _i < l; _i++) *(a)++= ((UINT8 *) p)[_i];}
  287. //*****************************************************************************
  288. //
  289. // Mark the end of the C bindings section for C++ compilers.
  290. //
  291. //*****************************************************************************
  292. #ifdef __cplusplus
  293. }
  294. #endif // __cplusplus
  295. #endif // __CC3000_COMMON_H__