Microchip® Advanced Software Framework

sam/applications/sam_low_power/main.c File Reference

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_backup_mode (void)
 Test backup 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()
#define example_set_wakeup_from_backup_mode ( )
Value:
supc_set_wakeup_inputs(SUPC, WAKEUP_BACKUP_INPUT_ID, \
WAKEUP_BACKUP_INPUT_ID)
void supc_set_wakeup_inputs(Supc *p_supc, uint32_t ul_inputs, uint32_t ul_transition)
Set system controller wake up inputs.
Definition: supc.c:254

Referenced by test_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,
 
)
Value:
do { \
} while (0)
uint32_t pmc_switch_mck_to_pllack(uint32_t ul_pres)
Switch master clock source selection to PLLA clock.
Definition: pmc.c:218
void pmc_enable_pllack(uint32_t mula, uint32_t pllacount, uint32_t diva)
Enable PLLA clock.
Definition: pmc.c:558

Referenced by set_default_working_clock(), and user_change_clock().

#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)

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
Value:
"-- Low Power Example --\r\n" \
"-- "BOARD_NAME " --\r\n" \
"-- Compiled: "__DATE__ " "__TIME__ " --"STRING_EOL
#define BOARD_NAME
Definition: inc/app_init.h:140
#define STRING_EOL
Definition: sam/applications/sam_low_power/main.c:92

Referenced by main().

static void button_handler ( uint32_t  ul_id,
uint32_t  ul_mask 
)
static

Handler for button interrupt.

Note
This interrupt is for waking up from sleep mode or exiting from active mode.

References g_ul_button_pressed, PIN_PUSHBUTTON_WAKEUP_ID, and PIN_PUSHBUTTON_WAKEUP_MASK.

Referenced by configure_button().

static void configure_button ( void  )
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(), and pio_set_debounce_filter().

Referenced by test_active_mode(), and test_sleep_mode().

static void display_menu_core ( void  )
static

Display test core menu.

References efc_get_flash_access_mode(), g_ul_current_mck, GPBR0, and gpbr_read().

Referenced by test_core().

static uint32_t fib ( uint32_t  ul_n)
static

Fibonacci calculation.

Parameters
ul_nNumber N.

Referenced by test_active_mode().

static void init_chip ( void  )
static

Initialize the chip for low power test.

References pmc_disable_all_periph_clk(), supc_disable_brownout_detector(), uart_is_tx_empty(), and usart_is_tx_empty().

Referenced by main().

int main ( void  )
static void reconfigure_console ( uint32_t  ul_mck,
uint32_t  ul_baudrate 
)
static

Reconfigure UART console for changed MCK and baudrate.

References CONF_UART, 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 void test_active_mode ( void  )
static
static void test_backup_mode ( void  )
static
static void test_core ( void  )
static
static void user_change_clock ( uint8_t *  p_uc_str)
static

volatile uint32_t g_ul_button_pressed = 0

Button pressed flag.

Referenced by button_handler(), and test_active_mode().