123r

Dependencies:   WNC14A2AInterface

Committer:
JMF
Date:
Wed Apr 19 01:13:10 2017 +0000
Revision:
0:2563b0415d1f
Initial commit

Who changed what in which revision?

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