Microchip® Advanced Software Framework

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

Unit tests for PMC driver.

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

#include <stdint.h>
#include <stdbool.h>
#include <board.h>
#include <sysclk.h>
#include <pmc.h>
#include <unit_test/suite.h>
#include <stdio_serial.h>
#include <conf_test.h>
#include <conf_board.h>

Macros

#define PMC_PCK_PRES_CLK_1   PMC_PCK_PRES(0)
 

Functions

static uint32_t is_serial_output_done (void)
 Check if serial output is done. More...
 
int main (void)
 Run PMC driver unit tests. More...
 
static void run_periph_clk_cfg_test (const struct test_case *test)
 Enable and disable peripheral clock test. More...
 
static void run_sleep_mode_test (const struct test_case *test)
 Test entering and exiting sleep mode. More...
 
static void run_switch_mainck_as_mck_test (const struct test_case *test)
 Switch main clock as MCK and enable PCK output, and check if it can be used. More...
 
static void run_switch_pllack_as_mck_test (const struct test_case *test)
 Switch PLLA clock as MCK and enable PCK output, and check if it can be used. More...
 
static void run_switch_slck_as_mck_test (const struct test_case *test)
 Switch slow clock as MCK and enable PCK output, and check if it can be used. More...
 
static void switch_mck_to_default (void)
 Switch MCK to default as startup. More...
 
void SysTick_Handler (void)
 SysTick handler. More...
 

Variables

volatile uint32_t g_ul_sleep_wake_up = 0
 

#define PMC_PCK_PRES_CLK_1   PMC_PCK_PRES(0)

static uint32_t is_serial_output_done ( void  )
static

Check if serial output is done.

Return values
0- Not done.
1- Done.

References uart_is_tx_empty(), and usart_is_tx_empty().

Referenced by run_switch_mainck_as_mck_test(), run_switch_pllack_as_mck_test(), and run_switch_slck_as_mck_test().

static void run_periph_clk_cfg_test ( const struct test_case test)
static

Enable and disable peripheral clock test.

Enable peripheral clocks, and then check if the clocks are enabled. Disable peripheral clocks, and then check if the clocks are disabled.

Parameters
testCurrent test case.

References pmc_disable_periph_clk(), pmc_enable_periph_clk(), and test_assert_true.

Referenced by main().

static void run_sleep_mode_test ( const struct test_case test)
static

Test entering and exiting sleep mode.

Parameters
testCurrent test case.

References g_ul_sleep_wake_up, pmc_enable_sleepmode(), sysclk_get_cpu_hz(), and test_assert_true.

Referenced by main().

static void run_switch_mainck_as_mck_test ( const struct test_case test)
static
static void run_switch_pllack_as_mck_test ( const struct test_case test)
static

Switch PLLA clock as MCK and enable PCK output, and check if it can be used.

Parameters
testCurrent test case.

References is_serial_output_done(), pmc_disable_pck(), pmc_enable_pck(), pmc_enable_pllack(), PMC_PCK_0, PMC_PCK_PRES_CLK_1, pmc_switch_mck_to_mainck(), pmc_switch_mck_to_pllack(), pmc_switch_pck_to_pllack(), switch_mck_to_default(), and test_assert_true.

Referenced by main().

static void run_switch_slck_as_mck_test ( const struct test_case test)
static

Switch slow clock as MCK and enable PCK output, and check if it can be used.

Parameters
testCurrent test case.

References is_serial_output_done(), pmc_disable_pck(), pmc_enable_pck(), PMC_PCK_0, PMC_PCK_PRES_CLK_1, pmc_switch_mck_to_sclk(), pmc_switch_pck_to_sclk(), switch_mck_to_default(), and test_assert_true.

Referenced by main().

static void switch_mck_to_default ( void  )
static

Switch MCK to default as startup.

Note
MCK should be switched to default after clock switching test, so that we can use stdio console again.

References pmc_switch_mck_to_mainck(), and sysclk_init().

Referenced by run_switch_mainck_as_mck_test(), run_switch_pllack_as_mck_test(), and run_switch_slck_as_mck_test().

void SysTick_Handler ( void  )

SysTick handler.

References g_ul_sleep_wake_up.

volatile uint32_t g_ul_sleep_wake_up = 0