Update revision to use TI's mqtt and Freertos.
Dependencies: mbed client server
Fork of cc3100_Test_mqtt_CM3 by
cc3100_spi.h
00001 /* 00002 * spi.h - 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 00038 #ifndef SPI_H_ 00039 #define SPI_H_ 00040 00041 #include "mbed.h" 00042 00043 /*! 00044 \brief type definition for the spi channel file descriptor 00045 00046 \note On each porting or platform the type could be whatever is needed 00047 - integer, pointer to structure etc. 00048 */ 00049 typedef unsigned int Fd_t; 00050 00051 typedef void (*P_EVENT_HANDLER)(void* pValue); 00052 00053 typedef enum events 00054 { 00055 NO_ACTION = -1, 00056 PUSH_BUTTON_1_PRESSED = 3, 00057 PUSH_BUTTON_2_PRESSED = 4, 00058 BROKER_DISCONNECTION = 2 00059 } osi_messages; 00060 00061 extern uint32_t g_publishCount; 00062 00063 namespace mbed_cc3100 { 00064 00065 class cc3100_driver; 00066 00067 class cc3100_spi 00068 { 00069 public: 00070 00071 cc3100_spi(PinName button1_irq, PinName button2_irq, PinName cc3100_irq, PinName cc3100_nHIB, PinName cc3100_cs, SPI cc3100_spi, cc3100_driver &driver); 00072 00073 ~cc3100_spi(); 00074 00075 00076 /*! 00077 \brief Enables the CC3100 00078 00079 \param[in] none 00080 00081 \return none 00082 00083 \note 00084 00085 \warning 00086 */ 00087 void CC3100_enable(); 00088 00089 /*! 00090 \brief Disables the CC3100 00091 00092 \param[in] none 00093 00094 \return none 00095 00096 \note 00097 00098 \warning 00099 */ 00100 void CC3100_disable(); 00101 00102 /*! 00103 \brief Disables the button push interrupt 00104 00105 \param[in] none 00106 00107 \return none 00108 00109 \note 00110 00111 \warning 00112 */ 00113 void button1_InterruptDisable(); 00114 00115 /*! 00116 \brief Enables the button push interrupt 00117 00118 \param[in] none 00119 00120 \return none 00121 00122 \note 00123 00124 \warning 00125 */ 00126 void button1_InterruptEnable(); 00127 00128 /*! 00129 \brief Disables the button push interrupt 00130 00131 \param[in] none 00132 00133 \return none 00134 00135 \note 00136 00137 \warning 00138 */ 00139 void button2_InterruptDisable(); 00140 00141 /*! 00142 \brief Enables the button push interrupt 00143 00144 \param[in] none 00145 00146 \return none 00147 00148 \note 00149 00150 \warning 00151 */ 00152 void button2_InterruptEnable(); 00153 00154 /*! 00155 \brief Enables the interrupt from the CC3100 00156 00157 \param[in] none 00158 00159 \return none 00160 00161 \note 00162 00163 \warning 00164 */ 00165 void cc3100_InterruptEnable(); 00166 00167 /*! 00168 \brief Disables the interrupt from the CC3100 00169 00170 \param[in] none 00171 00172 \return none 00173 00174 \note 00175 00176 \warning 00177 */ 00178 void cc3100_InterruptDisable(); 00179 00180 /*! 00181 \brief open spi communication port to be used for communicating with a 00182 SimpleLink device 00183 00184 Given an interface name and option flags, this function opens the spi 00185 communication port and creates a file descriptor. This file descriptor can 00186 be used afterwards to read and write data from and to this specific spi 00187 channel. 00188 The SPI speed, clock polarity, clock phase, chip select and all other 00189 attributes are all set to hardcoded values in this function. 00190 00191 \param[in] ifName - points to the interface name/path. The 00192 interface name is an optional attributes that the simple 00193 link driver receives on opening the device. in systems that 00194 the spi channel is not implemented as part of the os device 00195 drivers, this parameter could be NULL. 00196 \param[in] flags - option flags 00197 00198 \return upon successful completion, the function shall open the spi 00199 channel and return a non-negative integer representing the 00200 file descriptor. Otherwise, -1 shall be returned 00201 00202 \sa spi_Close , spi_Read , spi_Write 00203 \note 00204 \warning 00205 */ 00206 00207 Fd_t spi_Open(int8_t *ifName, uint32_t flags); 00208 00209 /*! 00210 \brief closes an opened spi communication port 00211 00212 \param[in] fd - file descriptor of an opened SPI channel 00213 00214 \return upon successful completion, the function shall return 0. 00215 Otherwise, -1 shall be returned 00216 00217 \sa spi_Open 00218 \note 00219 \warning 00220 */ 00221 int spi_Close(Fd_t fd); 00222 00223 /*! 00224 \brief attempts to read up to len bytes from SPI channel into a buffer 00225 starting at pBuff. 00226 00227 \param[in] fd - file descriptor of an opened SPI channel 00228 00229 \param[in] pBuff - points to first location to start writing the 00230 data 00231 00232 \param[in] len - number of bytes to read from the SPI channel 00233 00234 \return upon successful completion, the function shall return 0. 00235 Otherwise, -1 shall be returned 00236 00237 \sa spi_Open , spi_Write 00238 \note 00239 \warning 00240 */ 00241 int spi_Read(Fd_t fd, uint8_t *pBuff, int len); 00242 00243 /*! 00244 \brief attempts to write up to len bytes to the SPI channel 00245 00246 \param[in] fd - file descriptor of an opened SPI channel 00247 00248 \param[in] pBuff - points to first location to start getting the 00249 data from 00250 00251 \param[in] len - number of bytes to write to the SPI channel 00252 00253 \return upon successful completion, the function shall return 0. 00254 Otherwise, -1 shall be returned 00255 00256 \sa spi_Open , spi_Read 00257 \note This function could be implemented as zero copy and return 00258 only upon successful completion of writing the whole buffer, 00259 but in cases that memory allocation is not too tight, the 00260 function could copy the data to internal buffer, return 00261 back and complete the write in parallel to other activities 00262 as long as the other SPI activities would be blocked untill 00263 the entire buffer write would be completed 00264 \warning 00265 */ 00266 int spi_Write(Fd_t fd, uint8_t *pBuff, int len); 00267 00268 /*! 00269 \brief The IntSpiGPIOHandler interrupt handler 00270 00271 \param[in] none 00272 00273 \return none 00274 00275 \note 00276 00277 \warning 00278 */ 00279 void IntSpiGPIOHandler(void); 00280 00281 /*! 00282 \brief register an interrupt handler for the host IRQ 00283 00284 \param[in] InterruptHdl - pointer to interrupt handler function 00285 00286 \param[in] pValue - pointer to a memory strcuture that is 00287 passed to the interrupt handler. 00288 00289 \return upon successful registration, the function shall return 0. 00290 Otherwise, -1 shall be returned 00291 00292 \sa 00293 \note If there is already registered interrupt handler, the 00294 function should overwrite the old handler with the new one 00295 \warning 00296 */ 00297 int registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue); 00298 00299 /*! 00300 \brief Masks the Host IRQ 00301 00302 \param[in] none 00303 00304 \return none 00305 00306 \warning 00307 */ 00308 void MaskIntHdlr(); 00309 00310 /*! 00311 \brief Unmasks the Host IRQ 00312 00313 \param[in] none 00314 00315 \return none 00316 00317 \warning 00318 */ 00319 void UnMaskIntHdlr(); 00320 00321 void buttonHandler_1(void); 00322 00323 void buttonHandler_2(void); 00324 00325 private: 00326 00327 InterruptIn _sw1_irq; 00328 InterruptIn _sw2_irq; 00329 InterruptIn _wlan_irq; 00330 DigitalOut _wlan_nHIB; 00331 DigitalOut _wlan_cs; 00332 SPI _wlan_spi; 00333 cc3100_driver &_driver; 00334 00335 00336 };//class 00337 }//namespace mbed_cc3100 00338 #endif 00339
Generated on Tue Jul 12 2022 18:55:10 by 1.7.2