David Fletcher
/
cc3100_Test_Demo
TI's CC3100. A test demo with very little testing done!
Embed:
(wiki syntax)
Show/hide line numbers
cc3100_spi.cpp
00001 /* 00002 * spi.cpp mbed 00003 * 00004 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 00005 * 00006 * 00007 * Redistribution and use in source and binary forms, with or without 00008 * modification, are permitted provided that the following conditions 00009 * are met: 00010 * 00011 * Redistributions of source code must retain the above copyright 00012 * notice, this list of conditions and the following disclaimer. 00013 * 00014 * Redistributions in binary form must reproduce the above copyright 00015 * notice, this list of conditions and the following disclaimer in the 00016 * documentation and/or other materials provided with the 00017 * distribution. 00018 * 00019 * Neither the name of Texas Instruments Incorporated nor the names of 00020 * its contributors may be used to endorse or promote products derived 00021 * from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00024 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00025 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00026 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 00027 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00028 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00029 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00030 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 00031 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00032 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 */ 00036 00037 #include "cc3100_simplelink.h" 00038 #include "cc3100_spi.h" 00039 00040 00041 namespace mbed_cc3100 { 00042 00043 P_EVENT_HANDLER pIraEventHandler = 0; 00044 uint8_t IntIsMasked; 00045 00046 cc3100_spi::cc3100_spi(PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver) 00047 : _wlan_irq(cc3100_irq), _wlan_nHIB(cc3100_nHIB), _wlan_cs(cc3100_cs), _wlan_spi(cc3100_spi), _driver(driver) 00048 { 00049 00050 _wlan_spi.format(8,0); 00051 _wlan_spi.frequency(16000000); 00052 _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); //_SlDrvRxIrqHandler is triggered after IntSpiGPIOHandler 00053 _wlan_nHIB = 0; 00054 _wlan_cs = 1; 00055 wait_ms(200); 00056 00057 00058 } 00059 00060 cc3100_spi::~cc3100_spi() 00061 { 00062 00063 } 00064 00065 int cc3100_spi::spi_Close(Fd_t fd) 00066 { 00067 // Disable WLAN Interrupt ... 00068 cc3100_InterruptDisable(); 00069 00070 return NONOS_RET_OK; 00071 } 00072 00073 void cc3100_spi::cc3100_InterruptEnable() 00074 { 00075 __enable_irq(); 00076 } 00077 00078 void cc3100_spi::cc3100_InterruptDisable() 00079 { 00080 __disable_irq(); 00081 } 00082 00083 void cc3100_spi::CC3100_disable() 00084 { 00085 _wlan_nHIB = 0; 00086 } 00087 00088 void cc3100_spi::CC3100_enable() 00089 { 00090 00091 _wlan_nHIB = 1; 00092 } 00093 00094 Fd_t cc3100_spi::spi_Open(int8_t *ifName, uint32_t flags) 00095 { 00096 00097 // 50 ms delay 00098 wait_ms(50); 00099 00100 // Enable WLAN interrupt 00101 cc3100_InterruptEnable(); 00102 00103 return NONOS_RET_OK; 00104 } 00105 00106 int cc3100_spi::spi_Write(Fd_t fd, uint8_t *pBuff, int len) 00107 { 00108 00109 int len_to_return = len; 00110 00111 _wlan_cs = 0; 00112 00113 while(len) { 00114 _wlan_spi.write(*pBuff++); 00115 len--; 00116 } 00117 00118 _wlan_cs = 1; 00119 00120 return len_to_return; 00121 } 00122 00123 int cc3100_spi::spi_Read(Fd_t fd, uint8_t *pBuff, int len) 00124 { 00125 int i = 0; 00126 00127 _wlan_cs = 0; 00128 00129 for (i = 0; i < len; i++) { 00130 pBuff[i] = _wlan_spi.write(0xFF); 00131 } 00132 00133 _wlan_cs = 1; 00134 00135 return len; 00136 } 00137 00138 void cc3100_spi::IntSpiGPIOHandler(void) 00139 { 00140 00141 if(_wlan_irq){ 00142 _driver._SlDrvRxIrqHandler(0); 00143 } 00144 } 00145 00146 /*! 00147 \brief register an interrupt handler for the host IRQ 00148 00149 \param[in] InterruptHdl - pointer to interrupt handler function 00150 00151 \param[in] pValue - pointer to a memory strcuture that is 00152 passed to the interrupt handler. 00153 00154 \return upon successful registration, the function shall return 0. 00155 Otherwise, -1 shall be returned 00156 00157 \sa 00158 \note If there is already registered interrupt handler, the 00159 function should overwrite the old handler with the new one 00160 \warning 00161 */ 00162 int cc3100_spi::registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue) 00163 { 00164 00165 pIraEventHandler = InterruptHdl; 00166 return 0; 00167 } 00168 00169 /*! 00170 \brief Unmasks the Host IRQ 00171 00172 \param[in] none 00173 00174 \return none 00175 00176 \warning 00177 */ 00178 void cc3100_spi::UnMaskIntHdlr() 00179 { 00180 IntIsMasked = FALSE; 00181 } 00182 00183 /*! 00184 \brief Masks the Host IRQ 00185 00186 \param[in] none 00187 00188 \return none 00189 00190 \warning 00191 */ 00192 void cc3100_spi::MaskIntHdlr() 00193 { 00194 IntIsMasked = TRUE; 00195 } 00196 00197 }//namespace mbed_cc3100 00198 00199 00200 00201 00202
Generated on Sun Jul 17 2022 07:25:50 by 1.7.2