Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.
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 #include "cli_uart.h" 00040 00041 #include "osi.h" 00042 #include "portmacro.h" 00043 #include "projdefs.h" 00044 00045 OsiMsgQ_t g_PBQueue; /*Message Queue*/ 00046 uint32_t g_publishCount; 00047 00048 namespace mbed_cc3100 { 00049 00050 P_EVENT_HANDLER pIraEventHandler = 0; 00051 uint8_t IntIsMasked; 00052 00053 cc3100_spi::cc3100_spi(PinName button1_irq, PinName button2_irq, PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver) 00054 : /*_sw1_irq(button1_irq), _sw2_irq(button2_irq),*/ _wlan_irq(cc3100_irq), _wlan_nHIB(cc3100_nHIB), _wlan_cs(cc3100_cs), _wlan_spi(cc3100_spi), _driver(driver) 00055 { 00056 00057 _wlan_spi.format(8,0);//Note: 8 bit Mode 0 00058 _wlan_spi.frequency(12000000); 00059 _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); //_SlDrvRxIrqHandler is called from IntSpiGPIOHandler 00060 // _sw1_irq.rise(this, &cc3100_spi::buttonHandler_1); 00061 // _sw2_irq.rise(this, &cc3100_spi::buttonHandler_2); 00062 _wlan_nHIB = 0; 00063 _wlan_cs = 1; 00064 wait_ms(100); 00065 00066 00067 } 00068 00069 cc3100_spi::~cc3100_spi() 00070 { 00071 00072 } 00073 00074 int cc3100_spi::spi_Close(Fd_t fd) 00075 { 00076 00077 // Disable WLAN Interrupt ... 00078 cc3100_InterruptDisable(); 00079 00080 return 0; 00081 } 00082 00083 void cc3100_spi::button1_InterruptDisable() 00084 { 00085 // _sw1_irq.rise(NULL); 00086 wait_ms(1); 00087 } 00088 00089 void cc3100_spi::button2_InterruptDisable() 00090 { 00091 // _sw2_irq.rise(NULL); 00092 wait_ms(1); 00093 } 00094 00095 void cc3100_spi::button1_InterruptEnable() 00096 { 00097 // _sw1_irq.rise(this, &cc3100_spi::buttonHandler_1); 00098 } 00099 00100 void cc3100_spi::button2_InterruptEnable() 00101 { 00102 // _sw2_irq.rise(this, &cc3100_spi::buttonHandler_2); 00103 } 00104 00105 void cc3100_spi::cc3100_InterruptEnable() 00106 { 00107 _wlan_irq.rise(this, &cc3100_spi::IntSpiGPIOHandler); 00108 } 00109 00110 void cc3100_spi::cc3100_InterruptDisable() 00111 { 00112 _wlan_irq.rise(NULL); 00113 } 00114 00115 void cc3100_spi::CC3100_disable() 00116 { 00117 _wlan_nHIB = 0; 00118 } 00119 00120 void cc3100_spi::CC3100_enable() 00121 { 00122 00123 _wlan_nHIB = 1; 00124 } 00125 00126 Fd_t cc3100_spi::spi_Open(int8_t *ifName, uint32_t flags) 00127 { 00128 00129 // Enable WLAN interrupt 00130 cc3100_InterruptEnable(); 00131 00132 return 0; 00133 } 00134 00135 int cc3100_spi::spi_Write(Fd_t fd, uint8_t *pBuff, int len) 00136 { 00137 int len_to_return = len; 00138 00139 _wlan_cs = 0; 00140 // wait_us(10); 00141 while(len) { 00142 _wlan_spi.write(*pBuff++); 00143 len--; 00144 } 00145 // wait_us(10); 00146 _wlan_cs = 1; 00147 00148 return len_to_return; 00149 } 00150 00151 int cc3100_spi::spi_Read(Fd_t fd, uint8_t *pBuff, int len) 00152 { 00153 int i = 0; 00154 00155 _wlan_cs = 0; 00156 // wait_us(10); 00157 for (i = 0; i < len; i++) { 00158 pBuff[i] = _wlan_spi.write(0xFF); 00159 } 00160 // wait_us(10); 00161 _wlan_cs = 1; 00162 return len; 00163 } 00164 00165 void cc3100_spi::IntSpiGPIOHandler(void) 00166 { 00167 00168 if(_wlan_irq){ 00169 _driver._SlDrvRxIrqHandler(0); 00170 } 00171 } 00172 00173 /*! 00174 \brief register an interrupt handler for the host IRQ 00175 00176 \param[in] InterruptHdl - pointer to interrupt handler function 00177 00178 \param[in] pValue - pointer to a memory strcuture that is 00179 passed to the interrupt handler. 00180 00181 \return upon successful registration, the function shall return 0. 00182 Otherwise, -1 shall be returned 00183 00184 \sa 00185 \note If there is already registered interrupt handler, the 00186 function should overwrite the old handler with the new one 00187 \warning 00188 */ 00189 int cc3100_spi::registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue) 00190 { 00191 00192 pIraEventHandler = InterruptHdl; 00193 return 0; 00194 } 00195 00196 /*! 00197 \brief Unmasks the Host IRQ 00198 00199 \param[in] none 00200 00201 \return none 00202 00203 \warning 00204 */ 00205 void cc3100_spi::UnMaskIntHdlr() 00206 { 00207 IntIsMasked = FALSE; 00208 } 00209 00210 /*! 00211 \brief Masks the Host IRQ 00212 00213 \param[in] none 00214 00215 \return none 00216 00217 \warning 00218 */ 00219 void cc3100_spi::MaskIntHdlr() 00220 { 00221 IntIsMasked = TRUE; 00222 } 00223 00224 /*! 00225 \brief Handles the button press 1 on the MCU 00226 and updates the queue with relevant action. 00227 00228 \param none 00229 00230 \return none 00231 */ 00232 void cc3100_spi::buttonHandler_1(void) 00233 { 00234 int32_t rv = 0; 00235 button1_InterruptDisable(); 00236 osi_messages var; 00237 00238 g_publishCount++; 00239 00240 var = PUSH_BUTTON_1_PRESSED; 00241 00242 rv = osi_MsgQWrite(&g_PBQueue, &var, OSI_NO_WAIT); 00243 if(rv < 0){ 00244 Uart_Write((uint8_t*)"Messsage queue failed\r\n"); 00245 } 00246 00247 } 00248 00249 /*! 00250 \brief Handles the button press 2 on the MCU 00251 and updates the queue with relevant action. 00252 00253 \param none 00254 00255 \return none 00256 */ 00257 void cc3100_spi::buttonHandler_2(void) 00258 { 00259 int32_t rv = 0; 00260 button2_InterruptDisable(); 00261 osi_messages var; 00262 00263 g_publishCount++; 00264 00265 var = PUSH_BUTTON_2_PRESSED; 00266 00267 rv = osi_MsgQWrite(&g_PBQueue, &var, OSI_NO_WAIT); 00268 if(rv < 0){ 00269 Uart_Write((uint8_t*)"Messsage queue failed\r\n"); 00270 } 00271 00272 } 00273 00274 }//namespace mbed_cc3100 00275 00276 00277 00278 00279 00280 00281 00282
Generated on Tue Jul 12 2022 22:22:38 by 1.7.2