Microchip® Advanced Software Framework

cycle_counter_example.c File Reference

CPU Cycle Counter Example application for AVR UC3.

Copyright (c) 2013-2018 Microchip Technology Inc. and its subsidiaries.

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

Macros

#define _ASSERT_ENABLE_
 
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 bool compare_isr_fired = true
 Flag to indicate that the ISR has fired. More...
 
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...
 

#define _ASSERT_ENABLE_
#define EXAMPLE_DELAY_MS   100

Delay period between COMPARE interrupts given in milliseconds.

Note
Example delay -> 100 ms in this example.

Referenced by main().

int main ( void  )

Application main loop.

Main function sets the COMPARE register and enables the interrupt for COMPARE match. On every COMPARE match interrupt, a message is displayed and LEDS are switched ON alternatively.

References Assert, AVR32_CORE_COMPARE_IRQ, compare_isr_fired, cpu_irq_disable, cpu_irq_enable, cpu_ms_2_cy(), delay_clock_cycles, EXAMPLE_DELAY_MS, Get_sys_compare, Get_sys_count, init_dbg_rs232(), irq_initialize_vectors, irq_register_handler, LED0, LED1, LED2, LED3, LED_Display_Field(), LED_Toggle(), max, number_of_compares, print_dbg(), print_dbg_ulong(), Set_sys_compare(), sysclk_get_cpu_hz(), sysclk_get_pba_hz(), and sysclk_init().

Set_sys_compare ( Get_sys_count()+  delay_clock_cycles)

Referenced by main().

compare_isr_fired = true
static

Flag to indicate that the ISR has fired.

COUNT/COMPARE match interrupt handler.

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

Referenced by main().

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.

Referenced by main().