Microchip® Advanced Software Framework

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 CONF_UNIT_USART, and USART_U2X_bm.

Referenced by run_baudrate_test().

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(), CONF_UNIT_USART, 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, CONF_UNIT_BAUDRATE, CONF_UNIT_CHARLENGTH, CONF_UNIT_PARITY, CONF_UNIT_STOPBITS, CONF_UNIT_USART, 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 CONF_UNIT_BAUDRATE, CONF_UNIT_USART, ioport_configure_port_pin(), IOPORT_CREATE_PIN, IOPORT_DIR_OUTPUT, IOPORT_INIT_HIGH, ioport_pin_to_mask(), ioport_pin_to_port(), 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, CONF_UNIT_BAUDRATE, CONF_UNIT_CHARLENGTH, CONF_UNIT_PARITY, CONF_UNIT_STOPBITS, CONF_UNIT_USART, test_assert_true, usart_getchar(), usart_init_rs232(), and usart_putchar().

Referenced by main().