Atmel Software Framework

tc_simulator_example1.c File Reference

TC Example application for AVR UC3 TC driver.

Copyright (c) 2011 Atmel Corporation. All rights reserved.

#include <stdint.h>
#include <stdbool.h>
#include "tc.h"
#include "sysclk.h"
#include "board.h"
#include "gpio.h"
#include "intc.h"
#include "conf_example.h"


int main (void)
 Main function. More...
static void tc_init (volatile avr32_tc_t *tc)
 TC Initialization. More...
static void tc_irq (void)
 TC interrupt. More...


static volatile uint32_t tc_tick = 0
static volatile bool update_timer = true

int main ( void  )

Main function.

Main function performs the following:

  • Configure the TC Module
  • Register the TC interrupt
  • Configure, enable the CPCS (RC compare match) interrupt,
  • and start a TC channel in waveform mode
the call to sysclk_init() will disable all non-vital peripheral clocks, except for the peripheral clocks explicitly enabled in conf_clock.h.

References cpu_irq_disable, cpu_irq_enable, EXAMPLE_TC, INTC_init_interrupts(), INTC_register_interrupt(), sysclk_enable_peripheral_clock(), sysclk_init(), tc_init(), tc_irq(), timer, and update_timer.

static void tc_init ( volatile avr32_tc_t *  tc)

TC Initialization.

Initializes and start the TC module with the following:

  • Counter in Up mode with automatic reset on RC compare match.
  • fPBA/8 is used as clock source for TC
  • Enables RC compare match interrupt
    tcBase address of the TC module

References tc_waveform_opt_t::channel, tc_interrupt_t::etrgs, sysclk_get_pba_hz(), TC_CLOCK_SOURCE_TC3, tc_configure_interrupts(), TC_EVT_EFFECT_NOOP, tc_init_waveform(), TC_SEL_NO_EDGE, tc_start(), TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, and tc_write_rc().

Referenced by main().

static void tc_irq ( void  )

TC interrupt.

The ISR handles RC compare interrupt and sets the update_timer flag to update the timer value.

References EXAMPLE_TC, EXAMPLE_TOGGLE_PIN, gpio_tgl_gpio_pin(), tc_read_sr(), tc_tick, and update_timer.

Referenced by init_timer_isr(), and main().

volatile uint32_t tc_tick = 0

Referenced by tc_irq().

volatile bool update_timer = true

Referenced by main(), and tc_irq().