Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion test/vsf_test_suite/hal/driver/adc/suite/vsf_test_adc_oneshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ const struct vsf_test_adc_oneshot_s {

/*============================ LOCAL VARIABLES ===============================*/

static volatile bool __adc_oneshot_completed = false;

/*============================ IMPLEMENTATION ================================*/

static void __adc_oneshot_isr(void *target_ptr, vsf_adc_t *adc_ptr,
vsf_adc_irq_mask_t irq_mask)
{
VSF_UNUSED_PARAM(target_ptr);
VSF_UNUSED_PARAM(adc_ptr);
if (irq_mask & VSF_ADC_IRQ_MASK_CPL) {
__adc_oneshot_completed = true;
}
}

void vsf_test_adc_oneshot_run(const vsf_test_suite_t *suite, const vsf_test_case_t *tc, const vsf_test_inst_t *inst)
{
vsf_test_adc_oneshot_params_t *p = tc->params;
Expand Down Expand Up @@ -69,7 +81,11 @@ void vsf_test_adc_oneshot_run(const vsf_test_suite_t *suite, const vsf_test_case
VSF_TEST_TRACE_DEBUG("adc_oneshot:vsf_adc_init" VSF_TRACE_CFG_LINEEND);
vsf_adc_cfg_t cfg = {
.mode = VSF_TEST_ADC_ONESHOT_MODE,
.isr = {NULL, NULL, 0},
.isr = {
.handler_fn = __adc_oneshot_isr,
.target_ptr = NULL,
.prio = VSF_TEST_ADC_ONESHOT_PRIO,
},
.clock_hz = VSF_TEST_ADC_CLOCK_HZ,
};
vsf_err_t err = vsf_adc_init(adc, &cfg);
Expand All @@ -91,11 +107,23 @@ void vsf_test_adc_oneshot_run(const vsf_test_suite_t *suite, const vsf_test_case
.sample_cycles = VSF_TEST_ADC_ONESHOT_SAMPLE_CYCLES,
};
uint16_t sample = 0;
__adc_oneshot_completed = false;
err = vsf_adc_channel_request_once(adc, &ch_cfg, &sample);
VSF_TEST_ASSERT_ERR_NONE(err,
"adc_oneshot:vsf_adc_channel_request_once failed (err=%d) (ch=%u)"
VSF_TRACE_CFG_LINEEND, (int)err, (unsigned)ch_cfg.channel);

// vsf_adc_channel_request_once is asynchronous: wait for the conversion-complete
// interrupt (VSF_ADC_IRQ_MASK_CPL) before reading the result.
VSF_TEST_TRACE_DEBUG("adc_oneshot:waiting for completion" VSF_TRACE_CFG_LINEEND);
VSF_TEST_WAIT_FOR(__adc_oneshot_completed, VSF_TEST_ADC_ONESHOT_TIMEOUT_MS);
if (!__adc_oneshot_completed) {
VSF_TEST_TRACE_ERROR("adc_oneshot:conversion timeout after %u ms"
VSF_TRACE_CFG_LINEEND,
(unsigned)VSF_TEST_ADC_ONESHOT_TIMEOUT_MS);
}
VSF_TEST_ASSERT(__adc_oneshot_completed);

// Result must be within 12-bit range
if (sample > VSF_TEST_ADC_ONESHOT_MAX_SAMPLE) {
VSF_TEST_TRACE_ERROR("adc_oneshot:sample out of range (sample=0x%03x max=0x%03x)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
# define VSF_TEST_ADC_ONESHOT_SAMPLE_CYCLES 0
#endif

#ifndef VSF_TEST_ADC_ONESHOT_PRIO
# define VSF_TEST_ADC_ONESHOT_PRIO vsf_arch_prio_1
#endif

#ifndef VSF_TEST_ADC_ONESHOT_TIMEOUT_MS
# define VSF_TEST_ADC_ONESHOT_TIMEOUT_MS 500
#endif


#ifndef VSF_TEST_ADC_CLOCK_HZ
# define VSF_TEST_ADC_CLOCK_HZ 48000000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ const struct vsf_test_adc_temperature_s {

/*============================ LOCAL VARIABLES ===============================*/

static volatile bool __adc_temperature_completed = false;

/*============================ IMPLEMENTATION ================================*/

static void __adc_temperature_isr(void *target_ptr, vsf_adc_t *adc_ptr,
vsf_adc_irq_mask_t irq_mask)
{
VSF_UNUSED_PARAM(target_ptr);
VSF_UNUSED_PARAM(adc_ptr);
if (irq_mask & VSF_ADC_IRQ_MASK_CPL) {
__adc_temperature_completed = true;
}
}

void vsf_test_adc_temperature_run(const vsf_test_suite_t *suite, const vsf_test_case_t *tc, const vsf_test_inst_t *inst)
{
vsf_test_adc_temperature_params_t *p = tc->params;
Expand All @@ -62,7 +74,11 @@ void vsf_test_adc_temperature_run(const vsf_test_suite_t *suite, const vsf_test_
VSF_TEST_TRACE_DEBUG("adc_temperature:vsf_adc_init" VSF_TRACE_CFG_LINEEND);
vsf_adc_cfg_t cfg = {
.mode = VSF_TEST_ADC_TEMPERATURE_MODE,
.isr = {NULL, NULL, 0},
.isr = {
.handler_fn = __adc_temperature_isr,
.target_ptr = NULL,
.prio = VSF_TEST_ADC_TEMPERATURE_PRIO,
},
.clock_hz = VSF_TEST_ADC_CLOCK_HZ,
};
vsf_err_t err = vsf_adc_init(adc, &cfg);
Expand All @@ -83,11 +99,23 @@ void vsf_test_adc_temperature_run(const vsf_test_suite_t *suite, const vsf_test_
.sample_cycles = VSF_TEST_ADC_TEMPERATURE_SAMPLE_CYCLES,
};
uint16_t sample = 0;
__adc_temperature_completed = false;
err = vsf_adc_channel_request_once(adc, &ch_cfg, &sample);
VSF_TEST_ASSERT_ERR_NONE(err,
"adc_temperature:vsf_adc_channel_request_once failed (err=%d) (ch=%u)"
VSF_TRACE_CFG_LINEEND, (int)err, (unsigned)ch_cfg.channel);

// vsf_adc_channel_request_once is asynchronous: wait for the conversion-complete
// interrupt (VSF_ADC_IRQ_MASK_CPL) before reading the result.
VSF_TEST_TRACE_DEBUG("adc_temperature:waiting for completion" VSF_TRACE_CFG_LINEEND);
VSF_TEST_WAIT_FOR(__adc_temperature_completed, VSF_TEST_ADC_TEMPERATURE_TIMEOUT_MS);
if (!__adc_temperature_completed) {
VSF_TEST_TRACE_ERROR("adc_temperature:conversion timeout after %u ms"
VSF_TRACE_CFG_LINEEND,
(unsigned)VSF_TEST_ADC_TEMPERATURE_TIMEOUT_MS);
}
VSF_TEST_ASSERT(__adc_temperature_completed);

/* Verify raw value is within 12-bit range. Temperature varies by
* environment and VREF tolerance, so no tight bounds. */
if (sample > VSF_TEST_ADC_TEMPERATURE_MAX_SAMPLE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@
# define VSF_TEST_ADC_TEMPERATURE_SAMPLE_CYCLES 0
#endif

#ifndef VSF_TEST_ADC_TEMPERATURE_PRIO
# define VSF_TEST_ADC_TEMPERATURE_PRIO vsf_arch_prio_1
#endif

#ifndef VSF_TEST_ADC_TEMPERATURE_TIMEOUT_MS
# define VSF_TEST_ADC_TEMPERATURE_TIMEOUT_MS 500
#endif


#ifndef VSF_TEST_ADC_CLOCK_HZ
# define VSF_TEST_ADC_CLOCK_HZ 48000000
Expand Down
Loading