Added mutex for multiple SPI devices on the same SPI bus

Fork of cc3000_hostdriver_mbedsocket by Martin Kojtal

Committer:
vpcola
Date:
Thu Oct 16 13:39:08 2014 +0000
Revision:
47:cc9a2501e29f
Parent:
20:30b6ed7bf8fd
Added mutex if used in rtos

Who changed what in which revision?

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