SAM TCC Unit test.
Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.
#include <asf.h>
#include <stdio_serial.h>
#include <string.h>
#include "conf_test.h"
#include "conf_clocks.h"
Functions | |
static void | cdc_uart_init (void) |
Initialize the USART for unit test. More... | |
int | main (void) |
Run TCC unit tests. More... | |
static void | run_basic_functionality_test (const struct test_case *test) |
Test basic functionality. More... | |
static void | run_callback_test (const struct test_case *test) |
Test the callback API. More... | |
static void | run_capture_and_compare_test (const struct test_case *test) |
Test capture and compare. More... | |
static void | run_faultn_test (const struct test_case *test) |
Test Recoverable Fault (FAULTn) More... | |
static void | run_faultx_test (const struct test_case *test) |
Test Non-Recoverable Fault (FAULTx) More... | |
static void | run_init_test (const struct test_case *test) |
Test of tcc_init() and tcc_get_config_defaults() More... | |
static void | run_reset_test (const struct test_case *test) |
Test initializing and resetting TCC and reinitialize. More... | |
static void | tcc_callback_function (struct tcc_module *const module_inst) |
Function used to test callback API. More... | |
Variables | |
static volatile bool | basic_functionality_test_passed = false |
static volatile uint32_t | callback_function_entered = 0 |
static struct usart_module | cdc_uart_module |
static bool | tcc_init_success = 0 |
static struct tcc_config | tcc_test0_config |
static struct tcc_module | tcc_test0_module |
static struct tcc_config | tcc_test1_config |
static struct tcc_module | tcc_test1_module |
|
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, 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().
int main | ( | void | ) |
Run TCC unit tests.
Initializes the system and serial output, then sets up the TCC unit test suite and runs it.
References cdc_uart_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_basic_functionality_test(), run_callback_test(), run_capture_and_compare_test(), run_faultn_test(), run_faultx_test(), run_init_test(), run_reset_test(), system_init(), tcc_reset(), tcc_test0_module, tcc_test1_module, and test_suite_run().
|
static |
Test basic functionality.
This test tests the basic functionality for the TCC. It tests the following functions:
test | Current test case. |
References basic_functionality_test_passed, tcc_enable(), tcc_get_config_defaults(), tcc_get_count_value(), tcc_init(), tcc_init_success, tcc_reset(), tcc_restart_counter(), tcc_set_count_value(), tcc_stop_counter(), tcc_test0_config, tcc_test0_module, and test_assert_true.
Referenced by main().
|
static |
Test the callback API.
This test tests the callback API for the TCC. The TCC uses one-shot mode.
test | Current test case. |
References basic_functionality_test_passed, callback_function_entered, tcc_config::compare, tcc_config::counter, tcc_match_wave_config::match, tcc_counter_config::period, tcc_callback_function(), tcc_clear_status(), tcc_disable(), tcc_disable_callback(), tcc_enable(), tcc_enable_callback(), tcc_get_config_defaults(), tcc_get_status(), tcc_init(), tcc_init_success, tcc_register_callback(), tcc_reset(), tcc_set_count_value(), TCC_STATUS_COUNT_OVERFLOW, tcc_test0_config, tcc_test0_module, TCC_WAVE_GENERATION_NORMAL_FREQ, test_assert_true, and tcc_match_wave_config::wave_generation.
Referenced by main().
|
static |
Test capture and compare.
This test uses TCC0 as a PWM generator (compare function). TCC1 will be set to capture the signal from TCC0 to test the capture functionality.
test | Current test case. |
References callback_function_entered, tcc_config::capture, tcc_capture_config::channel_function, tcc_counter_config::clock_prescaler, tcc_config::compare, tcc_config::counter, extint_chan_conf::detection_criteria, events_config::edge_detect, tcc_pins_config::enable_wave_out_pin, events_allocate(), events_attach_user(), EVENTS_EDGE_DETECT_NONE, events_get_config_defaults(), EVENTS_PATH_ASYNCHRONOUS, extint_chan_set_config(), EXTINT_DETECT_HIGH, extint_enable_events(), EXTINT_PULL_UP, extint_chan_conf::filter_input_signal, extint_events::generate_event_on_detect, events_config::generator, extint_chan_conf::gpio_pin, extint_chan_conf::gpio_pin_mux, extint_chan_conf::gpio_pin_pull, tcc_match_wave_config::match, tcc_events::on_input_event_perform_action, events_config::path, tcc_counter_config::period, tcc_config::pins, system_clock_source_get_hz(), tcc_callback_function(), TCC_CHANNEL_FUNCTION_CAPTURE, TCC_CLOCK_PRESCALER_DIV1, tcc_enable(), tcc_enable_callback(), tcc_enable_events(), TCC_EVENT_ACTION_PERIOD_PULSE_WIDTH_CAPTURE, tcc_get_capture_value(), tcc_get_config_defaults(), tcc_init(), tcc_init_success, tcc_register_callback(), tcc_reset(), tcc_test0_config, tcc_test0_module, tcc_test1_config, tcc_test1_module, TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM, test_assert_true, extint_chan_conf::wake_if_sleeping, tcc_match_wave_config::wave_generation, tcc_pins_config::wave_out_pin, and tcc_pins_config::wave_out_pin_mux.
Referenced by main().
|
static |
Test Recoverable Fault (FAULTn)
This test uses TCC0 as a PWM generator (compare function). EXTINT will be used to route fault input to TCC0.
test | Current test case. |
References tcc_config::compare, tcc_config::counter, extint_chan_conf::detection_criteria, port_config::direction, events_allocate(), events_attach_user(), events_get_config_defaults(), EVENTS_PATH_ASYNCHRONOUS, extint_chan_get_config_defaults(), extint_chan_set_config(), EXTINT_DETECT_BOTH, extint_enable_events(), extint_chan_conf::filter_input_signal, extint_events::generate_event_on_detect, events_config::generator, extint_chan_conf::gpio_pin, extint_chan_conf::gpio_pin_mux, tcc_recoverable_fault_config::halt_action, tcc_match_wave_config::match, tcc_events::on_event_perform_channel_action, events_config::path, tcc_counter_config::period, port_get_config_defaults(), PORT_PIN_DIR_OUTPUT, port_pin_set_config(), port_pin_set_output_level(), tcc_wave_extension_config::recoverable_fault, tcc_recoverable_fault_config::source, tcc_clear_status(), tcc_enable(), tcc_enable_events(), TCC_FAULT_HALT_ACTION_SW_HALT, TCC_FAULT_SOURCE_ENABLE, tcc_get_config_defaults(), tcc_get_count_value(), tcc_get_status(), tcc_init(), tcc_init_success, tcc_reset(), TCC_STATUS_RECOVERABLE_FAULT_OCCUR, TCC_STATUS_RECOVERABLE_FAULT_PRESENT, tcc_test0_config, tcc_test0_module, TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM, test_assert_true, tcc_config::wave_ext, and tcc_match_wave_config::wave_generation.
Referenced by main().
|
static |
Test Non-Recoverable Fault (FAULTx)
This test uses TCC0 as a PWM generator (compare function). EXTINT will be used to route fault input to TCC0.
test | Current test case. |
References tcc_input_event_config::action, tcc_config::compare, tcc_config::counter, extint_chan_conf::detection_criteria, port_config::direction, events_allocate(), events_attach_user(), events_get_config_defaults(), EVENTS_PATH_ASYNCHRONOUS, extint_chan_get_config_defaults(), extint_chan_set_config(), EXTINT_DETECT_BOTH, extint_enable_events(), extint_chan_conf::filter_input_signal, extint_events::generate_event_on_detect, events_config::generator, extint_chan_conf::gpio_pin, extint_chan_conf::gpio_pin_mux, tcc_events::input_config, tcc_match_wave_config::match, tcc_input_event_config::modify_action, tcc_wave_extension_config::non_recoverable_fault, tcc_events::on_input_event_perform_action, tcc_non_recoverable_fault_config::output, events_config::path, tcc_counter_config::period, port_get_config_defaults(), PORT_PIN_DIR_OUTPUT, port_pin_set_config(), port_pin_set_output_level(), tcc_clear_status(), tcc_enable(), tcc_enable_events(), TCC_EVENT_ACTION_NON_RECOVERABLE_FAULT, TCC_FAULT_STATE_OUTPUT_1, tcc_get_config_defaults(), tcc_get_count_value(), tcc_get_status(), tcc_init(), tcc_init_success, tcc_reset(), TCC_STATUS_NON_RECOVERABLE_FAULT_OCCUR, TCC_STATUS_NON_RECOVERABLE_FAULT_PRESENT, tcc_test0_config, tcc_test0_module, TCC_WAVE_GENERATION_SINGLE_SLOPE_PWM, test_assert_true, tcc_config::wave_ext, and tcc_match_wave_config::wave_generation.
Referenced by main().
|
static |
Test of tcc_init() and tcc_get_config_defaults()
This test is used to initialize the tccx_module structs and associate the given hw module with the struct. This test should be run at the very beginning of testing as other tests depend on the result of this test.
References STATUS_OK, tcc_get_config_defaults(), tcc_init(), tcc_init_success, tcc_test0_config, tcc_test0_module, tcc_test1_config, tcc_test1_module, and test_assert_true.
Referenced by main().
|
static |
Test initializing and resetting TCC and reinitialize.
This test tests the software reset of a TCC by the use of the tcc_reset().
test | Current test case. |
References tcc_module::hw, tcc_enable(), tcc_get_config_defaults(), tcc_init(), tcc_init_success, tcc_is_syncing(), tcc_reset(), tcc_test0_config, tcc_test0_module, test_assert_false, and test_assert_true.
Referenced by main().
|
static |
Function used to test callback API.
This function indicates that the callback function has been invoked.
References callback_function_entered.
Referenced by run_callback_test(), and run_capture_and_compare_test().
Referenced by run_basic_functionality_test(), and run_callback_test().
|
static |
Referenced by run_callback_test(), run_capture_and_compare_test(), and tcc_callback_function().
|
static |
|
static |
|
static |
|
static |
|
static |
Referenced by run_capture_and_compare_test(), and run_init_test().
|
static |
Referenced by main(), run_capture_and_compare_test(), and run_init_test().