Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 * spi.h - mbed
dflet 3:a8c249046181 3 *
dflet 3:a8c249046181 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 3:a8c249046181 5 *
dflet 3:a8c249046181 6 *
dflet 3:a8c249046181 7 * Redistribution and use in source and binary forms, with or without
dflet 3:a8c249046181 8 * modification, are permitted provided that the following conditions
dflet 3:a8c249046181 9 * are met:
dflet 3:a8c249046181 10 *
dflet 3:a8c249046181 11 * Redistributions of source code must retain the above copyright
dflet 3:a8c249046181 12 * notice, this list of conditions and the following disclaimer.
dflet 3:a8c249046181 13 *
dflet 3:a8c249046181 14 * Redistributions in binary form must reproduce the above copyright
dflet 3:a8c249046181 15 * notice, this list of conditions and the following disclaimer in the
dflet 3:a8c249046181 16 * documentation and/or other materials provided with the
dflet 3:a8c249046181 17 * distribution.
dflet 3:a8c249046181 18 *
dflet 3:a8c249046181 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 3:a8c249046181 20 * its contributors may be used to endorse or promote products derived
dflet 3:a8c249046181 21 * from this software without specific prior written permission.
dflet 3:a8c249046181 22 *
dflet 3:a8c249046181 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 3:a8c249046181 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 3:a8c249046181 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 3:a8c249046181 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 3:a8c249046181 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 3:a8c249046181 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 3:a8c249046181 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 3:a8c249046181 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 3:a8c249046181 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 3:a8c249046181 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 3:a8c249046181 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 3:a8c249046181 34 *
dflet 3:a8c249046181 35 */
dflet 3:a8c249046181 36
dflet 3:a8c249046181 37
dflet 3:a8c249046181 38 #ifndef SPI_H_
dflet 3:a8c249046181 39 #define SPI_H_
dflet 3:a8c249046181 40
dflet 3:a8c249046181 41 #include "mbed.h"
dflet 3:a8c249046181 42
dflet 3:a8c249046181 43 /*!
dflet 3:a8c249046181 44 \brief type definition for the spi channel file descriptor
dflet 3:a8c249046181 45
dflet 3:a8c249046181 46 \note On each porting or platform the type could be whatever is needed
dflet 3:a8c249046181 47 - integer, pointer to structure etc.
dflet 3:a8c249046181 48 */
dflet 3:a8c249046181 49 typedef unsigned int Fd_t;
dflet 3:a8c249046181 50
dflet 3:a8c249046181 51 typedef void (*P_EVENT_HANDLER)(void* pValue);
dflet 3:a8c249046181 52
dflet 3:a8c249046181 53 typedef enum events
dflet 3:a8c249046181 54 {
dflet 3:a8c249046181 55 NO_ACTION = -1,
dflet 3:a8c249046181 56 PUSH_BUTTON_1_PRESSED = 3,
dflet 3:a8c249046181 57 PUSH_BUTTON_2_PRESSED = 4,
dflet 3:a8c249046181 58 BROKER_DISCONNECTION = 2
dflet 3:a8c249046181 59 } osi_messages;
dflet 3:a8c249046181 60
dflet 3:a8c249046181 61 extern uint32_t g_publishCount;
dflet 3:a8c249046181 62
dflet 3:a8c249046181 63 namespace mbed_cc3100 {
dflet 3:a8c249046181 64
dflet 3:a8c249046181 65 class cc3100_driver;
dflet 3:a8c249046181 66
dflet 3:a8c249046181 67 class cc3100_spi
dflet 3:a8c249046181 68 {
dflet 3:a8c249046181 69 public:
dflet 3:a8c249046181 70
dflet 3:a8c249046181 71 cc3100_spi(PinName button1_irq, PinName button2_irq, PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver);
dflet 3:a8c249046181 72
dflet 3:a8c249046181 73 ~cc3100_spi();
dflet 3:a8c249046181 74
dflet 3:a8c249046181 75
dflet 3:a8c249046181 76 /*!
dflet 3:a8c249046181 77 \brief Enables the CC3100
dflet 3:a8c249046181 78
dflet 3:a8c249046181 79 \param[in] none
dflet 3:a8c249046181 80
dflet 3:a8c249046181 81 \return none
dflet 3:a8c249046181 82
dflet 3:a8c249046181 83 \note
dflet 3:a8c249046181 84
dflet 3:a8c249046181 85 \warning
dflet 3:a8c249046181 86 */
dflet 3:a8c249046181 87 void CC3100_enable();
dflet 3:a8c249046181 88
dflet 3:a8c249046181 89 /*!
dflet 3:a8c249046181 90 \brief Disables the CC3100
dflet 3:a8c249046181 91
dflet 3:a8c249046181 92 \param[in] none
dflet 3:a8c249046181 93
dflet 3:a8c249046181 94 \return none
dflet 3:a8c249046181 95
dflet 3:a8c249046181 96 \note
dflet 3:a8c249046181 97
dflet 3:a8c249046181 98 \warning
dflet 3:a8c249046181 99 */
dflet 3:a8c249046181 100 void CC3100_disable();
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 /*!
dflet 3:a8c249046181 103 \brief Disables the button push interrupt
dflet 3:a8c249046181 104
dflet 3:a8c249046181 105 \param[in] none
dflet 3:a8c249046181 106
dflet 3:a8c249046181 107 \return none
dflet 3:a8c249046181 108
dflet 3:a8c249046181 109 \note
dflet 3:a8c249046181 110
dflet 3:a8c249046181 111 \warning
dflet 3:a8c249046181 112 */
dflet 3:a8c249046181 113 void button1_InterruptDisable();
dflet 3:a8c249046181 114
dflet 3:a8c249046181 115 /*!
dflet 3:a8c249046181 116 \brief Enables the button push interrupt
dflet 3:a8c249046181 117
dflet 3:a8c249046181 118 \param[in] none
dflet 3:a8c249046181 119
dflet 3:a8c249046181 120 \return none
dflet 3:a8c249046181 121
dflet 3:a8c249046181 122 \note
dflet 3:a8c249046181 123
dflet 3:a8c249046181 124 \warning
dflet 3:a8c249046181 125 */
dflet 3:a8c249046181 126 void button1_InterruptEnable();
dflet 3:a8c249046181 127
dflet 3:a8c249046181 128 /*!
dflet 3:a8c249046181 129 \brief Disables the button push interrupt
dflet 3:a8c249046181 130
dflet 3:a8c249046181 131 \param[in] none
dflet 3:a8c249046181 132
dflet 3:a8c249046181 133 \return none
dflet 3:a8c249046181 134
dflet 3:a8c249046181 135 \note
dflet 3:a8c249046181 136
dflet 3:a8c249046181 137 \warning
dflet 3:a8c249046181 138 */
dflet 3:a8c249046181 139 void button2_InterruptDisable();
dflet 3:a8c249046181 140
dflet 3:a8c249046181 141 /*!
dflet 3:a8c249046181 142 \brief Enables the button push interrupt
dflet 3:a8c249046181 143
dflet 3:a8c249046181 144 \param[in] none
dflet 3:a8c249046181 145
dflet 3:a8c249046181 146 \return none
dflet 3:a8c249046181 147
dflet 3:a8c249046181 148 \note
dflet 3:a8c249046181 149
dflet 3:a8c249046181 150 \warning
dflet 3:a8c249046181 151 */
dflet 3:a8c249046181 152 void button2_InterruptEnable();
dflet 3:a8c249046181 153
dflet 3:a8c249046181 154 /*!
dflet 3:a8c249046181 155 \brief Enables the interrupt from the CC3100
dflet 3:a8c249046181 156
dflet 3:a8c249046181 157 \param[in] none
dflet 3:a8c249046181 158
dflet 3:a8c249046181 159 \return none
dflet 3:a8c249046181 160
dflet 3:a8c249046181 161 \note
dflet 3:a8c249046181 162
dflet 3:a8c249046181 163 \warning
dflet 3:a8c249046181 164 */
dflet 3:a8c249046181 165 void cc3100_InterruptEnable();
dflet 3:a8c249046181 166
dflet 3:a8c249046181 167 /*!
dflet 3:a8c249046181 168 \brief Disables the interrupt from the CC3100
dflet 3:a8c249046181 169
dflet 3:a8c249046181 170 \param[in] none
dflet 3:a8c249046181 171
dflet 3:a8c249046181 172 \return none
dflet 3:a8c249046181 173
dflet 3:a8c249046181 174 \note
dflet 3:a8c249046181 175
dflet 3:a8c249046181 176 \warning
dflet 3:a8c249046181 177 */
dflet 3:a8c249046181 178 void cc3100_InterruptDisable();
dflet 3:a8c249046181 179
dflet 3:a8c249046181 180 /*!
dflet 3:a8c249046181 181 \brief open spi communication port to be used for communicating with a
dflet 3:a8c249046181 182 SimpleLink device
dflet 3:a8c249046181 183
dflet 3:a8c249046181 184 Given an interface name and option flags, this function opens the spi
dflet 3:a8c249046181 185 communication port and creates a file descriptor. This file descriptor can
dflet 3:a8c249046181 186 be used afterwards to read and write data from and to this specific spi
dflet 3:a8c249046181 187 channel.
dflet 3:a8c249046181 188 The SPI speed, clock polarity, clock phase, chip select and all other
dflet 3:a8c249046181 189 attributes are all set to hardcoded values in this function.
dflet 3:a8c249046181 190
dflet 3:a8c249046181 191 \param[in] ifName - points to the interface name/path. The
dflet 3:a8c249046181 192 interface name is an optional attributes that the simple
dflet 3:a8c249046181 193 link driver receives on opening the device. in systems that
dflet 3:a8c249046181 194 the spi channel is not implemented as part of the os device
dflet 3:a8c249046181 195 drivers, this parameter could be NULL.
dflet 3:a8c249046181 196 \param[in] flags - option flags
dflet 3:a8c249046181 197
dflet 3:a8c249046181 198 \return upon successful completion, the function shall open the spi
dflet 3:a8c249046181 199 channel and return a non-negative integer representing the
dflet 3:a8c249046181 200 file descriptor. Otherwise, -1 shall be returned
dflet 3:a8c249046181 201
dflet 3:a8c249046181 202 \sa spi_Close , spi_Read , spi_Write
dflet 3:a8c249046181 203 \note
dflet 3:a8c249046181 204 \warning
dflet 3:a8c249046181 205 */
dflet 3:a8c249046181 206
dflet 3:a8c249046181 207 Fd_t spi_Open(int8_t *ifName, uint32_t flags);
dflet 3:a8c249046181 208
dflet 3:a8c249046181 209 /*!
dflet 3:a8c249046181 210 \brief closes an opened spi communication port
dflet 3:a8c249046181 211
dflet 3:a8c249046181 212 \param[in] fd - file descriptor of an opened SPI channel
dflet 3:a8c249046181 213
dflet 3:a8c249046181 214 \return upon successful completion, the function shall return 0.
dflet 3:a8c249046181 215 Otherwise, -1 shall be returned
dflet 3:a8c249046181 216
dflet 3:a8c249046181 217 \sa spi_Open
dflet 3:a8c249046181 218 \note
dflet 3:a8c249046181 219 \warning
dflet 3:a8c249046181 220 */
dflet 3:a8c249046181 221 int spi_Close(Fd_t fd);
dflet 3:a8c249046181 222
dflet 3:a8c249046181 223 /*!
dflet 3:a8c249046181 224 \brief attempts to read up to len bytes from SPI channel into a buffer
dflet 3:a8c249046181 225 starting at pBuff.
dflet 3:a8c249046181 226
dflet 3:a8c249046181 227 \param[in] fd - file descriptor of an opened SPI channel
dflet 3:a8c249046181 228
dflet 3:a8c249046181 229 \param[in] pBuff - points to first location to start writing the
dflet 3:a8c249046181 230 data
dflet 3:a8c249046181 231
dflet 3:a8c249046181 232 \param[in] len - number of bytes to read from the SPI channel
dflet 3:a8c249046181 233
dflet 3:a8c249046181 234 \return upon successful completion, the function shall return 0.
dflet 3:a8c249046181 235 Otherwise, -1 shall be returned
dflet 3:a8c249046181 236
dflet 3:a8c249046181 237 \sa spi_Open , spi_Write
dflet 3:a8c249046181 238 \note
dflet 3:a8c249046181 239 \warning
dflet 3:a8c249046181 240 */
dflet 3:a8c249046181 241 int spi_Read(Fd_t fd, uint8_t *pBuff, int len);
dflet 3:a8c249046181 242
dflet 3:a8c249046181 243 /*!
dflet 3:a8c249046181 244 \brief attempts to write up to len bytes to the SPI channel
dflet 3:a8c249046181 245
dflet 3:a8c249046181 246 \param[in] fd - file descriptor of an opened SPI channel
dflet 3:a8c249046181 247
dflet 3:a8c249046181 248 \param[in] pBuff - points to first location to start getting the
dflet 3:a8c249046181 249 data from
dflet 3:a8c249046181 250
dflet 3:a8c249046181 251 \param[in] len - number of bytes to write to the SPI channel
dflet 3:a8c249046181 252
dflet 3:a8c249046181 253 \return upon successful completion, the function shall return 0.
dflet 3:a8c249046181 254 Otherwise, -1 shall be returned
dflet 3:a8c249046181 255
dflet 3:a8c249046181 256 \sa spi_Open , spi_Read
dflet 3:a8c249046181 257 \note This function could be implemented as zero copy and return
dflet 3:a8c249046181 258 only upon successful completion of writing the whole buffer,
dflet 3:a8c249046181 259 but in cases that memory allocation is not too tight, the
dflet 3:a8c249046181 260 function could copy the data to internal buffer, return
dflet 3:a8c249046181 261 back and complete the write in parallel to other activities
dflet 3:a8c249046181 262 as long as the other SPI activities would be blocked untill
dflet 3:a8c249046181 263 the entire buffer write would be completed
dflet 3:a8c249046181 264 \warning
dflet 3:a8c249046181 265 */
dflet 3:a8c249046181 266 int spi_Write(Fd_t fd, uint8_t *pBuff, int len);
dflet 3:a8c249046181 267
dflet 3:a8c249046181 268 /*!
dflet 3:a8c249046181 269 \brief The IntSpiGPIOHandler interrupt handler
dflet 3:a8c249046181 270
dflet 3:a8c249046181 271 \param[in] none
dflet 3:a8c249046181 272
dflet 3:a8c249046181 273 \return none
dflet 3:a8c249046181 274
dflet 3:a8c249046181 275 \note
dflet 3:a8c249046181 276
dflet 3:a8c249046181 277 \warning
dflet 3:a8c249046181 278 */
dflet 3:a8c249046181 279 void IntSpiGPIOHandler(void);
dflet 3:a8c249046181 280
dflet 3:a8c249046181 281 /*!
dflet 3:a8c249046181 282 \brief register an interrupt handler for the host IRQ
dflet 3:a8c249046181 283
dflet 3:a8c249046181 284 \param[in] InterruptHdl - pointer to interrupt handler function
dflet 3:a8c249046181 285
dflet 3:a8c249046181 286 \param[in] pValue - pointer to a memory strcuture that is
dflet 3:a8c249046181 287 passed to the interrupt handler.
dflet 3:a8c249046181 288
dflet 3:a8c249046181 289 \return upon successful registration, the function shall return 0.
dflet 3:a8c249046181 290 Otherwise, -1 shall be returned
dflet 3:a8c249046181 291
dflet 3:a8c249046181 292 \sa
dflet 3:a8c249046181 293 \note If there is already registered interrupt handler, the
dflet 3:a8c249046181 294 function should overwrite the old handler with the new one
dflet 3:a8c249046181 295 \warning
dflet 3:a8c249046181 296 */
dflet 3:a8c249046181 297 int registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue);
dflet 3:a8c249046181 298
dflet 3:a8c249046181 299 /*!
dflet 3:a8c249046181 300 \brief Masks the Host IRQ
dflet 3:a8c249046181 301
dflet 3:a8c249046181 302 \param[in] none
dflet 3:a8c249046181 303
dflet 3:a8c249046181 304 \return none
dflet 3:a8c249046181 305
dflet 3:a8c249046181 306 \warning
dflet 3:a8c249046181 307 */
dflet 3:a8c249046181 308 void MaskIntHdlr();
dflet 3:a8c249046181 309
dflet 3:a8c249046181 310 /*!
dflet 3:a8c249046181 311 \brief Unmasks the Host IRQ
dflet 3:a8c249046181 312
dflet 3:a8c249046181 313 \param[in] none
dflet 3:a8c249046181 314
dflet 3:a8c249046181 315 \return none
dflet 3:a8c249046181 316
dflet 3:a8c249046181 317 \warning
dflet 3:a8c249046181 318 */
dflet 3:a8c249046181 319 void UnMaskIntHdlr();
dflet 3:a8c249046181 320
dflet 3:a8c249046181 321 void buttonHandler_1(void);
dflet 3:a8c249046181 322
dflet 3:a8c249046181 323 void buttonHandler_2(void);
dflet 3:a8c249046181 324
dflet 3:a8c249046181 325 private:
dflet 3:a8c249046181 326
dflet 3:a8c249046181 327 InterruptIn _sw1_irq;
dflet 3:a8c249046181 328 InterruptIn _sw2_irq;
dflet 3:a8c249046181 329 InterruptIn _wlan_irq;
dflet 3:a8c249046181 330 DigitalOut _wlan_nHIB;
dflet 3:a8c249046181 331 DigitalOut _wlan_cs;
dflet 3:a8c249046181 332 SPI _wlan_spi;
dflet 3:a8c249046181 333 cc3100_driver &_driver;
dflet 3:a8c249046181 334
dflet 3:a8c249046181 335
dflet 3:a8c249046181 336 };//class
dflet 3:a8c249046181 337 }//namespace mbed_cc3100
dflet 3:a8c249046181 338 #endif
dflet 3:a8c249046181 339