Low Power Application.
Copyright (c) 2012-2018 Microchip Technology Inc. and its subsidiaries.
#include "asf.h"
#include "stdio_serial.h"
#include "conf_board.h"
#include "conf_clock.h"
#include "conf_uart_serial.h"
#include "low_power_board.h"
Macros | |
#define | example_disable_pll() pmc_disable_pllack() |
#define | example_set_wakeup_from_backup_mode() |
#define | example_set_wakeup_from_wait_mode() pmc_set_fast_startup_input(WAKEUP_WAIT_INPUT_ID) |
#define | example_switch_clock(a, b, c, d) |
#define | MCK_DEFAULT_DIV PMC_MCKR_PRES_CLK_4 |
#define | PLL_DEFAULT_DIV 1 |
#define | PLL_DEFAULT_MUL 7 |
#define | PMC_PCK_PRES_CLK_1 PMC_PCK_PRES(0) |
#define | PMC_PCK_PRES_CLK_16 PMC_PCK_PRES(4) |
#define | PMC_PCK_PRES_CLK_2 PMC_PCK_PRES(1) |
#define | PMC_PCK_PRES_CLK_32 PMC_PCK_PRES(5) |
#define | PMC_PCK_PRES_CLK_4 PMC_PCK_PRES(2) |
#define | PMC_PCK_PRES_CLK_64 PMC_PCK_PRES(6) |
#define | PMC_PCK_PRES_CLK_8 PMC_PCK_PRES(3) |
#define | STRING_EOL "\r" |
#define | STRING_HEADER |
Functions | |
static void | button_handler (uint32_t ul_id, uint32_t ul_mask) |
Handler for button interrupt. More... | |
static void | configure_button (void) |
Configure the push button. More... | |
static void | configure_console (void) |
Configure UART console. More... | |
static void | display_menu_core (void) |
Display test core menu. More... | |
static uint32_t | fib (uint32_t ul_n) |
Fibonacci calculation. More... | |
static void | init_chip (void) |
Initialize the chip for low power test. More... | |
int | main (void) |
Low power application entry point. More... | |
static void | reconfigure_console (uint32_t ul_mck, uint32_t ul_baudrate) |
Reconfigure UART console for changed MCK and baudrate. More... | |
static void | set_default_working_clock (void) |
Set default clock (MCK = 24MHz). More... | |
static void | test_active_mode (void) |
Test active mode. More... | |
static void | test_core (void) |
Test Core consumption. More... | |
static void | test_sleep_mode (void) |
Test sleep Mode. More... | |
static void | test_wait_mode (void) |
Test wait mode. More... | |
static void | user_change_clock (uint8_t *p_uc_str) |
Change clock configuration. More... | |
Variables | |
volatile uint32_t | g_ul_button_pressed = 0 |
Button pressed flag. More... | |
uint32_t | g_ul_current_mck |
Current MCK in Hz. More... | |
#define example_disable_pll | ( | ) | pmc_disable_pllack() |
Referenced by test_wait_mode(), and user_change_clock().
#define example_set_wakeup_from_backup_mode | ( | ) |
#define example_set_wakeup_from_wait_mode | ( | ) | pmc_set_fast_startup_input(WAKEUP_WAIT_INPUT_ID) |
Referenced by test_wait_mode().
#define example_switch_clock | ( | a, | |
b, | |||
c, | |||
d | |||
) |
Referenced by set_default_working_clock(), and user_change_clock().
#define MCK_DEFAULT_DIV PMC_MCKR_PRES_CLK_4 |
Referenced by set_default_working_clock().
#define PLL_DEFAULT_DIV 1 |
Referenced by set_default_working_clock().
#define PLL_DEFAULT_MUL 7 |
Referenced by set_default_working_clock().
#define PMC_PCK_PRES_CLK_1 PMC_PCK_PRES(0) |
Referenced by test_wait_mode().
#define PMC_PCK_PRES_CLK_16 PMC_PCK_PRES(4) |
#define PMC_PCK_PRES_CLK_2 PMC_PCK_PRES(1) |
#define PMC_PCK_PRES_CLK_32 PMC_PCK_PRES(5) |
#define PMC_PCK_PRES_CLK_4 PMC_PCK_PRES(2) |
#define PMC_PCK_PRES_CLK_64 PMC_PCK_PRES(6) |
#define PMC_PCK_PRES_CLK_8 PMC_PCK_PRES(3) |
#define STRING_EOL "\r" |
#define STRING_HEADER |
Referenced by main().
|
static |
Handler for button interrupt.
References g_ul_button_pressed, PIN_PUSHBUTTON_WAKEUP_ID, and PIN_PUSHBUTTON_WAKEUP_MASK.
Referenced by configure_button().
|
static |
Configure the push button.
Configure the PIO as inputs and generate corresponding interrupt when pressed or released.
References button_handler(), PIN_PUSHBUTTON_WAKEUP_ATTR, PIN_PUSHBUTTON_WAKEUP_ID, PIN_PUSHBUTTON_WAKEUP_MASK, PIN_PUSHBUTTON_WAKEUP_PIO, pio_enable_interrupt(), pio_handler_set(), and pio_set_debounce_filter().
Referenced by test_active_mode(), and test_sleep_mode().
|
static |
Configure UART console.
References uart_rs232_options::baudrate, CONF_PINS_UART, CONF_PINS_UART_FLAGS, CONF_UART, CONF_UART_BAUDRATE, CONF_UART_PARITY, CONF_UART_PIO, CONSOLE_UART_ID, pio_configure_pin_group(), stdio_serial_init(), and sysclk_enable_peripheral_clock().
Referenced by main().
|
static |
Display test core menu.
References EFC, g_ul_current_mck, GPBR0, and gpbr_read().
Referenced by test_core().
|
static |
|
static |
Initialize the chip for low power test.
References CONSOLE_UART, init_specific_board(), pmc_disable_all_periph_clk(), supc_disable_brownout_detector(), uart_is_tx_empty(), and usart_is_tx_empty().
Referenced by main().
int main | ( | void | ) |
Low power application entry point.
References board_init(), CONF_UART_BAUDRATE, configure_console(), g_ul_current_mck, init_chip(), reconfigure_console(), set_default_working_clock(), STRING_HEADER, sysclk_get_cpu_hz(), sysclk_init(), and test_core().
|
static |
Reconfigure UART console for changed MCK and baudrate.
References CONF_PINS_UART, CONF_PINS_UART_FLAGS, CONF_UART, CONF_UART_PIO, CONSOLE_UART_ID, pio_configure_pin_group(), pmc_enable_periph_clk(), and uart_init().
Referenced by main(), test_active_mode(), test_sleep_mode(), and test_wait_mode().
|
static |
Set default clock (MCK = 24MHz).
References BOARD_OSC_STARTUP_US, example_switch_clock, g_ul_current_mck, MCK_DEFAULT_DIV, PLL_COUNT, PLL_DEFAULT_DIV, PLL_DEFAULT_MUL, pmc_osc_disable_fastrc(), pmc_switch_mainck_to_xtal(), and pmc_switch_mck_to_sclk().
Referenced by main(), test_active_mode(), test_sleep_mode(), and test_wait_mode().
|
static |
Test active mode.
References CONF_UART_BAUDRATE, configure_button(), fib(), g_ul_button_pressed, g_ul_current_mck, reconfigure_console(), set_default_working_clock(), STRING_ACTIVE, and user_change_clock().
Referenced by test_core().
|
static |
Test Core consumption.
References display_menu_core(), EFC, test_active_mode(), test_sleep_mode(), and test_wait_mode().
Referenced by main().
|
static |
Test sleep Mode.
References CONF_UART_BAUDRATE, configure_button(), CONSOLE_UART_ID, g_ul_current_mck, pmc_disable_periph_clk(), pmc_enable_sleepmode(), reconfigure_console(), set_default_working_clock(), STRING_SLEEP, and user_change_clock().
Referenced by test_core().
|
static |
Test wait mode.
References CONF_UART_BAUDRATE, CONSOLE_UART, example_disable_pll, example_set_wakeup_from_wait_mode, g_ul_current_mck, pmc_enable_waitmode(), pmc_osc_disable_xtal(), PMC_PCK_PRES_CLK_1, pmc_switch_mainck_to_fastrc(), pmc_switch_mck_to_mainck(), pmc_switch_mck_to_sclk(), reconfigure_console(), set_default_working_clock(), STRING_WAIT, uart_is_tx_empty(), and usart_is_tx_empty().
Referenced by test_core().
|
static |
Change clock configuration.
p_uc_str | Hint string to be output on console before changing clock. |
References BOARD_OSC_STARTUP_US, CLOCK_LIST_MENU, CONSOLE_UART, example_disable_pll, example_switch_clock, g_fastrc_clock_list, g_pll_clock_list, g_ul_current_mck, MAX_CLOCK_FAST_RC_ITEM, MAX_CLOCK_PLL_ITEM, MIN_CLOCK_FAST_RC_ITEM, MIN_CLOCK_PLL_ITEM, PLL_COUNT, pmc_osc_disable_fastrc(), pmc_osc_disable_xtal(), pmc_osc_enable_fastrc(), pmc_switch_mainck_to_fastrc(), pmc_switch_mainck_to_xtal(), pmc_switch_mck_to_mainck(), pmc_switch_mck_to_sclk(), uart_is_tx_empty(), and usart_is_tx_empty().
Referenced by test_active_mode(), and test_sleep_mode().
volatile uint32_t g_ul_button_pressed = 0 |
Button pressed flag.
Referenced by button_handler(), and test_active_mode().
uint32_t g_ul_current_mck |
Current MCK in Hz.
Referenced by display_menu_core(), main(), set_default_working_clock(), test_active_mode(), test_sleep_mode(), test_wait_mode(), and user_change_clock().