no-OS
Macros | Functions
ad7124.c File Reference

AD7124 implementation file. Devices: AD7124-4, AD7124-8. More...

#include <stdlib.h>
#include <stdbool.h>
#include "ad7124.h"
#include "no_os_delay.h"
#include "no_os_alloc.h"
#include "no_os_error.h"
Include dependency graph for ad7124.c:

Macros

#define AD7124_POST_RESET_DELAY   4
 

Functions

int32_t ad7124_no_check_read_register (struct ad7124_dev *dev, struct ad7124_st_reg *p_reg)
 Reads the value of the specified register without checking if the device is ready to accept user requests. More...
 
int32_t ad7124_no_check_write_register (struct ad7124_dev *dev, struct ad7124_st_reg reg)
 Writes the value of the specified register without checking if the device is ready to accept user requests. More...
 
int32_t ad7124_read_register (struct ad7124_dev *dev, struct ad7124_st_reg *p_reg)
 Reads the value of the specified register only when the device is ready to accept user requests. If the device ready flag is deactivated the read operation will be executed without checking the device state. DEPRECATED, use ad7124_read_register2. More...
 
int32_t ad7124_read_register2 (struct ad7124_dev *dev, uint32_t reg, uint32_t *readval)
 Wrap the read register function to give it a modern signature. More...
 
int32_t ad7124_write_register (struct ad7124_dev *dev, struct ad7124_st_reg p_reg)
 Writes the value of the specified register only when the device is ready to accept user requests. If the device ready flag is deactivated the write operation will be executed without checking the device state. DEPRECATED, use ad7124_write_register2. More...
 
int32_t ad7124_write_register2 (struct ad7124_dev *dev, uint32_t reg, uint32_t writeval)
 Wrap the write register function to give it a modern signature. More...
 
int32_t ad7124_reset (struct ad7124_dev *dev)
 Resets the device. More...
 
int32_t ad7124_wait_for_spi_ready (struct ad7124_dev *dev, uint32_t timeout)
 Waits until the device can accept read and write user actions. More...
 
int32_t ad7124_wait_to_power_on (struct ad7124_dev *dev, uint32_t timeout)
 Waits until the device finishes the power-on reset operation. More...
 
int32_t ad7124_wait_for_conv_ready (struct ad7124_dev *dev, uint32_t timeout)
 Waits until a new conversion result is available. More...
 
int32_t ad7124_read_data (struct ad7124_dev *dev, int32_t *p_data)
 Reads the conversion result from the device. More...
 
int32_t ad7124_get_read_chan_id (struct ad7124_dev *dev, uint32_t *status)
 Get the ID of the channel of the latest conversion. More...
 
uint8_t ad7124_compute_crc8 (uint8_t *p_buf, uint8_t buf_size)
 Computes the CRC checksum for a data buffer. More...
 
void ad7124_update_crcsetting (struct ad7124_dev *dev)
 Updates the CRC settings. More...
 
void ad7124_update_dev_spi_settings (struct ad7124_dev *dev)
 Updates the device SPI interface settings. More...
 
int32_t ad7124_fclk_get (struct ad7124_dev *dev, float *f_clk)
 Get the AD7124 reference clock. More...
 
int32_t ad7124_fltcoff_get (struct ad7124_dev *dev, int16_t chn_num, uint16_t *flt_coff)
 Get the filter coefficient for the sample rate. More...
 
float ad7124_get_odr (struct ad7124_dev *dev, int16_t chn_num)
 Calculate ODR of the device. More...
 
int32_t ad7124_set_odr (struct ad7124_dev *dev, float odr, int16_t chn_num)
 Set ODR of the device. More...
 
int ad7124_reg_write_msk (struct ad7124_dev *dev, uint32_t reg_addr, uint32_t data, uint32_t mask)
 
  • SPI internal register write to device using a mask.
More...
 
int ad7124_set_adc_mode (struct ad7124_dev *device, enum ad7124_mode adc_mode)
 Set ADC Mode. More...
 
int ad7124_set_channel_status (struct ad7124_dev *device, uint8_t chn_num, bool channel_status)
 
int ad7124_connect_analog_input (struct ad7124_dev *device, uint8_t chn_num, struct ad7124_analog_inputs analog_input)
 Set Analog Inputs to channel. More...
 
int ad7124_assign_setup (struct ad7124_dev *device, uint8_t chn_num, uint8_t setup)
 Assign Setup to Channel. More...
 
int ad7124_set_polarity (struct ad7124_dev *device, bool bipolar, uint8_t setup_id)
 Set Polarity. More...
 
int ad7124_set_reference_source (struct ad7124_dev *device, enum ad7124_reference_source ref_source, uint8_t setup_id, bool ref_en)
 
int ad7124_enable_buffers (struct ad7124_dev *device, bool inbuf_en, bool refbuf_en, uint8_t setup_id)
 Enable Input Buffer. More...
 
int ad7124_set_power_mode (struct ad7124_dev *device, enum ad7124_power_mode mode)
 Select the Power Mode. More...
 
