Example to illustrate the Sleepwalking feature with the ADCIFB 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 "adcifb.h"
#include "gpio.h"
#include "ast.h"
#include "scif_uc3l.h"
#include "pm_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 | ADC &AVR32_ADCIFB |
ADCIFB Module is used. More... | |
#define | ADC_FREQUENCY 250000 |
ADCIFB Clock Frequency - 1 MHz. More... | |
#define | ADC_INTERRUPT_PRIORITY 1 |
ADCIFB interrupt priority is set to 1. More... | |
#define | ADC_SAMPLE_HOLD_TIME 4 |
ADCIFB sample & hold time configuration - 0 Sample & Hold Time = (ADC_SAMPLE_HOLD_TIME + 3)* Tclk_adc. More... | |
#define | ADC_COMPARE_VALUE 0x200 |
ADCIFB compare value in Analog Compare Mode - 1.5V. More... | |
#define | ADC_STARTUP_TIME 0 |
ADCIFB startup time configuration - 0 Tstartup = (ADC_STARTUP_TIME + 1) * 8 * Tclk_adc (assuming Tstartup ~ 15us max) -> 1 * 8 * 1/250000 = 32us. More... | |
#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 5 |
Functions | |
static status_code_t | adc_init (void) |
Initializes the ADCIFB module with trigger. More... | |
static status_code_t | ast_init (void) |
Initialize Asynchronous Timer to trigger ADCIFB module at regular intervals. More... | |
ISR (ADCIFB_interrupt_handler, AVR32_ADCIFB_IRQ_GROUP, ADC_INTERRUPT_PRIORITY) | |
ADCIFB 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 | |
static uint32_t | adc_output |
Static variable to store the ADCIFB output value. More... | |
volatile avr32_adcifb_t * | adcifb = ADC |
Global variable to Store the ADCIFB module address. More... | |
static volatile unsigned int | cycle_cnt |
uint32_t | gpio_used_pins [NB_GPIO_USED_PINS] |
Array to hold the used GPIO pins. More... | |
#define ADC &AVR32_ADCIFB |
ADCIFB Module is used.
#define ADC_COMPARE_VALUE 0x200 |
ADCIFB compare value in Analog Compare Mode - 1.5V.
Referenced by adc_init().
#define ADC_FREQUENCY 250000 |
ADCIFB Clock Frequency - 1 MHz.
Referenced by adc_init().
#define ADC_INTERRUPT_PRIORITY 1 |
ADCIFB interrupt priority is set to 1.
Referenced by adc_init().
#define ADC_SAMPLE_HOLD_TIME 4 |
ADCIFB sample & hold time configuration - 0 Sample & Hold Time = (ADC_SAMPLE_HOLD_TIME + 3)* Tclk_adc.
Referenced by adc_init().
#define ADC_STARTUP_TIME 0 |
ADCIFB startup time configuration - 0 Tstartup = (ADC_STARTUP_TIME + 1) * 8 * Tclk_adc (assuming Tstartup ~ 15us max) -> 1 * 8 * 1/250000 = 32us.
Referenced by adc_init().
#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 LED_DELAY 10 |
Delay in ms for LED blinking.
Referenced by main().
#define NB_GPIO_USED_PINS 5 |
#define POWER_SUPPLY_MODE_1_8V false |
Enable when operated in 1.8V VDDIN.
|
static |
Initializes the ADCIFB module with trigger.
STATUS_OK | Configuration OK |
ERR_TIMEOUT | Timeout on configuring ADCIFB module |
ERR_BUSY | ADCIFB module unable to configure the trigger |
References ADC_COMPARE_VALUE, ADC_FREQUENCY, ADC_INTERRUPT_PRIORITY, ADC_SAMPLE_HOLD_TIME, ADC_STARTUP_TIME, adcifb, adcifb_channels_enable(), adcifb_configure(), adcifb_configure_trigger(), adcifb_enable_analog_compare_mode(), adcifb_enable_compare_gt_interrupt(), adcifb_set_high_compare_value(), cpu_irq_disable, ERR_BUSY, ERR_TIMEOUT, EXAMPLE_ADCIFB_CHANNEL, EXAMPLE_ADCIFB_FUNCTION, EXAMPLE_ADCIFB_PIN, gpio_disable_pin_pull_up(), gpio_enable_module(), irq_initialize_vectors, irq_register_handler, adcifb_opt_t::resolution, STATUS_OK, SYSCLK_ADCIFB, sysclk_enable_pba_module(), and sysclk_get_pba_hz().
Referenced by main().
|
static |
Initialize Asynchronous Timer to trigger ADCIFB module at regular intervals.
Asynchronous Timer Initialization.
STATUS_OK | Configuration OK |
ERR_TIMEOUT | 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_TIMEOUT, 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 | ( | ADCIFB_interrupt_handler | , |
AVR32_ADCIFB_IRQ_GROUP | , | ||
ADC_INTERRUPT_PRIORITY | |||
) |
ADCIFB ISR Routine.
References adc_output, adcifb, adcifb_clear_compare_gt_interrupt_flag(), and adcifb_get_last_data().
int main | ( | void | ) |
Main Application Routine.
References adc_init(), adc_output, 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(), print_dbg_hex(), 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, sysclk_disable_cpu_module(), and SYSCLK_OCD.
Referenced by main().
|
static |
volatile avr32_adcifb_t* adcifb = ADC |
Global variable to Store the ADCIFB module address.
Referenced by adc_init(), and ISR().
|
static |
uint32_t gpio_used_pins[NB_GPIO_USED_PINS] |
Array to hold the used GPIO pins.
Referenced by power_save_measures_init().