Skip to content

Commit

Permalink
projects:ad405x_iio: Resolve build warnings
Browse files Browse the repository at this point in the history
1. Update the application files acccording to the Coverity report
2. Add ad4050 as a device and double the value of data in test scripts
3. Add delay before eeprom read

Signed-off-by: Anush Shetty <[email protected]>
  • Loading branch information
Shetty-Anush authored and SaikiranGudla committed Feb 5, 2025
1 parent dcd4271 commit c846e3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
25 changes: 19 additions & 6 deletions projects/ad405x_iio/app/ad405x_iio.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ad405x_iio.h"
#include "ad405x_user_config.h"
#include "common.h"
#include "no_os_delay.h"
#include "no_os_error.h"
#include "no_os_gpio.h"
#include "no_os_pwm.h"
Expand Down Expand Up @@ -219,8 +220,8 @@ static struct scan_type ad405x_iio_scan_type = {
static char *ad405x_op_mode_str[] = {
"config_mode",
"adc_mode",
"averaging_mode",
"burst_averaging_mode",
"averaging_mode"
};

/* Averaging filter length values string representation */
Expand Down Expand Up @@ -645,9 +646,10 @@ static int iio_ad405x_attr_set(void *device,
enum ad405x_avg_filter_l filter_len;
enum ad405x_sample_rate burst_rate;
uint32_t requested_sampling_period;
uint32_t requested_sampling_rate;
uint32_t cnv_time;
int32_t ret;
uint8_t value;
uint8_t value = 0;

switch (priv) {
case ADC_RAW:
Expand All @@ -659,7 +661,7 @@ static int iio_ad405x_attr_set(void *device,

case ADC_OPERATING_MODE :
for (op_mode = AD405X_CONFIG_MODE_OP;
op_mode <= AD405X_NON_PERSISTENT_AUTO_MODE_OP;
op_mode <= AD405X_BURST_AVERAGING_MODE_OP;
op_mode++) {
if (!strncmp(buf, ad405x_op_mode_str[op_mode], strlen(buf))) {
value = op_mode;
Expand Down Expand Up @@ -741,7 +743,11 @@ static int iio_ad405x_attr_set(void *device,
#endif

case ADC_SAMPLE_RATE:
requested_sampling_period = CONV_TRIGGER_PERIOD_NSEC(no_os_str_to_uint32(buf));
requested_sampling_rate = no_os_str_to_uint32(buf);
if (requested_sampling_rate == 0) {
return -EINVAL;
}
requested_sampling_period = CONV_TRIGGER_PERIOD_NSEC(requested_sampling_rate);

#if (ADC_CAPTURE_MODE == SAMPLE_MODE)
ad405x_sample_rate = no_os_str_to_uint32(buf);
Expand Down Expand Up @@ -798,7 +804,7 @@ static int iio_ad405x_attr_available_get(void *device,
"%s %s %s",
ad405x_op_mode_str[0],
ad405x_op_mode_str[1],
ad405x_op_mode_str[2]);
ad405x_op_mode_str[3]);

#if (ADC_CAPTURE_MODE != SAMPLE_MODE)
#if (ADC_CAPTURE_MODE == BURST_AVERAGING_MODE)
Expand Down Expand Up @@ -1161,7 +1167,7 @@ static int32_t iio_ad405x_submit_samples(struct iio_device_data *iio_dev_data)

ad405x_conversion_flag = false;

dma_cycle_count = ((nb_of_samples) / spirxdma_ndtr) + 1;
dma_cycle_count = ((nb_of_samples) / rxdma_ndtr) + 1;

/* Set the callback count to twice the number of DMA cycles */
callback_count = dma_cycle_count * 2;
Expand Down Expand Up @@ -1444,6 +1450,7 @@ static int32_t ad405x_iio_trigger_param_init(struct iio_hw_trig **desc)
/* Initialize hardware trigger */
ret = iio_hw_trig_init(&hw_trig_desc, &ad405x_hw_trig_init_params);
if (ret) {
no_os_free(hw_trig_desc);
return ret;
}

Expand Down Expand Up @@ -1492,6 +1499,10 @@ int32_t iio_ad405x_initialize(void)
}
};

no_os_udelay(
1000000); // Add a fixed delay of 1 sec before system init for the PoR sequence to get completed


init_status = init_system();
if (init_status) {
return init_status;
Expand All @@ -1503,6 +1514,8 @@ int32_t iio_ad405x_initialize(void)
"EVAL-AD4052-ARDZ"
};

no_os_udelay(1000000); // Add delay between the i2c init and the eeprom read

/* Iterate twice to detect the correct attached board */
for (indx = 0; indx < NO_OS_ARRAY_SIZE(mezzanine_names); indx++) {
init_status = get_iio_context_attributes(&iio_init_params.ctx_attrs,
Expand Down
1 change: 1 addition & 0 deletions projects/ad405x_iio/app/app_config_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -443,5 +443,6 @@ int stm32_abort_dma_transfer(void)
return ret;
}

return 0;
}
#endif
6 changes: 4 additions & 2 deletions projects/ad405x_iio/tests/func/test_ad405x_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from ad405x import * #TODO: Remove this later when driver is released to pyadi-iio


iio_device = { 'DEV_AD4052': 'ad4052' }
iio_device = { 'DEV_AD4050': 'ad4050',
'DEV_AD4052': 'ad4052' }
MAX_EXPECTED_VOLTAGE = 1.9
MIN_EXPECTED_VOLTAGE = 1.7

Expand Down Expand Up @@ -41,7 +42,8 @@ def test_ad405x(serial_port, device_name, target_reset):

# Extract the data of enabled channels in rx_enabled_channels
for sample_index in range(0, len(data)):
data[sample_index] = chn_data[ad405x_dev.rx_enabled_channels[0]]
# The eval board reports half of the actual input voltage
data[sample_index] = chn_data[ad405x_dev.rx_enabled_channels[0]] * 2
sample_index = sample_index + len(ad405x_dev.channel)


Expand Down

0 comments on commit c846e3d

Please sign in to comment.