Nisarg Sheth / ADMX2001
Committer:
nsheth
Date:
Tue Nov 02 10:13:33 2021 +0000
Revision:
10:49537b1dbbd7
Parent:
9:f286301109fb
Child:
11:071709f5f7d4
Removing platform drivers

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nsheth 9:f286301109fb 1 /* Copyright (c) 2021 Analog Devices, Inc. All rights reserved.
nsheth 9:f286301109fb 2
nsheth 9:f286301109fb 3 Redistribution and use in source and binary forms, with or without modification,
nsheth 9:f286301109fb 4 are permitted provided that the following conditions are met:
nsheth 9:f286301109fb 5 - Redistributions of source code must retain the above copyright notice,
nsheth 9:f286301109fb 6 this list of conditions and the following disclaimer.
nsheth 9:f286301109fb 7 - Redistributions in binary form must reproduce the above copyright notice,
nsheth 9:f286301109fb 8 this list of conditions and the following disclaimer in the documentation
nsheth 9:f286301109fb 9 and/or other materials provided with the distribution.
nsheth 9:f286301109fb 10 - Modified versions of the software must be conspicuously marked as such.
nsheth 9:f286301109fb 11 - This software is licensed solely and exclusively for use with processors/products
nsheth 9:f286301109fb 12 manufactured by or for Analog Devices, Inc.
nsheth 9:f286301109fb 13 - This software may not be combined or merged with other code in any manner
nsheth 9:f286301109fb 14 that would cause the software to become subject to terms and conditions which
nsheth 9:f286301109fb 15 differ from those listed here.
nsheth 9:f286301109fb 16 - Neither the name of Analog Devices, Inc. nor the names of its contributors
nsheth 9:f286301109fb 17 may be used to endorse or promote products derived from this software without
nsheth 9:f286301109fb 18 specific prior written permission.
nsheth 9:f286301109fb 19 - The use of this software may or may not infringe the patent rights of one or
nsheth 9:f286301109fb 20 more patent holders. This license does not release you from the requirement
nsheth 9:f286301109fb 21 that you obtain separate licenses from these patent holders to use this software.
nsheth 9:f286301109fb 22
nsheth 9:f286301109fb 23 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. AND CONTRIBUTORS "AS IS" AND
nsheth 9:f286301109fb 24 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
nsheth 9:f286301109fb 25 TITLE, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
nsheth 9:f286301109fb 26 NO EVENT SHALL ANALOG DEVICES, INC. OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
nsheth 9:f286301109fb 27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, PUNITIVE OR CONSEQUENTIAL DAMAGES
nsheth 9:f286301109fb 28 (INCLUDING, BUT NOT LIMITED TO, DAMAGES ARISING OUT OF CLAIMS OF INTELLECTUAL
nsheth 9:f286301109fb 29 PROPERTY RIGHTS INFRINGEMENT; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
nsheth 9:f286301109fb 30 OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nsheth 9:f286301109fb 31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
nsheth 9:f286301109fb 32 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
nsheth 9:f286301109fb 33 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nsheth 9:f286301109fb 34
nsheth 9:f286301109fb 35 2021-01-10-7CBSD SLA
nsheth 9:f286301109fb 36 */
nsheth 10:49537b1dbbd7 37
nsheth 2:4af4940055a7 38 /**
nsheth 9:f286301109fb 39 * @file ADMX2001.cpp
nsheth 2:4af4940055a7 40 * @brief This file contains admx200x APIs for sdpk1 host
nsheth 2:4af4940055a7 41 * @addtogroup SDPK1
nsheth 2:4af4940055a7 42 * @{
nsheth 2:4af4940055a7 43 */
nsheth 2:4af4940055a7 44 /*============= I N C L U D E S =============*/
nsheth 4:eb7a23c25751 45 #include "ADMX2001.h"
nsheth 4:eb7a23c25751 46 #include "ADMX2001_commands.h"
nsheth 2:4af4940055a7 47 #include "message.h"
nsheth 2:4af4940055a7 48 #include <stdlib.h>
nsheth 2:4af4940055a7 49 #include <string.h>
nsheth 2:4af4940055a7 50
nsheth 2:4af4940055a7 51 static uint32_t SwapEndian(uint32_t *pData);
nsheth 2:4af4940055a7 52 /** milli second delay**/
nsheth 2:4af4940055a7 53 static void Admx200xDelay(uint32_t msec);
nsheth 2:4af4940055a7 54
nsheth 2:4af4940055a7 55 /**
nsheth 2:4af4940055a7 56 * Swaps endian of a 32 bit number
nsheth 2:4af4940055a7 57 * @param data - 32 bit number
nsheth 2:4af4940055a7 58 * @return
nsheth 2:4af4940055a7 59 */
nsheth 2:4af4940055a7 60 uint32_t SwapEndian(uint32_t *pData)
nsheth 2:4af4940055a7 61 {
nsheth 2:4af4940055a7 62 uint8_t *pDataU8 = (uint8_t *)pData;
nsheth 2:4af4940055a7 63
nsheth 2:4af4940055a7 64 return (uint32_t)pDataU8[0] << 24 | (uint32_t)pDataU8[1] << 16 |
nsheth 2:4af4940055a7 65 (uint32_t)pDataU8[2] << 8 | (uint32_t)pDataU8[3];
nsheth 2:4af4940055a7 66 }
nsheth 2:4af4940055a7 67
nsheth 2:4af4940055a7 68 /**
nsheth 2:4af4940055a7 69 * @brief Initializes the ADMX200X.
nsheth 2:4af4940055a7 70 *
nsheth 2:4af4940055a7 71 * @param pDevice - The device structure.
nsheth 2:4af4940055a7 72 * @param pSpiDesc - Pointer to spi device
nsheth 2:4af4940055a7 73 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 74 */
nsheth 2:4af4940055a7 75 int32_t Admx200xInit(Admx200xDev *pDevice, spi_desc *pSpiDesc)
nsheth 2:4af4940055a7 76 {
nsheth 2:4af4940055a7 77 int32_t ret = 0;
nsheth 2:4af4940055a7 78
nsheth 2:4af4940055a7 79 pDevice->pSpiDesc = pSpiDesc;
nsheth 2:4af4940055a7 80
nsheth 2:4af4940055a7 81 return ret;
nsheth 2:4af4940055a7 82 }
nsheth 2:4af4940055a7 83
nsheth 2:4af4940055a7 84 /**
nsheth 2:4af4940055a7 85 * Wrapper fro delay
nsheth 2:4af4940055a7 86 * @param msecs - delay in milliseconds
nsheth 2:4af4940055a7 87 */
nsheth 2:4af4940055a7 88 void Admx200xDelay(uint32_t msecs)
nsheth 2:4af4940055a7 89 {
nsheth 2:4af4940055a7 90 mdelay(msecs);
nsheth 2:4af4940055a7 91 }
nsheth 2:4af4940055a7 92
nsheth 2:4af4940055a7 93 /**
nsheth 2:4af4940055a7 94 * @brief Create a command payload in buffer with inputs.
nsheth 2:4af4940055a7 95 *
nsheth 2:4af4940055a7 96 * @param pCmdId - Command ID.
nsheth 2:4af4940055a7 97 * @param pAddr - Sub commands addresses.
nsheth 2:4af4940055a7 98 * @param pData - Data to wildcat.
nsheth 2:4af4940055a7 99 * @param pBuffer - Data to wildcat.
nsheth 2:4af4940055a7 100 *
nsheth 2:4af4940055a7 101 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 102 */
nsheth 2:4af4940055a7 103 int32_t Admx200xCreateCmdPayload(uint8_t *pCmdId, uint16_t *pAddr,
nsheth 2:4af4940055a7 104 uint32_t *pData, uint8_t *pBuffer)
nsheth 2:4af4940055a7 105 {
nsheth 2:4af4940055a7 106 int32_t ret = 0;
nsheth 5:b9608e6cc24b 107 //DEBUG_MSG("cmd:%d,addr:%d, data: 0x%x\n\r", *pCmdId, *pAddr, *pData);
nsheth 2:4af4940055a7 108 pBuffer[0] = pCmdId[0];
nsheth 2:4af4940055a7 109 pBuffer[1] = ((uint8_t *)pAddr)[1];
nsheth 2:4af4940055a7 110 pBuffer[2] = ((uint8_t *)pAddr)[0];
nsheth 2:4af4940055a7 111 pBuffer[3] = ((uint8_t *)pData)[3];
nsheth 2:4af4940055a7 112 pBuffer[4] = ((uint8_t *)pData)[2];
nsheth 2:4af4940055a7 113 pBuffer[5] = ((uint8_t *)pData)[1];
nsheth 2:4af4940055a7 114 pBuffer[6] = ((uint8_t *)pData)[0];
nsheth 2:4af4940055a7 115
nsheth 2:4af4940055a7 116 return ret;
nsheth 2:4af4940055a7 117 }
nsheth 2:4af4940055a7 118
nsheth 2:4af4940055a7 119 /**
nsheth 2:4af4940055a7 120 * @brief Parse the payload to get cmdID, addr and data.
nsheth 2:4af4940055a7 121
nsheth 2:4af4940055a7 122 * @param[in] pBuffer - Data from wildcat.
nsheth 2:4af4940055a7 123 * @param[out] pCmdId - Pointer to store Command ID.
nsheth 2:4af4940055a7 124 * @param[out] pAddr - Pointer to store addresses.
nsheth 2:4af4940055a7 125 * @param[out] pData - Pointer to store Data
nsheth 2:4af4940055a7 126 *
nsheth 2:4af4940055a7 127 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 128 */
nsheth 2:4af4940055a7 129 int32_t Admx200xParseCmdPayload(uint8_t *pBuffer, uint8_t *pCmdId,
nsheth 2:4af4940055a7 130 uint16_t *pAddr, uint32_t *pData)
nsheth 2:4af4940055a7 131 {
nsheth 2:4af4940055a7 132 int32_t ret = 0;
nsheth 2:4af4940055a7 133
nsheth 2:4af4940055a7 134 *pCmdId = pBuffer[0];
nsheth 2:4af4940055a7 135 *pAddr = ((uint16_t)pBuffer[1] << 8) | ((uint16_t)pBuffer[2]);
nsheth 2:4af4940055a7 136
nsheth 2:4af4940055a7 137 *pData = SwapEndian((uint32_t *)&pBuffer[3]);
nsheth 2:4af4940055a7 138
nsheth 2:4af4940055a7 139 return ret;
nsheth 2:4af4940055a7 140 }
nsheth 2:4af4940055a7 141
nsheth 2:4af4940055a7 142 /**
nsheth 2:4af4940055a7 143 * @brief Waits till done bit is set in the status
nsheth 2:4af4940055a7 144 *
nsheth 2:4af4940055a7 145 * @param pDevice - The handler of the instance of the driver.
nsheth 2:4af4940055a7 146 * @param timeout - Count representing the number of polls to be done until the
nsheth 2:4af4940055a7 147 * function returns if no new data is available.
nsheth 2:4af4940055a7 148 * @param reqStatus - The status to be checked is passed via this argument.
nsheth 2:4af4940055a7 149 * @param pStatReg - Get the status word in pStatReg.
nsheth 2:4af4940055a7 150 *
nsheth 2:4af4940055a7 151 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 152 */
nsheth 2:4af4940055a7 153 int32_t Admx200xWaitForStatus(Admx200xDev *pDevice, uint32_t timeout,
nsheth 2:4af4940055a7 154 uint32_t reqStatus, uint32_t *pStatReg)
nsheth 2:4af4940055a7 155 {
nsheth 2:4af4940055a7 156 int32_t status = ADMX_STATUS_SUCCESS;
nsheth 2:4af4940055a7 157 int8_t done = 0;
nsheth 2:4af4940055a7 158 uint8_t cmdId = CMD_STATUS_READ;
nsheth 2:4af4940055a7 159
nsheth 2:4af4940055a7 160 if (pDevice != NULL)
nsheth 2:4af4940055a7 161 {
nsheth 2:4af4940055a7 162 while (!done && --timeout)
nsheth 2:4af4940055a7 163 {
nsheth 2:4af4940055a7 164
nsheth 2:4af4940055a7 165 status = Admx200xReadData(pDevice, cmdId, pStatReg);
nsheth 2:4af4940055a7 166
nsheth 2:4af4940055a7 167 if (status == 0)
nsheth 2:4af4940055a7 168 {
nsheth 2:4af4940055a7 169 /* Check the DONE bit in the Status Register */
nsheth 2:4af4940055a7 170 if (((*pStatReg) & reqStatus) == reqStatus)
nsheth 2:4af4940055a7 171 {
nsheth 2:4af4940055a7 172 done = 1;
nsheth 2:4af4940055a7 173 if (*pStatReg & ADMX200X_STATUS_ERROR_BITM)
nsheth 2:4af4940055a7 174 {
nsheth 2:4af4940055a7 175 status = *pStatReg & ADMX200X_STATUS_CODE_BITM;
nsheth 2:4af4940055a7 176 if (status & ADMX_STATUS_LOG_ZERO_ERROR)
nsheth 2:4af4940055a7 177 {
nsheth 2:4af4940055a7 178 ERROR_MSG("sweep_start/sweep_end cannot be zero "
nsheth 2:4af4940055a7 179 "for logarithmic sweep");
nsheth 2:4af4940055a7 180 status &= (~ADMX_STATUS_LOG_ZERO_ERROR);
nsheth 2:4af4940055a7 181 }
nsheth 2:4af4940055a7 182 if (status & ADMX_STATUS_LOG_SIGN_ERROR)
nsheth 2:4af4940055a7 183 {
nsheth 2:4af4940055a7 184 ERROR_MSG("sweep_start and sweep_end need to have "
nsheth 2:4af4940055a7 185 "the same sign "
nsheth 2:4af4940055a7 186 "for logarithmic sweep");
nsheth 2:4af4940055a7 187 status &= (~ADMX_STATUS_LOG_SIGN_ERROR);
nsheth 2:4af4940055a7 188 }
nsheth 2:4af4940055a7 189 if (status & ADMX_STATUS_VOLT_ADC_ERROR)
nsheth 2:4af4940055a7 190 {
nsheth 2:4af4940055a7 191 ERROR_MSG("Voltage ADC Saturated\n");
nsheth 2:4af4940055a7 192 status &= (~ADMX_STATUS_VOLT_ADC_ERROR);
nsheth 2:4af4940055a7 193 }
nsheth 2:4af4940055a7 194 if (status & ADMX_STATUS_CURR_ADC_ERROR)
nsheth 2:4af4940055a7 195 {
nsheth 2:4af4940055a7 196 ERROR_MSG("Current ADC Saturated\n");
nsheth 2:4af4940055a7 197 status &= (~ADMX_STATUS_CURR_ADC_ERROR);
nsheth 2:4af4940055a7 198 }
nsheth 2:4af4940055a7 199 if (status & ADMX_STATUS_FIFO_ERROR)
nsheth 2:4af4940055a7 200 {
nsheth 2:4af4940055a7 201 ERROR_MSG(
nsheth 2:4af4940055a7 202 "FIFO either Overflowed or Underflowed\n");
nsheth 2:4af4940055a7 203 status &= (~ADMX_STATUS_FIFO_ERROR);
nsheth 2:4af4940055a7 204 }
nsheth 2:4af4940055a7 205 if (status & ADMX_STATUS_COUNT_EXCEEDED)
nsheth 2:4af4940055a7 206 {
nsheth 2:4af4940055a7 207 ERROR_MSG("Sweep count exceeded maximum value");
nsheth 2:4af4940055a7 208 status &= (~ADMX_STATUS_COUNT_EXCEEDED);
nsheth 2:4af4940055a7 209 }
nsheth 2:4af4940055a7 210 }
nsheth 2:4af4940055a7 211 }
nsheth 2:4af4940055a7 212 }
nsheth 2:4af4940055a7 213 }
nsheth 2:4af4940055a7 214
nsheth 2:4af4940055a7 215 if (!timeout)
nsheth 2:4af4940055a7 216 {
nsheth 2:4af4940055a7 217 status = ADMX_STATUS_TIMEOUT;
nsheth 2:4af4940055a7 218 }
nsheth 2:4af4940055a7 219 }
nsheth 2:4af4940055a7 220 else
nsheth 2:4af4940055a7 221 {
nsheth 2:4af4940055a7 222 status = ADMX_STATUS_FAILED;
nsheth 2:4af4940055a7 223 }
nsheth 2:4af4940055a7 224 return status;
nsheth 2:4af4940055a7 225 }
nsheth 2:4af4940055a7 226
nsheth 2:4af4940055a7 227 /**
nsheth 2:4af4940055a7 228 * @brief Sends teh command to ADMX200x and wait till done bit is set
nsheth 2:4af4940055a7 229 * @param pDevice - Device Handle
nsheth 2:4af4940055a7 230 * @param pCmdId - The command ID
nsheth 2:4af4940055a7 231 * @param pAddr - Address
nsheth 2:4af4940055a7 232 * @param pData - Data
nsheth 2:4af4940055a7 233 * @param pStatReg - Status register info
nsheth 2:4af4940055a7 234 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 235 */
nsheth 2:4af4940055a7 236 int32_t Admx200xSendCmd(Admx200xDev *pDevice, uint8_t *pCmdId, uint16_t *pAddr,
nsheth 2:4af4940055a7 237 uint32_t *pData, uint32_t *pStatReg)
nsheth 2:4af4940055a7 238 {
nsheth 2:4af4940055a7 239
nsheth 2:4af4940055a7 240 int32_t status = ADMX_STATUS_SUCCESS;
nsheth 2:4af4940055a7 241 uint8_t cmdPayload[ADMX200X_CMD_LENGTH];
nsheth 2:4af4940055a7 242
nsheth 2:4af4940055a7 243 Admx200xCreateCmdPayload(pCmdId, pAddr, pData, &cmdPayload[0]);
nsheth 2:4af4940055a7 244
nsheth 2:4af4940055a7 245 status = spi_write_and_read(pDevice->pSpiDesc, &cmdPayload[0],
nsheth 2:4af4940055a7 246 ADMX200X_CMD_LENGTH);
nsheth 2:4af4940055a7 247 Admx200xDelay(100);
nsheth 2:4af4940055a7 248 // printf("CMD :%02x ADDR: %04x DATA: %08x\n\r",*pCmdId, *pAddr, *pData);
nsheth 2:4af4940055a7 249 if (!status)
nsheth 2:4af4940055a7 250 {
nsheth 2:4af4940055a7 251 /** Wait for status done = 1,Warn/error/command result = 0 from result
nsheth 2:4af4940055a7 252 */
nsheth 2:4af4940055a7 253 status = Admx200xWaitForStatus(pDevice, SPI_TIMEOUT,
nsheth 2:4af4940055a7 254 ADMX200X_STATUS_DONE_BITM, pStatReg);
nsheth 2:4af4940055a7 255
nsheth 6:7d8f30b3bc57 256 //printf("Stat Reg: %08x\n\r", *pStatReg);
nsheth 2:4af4940055a7 257 if (status == ADMX_STATUS_SUCCESS)
nsheth 2:4af4940055a7 258 {
nsheth 2:4af4940055a7 259 status = *pStatReg & ADMX200X_STATUS_CODE_BITM;
nsheth 2:4af4940055a7 260 }
nsheth 2:4af4940055a7 261 }
nsheth 2:4af4940055a7 262 if (status == ADMX_STATUS_TIMEOUT)
nsheth 2:4af4940055a7 263 {
nsheth 2:4af4940055a7 264 ERROR_MSG("SPI interface timed out : Not responding");
nsheth 2:4af4940055a7 265 }
nsheth 2:4af4940055a7 266 return status;
nsheth 2:4af4940055a7 267 }
nsheth 2:4af4940055a7 268
nsheth 2:4af4940055a7 269 /**
nsheth 2:4af4940055a7 270 * @brief Read result register from the WILDCAT
nsheth 2:4af4940055a7 271 * @param pDevice - Device Handle
nsheth 2:4af4940055a7 272 * @param cmdId - This determines where the data is read from - result
nsheth 2:4af4940055a7 273 * register, status register or Fifo
nsheth 2:4af4940055a7 274 * @param pResult - The data in the result register
nsheth 2:4af4940055a7 275 * @return Returns 0 for success or negative error code.
nsheth 2:4af4940055a7 276 */
nsheth 2:4af4940055a7 277 int32_t Admx200xReadData(Admx200xDev *pDevice, uint8_t cmdId, uint32_t *pResult)
nsheth 2:4af4940055a7 278 {
nsheth 2:4af4940055a7 279 int32_t ret = ADMX_STATUS_SUCCESS;
nsheth 2:4af4940055a7 280 uint8_t cmdTemp;
nsheth 2:4af4940055a7 281 uint16_t addrTemp;
nsheth 2:4af4940055a7 282 uint16_t addr;
nsheth 2:4af4940055a7 283 uint32_t data;
nsheth 2:4af4940055a7 284 uint8_t cmdPayload[ADMX200X_CMD_LENGTH];
nsheth 2:4af4940055a7 285
nsheth 2:4af4940055a7 286 /*FIXME: Insert checks here. Not all command IDs are accepted here */
nsheth 2:4af4940055a7 287 addr = 0;
nsheth 2:4af4940055a7 288 data = 0;
nsheth 2:4af4940055a7 289
nsheth 2:4af4940055a7 290 Admx200xCreateCmdPayload(&cmdId, &addr, &data, &cmdPayload[0]);
nsheth 2:4af4940055a7 291
nsheth 2:4af4940055a7 292 /* Send command and Read response from the slave */
nsheth 2:4af4940055a7 293 ret = spi_write_and_read(pDevice->pSpiDesc, &cmdPayload[0],
nsheth 2:4af4940055a7 294 ADMX200X_CMD_LENGTH);
nsheth 2:4af4940055a7 295 Admx200xDelay(100);
nsheth 2:4af4940055a7 296 Admx200xParseCmdPayload(&cmdPayload[0], &cmdTemp, &addrTemp, pResult);
nsheth 2:4af4940055a7 297
nsheth 2:4af4940055a7 298 return ret;
nsheth 2:4af4940055a7 299 }
nsheth 2:4af4940055a7 300
nsheth 2:4af4940055a7 301 /**
nsheth 2:4af4940055a7 302 * @brief Read array of datatype doube from the fifo of the WILDCAT
nsheth 2:4af4940055a7 303 * @param pDevice - Device Handle
nsheth 2:4af4940055a7 304 * @param pFifo - Double array that stores the data
nsheth 2:4af4940055a7 305 * @param pCount - Stores the number of double values stored in the pFifo array
nsheth 2:4af4940055a7 306 */
nsheth 2:4af4940055a7 307 int32_t Admx200xReadFifo(Admx200xDev *pDevice, double *pFifo, int32_t *pCount)
nsheth 2:4af4940055a7 308 {
nsheth 2:4af4940055a7 309 int32_t status = ADMX_STATUS_SUCCESS;
nsheth 2:4af4940055a7 310 int32_t i;
nsheth 2:4af4940055a7 311 uint32_t *pData = (uint32_t *)pFifo;
nsheth 2:4af4940055a7 312 uint8_t cmdId = CMD_STATUS_READ;
nsheth 2:4af4940055a7 313 uint32_t statusReg;
nsheth 2:4af4940055a7 314 int32_t numDoublesInFifo;
nsheth 2:4af4940055a7 315
nsheth 2:4af4940055a7 316 status = Admx200xReadData(pDevice, cmdId, &statusReg);
nsheth 2:4af4940055a7 317
nsheth 2:4af4940055a7 318 /* Fifo depth in doubles */
nsheth 2:4af4940055a7 319 numDoublesInFifo = (statusReg & ADMX200X_STATUS_FIFO_DEPTH_BITM) >> 17;
nsheth 2:4af4940055a7 320
nsheth 2:4af4940055a7 321 if (numDoublesInFifo < *pCount)
nsheth 2:4af4940055a7 322 {
nsheth 2:4af4940055a7 323 *pCount = numDoublesInFifo;
nsheth 2:4af4940055a7 324 }
nsheth 2:4af4940055a7 325
nsheth 2:4af4940055a7 326 for (i = 0; i < *pCount; i++)
nsheth 2:4af4940055a7 327 {
nsheth 2:4af4940055a7 328 /* Read a double -- Split it into two reads for redability*/
nsheth 2:4af4940055a7 329 Admx200xReadData(pDevice, CMD_FIFO_READ, &pData[2 * i]);
nsheth 2:4af4940055a7 330 Admx200xReadData(pDevice, CMD_FIFO_READ, &pData[2 * i + 1]);
nsheth 2:4af4940055a7 331 }
nsheth 2:4af4940055a7 332 return status;
nsheth 2:4af4940055a7 333 }
nsheth 2:4af4940055a7 334
nsheth 2:4af4940055a7 335 /**
nsheth 2:4af4940055a7 336 * @brief Clears the Admx2001 SPI FIFO & errors
nsheth 2:4af4940055a7 337 *
nsheth 2:4af4940055a7 338 * @param pDevice - Device Handle
nsheth 2:4af4940055a7 339 * @return Returns 0 for success or error code.
nsheth 2:4af4940055a7 340 */
nsheth 2:4af4940055a7 341 int32_t Admx200xClearSPI(Admx200xDev *pDevice)
nsheth 2:4af4940055a7 342 {
nsheth 2:4af4940055a7 343 int32_t status = ADMX_STATUS_SUCCESS;
nsheth 2:4af4940055a7 344 uint8_t cmdID;
nsheth 2:4af4940055a7 345 uint16_t addr = 0;
nsheth 2:4af4940055a7 346 uint32_t statReg = 0;
nsheth 2:4af4940055a7 347 uint32_t data = 0;
nsheth 2:4af4940055a7 348
nsheth 2:4af4940055a7 349 cmdID = CMD_CLEAR_ERROR;
nsheth 2:4af4940055a7 350 status = Admx200xSendCmd(pDevice, &cmdID, &addr, &data, &statReg);
nsheth 2:4af4940055a7 351
nsheth 2:4af4940055a7 352 return status;
nsheth 2:4af4940055a7 353 }
nsheth 2:4af4940055a7 354
nsheth 2:4af4940055a7 355 /**
nsheth 2:4af4940055a7 356 * @}
nsheth 2:4af4940055a7 357 */