David Fletcher
/
cc3100_test
TI's CC3100 host driver and demo. Experimental and a work in progress.
Embed:
(wiki syntax)
Show/hide line numbers
cc3100_spi.h
00001 /* 00002 * spi.h - msp430f5529 experiment board spi interface implementation 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 00042 #include "mbed.h" 00043 00044 //#ifdef __cplusplus 00045 //extern "C" { 00046 //#endif 00047 00048 //namespace mbed_cc3100 { 00049 00050 /* This macro is for use by other macros to form a fully valid C statement. */ 00051 #define st(x) do { x } while (__LINE__ == -1) 00052 00053 /*! 00054 \brief type definition for the spi channel file descriptor 00055 00056 \note On each porting or platform the type could be whatever is needed 00057 - integer, pointer to structure etc. 00058 */ 00059 typedef unsigned int Fd_t; 00060 00061 typedef void (*P_EVENT_HANDLER)(void* pValue); 00062 00063 00064 class cc3100_spi { 00065 public: 00066 00067 cc3100_spi(PinName cc3100_irq, PinName cc3100_en, PinName cc3100_cs, SPI cc3100_spi); 00068 00069 ~cc3100_spi(); 00070 00071 /*! 00072 \brief Enables the CC3100 00073 00074 \param[in] none 00075 00076 \return none 00077 00078 \note 00079 00080 \warning 00081 */ 00082 //void CC3100_enable(); 00083 00084 /*! 00085 \brief Disables the CC3100 00086 00087 \param[in] none 00088 00089 \return none 00090 00091 \note 00092 00093 \warning 00094 */ 00095 //void CC3100_disable(); 00096 00097 /*! 00098 \brief Enables the interrupt from the CC3100 00099 00100 \param[in] none 00101 00102 \return none 00103 00104 \note 00105 00106 \warning 00107 */ 00108 void cc3100_InterruptEnable(); 00109 00110 /*! 00111 \brief Disables the interrupt from the CC3100 00112 00113 \param[in] none 00114 00115 \return none 00116 00117 \note 00118 00119 \warning 00120 */ 00121 void cc3100_InterruptDisable(); 00122 00123 /*! 00124 \brief open spi communication port to be used for communicating with a 00125 SimpleLink device 00126 00127 Given an interface name and option flags, this function opens the spi 00128 communication port and creates a file descriptor. This file descriptor can 00129 be used afterwards to read and write data from and to this specific spi 00130 channel. 00131 The SPI speed, clock polarity, clock phase, chip select and all other 00132 attributes are all set to hardcoded values in this function. 00133 00134 \param[in] ifName - points to the interface name/path. The 00135 interface name is an optional attributes that the simple 00136 link driver receives on opening the device. in systems that 00137 the spi channel is not implemented as part of the os device 00138 drivers, this parameter could be NULL. 00139 \param[in] flags - option flags 00140 00141 \return upon successful completion, the function shall open the spi 00142 channel and return a non-negative integer representing the 00143 file descriptor. Otherwise, -1 shall be returned 00144 00145 \sa spi_Close , spi_Read , spi_Write 00146 \note 00147 \warning 00148 */ 00149 00150 //Fd_t spi_Open(char *ifName, unsigned long flags); 00151 00152 /*! 00153 \brief closes an opened spi communication port 00154 00155 \param[in] fd - file descriptor of an opened SPI channel 00156 00157 \return upon successful completion, the function shall return 0. 00158 Otherwise, -1 shall be returned 00159 00160 \sa spi_Open 00161 \note 00162 \warning 00163 */ 00164 //int spi_Close(Fd_t fd); 00165 00166 /*! 00167 \brief attempts to read up to len bytes from SPI channel into a buffer 00168 starting at pBuff. 00169 00170 \param[in] fd - file descriptor of an opened SPI channel 00171 00172 \param[in] pBuff - points to first location to start writing the 00173 data 00174 00175 \param[in] len - number of bytes to read from the SPI channel 00176 00177 \return upon successful completion, the function shall return 0. 00178 Otherwise, -1 shall be returned 00179 00180 \sa spi_Open , spi_Write 00181 \note 00182 \warning 00183 */ 00184 //int spi_Read(Fd_t fd, unsigned char *pBuff, int len); 00185 00186 /*! 00187 \brief attempts to write up to len bytes to the SPI channel 00188 00189 \param[in] fd - file descriptor of an opened SPI channel 00190 00191 \param[in] pBuff - points to first location to start getting the 00192 data from 00193 00194 \param[in] len - number of bytes to write to the SPI channel 00195 00196 \return upon successful completion, the function shall return 0. 00197 Otherwise, -1 shall be returned 00198 00199 \sa spi_Open , spi_Read 00200 \note This function could be implemented as zero copy and return 00201 only upon successful completion of writing the whole buffer, 00202 but in cases that memory allocation is not too tight, the 00203 function could copy the data to internal buffer, return 00204 back and complete the write in parallel to other activities 00205 as long as the other SPI activities would be blocked untill 00206 the entire buffer write would be completed 00207 \warning 00208 */ 00209 //int spi_Write(Fd_t fd, unsigned char *pBuff, int len); 00210 00211 00212 public: 00213 00214 InterruptIn _wlan_irq; 00215 DigitalOut _wlan_nHIB; 00216 DigitalOut _wlan_cs; 00217 SPI _wlan_spi; 00218 00219 }; 00220 00221 #ifdef __cplusplus 00222 extern "C" { 00223 #endif /* __cplusplus */ 00224 00225 /*! 00226 \brief The IntSpiGPIOHandler interrupt handler 00227 00228 \param[in] none 00229 00230 \return none 00231 00232 \note 00233 00234 \warning 00235 */ 00236 void IntSpiGPIOHandler(void); 00237 00238 /*! 00239 \brief register an interrupt handler for the host IRQ 00240 00241 \param[in] InterruptHdl - pointer to interrupt handler function 00242 00243 \param[in] pValue - pointer to a memory strcuture that is 00244 passed to the interrupt handler. 00245 00246 \return upon successful registration, the function shall return 0. 00247 Otherwise, -1 shall be returned 00248 00249 \sa 00250 \note If there is already registered interrupt handler, the 00251 function should overwrite the old handler with the new one 00252 \warning 00253 */ 00254 int registerInterruptHandler(P_EVENT_HANDLER InterruptHdl , void* pValue); 00255 00256 /*! 00257 \brief Masks the Host IRQ 00258 00259 \param[in] none 00260 00261 \return none 00262 00263 \warning 00264 */ 00265 void MaskIntHdlr(); 00266 00267 /*! 00268 \brief Unmasks the Host IRQ 00269 00270 \param[in] none 00271 00272 \return none 00273 00274 \warning 00275 */ 00276 void UnMaskIntHdlr(); 00277 00278 /*! 00279 \brief Disables the CC3100 00280 00281 \param[in] none 00282 00283 \return none 00284 00285 \note 00286 00287 \warning 00288 */ 00289 void CC3100_disable(); 00290 00291 /*! 00292 \brief Enables the CC3100 00293 00294 \param[in] none 00295 00296 \return none 00297 00298 \note 00299 00300 \warning 00301 */ 00302 void CC3100_enable(); 00303 00304 /*! 00305 \brief open spi communication port to be used for communicating with a 00306 SimpleLink device 00307 00308 Given an interface name and option flags, this function opens the spi 00309 communication port and creates a file descriptor. This file descriptor can 00310 be used afterwards to read and write data from and to this specific spi 00311 channel. 00312 The SPI speed, clock polarity, clock phase, chip select and all other 00313 attributes are all set to hardcoded values in this function. 00314 00315 \param[in] ifName - points to the interface name/path. The 00316 interface name is an optional attributes that the simple 00317 link driver receives on opening the device. in systems that 00318 the spi channel is not implemented as part of the os device 00319 drivers, this parameter could be NULL. 00320 \param[in] flags - option flags 00321 00322 \return upon successful completion, the function shall open the spi 00323 channel and return a non-negative integer representing the 00324 file descriptor. Otherwise, -1 shall be returned 00325 00326 \sa spi_Close , spi_Read , spi_Write 00327 \note 00328 \warning 00329 */ 00330 00331 Fd_t spi_Open(char *ifName, unsigned long flags); 00332 00333 /*! 00334 \brief closes an opened spi communication port 00335 00336 \param[in] fd - file descriptor of an opened SPI channel 00337 00338 \return upon successful completion, the function shall return 0. 00339 Otherwise, -1 shall be returned 00340 00341 \sa spi_Open 00342 \note 00343 \warning 00344 */ 00345 int spi_Close(Fd_t fd); 00346 00347 /*! 00348 \brief attempts to read up to len bytes from SPI channel into a buffer 00349 starting at pBuff. 00350 00351 \param[in] fd - file descriptor of an opened SPI channel 00352 00353 \param[in] pBuff - points to first location to start writing the 00354 data 00355 00356 \param[in] len - number of bytes to read from the SPI channel 00357 00358 \return upon successful completion, the function shall return 0. 00359 Otherwise, -1 shall be returned 00360 00361 \sa spi_Open , spi_Write 00362 \note 00363 \warning 00364 */ 00365 int spi_Read(Fd_t fd, unsigned char *pBuff, int len); 00366 00367 /*! 00368 \brief attempts to write up to len bytes to the SPI channel 00369 00370 \param[in] fd - file descriptor of an opened SPI channel 00371 00372 \param[in] pBuff - points to first location to start getting the 00373 data from 00374 00375 \param[in] len - number of bytes to write to the SPI channel 00376 00377 \return upon successful completion, the function shall return 0. 00378 Otherwise, -1 shall be returned 00379 00380 \sa spi_Open , spi_Read 00381 \note This function could be implemented as zero copy and return 00382 only upon successful completion of writing the whole buffer, 00383 but in cases that memory allocation is not too tight, the 00384 function could copy the data to internal buffer, return 00385 back and complete the write in parallel to other activities 00386 as long as the other SPI activities would be blocked untill 00387 the entire buffer write would be completed 00388 \warning 00389 */ 00390 int spi_Write(Fd_t fd, unsigned char *pBuff, int len); 00391 00392 //}//namespace mbed_cc3100 00393 00394 #ifdef __cplusplus 00395 } 00396 #endif // __cplusplus 00397 00398 #endif 00399
Generated on Tue Jul 12 2022 22:55:20 by 1.7.2