
IIO firmware for the AD717x and AD411x family of devices.
Dependencies: sdp_k1_sdram
Revision 0:5ad86d8d396a, committed 2022-06-09
- Comitter:
- Janani Sunil
- Date:
- Thu Jun 09 10:57:51 2022 +0530
- Child:
- 1:f71de62b7179
- Commit message:
- AD717x-Ad411x IIO Application- Initial Revision
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LICENSE.txt Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,26 @@ +Analog Devices, Inc. (“ADI”) +Source Code Software License Agreement +20210120-LWSC-CTSLA +BEFORE YOU SELECT THE "I ACCEPT" BUTTON AT THE BOTTOM OF THIS WINDOW, CAREFULLY READ THE TERMS AND CONDITIONS SET FORTH BELOW. BY SELECTING THE “I ACCEPT” BUTTON BELOW, OR DOWNLOADING, REPRODUCING, DISTRIBUTING OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE TERMS AND CONDITIONS SET FORTH BELOW. IF YOU DO NOT AGREE TO ALL OF THE TERMS AND CONDITIONS, SELECT THE 'I DO NOT ACCEPT' BUTTON AND YOU MUST NOT DOWNLOAD, INSTALL OR OTHERWISE USE THE SOFTWARE. + +DOWNLOADING, REPRODUCING, DISTRIBUTING OR OTHERWISE USING THE SOFTWARE CONSTITUTES ACCEPTANCE OF THIS LICENSE. THE SOFTWARE MAY NOT BE USED EXCEPT AS EXPRESSLY AUTHORIZED UNDER THIS LICENSE. + +The software is protected by copyright law and international copyright treaties. + +1. License: Subject to the terms and conditions of this license, the software may be reproduced, modified and distributed in source code and object code form. + +2. Conditions: +(a) Any distribution of the software must include a complete copy of this license and retain all copyright and other proprietary notices. The software that is distributed (including modified versions of the software) shall be subject to the terms and conditions of this license. +(b) The software may not be combined or merged with other software in any manner that would cause the software to become subject to terms and conditions which differ from those of this license. +(c) The software is licensed solely and exclusively for use with processors / products manufactured by or for ADI. +(d) Licensee shall not use the name or any trademark of ADI (including those of its licensors) or any contributor to endorse or promote products without prior written consent of the owner of the name or trademark. The term “contributor” means any person or entity that modifies or distributes the software. +(e) Modified versions of the Software must be conspicuously marked as such. +(f) Use of the software may or may not infringe patent rights of one or more patent holders. This license does not alleviate the obligation to obtain separate licenses from patent holders to use the software. +(g) All rights not expressly granted hereunder are reserved. +(h) This license shall be governed by the laws of Massachusetts, without regard to its conflict of laws rules. The software shall only be used in compliance with all applicable laws and regulations, including without limitation export control laws. + +3. WARRANTY DISCLAIMER: THE SOFTWARE AND ANY RELATED INFORMATION AND/OR ADVICE IS PROVIDED ON AN “AS IS” BASIS, WITHOUT REPRESENTATIONS, GUARANTEES OR WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED, ORAL OR WRITTEN, INCLUDING WITHOUT LIMITATION, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. There is no obligation to provide software support or updates. The Software is not fault-tolerant and is not intended for use in high risk applications, including without limitation in the operation of nuclear facilities, aircraft navigation or control systems, air traffic control, life support machines, weapons systems, autonomous driving or other safety critical automotive applications, or any other application in which the failure of the software could lead to death, personal injury, or severe physical or environmental damages. The software is not authorized to be used under such circumstances. + +4. LIMITATION OF LIABILITY: TO THE MAXIMUM EXTENT PERMITTED BY LAW ADI (INCLUDING ITS LICENSORS) AND CONTRIBUTORS SHALL NOT BE LIABLE FOR ANY DAMAGES ARISING FROM OR RELATED TO THE SOFTWARE, ITS USE OR ANY RELATED INFORMATION AND/OR SERVICES, INCLUDING BUT NOT LIMITED TO ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, PUNITIVE, EXEMPLARY, CONSEQUENTIAL OR ANALOGOUS DAMAGES (INCLUDING WITHOUT LIMITATION ANY DAMAGES RESULTING FROM LOSS OF USE, DATA, REVENUE, PROFITS, OR SAVINGS, COMPUTER DAMAGE OR ANY OTHER CAUSE), UNDER ANY LEGAL THEORY (INCLUDING WITHOUT LIMITATION CONTRACT, WARRANTY, TORT, NEGLIGENCE, STRICT OR PRODUCT LIABILITY), EVEN IF IT HAS BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. Some jurisdictions do not permit the exclusion or limitation of liability for consequential, incidental or other damages, and, as such, some portion of the above limitation may not apply. In such jurisdictions, liability is limited to the greatest extent permitted by law. +5. Third Party Software: The software may be accompanied by or include software made available by one or more third parties (“Third Party Software”). Each portion of Third Party Software is subject to its own separate software license terms and conditions (“Third Party Licenses”). The Third Party Licenses for Third Party Software delivered with the software are set forth or identified (by url or otherwise) in (i) Appendix A to this license (if any), (ii) the applicable software header or footer text, (iii) a text file located in the directory of the applicable Third Party Software component and/or (iv) such other location customarily used for licensing terms. The use of each portion of Third Party Software is subject to the Third Party Licenses, and you agree that your use of any Third Party Software is bound by the applicable Third Party License. You agree to review and comply with all applicable Third Party Licenses prior to any use or distribution of any Third Party Software. Third Party Software is provided on an “as is” basis without any representation, warranty or liability of any kind. ADI (including its licensors) and contributors shall have no liability or responsibility for the operation or performance of the Third Party Software and shall not be liable for any damages, costs, or expenses, direct or indirect, arising out of the performance or failure to perform of the Third Party Software. ADI (including its licensors) and contributors shall be entitled to the benefit of any and all limitations of liability and disclaimers of warranties contained in the Third Party Licenses. For the avoidance of doubt, this license does not alter, limit or expand the terms and conditions of, or rights granted to you pursuant to, Third Party Licenses. +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.txt Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,51 @@ +Evaluation Boards/Products Supported +------------------------------------ +EVAL-AD4111SDZ +EVAL-AD4112SDZ +EVAL-AD4114SDZ +EVAL-AD4115SDZ +EVAL-AD7172-4SDZ +EVAL-AD7173-8SDZ +EVAL-AD7175-2SDZ +EVAL-AD7175-8SDZ +EVAL-AD7176-2SDZ +EVAL-AD7177-2SDZ + +Overview +-------- +This is a IIO based firmware application to evalute the ADxxxx device. +This code was developed and tested on SDP-K1 controller board: https://os.mbed.com/platforms/SDP_K1/. +Use of Mbed platform allows code to port on other Mbed supported target boards with little or no modifications. + +Product details: https://www.analog.com/en/products/ad4111.html, https://www.analog.com/en/products/ad7172-2.html +Product Evaluation board details: https://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/EVAL-AD4111.html +User Guide for this code: https://wiki.analog.com/resources/tools-software/product-support-software/ad717x_mbed_iio_support +Communication Protocol: SPI + + +Hardware Setup +-------------- +Required: SDP-K1 (or alternative Mbed enabled controller board), EVAL-ADxxxx board and USB cable. +Plug in the EVAL-AD4111 board on SDP-K1 board (or any other Mbed enabled controller board) +using the SDP-120 or Arduino or PMOD on-board connector (refer software wiki page to identify suitable interface). +Connect SDP-K1 board to the PC using the USB cable. + + +How to Get Started +------------------ +Create an account with Keil Studio and log in: https://www.keil.arm.com/mbed/ +Import Code into compiler from here: https://os.mbed.com/teams/AnalogDevices/code/EVAL-AD717x-AD411x-IIO/ +Instructions on how to import code are here: https://developer.arm.com/documentation/102497/1-5/Create-or-import-a-project/Import-an-Mbed-project-from-a-URL +Compile code. Drag and drop binary into SDP-K1 controller board. Find detailed +instructions here: https://os.mbed.com/docs/mbed-os/v6.8/tools/getting-your-program-on-your-board.html +Open Tera Term (or alternative), select 230400 baud rate, and the applicable COM +port to see the list of options. + + +Notes +----- +If using Win 7, install serial drivers for Mbed. https://os.mbed.com/docs/mbed-os/v5.12/tutorials/windows-serial-driver.html +A detailed user guide on SDP-K1 controller board is available here https://www.analog.com/en/design-center/evaluation-hardware-and-software/evaluation-boards-kits/SDP-K1.html. + + +Copyright (c) 2022 Analog Devices, Inc. All rights reserved. \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/.mbedignore Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,57 @@ +no-OS/ci/ +no-OS/doc/ +no-OS/drivers/accel/ +no-OS/drivers/afe/ +no-OS/drivers/amplifiers/ +no-OS/drivers/axi_core/ +no-OS/drivers/adc/adaq8092/ +no-OS/drivers/adc/ad4* +no-OS/drivers/adc/ad6* +no-OS/drivers/adc/ad70* +no-OS/drivers/adc/ad72* +no-OS/drivers/adc/ad73* +no-OS/drivers/adc/ad74* +no-OS/drivers/adc/ad75* +no-OS/drivers/adc/ad76* +no-OS/drivers/adc/ad77* +no-OS/drivers/adc/ad78* +no-OS/drivers/adc/ad79* +no-OS/drivers/adc/ad713x/ +no-OS/drivers/adc/ad7124/ +no-OS/drivers/adc/ad719x/ +no-OS/drivers/adc/ad793x/ +no-OS/drivers/adc/ad7193/ +no-OS/drivers/adc/adaq7980/ +no-OS/drivers/adc/ad9* +no-OS/drivers/adc/ltc2312/ +no-OS/drivers/adc/adc_demo/ +no-OS/drivers/adc-dac/ +no-OS/drivers/display/ +no-OS/drivers/filter/ +no-OS/drivers/tdm/ +no-OS/drivers/cdc/ +no-OS/drivers/dac/ +no-OS/drivers/ecg/ +no-OS/drivers/frequency/ +no-OS/drivers/gyro/ +no-OS/drivers/impedance-analyzer/ +no-OS/drivers/io-expander/ +no-OS/drivers/mux/ +no-OS/drivers/photo-electronic/ +no-OS/drivers/platform/stm32/ +no-OS/drivers/platform/altera/ +no-OS/drivers/platform/xilinx/ +no-OS/drivers/platform/aducm3029/ +no-OS/drivers/platform/generic/ +no-OS/drivers/platform/linux/ +no-OS/drivers/platform/maxim/ +no-OS/drivers/potentiometer/ +no-OS/drivers/rf-transceiver/ +no-OS/drivers/sd-card/ +no-OS/drivers/temperature/ +no-OS/legacy/ +no-OS/libraries/ +no-OS/network/ +no-OS/projects/ +no-OS/tools/ +no-OS/iio/iio_app/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_data_capture.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,537 @@ +/***************************************************************************//** + * @file ad717x_data_capture.c + * @brief Source file for AD717x Data capture +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdbool.h> +#include "ad717x_data_capture.h" +#include "app_config.h" +#include "ad717x_iio.h" +#include "no_os_gpio.h" +#include "no_os_irq.h" +#include "ad717x_support.h" +#include "no_os_error.h" +#include "ad717x_user_config.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/* Timeout count to avoid stuck into potential infinite loop while checking + * for new data into an acquisition buffer. The actual timeout factor is determined + * through 'sampling_frequency' attribute of IIO app, but this period here makes sure + * we are not stuck into a forever loop in case data capture is interrupted + * or failed in between. + * Note: This timeout factor is dependent upon the MCU clock frequency. Below timeout + * is tested for SDP-K1 platform @180Mhz default core clock */ +#define BUF_READ_TIMEOUT 0xffffffff + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +/* + *@enum acq_buffer_state_e + *@details Data acquisition buffer states + **/ +typedef enum { + BUF_AVAILABLE, + BUF_EMPTY, + BUF_FULL +} acq_buffer_state_e; + +/* + *@struct acq_buf_t + *@details Data acquisition buffer parameters + **/ +typedef struct { + acq_buffer_state_e state; // Buffer state + uint32_t wr_indx; // Buffer write index (incremented per sample read) + uint32_t rd_indx; // Buffer read index (incremented per sample read) + int8_t *wr_pdata; // Data buffer write pointer + int8_t *rd_pdata; // Data buffer read pointer + bool reindex_buffer; // Reindex buffer to 0th channel +} acq_buf_t; + +/* ADC data acquisition buffers */ +static volatile acq_buf_t acq_buffer; + +/* Number of samples requested by IIO client */ +static volatile uint32_t num_of_requested_samples = 0; + +/* Number of active channels */ +static volatile uint8_t num_of_active_channels; + +/* ADC sample/raw data size in bytes */ +static volatile uint8_t sample_size_in_bytes; + +/* ADC data buffer */ +#if !defined(USE_SDRAM_CAPTURE_BUFFER) +int8_t adc_data_buffer[DATA_BUFFER_SIZE] = { 0 }; +#endif + +/* List of input channels to be captured */ +static volatile uint8_t input_channels[NUMBER_OF_CHANNELS]; + +/* Flag to indicate data capture status */ +static volatile bool start_cont_data_capture = false; + +/* Max available buffer size (after considering the data alignment with IIO buffer) */ +static volatile uint32_t max_buffer_sz; + +/* Current active channel index */ +static volatile uint8_t chn_indx; + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/ + +/*! + * @brief Reset the data capture specific variables + * @return none + */ +static void reset_data_capture(void) +{ + /* Reset data capture flags */ + num_of_active_channels = 0; + start_cont_data_capture = false; + + /* Reset acquisition buffer states and clear old data */ + acq_buffer.state = BUF_EMPTY; + acq_buffer.wr_indx = 0; + acq_buffer.rd_indx = 0; + acq_buffer.reindex_buffer = false; + + acq_buffer.wr_pdata = adc_data_buffer; + acq_buffer.rd_pdata = adc_data_buffer; + max_buffer_sz = DATA_BUFFER_SIZE; +} + + +/*! + * @brief Trigger a data capture in continuous/burst mode + * @return 0 in case of success, negative error code otherwise + */ +static int32_t adc_start_data_capture(void) +{ + /* Set ADC to Continuous conversion mode */ + return ad717x_set_adc_mode(p_ad717x_dev_inst, CONTINUOUS); +} + + +/*! + * @brief Stop a data capture operation + * @return 0 in case of success, negative error code otherwise + */ +static int32_t adc_stop_data_capture(void) +{ + /* Set ADC to Standby mode */ + return ad717x_set_adc_mode(p_ad717x_dev_inst, STANDBY); +} + + +/*! + * @brief Function to prepare the data ADC capture for new READBUFF + * request from IIO client (for active channels) + * @param chn_mask[in] - Channels to enable for data capturing + * @param num_of_chns[in] - ADC channel count + * @param sample_size[in] - Sample size in bytes + * @return 0 in case of success, negative error code otherwise + */ +int32_t prepare_data_transfer(uint32_t ch_mask, uint8_t num_of_chns, + uint8_t sample_size) +{ + uint8_t mask = 0x1; + int32_t ret; + uint8_t ch_id; + + /* Reset data capture module */ + reset_data_capture(); + + sample_size_in_bytes = sample_size; + + /* Enable Active channels requested and Disable the remaining */ + for (ch_id = 0; + ch_id < NUMBER_OF_CHANNELS; ch_id++) { + if (ch_mask & mask) { + ret = ad717x_set_channel_status(p_ad717x_dev_inst, ch_id, true); + if (ret) { + return ret; + } + num_of_active_channels++; + } else { + ret = ad717x_set_channel_status(p_ad717x_dev_inst, ch_id, false); + if (ret) { + return ret; + } + } + mask <<= 1; + } + + /* Trigger continuous data capture */ +#if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) + + /* Trigger continuous data capture */ + ret = adc_start_data_capture(); + if (ret) { + return ret; + } + + acq_buffer.state = BUF_AVAILABLE; + start_cont_data_capture = true; + + /* Enable Continuous read operation */ + ret = ad717x_enable_cont_read(p_ad717x_dev_inst, true); + if (ret) { + return ret; + } + + /* Pull the cs line low to detect the EOC bit during data capture */ + ret = no_os_gpio_set_value(csb_gpio, NO_OS_GPIO_LOW); + if (ret) { + return ret; + } + + ret = no_os_irq_enable(external_int_desc, IRQ_INT_ID); + if (ret) { + return ret; + } +#endif + + return 0; +} + + +/*! + * @brief Function to end data capture + * @return 0 in case of success, negative error code otherwise + */ +int32_t end_data_transfer(void) +{ + int32_t ret; + start_cont_data_capture = false; + +#if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) + /* Disable continous read mode */ + ret = ad717x_enable_cont_read(p_ad717x_dev_inst, false); + if (ret) { + return ret; + } +#endif + + /* Reset data capture module specific flags and variables */ + reset_data_capture(); + + /* Stop ADC data capture */ + return adc_stop_data_capture(); +} + + +/*! + * @brief Capture requested number of ADC samples in burst mode + * @param pbuf[out] - Pointer to ADC data buffer + * @param nb_of_samples[in] - Number of samples to be read + * @return 0 in case of success, negative error code otherwise + */ +static int32_t read_burst_data(int8_t *pbuf, uint32_t nb_of_samples) +{ + uint32_t sample_index = 0; + int32_t adc_raw_data; + int32_t ret; + + if (adc_start_data_capture() != 0) { + return -EINVAL; + } + + while (sample_index < nb_of_samples) { + /* Wait for the RDY Bit to go low to notify end of conversion */ + ret = AD717X_WaitForReady(p_ad717x_dev_inst, AD717X_CONV_TIMEOUT); + if (ret) { + return ret; + } + + /* Read the converted data from the Data register */ + ret = AD717X_ReadData(p_ad717x_dev_inst, &adc_raw_data); + if (ret) { + return ret; + } + + memcpy((uint8_t*)pbuf, &adc_raw_data, sample_size_in_bytes); + sample_index++; + pbuf += sample_size_in_bytes; + } + + /* Stop any active conversion */ + adc_stop_data_capture(); + + return 0; +} + + +/*! + * @brief Perform buffer read operations to read requested samples + * @param nb_of_samples[in] - Requested number of samples to read + * @return 0 in case of success, negative error code otherwise + */ +static int32_t buffer_read_operations(uint32_t nb_of_samples) +{ + uint32_t timeout = BUF_READ_TIMEOUT; + int32_t offset; + + /* Wait until requested samples are available in the buffer to read */ + do { + if (acq_buffer.wr_indx >= acq_buffer.rd_indx) { + offset = acq_buffer.wr_indx - acq_buffer.rd_indx; + } else { + offset = max_buffer_sz + (acq_buffer.wr_indx - acq_buffer.rd_indx); + } + + timeout--; + } while ((offset < (int32_t)(nb_of_samples)) && (timeout > 0)); + + if (timeout == 0) { + /* This returns the empty buffer */ + return -EIO; + } + + if (acq_buffer.rd_indx >= max_buffer_sz) { + acq_buffer.rd_indx = 0; + } + + return 0; +} + + +/*! + * @brief Perform buffer write operations such as buffer full or empty + * check, resetting buffer index and pointers, etc + * @return none + */ +static void buffer_write_operations(void) +{ + acq_buffer.wr_indx++; + + /* Perform buffer full check and operations */ + if (acq_buffer.wr_indx >= max_buffer_sz) { + if ((acq_buffer.rd_indx >= num_of_requested_samples) + && (acq_buffer.rd_indx != 0)) { + /* Reset buffer write index and write pointer when enough + * space available in the buffer to wrap to start */ + acq_buffer.wr_indx = 0; + + acq_buffer.wr_pdata = adc_data_buffer; + if (acq_buffer.rd_indx >= max_buffer_sz) { + /* Wrap the read index and read pointer to start of buffer + * if buffer is completely read/emptied */ + acq_buffer.rd_indx = 0; + acq_buffer.rd_pdata = adc_data_buffer; + } + + acq_buffer.state = BUF_AVAILABLE; + } else { + /* Wait until enough space available to wrap buffer write index + * at the start of buffer */ + acq_buffer.wr_indx = max_buffer_sz; + acq_buffer.state = BUF_FULL; + acq_buffer.reindex_buffer = true; + } + } +} + + +/*! + * @brief Read requested number of ADC samples in continuous mode + * @param pbuf[in] - Pointer to data buffer + * @param nb_of_samples[in] - Number of samples to read + * @return 0 in case of success, negative error code otherwise + * @note The actual sample capturing happens through interrupt. This + * function tracks the buffer read pointer to read block of data + */ +static int32_t read_continuous_conv_data(int8_t **pbuf, uint32_t nb_of_samples) +{ + volatile int8_t *rd_addr; + int32_t ret; + + /* Determine the max available buffer size based on the requested + * samples count and actual avilable buffer size. Buffer should be + * capable of holding all requested 'n' samples from previous write + * index upto to the end of buffer, as data is read linearly + * from adc buffer in IIO library. + * E.g. If actual buffer size is 2048 samples and requested samples + * are 1600, max available buffer size is actually 1600. So in given + * iteration, only 1600 samples will be stored into buffer and after + * that buffer indexes will be wrapped to a start of buffer. If index + * is not wrapped, the next 1600 requested samples won't accomodate into + * remaining 448 samples space. As buffer is read in linear fashion, the + * read index can't be wrapped to start of buffer to read remaining samples. + * So max available space in this case is 2048 but only utilized space + * will be 1600 in single read buffer request from IIO client. + **/ + max_buffer_sz = ((DATA_BUFFER_SIZE / sample_size_in_bytes) / + nb_of_samples) * nb_of_samples; + + ret = buffer_read_operations(nb_of_samples); + if (ret) { + return ret; + } + + /* Get the next read address */ + rd_addr = (volatile int8_t *)(acq_buffer.rd_pdata + (acq_buffer.rd_indx * + sample_size_in_bytes)); + acq_buffer.rd_indx += nb_of_samples; + + /* Update the IIO buffer pointer to point to next read start location */ + *pbuf = rd_addr; + + return 0; +} + + +/*! + * @brief Read ADC raw data for recently sampled channel + * @param adc_data[out] - Pointer to adc data read variable + * @param input_chn[in] - Input channel + * @return 0 in case of success, negative error code otherwise + * @note This function is intended to call from the conversion end trigger + * event. Therefore, this function should just read raw ADC data + * without further monitoring conversion end event + */ +static int32_t adc_read_converted_sample(uint32_t *adc_data, uint8_t input_chn) +{ + uint32_t adc_raw = 0; + int32_t ret; + uint8_t buffer[3] = { 0, 0, 0 }; + uint8_t buffer_index; + + if (!adc_data) { + return -EINVAL; + } + + ret = no_os_spi_write_and_read(p_ad717x_dev_inst->spi_desc, buffer, + sizeof(buffer)); + if (ret) { + return ret; + } + + ret = no_os_gpio_set_value(csb_gpio, NO_OS_GPIO_LOW); + if (ret) { + return ret; + } + + for (buffer_index = 0; buffer_index < sizeof(buffer); buffer_index++) { + adc_raw <<= 8; + adc_raw += buffer[buffer_index]; + } + + /* Enable external interrupts */ + ret = no_os_irq_enable(external_int_desc, IRQ_INT_ID); + if (ret) { + return ret; + } + + *adc_data = adc_raw; + + return 0; +} + + +/*! + * @brief This is an ISR (Interrupt Service Routine) to monitor end of conversion event. + * @param ctx[in] - Callback context (unused) + * @param event[in] - Callback event (unused) + * @param extra[in] - Callback extra (unused) + * @return none + * @details This is an Interrupt callback function/ISR invoked in synchronous/asynchronous + * manner depending upon the application implementation. The conversion results + * are read into acquisition buffer and control continue to sample next channel. + * This continues until conversion is stopped (through IIO client command) + */ +void data_capture_callback(void *ctx, uint32_t event, void *extra) +{ + uint32_t adc_sample; + volatile uint8_t *wr_addr; + + /* The callback function is triggered when a falling edge is detected + * on the MISO pin. The first falling edge on the MISO pin indicates the + * end of conversion bit. The converted sample is also recieved on the MISO line and + * any falling edge during SPI tracsaction would be interpreted as interrupt and results + * in nested interrupts. Hence disabling the external interrupt as soon as the control + * enters the callback function due to an EOC event. + */ + no_os_irq_disable(external_int_desc, IRQ_INT_ID); + + if (start_cont_data_capture == true) { + /* Read the sample for channel which has been sampled recently */ + if (adc_read_converted_sample(&adc_sample, + input_channels[chn_indx]) == 0) { + do { + if (acq_buffer.state == BUF_AVAILABLE) { + if (acq_buffer.reindex_buffer) { + /* Buffer refilling must start with first active channel data + * for IIO client to synchronize the buffered data */ + if (chn_indx != 0) { + break; + } + acq_buffer.reindex_buffer = false; + } + + /* Copy adc samples into acquisition buffer to transport over + * communication link */ + wr_addr = (volatile uint8_t *)(acq_buffer.wr_pdata + (acq_buffer.wr_indx * + sample_size_in_bytes)); + memcpy((uint8_t *)wr_addr, &adc_sample, sample_size_in_bytes); + } + + /* Perform buffer write operations */ + buffer_write_operations(); + } while (0); + + /* Track the count for recently sampled channel */ + chn_indx++; + if (chn_indx >= num_of_active_channels) { + chn_indx = 0; + } + } + } +} + + +/*! + * @brief Function to read the ADC buffered raw data requested + * by IIO client + * @param pbuf[in] - Pointer to data buffer + * @param nb_of_bytes[in] - Number of bytes to read + * @return 0 in case of success, negative error code otherwise + */ +int32_t read_buffered_data(int8_t **pbuf, uint32_t nb_of_bytes) +{ + int32_t ret; + num_of_requested_samples = nb_of_bytes / sample_size_in_bytes; + +#if (DATA_CAPTURE_MODE == BURST_DATA_CAPTURE) + ret = read_burst_data(*pbuf, num_of_requested_samples); +#else + ret = read_continuous_conv_data(pbuf, num_of_requested_samples); +#endif + + if (ret) { + return ret; + } + + return nb_of_bytes; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_data_capture.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,46 @@ +/***************************************************************************//** + * @file ad717x_data_capture.h + * @brief Header file for AD717x Data capture +******************************************************************************** + * Copyright (c) 2021-22 Analog Devices, Inc. + * All rights reserved. + * + * This software is proprietary to Analog Devices, Inc. and its licensors. + * By using this software you agree to the terms of the associated + * Analog Devices Software License Agreement. +*******************************************************************************/ + +#ifndef _AD717X_DATA_CAPTURE_H_ +#define _AD717X_DATA_CAPTURE_H_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdint.h> +#include "app_config.h" + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +#if defined(USE_SDRAM_CAPTURE_BUFFER) +#define adc_data_buffer SDRAM_START_ADDRESS +#define DATA_BUFFER_SIZE SDRAM_SIZE_BYTES +#else +extern int8_t adc_data_buffer[]; +#define DATA_BUFFER_SIZE (32768) // 32kbytes +#endif + +/******************************************************************************/ +/********************** Public/Extern Declarations ****************************/ +/******************************************************************************/ + +int32_t prepare_data_transfer(uint32_t ch_mask, uint8_t num_of_chns, + uint8_t sample_size_in_byte); +int32_t end_data_transfer(void); +int32_t read_buffered_data(int8_t **pbuf, uint32_t nb_of_bytes); +void data_capture_callback(void *ctx, uint32_t event, void *extra); + +#endif /* _AD717X_DATA_CAPTURE_H_ */ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_iio.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,497 @@ +/***************************************************************************//** + * @file ad717x_iio.c + * @brief Source file for the AD717x IIO Application +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdio.h> +#include "ad717x_user_config.h" +#include "app_config.h" +#include "ad717x_iio.h" +#include "ad717x.h" +#include "iio.h" +#include "no_os_util.h" +#include "ad717x_data_capture.h" +#include "no_os_error.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/* Define ADC Resolution in Bits */ +#if defined (DEV_AD7177_2) +#define AD717x_RESOLUTION 32 +#else +#define AD717x_RESOLUTION 24 +#endif + +/* ADC max count (full scale value) for unipolar inputs */ +#define ADC_MAX_COUNT_UNIPOLAR (uint32_t)((1 << AD717x_RESOLUTION) - 1) + +/* ADC max count (full scale value) for bipolar inputs */ +#define ADC_MAX_COUNT_BIPOLAR (uint32_t)(1 << (AD717x_RESOLUTION-1)) + +/* Bytes per sample (*Note: 4 bytes needed per sample for data range + * of 0 to 32-bit) */ +#define BYTES_PER_SAMPLE sizeof(uint32_t) + +/* Number of data storage bits (needed for IIO client) */ +#define CHN_STORAGE_BITS (BYTES_PER_SAMPLE * 8) + +/* Private IDs for IIO attributes */ +#define AD717x_RAW_ATTR_ID 0 +#define AD717x_SCALE_ATTR_ID 1 +#define AD717x_OFFSET_ATTR_ID 2 +#define AD717x_SAMPLING_FREQUENCY_ID 3 + +/* Data Buffer for burst mode data capture */ +#define AD717x_DATA_BUFFER_SIZE (8192) + +/* Scan type definition */ +#define AD717x_SCAN {\ + .sign = 'u',\ + .realbits = AD717x_RESOLUTION,\ + .storagebits = CHN_STORAGE_BITS,\ + .shift = 0,\ + .is_big_endian = false\ +} + +/* Channel attribute definition */ +#define AD717x_CHANNEL(_name, _priv) {\ + .name = _name,\ + .priv = _priv,\ + .show = get_adc_attribute,\ + .store = set_adc_attribute\ +} + +/* AD717x Channel Definition */ +#define IIO_AD717x_CHANNEL(_idx) {\ + .name = "ch" # _idx,\ + .ch_type = IIO_VOLTAGE,\ + .channel = _idx,\ + .scan_index = _idx,\ + .indexed = true,\ + .scan_type = &ad717x_scan_type[_idx],\ + .ch_out = false,\ + .attributes = ad717x_channel_attributes,\ +} + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +/* IIO interface descriptor */ +static struct iio_desc *p_ad717x_iio_desc; + +/* Pointer to the struct representing the AD717x IIO device */ +ad717x_dev *p_ad717x_dev_inst = NULL; + +/* Device Name */ +static const char dev_name[] = ACTIVE_DEVICE_NAME; + +/* Variable to hold the number of active channels*/ +uint8_t num_active_channels = 0; + +/* Channel scale values */ +static float attr_scale_val[NUMBER_OF_CHANNELS]; + +/* Channel offset values */ +static int attr_offset_val[NUMBER_OF_CHANNELS]; + +/* AD717x channel scan type */ +static struct scan_type ad717x_scan_type[] = { + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, +#if (NUMBER_OF_CHANNELS != 4) + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, +#if (NUMBER_OF_CHANNELS != 4) && (NUMBER_OF_CHANNELS !=8 ) + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN, + AD717x_SCAN +#endif +#endif +}; + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/ + +/*! + * @brief Getter/Setter for the attribute value + * @param device[in]- pointer to IIO device structure + * @param buf[in]- pointer to buffer holding attribute value + * @param len[in]- length of buffer string data + * @param channel[in]- pointer to IIO channel structure + * @param id[in]- Attribute ID + * @return Number of characters read/written in case of success, negative error code otherwise + */ +static int32_t get_adc_attribute(void *device, + char *buf, + uint32_t len, + const struct iio_ch_info *channel, + intptr_t id) +{ + int32_t adc_raw_data = 0; + int32_t adc_offset = 0; + + switch (id) { + case AD717x_RAW_ATTR_ID: + if (ad717x_single_read(device, channel->ch_num, &adc_raw_data) < 0) + return -EINVAL; + + return sprintf(buf, "%d", adc_raw_data); + + case AD717x_SCALE_ATTR_ID: + return sprintf(buf, "%f", attr_scale_val[channel->ch_num]); + + case AD717x_OFFSET_ATTR_ID: + return sprintf(buf, "%d", attr_offset_val[channel->ch_num]); + + case AD717x_SAMPLING_FREQUENCY_ID: + return sprintf(buf, "%d", AD717x_SAMPLING_RATE/NUMBER_OF_CHANNELS); + + default: + break; + } + + return -EINVAL; +} + + +static int32_t set_adc_attribute(void *device, + char *buf, + uint32_t len, + const struct iio_ch_info *channel, + intptr_t id) +{ + switch (id) { + + /* ADC Raw, Scale, Offset factors are constant for the firmware configuration */ + case AD717x_RAW_ATTR_ID: + case AD717x_SCALE_ATTR_ID: + case AD717x_OFFSET_ATTR_ID: + case AD717x_SAMPLING_FREQUENCY_ID: + default: + break; + } + + return len; +} + +/* AD717X Channel Attributes */ +static struct iio_attribute ad717x_channel_attributes[] = { + AD717x_CHANNEL("raw", AD717x_RAW_ATTR_ID), + AD717x_CHANNEL("scale", AD717x_SCALE_ATTR_ID), + AD717x_CHANNEL("offset", AD717x_OFFSET_ATTR_ID), + END_ATTRIBUTES_ARRAY +}; + +/* AD717x Global Attributes */ +static struct iio_attribute iio_ad717x_global_attributes[] = { + AD717x_CHANNEL("sampling_frequency", AD717x_SAMPLING_FREQUENCY_ID), + END_ATTRIBUTES_ARRAY +}; + +/* IIO Attributes */ +static struct iio_channel iio_adc_channels[] = { + IIO_AD717x_CHANNEL(0), + IIO_AD717x_CHANNEL(1), + IIO_AD717x_CHANNEL(2), + IIO_AD717x_CHANNEL(3), +#if (NUMBER_OF_CHANNELS != 4) + IIO_AD717x_CHANNEL(4), + IIO_AD717x_CHANNEL(5), + IIO_AD717x_CHANNEL(6), + IIO_AD717x_CHANNEL(7), +#if (NUMBER_OF_CHANNELS != 4) && (NUMBER_OF_CHANNELS != 8) + IIO_AD717x_CHANNEL(8), + IIO_AD717x_CHANNEL(9), + IIO_AD717x_CHANNEL(10), + IIO_AD717x_CHANNEL(11), + IIO_AD717x_CHANNEL(12), + IIO_AD717x_CHANNEL(13), + IIO_AD717x_CHANNEL(14), + IIO_AD717x_CHANNEL(15) +#endif +#endif +}; + +/** + * @brief Read the debug register value + * @param desc[in,out] - Pointer to IIO device descriptor + * @param reg[in]- Address of the register to be read + * @param readval[out]- Pointer to the register data variable + * @return 0 in case of success, negative error code + */ +static int32_t iio_ad717x_debug_reg_read(void *dev, + uint32_t reg, + uint32_t *readval) +{ + int32_t debug_read_status; // Status check variable + + /* Retrieve the pointer to the requested register */ + ad717x_st_reg *read_register = AD717X_GetReg(p_ad717x_dev_inst, reg); + if (!read_register) { + return -EINVAL; + } + + /* Read the register data, extract the value */ + debug_read_status = AD717X_ReadRegister(p_ad717x_dev_inst, reg); + if (debug_read_status) { + return debug_read_status; + } + *readval = read_register->value; + + return 0; +} + + +/** + * @brief Write value to the debug register + * @param desc[in,out] Pointer to IIO device descriptor + * @param reg[in] Address of the register where the data is to be written + * @param write_val[out] Pointer to the register data variable + * @return 0 in case of success, negative error code otherwise + */ +static int32_t iio_ad717x_debug_reg_write(void *dev, + uint32_t reg, + uint32_t write_val) +{ + int32_t debug_write_status; // Status check variable + ad717x_st_reg *device_data_reg; // Pointer to data register + + /* Retrieve the pointer to the requested registrer */ + device_data_reg = AD717X_GetReg(p_ad717x_dev_inst, reg); + device_data_reg->value = write_val; + + /* Write value to the register */ + debug_write_status = AD717X_WriteRegister(p_ad717x_dev_inst, reg); + if (debug_write_status) { + return debug_write_status; + } + + return 0; +} + + +/** + * @brief Transfer the device data into memory (optional) + * @param dev_instance[in] - IIO device instance + * @param ch_mask[in] - Channels select mask + * @return 0 in case of success or negative value otherwise + */ +static int32_t iio_ad717x_pre_enable(void *dev_instance, uint32_t chn_mask) +{ + return prepare_data_transfer(chn_mask, NUMBER_OF_CHANNELS, BYTES_PER_SAMPLE); +} + + +/** + * @brief Read buffer data corresponding to AD4170 IIO device + * @param iio_dev_data[in] - Pointer to IIO device data structure + * @return 0 in case of success or negative value otherwise + */ +static int32_t iio_ad717x_submit_buffer(struct iio_device_data *iio_dev_data) +{ + int32_t ret; + + /* Read the samples counts equal to buffer size/block */ + ret = read_buffered_data(&iio_dev_data->buffer->buf->buff, + iio_dev_data->buffer->size); + + /* Increment the write spin count as buffer reads all 'n' samples + * in one go which is also the size of buffer block for a given instance. + * The read spin count is incremented from IIO library during buffer + * write/offloading into transmit buffer */ + if (iio_dev_data->buffer->buf->write.spin_count >= UINT32_MAX) { + iio_dev_data->buffer->buf->write.spin_count = 0; + } + + iio_dev_data->buffer->buf->write.spin_count += 1; + + return ret; +} + + +/** + * @brief Perform tasks before end of current data transfer + * @param dev[in] - IIO device instance + * @return 0 in case of success or negative value otherwise + */ +static int32_t iio_ad717x_post_disable(void *dev) +{ + return end_data_transfer(); +} + + +/** + * @brief Init for reading/writing and parameterization of a AD717x IIO device + * @param desc[in,out] IIO device descriptor + * @return 0 in case of success, negative error code otherwise + */ +int32_t iio_ad717x_init(struct iio_device **desc) +{ + struct iio_device *iio_ad717x_inst; // IIO Device Descriptor for AD717x + + iio_ad717x_inst = calloc(1, sizeof(struct iio_device)); + if (!iio_ad717x_inst) { + return -EINVAL; + } + + iio_ad717x_inst->num_ch = NO_OS_ARRAY_SIZE(iio_adc_channels); + iio_ad717x_inst->channels = iio_adc_channels; + iio_ad717x_inst->attributes = iio_ad717x_global_attributes; + iio_ad717x_inst->buffer_attributes = NULL; + iio_ad717x_inst->write_dev = NULL; + iio_ad717x_inst->pre_enable = iio_ad717x_pre_enable; + iio_ad717x_inst->post_disable = iio_ad717x_post_disable; + iio_ad717x_inst->submit = iio_ad717x_submit_buffer; + iio_ad717x_inst->debug_reg_read = iio_ad717x_debug_reg_read; + iio_ad717x_inst->debug_reg_write = iio_ad717x_debug_reg_write; + + *desc = iio_ad717x_inst; + + return 0; +} + + +/** + * @brief Function to update scale and offset values based on user selection + * @param device[in] AD717x device descriptor + * @return 0 in case of success, negative error code otherwise + */ +static int32_t ad717x_update_attr_parameters(ad717x_dev *device) +{ + float reference_value = 0; // Variable to hold the updated reference value + uint8_t i; + + for (i = 0; i < NUMBER_OF_CHANNELS; i++) { + /* Update reference value */ + switch (device->setups[device->chan_map[i].setup_sel].ref_source) { + case INTERNAL_REF: + reference_value = AD717X_INTERNAL_REFERENCE; + break; + case EXTERNAL_REF: + reference_value = AD717x_EXTERNAL_REFERENCE; + break; + case AVDD_AVSS: + reference_value = AD717X_AVDD_AVSS_REFERENCE; + break; + default: + return -EINVAL; + } + + /* Update channel attribute parameters */ + if (!(device->setups[device->chan_map[i].setup_sel].bi_unipolar)) { + /* Settings for Unipolar mode */ + attr_scale_val[i] = ((reference_value / ADC_MAX_COUNT_UNIPOLAR) * 1000) / + SCALE_FACTOR_DR; + attr_offset_val[i] = 0; + ad717x_scan_type[i].sign = 'u'; + ad717x_scan_type[i].realbits = AD717x_RESOLUTION; + } else { + /* Settings for Bipolar mode */ + attr_scale_val[i] = ((reference_value / (ADC_MAX_COUNT_BIPOLAR)) * 1000) / + SCALE_FACTOR_DR; + attr_offset_val[i] = -(1 << (AD717x_RESOLUTION - 1)); + ad717x_scan_type[i].sign = 's'; + ad717x_scan_type[i].realbits = CHN_STORAGE_BITS; + } + } + + return 0; +} + + +/** + * @brief Initialize the AD717x IIO Interface + * @return 0 in case of success, negative error code otherwise + */ +int32_t ad717x_iio_initialize(void) +{ + int32_t iio_init_status; // Status check variable + struct iio_init_param iio_init_params; // IIO Init Parameters + struct iio_device *ad717x_iio_desc; // aD717x IIO Descriptor + + /* Init the system peripheral- UART */ + iio_init_status = init_system(); + if (iio_init_status) { + return iio_init_status; + } + + /* IIO Initialization Parameters */ + iio_init_params.phy_type = USE_UART; + iio_init_params.nb_devs = 1; + + /* IIOD init parameters */ + struct iio_device_init iio_device_init_params = { + .name = (char*)dev_name, + .raw_buf = adc_data_buffer, + .raw_buf_len = DATA_BUFFER_SIZE + }; + + /* Initialize AD717x device */ + iio_init_status = AD717X_Init(&p_ad717x_dev_inst, ad717x_init_params); + if (iio_init_status) { + return iio_init_status; + } + + /* Update the ADC scale respective to the device settings */ + iio_init_status = ad717x_update_attr_parameters(p_ad717x_dev_inst); + if (iio_init_status) { + return iio_init_status; + } + + /* Initialize the AD717x IIO Interface */ + iio_init_status = iio_ad717x_init(&ad717x_iio_desc); + if (iio_init_status) { + return iio_init_status; + } + + /* Initialize the IIO Interface */ + iio_init_params.uart_desc = uart_desc; + iio_device_init_params.dev = p_ad717x_dev_inst; + iio_device_init_params.dev_descriptor = ad717x_iio_desc; + iio_init_params.devs = &iio_device_init_params; + iio_init_params.nb_trigs = 0; + iio_init_status = iio_init(&p_ad717x_iio_desc, &iio_init_params); + if (iio_init_status) { + return iio_init_status; + } + + return 0; +} + + +/** + * @brief Run the AD717x IIO event handler + * @return None + */ +void ad717x_iio_event_handler(void) +{ + (void)iio_step(p_ad717x_iio_desc); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_iio.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,42 @@ +/*************************************************************************//** + * @file ad717x_iio.h + * @brief IIO Header file for AD717x and AD411x +****************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*****************************************************************************/ + +#ifndef AD717x_IIO_H_ +#define AD717x_IIO_H_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdint.h> +#include "iio.h" +#include "ad717x.h" + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************ Public Declarations *********************************/ +/******************************************************************************/ + +extern ad717x_dev *p_ad717x_dev_inst; +int32_t ad717x_iio_initialize(void); +void ad717x_iio_event_handler(void); + +#endif // AD717x_IIO_H_ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_support.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,63 @@ +/*************************************************************************//** + * @file ad717x_support.c + * @brief Support file for AD717X device configurations +****************************************************************************** +* Copyright (c) 2022 Analog Devices, Inc. +* +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*****************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include "ad717x_support.h" +#include "ad717x_iio.h" +#include "no_os_error.h" + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Declarations ****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************ Functions Definitions *******************************/ +/******************************************************************************/ + +/** + * @brief Enable/Disable continuous read mode + * @param device[in] - The AD717x Device descriptor + * @param cont_read_en[in] - True in case of enable CONT_READ/ False in case of disable + * @return 0 in case of success, negative error code otherwise + */ +int32_t ad717x_enable_cont_read(ad717x_dev *device, bool cont_read_en) +{ + ad717x_st_reg *ifmode_reg; + int32_t ret; + + /* Retrieve the IFMODE Register */ + ifmode_reg = AD717X_GetReg(p_ad717x_dev_inst, AD717X_IFMODE_REG); + if (!ifmode_reg) { + return -EINVAL; + } + + if (cont_read_en) { + ifmode_reg->value |= (AD717X_IFMODE_REG_CONT_READ); + } else { + ifmode_reg->value &= ~(AD717X_IFMODE_REG_CONT_READ); + } + + ret = AD717X_WriteRegister(p_ad717x_dev_inst, AD717X_IFMODE_REG); + if (ret) { + return ret; + } + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_support.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,36 @@ +/*************************************************************************//** + * @file ad717x_support.h + * @brief Header for AD717X support configurations +****************************************************************************** +* Copyright (c) 2022 Analog Devices, Inc. +* +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*****************************************************************************/ +#ifndef AD717X_SUPPORT_H_ +#define AD717X_SUPPORT_H_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include "ad717x.h" + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ + +/******************************************************************************/ +/********************** Public/Extern Declarations ****************************/ +/******************************************************************************/ + +int32_t ad717x_enable_cont_read(ad717x_dev *device, bool cont_read_en); + +#endif /* AD717X_SUPPORT_H_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_user_config.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,159 @@ +/***************************************************************************//** + * @file ad717x_user_config.c + * @brief User Configuration source for AD717x-AD411x IIO Application +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdio.h> +#include "ad717x_user_config.h" +#include "ad717x.h" +#include "ad717x_iio.h" +#include "no_os_util.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +#if defined(DEV_AD4111) || defined(DEV_AD4112) || defined(DEV_AD4114) || \ + defined(DEV_AD4115) +#include <ad411x_regs.h> +#define AD717X_DEVICE_MAP ad4111_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad4111_regs) +#elif defined(DEV_AD7172_2) +#include <ad7172_2_regs.h> +#define AD717X_DEVICE_MAP ad7172_2_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7172_2_regs) +#elif defined(DEV_AD7172_4) +#include <ad7172_4_regs.h> +#define AD717X_DEVICE_MAP ad7172_4_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7172_4_regs) +#elif defined(DEV_AD7173_8) +#include <ad7173_8_regs.h> +#define AD717X_DEVICE_MAP ad7173_8_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7173_8_regs) +#elif defined(DEV_AD7175_2) +#include <ad7175_2_regs.h> +#define AD717X_DEVICE_MAP ad7175_2_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7175_2_regs) +#elif defined(DEV_AD7175_8) +#include <ad7175_8_regs.h> +#define AD717X_DEVICE_MAP ad7175_8_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7175_8_regs) +#elif defined(DEV_AD7176_2) +#include <ad7176_2_regs.h> +#define AD717X_DEVICE_MAP ad7176_2_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad7176_2_regs) +#else +#include <ad411x_regs.h> +#define AD717X_DEVICE_MAP ad4111_regs +#define AD717x_NUM_REGS NO_OS_ARRAY_SIZE(ad4111_regs) +#endif + +/* AD717x Init Parameters */ +ad717x_init_param ad717x_init_params = { + .spi_init = { + .max_speed_hz = 20000000, + .chip_select = SPI_CSB, + .mode = NO_OS_SPI_MODE_3, + .platform_ops = &spi_platform_ops, + .extra = &spi_extra_init_params + }, + .num_regs = AD717x_NUM_REGS, + .regs = AD717X_DEVICE_MAP, + .ref_en = true, + .active_device = ACTIVE_DEVICE_ID, + .num_channels = NUMBER_OF_CHANNELS, + .num_setups = NUMBER_OF_SETUPS, + .mode = CONTINUOUS, + .setups = { + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, +#if (NUMBER_OF_SETUPS != 4) + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, + { .bi_unipolar = true, .ref_buff = false, .input_buff = true, .ref_source = INTERNAL_REF }, +#endif + }, + .chan_map = { +#if defined (DEV_AD4111) || defined (DEV_AD4112) || defined (DEV_AD4114) || defined (DEV_AD4115) + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 1, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, +#if (NUMBER_OF_CHANNELS != 4) + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, +#if (NUMBER_OF_CHANNELS != 4) && (NUMBER_OF_CHANNELS != 8) + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.analog_input_pairs = VIN0_VIN1 }, +#endif +#endif +#else // AD717x Family + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, +#if (NUMBER_OF_CHANNELS != 4) + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, +#if (NUMBER_OF_CHANNELS != 4) && (NUMBER_OF_CHANNELS != 8) + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, + { .channel_enable = false, .setup_sel = 0, .analog_inputs.ainp.pos_analog_input = AIN0, .analog_inputs.ainp.neg_analog_input = AIN1 }, +#endif // (NUMBER_OF_CHANNELS != 4) && (NUMBER_OF_CHANNELS != 8) +#endif // (NUMBER_OF_CHANNELS != 4) +#endif // (DEV_AD4111),(DEV_AD4112),(DEV_AD4114),(DEV_AD4115) + }, + .filter_configuration = { + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, +#if (NUMBER_OF_SETUPS != 4) + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, + {.odr = AD717x_ODR_SEL}, +#endif // (NUMBER_OF_SETUPS!= 4) + } +}; + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/ad717x_user_config.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,39 @@ +/*************************************************************************//** + * @file ad717x_user_config.h + * @brief User configuration file for AD717x-AD411x IIO firmware application +****************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*****************************************************************************/ + +#ifndef AD717x_USER_CONFIG_H_ +#define AD717x_USER_CONFIG_H_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdio.h> +#include "ad717x.h" +#include "app_config.h" + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************ Public Declarations *********************************/ +/******************************************************************************/ + +extern ad717x_init_param ad717x_init_params; + +#endif // AD717x_USER_CONFIG_H_
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/app_config.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,157 @@ +/***************************************************************************//** + * @file app_config.c + * @brief Source file for the application configuration for AD717x IIO Application +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdio.h> +#include "no_os_uart.h" +#include "ad717x.h" +#include "app_config.h" +#include "no_os_gpio.h" +#include "no_os_irq.h" +#include "ad717x_data_capture.h" +#include "no_os_error.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +/* The UART Descriptor */ +struct no_os_uart_desc *uart_desc; + +/* GPIO descriptor for the chip select pin */ +struct no_os_gpio_desc *csb_gpio; + +/* External interrupt descriptor */ +struct no_os_irq_ctrl_desc *external_int_desc; + +/* UART Initialization Parameters */ +static struct no_os_uart_init_param uart_init_params = { + .device_id = NULL, + .baud_rate = IIO_UART_BAUD_RATE, + .size = NO_OS_UART_CS_8, + .parity = NO_OS_UART_PAR_NO, + .stop = NO_OS_UART_STOP_1_BIT, + .extra = &uart_extra_init_params +}; + +/* GPIO - Chip select Pin init parameters */ +static struct no_os_gpio_init_param csb_init_param = { + .number = SPI_CSB, + .platform_ops = &csb_platform_ops, + .extra = NULL +}; + +/* External interrupt init parameters */ +static struct no_os_irq_init_param ext_int_init_params = { + .irq_ctrl_id = 0, + .platform_ops = &irq_platform_ops, + .extra = &ext_int_extra_init_params +}; + +/* External interrupt callback descriptor */ +static struct no_os_callback_desc ext_int_callback_desc = { + data_capture_callback, + NULL, + NULL +}; + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/ + +/** + * @brief Initialize the UART peripheral + * @return SUCCESS in case of success, negative error code + */ +static int32_t init_uart(void) +{ + return no_os_uart_init(&uart_desc, &uart_init_params); +} + + +/** + * @brief Initialize the IRQ contoller + * @return SUCCESS in case of success, negative error code otherwise + * @details This function initialize the interrupts for system peripherals + */ +int32_t init_interrupt(void) +{ + int32_t ret; + + do { + /* Init interrupt controller for external interrupt */ + ret = no_os_irq_ctrl_init(&external_int_desc, &ext_int_init_params); + if (ret) { + break; + } + + /* Register a callback function for external interrupt */ + ret = no_os_irq_register_callback(external_int_desc, EXTERNAL_INT_ID1, + &ext_int_callback_desc); + if (ret) { + break; + } + + return 0; + } while (0); + + return ret; +} + + +/** + * @brief Initialize the system peripherals + * @return SUCCESS in case of success, negative error code otherwise + */ +int32_t init_system(void) +{ + int32_t ret; + + if (init_uart() != 0) { + return -EINVAL; + } + +#if defined(USE_SDRAM_CAPTURE_BUFFER) + if (sdram_init() != 0) { + return -EINVAL; + } +#endif + +#if (DATA_CAPTURE_MODE == CONTINUOUS_DATA_CAPTURE) + ret = init_interrupt(); + if (ret) { + return ret; + } + + ret = no_os_gpio_get(&csb_gpio, &csb_init_param); + if (ret) { + return ret; + } + + ret = no_os_gpio_direction_output(csb_gpio, NO_OS_GPIO_HIGH); + if (ret) { + return ret; + } +#endif + return 0; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/app_config.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,296 @@ +/*************************************************************************//** + * @file app_config.h + * @brief Configuration file for AD717x and AD411x IIO firmware application +****************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*****************************************************************************/ + +#ifndef APP_CONFIG_H +#define APP_CONFIG_H + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ +#include <stdint.h> +#include "no_os_gpio.h" + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +/* List of supported platforms */ +#define MBED_PLATFORM 1 + +/* Select the active platform */ +#if !defined(ACTIVE_PLATFORM) +#define ACTIVE_PLATFORM MBED_PLATFORM +#endif // ACTIVE_PLATFORM + +/* List of data capture modes for AD717x device */ +#define CONTINUOUS_DATA_CAPTURE 0 +#define BURST_DATA_CAPTURE 1 + +// **** Note for User on selection of Active Device ****// +/* Define the device type here from the list of below device type defines + * (one at a time. Defining more than one device can result into compile error). + * e.g. #define DEV_AD4111 -> This will make AD4111 as an active device. + * The active device is default set to AD4111 if device type is not defined. + * */ +// #define DEV_AD4111 + +#if defined(DEV_AD4111) +#define ACTIVE_DEVICE_NAME "ad4111" +#define ACTIVE_DEVICE_ID ID_AD4111 +#elif defined(DEV_AD4112) +#define ACTIVE_DEVICE_NAME "ad4112" +#define ACTIVE_DEVICE_ID ID_AD4112 +#elif defined(DEV_AD4114) +#define ACTIVE_DEVICE_NAME "ad4114" +#define ACTIVE_DEVICE_ID ID_AD4114 +#elif defined(DEV_AD4115) +#define ACTIVE_DEVICE_NAME "ad4115" +#define ACTIVE_DEVICE_ID ID_AD4115 +#elif defined(DEV_AD7172_2) +#define AD7172_2_INIT +#define ACTIVE_DEVICE_NAME "ad7172-2" +#define ACTIVE_DEVICE_ID ID_AD7172_2 +#elif defined(DEV_AD7172_4) +#define AD7172_4_INIT +#define ACTIVE_DEVICE_NAME "ad7172-4" +#define ACTIVE_DEVICE_ID ID_AD7172_4 +#elif defined(DEV_AD7173_8) +#define AD7173_8_INIT +#define ACTIVE_DEVICE_NAME "ad7173-8" +#define ACTIVE_DEVICE_ID ID_AD7173_8 +#elif defined(DEV_AD7175_2) +#define AD7175_2_INIT +#define ACTIVE_DEVICE_NAME "ad7175-2" +#define ACTIVE_DEVICE_ID ID_AD7175_2 +#elif defined(DEV_AD7175_8) +#define AD7175_8_INIT +#define ACTIVE_DEVICE_NAME "ad7175-8" +#define ACTIVE_DEVICE_ID ID_AD7175_8 +#elif defined(DEV_AD7176_2) +#define AD7176_2_INIT +#define ACTIVE_DEVICE_NAME "ad7176-2" +#define ACTIVE_DEVICE_ID ID_AD7176_2 +#elif defined(DEV_AD7177_2) +#define AD7177_2_INIT +#define ACTIVE_DEVICE_NAME "ad7177-2" +#define ACTIVE_DEVICE_ID ID_AD7177_2 +#else +#warning No/Unsupported ADxxxxy symbol defined. AD4111 defined +#define DEV_AD4111 +#define ACTIVE_DEVICE_NAME "ad4111" +#define ACTIVE_DEVICE_ID ID_AD4111 +#endif // Device Select (Active Device name definition) + +#if (ACTIVE_PLATFORM == MBED_PLATFORM) +#include "app_config_mbed.h" +/* Redefine the init params structure mapping w.r.t. platform */ +#define uart_extra_init_params mbed_uart_extra_init_params +#define spi_extra_init_params mbed_spi_extra_init_params +#define ext_int_extra_init_params mbed_ext_int_extra_init_params +#define csb_platform_ops mbed_gpio_ops +#define irq_platform_ops mbed_irq_ops +#define spi_platform_ops mbed_spi_ops +#define IRQ_INT_ID EXTERNAL_INT_ID1 +#endif // ACTIVE_PLATFORM + +/* Enable the UART/VirtualCOM port connection (default VCOM) */ +//#define USE_PHY_COM_PORT // Uncomment to select UART + +#if !defined(USE_PHY_COM_PORT) + +/* VCOM Serial number definition */ +#define FIRMWARE_NAME "AD717x_MBED_IIO_APPLICATION" + +#if !defined(PLATFORM_NAME) +#define PLATFORM_NAME "SDP_K1" +#endif + +#if !defined(EVB_INTERFACE) +#define EVB_INTERFACE "SDP_120" +#endif + +/* Below USB configurations (VID and PID) are owned and assigned by ADI. + * If intended to distribute software further, use the VID and PID owned by your + * organization */ +#define VIRTUAL_COM_PORT_VID 0x0456 +#define VIRTUAL_COM_PORT_PID 0xb66c + +#define VIRTUAL_COM_SERIAL_NUM (FIRMWARE_NAME "_" PLATFORM_NAME "_" EVB_INTERFACE) +#endif // !defined(USE_PHY_COM_PORT) + +/* Definition for number of channels for the selected device */ +#if defined(DEV_AD4111) || defined(DEV_AD4112) || \ + defined(DEV_AD4114) || defined(DEV_AD4115) || \ + defined(DEV_AD7173_8) || defined(DEV_AD7175_8) +#define NUMBER_OF_CHANNELS 16U +#define NUMBER_OF_SETUPS 8U +#elif defined(DEV_AD7172_4) +#define NUMBER_OF_CHANNELS 8U +#define NUMBER_OF_SETUPS 8U +#else //AD7172_2, AD71725_2, AD7176-2, AD7177-2 +#define NUMBER_OF_CHANNELS 4U +#define NUMBER_OF_SETUPS 4U +#endif // Device Select + +/* Select the ADC data capture mode (default is CC mode) */ +#if !defined(DATA_CAPTURE_MODE) +#define DATA_CAPTURE_MODE CONTINUOUS_DATA_CAPTURE +#endif + +/* Enable/Disable the use of SDRAM for ADC data capture buffer */ +//#define USE_SDRAM_CAPTURE_BUFFER // Uncomment to use SDRAM as data buffer + +/* ADC Reference Voltage in volts */ +#define AD717X_INTERNAL_REFERENCE 2.5 +#define AD717x_EXTERNAL_REFERENCE 2.5 +#define AD717X_AVDD_AVSS_REFERENCE 2.5 + +/* Baud Rate for IIO Application */ +#define IIO_UART_BAUD_RATE (230400) + +/* AD717x Sampling Rate of the device in SPS, excluding the fractional part. + * The following are the possible values of sampling frequencies (in SPS): + * + * AD4111, AD41112, AD4114, AD4115: + * 31250, 15625, 10417, 5208, 2957, 1007, 503, 381, 200, 100, 59, 49, 20, 16, 10, 5, 2, 1. + * + *AD7175_2, AD7175_8, AD7176_2: + * 31250, 25000, 10000, 5000, 2500, 1000, 500, 397, 200, 100, 59, 49, 20, 16, 10, 5 + * + *AD7177_2: + *10000, 5000, 2500, 1000, 500, 397, 200, 100, 59, 49, 20, 16, 10, 5 + * + * Note: The below defined sampling frequency is applicable for all setups */ +#define AD717x_SAMPLING_RATE (31250) + +/* ODR[4:0] bits*/ +#if defined (DEV_AD4111) || defined (DEV_AD4112) || defined (DEV_AD4114) ||\ + defined (DEV_AD4115) || defined (DEV_AD7172_2) || defined (DEV_AD7172_4) ||\ +defined (DEV_AD7173_8) +#if (AD717x_SAMPLING_RATE == 31250) +#define AD717x_ODR_SEL 0 +#elif (AD717x_SAMPLING_RATE == 15625) +#define AD717x_ODR_SEL 6 +#elif (AD717x_SAMPLING_RATE == 10417) +#define AD717x_ODR_SEL 7 +#elif (AD717x_SAMPLING_RATE == 5208) +#define AD717x_ODR_SEL 8 +#elif (AD717x_SAMPLING_RATE == 2957) +#define AD717x_ODR_SEL 9 +#elif (AD717x_SAMPLING_RATE == 1007) +#define AD717x_ODR_SEL 10 +#elif (AD717x_SAMPLING_RATE == 503) +#define AD717x_ODR_SEL 11 +#elif (AD717x_SAMPLING_RATE == 381) +#define AD717x_ODR_SEL 12 +#elif (AD717x_SAMPLING_RATE == 200) +#define AD717x_ODR_SEL 13 +#elif (AD717x_SAMPLING_RATE == 100) +#define AD717x_ODR_SEL 14 +#elif (AD717x_SAMPLING_RATE == 59) +#define AD717x_ODR_SEL 15 +#elif (AD717x_SAMPLING_RATE == 49) +#define AD717x_ODR_SEL 16 +#elif (AD717x_SAMPLING_RATE == 20) +#define AD717x_ODR_SEL 17 +#elif (AD717x_SAMPLING_RATE == 16) +#define AD717x_ODR_SEL 18 +#elif (AD717x_SAMPLING_RATE == 10) +#define AD717x_ODR_SEL 19 +#elif (AD717x_SAMPLING_RATE == 5) +#define AD717x_ODR_SEL 20 +#elif (AD717x_SAMPLING_RATE == 2) +#define AD717x_ODR_SEL 21 +#elif (AD717x_SAMPLING_RATE == 1) +#define AD717x_ODR_SEL 22 +#else +#warining "Invalid sampling frequency selection, using 31250 as default" +#define AD717x_SAMPLING_RATE 31250 +#define AD717x_ODR_SEL 0 +#endif + +#elif defined (DEV_AD7175_2) || defined (DEV_AD7175_8) || defined (DEV_AD7176_2) || defined (DEV_AD7177_2) +#if !defined (DEV_AD7177_2) +#if (AD717x_SAMPLING_RATE == 31250) +#define AD717x_ODR_SEL 4 +#elif (AD717x_SAMPLING_RATE == 25000) +#define AD717x_ODR_SEL 5 +#elif (AD717x_SAMPLING_RATE == 15625) +#define AD717x_ODR_SEL 6 +#endif // DEV_AD7177_2 +#elif (AD717x_SAMPLING_RATE == 10000) +#define AD717x_ODR_SEL 7 +#elif (AD717x_SAMPLING_RATE == 5000) +#define AD717x_ODR_SEL 8 +#elif (AD717x_SAMPLING_RATE == 2500) +#define AD717x_ODR_SEL 9 +#elif (AD717x_SAMPLING_RATE == 1000) +#define AD717x_ODR_SEL 10 +#elif (AD717x_SAMPLING_RATE == 500) +#define AD717x_ODR_SEL 11 +#elif (AD717x_SAMPLING_RATE == 397) +#define AD717x_ODR_SEL 12 +#elif (AD717x_SAMPLING_RATE == 200) +#define AD717x_ODR_SEL 13 +#elif (AD717x_SAMPLING_RATE == 100) +#define AD717x_ODR_SEL 14 +#elif (AD717x_SAMPLING_RATE == 59) +#define AD717x_ODR_SEL 15 +#elif (AD717x_SAMPLING_RATE == 49) +#define AD717x_ODR_SEL 16 +#elif (AD717x_SAMPLING_RATE == 20) +#define AD717x_ODR_SEL 17 +#elif (AD717x_SAMPLING_RATE == 16) +#define AD717x_ODR_SEL 18 +#elif (AD717x_SAMPLING_RATE == 10) +#define AD717x_ODR_SEL 19 +#elif (AD717x_SAMPLING_RATE == 5) +#define AD717x_ODR_SEL 20 +#else +#warning "Invalid sampling frequency selection, using 31250 as default" +#if defined(DEV_AD7177_2) +#define AD717x_SAMPLING_RATE 10000 +#define AD717x_ODR_SEL 7 +#else +#define AD717x_SAMPLING_RATE 31250 +#define AD717x_ODR_SEL 4 +#endif // DEV_AD7177_2 warning +#endif +#endif + +/* Denominator of the scale factor to be applied while converting raw values to actual voltage */ +#if defined(DEV_AD4111) || defined(DEV_AD4112) || \ + defined(DEV_AD4114) || defined(DEV_AD4115) +#define SCALE_FACTOR_DR 0.1 +#else +#define SCALE_FACTOR_DR 1 +#endif + +/******************************************************************************/ +/********************** Variables and User Defined Data Types *****************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************ Public Declarations *********************************/ +/******************************************************************************/ + +extern struct no_os_uart_desc *uart_desc; + +extern struct no_os_gpio_desc *csb_gpio; + +extern struct no_os_irq_ctrl_desc *external_int_desc; + +int32_t init_system(void); + +#endif // APP_CONFIG_H +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/app_config_mbed.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,62 @@ +/***************************************************************************//** + * @file app_config_mbed.c + * @brief Source file for the mbed configuration for AD717x IIO Application +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include "app_config.h" +#include "app_config_mbed.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +/* UART MBED Platform Specific Init Parameters */ +struct mbed_uart_init_param mbed_uart_extra_init_params = { +#if defined(USE_PHY_COM_PORT) + .virtual_com_enable = false, + .uart_tx_pin = UART_TX, + .uart_rx_pin = UART_RX +#else + .virtual_com_enable = true, + .vendor_id = VIRTUAL_COM_PORT_VID, + .product_id = VIRTUAL_COM_PORT_PID, + .serial_number = VIRTUAL_COM_SERIAL_NUM +#endif +}; + +/* SPI MBED Platform Specific Init Parameters */ +struct mbed_spi_init_param mbed_spi_extra_init_params = { + .spi_clk_pin = SPI_SCK, + .spi_miso_pin = SPI_HOST_SDI, + .spi_mosi_pin = SPI_HOST_SDO, +}; + +/* External interrupt Mbed platform specific parameters */ +struct mbed_irq_init_param mbed_ext_int_extra_init_params = { + .int_mode = EXT_IRQ_FALL, + .ext_int_pin = RDY_PIN, + .int_obj_type = NULL +}; + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/app_config_mbed.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,82 @@ +/***************************************************************************//** + * @file app_config_mbed.h + * @brief Header file for Mbed platform configurations. +******************************************************************************** + * Copyright (c) 2021-22 Analog Devices, Inc. + * All rights reserved. + * + * This software is proprietary to Analog Devices, Inc. and its licensors. + * By using this software you agree to the terms of the associated + * Analog Devices Software License Agreement. +*******************************************************************************/ + +#ifndef APP_CONFIG_MBED_H_ +#define APP_CONFIG_MBED_H_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdint.h> +#include <PinNames.h> +#include "mbed_spi.h" +#include "mbed_uart.h" +#include "mbed_irq.h" +#include "mbed_gpio.h" +#if defined(TARGET_SDP_K1) +#include "sdram_sdpk1.h" +#endif + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ +/** + * The ADI SDP_K1 can be used with either arduino headers + * or the 120-pin SDP connector found on ADI evaluation + * boards. The default is the SDP-120 connector. + * + * Uncomment the #define ARDUINO below to enable the Arduino connector for + * EVAL-AD4114SDZ and the EVAL-4115SDZ +*/ + +/* NOTE: Only EVAL-AD4114SDZ and EVAL-AD4115SDZ support Arduino and SDP_120 + * interface. The other EVAL Boadrds (EVAL-AD4111SDZ, EVAL-AD4112SDZ, + * EVAL-AD7172-4SDZ, EVAL-AD7172-2SDZ , EVAL-AD7173-8SDZ, EVAL-AD7175-2SDZ, + * EVAL-AD7175-8SDZ, EVAL-AD7176-2SDZ, EVAL-AD7177-2SDZ) support only the + * SDP-120 interface. + */ + +//#define ARDUINO + +#ifdef ARDUINO +/* SPI Pins on SDP-K1-Arduino Interface */ +#define SPI_CSB ARDUINO_UNO_D10 // SPI_CS +#define SPI_HOST_SDO ARDUINO_UNO_D11 // SPI_MOSI +#define SPI_HOST_SDI ARDUINO_UNO_D12 // SPI_MISO +#define SPI_SCK ARDUINO_UNO_D13 // SPI_SCK +#else // Default- SDP_120 Interface +/* SPI Pins on SDP-K1-SDP-120 Interface */ +#define SPI_CSB SDP_SPI_CS_A +#define SPI_HOST_SDI SDP_SPI_MISO +#define SPI_HOST_SDO SDP_SPI_MOSI +#define SPI_SCK SDP_SPI_SCK +#endif // ARDUINO + +/* UART Common Pin Mapping on SDP-K1 */ +#define UART_TX CONSOLE_TX +#define UART_RX CONSOLE_RX + +/* RDY Pin indicates the end of conversion. This is also +the MISO pin for SPI communications */ +#define RDY_PIN SPI_HOST_SDI + +/******************************************************************************/ +/********************** Public/Extern Declarations ****************************/ +/******************************************************************************/ + +extern struct mbed_uart_init_param mbed_uart_extra_init_params; +extern struct mbed_spi_init_param mbed_spi_extra_init_params; +extern struct mbed_irq_init_param mbed_ext_int_extra_init_params; + +#endif // APP_CONFIG_MBED_H_ +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/main.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,52 @@ +/***************************************************************************//** + * @file main.c + * @brief Main interface for AD717x-AD411x IIO firmware application +******************************************************************************** +* Copyright (c) 2021-22 Analog Devices, Inc. +* All rights reserved. +* +* This software is proprietary to Analog Devices, Inc. and its licensors. +* By using this software you agree to the terms of the associated +* Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdbool.h> +#include <assert.h> +#include "ad717x_iio.h" + +/******************************************************************************/ +/********************* Macros and Constants Definition ************************/ +/******************************************************************************/ + +/******************************************************************************/ +/******************** Variables and User Defined Data Types *******************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Declaration *****************************/ +/******************************************************************************/ + +/******************************************************************************/ +/************************** Functions Definition ******************************/ +/******************************************************************************/ + +/** + * @brief Main entry point to application + * @return none + */ +int main(void) +{ + /* Initialize the AD717x IIO interface */ + if (ad717x_iio_initialize() != 0) { + assert(-1); + } + + while (1) { + /* Monitor the IIO client events */ + ad717x_iio_event_handler(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/no-OS.lib Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,1 @@ +https://github.com/analogdevicesinc/no-OS/#20fa59639588b9bc7a45693d6119f53d05a67401 \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/sdp_k1_sdram.lib Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/AnalogDevices/code/sdp_k1_sdram/#c02d2095090a \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/sdram_sdpk1.c Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,35 @@ +/***************************************************************************//** + * @file sdram_sdpk1.c + * @brief SDP-K1 SDRAM interafaces +******************************************************************************** + * Copyright (c) 2022 Analog Devices, Inc. + * All rights reserved. + * + * This software is proprietary to Analog Devices, Inc. and its licensors. + * By using this software you agree to the terms of the associated + * Analog Devices Software License Agreement. +*******************************************************************************/ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include "sdp_k1_sdram.h" +#include "no_os_error.h" + +/******************************************************************************/ +/************************ Functions Definitions *******************************/ +/******************************************************************************/ + +/** + * @brief Initialize the SDRAM + * @return 0 in case of success, negative error code otherwise + */ +int32_t sdram_init(void) +{ + if (SDP_SDRAM_Init() != SDRAM_OK) { + return -EIO; + } + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/app/sdram_sdpk1.h Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,36 @@ +/***************************************************************************//** + * @file sdram_sdpk1.c + * @brief SDP-K1 SDRAM interafaces header file +******************************************************************************** + * Copyright (c) 2022 Analog Devices, Inc. + * All rights reserved. + * + * This software is proprietary to Analog Devices, Inc. and its licensors. + * By using this software you agree to the terms of the associated + * Analog Devices Software License Agreement. +*******************************************************************************/ + +#ifndef SDRAM_SDPK1_ +#define SDRAM_SDPK1_ + +/******************************************************************************/ +/***************************** Include Files **********************************/ +/******************************************************************************/ + +#include <stdint.h> + +/******************************************************************************/ +/********************** Macros and Constants Definition ***********************/ +/******************************************************************************/ + +/* SDRAM configs for SDP-K1 */ +#define SDRAM_START_ADDRESS (volatile int8_t *)0xC0000000 +#define SDRAM_SIZE_BYTES (16777216) // 16MBytes + +/******************************************************************************/ +/************************ Public Declarations *********************************/ +/******************************************************************************/ + +int32_t sdram_init(void); + +#endif /* SDRAM_SDPK1_ */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#2eb06e76208588afc6cb7580a8dd64c5429a10ce \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed_app.json Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,23 @@ +{ + "config": { + "usb_speed": { + "help": "USE_USB_OTG_FS or USE_USB_OTG_HS or USE_USB_HS_IN_FS", + "value": "USE_USB_OTG_HS" + } + }, + "requires": ["bare-metal", "drivers-usb", "events"], + "macros": [ + "TINYIIOD_VERSION_MAJOR=0", + "TINYIIOD_VERSION_MINOR=1", + "TINYIIOD_VERSION_GIT=\"0.1\"", + "IIOD_BUFFER_SIZE=0x1000", + "_USE_STD_INT_TYPES" + ], + "target_overrides": { + "*": { + "platform.default-serial-baud-rate": 230400, + "target.printf_lib": "std", + "target.device_has_remove": ["CAN"] + } + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/ad717x_data_capture.py Thu Jun 09 10:57:51 2022 +0530 @@ -0,0 +1,153 @@ +import numpy +from serial import Serial +from time import sleep +from pynput import keyboard +import sys +import select +import os +import csv +import adi.ad717x import * + +# Global variables +line = 0 +writer = 0 +run_continuous = False +iterations = 0 +data_capture_abort = False +chn_count = 0 +data_list = [] + +def key_press_event(key): + global data_capture_abort + data_capture_abort = True + +def init_data_capture(): + global device + global data_list + global chn_count + global listener + + ######## User configuration ########## + # Configure the backend for PC to IIOD interface + uri = "serial:COM16,230400" # For UART, baud rate must be same as set in the FW. COM port is physical Or VCOM. + device_name = "ad4111" # Name of the device must be same as set in the FW. + ###################################### + + # Create an IIO device context + device = ad717x(uri, device_name) + device._ctx.set_timeout(100000) + + ######## User configuration ########## + # Channels to be captured e.g. [0]: 1chn, [0,1]: 2chns, [0,1,2,3]: 4chns, [0,1,2,3,4,5,6,7]: 8chns + device.rx_enabled_channels = [0,1,2,3] + + # The block of samples to be captured. Total samples are received in multiple iterations or blocks + samples_block = 400 # The samples needs to be captured in smaller blocks due to limitations + # of buffer size (RAM) in the firmware and IIO client timeout factor. + # Request to capture samples more than buffer size, will be ignored by firmware. + # Large time taken to read the samples from device, may cause timeout on IIO client. + ###################################### + + # Get the channels count from user + chn_count = len(device.rx_enabled_channels) + + # Store the rx buffer size and rx data type based on input channels + device.rx_buffer_size = int(samples_block / chn_count) # Per channel sample count + device._rx_data_type = np.int32 # size of sample + + listener = keyboard.Listener(on_press=key_press_event) + listener.start() + +def read_user_inputs(): + global iterations + global run_continuous + global device + samples_count = int(input("Enter the number of samples to be captured \n\ + 0: Unlimited \n\ + <50-1000000>: ")) + + if (samples_count == 0): + run_continuous = True + else: + run_continuous = False + iterations = (int)(samples_count / device.rx_buffer_size) + if (samples_count % device.rx_buffer_size): + iterations = iterations + 1 + +def init_data_logger(): + global writer + global chn_count + file_name = "adc_data_capture.csv" + current_dir = os.getcwd() + output_file = os.path.join(current_dir, file_name) + result_file = open(output_file, 'w', newline="") + writer = csv.writer(result_file) + row = [] + # Write the channels list header + for chn in range(0,chn_count): + item = "Ch {}".format(chn) + row.insert(chn, item) + writer.writerow(row) + + +def read_buffered_data(): + global line + global writer + global device + + # Receive data from device + data = device.rx() + if (line == 0): + print("Data capture started >>") + print("."*line, end="\r") + + if (chn_count == 1): + # Convert 1-D array to 2-D array + data_arr = np.reshape(data, (-1,1)) + else: + # Transpose data from N-D data array + data_arr = np.transpose(data) + + writer.writerows(data_arr) + + line = line+1 + if (line == 100): + line = 1 + print("\n", end="\r") + +def do_data_capture(): + global iterations + global run_continuous + global data_capture_abort + done = False + if (run_continuous == True): + print("Press any key to stop data capture..") + sleep(2) + data_capture_abort = False + while not data_capture_abort: + read_buffered_data() + else: + for val in range(0,iterations): + read_buffered_data() + + print("\r\nData capture finished\r\n") + +def exit(): + global listener + global writer + global device + + # Delete the objects + del listener + del writer + del device + +def main(): + init_data_capture() + init_data_logger() + read_user_inputs() + do_data_capture() + exit() + +if __name__ == "__main__": + main() \ No newline at end of file