Microchip® Advanced Software Framework

unit_test.c File Reference

SAM USART 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"

Macros

#define TEST_STRING   "Hello world!"
 
#define TEST_STRING_LEN   13
 
#define TEST_USART_SPEED   115200
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
int main (void)
 Run USART unit tests. More...
 
static void run_buffer_read_write_interrupt_test (const struct test_case *test)
 Test sending and receiving a string using interrupts. More...
 
static void run_buffer_write_blocking_read_interrupt_test (const struct test_case *test)
 Test sending (blocking) and receiving (interrupt) a string. More...
 
static void run_transfer_single_8bit_char_test (const struct test_case *test)
 Test single 8-bit character send and receive. More...
 
static void run_transfer_single_9bit_char_test (const struct test_case *test)
 Test single 9-bit character send and receive. More...
 
static void test_system_init (void)
 Initialize USARTs for unit tests. More...
 
static void usart_callback (struct usart_module *const module)
 USART interrupt callback function. More...
 

Variables

struct usart_module cdc_uart_module
 
volatile bool transfer_complete
 
struct usart_config usart_rx_config
 
struct usart_module usart_rx_module
 
struct usart_config usart_tx_config
 
struct usart_module usart_tx_module
 

#define TEST_STRING   "Hello world!"
#define TEST_USART_SPEED   115200

Referenced by test_system_init().

static void cdc_uart_init ( void  )
static
static void run_buffer_read_write_interrupt_test ( const struct test_case test)
static

Test sending and receiving a string using interrupts.

This test sends one string from one USART to another. Both the send and receive is done using interrupts.

Parameters
testCurrent test case.

References test_assert_false, test_assert_true, TEST_STRING, TEST_STRING_LEN, transfer_complete, USART_CALLBACK_BUFFER_RECEIVED, usart_enable_callback(), usart_read_buffer_job(), usart_register_callback(), usart_rx_module, usart_tx_module, and usart_write_buffer_job().

Referenced by main().

static void run_buffer_write_blocking_read_interrupt_test ( const struct test_case test)
static

Test sending (blocking) and receiving (interrupt) a string.

This test sends one string from one USART to another. It's sent using a blocking write, while it's received using interrupts.

Parameters
testCurrent test case.

References test_assert_false, test_assert_true, TEST_STRING, TEST_STRING_LEN, transfer_complete, USART_CALLBACK_BUFFER_RECEIVED, usart_disable_callback(), usart_enable_callback(), usart_read_buffer_job(), usart_register_callback(), usart_rx_module, usart_tx_module, usart_unregister_callback(), and usart_write_buffer_wait().

Referenced by main().

static void run_transfer_single_8bit_char_test ( const struct test_case test)
static

Test single 8-bit character send and receive.

This test sends on 9-bit character and checks it's received properly on the other end.

Parameters
testCurrent test case.

References test_assert_true, usart_read_wait(), usart_rx_module, usart_tx_module, and usart_write_wait().

Referenced by main().

static void run_transfer_single_9bit_char_test ( const struct test_case test)
static

Test single 9-bit character send and receive.

This test sends one 9-bit character and checks it's received properly on the other end.

Parameters
testCurrent test case.

References usart_config::character_size, CONF_RX_USART, CONF_TX_USART, test_assert_true, USART_CHARACTER_SIZE_8BIT, USART_CHARACTER_SIZE_9BIT, usart_disable(), usart_enable(), usart_init(), usart_read_wait(), usart_rx_config, usart_rx_module, usart_tx_config, usart_tx_module, and usart_write_wait().

Referenced by main().

static void usart_callback ( struct usart_module *const  module)
static

USART interrupt callback function.

Called by USART driver when receiving is complete.

  • Parameters
    moduleUSART module causing the interrupt (not used)

References transfer_complete.

struct usart_module cdc_uart_module

Referenced by cdc_uart_init().

struct usart_config usart_rx_config
struct usart_config usart_tx_config