Added mutex for multiple SPI devices on the same SPI bus

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
Kojto
Date:
Thu Sep 19 08:01:20 2013 +0000
Revision:
1:c7b8f55e0ca1
Child:
20:30b6ed7bf8fd
added common.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Kojto 1:c7b8f55e0ca1 1 /*****************************************************************************
Kojto 1:c7b8f55e0ca1 2 *
Kojto 1:c7b8f55e0ca1 3 * C++ interface/implementation created by Martin Kojtal (0xc0170). Thanks to
Kojto 1:c7b8f55e0ca1 4 * Jim Carver and Frank Vannieuwkerke for their inital cc3000 mbed port and
Kojto 1:c7b8f55e0ca1 5 * provided help.
Kojto 1:c7b8f55e0ca1 6 *
Kojto 1:c7b8f55e0ca1 7 * This version of "host driver" uses CC3000 Host Driver Implementation. Thus
Kojto 1:c7b8f55e0ca1 8 * read the following copyright:
Kojto 1:c7b8f55e0ca1 9 *
Kojto 1:c7b8f55e0ca1 10 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
Kojto 1:c7b8f55e0ca1 11 *
Kojto 1:c7b8f55e0ca1 12 * Redistribution and use in source and binary forms, with or without
Kojto 1:c7b8f55e0ca1 13 * modification, are permitted provided that the following conditions
Kojto 1:c7b8f55e0ca1 14 * are met:
Kojto 1:c7b8f55e0ca1 15 *
Kojto 1:c7b8f55e0ca1 16 * Redistributions of source code must retain the above copyright
Kojto 1:c7b8f55e0ca1 17 * notice, this list of conditions and the following disclaimer.
Kojto 1:c7b8f55e0ca1 18 *
Kojto 1:c7b8f55e0ca1 19 * Redistributions in binary form must reproduce the above copyright
Kojto 1:c7b8f55e0ca1 20 * notice, this list of conditions and the following disclaimer in the
Kojto 1:c7b8f55e0ca1 21 * documentation and/or other materials provided with the
Kojto 1:c7b8f55e0ca1 22 * distribution.
Kojto 1:c7b8f55e0ca1 23 *
Kojto 1:c7b8f55e0ca1 24 * Neither the name of Texas Instruments Incorporated nor the names of
Kojto 1:c7b8f55e0ca1 25 * its contributors may be used to endorse or promote products derived
Kojto 1:c7b8f55e0ca1 26 * from this software without specific prior written permission.
Kojto 1:c7b8f55e0ca1 27 *
Kojto 1:c7b8f55e0ca1 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Kojto 1:c7b8f55e0ca1 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Kojto 1:c7b8f55e0ca1 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Kojto 1:c7b8f55e0ca1 31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Kojto 1:c7b8f55e0ca1 32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Kojto 1:c7b8f55e0ca1 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Kojto 1:c7b8f55e0ca1 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Kojto 1:c7b8f55e0ca1 35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Kojto 1:c7b8f55e0ca1 36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 1:c7b8f55e0ca1 37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Kojto 1:c7b8f55e0ca1 38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 1:c7b8f55e0ca1 39 *
Kojto 1:c7b8f55e0ca1 40 *****************************************************************************/
Kojto 1:c7b8f55e0ca1 41 #ifndef CC3000_COMMON_H
Kojto 1:c7b8f55e0ca1 42 #define CC3000_COMMON_H
Kojto 1:c7b8f55e0ca1 43
Kojto 1:c7b8f55e0ca1 44 #include <errno.h>
Kojto 1:c7b8f55e0ca1 45
Kojto 1:c7b8f55e0ca1 46 //#define CC3000_TINY_DRIVER // Driver for small memory model CPUs
Kojto 1:c7b8f55e0ca1 47
Kojto 1:c7b8f55e0ca1 48 #define ESUCCESS 0
Kojto 1:c7b8f55e0ca1 49 #define EFAIL -1
Kojto 1:c7b8f55e0ca1 50 #define EERROR EFAIL
Kojto 1:c7b8f55e0ca1 51
Kojto 1:c7b8f55e0ca1 52 #define CC3000_UNENCRYPTED_SMART_CONFIG // No encryption
Kojto 1:c7b8f55e0ca1 53
Kojto 1:c7b8f55e0ca1 54 #define ERROR_SOCKET_INACTIVE -57
Kojto 1:c7b8f55e0ca1 55
Kojto 1:c7b8f55e0ca1 56 #define HCI_CC_PAYLOAD_LEN 5
Kojto 1:c7b8f55e0ca1 57
Kojto 1:c7b8f55e0ca1 58 #define WLAN_ENABLE (1)
Kojto 1:c7b8f55e0ca1 59 #define WLAN_DISABLE (0)
Kojto 1:c7b8f55e0ca1 60
Kojto 1:c7b8f55e0ca1 61 #define MAC_ADDR_LEN (6)
Kojto 1:c7b8f55e0ca1 62
Kojto 1:c7b8f55e0ca1 63
Kojto 1:c7b8f55e0ca1 64 /*Defines for minimal and maximal RX buffer size. This size includes the spi
Kojto 1:c7b8f55e0ca1 65 header and hci header.
Kojto 1:c7b8f55e0ca1 66 maximal buffer size: MTU + HCI header + SPI header + sendto() args size
Kojto 1:c7b8f55e0ca1 67 minimum buffer size: HCI header + SPI header + max args size
Kojto 1:c7b8f55e0ca1 68
Kojto 1:c7b8f55e0ca1 69 This buffer is used for receiving events and data.
Kojto 1:c7b8f55e0ca1 70 The packet can not be longer than MTU size and CC3000 does not support
Kojto 1:c7b8f55e0ca1 71 fragmentation. Note that the same buffer is used for reception of the data
Kojto 1:c7b8f55e0ca1 72 and events from CC3000. That is why the minimum is defined.
Kojto 1:c7b8f55e0ca1 73 The calculation for the actual size of buffer for reception is:
Kojto 1:c7b8f55e0ca1 74 Given the maximal data size MAX_DATA that is expected to be received by
Kojto 1:c7b8f55e0ca1 75 application, the required buffer Using recv() or recvfrom():
Kojto 1:c7b8f55e0ca1 76
Kojto 1:c7b8f55e0ca1 77 max(CC3000_MINIMAL_RX_SIZE, MAX_DATA + HEADERS_SIZE_DATA + fromlen + ucArgsize + 1)
Kojto 1:c7b8f55e0ca1 78
Kojto 1:c7b8f55e0ca1 79 Using gethostbyname() with minimal buffer size will limit the host name returned to 99 bytes.
Kojto 1:c7b8f55e0ca1 80 The 1 is used for the overrun detection
Kojto 1:c7b8f55e0ca1 81 */
Kojto 1:c7b8f55e0ca1 82
Kojto 1:c7b8f55e0ca1 83 #define CC3000_MINIMAL_RX_SIZE (118 + 1)
Kojto 1:c7b8f55e0ca1 84 #define CC3000_MAXIMAL_RX_SIZE (511 + 1)
Kojto 1:c7b8f55e0ca1 85
Kojto 1:c7b8f55e0ca1 86 /*Defines for minimal and maximal TX buffer size.
Kojto 1:c7b8f55e0ca1 87 This buffer is used for sending events and data.
Kojto 1:c7b8f55e0ca1 88 The packet can not be longer than MTU size and CC3000 does not support
Kojto 1:c7b8f55e0ca1 89 fragmentation. Note that the same buffer is used for transmission of the data
Kojto 1:c7b8f55e0ca1 90 and commands. That is why the minimum is defined.
Kojto 1:c7b8f55e0ca1 91 The calculation for the actual size of buffer for transmission is:
Kojto 1:c7b8f55e0ca1 92 Given the maximal data size MAX_DATA, the required buffer is:
Kojto 1:c7b8f55e0ca1 93 Using Sendto():
Kojto 1:c7b8f55e0ca1 94
Kojto 1:c7b8f55e0ca1 95 max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
Kojto 1:c7b8f55e0ca1 96 + SOCKET_SENDTO_PARAMS_LEN + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
Kojto 1:c7b8f55e0ca1 97
Kojto 1:c7b8f55e0ca1 98 Using Send():
Kojto 1:c7b8f55e0ca1 99
Kojto 1:c7b8f55e0ca1 100 max(CC3000_MINIMAL_TX_SIZE, MAX_DATA + SPI_HEADER_SIZE
Kojto 1:c7b8f55e0ca1 101 + HCI_CMND_SEND_ARG_LENGTH + SIMPLE_LINK_HCI_DATA_HEADER_SIZE + 1)
Kojto 1:c7b8f55e0ca1 102
Kojto 1:c7b8f55e0ca1 103 The 1 is used for the overrun detection */
Kojto 1:c7b8f55e0ca1 104
Kojto 1:c7b8f55e0ca1 105 #define CC3000_MINIMAL_TX_SIZE (118 + 1)
Kojto 1:c7b8f55e0ca1 106 #define CC3000_MAXIMAL_TX_SIZE (1519 + 1)
Kojto 1:c7b8f55e0ca1 107
Kojto 1:c7b8f55e0ca1 108 //TX and RX buffer size - allow to receive and transmit maximum data at lengh 8.
Kojto 1:c7b8f55e0ca1 109 #ifdef CC3000_TINY_DRIVER
Kojto 1:c7b8f55e0ca1 110 #define TINY_CC3000_MAXIMAL_RX_SIZE 44
Kojto 1:c7b8f55e0ca1 111 #define TINY_CC3000_MAXIMAL_TX_SIZE 59
Kojto 1:c7b8f55e0ca1 112 #endif
Kojto 1:c7b8f55e0ca1 113
Kojto 1:c7b8f55e0ca1 114 /*In order to determine your preferred buffer size,
Kojto 1:c7b8f55e0ca1 115 change CC3000_MAXIMAL_RX_SIZE and CC3000_MAXIMAL_TX_SIZE to a value between
Kojto 1:c7b8f55e0ca1 116 the minimal and maximal specified above.
Kojto 1:c7b8f55e0ca1 117 Note that the buffers are allocated by SPI.
Kojto 1:c7b8f55e0ca1 118 */
Kojto 1:c7b8f55e0ca1 119
Kojto 1:c7b8f55e0ca1 120 #ifndef CC3000_TINY_DRIVER
Kojto 1:c7b8f55e0ca1 121
Kojto 1:c7b8f55e0ca1 122 #define CC3000_RX_BUFFER_SIZE (CC3000_MAXIMAL_RX_SIZE)
Kojto 1:c7b8f55e0ca1 123 #define CC3000_TX_BUFFER_SIZE (CC3000_MAXIMAL_TX_SIZE)
Kojto 1:c7b8f55e0ca1 124 #define SP_PORTION_SIZE 512
Kojto 1:c7b8f55e0ca1 125
Kojto 1:c7b8f55e0ca1 126 //TINY DRIVER: We use smaller rx and tx buffers in order to minimize RAM consumption
Kojto 1:c7b8f55e0ca1 127 #else
Kojto 1:c7b8f55e0ca1 128 #define CC3000_RX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_RX_SIZE)
Kojto 1:c7b8f55e0ca1 129 #define CC3000_TX_BUFFER_SIZE (TINY_CC3000_MAXIMAL_TX_SIZE)
Kojto 1:c7b8f55e0ca1 130 #define SP_PORTION_SIZE 32
Kojto 1:c7b8f55e0ca1 131 #endif
Kojto 1:c7b8f55e0ca1 132
Kojto 1:c7b8f55e0ca1 133
Kojto 1:c7b8f55e0ca1 134 //Copy 8 bit to stream while converting to little endian format.
Kojto 1:c7b8f55e0ca1 135 #define UINT8_TO_STREAM(_p, _val) {*(_p)++ = (_val);}
Kojto 1:c7b8f55e0ca1 136 //Copy 16 bit to stream while converting to little endian format.
Kojto 1:c7b8f55e0ca1 137 #define UINT16_TO_STREAM(_p, _u16) (UINT16_TO_STREAM_f(_p, _u16))
Kojto 1:c7b8f55e0ca1 138 //Copy 32 bit to stream while converting to little endian format.
Kojto 1:c7b8f55e0ca1 139 #define UINT32_TO_STREAM(_p, _u32) (UINT32_TO_STREAM_f(_p, _u32))
Kojto 1:c7b8f55e0ca1 140 //Copy a specified value length bits (l) to stream while converting to little endian format.
Kojto 1:c7b8f55e0ca1 141 #define ARRAY_TO_STREAM(p, a, l) {uint32_t _i; for (_i = 0; _i < l; _i++) *(p)++ = ((uint8_t *) a)[_i];}
Kojto 1:c7b8f55e0ca1 142 //Copy received stream to 8 bit in little endian format.
Kojto 1:c7b8f55e0ca1 143 #define STREAM_TO_UINT8(_p, _offset, _u8) {_u8 = (uint8_t)(*(_p + _offset));}
Kojto 1:c7b8f55e0ca1 144 //Copy received stream to 16 bit in little endian format.
Kojto 1:c7b8f55e0ca1 145 #define STREAM_TO_UINT16(_p, _offset, _u16) {_u16 = STREAM_TO_UINT16_f(_p, _offset);}
Kojto 1:c7b8f55e0ca1 146 //Copy received stream to 32 bit in little endian format.
Kojto 1:c7b8f55e0ca1 147 #define STREAM_TO_UINT32(_p, _offset, _u32) {_u32 = STREAM_TO_UINT32_f(_p, _offset);}
Kojto 1:c7b8f55e0ca1 148 #define STREAM_TO_STREAM(p, a, l) {uint32_t _i; for (_i = 0; _i < l; _i++) *(a)++= ((uint8_t *) p)[_i];}
Kojto 1:c7b8f55e0ca1 149
Kojto 1:c7b8f55e0ca1 150 typedef struct _sockaddr_t
Kojto 1:c7b8f55e0ca1 151 {
Kojto 1:c7b8f55e0ca1 152 uint16_t family;
Kojto 1:c7b8f55e0ca1 153 uint8_t data[14];
Kojto 1:c7b8f55e0ca1 154 } sockaddr;
Kojto 1:c7b8f55e0ca1 155
Kojto 1:c7b8f55e0ca1 156 struct timeval
Kojto 1:c7b8f55e0ca1 157 {
Kojto 1:c7b8f55e0ca1 158 int32_t tv_sec; /* seconds */
Kojto 1:c7b8f55e0ca1 159 int32_t tv_usec; /* microseconds */
Kojto 1:c7b8f55e0ca1 160 };
Kojto 1:c7b8f55e0ca1 161
Kojto 1:c7b8f55e0ca1 162 #define SMART_CONFIG_PROFILE_SIZE 67 // 67 = 32 (max ssid) + 32 (max key) + 1 (SSID length) + 1 (security type) + 1 (key length)
Kojto 1:c7b8f55e0ca1 163
Kojto 1:c7b8f55e0ca1 164 /* patches type */
Kojto 1:c7b8f55e0ca1 165 #define PATCHES_HOST_TYPE_WLAN_DRIVER 0x01
Kojto 1:c7b8f55e0ca1 166 #define PATCHES_HOST_TYPE_WLAN_FW 0x02
Kojto 1:c7b8f55e0ca1 167 #define PATCHES_HOST_TYPE_BOOTLOADER 0x03
Kojto 1:c7b8f55e0ca1 168
Kojto 1:c7b8f55e0ca1 169 #define SL_SET_SCAN_PARAMS_INTERVAL_LIST_SIZE (16)
Kojto 1:c7b8f55e0ca1 170 #define SL_SIMPLE_CONFIG_PREFIX_LENGTH (3)
Kojto 1:c7b8f55e0ca1 171 #define ETH_ALEN (6)
Kojto 1:c7b8f55e0ca1 172 #define MAXIMAL_SSID_LENGTH (32)
Kojto 1:c7b8f55e0ca1 173
Kojto 1:c7b8f55e0ca1 174 #define SL_PATCHES_REQUEST_DEFAULT (0)
Kojto 1:c7b8f55e0ca1 175 #define SL_PATCHES_REQUEST_FORCE_HOST (1)
Kojto 1:c7b8f55e0ca1 176 #define SL_PATCHES_REQUEST_FORCE_NONE (2)
Kojto 1:c7b8f55e0ca1 177
Kojto 1:c7b8f55e0ca1 178
Kojto 1:c7b8f55e0ca1 179 #define WLAN_SEC_UNSEC (0)
Kojto 1:c7b8f55e0ca1 180 #define WLAN_SEC_WEP (1)
Kojto 1:c7b8f55e0ca1 181 #define WLAN_SEC_WPA (2)
Kojto 1:c7b8f55e0ca1 182 #define WLAN_SEC_WPA2 (3)
Kojto 1:c7b8f55e0ca1 183
Kojto 1:c7b8f55e0ca1 184
Kojto 1:c7b8f55e0ca1 185 #define WLAN_SL_INIT_START_PARAMS_LEN (1)
Kojto 1:c7b8f55e0ca1 186 #define WLAN_PATCH_PARAMS_LENGTH (8)
Kojto 1:c7b8f55e0ca1 187 #define WLAN_SET_CONNECTION_POLICY_PARAMS_LEN (12)
Kojto 1:c7b8f55e0ca1 188 #define WLAN_DEL_PROFILE_PARAMS_LEN (4)
Kojto 1:c7b8f55e0ca1 189 #define WLAN_SET_MASK_PARAMS_LEN (4)
Kojto 1:c7b8f55e0ca1 190 #define WLAN_SET_SCAN_PARAMS_LEN (100)
Kojto 1:c7b8f55e0ca1 191 #define WLAN_GET_SCAN_RESULTS_PARAMS_LEN (4)
Kojto 1:c7b8f55e0ca1 192 #define WLAN_ADD_PROFILE_NOSEC_PARAM_LEN (24)
Kojto 1:c7b8f55e0ca1 193 #define WLAN_ADD_PROFILE_WEP_PARAM_LEN (36)
Kojto 1:c7b8f55e0ca1 194 #define WLAN_ADD_PROFILE_WPA_PARAM_LEN (44)
Kojto 1:c7b8f55e0ca1 195 #define WLAN_CONNECT_PARAM_LEN (29)
Kojto 1:c7b8f55e0ca1 196 #define WLAN_SMART_CONFIG_START_PARAMS_LEN (4)
Kojto 1:c7b8f55e0ca1 197
Kojto 1:c7b8f55e0ca1 198 #endif