Microchip® Advanced Software Framework

tc_simulator_example1.c File Reference

TC Example application for AVR UC3 TC driver.

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

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

Functions

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...
 

Variables

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
Note
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, EXAMPLE_TC_IRQ, EXAMPLE_TC_IRQ_PRIORITY, INTC_init_interrupts(), INTC_register_interrupt(), sysclk_enable_peripheral_clock(), sysclk_init(), tc_init(), tc_irq(), and update_timer.

static void tc_init ( volatile avr32_tc_t *  tc)
static

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
    Parameters
    tcBase address of the TC module

References tc_waveform_opt_t::channel, tc_interrupt_t::etrgs, EXAMPLE_TC_CHANNEL, 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  )
static

TC interrupt.

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

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

Referenced by main().

volatile uint32_t tc_tick = 0
static

Referenced by tc_irq().

volatile bool update_timer = true
static

Referenced by main(), and tc_irq().