SAM Analog to Digital Converter (ADC) Unit test.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | ADC_OFFSET 150 |
#define | ADC_SAMPLES 128 |
#define | ADC_VAL_DAC_FULL_OUTPUT 4095 |
#define | ADC_VAL_DAC_HALF_OUTPUT 2047 |
#define | DAC_VAL_HALF_VOLT 2047 |
#define | DAC_VAL_ONE_VOLT 4095 |
Functions | |
static void | adc_user_callback (struct adc_module *const module) |
ADC callback function. More... | |
static void | cdc_uart_init (void) |
Initialize the USART for unit test. More... | |
static void | cleanup_adc_callback_mode_test (const struct test_case *test) |
Cleanup Function: ADC callback mode test. More... | |
static void | cleanup_adc_window_mode_test (const struct test_case *test) |
Cleanup Function: ADC window mode test. More... | |
int | main (void) |
Run ADC unit tests. More... | |
static void | run_adc_average_mode_test (const struct test_case *test) |
ADC average mode test function. More... | |
static void | run_adc_callback_mode_test (const struct test_case *test) |
ADC callback mode test function. More... | |
static void | run_adc_init_test (const struct test_case *test) |
Test for ADC initialization. More... | |
static void | run_adc_polled_mode_test (const struct test_case *test) |
Test for ADC conversion in polled mode. More... | |
static void | run_adc_window_mode_test (const struct test_case *test) |
ADC window mode test function. More... | |
static void | setup_adc_average_mode_test (const struct test_case *test) |
Setup Function: ADC average mode test. More... | |
static void | setup_adc_callback_mode_test (const struct test_case *test) |
Setup Function: ADC callback mode test. More... | |
static void | setup_adc_window_mode_test (const struct test_case *test) |
Setup Function: ADC window mode test. More... | |
static void | test_dac_init (void) |
Initialize the DAC for unit test. More... | |
Variables | |
uint16_t | adc_buf [ADC_SAMPLES] |
volatile bool | adc_init_success = false |
struct adc_module | adc_inst |
struct usart_module | cdc_uart_module |
struct dac_module | dac_inst |
volatile bool | interrupt_flag = false |
#define ADC_OFFSET 150 |
#define ADC_SAMPLES 128 |
Referenced by cleanup_adc_callback_mode_test(), run_adc_callback_mode_test(), and setup_adc_callback_mode_test().
#define ADC_VAL_DAC_FULL_OUTPUT 4095 |
Referenced by run_adc_polled_mode_test().
#define ADC_VAL_DAC_HALF_OUTPUT 2047 |
#define DAC_VAL_HALF_VOLT 2047 |
#define DAC_VAL_ONE_VOLT 4095 |
Referenced by run_adc_polled_mode_test(), and run_adc_window_mode_test().
|
static |
ADC callback function.
Called by ADC driver on interrupt detection.
module | Pointer to the ADC module (not used) |
References interrupt_flag.
Referenced by setup_adc_callback_mode_test(), and setup_adc_window_mode_test().
|
static |
Initialize the USART for unit test.
Initializes the SERCOM USART (SERCOM4) used for sending the unit test status to the computer via the EDBG CDC gateway.
References usart_config::baudrate, cdc_uart_module, CONF_STDIO_BAUDRATE, CONF_STDIO_MUX_SETTING, CONF_STDIO_PINMUX_PAD0, CONF_STDIO_PINMUX_PAD1, CONF_STDIO_PINMUX_PAD2, CONF_STDIO_PINMUX_PAD3, CONF_STDIO_USART, usart_config::mux_setting, usart_config::pinmux_pad0, usart_config::pinmux_pad1, usart_config::pinmux_pad2, usart_config::pinmux_pad3, usart_enable(), and usart_get_config_defaults().
Referenced by main().
|
static |
Cleanup Function: ADC callback mode test.
This function clears the ADC result buffer and unregisters & disables callback for the ADC buffer read.
test | Current test case. |
References adc_buf, ADC_CALLBACK_READ_BUFFER, adc_disable_callback(), adc_inst, ADC_SAMPLES, and adc_unregister_callback().
Referenced by main().
|
static |
Cleanup Function: ADC window mode test.
This function unregisters & disables callback for window detection.
test | Current test case. |
References ADC_CALLBACK_WINDOW, adc_disable_callback(), adc_inst, and adc_unregister_callback().
Referenced by main().
int main | ( | void | ) |
Run ADC unit tests.
Initializes the system and serial output, then sets up the ADC unit test suite and runs it.
References cdc_uart_init(), cleanup_adc_callback_mode_test(), cleanup_adc_window_mode_test(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, delay_init(), run_adc_average_mode_test(), run_adc_callback_mode_test(), run_adc_init_test(), run_adc_polled_mode_test(), run_adc_window_mode_test(), setup_adc_average_mode_test(), setup_adc_callback_mode_test(), setup_adc_window_mode_test(), system_init(), test_dac_init(), and test_suite_run().
|
static |
ADC average mode test function.
This test performs the ADC averaging by starting a conversion. 0.5V is applied as input from DAC. Converted result is verified for expected results.
test | Current test case. |
References adc_inst, ADC_OFFSET, adc_read(), adc_start_conversion(), ADC_VAL_DAC_HALF_OUTPUT, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, delay_ms, STATUS_OK, and test_assert_true.
Referenced by main().
|
static |
ADC callback mode test function.
This test checks the callback functionality of the ADC driver. ADC callback for buffered conversion is enabled. Converted results are verified for expected results.
test | Current test case. |
References adc_buf, adc_inst, ADC_OFFSET, adc_read_buffer_job(), ADC_SAMPLES, ADC_VAL_DAC_HALF_OUTPUT, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, delay_ms, interrupt_flag, and test_assert_true.
Referenced by main().
|
static |
Test for ADC initialization.
This test initializes the ADC module and checks whether the initialization is successful or not.
If this test fails no other tests will run.
test | Current test case. |
References adc_enable(), adc_get_config_defaults(), adc_init(), adc_init_success, adc_inst, ADC_REFERENCE_INTREF, adc_config::clock_source, CONF_ADC_NEGATIVE_INPUT, CONF_ADC_POSITIVE_INPUT, GCLK_GENERATOR_3, adc_config::negative_input, adc_config::positive_input, adc_config::reference, STATUS_ERR_IO, STATUS_OK, and test_assert_true.
Referenced by main().
|
static |
Test for ADC conversion in polled mode.
This test checks the polled mode functionality of the ADC. 0.5V and 1V inputs are applied to the ADC via DAC and the ADC outputs are verified for expected results.
test | Current test case. |
References adc_flush(), adc_init_success, adc_inst, ADC_OFFSET, adc_read(), adc_start_conversion(), ADC_VAL_DAC_FULL_OUTPUT, ADC_VAL_DAC_HALF_OUTPUT, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, DAC_VAL_ONE_VOLT, delay_ms, STATUS_OK, and test_assert_true.
Referenced by main().
|
static |
ADC window mode test function.
This test gives an input voltage outside the window and checks whether the callback is triggered or not.
test | Current test case. |
References dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_ONE_VOLT, delay_ms, interrupt_flag, and test_assert_true.
Referenced by main().
|
static |
Setup Function: ADC average mode test.
This function initializes the ADC in averaging mode.
test | Current test case. |
References adc_disable(), adc_enable(), adc_get_config_defaults(), adc_init(), adc_init_success, adc_inst, ADC_REFERENCE_INTREF, adc_config::clock_source, CONF_ADC_NEGATIVE_INPUT, CONF_ADC_POSITIVE_INPUT, GCLK_GENERATOR_3, adc_config::negative_input, adc_config::positive_input, adc_config::reference, STATUS_ERR_IO, STATUS_OK, and test_assert_true.
Referenced by main().
|
static |
Setup Function: ADC callback mode test.
This function initializes the ADC result buffer and registers & enables callback for the ADC buffer read.
test | Current test case. |
References adc_buf, ADC_CALLBACK_READ_BUFFER, adc_enable_callback(), adc_init_success, adc_inst, adc_register_callback(), ADC_SAMPLES, adc_user_callback(), interrupt_flag, and test_assert_true.
Referenced by main().
|
static |
Setup Function: ADC window mode test.
This function initializes the ADC in window mode. Upper and lower threshold values are provided. It also registers & enables callback for window detection.
test | Current test case. |
References ADC_CALLBACK_WINDOW, ADC_CLOCK_PRESCALER_DIV16, adc_disable(), adc_enable(), adc_enable_callback(), adc_get_config_defaults(), adc_init(), adc_init_success, adc_inst, ADC_OFFSET, ADC_REFERENCE_INTREF, adc_register_callback(), ADC_RESOLUTION_12BIT, adc_start_conversion(), adc_user_callback(), ADC_VAL_DAC_HALF_OUTPUT, ADC_WINDOW_MODE_BETWEEN_INVERTED, adc_config::clock_prescaler, adc_config::clock_source, CONF_ADC_NEGATIVE_INPUT, CONF_ADC_POSITIVE_INPUT, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, delay_ms, adc_config::freerunning, GCLK_GENERATOR_3, interrupt_flag, adc_config::negative_input, adc_config::positive_input, adc_config::reference, adc_config::resolution, STATUS_ERR_IO, STATUS_OK, test_assert_true, adc_config::window, adc_window_config::window_lower_value, adc_window_config::window_mode, and adc_window_config::window_upper_value.
Referenced by main().
|
static |
Initialize the DAC for unit test.
Initializes the DAC module used for sending the analog values to the ADC during test.
References dac_config::clock_source, dac_chan_enable(), dac_chan_get_config_defaults(), dac_chan_set_config(), DAC_CHANNEL_0, dac_enable(), dac_get_config_defaults(), dac_init(), dac_inst, DAC_REFERENCE_INTREF, GCLK_GENERATOR_3, and dac_config::reference.
Referenced by main().
uint16_t adc_buf[ADC_SAMPLES] |
Referenced by cleanup_adc_callback_mode_test(), run_adc_callback_mode_test(), and setup_adc_callback_mode_test().
struct adc_module adc_inst |
struct usart_module cdc_uart_module |
Referenced by cdc_uart_init().
struct dac_module dac_inst |