Updated to use external spawn.

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:48:29 2015 +0000
Revision:
1:9b68e650b3f6
Parent:
0:1a07906111ec
Oppps

Who changed what in which revision?

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