Microchip® Advanced Software Framework

mega/drivers/usart/unit_tests/unit_tests.c File Reference

Unit tests for USART driver.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <asf.h>
#include <conf_test.h>

Functions

static uint32_t calculate_baudrate (uint32_t baud, uint32_t cpu_hz)
 
int main (void)
 Run USART unit tests. More...
 
static void run_baudrate_test (const struct test_case *test)
 Test setting different baud rates of the USART module. More...
 
static void run_check_registers_test (const struct test_case *test)
 Test checking different registers of the USART module. More...
 
static void run_loopback_syncmode_test (const struct test_case *test)
 Test physical loop-back with some characters in sunc mode. More...
 
static void run_loopback_test (const struct test_case *test)
 Test physical loop-back with some characters. More...
 
static void run_set_functions_test (const struct test_case *test)
 Test setting different parameters of the USART module. More...
 

static uint32_t calculate_baudrate ( uint32_t  baud,
uint32_t  cpu_hz 
)
static

References USART_U2X_bm.

Referenced by run_baudrate_test().

int main ( void  )

Run USART unit tests.

Main function.

Initializes the clock system, board and serial output, then sets up the USART unit test suite and runs it.

The SAM3X_EK, SAM3X Arduino board and SAM4C_EK use two bytes length internal address EEPROM.

References usart_rs232_options::baudrate, board_init(), DEFINE_TEST_ARRAY, DEFINE_TEST_CASE, DEFINE_TEST_SUITE, NULL, run_baudrate_test(), run_check_registers_test(), run_loopback_syncmode_test(), run_loopback_test(), run_set_functions_test(), stdio_serial_init(), sysclk_init(), test_suite_run(), and usart_serial_options.

static void run_baudrate_test ( const struct test_case test)
static

Test setting different baud rates of the USART module.

This function calls the set function and check that the correct baud-rate has been set in the register.

Parameters
testCurrent test case.

References calculate_baudrate(), success, sysclk_get_cpu_hz(), test_assert_true, and usart_set_baudrate().

Referenced by main().

static void run_check_registers_test ( const struct test_case test)
static

Test checking different registers of the USART module.

This function calls the different check functions and make sure they set the correct values.

Parameters
testCurrent test case.

References usart_rs232_options::baudrate, data, success, test_assert_true, usart_data_register_is_empty(), usart_get(), usart_init_rs232(), usart_put(), usart_rx_is_complete(), and usart_tx_is_complete().

Referenced by main().

static void run_loopback_syncmode_test ( const struct test_case test)
static

Test physical loop-back with some characters in sunc mode.

This function sends a character over USART on loop back to verify that init and sending/receiving works. A jumper is connected on the USART.

Parameters
testCurrent test case.

References ioport_configure_port_pin(), IOPORT_CREATE_PIN, IOPORT_DIR_OUTPUT, IOPORT_INIT_HIGH, ioport_pin_to_mask(), ioport_pin_to_port(), PRUSART0_bm, sysclk_enable_module(), sysclk_get_source_clock_hz(), test_assert_true, USART_CMODE_SYNCHRONOUS_gc, usart_getchar(), usart_putchar(), usart_rx_enable(), usart_set_mode(), usart_spi_set_baudrate(), and usart_tx_enable().

Referenced by main().

static void run_loopback_test ( const struct test_case test)
static

Test physical loop-back with some characters.

This function sends a character over USART on loop back to verify that init and sending/receiving works. A jumper is connected on the USART.

Parameters
testCurrent test case.

References usart_rs232_options::baudrate, test_assert_true, usart_getchar(), usart_init_rs232(), and usart_putchar().

Referenced by main().