Atmel Software Framework

simulator_example/cycle_counter_example.c File Reference

CPU Cycle Counter Example application for AVR UC3.

Copyright (C) 2013-2014 Atmel Corporation. All rights reserved.

#include <stdint.h>
#include <stdbool.h>
#include <asf.h>

Macros

#define _ASSERT_ENABLE_
 
Example configuration
#define EXAMPLE_TOGGLE_PIN   AVR32_PIN_PA03
 GPIO Line to toggle on compare match. More...
 
Example configuration
#define EXAMPLE_DELAY_MS   100
 Delay period between COMPARE interrupts given in milliseconds. More...
 

Functions

int main (void)
 Application main loop. More...
 
 Set_sys_compare (Get_sys_count()+delay_clock_cycles)
 

Variables

static volatile uint32_t delay_clock_cycles
 Number of clock cycles representing the EXAMPLE_DELAY_MS. More...
 
static volatile uint32_t number_of_compares = 0
 Counter to store the number for COMPARE interrupts. More...
 
static volatile bool toggle_gpio = false
 Flag to indicate that the GPIO line should be toggled. More...
 

#define _ASSERT_ENABLE_
#define EXAMPLE_DELAY_MS   100

Delay period between COMPARE interrupts given in milliseconds.

Example delay period between COMPARE interrupts given in milliseconds.

Referenced by main().

#define EXAMPLE_TOGGLE_PIN   AVR32_PIN_PA03

GPIO Line to toggle on compare match.

Toggle PA03 GPIO in the example upon COMPARE interrupts.

Referenced by main(), and tc_irq().

int main ( void  )

Application main loop.

Main function sets the COMPARE register and enables the interrupt for COMPARE match. On every COMPARE match interrupt the GPIO line is toggled.

Note
Use No compiler optimization to visualize the variable updates using Watch Window

References Assert, cpu_irq_disable, cpu_irq_enable, cpu_ms_2_cy(), delay_clock_cycles, EXAMPLE_DELAY_MS, EXAMPLE_TOGGLE_PIN, Get_sys_compare, Get_sys_count, gpio_tgl_gpio_pin(), irq_initialize_vectors, irq_register_handler, Set_sys_compare, sysclk_get_cpu_hz(), sysclk_init(), temp, and toggle_gpio.

Set_sys_compare ( Get_sys_count()+  delay_clock_cycles)

volatile uint32_t delay_clock_cycles
static

Number of clock cycles representing the EXAMPLE_DELAY_MS.

Referenced by main().

volatile uint32_t number_of_compares = 0
static

Counter to store the number for COMPARE interrupts.

toggle_gpio = false
static

Flag to indicate that the GPIO line should be toggled.

COUNT/COMPARE match interrupt handler.

Interrupt handler to set GPIO toggle flag on COUNT COMPARE match and reloads the COMPARE register.

Referenced by main().