int32_t ad7124_setup (struct ad7124_dev **device, struct ad7124_init_param *init_param)
 Initializes the AD7124. More...
 
int32_t ad7124_remove (struct ad7124_dev *dev)
 Free the resources allocated by ad7124_setup(). More...
 

Detailed Description

AD7124 implementation file. Devices: AD7124-4, AD7124-8.

Copyright 2015-2019, 2023(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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of Analog Devices, Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

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.

Macro Definition Documentation

◆ AD7124_POST_RESET_DELAY

#define AD7124_POST_RESET_DELAY   4

Function Documentation

◆ ad7124_assign_setup()

int ad7124_assign_setup ( struct ad7124_dev device,
uint8_t  chn_num,
uint8_t  setup 
)

Assign Setup to Channel.

Parameters
device- AD7124 Device Descriptor.
chn_num- Channel ID (number).
setup- Setup ID (number).
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_compute_crc8()

uint8_t ad7124_compute_crc8 ( uint8_t *  p_buf,
uint8_t  buf_size 
)

Computes the CRC checksum for a data buffer.

Parameters
p_buf- Data buffer
buf_size- Data buffer size in bytes
Returns
Returns the computed CRC checksum.
Here is the caller graph for this function:

◆ ad7124_connect_analog_input()

int ad7124_connect_analog_input ( struct ad7124_dev device,
uint8_t  chn_num,
struct ad7124_analog_inputs  analog_input 
)

Set Analog Inputs to channel.

Parameters
device- AD7124 Device Descriptor.
chn_num- Channel whose Analog input is to be configured.
analog_input- Analog Inputs to the Channel.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_enable_buffers()

int ad7124_enable_buffers ( struct ad7124_dev device,
bool  inbuf_en,
bool  refbuf_en,
uint8_t  setup_id 
)

Enable Input Buffer.

Parameters
device- AD7124 Device Descriptor.
inbuf_en- Enable Input Buffer.
refbuf_en- Enable reference Buffer.
setup_id- Setup ID (Number).
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_fclk_get()

int32_t ad7124_fclk_get ( struct ad7124_dev dev,
float *  f_clk 
)

Get the AD7124 reference clock.

Parameters
[in]dev- Pointer to the application handler.
[out]f_clk- Pointer to the clock frequency container.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_fltcoff_get()

int32_t ad7124_fltcoff_get ( struct ad7124_dev dev,
int16_t  chn_num,
uint16_t *  flt_coff 
)

Get the filter coefficient for the sample rate.

Parameters
[in]dev- Pointer to the application handler.
[in]chn_num- Channel number.
[out]flt_coff- Pointer to the filter coefficient container.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_get_odr()

float ad7124_get_odr ( struct ad7124_dev dev,
int16_t  chn_num 
)

Calculate ODR of the device.

Parameters
[in]dev- Pointer to the application handler.
[in]chn_num- Channel number.
Returns
Output data rate in case of success, negative error code otherwise.

◆ ad7124_get_read_chan_id()

int32_t ad7124_get_read_chan_id ( struct ad7124_dev dev,
uint32_t *  status 
)

Get the ID of the channel of the latest conversion.

Parameters
dev- The handler of the instance of the driver.
status- Pointer to store the read data.
Returns
Returns 0 for success or negative error code otherwise.

◆ ad7124_no_check_read_register()

int32_t ad7124_no_check_read_register ( struct ad7124_dev dev,
struct ad7124_st_reg p_reg 
)

Reads the value of the specified register without checking if the device is ready to accept user requests.

Parameters
dev- The handler of the instance of the driver.
p_reg- Pointer to the register structure holding info about the register to be read. The read value is stored inside the register structure.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_no_check_write_register()

int32_t ad7124_no_check_write_register ( struct ad7124_dev dev,
struct ad7124_st_reg  reg 
)

Writes the value of the specified register without checking if the device is ready to accept user requests.

Parameters
dev- The handler of the instance of the driver.
reg- Register structure holding info about the register to be written
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_read_data()

int32_t ad7124_read_data ( struct ad7124_dev dev,
int32_t *  p_data 
)

Reads the conversion result from the device.

Parameters
dev- The handler of the instance of the driver.
p_data- Pointer to store the read data.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_read_register()

int32_t ad7124_read_register ( struct ad7124_dev dev,
struct ad7124_st_reg p_reg 
)

Reads the value of the specified register only when the device is ready to accept user requests. If the device ready flag is deactivated the read operation will be executed without checking the device state. DEPRECATED, use ad7124_read_register2.

Parameters
dev- The handler of the instance of the driver.
p_reg- Pointer to the register structure holding info about the register to be read. The read value is stored inside the register structure.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_read_register2()

int32_t ad7124_read_register2 ( struct ad7124_dev dev,
uint32_t  reg,
uint32_t *  readval 
)

Wrap the read register function to give it a modern signature.

Parameters
[in]dev- Driver handler pointer.
[in]reg- Address of the register to be read.
[out]readval- Pointer to the register value.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_reg_write_msk()

int ad7124_reg_write_msk ( struct ad7124_dev dev,
uint32_t  reg_addr,
uint32_t  data,
uint32_t  mask 
)

  • SPI internal register write to device using a mask.

Parameters
dev- The device structure.
reg_addr- The register address.
data- The register data.
mask- The mask.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_remove()

int32_t ad7124_remove ( struct ad7124_dev dev)

Free the resources allocated by ad7124_setup().

Parameters
dev- The device structure.
Returns
Returns 0 for success or negative error code otherwise.

◆ ad7124_reset()

int32_t ad7124_reset ( struct ad7124_dev dev)

Resets the device.

Parameters
dev- The handler of the instance of the driver.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_set_adc_mode()

int ad7124_set_adc_mode ( struct ad7124_dev device,
enum ad7124_mode  adc_mode 
)

Set ADC Mode.

Parameters
device- AD7124 Device Descriptor
adc_mode- ADC Mode to be configured
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_set_channel_status()

int ad7124_set_channel_status ( struct ad7124_dev device,
uint8_t  chn_num,
bool  channel_status 
)

Enable/disable channel.

Parameters
device- The device structure.
chn_num- The channel number.
channel_status- Channel status.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_set_odr()

int32_t ad7124_set_odr ( struct ad7124_dev dev,
float  odr,
int16_t  chn_num 
)

Set ODR of the device.

Parameters
[in]dev- Pointer to the application handler.
[in]odr- New ODR of the device.
[in]chn_num- Channel number.
Returns
Returns 0 for success or negative error code otherwise.

◆ ad7124_set_polarity()

int ad7124_set_polarity ( struct ad7124_dev device,
bool  bipolar,
uint8_t  setup_id 
)

Set Polarity.

Parameters
device- AD7124 Device Descriptor.
bipolar- Polarity Select:True in case of Bipolar, False in case of Unipolar.
setup_id- Setup ID (number).
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_set_power_mode()

int ad7124_set_power_mode ( struct ad7124_dev device,
enum ad7124_power_mode  mode 
)

Select the Power Mode.

Parameters
device- AD7124 Device Descriptor.
mode- ADC Power Mode.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_set_reference_source()

int ad7124_set_reference_source ( struct ad7124_dev device,
enum ad7124_reference_source  ref_source,
uint8_t  setup_id,
bool  ref_en 
)
Here is the caller graph for this function:

◆ ad7124_setup()

int32_t ad7124_setup ( struct ad7124_dev **  device,
struct ad7124_init_param init_param 
)

Initializes the AD7124.

Parameters
device- The device structure.
init_param- The structure that contains the device initial parameters.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_update_crcsetting()

void ad7124_update_crcsetting ( struct ad7124_dev dev)

Updates the CRC settings.

Parameters
dev- The handler of the instance of the driver.
Returns
None.
Here is the caller graph for this function:

◆ ad7124_update_dev_spi_settings()

void ad7124_update_dev_spi_settings ( struct ad7124_dev dev)

Updates the device SPI interface settings.

Parameters
dev- The handler of the instance of the driver.
Returns
None.
Here is the caller graph for this function:

◆ ad7124_wait_for_conv_ready()

int32_t ad7124_wait_for_conv_ready ( struct ad7124_dev dev,
uint32_t  timeout 
)

Waits until a new conversion result is available.

Parameters
dev- The handler of the instance of the driver.
timeout- Count representing the number of polls to be done until the function returns if no new data is available.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_wait_for_spi_ready()

int32_t ad7124_wait_for_spi_ready ( struct ad7124_dev dev,
uint32_t  timeout 
)

Waits until the device can accept read and write user actions.

Parameters
dev- The handler of the instance of the driver.
timeout- Count representing the number of polls to be done until the function returns.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_wait_to_power_on()

int32_t ad7124_wait_to_power_on ( struct ad7124_dev dev,
uint32_t  timeout 
)

Waits until the device finishes the power-on reset operation.

Parameters
dev- The handler of the instance of the driver.
timeout- Count representing the number of polls to be done until the function returns.
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_write_register()

int32_t ad7124_write_register ( struct ad7124_dev dev,
struct ad7124_st_reg  p_reg 
)

Writes the value of the specified register only when the device is ready to accept user requests. If the device ready flag is deactivated the write operation will be executed without checking the device state. DEPRECATED, use ad7124_write_register2.

Parameters
dev- The handler of the instance of the driver.
p_reg- Register structure holding info about the register to be written
Returns
Returns 0 for success or negative error code otherwise.
Here is the caller graph for this function:

◆ ad7124_write_register2()

int32_t ad7124_write_register2 ( struct ad7124_dev dev,
uint32_t  reg,
uint32_t  writeval 
)

Wrap the write register function to give it a modern signature.

Parameters
[in]dev- Driver handler pointer.
[in]reg- Address of the register to be read.
[in]writeval- New value for the register.
Returns
0 in case of success, error code otherwise.
Here is the caller graph for this function: