SAM Analog Comparator (AC) Unit test.
Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.
Macros | |
#define | AC_SCALER_0_25_VOLT 4 |
#define | AC_SCALER_0_50_VOLT 9 |
#define | AC_SCALER_0_75_VOLT 14 |
#define | DAC_VAL_HALF_VOLT 512 |
#define | DAC_VAL_ONE_VOLT 1023 |
#define | DAC_VAL_ZERO_VOLT 0 |
Functions | |
static void | ac_user_callback (struct ac_module *const module_inst) |
AC callback function. More... | |
static void | cdc_uart_init (void) |
Initialize the USART for unit test. More... | |
static void | cleanup_ac_callback_mode_test (const struct test_case *test) |
Cleanup Function: AC callback mode test. More... | |
int | main (void) |
Run AC unit tests. More... | |
static void | run_ac_callback_mode_test (const struct test_case *test) |
AC callback mode test function. More... | |
static void | run_ac_init_test (const struct test_case *test) |
Test for AC initialization. More... | |
static void | run_ac_single_shot_test (const struct test_case *test) |
Test for AC comparison in single shot mode. More... | |
static void | run_ac_window_mode_test (const struct test_case *test) |
AC window mode test function. More... | |
static void | setup_ac_callback_mode_test (const struct test_case *test) |
Setup Function: AC callback mode test. More... | |
static void | setup_ac_window_mode_test (const struct test_case *test) |
Setup Function: AC window mode test. More... | |
static void | test_dac_init (void) |
Initialize the DAC for unit test. More... | |
Variables | |
volatile bool | ac_init_success = false |
struct ac_module | ac_inst |
struct usart_module | cdc_uart_module |
struct dac_module | dac_inst |
volatile bool | interrupt_flag = false |
#define AC_SCALER_0_25_VOLT 4 |
Referenced by setup_ac_window_mode_test().
#define AC_SCALER_0_50_VOLT 9 |
Referenced by run_ac_init_test(), and setup_ac_callback_mode_test().
#define AC_SCALER_0_75_VOLT 14 |
Referenced by setup_ac_window_mode_test().
#define DAC_VAL_HALF_VOLT 512 |
Referenced by run_ac_window_mode_test().
#define DAC_VAL_ONE_VOLT 1023 |
Referenced by run_ac_callback_mode_test(), run_ac_single_shot_test(), and run_ac_window_mode_test().
#define DAC_VAL_ZERO_VOLT 0 |
Referenced by run_ac_callback_mode_test(), run_ac_single_shot_test(), and run_ac_window_mode_test().
|
static |
AC callback function.
Called by AC driver on interrupt detection.
module | Pointer to the AC module (not used) |
References interrupt_flag.
Referenced by setup_ac_callback_mode_test().
|
static |
Initialize the USART for unit test.
Initializes the SERCOM USART 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, 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: AC callback mode test.
This function unregisters & disables callback for edge detection.
test | Current test case. |
References AC_CALLBACK_COMPARATOR_0, ac_disable_callback(), ac_inst, and ac_unregister_callback().
Referenced by main().
int main | ( | void | ) |
Run AC unit tests.
Initializes the system and serial output, then sets up the AC unit test suite and runs it.
References cdc_uart_init(), cleanup_ac_callback_mode_test(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, delay_init(), NULL, run_ac_callback_mode_test(), run_ac_init_test(), run_ac_single_shot_test(), run_ac_window_mode_test(), setup_ac_callback_mode_test(), setup_ac_window_mode_test(), system_init(), test_dac_init(), and test_suite_run().
|
static |
AC callback mode test function.
This test changes the positive input from 0V to 1V to detect the rising edge and again from 1V to 0V to detect the falling edge.
test | Current test case. |
References ac_init_success, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, interrupt_flag, and test_assert_true.
Referenced by main().
|
static |
Test for AC initialization.
This test initializes the AC module and checks whether the initialization is successful or not.
If this test fails no other tests will run.
test | Current test case. |
References AC_CHAN_CHANNEL_0, ac_chan_enable(), ac_chan_get_config_defaults(), AC_CHAN_MODE_SINGLE_SHOT, AC_CHAN_NEG_MUX_SCALED_VCC, AC_CHAN_POS_MUX_PIN0, ac_chan_set_config(), ac_enable(), ac_get_config_defaults(), ac_init(), ac_init_success, ac_inst, AC_SCALER_0_50_VOLT, system_pinmux_config::direction, system_pinmux_config::mux_position, ac_chan_config::negative_input, ac_chan_config::positive_input, ac_chan_config::sample_mode, STATUS_ERR_IO, STATUS_OK, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, system_pinmux_pin_set_config(), test_assert_true, and ac_chan_config::vcc_scale_factor.
Referenced by main().
|
static |
Test for AC comparison in single shot mode.
This test checks the single shot comparison of the AC. 0.5V is applied to the negative input of AC from internal voltage scaler. 0V and 1V from DAC is applied to the positive input and the results are verified.
test | Current test case. |
References AC_CHAN_CHANNEL_0, ac_chan_clear_status(), ac_chan_get_status(), ac_chan_is_ready(), AC_CHAN_STATUS_NEG_ABOVE_POS, AC_CHAN_STATUS_POS_ABOVE_NEG, AC_CHAN_STATUS_UNKNOWN, ac_chan_trigger_single_shot(), ac_init_success, ac_inst, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, state, and test_assert_true.
Referenced by main().
|
static |
AC window mode test function.
This test checks the window functionality of the AC module. Inputs are given in each region of the window (below, inside & above) and corresponding window output states are verified.
test | Current test case. |
References AC_CHAN_CHANNEL_0, AC_CHAN_CHANNEL_1, ac_chan_clear_status(), ac_chan_trigger_single_shot(), ac_init_success, ac_inst, AC_WIN_CHANNEL_0, ac_win_clear_status(), ac_win_get_status(), ac_win_is_ready(), AC_WIN_STATUS_ABOVE, AC_WIN_STATUS_BELOW, AC_WIN_STATUS_INSIDE, AC_WIN_STATUS_UNKNOWN, dac_chan_write(), DAC_CHANNEL_0, dac_inst, DAC_VAL_HALF_VOLT, DAC_VAL_ONE_VOLT, DAC_VAL_ZERO_VOLT, delay_ms, state, and test_assert_true.
Referenced by main().
|
static |
Setup Function: AC callback mode test.
This function initializes the AC to generate interrupt when the AC output toggles.
test | Current test case. |
References AC_CALLBACK_COMPARATOR_0, AC_CHAN_CHANNEL_0, ac_chan_enable(), ac_chan_get_config_defaults(), AC_CHAN_MODE_CONTINUOUS, AC_CHAN_NEG_MUX_SCALED_VCC, AC_CHAN_POS_MUX_PIN0, ac_chan_set_config(), ac_enable(), ac_enable_callback(), ac_get_config_defaults(), ac_init(), ac_init_success, ac_inst, ac_register_callback(), ac_reset(), AC_SCALER_0_50_VOLT, ac_user_callback(), system_pinmux_config::direction, system_pinmux_config::mux_position, ac_chan_config::negative_input, ac_chan_config::positive_input, ac_chan_config::sample_mode, STATUS_ERR_IO, STATUS_OK, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, system_pinmux_pin_set_config(), test_assert_true, and ac_chan_config::vcc_scale_factor.
Referenced by main().
|
static |
Setup Function: AC window mode test.
This function initializes the AC in window mode detection. 0.25V and 0.75V from internal voltage scaler are used as lower and upper limits of the window respectively.
test | Current test case. |
References AC_CHAN_CHANNEL_0, AC_CHAN_CHANNEL_1, ac_chan_enable(), ac_chan_get_config_defaults(), AC_CHAN_MODE_SINGLE_SHOT, AC_CHAN_NEG_MUX_SCALED_VCC, AC_CHAN_POS_MUX_PIN0, ac_chan_set_config(), ac_enable(), ac_get_config_defaults(), ac_init(), ac_init_success, ac_inst, ac_reset(), AC_SCALER_0_25_VOLT, AC_SCALER_0_75_VOLT, AC_WIN_CHANNEL_0, ac_win_enable(), ac_win_get_config_defaults(), ac_win_set_config(), system_pinmux_config::direction, system_pinmux_config::mux_position, ac_chan_config::negative_input, ac_chan_config::positive_input, ac_chan_config::sample_mode, STATUS_ERR_IO, STATUS_OK, system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, system_pinmux_pin_set_config(), test_assert_true, and ac_chan_config::vcc_scale_factor.
Referenced by main().
|
static |
Initialize the DAC for unit test.
Initializes the DAC module used for sending the analog values to the AC during test.
References dac_chan_enable(), dac_chan_get_config_defaults(), dac_chan_set_config(), DAC_CHANNEL_0, dac_enable(), dac_get_config_defaults(), dac_init(), and dac_inst.
Referenced by main().
struct ac_module ac_inst |
struct usart_module cdc_uart_module |
struct dac_module dac_inst |