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