![](/media/cache/profiles/5f55d0baa59f4bc1dc393149183f1492.jpg.50x50_q85.jpg)
wifi test
Dependencies: X_NUCLEO_IKS01A2 mbed-http
easy-connect/stm-spirit1-rf-driver/source/radio_spi.cpp@0:24d3eb812fd4, 2018-09-05 (annotated)
- Committer:
- JMF
- Date:
- Wed Sep 05 14:28:24 2018 +0000
- Revision:
- 0:24d3eb812fd4
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:24d3eb812fd4 | 1 | /** |
JMF | 0:24d3eb812fd4 | 2 | ****************************************************************************** |
JMF | 0:24d3eb812fd4 | 3 | * @file radio_spi.c |
JMF | 0:24d3eb812fd4 | 4 | * @author System Lab - NOIDA |
JMF | 0:24d3eb812fd4 | 5 | * @version V1.0.0 |
JMF | 0:24d3eb812fd4 | 6 | * @date 15-May-2014 |
JMF | 0:24d3eb812fd4 | 7 | * @brief This file provides code for the configuration of the SPI instances. |
JMF | 0:24d3eb812fd4 | 8 | ****************************************************************************** |
JMF | 0:24d3eb812fd4 | 9 | * @attention |
JMF | 0:24d3eb812fd4 | 10 | * |
JMF | 0:24d3eb812fd4 | 11 | * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2> |
JMF | 0:24d3eb812fd4 | 12 | * |
JMF | 0:24d3eb812fd4 | 13 | * Redistribution and use in source and binary forms, with or without modification, |
JMF | 0:24d3eb812fd4 | 14 | * are permitted provided that the following conditions are met: |
JMF | 0:24d3eb812fd4 | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
JMF | 0:24d3eb812fd4 | 16 | * this list of conditions and the following disclaimer. |
JMF | 0:24d3eb812fd4 | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
JMF | 0:24d3eb812fd4 | 18 | * this list of conditions and the following disclaimer in the documentation |
JMF | 0:24d3eb812fd4 | 19 | * and/or other materials provided with the distribution. |
JMF | 0:24d3eb812fd4 | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
JMF | 0:24d3eb812fd4 | 21 | * may be used to endorse or promote products derived from this software |
JMF | 0:24d3eb812fd4 | 22 | * without specific prior written permission. |
JMF | 0:24d3eb812fd4 | 23 | * |
JMF | 0:24d3eb812fd4 | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
JMF | 0:24d3eb812fd4 | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
JMF | 0:24d3eb812fd4 | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
JMF | 0:24d3eb812fd4 | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
JMF | 0:24d3eb812fd4 | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
JMF | 0:24d3eb812fd4 | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
JMF | 0:24d3eb812fd4 | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
JMF | 0:24d3eb812fd4 | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
JMF | 0:24d3eb812fd4 | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
JMF | 0:24d3eb812fd4 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
JMF | 0:24d3eb812fd4 | 34 | * |
JMF | 0:24d3eb812fd4 | 35 | ****************************************************************************** |
JMF | 0:24d3eb812fd4 | 36 | */ |
JMF | 0:24d3eb812fd4 | 37 | |
JMF | 0:24d3eb812fd4 | 38 | |
JMF | 0:24d3eb812fd4 | 39 | /* Includes ------------------------------------------------------------------*/ |
JMF | 0:24d3eb812fd4 | 40 | #include "radio_spi.h" |
JMF | 0:24d3eb812fd4 | 41 | |
JMF | 0:24d3eb812fd4 | 42 | #include "SimpleSpirit1.h" |
JMF | 0:24d3eb812fd4 | 43 | |
JMF | 0:24d3eb812fd4 | 44 | |
JMF | 0:24d3eb812fd4 | 45 | /** |
JMF | 0:24d3eb812fd4 | 46 | * @addtogroup BSP |
JMF | 0:24d3eb812fd4 | 47 | * @{ |
JMF | 0:24d3eb812fd4 | 48 | */ |
JMF | 0:24d3eb812fd4 | 49 | |
JMF | 0:24d3eb812fd4 | 50 | |
JMF | 0:24d3eb812fd4 | 51 | /** |
JMF | 0:24d3eb812fd4 | 52 | * @addtogroup X-NUCLEO-IDS02Ax |
JMF | 0:24d3eb812fd4 | 53 | * @{ |
JMF | 0:24d3eb812fd4 | 54 | */ |
JMF | 0:24d3eb812fd4 | 55 | |
JMF | 0:24d3eb812fd4 | 56 | |
JMF | 0:24d3eb812fd4 | 57 | /** |
JMF | 0:24d3eb812fd4 | 58 | * @defgroup RADIO_SPI_Private_TypesDefinitions RADIO_SPI Private Types Definitions |
JMF | 0:24d3eb812fd4 | 59 | * @{ |
JMF | 0:24d3eb812fd4 | 60 | */ |
JMF | 0:24d3eb812fd4 | 61 | |
JMF | 0:24d3eb812fd4 | 62 | /** |
JMF | 0:24d3eb812fd4 | 63 | * @} |
JMF | 0:24d3eb812fd4 | 64 | */ |
JMF | 0:24d3eb812fd4 | 65 | |
JMF | 0:24d3eb812fd4 | 66 | |
JMF | 0:24d3eb812fd4 | 67 | /** |
JMF | 0:24d3eb812fd4 | 68 | * @defgroup RADIO_SPI_Private_Defines RADIO_SPI Private Defines |
JMF | 0:24d3eb812fd4 | 69 | * @{ |
JMF | 0:24d3eb812fd4 | 70 | */ |
JMF | 0:24d3eb812fd4 | 71 | |
JMF | 0:24d3eb812fd4 | 72 | /** |
JMF | 0:24d3eb812fd4 | 73 | * @} |
JMF | 0:24d3eb812fd4 | 74 | */ |
JMF | 0:24d3eb812fd4 | 75 | |
JMF | 0:24d3eb812fd4 | 76 | |
JMF | 0:24d3eb812fd4 | 77 | /** |
JMF | 0:24d3eb812fd4 | 78 | * @defgroup RADIO_SPI_Private_Macros RADIO_SPI Private Macros |
JMF | 0:24d3eb812fd4 | 79 | * @{ |
JMF | 0:24d3eb812fd4 | 80 | */ |
JMF | 0:24d3eb812fd4 | 81 | |
JMF | 0:24d3eb812fd4 | 82 | /** |
JMF | 0:24d3eb812fd4 | 83 | * @} |
JMF | 0:24d3eb812fd4 | 84 | */ |
JMF | 0:24d3eb812fd4 | 85 | |
JMF | 0:24d3eb812fd4 | 86 | |
JMF | 0:24d3eb812fd4 | 87 | /** |
JMF | 0:24d3eb812fd4 | 88 | * @defgroup RADIO_SPI_Private_Variables RADIO_SPI Private Variables |
JMF | 0:24d3eb812fd4 | 89 | * @{ |
JMF | 0:24d3eb812fd4 | 90 | */ |
JMF | 0:24d3eb812fd4 | 91 | |
JMF | 0:24d3eb812fd4 | 92 | /** |
JMF | 0:24d3eb812fd4 | 93 | * @} |
JMF | 0:24d3eb812fd4 | 94 | */ |
JMF | 0:24d3eb812fd4 | 95 | |
JMF | 0:24d3eb812fd4 | 96 | |
JMF | 0:24d3eb812fd4 | 97 | /** |
JMF | 0:24d3eb812fd4 | 98 | * @defgroup RADIO_SPI_Private_FunctionPrototypes RADIO_SPI Private Function Prototypes |
JMF | 0:24d3eb812fd4 | 99 | * @{ |
JMF | 0:24d3eb812fd4 | 100 | */ |
JMF | 0:24d3eb812fd4 | 101 | |
JMF | 0:24d3eb812fd4 | 102 | /** |
JMF | 0:24d3eb812fd4 | 103 | * @} |
JMF | 0:24d3eb812fd4 | 104 | */ |
JMF | 0:24d3eb812fd4 | 105 | |
JMF | 0:24d3eb812fd4 | 106 | /** |
JMF | 0:24d3eb812fd4 | 107 | * @defgroup RADIO_SPI_Private_Functions RADIO_SPI Private Functions |
JMF | 0:24d3eb812fd4 | 108 | * @{ |
JMF | 0:24d3eb812fd4 | 109 | */ |
JMF | 0:24d3eb812fd4 | 110 | |
JMF | 0:24d3eb812fd4 | 111 | /** |
JMF | 0:24d3eb812fd4 | 112 | * @} |
JMF | 0:24d3eb812fd4 | 113 | */ |
JMF | 0:24d3eb812fd4 | 114 | |
JMF | 0:24d3eb812fd4 | 115 | /** |
JMF | 0:24d3eb812fd4 | 116 | * @brief Write single or multiple RF Transceivers register |
JMF | 0:24d3eb812fd4 | 117 | * @param cRegAddress: base register's address to be write |
JMF | 0:24d3eb812fd4 | 118 | * @param cNbBytes: number of registers and bytes to be write |
JMF | 0:24d3eb812fd4 | 119 | * @param pcBuffer: pointer to the buffer of values have to be written into registers |
JMF | 0:24d3eb812fd4 | 120 | * @retval StatusBytes |
JMF | 0:24d3eb812fd4 | 121 | */ |
JMF | 0:24d3eb812fd4 | 122 | StatusBytes SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 123 | { |
JMF | 0:24d3eb812fd4 | 124 | return SimpleSpirit1::Instance().SdkEvalSpiWriteRegisters(cRegAddress, cNbBytes, pcBuffer); |
JMF | 0:24d3eb812fd4 | 125 | } |
JMF | 0:24d3eb812fd4 | 126 | |
JMF | 0:24d3eb812fd4 | 127 | StatusBytes SimpleSpirit1::SdkEvalSpiWriteRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 128 | { |
JMF | 0:24d3eb812fd4 | 129 | uint8_t aHeader[2] = {0}; |
JMF | 0:24d3eb812fd4 | 130 | uint16_t tmpstatus = 0x0000; |
JMF | 0:24d3eb812fd4 | 131 | StatusBytes *pStatus=(StatusBytes *)&tmpstatus; |
JMF | 0:24d3eb812fd4 | 132 | |
JMF | 0:24d3eb812fd4 | 133 | /* Built the aHeader bytes */ |
JMF | 0:24d3eb812fd4 | 134 | aHeader[0] = WRITE_HEADER; |
JMF | 0:24d3eb812fd4 | 135 | aHeader[1] = cRegAddress; |
JMF | 0:24d3eb812fd4 | 136 | |
JMF | 0:24d3eb812fd4 | 137 | /* Puts the SPI chip select low to start the transaction */ |
JMF | 0:24d3eb812fd4 | 138 | chip_sync_select(); |
JMF | 0:24d3eb812fd4 | 139 | |
JMF | 0:24d3eb812fd4 | 140 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 141 | tmpstatus = _spi.write(aHeader[0]); |
JMF | 0:24d3eb812fd4 | 142 | tmpstatus = tmpstatus << 8; |
JMF | 0:24d3eb812fd4 | 143 | |
JMF | 0:24d3eb812fd4 | 144 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 145 | tmpstatus |= _spi.write(aHeader[1]); |
JMF | 0:24d3eb812fd4 | 146 | |
JMF | 0:24d3eb812fd4 | 147 | /* Writes the registers according to the number of bytes */ |
JMF | 0:24d3eb812fd4 | 148 | for (int index = 0; index < cNbBytes; index++) |
JMF | 0:24d3eb812fd4 | 149 | { |
JMF | 0:24d3eb812fd4 | 150 | _spi.write(pcBuffer[index]); |
JMF | 0:24d3eb812fd4 | 151 | } |
JMF | 0:24d3eb812fd4 | 152 | |
JMF | 0:24d3eb812fd4 | 153 | /* Puts the SPI chip select high to end the transaction */ |
JMF | 0:24d3eb812fd4 | 154 | chip_sync_unselect(); |
JMF | 0:24d3eb812fd4 | 155 | |
JMF | 0:24d3eb812fd4 | 156 | return *pStatus; |
JMF | 0:24d3eb812fd4 | 157 | } |
JMF | 0:24d3eb812fd4 | 158 | |
JMF | 0:24d3eb812fd4 | 159 | |
JMF | 0:24d3eb812fd4 | 160 | /** |
JMF | 0:24d3eb812fd4 | 161 | * @brief Read single or multiple SPIRIT1 register |
JMF | 0:24d3eb812fd4 | 162 | * @param cRegAddress: base register's address to be read |
JMF | 0:24d3eb812fd4 | 163 | * @param cNbBytes: number of registers and bytes to be read |
JMF | 0:24d3eb812fd4 | 164 | * @param pcBuffer: pointer to the buffer of registers' values read |
JMF | 0:24d3eb812fd4 | 165 | * @retval StatusBytes |
JMF | 0:24d3eb812fd4 | 166 | */ |
JMF | 0:24d3eb812fd4 | 167 | StatusBytes SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 168 | { |
JMF | 0:24d3eb812fd4 | 169 | return SimpleSpirit1::Instance().SdkEvalSpiReadRegisters(cRegAddress, cNbBytes, pcBuffer); |
JMF | 0:24d3eb812fd4 | 170 | } |
JMF | 0:24d3eb812fd4 | 171 | |
JMF | 0:24d3eb812fd4 | 172 | StatusBytes SimpleSpirit1::SdkEvalSpiReadRegisters(uint8_t cRegAddress, uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 173 | { |
JMF | 0:24d3eb812fd4 | 174 | uint16_t tmpstatus = 0x00; |
JMF | 0:24d3eb812fd4 | 175 | StatusBytes *pStatus = (StatusBytes *)&tmpstatus; |
JMF | 0:24d3eb812fd4 | 176 | |
JMF | 0:24d3eb812fd4 | 177 | uint8_t aHeader[2] = {0}; |
JMF | 0:24d3eb812fd4 | 178 | |
JMF | 0:24d3eb812fd4 | 179 | /* Built the aHeader bytes */ |
JMF | 0:24d3eb812fd4 | 180 | aHeader[0] = READ_HEADER; |
JMF | 0:24d3eb812fd4 | 181 | aHeader[1] = cRegAddress; |
JMF | 0:24d3eb812fd4 | 182 | |
JMF | 0:24d3eb812fd4 | 183 | /* Put the SPI chip select low to start the transaction */ |
JMF | 0:24d3eb812fd4 | 184 | chip_sync_select(); |
JMF | 0:24d3eb812fd4 | 185 | |
JMF | 0:24d3eb812fd4 | 186 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 187 | tmpstatus = _spi.write(aHeader[0]); |
JMF | 0:24d3eb812fd4 | 188 | tmpstatus = tmpstatus << 8; |
JMF | 0:24d3eb812fd4 | 189 | |
JMF | 0:24d3eb812fd4 | 190 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 191 | tmpstatus |= _spi.write(aHeader[1]); |
JMF | 0:24d3eb812fd4 | 192 | |
JMF | 0:24d3eb812fd4 | 193 | for (int index = 0; index < cNbBytes; index++) |
JMF | 0:24d3eb812fd4 | 194 | { |
JMF | 0:24d3eb812fd4 | 195 | pcBuffer[index] = _spi.write(0xFF); |
JMF | 0:24d3eb812fd4 | 196 | } |
JMF | 0:24d3eb812fd4 | 197 | |
JMF | 0:24d3eb812fd4 | 198 | /* Put the SPI chip select high to end the transaction */ |
JMF | 0:24d3eb812fd4 | 199 | chip_sync_unselect(); |
JMF | 0:24d3eb812fd4 | 200 | |
JMF | 0:24d3eb812fd4 | 201 | return *pStatus; |
JMF | 0:24d3eb812fd4 | 202 | } |
JMF | 0:24d3eb812fd4 | 203 | |
JMF | 0:24d3eb812fd4 | 204 | |
JMF | 0:24d3eb812fd4 | 205 | /** |
JMF | 0:24d3eb812fd4 | 206 | * @brief Send a command |
JMF | 0:24d3eb812fd4 | 207 | * @param cCommandCode: command code to be sent |
JMF | 0:24d3eb812fd4 | 208 | * @retval StatusBytes |
JMF | 0:24d3eb812fd4 | 209 | */ |
JMF | 0:24d3eb812fd4 | 210 | StatusBytes SdkEvalSpiCommandStrobes(uint8_t cCommandCode) |
JMF | 0:24d3eb812fd4 | 211 | { |
JMF | 0:24d3eb812fd4 | 212 | return SimpleSpirit1::Instance().SdkEvalSpiCommandStrobes(cCommandCode); |
JMF | 0:24d3eb812fd4 | 213 | } |
JMF | 0:24d3eb812fd4 | 214 | |
JMF | 0:24d3eb812fd4 | 215 | StatusBytes SimpleSpirit1::SdkEvalSpiCommandStrobes(uint8_t cCommandCode) |
JMF | 0:24d3eb812fd4 | 216 | { |
JMF | 0:24d3eb812fd4 | 217 | uint8_t aHeader[2] = {0}; |
JMF | 0:24d3eb812fd4 | 218 | uint16_t tmpstatus = 0x0000; |
JMF | 0:24d3eb812fd4 | 219 | |
JMF | 0:24d3eb812fd4 | 220 | StatusBytes *pStatus = (StatusBytes *)&tmpstatus; |
JMF | 0:24d3eb812fd4 | 221 | |
JMF | 0:24d3eb812fd4 | 222 | /* Built the aHeader bytes */ |
JMF | 0:24d3eb812fd4 | 223 | aHeader[0] = COMMAND_HEADER; |
JMF | 0:24d3eb812fd4 | 224 | aHeader[1] = cCommandCode; |
JMF | 0:24d3eb812fd4 | 225 | |
JMF | 0:24d3eb812fd4 | 226 | /* Puts the SPI chip select low to start the transaction */ |
JMF | 0:24d3eb812fd4 | 227 | chip_sync_select(); |
JMF | 0:24d3eb812fd4 | 228 | |
JMF | 0:24d3eb812fd4 | 229 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 230 | tmpstatus = _spi.write(aHeader[0]); |
JMF | 0:24d3eb812fd4 | 231 | tmpstatus = tmpstatus<<8; |
JMF | 0:24d3eb812fd4 | 232 | |
JMF | 0:24d3eb812fd4 | 233 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 234 | tmpstatus |= _spi.write(aHeader[1]); |
JMF | 0:24d3eb812fd4 | 235 | |
JMF | 0:24d3eb812fd4 | 236 | /* Puts the SPI chip select high to end the transaction */ |
JMF | 0:24d3eb812fd4 | 237 | chip_sync_unselect(); |
JMF | 0:24d3eb812fd4 | 238 | |
JMF | 0:24d3eb812fd4 | 239 | return *pStatus; |
JMF | 0:24d3eb812fd4 | 240 | } |
JMF | 0:24d3eb812fd4 | 241 | |
JMF | 0:24d3eb812fd4 | 242 | |
JMF | 0:24d3eb812fd4 | 243 | /** |
JMF | 0:24d3eb812fd4 | 244 | * @brief Write data into TX FIFO |
JMF | 0:24d3eb812fd4 | 245 | * @param cNbBytes: number of bytes to be written into TX FIFO |
JMF | 0:24d3eb812fd4 | 246 | * @param pcBuffer: pointer to data to write |
JMF | 0:24d3eb812fd4 | 247 | * @retval StatusBytes |
JMF | 0:24d3eb812fd4 | 248 | */ |
JMF | 0:24d3eb812fd4 | 249 | StatusBytes SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 250 | { |
JMF | 0:24d3eb812fd4 | 251 | return SimpleSpirit1::Instance().SdkEvalSpiWriteFifo(cNbBytes, pcBuffer); |
JMF | 0:24d3eb812fd4 | 252 | } |
JMF | 0:24d3eb812fd4 | 253 | |
JMF | 0:24d3eb812fd4 | 254 | StatusBytes SimpleSpirit1::SdkEvalSpiWriteFifo(uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 255 | { |
JMF | 0:24d3eb812fd4 | 256 | uint16_t tmpstatus = 0x0000; |
JMF | 0:24d3eb812fd4 | 257 | StatusBytes *pStatus = (StatusBytes *)&tmpstatus; |
JMF | 0:24d3eb812fd4 | 258 | |
JMF | 0:24d3eb812fd4 | 259 | uint8_t aHeader[2] = {0}; |
JMF | 0:24d3eb812fd4 | 260 | |
JMF | 0:24d3eb812fd4 | 261 | /* Built the aHeader bytes */ |
JMF | 0:24d3eb812fd4 | 262 | aHeader[0] = WRITE_HEADER; |
JMF | 0:24d3eb812fd4 | 263 | aHeader[1] = LINEAR_FIFO_ADDRESS; |
JMF | 0:24d3eb812fd4 | 264 | |
JMF | 0:24d3eb812fd4 | 265 | /* Put the SPI chip select low to start the transaction */ |
JMF | 0:24d3eb812fd4 | 266 | chip_sync_select(); |
JMF | 0:24d3eb812fd4 | 267 | |
JMF | 0:24d3eb812fd4 | 268 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 269 | tmpstatus = _spi.write(aHeader[0]); |
JMF | 0:24d3eb812fd4 | 270 | tmpstatus = tmpstatus<<8; |
JMF | 0:24d3eb812fd4 | 271 | |
JMF | 0:24d3eb812fd4 | 272 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 273 | tmpstatus |= _spi.write(aHeader[1]); |
JMF | 0:24d3eb812fd4 | 274 | |
JMF | 0:24d3eb812fd4 | 275 | /* Writes the registers according to the number of bytes */ |
JMF | 0:24d3eb812fd4 | 276 | for (int index = 0; index < cNbBytes; index++) |
JMF | 0:24d3eb812fd4 | 277 | { |
JMF | 0:24d3eb812fd4 | 278 | _spi.write(pcBuffer[index]); |
JMF | 0:24d3eb812fd4 | 279 | } |
JMF | 0:24d3eb812fd4 | 280 | |
JMF | 0:24d3eb812fd4 | 281 | /* Put the SPI chip select high to end the transaction */ |
JMF | 0:24d3eb812fd4 | 282 | chip_sync_unselect(); |
JMF | 0:24d3eb812fd4 | 283 | |
JMF | 0:24d3eb812fd4 | 284 | return *pStatus; |
JMF | 0:24d3eb812fd4 | 285 | } |
JMF | 0:24d3eb812fd4 | 286 | |
JMF | 0:24d3eb812fd4 | 287 | /** |
JMF | 0:24d3eb812fd4 | 288 | * @brief Read data from RX FIFO |
JMF | 0:24d3eb812fd4 | 289 | * @param cNbBytes: number of bytes to read from RX FIFO |
JMF | 0:24d3eb812fd4 | 290 | * @param pcBuffer: pointer to data read from RX FIFO |
JMF | 0:24d3eb812fd4 | 291 | * @retval StatusBytes |
JMF | 0:24d3eb812fd4 | 292 | */ |
JMF | 0:24d3eb812fd4 | 293 | StatusBytes SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 294 | { |
JMF | 0:24d3eb812fd4 | 295 | return SimpleSpirit1::Instance().SdkEvalSpiReadFifo(cNbBytes, pcBuffer); |
JMF | 0:24d3eb812fd4 | 296 | } |
JMF | 0:24d3eb812fd4 | 297 | |
JMF | 0:24d3eb812fd4 | 298 | StatusBytes SimpleSpirit1::SdkEvalSpiReadFifo(uint8_t cNbBytes, uint8_t* pcBuffer) |
JMF | 0:24d3eb812fd4 | 299 | { |
JMF | 0:24d3eb812fd4 | 300 | uint16_t tmpstatus = 0x0000; |
JMF | 0:24d3eb812fd4 | 301 | StatusBytes *pStatus = (StatusBytes *)&tmpstatus; |
JMF | 0:24d3eb812fd4 | 302 | |
JMF | 0:24d3eb812fd4 | 303 | uint8_t aHeader[2]; |
JMF | 0:24d3eb812fd4 | 304 | |
JMF | 0:24d3eb812fd4 | 305 | /* Built the aHeader bytes */ |
JMF | 0:24d3eb812fd4 | 306 | aHeader[0]=READ_HEADER; |
JMF | 0:24d3eb812fd4 | 307 | aHeader[1]=LINEAR_FIFO_ADDRESS; |
JMF | 0:24d3eb812fd4 | 308 | |
JMF | 0:24d3eb812fd4 | 309 | /* Put the SPI chip select low to start the transaction */ |
JMF | 0:24d3eb812fd4 | 310 | chip_sync_select(); |
JMF | 0:24d3eb812fd4 | 311 | |
JMF | 0:24d3eb812fd4 | 312 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 313 | tmpstatus = _spi.write(aHeader[0]); |
JMF | 0:24d3eb812fd4 | 314 | tmpstatus = tmpstatus<<8; |
JMF | 0:24d3eb812fd4 | 315 | |
JMF | 0:24d3eb812fd4 | 316 | /* Write the aHeader bytes and read the SPIRIT1 status bytes */ |
JMF | 0:24d3eb812fd4 | 317 | tmpstatus |= _spi.write(aHeader[1]); |
JMF | 0:24d3eb812fd4 | 318 | |
JMF | 0:24d3eb812fd4 | 319 | for (int index = 0; index < cNbBytes; index++) |
JMF | 0:24d3eb812fd4 | 320 | { |
JMF | 0:24d3eb812fd4 | 321 | pcBuffer[index] = _spi.write(0xFF); |
JMF | 0:24d3eb812fd4 | 322 | } |
JMF | 0:24d3eb812fd4 | 323 | |
JMF | 0:24d3eb812fd4 | 324 | /* Put the SPI chip select high to end the transaction */ |
JMF | 0:24d3eb812fd4 | 325 | chip_sync_unselect(); |
JMF | 0:24d3eb812fd4 | 326 | |
JMF | 0:24d3eb812fd4 | 327 | return *pStatus; |
JMF | 0:24d3eb812fd4 | 328 | } |
JMF | 0:24d3eb812fd4 | 329 | |
JMF | 0:24d3eb812fd4 | 330 | |
JMF | 0:24d3eb812fd4 | 331 | /** |
JMF | 0:24d3eb812fd4 | 332 | * @} |
JMF | 0:24d3eb812fd4 | 333 | */ |
JMF | 0:24d3eb812fd4 | 334 | |
JMF | 0:24d3eb812fd4 | 335 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |