version_2.0

Dependents:   cc3000_ping_demo_try_2

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
Kojto
Date:
Thu Sep 19 07:55:14 2013 +0000
Revision:
0:615c697c33b0
Child:
20:30b6ed7bf8fd
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 0:615c697c33b0 1 /*****************************************************************************
Kojto 0:615c697c33b0 2 *
Kojto 0:615c697c33b0 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
Kojto 0:615c697c33b0 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
Kojto 0:615c697c33b0 5 * provided help.
Kojto 0:615c697c33b0 6 *
Kojto 0:615c697c33b0 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
Kojto 0:615c697c33b0 8 * read the following copyright:
Kojto 0:615c697c33b0 9 *
Kojto 0:615c697c33b0 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Kojto 0:615c697c33b0 11 *
Kojto 0:615c697c33b0 12 * Redistribution and use in source and binary forms, with or without
Kojto 0:615c697c33b0 13 * modification, are permitted provided that the following conditions
Kojto 0:615c697c33b0 14 * are met:
Kojto 0:615c697c33b0 15 *
Kojto 0:615c697c33b0 16 * Redistributions of source code must retain the above copyright
Kojto 0:615c697c33b0 17 * notice, this list of conditions and the following disclaimer.
Kojto 0:615c697c33b0 18 *
Kojto 0:615c697c33b0 19 * Redistributions in binary form must reproduce the above copyright
Kojto 0:615c697c33b0 20 * notice, this list of conditions and the following disclaimer in the
Kojto 0:615c697c33b0 21 * documentation and/or other materials provided with the
Kojto 0:615c697c33b0 22 * distribution.
Kojto 0:615c697c33b0 23 *
Kojto 0:615c697c33b0 24 * Neither the name of Texas Instruments Incorporated nor the names of
Kojto 0:615c697c33b0 25 * its contributors may be used to endorse or promote products derived
Kojto 0:615c697c33b0 26 * from this software without specific prior written permission.
Kojto 0:615c697c33b0 27 *
Kojto 0:615c697c33b0 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Kojto 0:615c697c33b0 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Kojto 0:615c697c33b0 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Kojto 0:615c697c33b0 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Kojto 0:615c697c33b0 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Kojto 0:615c697c33b0 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Kojto 0:615c697c33b0 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Kojto 0:615c697c33b0 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Kojto 0:615c697c33b0 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 0:615c697c33b0 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 0:615c697c33b0 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 0:615c697c33b0 39 *
Kojto 0:615c697c33b0 40 *****************************************************************************/
Kojto 0:615c697c33b0 41 #ifndef CC3000_SPI_H
Kojto 0:615c697c33b0 42 #define CC3000_SPI_H
Kojto 0:615c697c33b0 43
Kojto 0:615c697c33b0 44 typedef struct
Kojto 0:615c697c33b0 45 {
Kojto 0:615c697c33b0 46 uint16_t tx_packet_length;
Kojto 0:615c697c33b0 47 uint16_t rx_packet_length;
Kojto 0:615c697c33b0 48 uint32_t spi_state;
Kojto 0:615c697c33b0 49 } tSpiInfo;
Kojto 0:615c697c33b0 50
Kojto 0:615c697c33b0 51
Kojto 0:615c697c33b0 52 /* ===========================================================================================
Kojto 0:615c697c33b0 53 SPI
Kojto 0:615c697c33b0 54 =========================================================================================== */
Kojto 0:615c697c33b0 55 #define READ 3
Kojto 0:615c697c33b0 56 #define WRITE 1
Kojto 0:615c697c33b0 57
Kojto 0:615c697c33b0 58 #define HI(value) (((value) & 0xFF00) >> 8)
Kojto 0:615c697c33b0 59 #define LO(value) ((value) & 0x00FF)
Kojto 0:615c697c33b0 60
Kojto 0:615c697c33b0 61 #define HEADERS_SIZE_EVNT (SPI_HEADER_SIZE + 5)
Kojto 0:615c697c33b0 62
Kojto 0:615c697c33b0 63 #define SPI_HEADER_SIZE (5)
Kojto 0:615c697c33b0 64
Kojto 0:615c697c33b0 65 #define eSPI_STATE_POWERUP (0)
Kojto 0:615c697c33b0 66 #define eSPI_STATE_INITIALIZED (1)
Kojto 0:615c697c33b0 67 #define eSPI_STATE_IDLE (2)
Kojto 0:615c697c33b0 68 #define eSPI_STATE_WRITE_IRQ (3)
Kojto 0:615c697c33b0 69 #define eSPI_STATE_WRITE_FIRST_PORTION (4)
Kojto 0:615c697c33b0 70 #define eSPI_STATE_WRITE_EOT (5)
Kojto 0:615c697c33b0 71 #define eSPI_STATE_READ_IRQ (6)
Kojto 0:615c697c33b0 72 #define eSPI_STATE_READ_FIRST_PORTION (7)
Kojto 0:615c697c33b0 73 #define eSPI_STATE_READ_EOT (8)
Kojto 0:615c697c33b0 74
Kojto 0:615c697c33b0 75 // The magic number that resides at the end of the TX/RX buffer (1 byte after the allocated size)
Kojto 0:615c697c33b0 76 // for the purpose of detection of the overrun. The location of the memory where the magic number
Kojto 0:615c697c33b0 77 // resides shall never be written. In case it is written - overrun occured and either recevie function
Kojto 0:615c697c33b0 78 // or send function will be stuck forever.
Kojto 0:615c697c33b0 79 #define CC3000_BUFFER_MAGIC_NUMBER (0xDE)
Kojto 0:615c697c33b0 80
Kojto 0:615c697c33b0 81 /* ===========================================================================================
Kojto 0:615c697c33b0 82 HCI
Kojto 0:615c697c33b0 83 =========================================================================================== */
Kojto 0:615c697c33b0 84
Kojto 0:615c697c33b0 85 #define SL_PATCH_PORTION_SIZE (1000)
Kojto 0:615c697c33b0 86
Kojto 0:615c697c33b0 87 #define SPI_HEADER_SIZE (5)
Kojto 0:615c697c33b0 88 #define SIMPLE_LINK_HCI_CMND_HEADER_SIZE (4)
Kojto 0:615c697c33b0 89 #define HEADERS_SIZE_CMD (SPI_HEADER_SIZE + SIMPLE_LINK_HCI_CMND_HEADER_SIZE)
Kojto 0:615c697c33b0 90 #define SIMPLE_LINK_HCI_DATA_CMND_HEADER_SIZE (5)
Kojto 0:615c697c33b0 91 #define SIMPLE_LINK_HCI_DATA_HEADER_SIZE (5)
Kojto 0:615c697c33b0 92 #define SIMPLE_LINK_HCI_PATCH_HEADER_SIZE (2)
Kojto 0:615c697c33b0 93
Kojto 0:615c697c33b0 94 // Values that can be used as HCI Commands and HCI Packet header defines
Kojto 0:615c697c33b0 95 #define HCI_TYPE_CMND 0x1
Kojto 0:615c697c33b0 96 #define HCI_TYPE_DATA 0x2
Kojto 0:615c697c33b0 97 #define HCI_TYPE_PATCH 0x3
Kojto 0:615c697c33b0 98 #define HCI_TYPE_EVNT 0x4
Kojto 0:615c697c33b0 99
Kojto 0:615c697c33b0 100
Kojto 0:615c697c33b0 101 #define HCI_EVENT_PATCHES_DRV_REQ (1)
Kojto 0:615c697c33b0 102 #define HCI_EVENT_PATCHES_FW_REQ (2)
Kojto 0:615c697c33b0 103 #define HCI_EVENT_PATCHES_BOOTLOAD_REQ (3)
Kojto 0:615c697c33b0 104
Kojto 0:615c697c33b0 105
Kojto 0:615c697c33b0 106 #define HCI_CMND_WLAN_BASE (0x0000)
Kojto 0:615c697c33b0 107 #define HCI_CMND_WLAN_CONNECT 0x0001
Kojto 0:615c697c33b0 108 #define HCI_CMND_WLAN_DISCONNECT 0x0002
Kojto 0:615c697c33b0 109 #define HCI_CMND_WLAN_IOCTL_SET_SCANPARAM 0x0003
Kojto 0:615c697c33b0 110 #define HCI_CMND_WLAN_IOCTL_SET_CONNECTION_POLICY 0x0004
Kojto 0:615c697c33b0 111 #define HCI_CMND_WLAN_IOCTL_ADD_PROFILE 0x0005
Kojto 0:615c697c33b0 112 #define HCI_CMND_WLAN_IOCTL_DEL_PROFILE 0x0006
Kojto 0:615c697c33b0 113 #define HCI_CMND_WLAN_IOCTL_GET_SCAN_RESULTS 0x0007
Kojto 0:615c697c33b0 114 #define HCI_CMND_EVENT_MASK 0x0008
Kojto 0:615c697c33b0 115 #define HCI_CMND_WLAN_IOCTL_STATUSGET 0x0009
Kojto 0:615c697c33b0 116 #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_START 0x000A
Kojto 0:615c697c33b0 117 #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_STOP 0x000B
Kojto 0:615c697c33b0 118 #define HCI_CMND_WLAN_IOCTL_SIMPLE_CONFIG_SET_PREFIX 0x000C
Kojto 0:615c697c33b0 119 #define HCI_CMND_WLAN_CONFIGURE_PATCH 0x000D
Kojto 0:615c697c33b0 120
Kojto 0:615c697c33b0 121
Kojto 0:615c697c33b0 122 #define HCI_CMND_SOCKET_BASE 0x1000
Kojto 0:615c697c33b0 123 #define HCI_CMND_SOCKET 0x1001
Kojto 0:615c697c33b0 124 #define HCI_CMND_BIND 0x1002
Kojto 0:615c697c33b0 125 #define HCI_CMND_RECV 0x1004
Kojto 0:615c697c33b0 126 #define HCI_CMND_ACCEPT 0x1005
Kojto 0:615c697c33b0 127 #define HCI_CMND_LISTEN 0x1006
Kojto 0:615c697c33b0 128 #define HCI_CMND_CONNECT 0x1007
Kojto 0:615c697c33b0 129 #define HCI_CMND_BSD_SELECT 0x1008
Kojto 0:615c697c33b0 130 #define HCI_CMND_SETSOCKOPT 0x1009
Kojto 0:615c697c33b0 131 #define HCI_CMND_GETSOCKOPT 0x100A
Kojto 0:615c697c33b0 132 #define HCI_CMND_CLOSE_SOCKET 0x100B
Kojto 0:615c697c33b0 133 #define HCI_CMND_RECVFROM 0x100D
Kojto 0:615c697c33b0 134 #define HCI_CMND_GETHOSTNAME 0x1010
Kojto 0:615c697c33b0 135 #define HCI_CMND_MDNS_ADVERTISE 0x1011
Kojto 0:615c697c33b0 136
Kojto 0:615c697c33b0 137
Kojto 0:615c697c33b0 138 #define HCI_DATA_BASE 0x80
Kojto 0:615c697c33b0 139
Kojto 0:615c697c33b0 140 #define HCI_CMND_SEND (0x01 + HCI_DATA_BASE)
Kojto 0:615c697c33b0 141 #define HCI_CMND_SENDTO (0x03 + HCI_DATA_BASE)
Kojto 0:615c697c33b0 142 #define HCI_DATA_BSD_RECVFROM (0x04 + HCI_DATA_BASE)
Kojto 0:615c697c33b0 143 #define HCI_DATA_BSD_RECV (0x05 + HCI_DATA_BASE)
Kojto 0:615c697c33b0 144
Kojto 0:615c697c33b0 145
Kojto 0:615c697c33b0 146 #define HCI_CMND_NVMEM_CBASE (0x0200)
Kojto 0:615c697c33b0 147
Kojto 0:615c697c33b0 148
Kojto 0:615c697c33b0 149 #define HCI_CMND_NVMEM_CREATE_ENTRY (0x0203)
Kojto 0:615c697c33b0 150 #define HCI_CMND_NVMEM_SWAP_ENTRY (0x0205)
Kojto 0:615c697c33b0 151 #define HCI_CMND_NVMEM_READ (0x0201)
Kojto 0:615c697c33b0 152 #define HCI_CMND_NVMEM_WRITE (0x0090)
Kojto 0:615c697c33b0 153 #define HCI_CMND_NVMEM_WRITE_PATCH (0x0204)
Kojto 0:615c697c33b0 154 #define HCI_CMND_READ_SP_VERSION (0x0207)
Kojto 0:615c697c33b0 155
Kojto 0:615c697c33b0 156 #define HCI_CMND_READ_BUFFER_SIZE 0x400B
Kojto 0:615c697c33b0 157 #define HCI_CMND_SIMPLE_LINK_START 0x4000
Kojto 0:615c697c33b0 158
Kojto 0:615c697c33b0 159 #define HCI_CMND_NETAPP_BASE 0x2000
Kojto 0:615c697c33b0 160
Kojto 0:615c697c33b0 161 #define HCI_NETAPP_DHCP (0x0001 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 162 #define HCI_NETAPP_PING_SEND (0x0002 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 163 #define HCI_NETAPP_PING_REPORT (0x0003 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 164 #define HCI_NETAPP_PING_STOP (0x0004 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 165 #define HCI_NETAPP_IPCONFIG (0x0005 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 166 #define HCI_NETAPP_ARP_FLUSH (0x0006 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 167 #define HCI_NETAPP_SET_DEBUG_LEVEL (0x0008 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 168 #define HCI_NETAPP_SET_TIMERS (0x0009 + HCI_CMND_NETAPP_BASE)
Kojto 0:615c697c33b0 169
Kojto 0:615c697c33b0 170 // Values that can be used as HCI Events defines
Kojto 0:615c697c33b0 171 #define HCI_EVNT_WLAN_BASE 0x0000
Kojto 0:615c697c33b0 172 #define HCI_EVNT_WLAN_CONNECT 0x0001
Kojto 0:615c697c33b0 173 #define HCI_EVNT_WLAN_DISCONNECT \
Kojto 0:615c697c33b0 174 0x0002
Kojto 0:615c697c33b0 175 #define HCI_EVNT_WLAN_IOCTL_ADD_PROFILE \
Kojto 0:615c697c33b0 176 0x0005
Kojto 0:615c697c33b0 177
Kojto 0:615c697c33b0 178
Kojto 0:615c697c33b0 179 #define HCI_EVNT_SOCKET HCI_CMND_SOCKET
Kojto 0:615c697c33b0 180 #define HCI_EVNT_BIND HCI_CMND_BIND
Kojto 0:615c697c33b0 181 #define HCI_EVNT_RECV HCI_CMND_RECV
Kojto 0:615c697c33b0 182 #define HCI_EVNT_ACCEPT HCI_CMND_ACCEPT
Kojto 0:615c697c33b0 183 #define HCI_EVNT_LISTEN HCI_CMND_LISTEN
Kojto 0:615c697c33b0 184 #define HCI_EVNT_CONNECT HCI_CMND_CONNECT
Kojto 0:615c697c33b0 185 #define HCI_EVNT_SELECT HCI_CMND_BSD_SELECT
Kojto 0:615c697c33b0 186 #define HCI_EVNT_CLOSE_SOCKET HCI_CMND_CLOSE_SOCKET
Kojto 0:615c697c33b0 187 #define HCI_EVNT_RECVFROM HCI_CMND_RECVFROM
Kojto 0:615c697c33b0 188 #define HCI_EVNT_SETSOCKOPT HCI_CMND_SETSOCKOPT
Kojto 0:615c697c33b0 189 #define HCI_EVNT_GETSOCKOPT HCI_CMND_GETSOCKOPT
Kojto 0:615c697c33b0 190 #define HCI_EVNT_BSD_GETHOSTBYNAME HCI_CMND_GETHOSTNAME
Kojto 0:615c697c33b0 191 #define HCI_EVNT_MDNS_ADVERTISE HCI_CMND_MDNS_ADVERTISE
Kojto 0:615c697c33b0 192
Kojto 0:615c697c33b0 193 #define HCI_EVNT_SEND 0x1003
Kojto 0:615c697c33b0 194 #define HCI_EVNT_WRITE 0x100E
Kojto 0:615c697c33b0 195 #define HCI_EVNT_SENDTO 0x100F
Kojto 0:615c697c33b0 196
Kojto 0:615c697c33b0 197 #define HCI_EVNT_PATCHES_REQ 0x1000
Kojto 0:615c697c33b0 198
Kojto 0:615c697c33b0 199 #define HCI_EVNT_UNSOL_BASE 0x4000
Kojto 0:615c697c33b0 200
Kojto 0:615c697c33b0 201 #define HCI_EVNT_WLAN_UNSOL_BASE (0x8000)
Kojto 0:615c697c33b0 202
Kojto 0:615c697c33b0 203 #define HCI_EVNT_WLAN_UNSOL_CONNECT (0x0001 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 204 #define HCI_EVNT_WLAN_UNSOL_DISCONNECT (0x0002 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 205 #define HCI_EVNT_WLAN_UNSOL_INIT (0x0004 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 206 #define HCI_EVNT_WLAN_TX_COMPLETE (0x0008 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 207 #define HCI_EVNT_WLAN_UNSOL_DHCP (0x0010 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 208 #define HCI_EVNT_WLAN_ASYNC_PING_REPORT (0x0040 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 209 #define HCI_EVNT_WLAN_ASYNC_SIMPLE_CONFIG_DONE (0x0080 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 210 #define HCI_EVNT_WLAN_KEEPALIVE (0x0200 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 211 #define HCI_EVNT_BSD_TCP_CLOSE_WAIT (0x0800 + HCI_EVNT_WLAN_UNSOL_BASE)
Kojto 0:615c697c33b0 212
Kojto 0:615c697c33b0 213 #define HCI_EVNT_DATA_UNSOL_FREE_BUFF \
Kojto 0:615c697c33b0 214 0x4100
Kojto 0:615c697c33b0 215
Kojto 0:615c697c33b0 216 #define HCI_EVNT_NVMEM_CREATE_ENTRY \
Kojto 0:615c697c33b0 217 HCI_CMND_NVMEM_CREATE_ENTRY
Kojto 0:615c697c33b0 218 #define HCI_EVNT_NVMEM_SWAP_ENTRY HCI_CMND_NVMEM_SWAP_ENTRY
Kojto 0:615c697c33b0 219
Kojto 0:615c697c33b0 220 #define HCI_EVNT_NVMEM_READ HCI_CMND_NVMEM_READ
Kojto 0:615c697c33b0 221 #define HCI_EVNT_NVMEM_WRITE (0x0202)
Kojto 0:615c697c33b0 222
Kojto 0:615c697c33b0 223 #define HCI_EVNT_READ_SP_VERSION \
Kojto 0:615c697c33b0 224 HCI_CMND_READ_SP_VERSION
Kojto 0:615c697c33b0 225
Kojto 0:615c697c33b0 226 #define HCI_EVNT_INPROGRESS 0xFFFF
Kojto 0:615c697c33b0 227
Kojto 0:615c697c33b0 228
Kojto 0:615c697c33b0 229 #define HCI_DATA_RECVFROM 0x84
Kojto 0:615c697c33b0 230 #define HCI_DATA_RECV 0x85
Kojto 0:615c697c33b0 231 #define HCI_DATA_NVMEM 0x91
Kojto 0:615c697c33b0 232
Kojto 0:615c697c33b0 233 #define HCI_EVENT_CC3000_CAN_SHUT_DOWN 0x99
Kojto 0:615c697c33b0 234
Kojto 0:615c697c33b0 235 // Prototypes for the structures for HCI APIs.
Kojto 0:615c697c33b0 236 #define HCI_DATA_HEADER_SIZE (5)
Kojto 0:615c697c33b0 237 #define HCI_EVENT_HEADER_SIZE (5)
Kojto 0:615c697c33b0 238 #define HCI_DATA_CMD_HEADER_SIZE (5)
Kojto 0:615c697c33b0 239 #define HCI_PATCH_HEADER_SIZE (6)
Kojto 0:615c697c33b0 240
Kojto 0:615c697c33b0 241 #define HCI_PACKET_TYPE_OFFSET (0)
Kojto 0:615c697c33b0 242 #define HCI_PACKET_ARGSIZE_OFFSET (2)
Kojto 0:615c697c33b0 243 #define HCI_PACKET_LENGTH_OFFSET (3)
Kojto 0:615c697c33b0 244
Kojto 0:615c697c33b0 245
Kojto 0:615c697c33b0 246 #define HCI_EVENT_OPCODE_OFFSET (1)
Kojto 0:615c697c33b0 247 #define HCI_EVENT_LENGTH_OFFSET (3)
Kojto 0:615c697c33b0 248 #define HCI_EVENT_STATUS_OFFSET (4)
Kojto 0:615c697c33b0 249 #define HCI_DATA_LENGTH_OFFSET (3)
Kojto 0:615c697c33b0 250
Kojto 0:615c697c33b0 251 #endif