Example to illustrate the Sleepwalking feature with the ACIFB module in AT32UC3L series.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include <stdint.h>
#include "compiler.h"
#include "board.h"
#include "conf_example.h"
#include "acifb.h"
#include "gpio.h"
#include "ast.h"
#include "pm_uc3l.h"
#include "scif_uc3l.h"
#include "intc.h"
#include "sysclk.h"
#include "sleepmgr.h"
#include "delay.h"
#include "status_codes.h"
Macros | |
APPLICATION SPECIFIC CONFIGURATION | |
#define | DEBUG_MESSAGES DISABLE |
Enable Trace messages through USART terminal. More... | |
#define | STATUS_LED LED1_GPIO |
LED1_GPIO is used as status LED. More... | |
#define | ERROR_LED LED0_GPIO |
LED0_GPIO is used as error status LED. More... | |
#define | LED_DELAY 10 |
Delay in ms for LED blinking. More... | |
#define | POWER_SUPPLY_MODE_1_8V false |
Enable when operated in 1.8V VDDIN. More... | |
#define | AC &AVR32_ACIFB |
ACIFB Module is used. More... | |
#define | AC_INTERRUPT_PRIORITY 1 |
ACIFB interrupt priority is set to 1. More... | |
#define | AC_GCLK_ID AVR32_SCIF_GCLK_ACIFB |
ACIFB Generic Clock - GCLK4. More... | |
#define | AC_GCLK_SRC SCIF_GCCTRL_PBACLOCK |
ACIFB Generic Clock Source - PBA. More... | |
#define | AC_GCLK_FREQUENCY 250000 |
ACIFB Generic Clock Frequency - 1 MHz. More... | |
#define | AC_STARTUP_CYCLES 6 |
ACIFB startup cycle - 6 cycles. More... | |
#define | AC_NB_CHANNELS 1 |
#define | AST_CLOCK_SOURCE AST_OSC_32KHZ |
32KHz external oscillator is used as AST source More... | |
#define | AST_PRESCALER AST_PSEL_32KHZ_1HZ |
Prescaler is set to AST_PSEL_32KHZ_1HZ to run at 1Hz. More... | |
#define | AST_TRIGGER_PRESCALER 13 |
Periodic interrupt prescaler is set to 12 for trigger in every 250ms. More... | |
#define | NB_GPIO_USED_PINS 6 |
Functions | |
static status_code_t | ac_init (void) |
Initializes the ACIFB module with trigger. More... | |
static status_code_t | ast_init (void) |
Initialize Asynchronous Timer to trigger ACIFB module at regular intervals. More... | |
ISR (ACIFB_interrupt_handler, AVR32_ACIFB_IRQ_GROUP, AC_INTERRUPT_PRIORITY) | |
ACIFB ISR Routine. More... | |
int | main (void) |
Main Application Routine. More... | |
static void | power_save_measures_init (void) |
Initializes the power saving measures to reduce power consumption. More... | |
Variables | |
volatile avr32_acifb_t * | acifb = AC |
Global variable to Store the ACIFB module address. More... | |
uint32_t | gpio_used_pins [NB_GPIO_USED_PINS] |
Array to hold the used GPIO pins. More... | |
#define AC &AVR32_ACIFB |
ACIFB Module is used.
#define AC_GCLK_FREQUENCY 250000 |
ACIFB Generic Clock Frequency - 1 MHz.
Referenced by ac_init().
#define AC_GCLK_ID AVR32_SCIF_GCLK_ACIFB |
ACIFB Generic Clock - GCLK4.
Referenced by ac_init().
#define AC_GCLK_SRC SCIF_GCCTRL_PBACLOCK |
ACIFB Generic Clock Source - PBA.
Referenced by ac_init().
#define AC_INTERRUPT_PRIORITY 1 |
ACIFB interrupt priority is set to 1.
Referenced by ac_init().
#define AC_NB_CHANNELS 1 |
Referenced by ac_init().
#define AC_STARTUP_CYCLES 6 |
ACIFB startup cycle - 6 cycles.
#define AST_CLOCK_SOURCE AST_OSC_32KHZ |
32KHz external oscillator is used as AST source
Referenced by ast_init().
#define AST_PRESCALER AST_PSEL_32KHZ_1HZ |
Prescaler is set to AST_PSEL_32KHZ_1HZ to run at 1Hz.
Referenced by ast_init().
#define AST_TRIGGER_PRESCALER 13 |
Periodic interrupt prescaler is set to 12 for trigger in every 250ms.
Referenced by ast_init().
#define DEBUG_MESSAGES DISABLE |
Enable Trace messages through USART terminal.
#define ERROR_LED LED0_GPIO |
LED0_GPIO is used as error status LED.
Referenced by main().
#define LED_DELAY 10 |
Delay in ms for LED blinking.
Referenced by main().
#define NB_GPIO_USED_PINS 6 |
#define POWER_SUPPLY_MODE_1_8V false |
Enable when operated in 1.8V VDDIN.
#define STATUS_LED LED1_GPIO |
LED1_GPIO is used as status LED.
Referenced by main().
|
static |
Initializes the ACIFB module with trigger.
STATUS_OK | Configuration OK |
ERR_TIMEOUT | Timeout on configuring ACIFB module |
ERR_BUSY | ACIFB module unable to configure the trigger |
References AC_GCLK_FREQUENCY, AC_GCLK_ID, AC_GCLK_SRC, AC_INTERRUPT_PRIORITY, AC_NB_CHANNELS, acifb, acifb_channels_setup(), acifb_enable_comparison_interrupt(), acifb_setup_and_enable(), cpu_irq_disable, cpu_irq_enable, acifb_channel_t::filter_len, gpio_disable_pin_pull_up(), gpio_enable_module(), irq_initialize_vectors, irq_register_handler, scif_gc_enable(), scif_gc_setup(), STATUS_OK, acifb_t::sut, SYSCLK_ACIFB, sysclk_enable_pba_module(), and sysclk_get_pba_hz().
Referenced by main().
|
static |
Initialize Asynchronous Timer to trigger ACIFB module at regular intervals.
Asynchronous Timer Initialization.
STATUS_OK | Configuration OK |
ERR_BUSY | Error in configuring the AST module |
References ast_clear_all_status_flags(), AST_CLOCK_SOURCE, ast_enable(), ast_enable_periodic0(), ast_init_counter(), AST_PRESCALER, ast_set_periodic0_value(), AST_TRIGGER_PRESCALER, BOARD_OSC32_PINSEL, ERR_BUSY, scif_osc32_opt_t::mode, OSC32_STARTUP_8192, SCIF_OSC_MODE_2PIN_CRYSTAL_HICUR, scif_start_osc32(), STATUS_OK, SYSCLK_AST, sysclk_disable_pba_module(), sysclk_enable_hsb_module(), sysclk_enable_pba_module(), and SYSCLK_EVENT.
Referenced by main().
ISR | ( | ACIFB_interrupt_handler | , |
AVR32_ACIFB_IRQ_GROUP | , | ||
AC_INTERRUPT_PRIORITY | |||
) |
ACIFB ISR Routine.
References acifb, and acifb_clear_comparison_interrupt_flag().
int main | ( | void | ) |
Main Application Routine.
References ac_init(), ast_clear_all_status_flags(), ast_init(), DBG_USART, delay_init, delay_ms, ERROR_LED, gpio_clr_gpio_pin(), gpio_set_gpio_pin(), gpio_tgl_gpio_pin(), init_dbg_rs232(), LED_DELAY, pm_asyn_wake_up_disable(), pm_asyn_wake_up_enable(), power_save_measures_init(), print_dbg(), sleepmgr_enter_sleep(), sleepmgr_init(), sleepmgr_lock_mode(), SLEEPMGR_STATIC, STATUS_LED, STATUS_OK, sysclk_disable_pba_module(), sysclk_enable_pba_module(), sysclk_enable_peripheral_clock(), sysclk_get_cpu_hz(), sysclk_get_pba_hz(), SYSCLK_GPIO, and sysclk_init().
|
static |
Initializes the power saving measures to reduce power consumption.
Low Power Configuration Initializes the power saving measures to reduce power consumption.
References gpio_configure_group(), GPIO_DIR_INPUT, GPIO_PULL_UP, gpio_used_pins, i, sysclk_disable_cpu_module(), SYSCLK_OCD, and tmp.
Referenced by main().
volatile avr32_acifb_t* acifb = AC |
Global variable to Store the ACIFB module address.
uint32_t gpio_used_pins[NB_GPIO_USED_PINS] |
Array to hold the used GPIO pins.
Referenced by power_save_measures_init().