Microchip® Advanced Software Framework

sam/drivers/bpm/unit_tests/unit_tests.c File Reference

Unit tests for BPM driver.

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

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

Unit test configuration

#define EVENT_WAKEUP   1
 Wakeup event, logged in ISR that wakes up the device. More...
 
#define EVENT_RUN   2
 Run event, logged in main loop after wakeup. More...
 
#define IS_NB_EVENTS_OK()   (2 == log_index)
 Is OK if 2 events detected. More...
 
#define IS_EVENTS_OK()   ((log_events[0]==EVENT_WAKEUP) && (log_events[1]==EVENT_RUN))
 Is OK if first event is wakeup and second one is run. More...
 
static uint8_t log_events [2]
 Logs for events detected. More...
 
static volatile uint8_t log_index = 0
 Current log index. More...
 
static volatile uint32_t tick_1ms = 0
 1ms Time Tick More...
 
static void reset_log (void)
 Reset event log list. More...
 
static void log_event (uint8_t event)
 Log a event. More...
 
static void wait_test_assert_idle (void)
 Wait until test assert is done (no wave on assert port) More...
 
static void ast_per_callback (void)
 AST interrupt handler. More...
 
void BPM_Handler (void)
 BPM interrupt handler. More...
 
static void run_backup_test (const struct test_case *test)
 Test entering and exiting backup mode. More...
 
static void run_ps_test (const struct test_case *test)
 Test power scaling switch. More...
 
static void run_ret_test (const struct test_case *test)
 Test entering and exiting retention mode. More...
 
static void run_wait_test (const struct test_case *test)
 Test entering and exiting wait mode. More...
 
static void run_sleep_3_test (const struct test_case *test)
 Test entering and exiting sleep 3 mode. More...
 
static void run_sleep_2_test (const struct test_case *test)
 Test entering and exiting sleep 2 mode. More...
 
static void run_sleep_1_test (const struct test_case *test)
 Test entering and exiting sleep 1 mode. More...
 
static void run_sleep_0_test (const struct test_case *test)
 Test entering and exiting sleep 0 mode. More...
 
int main (void)
 Run BPM driver unit tests. More...
 

#define EVENT_RUN   2

Run event, logged in main loop after wakeup.

Referenced by run_ret_test(), run_sleep_0_test(), run_sleep_1_test(), run_sleep_2_test(), run_sleep_3_test(), and run_wait_test().

#define EVENT_WAKEUP   1

Wakeup event, logged in ISR that wakes up the device.

Referenced by ast_per_callback(), and BPM_Handler().

#define IS_EVENTS_OK ( )    ((log_events[0]==EVENT_WAKEUP) && (log_events[1]==EVENT_RUN))

Is OK if first event is wakeup and second one is run.

Referenced by run_ret_test(), run_sleep_0_test(), run_sleep_1_test(), run_sleep_2_test(), run_sleep_3_test(), and run_wait_test().

#define IS_NB_EVENTS_OK ( )    (2 == log_index)

static void ast_per_callback ( void  )
static

AST interrupt handler.

References ast_clear_interrupt_flag(), AST_INTERRUPT_PER, EVENT_WAKEUP, and log_event().

Referenced by main().

void BPM_Handler ( void  )
static void log_event ( uint8_t  event)
inlinestatic
static void reset_log ( void  )
inlinestatic
static void run_backup_test ( const struct test_case test)
static

Test entering and exiting backup mode.

Parameters
testCurrent test case.

References bpm_get_backup_wakeup_cause(), bpm_sleep(), BPM_SM_BACKUP, delay_ms, and test_assert_true.

Referenced by main().

static void run_ps_test ( const struct test_case test)
static

Test power scaling switch.

Parameters
testCurrent test case.

References bpm_power_scaling_cpu_failsafe(), BPM_PS_0, BPM_PS_1, sysclk_get_cpu_hz(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_ret_test ( const struct test_case test)
static

Test entering and exiting retention mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_RET, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_sleep_0_test ( const struct test_case test)
static

Test entering and exiting sleep 0 mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_SLEEP_0, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_sleep_1_test ( const struct test_case test)
static

Test entering and exiting sleep 1 mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_SLEEP_1, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_sleep_2_test ( const struct test_case test)
static

Test entering and exiting sleep 2 mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_SLEEP_2, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_sleep_3_test ( const struct test_case test)
static

Test entering and exiting sleep 3 mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_SLEEP_3, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void run_wait_test ( const struct test_case test)
static

Test entering and exiting wait mode.

Parameters
testCurrent test case.

References bpm_sleep(), BPM_SM_WAIT, delay_ms, EVENT_RUN, IS_EVENTS_OK, IS_NB_EVENTS_OK, log_event(), reset_log(), test_assert_true, and wait_test_assert_idle().

Referenced by main().

static void wait_test_assert_idle ( void  )
inlinestatic

Wait until test assert is done (no wave on assert port)

References usart_is_tx_empty().

Referenced by run_ps_test(), run_ret_test(), run_sleep_0_test(), run_sleep_1_test(), run_sleep_2_test(), run_sleep_3_test(), and run_wait_test().

uint8_t log_events[2]
static

Logs for events detected.

Referenced by log_event(), and reset_log().

volatile uint8_t log_index = 0
static

Current log index.

Referenced by log_event(), and reset_log().

volatile uint32_t tick_1ms = 0
static

1ms Time Tick