no-OS
|
Implementation of ad7606 Driver. More...
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include "ad7606.h"
#include "no_os_error.h"
#include "no_os_util.h"
#include "no_os_crc.h"
#include "no_os_alloc.h"
#include "spi_engine.h"
#include "no_os_axi_io.h"
Classes | |
struct | ad7606_chip_info |
struct | ad7606_axi_dev |
Structure for AXI FPGA cores. More... | |
struct | ad7606_dev |
Device driver structure. More... | |
Macros | |
#define | AD7606_SPI_ENG_DATA_WIDTH 0x0C |
#define | AD7606_SPI_ENG_OFFLOAD_ADDR_WIDTH 0x10 |
#define | AD7606_SPI_ENG_OFFLOAD_FIFO_WIDTH 0x14 |
#define | AD7606_CONFIG_WR 0x80 |
#define | AD7606_CONFIG_RD 0x84 |
#define | AD7606_CONFIG_CTRL 0x8C |
#define | AD7606_CONFIG_CTRL_DEFAULT 0x00 |
#define | AD7606_CONFIG_CTRL_READ_OP 0x03 |
#define | AD7606_CONFIG_CTRL_WRITE_OP 0x01 |
#define | AD7606_CHAN_CTRL(c) (0x0400 + (c) * 0x40) |
#define | AD7606_CHAN_CTRL_ENABLE 0x01 |
#define | AD7606_CHAN_CTRL_DISABLE 0x00 |
#define | AD7606_CORE_CNTRL_3 0x4C |
#define | AD7606_CORE_RESET 0x40 |
#define | AD7606_SERIAL_CORE_ENABLE 0x00 |
#define | AD7606_SERIAL_CORE_DISABLE 0x01 |
#define | AD7606_PARALLEL_CORE_ENABLE 0x01 |
#define | AD7606_PARALLEL_CORE_DISABLE 0x00 |
Functions | |
NO_OS_DECLARE_CRC8_TABLE (ad7606_crc8) | |
NO_OS_DECLARE_CRC16_TABLE (ad7606_crc16) | |
int32_t | ad7606_get_channels_number (struct ad7606_dev *dev) |
Returns the number of channels this ADC has. More... | |
int32_t | ad7606_reg_read (struct ad7606_dev *dev, uint8_t reg_addr, uint8_t *reg_data) |
Write a device register via SPI or AXI Parallel core. More... | |
int32_t | ad7606_reg_write (struct ad7606_dev *dev, uint8_t reg_addr, uint8_t reg_data) |
Write a device register via SPI or AXI Parallel core. More... | |
int32_t | ad7606_reg_write_mask (struct ad7606_dev *dev, uint32_t addr, uint32_t mask, uint32_t val) |
Write a device register via SPI with masking. More... | |
int32_t | ad7606_convst (struct ad7606_dev *dev) |
Toggle the CONVST pin to start a conversion. More... | |
int32_t | ad7606_spi_data_read (struct ad7606_dev *dev, uint32_t *data) |
Read conversion data. More... | |
int32_t | ad7606_capture_pre_enable (struct ad7606_dev *dev) |
Prepares buffer capture for an AXI SPI Engine or AXI Parallel interface. More... | |
void | ad7606_capture_post_disable (struct ad7606_dev *dev) |
Disables buffer capture for an AXI SPI Engine or AXI Parallel interface. More... | |
int32_t | ad7606_read_samples (struct ad7606_dev *dev, uint32_t *data, uint32_t samples) |
Read muliple raw samples from device. More... | |
int32_t | ad7606_reset (struct ad7606_dev *dev) |
Reset the device by toggling the reset GPIO. More... | |
int32_t | ad7606_set_oversampling (struct ad7606_dev *dev, struct ad7606_oversampling oversampling) |
Set the oversampling ratio. More... | |
int32_t | ad7606_get_oversampling (struct ad7606_dev *dev, struct ad7606_oversampling *oversampling) |
Get the oversampling ratio. More... | |
const struct ad7606_range * | ad7606_get_ch_ranges (struct ad7606_dev *dev, uint8_t ch, uint32_t *num_ranges) |
Get the available channel ranges for the given channel. More... | |
bool | ad7606_sw_mode_enabled (struct ad7606_dev *dev) |
Returns true if SW mode is enabled. More... | |
int32_t | ad7606_set_ch_range (struct ad7606_dev *dev, uint8_t ch, struct ad7606_range range) |
Set the channel operation range. More... | |
int32_t | ad7606_get_ch_scale (struct ad7606_dev *dev, uint8_t ch, double *scale) |
Get the value of scale for the channel. More... | |
int32_t | ad7606_get_resolution_bits (struct ad7606_dev *dev) |
Get the resolution bits of this device. More... | |
int32_t | ad7606_set_ch_offset (struct ad7606_dev *dev, uint8_t ch, int8_t offset) |
Set the channel offset. More... | |
int32_t | ad7606_set_ch_phase (struct ad7606_dev *dev, uint8_t ch, uint8_t phase) |
Set the channel phase. More... | |
int32_t | ad7606_set_ch_gain (struct ad7606_dev *dev, uint8_t ch, uint8_t gain) |
Set the channel gain. More... | |
int32_t | ad7606_set_config (struct ad7606_dev *dev, struct ad7606_config config) |
Set the device config register. More... | |
int32_t | ad7606_set_digital_diag (struct ad7606_dev *dev, struct ad7606_digital_diag diag) |
Set the device digital diagnostics configuration. More... | |
int32_t | ad7606_init (struct ad7606_dev **device, struct ad7606_init_param *init_param) |
Initialize the ad7606 device structure. More... | |
int32_t | ad7606_data_correction_serial (struct ad7606_dev *dev, uint32_t *buf, int32_t *data, uint8_t *status) |
void | ad7606_axi_remove (struct ad7606_dev *dev) |
Free any resource used by the driver. More... | |
int32_t | ad7606_remove (struct ad7606_dev *dev) |
Free any resource used by the driver. More... | |
Implementation of ad7606 Driver.
Copyright 2019(c) Analog Devices, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define AD7606_CHAN_CTRL | ( | c | ) | (0x0400 + (c) * 0x40) |
#define AD7606_CHAN_CTRL_DISABLE 0x00 |
#define AD7606_CHAN_CTRL_ENABLE 0x01 |
#define AD7606_CONFIG_CTRL 0x8C |
#define AD7606_CONFIG_CTRL_DEFAULT 0x00 |
#define AD7606_CONFIG_CTRL_READ_OP 0x03 |
#define AD7606_CONFIG_CTRL_WRITE_OP 0x01 |
#define AD7606_CONFIG_RD 0x84 |
#define AD7606_CONFIG_WR 0x80 |
#define AD7606_CORE_CNTRL_3 0x4C |
#define AD7606_CORE_RESET 0x40 |
#define AD7606_PARALLEL_CORE_DISABLE 0x00 |
#define AD7606_PARALLEL_CORE_ENABLE 0x01 |
#define AD7606_SERIAL_CORE_DISABLE 0x01 |
#define AD7606_SERIAL_CORE_ENABLE 0x00 |
#define AD7606_SPI_ENG_DATA_WIDTH 0x0C |
#define AD7606_SPI_ENG_OFFLOAD_ADDR_WIDTH 0x10 |
#define AD7606_SPI_ENG_OFFLOAD_FIFO_WIDTH 0x14 |
void ad7606_axi_remove | ( | struct ad7606_dev * | dev | ) |
Free any resource used by the driver.
dev | - The device structure. |
void ad7606_capture_post_disable | ( | struct ad7606_dev * | dev | ) |
Disables buffer capture for an AXI SPI Engine or AXI Parallel interface.
dev | - The device structure. |
int32_t ad7606_capture_pre_enable | ( | struct ad7606_dev * | dev | ) |
Prepares buffer capture for an AXI SPI Engine or AXI Parallel interface.
dev | - The device structure. |
int32_t ad7606_convst | ( | struct ad7606_dev * | dev | ) |
Toggle the CONVST pin to start a conversion.
If needed, this function also puts the device in ADC reading mode by a write at address zero.
dev | - The device structure. |
int32_t ad7606_data_correction_serial | ( | struct ad7606_dev * | dev, |
uint32_t * | buf, | ||
int32_t * | data, | ||
uint8_t * | status | ||
) |
const struct ad7606_range* ad7606_get_ch_ranges | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
uint32_t * | num_ranges | ||
) |
Get the available channel ranges for the given channel.
dev | - The device structure. |
ch | - The channel number |
num_ranges | - A pointer to store the number of returned ranges. |
int32_t ad7606_get_ch_scale | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
double * | scale | ||
) |
Get the value of scale for the channel.
dev | - The device structure. |
ch | - The channel number. |
scale | - Pointer where to store the channel scale. |
int32_t ad7606_get_channels_number | ( | struct ad7606_dev * | dev | ) |
Returns the number of channels this ADC has.
dev | - The device structure. |
int32_t ad7606_get_oversampling | ( | struct ad7606_dev * | dev, |
struct ad7606_oversampling * | oversampling | ||
) |
Get the oversampling ratio.
Return the current oversampling ratio.
dev | - The device structure. |
oversampling | - Pointer to an object where to store oversampling settings. |
int32_t ad7606_get_resolution_bits | ( | struct ad7606_dev * | dev | ) |
Get the resolution bits of this device.
dev | - The device structure. |
int32_t ad7606_init | ( | struct ad7606_dev ** | device, |
struct ad7606_init_param * | init_param | ||
) |
Initialize the ad7606 device structure.
Performs memory allocation of the device structure.
device | - Pointer to location of device structure to write. |
init_param | - Pointer to configuration of the driver. |
int32_t ad7606_read_samples | ( | struct ad7606_dev * | dev, |
uint32_t * | data, | ||
uint32_t | samples | ||
) |
Read muliple raw samples from device.
This function performs a series of conversion starts and then proceeds to reading the conversion data (after each conversion).
dev | - The device structure. |
data | - Pointer to location of buffer where to store the data. |
samples | - Number of samples to read |
int32_t ad7606_reg_read | ( | struct ad7606_dev * | dev, |
uint8_t | reg_addr, | ||
uint8_t * | reg_data | ||
) |
Write a device register via SPI or AXI Parallel core.
The behavior of this function varies slightly depending on whether the operation is done via SPI or AXI core.
dev | - The device structure. |
reg_addr | - Register address in device memory. |
reg_data | - Value to write to register. |
int32_t ad7606_reg_write | ( | struct ad7606_dev * | dev, |
uint8_t | reg_addr, | ||
uint8_t | reg_data | ||
) |
Write a device register via SPI or AXI Parallel core.
The behavior of this function varies slightly depending on whether the operation is done via SPI or AXI core.
dev | - The device structure. |
reg_addr | - Register address in device memory. |
reg_data | - Value to write to register. |
int32_t ad7606_reg_write_mask | ( | struct ad7606_dev * | dev, |
uint32_t | addr, | ||
uint32_t | mask, | ||
uint32_t | val | ||
) |
Write a device register via SPI with masking.
dev | - The device structure. |
addr | - Register address in device memory. |
mask | - Only bits set to 1 in mask will be modified. |
val | - Value to write to register. |
int32_t ad7606_remove | ( | struct ad7606_dev * | dev | ) |
Free any resource used by the driver.
dev | - The device structure. |
int32_t ad7606_reset | ( | struct ad7606_dev * | dev | ) |
Reset the device by toggling the reset GPIO.
dev | - The device structure. |
int32_t ad7606_set_ch_gain | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
uint8_t | gain | ||
) |
Set the channel gain.
dev | - The device structure. |
ch | - Channel number (0-7). |
gain | - Gain calibration amount. |
int32_t ad7606_set_ch_offset | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
int8_t | offset | ||
) |
Set the channel offset.
The offset parameter is a signed 8-bit integer ranging from -128 to 127 to make it intuitive and user-friendly.
This offset gets converted to the register representation where 0x80 is calibration offset 0, 0x0 is calibration offset -128 and 0xFF is calibration offset 127, etc.
dev | - The device structure. |
ch | - Channel number (0-7). |
offset | - Offset calibration amount (-128...127). |
int32_t ad7606_set_ch_phase | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
uint8_t | phase | ||
) |
Set the channel phase.
dev | - The device structure. |
ch | - Channel number (0-7). |
phase | - Phase calibration amount. |
int32_t ad7606_set_ch_range | ( | struct ad7606_dev * | dev, |
uint8_t | ch, | ||
struct ad7606_range | range | ||
) |
Set the channel operation range.
dev | - The device structure. |
ch | - Channel number (0-7). |
range | - Operation range. |
int32_t ad7606_set_config | ( | struct ad7606_dev * | dev, |
struct ad7606_config | config | ||
) |
Set the device config register.
Configuration structure affects the CONFIG register of the device.
dev | - The device structure. |
config | - Configuration structure. |
int32_t ad7606_set_digital_diag | ( | struct ad7606_dev * | dev, |
struct ad7606_digital_diag | diag | ||
) |
Set the device digital diagnostics configuration.
Digital diagnostics structure affects the DIGITAL_DIAG register of the device.
dev | - The device structure. |
diag | - Configuration structure. |
int32_t ad7606_set_oversampling | ( | struct ad7606_dev * | dev, |
struct ad7606_oversampling | oversampling | ||
) |
Set the oversampling ratio.
In hardware mode, it silently sets AD7606_OSR_64 if higher oversampling is provided.
dev | - The device structure. |
oversampling | - Oversampling settings. |
int32_t ad7606_spi_data_read | ( | struct ad7606_dev * | dev, |
uint32_t * | data | ||
) |
Read conversion data.
This function performs CRC16 computation and checking if enabled in the device. If the status is enabled in device settings, each sample of data will contain status information in the lowest 8 bits.
The output buffer provided by the user should be as wide as to be able to contain 1 sample from each channel since this function reads conversion data across all channels.
dev | - The device structure. |
data | - Pointer to location of buffer where to store the data. |
bool ad7606_sw_mode_enabled | ( | struct ad7606_dev * | dev | ) |
Returns true if SW mode is enabled.
dev | - The device structure. |
NO_OS_DECLARE_CRC16_TABLE | ( | ad7606_crc16 | ) |
NO_OS_DECLARE_CRC8_TABLE | ( | ad7606_crc8 | ) |