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
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, 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, 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, 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, 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, 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, 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, GCLK_GENERATOR_0, 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, GCLK_GENERATOR_2, 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