Microchip® Advanced Software Framework

common/services/clock/unit_tests/unit_tests.c File Reference

Unit tests for common clock service.

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

#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <compiler.h>
#include <asf.h>
#include "conf_test.h"

Functions

int main (void)
 Run Common Clock service unit tests. More...
 
Common Clock unit test functions
static void run_osc_test (const struct test_case *test)
 Test Oscillator 0/1. More...
 
static void cleanup_osc_test (const struct test_case *test)
 cleanup oscillator test More...
 
static void run_osc32_test (const struct test_case *test)
 Test 32KHz oscillator. More...
 
static void cleanup_osc32_test (const struct test_case *test)
 cleanup 32KHz oscillator test More...
 
static void run_pll_dfll_test (const struct test_case *test)
 Test Pll and DFLL (if have) More...
 
static void cleanup_pll_dfll_test (const struct test_case *test)
 cleanup pll/dfll test More...
 
static void run_sync_clock_test (const struct test_case *test)
 Test Synchronous clock. More...
 
static void run_generic_clock_test (const struct test_case *test)
 Test Generic clock. More...
 
static void cleanup_generic_clock_test (const struct test_case *test)
 cleanup generic clock test More...
 

Variables

int(* ptr_put )(void volatile *, char)
 Pointer to the external low level write function. More...
 
int usart_ready = 0
 USART initialize with the CONFIG_PBA_HZ. More...
 

static void cleanup_generic_clock_test ( const struct test_case test)
static

cleanup generic clock test

Parameters
testCurrent test case.

References genclk_disable().

Referenced by main().

static void cleanup_osc32_test ( const struct test_case test)
static

cleanup 32KHz oscillator test

Parameters
testCurrent test case.

References osc_disable(), and OSC_ID_OSC32.

Referenced by main().

static void cleanup_osc_test ( const struct test_case test)
static

cleanup oscillator test

Parameters
testCurrent test case.

References osc_disable(), OSC_ID_OSC0, OSC_ID_RC1M, OSC_ID_RC80M, and OSC_ID_RCFAST.

Referenced by main().

static void cleanup_pll_dfll_test ( const struct test_case test)
static

cleanup pll/dfll test

Parameters
testCurrent test case.

References dfll_disable_closed_loop(), osc_disable(), OSC_ID_RCSYS, and pll_disable().

Referenced by main().

static void run_generic_clock_test ( const struct test_case test)
static

Test Generic clock.

This test enables the generic clock, sets its source and division factor, and then check if it's set correctly.

Parameters
testCurrent test case.

References genclk_config_defaults(), genclk_config_set_divider(), genclk_config_set_source(), genclk_enable(), status, and test_assert_true.

Referenced by main().

static void run_osc32_test ( const struct test_case test)
static

Test 32KHz oscillator.

This test enables the 32KHz oscillator, and then check if they can be used after startup time

Parameters
testCurrent test case.

References osc_enable(), OSC_ID_OSC32, osc_is_ready(), OSC_RCSYS_NOMINAL_HZ, status, test_assert_true, and wait().

Referenced by main().

static void run_osc_test ( const struct test_case test)
static

Test Oscillator 0/1.

This test enables the oscillator 0 and 1 (if have), and then check if they can be stable and ready for main clock after startup time

Parameters
testCurrent test case.

References OSC0_STARTUP_TIMEOUT, osc_enable(), OSC_ID_OSC0, OSC_ID_RC1M, OSC_ID_RC80M, OSC_ID_RCFAST, osc_is_ready(), status, test_assert_true, UNUSED, and wait().

Referenced by main().

static void run_pll_dfll_test ( const struct test_case test)
static

Test Pll and DFLL (if have)

This test enables pll/dfll source clock, sets its mul and div factor, and then enables it. Check if it's locked after max startup time.

Parameters
testCurrent test case.

References dfll_config_defaults, dfll_enable_closed_loop(), dfll_is_fine_locked(), osc_enable(), OSC_ID_RCSYS, osc_wait_ready(), pll_config_defaults, pll_enable(), pll_enable_source(), pll_is_locked(), PLL_MAX_STARTUP_CYCLES, status, test_assert_true, UNUSED, and wait().

Referenced by main().

static void run_sync_clock_test ( const struct test_case test)
static

Test Synchronous clock.

This test enables source clock for main clock, sets CPU/HSB, PBA,PBB,PBC(if have), PBD(if have) division factor, and then check if the chip is set correctly.

Note
It's not easy to measure CPU/HSB,PBA... frequency, even through some chips have freqm module. Using external module may cause some reliability issue. Since synchronous clocks share the common root main clock, they only need set division factor. So we just test the related registers if set correctly after calling common clock service.
Parameters
testCurrent test case.

References status, sysclk_get_cpu_hz(), sysclk_get_pba_hz(), sysclk_get_pbb_hz(), sysclk_get_pbc_hz(), sysclk_get_pbd_hz(), sysclk_init(), test_assert_true, UNUSED, and usart_ready.

Referenced by main().

int usart_ready = 0

USART initialize with the CONFIG_PBA_HZ.

Referenced by run_sync_clock_test().