Microchip® Advanced Software Framework

drivers/events/unit_test/unit_test.c File Reference

SAM Event System 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_EVENT_GEN   EVSYS_ID_GEN_RTC_OVF
 
#define TEST_EVENT_USER   EVSYS_ID_USER_TC3_EVU
 

Functions

static void cdc_uart_init (void)
 Initialize the USART for unit test. More...
 
static void cleanup_asynchronous_event_test (const struct test_case *test)
 Cleanup Function: Asynchronous event propagation. More...
 
static void cleanup_resynchronous_event_test (const struct test_case *test)
 Cleanup Function: Resynchronized event propagation. More...
 
static void cleanup_synchronous_event_test (const struct test_case *test)
 Cleanup Function: Synchronous event propagation. More...
 
int main (void)
 Run Event System unit tests. More...
 
static void run_asynchronous_event_test (const struct test_case *test)
 Test for event system in asynchronous mode. More...
 
static void run_resynchronous_event_test (const struct test_case *test)
 Test for event system in resynchronous mode. More...
 
static void run_synchronous_event_test (const struct test_case *test)
 Test for event system in synchronous mode. More...
 
static void setup_asynchronous_event_test (const struct test_case *test)
 Setup Function: Asynchronous event propagation. More...
 
static void setup_resynchronous_event_test (const struct test_case *test)
 Setup Function: Resynchronized event propagation. More...
 
static void setup_synchronous_event_test (const struct test_case *test)
 Setup Function: Synchronous event propagation. More...
 
static void test_event_gen_user_init (void)
 Initialize the (TC3 | TC1) & RTC for unit test. More...
 

Variables

struct usart_module cdc_uart_module
 
struct events_resource events
 
volatile bool init_success
 
struct rtc_module rtc_inst
 
struct tc_module tc_inst
 

#define TEST_EVENT_GEN   EVSYS_ID_GEN_RTC_OVF
#define TEST_EVENT_USER   EVSYS_ID_USER_TC3_EVU

static void cdc_uart_init ( void  )
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().

static void cleanup_asynchronous_event_test ( const struct test_case test)
static

Cleanup Function: Asynchronous event propagation.

This function disables the RTC, clears the RTC COUNT register and stops the timer (TC3 | TC1).

Parameters
testCurrent test case.

References events, events_release(), rtc_count_disable(), rtc_count_set_count(), rtc_inst, tc_inst, and tc_stop_counter().

Referenced by main().

static void cleanup_resynchronous_event_test ( const struct test_case test)
static

Cleanup Function: Resynchronized event propagation.

This function disables the RTC, clears the RTC COUNT register and stops the timer (TC3 | TC1).

Parameters
testCurrent test case.

References events, events_release(), rtc_count_disable(), rtc_count_set_count(), rtc_inst, tc_inst, and tc_stop_counter().

Referenced by main().

static void cleanup_synchronous_event_test ( const struct test_case test)
static

Cleanup Function: Synchronous event propagation.

This function disables the RTC, clears the RTC COUNT register and stops the timer (TC3 | TC1).

Parameters
testCurrent test case.

References events, events_release(), rtc_count_disable(), rtc_count_set_count(), rtc_inst, tc_inst, and tc_stop_counter().

Referenced by main().

static void run_asynchronous_event_test ( const struct test_case test)
static

Test for event system in asynchronous mode.

This test waits for event channel and user to be ready and then starts the RTC to generate overflow event. It waits until the timer is started. If the timer starts running then it can be assumed that the event has been propagated properly.

Parameters
testCurrent test case.

References init_success, rtc_count_enable(), rtc_count_set_period(), rtc_inst, tc_get_count_value(), tc_inst, and test_assert_true.

Referenced by main().

static void run_resynchronous_event_test ( const struct test_case test)
static

Test for event system in resynchronous mode.

This test waits for event channel and user to be ready and then starts the RTC to generate overflow event. It waits until the timer is started. If the timer starts running then it can be assumed that the event has been propagated properly.

Parameters
testCurrent test case.

References events, events_is_busy(), events_is_users_ready(), init_success, rtc_count_enable(), rtc_count_set_period(), rtc_inst, tc_get_count_value(), tc_inst, and test_assert_true.

Referenced by main().

static void run_synchronous_event_test ( const struct test_case test)
static

Test for event system in synchronous mode.

This test waits for event channel and user to be ready and then starts the RTC to generate overflow event. It waits until the timer is started. If the timer starts running then it can be assumed that the event has been propagated properly.

Parameters
testCurrent test case.

References events, events_is_busy(), events_is_users_ready(), init_success, rtc_count_enable(), rtc_count_set_period(), rtc_inst, tc_get_count_value(), tc_inst, and test_assert_true.

Referenced by main().

static void setup_asynchronous_event_test ( const struct test_case test)
static

Setup Function: Asynchronous event propagation.

This function initializes the event system channel 0 and the RTC module (event generator). The event channel clock will not be enabled for asynchronous event propagation.

Parameters
testCurrent test case.

References events, events_allocate(), events_attach_user(), events_get_config_defaults(), EVENTS_PATH_ASYNCHRONOUS, events_config::generator, events_config::path, TEST_EVENT_GEN, and TEST_EVENT_USER.

Referenced by main().

static void setup_resynchronous_event_test ( const struct test_case test)
static

Setup Function: Resynchronized event propagation.

This function initializes the event system channel 0 and the RTC module (event generator) to be in the different clock domain for resynchronized event propagation.

Parameters
testCurrent test case.

References events_config::clock_source, events_config::edge_detect, events, events_allocate(), events_attach_user(), EVENTS_EDGE_DETECT_RISING, events_get_config_defaults(), EVENTS_PATH_RESYNCHRONIZED, GCLK_GENERATOR_0, events_config::generator, events_config::path, TEST_EVENT_GEN, and TEST_EVENT_USER.

Referenced by main().

static void setup_synchronous_event_test ( const struct test_case test)
static

Setup Function: Synchronous event propagation.

This function initializes the event system channel 0 and the RTC module (event generator) to be in the same clock domain for synchronous event propagation.

Parameters
testCurrent test case.

References events_config::clock_source, events_config::edge_detect, events, events_allocate(), events_attach_user(), EVENTS_EDGE_DETECT_RISING, events_get_config_defaults(), EVENTS_PATH_SYNCHRONOUS, GCLK_GENERATOR_2, events_config::generator, events_config::path, TEST_EVENT_GEN, and TEST_EVENT_USER.

Referenced by main().

struct usart_module cdc_uart_module
volatile bool init_success
struct rtc_module rtc_inst