cc3100_Socket_Wifi_Server with Ethernet Interface not working
Dependencies: EthernetInterface mbed-rtos mbed
Fork of cc3100_Test_Demo by
simplelink/cc3100_spi.cpp@7:0687d16b9781, 2015-09-03 (annotated)
- Committer:
- dflet
- Date:
- Thu Sep 03 13:43:50 2015 +0000
- Revision:
- 7:0687d16b9781
- Parent:
- 0:e89ba455dbcf
Oooops SPI mode change from 1 to 0. Must be some clock skew to get away with that! Other updates.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:e89ba455dbcf | 1 | /* |
dflet | 0:e89ba455dbcf | 2 | * spi.cpp 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 | #include "cc3100_simplelink.h" |
dflet | 0:e89ba455dbcf | 38 | #include "cc3100_spi.h" |
dflet | 0:e89ba455dbcf | 39 | |
dflet | 0:e89ba455dbcf | 40 | |
dflet | 0:e89ba455dbcf | 41 | namespace mbed_cc3100 { |
dflet | 0:e89ba455dbcf | 42 | |
dflet | 0:e89ba455dbcf | 43 | P_EVENT_HANDLER pIraEventHandler = 0; |
dflet | 0:e89ba455dbcf | 44 | uint8_t IntIsMasked; |
dflet | 0:e89ba455dbcf | 45 | |
dflet | 0:e89ba455dbcf | 46 | cc3100_spi::cc3100_spi(PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver) |
dflet | 0:e89ba455dbcf | 47 | : _wlan_irq(cc3100_irq), _wlan_nHIB(cc3100_nHIB), _wlan_cs(cc3100_cs), _wlan_spi(cc3100_spi), _driver(driver) |
dflet | 0:e89ba455dbcf | 48 | { |
dflet | 0:e89ba455dbcf | 49 | |
dflet | 7:0687d16b9781 | 50 | _wlan_spi.format(8,0); |
dflet | 0:e89ba455dbcf | 51 | _wlan_spi.frequency(16000000); |
dflet | 0:e89ba455dbcf | 52 | _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); //_SlDrvRxIrqHandler is triggered after IntSpiGPIOHandler |
dflet | 0:e89ba455dbcf | 53 | _wlan_nHIB = 0; |
dflet | 0:e89ba455dbcf | 54 | _wlan_cs = 1; |
dflet | 0:e89ba455dbcf | 55 | wait_ms(200); |
dflet | 0:e89ba455dbcf | 56 | |
dflet | 0:e89ba455dbcf | 57 | |
dflet | 0:e89ba455dbcf | 58 | } |
dflet | 0:e89ba455dbcf | 59 | |
dflet | 0:e89ba455dbcf | 60 | cc3100_spi::~cc3100_spi() |
dflet | 0:e89ba455dbcf | 61 | { |
dflet | 0:e89ba455dbcf | 62 | |
dflet | 0:e89ba455dbcf | 63 | } |
dflet | 0:e89ba455dbcf | 64 | |
dflet | 0:e89ba455dbcf | 65 | int cc3100_spi::spi_Close(Fd_t fd) |
dflet | 0:e89ba455dbcf | 66 | { |
dflet | 0:e89ba455dbcf | 67 | // Disable WLAN Interrupt ... |
dflet | 0:e89ba455dbcf | 68 | cc3100_InterruptDisable(); |
dflet | 0:e89ba455dbcf | 69 | |
dflet | 0:e89ba455dbcf | 70 | return NONOS_RET_OK; |
dflet | 0:e89ba455dbcf | 71 | } |
dflet | 0:e89ba455dbcf | 72 | |
dflet | 0:e89ba455dbcf | 73 | void cc3100_spi::cc3100_InterruptEnable() |
dflet | 0:e89ba455dbcf | 74 | { |
dflet | 0:e89ba455dbcf | 75 | __enable_irq(); |
dflet | 0:e89ba455dbcf | 76 | } |
dflet | 0:e89ba455dbcf | 77 | |
dflet | 0:e89ba455dbcf | 78 | void cc3100_spi::cc3100_InterruptDisable() |
dflet | 0:e89ba455dbcf | 79 | { |
dflet | 0:e89ba455dbcf | 80 | __disable_irq(); |
dflet | 0:e89ba455dbcf | 81 | } |
dflet | 0:e89ba455dbcf | 82 | |
dflet | 0:e89ba455dbcf | 83 | void cc3100_spi::CC3100_disable() |
dflet | 0:e89ba455dbcf | 84 | { |
dflet | 0:e89ba455dbcf | 85 | _wlan_nHIB = 0; |
dflet | 0:e89ba455dbcf | 86 | } |
dflet | 0:e89ba455dbcf | 87 | |
dflet | 0:e89ba455dbcf | 88 | void cc3100_spi::CC3100_enable() |
dflet | 0:e89ba455dbcf | 89 | { |
dflet | 0:e89ba455dbcf | 90 | |
dflet | 0:e89ba455dbcf | 91 | _wlan_nHIB = 1; |
dflet | 0:e89ba455dbcf | 92 | } |
dflet | 0:e89ba455dbcf | 93 | |
dflet | 0:e89ba455dbcf | 94 | Fd_t cc3100_spi::spi_Open(int8_t *ifName, uint32_t flags) |
dflet | 0:e89ba455dbcf | 95 | { |
dflet | 0:e89ba455dbcf | 96 | |
dflet | 0:e89ba455dbcf | 97 | // 50 ms delay |
dflet | 0:e89ba455dbcf | 98 | wait_ms(50); |
dflet | 0:e89ba455dbcf | 99 | |
dflet | 0:e89ba455dbcf | 100 | // Enable WLAN interrupt |
dflet | 0:e89ba455dbcf | 101 | cc3100_InterruptEnable(); |
dflet | 0:e89ba455dbcf | 102 | |
dflet | 0:e89ba455dbcf | 103 | return NONOS_RET_OK; |
dflet | 0:e89ba455dbcf | 104 | } |
dflet | 0:e89ba455dbcf | 105 | |
dflet | 0:e89ba455dbcf | 106 | int cc3100_spi::spi_Write(Fd_t fd, uint8_t *pBuff, int len) |
dflet | 0:e89ba455dbcf | 107 | { |
dflet | 0:e89ba455dbcf | 108 | |
dflet | 0:e89ba455dbcf | 109 | int len_to_return = len; |
dflet | 0:e89ba455dbcf | 110 | |
dflet | 0:e89ba455dbcf | 111 | _wlan_cs = 0; |
dflet | 0:e89ba455dbcf | 112 | |
dflet | 0:e89ba455dbcf | 113 | while(len) { |
dflet | 0:e89ba455dbcf | 114 | _wlan_spi.write(*pBuff++); |
dflet | 0:e89ba455dbcf | 115 | len--; |
dflet | 0:e89ba455dbcf | 116 | } |
dflet | 0:e89ba455dbcf | 117 | |
dflet | 0:e89ba455dbcf | 118 | _wlan_cs = 1; |
dflet | 0:e89ba455dbcf | 119 | |
dflet | 0:e89ba455dbcf | 120 | return len_to_return; |
dflet | 0:e89ba455dbcf | 121 | } |
dflet | 0:e89ba455dbcf | 122 | |
dflet | 0:e89ba455dbcf | 123 | int cc3100_spi::spi_Read(Fd_t fd, uint8_t *pBuff, int len) |
dflet | 0:e89ba455dbcf | 124 | { |
dflet | 0:e89ba455dbcf | 125 | int i = 0; |
dflet | 0:e89ba455dbcf | 126 | |
dflet | 0:e89ba455dbcf | 127 | _wlan_cs = 0; |
dflet | 0:e89ba455dbcf | 128 | |
dflet | 0:e89ba455dbcf | 129 | for (i = 0; i < len; i++) { |
dflet | 0:e89ba455dbcf | 130 | pBuff[i] = _wlan_spi.write(0xFF); |
dflet | 0:e89ba455dbcf | 131 | } |
dflet | 0:e89ba455dbcf | 132 | |
dflet | 0:e89ba455dbcf | 133 | _wlan_cs = 1; |
dflet | 0:e89ba455dbcf | 134 | |
dflet | 0:e89ba455dbcf | 135 | return len; |
dflet | 0:e89ba455dbcf | 136 | } |
dflet | 0:e89ba455dbcf | 137 | |
dflet | 0:e89ba455dbcf | 138 | void cc3100_spi::IntSpiGPIOHandler(void) |
dflet | 0:e89ba455dbcf | 139 | { |
dflet | 0:e89ba455dbcf | 140 | |
dflet | 0:e89ba455dbcf | 141 | if(_wlan_irq){ |
dflet | 0:e89ba455dbcf | 142 | _driver._SlDrvRxIrqHandler(0); |
dflet | 0:e89ba455dbcf | 143 | } |
dflet | 0:e89ba455dbcf | 144 | } |
dflet | 0:e89ba455dbcf | 145 | |
dflet | 0:e89ba455dbcf | 146 | /*! |
dflet | 0:e89ba455dbcf | 147 | \brief register an interrupt handler for the host IRQ |
dflet | 0:e89ba455dbcf | 148 | |
dflet | 0:e89ba455dbcf | 149 | \param[in] InterruptHdl - pointer to interrupt handler function |
dflet | 0:e89ba455dbcf | 150 | |
dflet | 0:e89ba455dbcf | 151 | \param[in] pValue - pointer to a memory strcuture that is |
dflet | 0:e89ba455dbcf | 152 | passed to the interrupt handler. |
dflet | 0:e89ba455dbcf | 153 | |
dflet | 0:e89ba455dbcf | 154 | \return upon successful registration, the function shall return 0. |
dflet | 0:e89ba455dbcf | 155 | Otherwise, -1 shall be returned |
dflet | 0:e89ba455dbcf | 156 | |
dflet | 0:e89ba455dbcf | 157 | \sa |
dflet | 0:e89ba455dbcf | 158 | \note If there is already registered interrupt handler, the |
dflet | 0:e89ba455dbcf | 159 | function should overwrite the old handler with the new one |
dflet | 0:e89ba455dbcf | 160 | \warning |
dflet | 0:e89ba455dbcf | 161 | */ |
dflet | 0:e89ba455dbcf | 162 | int cc3100_spi::registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue) |
dflet | 0:e89ba455dbcf | 163 | { |
dflet | 0:e89ba455dbcf | 164 | |
dflet | 0:e89ba455dbcf | 165 | pIraEventHandler = InterruptHdl; |
dflet | 0:e89ba455dbcf | 166 | return 0; |
dflet | 0:e89ba455dbcf | 167 | } |
dflet | 0:e89ba455dbcf | 168 | |
dflet | 0:e89ba455dbcf | 169 | /*! |
dflet | 0:e89ba455dbcf | 170 | \brief Unmasks the Host IRQ |
dflet | 0:e89ba455dbcf | 171 | |
dflet | 0:e89ba455dbcf | 172 | \param[in] none |
dflet | 0:e89ba455dbcf | 173 | |
dflet | 0:e89ba455dbcf | 174 | \return none |
dflet | 0:e89ba455dbcf | 175 | |
dflet | 0:e89ba455dbcf | 176 | \warning |
dflet | 0:e89ba455dbcf | 177 | */ |
dflet | 0:e89ba455dbcf | 178 | void cc3100_spi::UnMaskIntHdlr() |
dflet | 0:e89ba455dbcf | 179 | { |
dflet | 0:e89ba455dbcf | 180 | IntIsMasked = FALSE; |
dflet | 0:e89ba455dbcf | 181 | } |
dflet | 0:e89ba455dbcf | 182 | |
dflet | 0:e89ba455dbcf | 183 | /*! |
dflet | 0:e89ba455dbcf | 184 | \brief Masks the Host IRQ |
dflet | 0:e89ba455dbcf | 185 | |
dflet | 0:e89ba455dbcf | 186 | \param[in] none |
dflet | 0:e89ba455dbcf | 187 | |
dflet | 0:e89ba455dbcf | 188 | \return none |
dflet | 0:e89ba455dbcf | 189 | |
dflet | 0:e89ba455dbcf | 190 | \warning |
dflet | 0:e89ba455dbcf | 191 | */ |
dflet | 0:e89ba455dbcf | 192 | void cc3100_spi::MaskIntHdlr() |
dflet | 0:e89ba455dbcf | 193 | { |
dflet | 0:e89ba455dbcf | 194 | IntIsMasked = TRUE; |
dflet | 0:e89ba455dbcf | 195 | } |
dflet | 0:e89ba455dbcf | 196 | |
dflet | 0:e89ba455dbcf | 197 | }//namespace mbed_cc3100 |
dflet | 0:e89ba455dbcf | 198 | |
dflet | 0:e89ba455dbcf | 199 | |
dflet | 0:e89ba455dbcf | 200 | |
dflet | 0:e89ba455dbcf | 201 | |
dflet | 0:e89ba455dbcf | 202 |