# tc.h File Reference

## Detailed Description

Timer/Counter driver for AVR32 UC3.

AVR32 Timer/Counter driver module.

- Compiler: IAR EWAVR32 and GNU GCC for AVR32
- Supported devices: All AVR32 devices with a TC module can be used.
- AppNote:

Author:
  Atmel Corporation: http://www.atmel.com
  Support and FAQ: http://support.atmel.no/

Definition in file tc.h.

`#include <avr32/io.h>`

Go to the source code of this file.

## Data Structures
struct | tc_capture_opt_t
| Parameters when initializing a timer/counter in capture mode. More...
struct | tc_interrupt_t
| Timer/counter interrupts. More...
struct | tc_waveform_opt_t
| Parameters when initializing a timer/counter in waveform mode. More...
## Defines
#define | TC_INVALID_ARGUMENT (-1)
| TC driver functions return value in case of invalid argument(s).
#define | TC_NUMBER_OF_CHANNELS (sizeof(((avr32_tc_t *)0)->channel) / sizeof(avr32_tc_channel_t))
| Number of timer/counter channels.
Burst Signal Selection
#define | TC_BURST_CLK_AND_XC0 AVR32_TC_BURST_CLK_AND_XC0
#define | TC_BURST_CLK_AND_XC1 AVR32_TC_BURST_CLK_AND_XC1
#define | TC_BURST_CLK_AND_XC2 AVR32_TC_BURST_CLK_AND_XC2
#define | TC_BURST_NOT_GATED AVR32_TC_BURST_NOT_GATED
External Clock Signal 0 Selection
#define | TC_CH0_EXT_CLK0_SRC_NO_CLK AVR32_TC_TC0XC0S_NO_CLK
#define | TC_CH0_EXT_CLK0_SRC_TCLK0 AVR32_TC_TC0XC0S_TCLK0
#define | TC_CH0_EXT_CLK0_SRC_TIOA1 AVR32_TC_TC0XC0S_TIOA1
#define | TC_CH0_EXT_CLK0_SRC_TIOA2 AVR32_TC_TC0XC0S_TIOA2
External Clock Signal 1 Selection
#define | TC_CH1_EXT_CLK1_SRC_NO_CLK AVR32_TC_TC1XC1S_NO_CLK
#define | TC_CH1_EXT_CLK1_SRC_TCLK1 AVR32_TC_TC1XC1S_TCLK1
#define | TC_CH1_EXT_CLK1_SRC_TIOA0 AVR32_TC_TC1XC1S_TIOA0
#define | TC_CH1_EXT_CLK1_SRC_TIOA2 AVR32_TC_TC1XC1S_TIOA2
External Clock Signal 2 Selection
#define | TC_CH2_EXT_CLK2_SRC_NO_CLK AVR32_TC_TC2XC2S_NO_CLK
#define | TC_CH2_EXT_CLK2_SRC_TCLK2 AVR32_TC_TC2XC2S_TCLK2
#define | TC_CH2_EXT_CLK2_SRC_TIOA0 AVR32_TC_TC2XC2S_TIOA0
#define | TC_CH2_EXT_CLK2_SRC_TIOA1 AVR32_TC_TC2XC2S_TIOA1
Clock Invert
#define | TC_CLOCK_FALLING_EDGE 1
#define | TC_CLOCK_RISING_EDGE 0
Clock Selection
#define | TC_CLOCK_SOURCE_TC1 AVR32_TC_TCCLKS_TIMER_CLOCK1
#define | TC_CLOCK_SOURCE_TC2 AVR32_TC_TCCLKS_TIMER_CLOCK2
#define | TC_CLOCK_SOURCE_TC3 AVR32_TC_TCCLKS_TIMER_CLOCK3
#define | TC_CLOCK_SOURCE_TC4 AVR32_TC_TCCLKS_TIMER_CLOCK4
#define | TC_CLOCK_SOURCE_TC5 AVR32_TC_TCCLKS_TIMER_CLOCK5
#define | TC_CLOCK_SOURCE_XC0 AVR32_TC_TCCLKS_XC0
#define | TC_CLOCK_SOURCE_XC1 AVR32_TC_TCCLKS_XC1
#define | TC_CLOCK_SOURCE_XC2 AVR32_TC_TCCLKS_XC2
Event/Trigger Actions on Output
#define | TC_EVT_EFFECT_CLEAR AVR32_TC_CLEAR
#define | TC_EVT_EFFECT_NOOP AVR32_TC_NONE
#define | TC_EVT_EFFECT_SET AVR32_TC_SET
#define | TC_EVT_EFFECT_TOGGLE AVR32_TC_TOGGLE
External Event Selection
#define | TC_EXT_EVENT_SEL_TIOB_INPUT AVR32_TC_EEVT_TIOB_INPUT
#define | TC_EXT_EVENT_SEL_XC0_OUTPUT AVR32_TC_EEVT_XC0_OUTPUT
#define | TC_EXT_EVENT_SEL_XC1_OUTPUT AVR32_TC_EEVT_XC1_OUTPUT
#define | TC_EXT_EVENT_SEL_XC2_OUTPUT AVR32_TC_EEVT_XC2_OUTPUT
TIOA or TIOB External Trigger Selection
#define | TC_EXT_TRIG_SEL_TIOA 1
#define | TC_EXT_TRIG_SEL_TIOB 0
RC Compare Trigger Enable
#define | TC_NO_TRIGGER_COMPARE_RC 0
#define | TC_TRIGGER_COMPARE_RC 1
Edge Selection
#define | TC_SEL_EACH_EDGE AVR32_TC_EEVTEDG_BOTH_EDGES
#define | TC_SEL_FALLING_EDGE AVR32_TC_EEVTEDG_NEG_EDGE
#define | TC_SEL_NO_EDGE AVR32_TC_EEVTEDG_NO_EDGE
#define | TC_SEL_RISING_EDGE AVR32_TC_EEVTEDG_POS_EDGE
Waveform Selection
#define | TC_WAVEFORM_SEL_UP_MODE AVR32_TC_WAVSEL_UP_NO_AUTO
#define | TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER AVR32_TC_WAVSEL_UP_AUTO
#define | TC_WAVEFORM_SEL_UPDOWN_MODE AVR32_TC_WAVSEL_UPDOWN_NO_AUTO
#define | TC_WAVEFORM_SEL_UPDOWN_MODE_RC_TRIGGER AVR32_TC_WAVSEL_UPDOWN_AUTO
## Functions
int | tc_configure_interrupts (volatile avr32_tc_t *tc, unsigned int channel, const tc_interrupt_t *bitfield)
| Enables various timer/counter interrupts.
int | tc_get_interrupt_settings (volatile avr32_tc_t *tc, unsigned int channel)
| Reads timer/counter interrupt settings.
int | tc_init_capture (volatile avr32_tc_t *tc, const tc_capture_opt_t *opt)
| Sets options for timer/counter capture initialization.
int | tc_init_waveform (volatile avr32_tc_t *tc, const tc_waveform_opt_t *opt)
| Sets options for timer/counter waveform initialization.
int | tc_read_ra (volatile avr32_tc_t *tc, unsigned int channel)
| Reads the channel's RA register and returns the value.
int | tc_read_rb (volatile avr32_tc_t *tc, unsigned int channel)
| Reads the channel's RB register and returns the value.
int | tc_read_rc (volatile avr32_tc_t *tc, unsigned int channel)
| Reads the channel's RC register and returns the value.
int | tc_read_sr (volatile avr32_tc_t *tc, unsigned int channel)
| Reads the status register.
int | tc_read_tc (volatile avr32_tc_t *tc, unsigned int channel)
| Reads the channel's TC counter and returns the value.
int | tc_select_external_clock (volatile avr32_tc_t *tc, unsigned int channel, unsigned int ext_clk_sig_src)
| Selects which external clock to use and how to configure it.
int | tc_software_trigger (volatile avr32_tc_t *tc, unsigned int channel)
| Performs a software trigger: the counter is reset and the clock is started.
int | tc_start (volatile avr32_tc_t *tc, unsigned int channel)
| Starts a timer/counter.
int | tc_stop (volatile avr32_tc_t *tc, unsigned int channel)
| Stops a timer/counter.
void | tc_sync_start (volatile avr32_tc_t *tc)
| Start all TC channels simultaneously.
void | tc_sync_trigger (volatile avr32_tc_t *tc)
| Asserts a SYNC signal to generate a software trigger and reset all channels.
int | tc_write_ra (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value)
| Writes a value to the channel's RA register.
int | tc_write_rb (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value)
| Writes a value to the channel's RB register.
int | tc_write_rc (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value)
| Writes a value to the channel's RC register.

## Define Documentation

#define TC_BURST_CLK_AND_XC0 AVR32_TC_BURST_CLK_AND_XC0

Definition at line 138 of file tc.h.

#define TC_BURST_CLK_AND_XC1 AVR32_TC_BURST_CLK_AND_XC1

Definition at line 139 of file tc.h.

#define TC_BURST_CLK_AND_XC2 AVR32_TC_BURST_CLK_AND_XC2

Definition at line 140 of file tc.h.

#define TC_BURST_NOT_GATED AVR32_TC_BURST_NOT_GATED

Definition at line 137 of file tc.h.

Referenced by main().

#define TC_CH0_EXT_CLK0_SRC_NO_CLK AVR32_TC_TC0XC0S_NO_CLK

Definition at line 61 of file tc.h.

#define TC_CH0_EXT_CLK0_SRC_TCLK0 AVR32_TC_TC0XC0S_TCLK0

Definition at line 60 of file tc.h.

#define TC_CH0_EXT_CLK0_SRC_TIOA1 AVR32_TC_TC0XC0S_TIOA1

Definition at line 62 of file tc.h.

#define TC_CH0_EXT_CLK0_SRC_TIOA2 AVR32_TC_TC0XC0S_TIOA2

Definition at line 63 of file tc.h.

#define TC_CH1_EXT_CLK1_SRC_NO_CLK AVR32_TC_TC1XC1S_NO_CLK

Definition at line 70 of file tc.h.

#define TC_CH1_EXT_CLK1_SRC_TCLK1 AVR32_TC_TC1XC1S_TCLK1

Definition at line 69 of file tc.h.

#define TC_CH1_EXT_CLK1_SRC_TIOA0 AVR32_TC_TC1XC1S_TIOA0

Definition at line 71 of file tc.h.

#define TC_CH1_EXT_CLK1_SRC_TIOA2 AVR32_TC_TC1XC1S_TIOA2

Definition at line 72 of file tc.h.

#define TC_CH2_EXT_CLK2_SRC_NO_CLK AVR32_TC_TC2XC2S_NO_CLK

Definition at line 79 of file tc.h.

#define TC_CH2_EXT_CLK2_SRC_TCLK2 AVR32_TC_TC2XC2S_TCLK2

Definition at line 78 of file tc.h.

#define TC_CH2_EXT_CLK2_SRC_TIOA0 AVR32_TC_TC2XC2S_TIOA0

Definition at line 80 of file tc.h.

#define TC_CH2_EXT_CLK2_SRC_TIOA1 AVR32_TC_TC2XC2S_TIOA1

Definition at line 81 of file tc.h.

#define TC_CLOCK_FALLING_EDGE 1

Definition at line 147 of file tc.h.

#define TC_CLOCK_RISING_EDGE 0

Definition at line 146 of file tc.h.

Referenced by main().

#define TC_CLOCK_SOURCE_TC1 AVR32_TC_TCCLKS_TIMER_CLOCK1

Definition at line 153 of file tc.h.

#define TC_CLOCK_SOURCE_TC2 AVR32_TC_TCCLKS_TIMER_CLOCK2

Definition at line 154 of file tc.h.

#define TC_CLOCK_SOURCE_TC3 AVR32_TC_TCCLKS_TIMER_CLOCK3

Definition at line 155 of file tc.h.

Referenced by main().

#define TC_CLOCK_SOURCE_TC4 AVR32_TC_TCCLKS_TIMER_CLOCK4

Definition at line 156 of file tc.h.

#define TC_CLOCK_SOURCE_TC5 AVR32_TC_TCCLKS_TIMER_CLOCK5

Definition at line 157 of file tc.h.

#define TC_CLOCK_SOURCE_XC0 AVR32_TC_TCCLKS_XC0

Definition at line 158 of file tc.h.

#define TC_CLOCK_SOURCE_XC1 AVR32_TC_TCCLKS_XC1

Definition at line 159 of file tc.h.

#define TC_CLOCK_SOURCE_XC2 AVR32_TC_TCCLKS_XC2

Definition at line 160 of file tc.h.

#define TC_EVT_EFFECT_CLEAR AVR32_TC_CLEAR

Definition at line 89 of file tc.h.

#define TC_EVT_EFFECT_NOOP AVR32_TC_NONE

Definition at line 87 of file tc.h.

Referenced by main().

#define TC_EVT_EFFECT_SET AVR32_TC_SET

Definition at line 88 of file tc.h.

#define TC_EVT_EFFECT_TOGGLE AVR32_TC_TOGGLE

Definition at line 90 of file tc.h.

Referenced by main().

#define TC_EXT_EVENT_SEL_TIOB_INPUT AVR32_TC_EEVT_TIOB_INPUT

Definition at line 119 of file tc.h.

Referenced by main().

#define TC_EXT_EVENT_SEL_XC0_OUTPUT AVR32_TC_EEVT_XC0_OUTPUT

Definition at line 120 of file tc.h.

#define TC_EXT_EVENT_SEL_XC1_OUTPUT AVR32_TC_EEVT_XC1_OUTPUT

Definition at line 121 of file tc.h.

#define TC_EXT_EVENT_SEL_XC2_OUTPUT AVR32_TC_EEVT_XC2_OUTPUT

Definition at line 122 of file tc.h.

#define TC_EXT_TRIG_SEL_TIOA 1

Definition at line 112 of file tc.h.

#define TC_EXT_TRIG_SEL_TIOB 0

Definition at line 113 of file tc.h.

#define TC_INVALID_ARGUMENT (-1)

TC driver functions return value in case of invalid argument(s).

Definition at line 52 of file tc.h.

Referenced by tc_configure_interrupts(), tc_get_interrupt_settings(), tc_init_capture(), tc_init_waveform(), tc_read_ra(), tc_read_rb(), tc_read_rc(), tc_read_sr(), tc_read_tc(), tc_select_external_clock(), tc_software_trigger(), tc_start(), tc_stop(), tc_write_ra(), tc_write_rb(), and tc_write_rc().

#define TC_NO_TRIGGER_COMPARE_RC 0

Definition at line 96 of file tc.h.

#define TC_NUMBER_OF_CHANNELS (sizeof(((avr32_tc_t *)0)->channel) / sizeof(avr32_tc_channel_t))

Number of timer/counter channels.

Definition at line 55 of file tc.h.

Referenced by tc_configure_interrupts(), tc_get_interrupt_settings(), tc_init_capture(), tc_init_waveform(), tc_read_ra(), tc_read_rb(), tc_read_rc(), tc_read_sr(), tc_read_tc(), tc_select_external_clock(), tc_software_trigger(), tc_start(), tc_stop(), tc_sync_start(), tc_write_ra(), tc_write_rb(), and tc_write_rc().

#define TC_SEL_EACH_EDGE AVR32_TC_EEVTEDG_BOTH_EDGES

Definition at line 131 of file tc.h.

#define TC_SEL_FALLING_EDGE AVR32_TC_EEVTEDG_NEG_EDGE

Definition at line 130 of file tc.h.

#define TC_SEL_NO_EDGE AVR32_TC_EEVTEDG_NO_EDGE

Definition at line 128 of file tc.h.

Referenced by main().

#define TC_SEL_RISING_EDGE AVR32_TC_EEVTEDG_POS_EDGE

Definition at line 129 of file tc.h.

#define TC_TRIGGER_COMPARE_RC 1

Definition at line 97 of file tc.h.

#define TC_WAVEFORM_SEL_UP_MODE AVR32_TC_WAVSEL_UP_NO_AUTO

Definition at line 103 of file tc.h.

Referenced by main().

#define TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER AVR32_TC_WAVSEL_UP_AUTO

Definition at line 104 of file tc.h.

#define TC_WAVEFORM_SEL_UPDOWN_MODE AVR32_TC_WAVSEL_UPDOWN_NO_AUTO

Definition at line 105 of file tc.h.

#define TC_WAVEFORM_SEL_UPDOWN_MODE_RC_TRIGGER AVR32_TC_WAVSEL_UPDOWN_AUTO

Definition at line 106 of file tc.h.

## Function Documentation

int tc_configure_interrupts | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel,
|  | const tc_interrupt_t * | bitfield |
| ) |  |  |

Enables various timer/counter interrupts.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.
  | bitfield | The interrupt enable configuration.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 60 of file tc.c.

References tc_interrupt_t::covfs, tc_interrupt_t::cpas, tc_interrupt_t::cpbs, tc_interrupt_t::cpcs, tc_interrupt_t::etrgs, tc_interrupt_t::ldras, tc_interrupt_t::ldrbs, tc_interrupt_t::lovrs, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00061 {
    00062   Bool global_interrupt_enabled = Is_global_interrupt_enabled();
    00063
    00064   // Check for valid input.
    00065   if (channel >= TC_NUMBER_OF_CHANNELS)
    00066     return TC_INVALID_ARGUMENT;
    00067
    00068   // Enable the appropriate interrupts.
    00069   tc->channel[channel].ier = bitfield->etrgs << AVR32_TC_ETRGS_OFFSET |
    00070                              bitfield->ldrbs << AVR32_TC_LDRBS_OFFSET |
    00071                              bitfield->ldras << AVR32_TC_LDRAS_OFFSET |
    00072                              bitfield->cpcs << AVR32_TC_CPCS_OFFSET |
    00073                              bitfield->cpbs << AVR32_TC_CPBS_OFFSET |
    00074                              bitfield->cpas << AVR32_TC_CPAS_OFFSET |
    00075                              bitfield->lovrs << AVR32_TC_LOVRS_OFFSET |
    00076                              bitfield->covfs << AVR32_TC_COVFS_OFFSET;
    00077
    00078   // Disable the appropriate interrupts.
    00079   if (global_interrupt_enabled) Disable_global_interrupt();
    00080   tc->channel[channel].idr = (~bitfield->etrgs & 1) << AVR32_TC_ETRGS_OFFSET |
    00081                              (~bitfield->ldrbs & 1) << AVR32_TC_LDRBS_OFFSET |
    00082                              (~bitfield->ldras & 1) << AVR32_TC_LDRAS_OFFSET |
    00083                              (~bitfield->cpcs & 1) << AVR32_TC_CPCS_OFFSET |
    00084                              (~bitfield->cpbs & 1) << AVR32_TC_CPBS_OFFSET |
    00085                              (~bitfield->cpas & 1) << AVR32_TC_CPAS_OFFSET |
    00086                              (~bitfield->lovrs & 1) << AVR32_TC_LOVRS_OFFSET |
    00087                              (~bitfield->covfs & 1) << AVR32_TC_COVFS_OFFSET;
    00088   tc->channel[channel].sr;
    00089   if (global_interrupt_enabled) Enable_global_interrupt();
    00090
    00091   return 0;
    00092 }

int tc_get_interrupt_settings | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads timer/counter interrupt settings.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | The interrupt enable configuration organized according to tc_interrupt_t.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 50 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00051 {
    00052   // Check for valid input.
    00053   if (channel >= TC_NUMBER_OF_CHANNELS)
    00054     return TC_INVALID_ARGUMENT;
    00055
    00056   return tc->channel[channel].imr;
    00057 }

int tc_init_capture | ( | volatile avr32_tc_t * | tc,
|  | const tc_capture_opt_t * | opt |
| ) |  |  |

Sets options for timer/counter capture initialization.

Parameters:

  | tc | Pointer to the TC instance to access.
  | opt | Options for capture mode.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 109 of file tc.c.

References tc_capture_opt_t::abetrg, tc_capture_opt_t::burst, tc_capture_opt_t::channel, tc_capture_opt_t::clki, tc_capture_opt_t::cpctrg, tc_capture_opt_t::etrgedg, tc_capture_opt_t::ldbdis, tc_capture_opt_t::ldbstop, tc_capture_opt_t::ldra, tc_capture_opt_t::ldrb, TC_INVALID_ARGUMENT, TC_NUMBER_OF_CHANNELS, and tc_capture_opt_t::tcclks.

    00110 {
    00111   // Check for valid input.
    00112   if (opt->channel >= TC_NUMBER_OF_CHANNELS)
    00113     return TC_INVALID_ARGUMENT;
    00114
    00115   // MEASURE SIGNALS: Capture operating mode.
    00116   tc->channel[opt->channel].cmr = opt->ldrb << AVR32_TC_LDRB_OFFSET |
    00117                                   opt->ldra << AVR32_TC_LDRA_OFFSET |
    00118                                   0 << AVR32_TC_WAVE_OFFSET |
    00119                                   opt->cpctrg << AVR32_TC_CPCTRG_OFFSET |
    00120                                   opt->abetrg << AVR32_TC_ABETRG_OFFSET |
    00121                                   opt->etrgedg << AVR32_TC_ETRGEDG_OFFSET|
    00122                                   opt->ldbdis << AVR32_TC_LDBDIS_OFFSET |
    00123                                   opt->ldbstop << AVR32_TC_LDBSTOP_OFFSET |
    00124                                   opt->burst << AVR32_TC_BURST_OFFSET |
    00125                                   opt->clki << AVR32_TC_CLKI_OFFSET |
    00126                                   opt->tcclks << AVR32_TC_TCCLKS_OFFSET;
    00127
    00128   return 0;
    00129 }

int tc_init_waveform | ( | volatile avr32_tc_t * | tc,
|  | const tc_waveform_opt_t * | opt |
| ) |  |  |

Sets options for timer/counter waveform initialization.

Parameters:

  | tc | Pointer to the TC instance to access.
  | opt | Options for waveform generation.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 132 of file tc.c.

References tc_waveform_opt_t::acpa, tc_waveform_opt_t::acpc, tc_waveform_opt_t::aeevt, tc_waveform_opt_t::aswtrg, tc_waveform_opt_t::bcpb, tc_waveform_opt_t::bcpc, tc_waveform_opt_t::beevt, tc_waveform_opt_t::bswtrg, tc_waveform_opt_t::burst, tc_waveform_opt_t::channel, tc_waveform_opt_t::clki, tc_waveform_opt_t::cpcdis, tc_waveform_opt_t::cpcstop, tc_waveform_opt_t::eevt, tc_waveform_opt_t::eevtedg, tc_waveform_opt_t::enetrg, TC_INVALID_ARGUMENT, TC_NUMBER_OF_CHANNELS, tc_waveform_opt_t::tcclks, and tc_waveform_opt_t::wavsel.

Referenced by main().

    00133 {
    00134   // Check for valid input.
    00135   if (opt->channel >= TC_NUMBER_OF_CHANNELS)
    00136     return TC_INVALID_ARGUMENT;
    00137
    00138   // GENERATE SIGNALS: Waveform operating mode.
    00139   tc->channel[opt->channel].cmr = opt->bswtrg << AVR32_TC_BSWTRG_OFFSET |
    00140                                   opt->beevt << AVR32_TC_BEEVT_OFFSET |
    00141                                   opt->bcpc << AVR32_TC_BCPC_OFFSET |
    00142                                   opt->bcpb << AVR32_TC_BCPB_OFFSET |
    00143                                   opt->aswtrg << AVR32_TC_ASWTRG_OFFSET |
    00144                                   opt->aeevt << AVR32_TC_AEEVT_OFFSET |
    00145                                   opt->acpc << AVR32_TC_ACPC_OFFSET |
    00146                                   opt->acpa << AVR32_TC_ACPA_OFFSET |
    00147                                   1 << AVR32_TC_WAVE_OFFSET |
    00148                                   opt->wavsel << AVR32_TC_WAVSEL_OFFSET |
    00149                                   opt->enetrg << AVR32_TC_ENETRG_OFFSET |
    00150                                   opt->eevt << AVR32_TC_EEVT_OFFSET |
    00151                                   opt->eevtedg << AVR32_TC_EEVTEDG_OFFSET |
    00152                                   opt->cpcdis << AVR32_TC_CPCDIS_OFFSET |
    00153                                   opt->cpcstop << AVR32_TC_CPCSTOP_OFFSET |
    00154                                   opt->burst << AVR32_TC_BURST_OFFSET |
    00155                                   opt->clki << AVR32_TC_CLKI_OFFSET |
    00156                                   opt->tcclks << AVR32_TC_TCCLKS_OFFSET;
    00157
    00158   return 0;
    00159 }

int tc_read_ra | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads the channel's RA register and returns the value.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | RA register value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 240 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00241 {
    00242   // Check for valid input.
    00243   if (channel >= TC_NUMBER_OF_CHANNELS)
    00244     return TC_INVALID_ARGUMENT;
    00245
    00246   return Rd_bitfield(tc->channel[channel].ra, AVR32_TC_RA_MASK);
    00247 }

int tc_read_rb | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads the channel's RB register and returns the value.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | RB register value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 250 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00251 {
    00252   // Check for valid input.
    00253   if (channel >= TC_NUMBER_OF_CHANNELS)
    00254     return TC_INVALID_ARGUMENT;
    00255
    00256   return Rd_bitfield(tc->channel[channel].rb, AVR32_TC_RB_MASK);
    00257 }

int tc_read_rc | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads the channel's RC register and returns the value.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | RC register value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 260 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00261 {
    00262   // Check for valid input.
    00263   if (channel >= TC_NUMBER_OF_CHANNELS)
    00264     return TC_INVALID_ARGUMENT;
    00265
    00266   return Rd_bitfield(tc->channel[channel].rc, AVR32_TC_RC_MASK);
    00267 }

int tc_read_sr | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads the status register.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | Status register value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 220 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00221 {
    00222   // Check for valid input.
    00223   if (channel >= TC_NUMBER_OF_CHANNELS)
    00224     return TC_INVALID_ARGUMENT;
    00225
    00226   return tc->channel[channel].sr;
    00227 }

int tc_read_tc | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Reads the channel's TC counter and returns the value.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | >=0 | TC counter value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 230 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00231 {
    00232   // Check for valid input.
    00233   if (channel >= TC_NUMBER_OF_CHANNELS)
    00234     return TC_INVALID_ARGUMENT;
    00235
    00236   return Rd_bitfield(tc->channel[channel].cv, AVR32_TC_CV_MASK);
    00237 }

int tc_select_external_clock | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel,
|  | unsigned int | ext_clk_sig_src |
| ) |  |  |

Selects which external clock to use and how to configure it.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.
  | ext_clk_sig_src | External clock signal selection: `TC_CH0_EXT_CLK0_SRC_TCLK0`; `TC_CH0_EXT_CLK0_SRC_NO_CLK`; `TC_CH0_EXT_CLK0_SRC_TIOA1`; `TC_CH0_EXT_CLK0_SRC_TIOA2`; `TC_CH1_EXT_CLK1_SRC_TCLK1`; `TC_CH1_EXT_CLK1_SRC_NO_CLK`; `TC_CH1_EXT_CLK1_SRC_TIOA0`; `TC_CH1_EXT_CLK1_SRC_TIOA2`; `TC_CH2_EXT_CLK2_SRC_TCLK2`; `TC_CH2_EXT_CLK2_SRC_NO_CLK`; `TC_CH2_EXT_CLK2_SRC_TIOA0`; `TC_CH2_EXT_CLK2_SRC_TIOA1`.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 95 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00096 {
    00097   // Check for valid input.
    00098   if (channel >= TC_NUMBER_OF_CHANNELS || ext_clk_sig_src >= 1 << AVR32_TC_BMR_TC0XC0S_SIZE)
    00099     return TC_INVALID_ARGUMENT;
    00100
    00101   // Clear bit-field and set the correct behavior.
    00102   tc->bmr = (tc->bmr & ~(AVR32_TC_BMR_TC0XC0S_MASK << (channel * AVR32_TC_BMR_TC0XC0S_SIZE))) |
    00103             (ext_clk_sig_src << (channel * AVR32_TC_BMR_TC0XC0S_SIZE));
    00104
    00105   return 0;
    00106 }

int tc_software_trigger | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Performs a software trigger: the counter is reset and the clock is started.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 188 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00189 {
    00190   // Check for valid input.
    00191   if (channel >= TC_NUMBER_OF_CHANNELS)
    00192     return TC_INVALID_ARGUMENT;
    00193
    00194   // Reset the selected timer/counter channel.
    00195   tc->channel[channel].ccr = AVR32_TC_SWTRG_MASK;
    00196
    00197   return 0;
    00198 }

int tc_start | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Starts a timer/counter.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 162 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

Referenced by main().

    00163 {
    00164   // Check for valid input.
    00165   if (channel >= TC_NUMBER_OF_CHANNELS)
    00166     return TC_INVALID_ARGUMENT;
    00167
    00168   // Enable, reset and start the selected timer/counter channel.
    00169   tc->channel[channel].ccr = AVR32_TC_SWTRG_MASK | AVR32_TC_CLKEN_MASK;
    00170
    00171   return 0;
    00172 }

int tc_stop | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel |
| ) |  |  |

Stops a timer/counter.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.

Return values:

  | 0 | Success.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 175 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00176 {
    00177   // Check for valid input.
    00178   if (channel >= TC_NUMBER_OF_CHANNELS)
    00179     return TC_INVALID_ARGUMENT;
    00180
    00181   // Disable the selected timer/counter channel.
    00182   tc->channel[channel].ccr = AVR32_TC_CLKDIS_MASK;
    00183
    00184   return 0;
    00185 }

void tc_sync_start | ( | volatile avr32_tc_t * | tc | ) |

Start all TC channels simultaneously.

Parameters:

  | tc | Pointer to the TC instance to access.

Definition at line 208 of file tc.c.

References TC_NUMBER_OF_CHANNELS.

    00209 {
    00210   unsigned int i;
    00211   // Enable the clock for each channel.
    00212   for(i=0; i<TC_NUMBER_OF_CHANNELS;i++)
    00213     tc->channel[i].ccr = AVR32_TC_CLKEN_MASK;
    00214
    00215   // Reset all channels of the selected timer/counter.
    00216   tc->bcr = AVR32_TC_BCR_SYNC_MASK;
    00217 }

void tc_sync_trigger | ( | volatile avr32_tc_t * | tc | ) |

Asserts a SYNC signal to generate a software trigger and reset all channels.

Parameters:

  | tc | Pointer to the TC instance to access.

Definition at line 201 of file tc.c.

    00202 {
    00203   // Reset all channels of the selected timer/counter.
    00204   tc->bcr = AVR32_TC_BCR_SYNC_MASK;
    00205 }

int tc_write_ra | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel,
|  | unsigned short | value |
| ) |  |  |

Writes a value to the channel's RA register.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.
  | value | Value to write to the RA register.

Return values:

  | >=0 | Written value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 270 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

Referenced by main().

    00271 {
    00272   // Check for valid input.
    00273   if (channel >= TC_NUMBER_OF_CHANNELS)
    00274     return TC_INVALID_ARGUMENT;
    00275
    00276   // This function is only available in WAVEFORM mode.
    00277   if (Tst_bits(tc->channel[channel].cmr, AVR32_TC_WAVE_MASK))
    00278     Wr_bitfield(tc->channel[channel].ra, AVR32_TC_RA_MASK, value);
    00279
    00280   return value;
    00281 }

int tc_write_rb | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel,
|  | unsigned short | value |
| ) |  |  |

Writes a value to the channel's RB register.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.
  | value | Value to write to the RB register.

Return values:

  | >=0 | Written value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 284 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

    00285 {
    00286   // Check for valid input.
    00287   if (channel >= TC_NUMBER_OF_CHANNELS)
    00288     return TC_INVALID_ARGUMENT;
    00289
    00290   // This function is only available in WAVEFORM mode.
    00291   if (Tst_bits(tc->channel[channel].cmr, AVR32_TC_WAVE_MASK))
    00292     Wr_bitfield(tc->channel[channel].rb, AVR32_TC_RB_MASK, value);
    00293
    00294   return value;
    00295 }

int tc_write_rc | ( | volatile avr32_tc_t * | tc,
|  | unsigned int | channel,
|  | unsigned short | value |
| ) |  |  |

Writes a value to the channel's RC register.

Parameters:

  | tc | Pointer to the TC instance to access.
  | channel | The TC instance channel to access.
  | value | Value to write to the RC register.

Return values:

  | >=0 | Written value.
  | TC_INVALID_ARGUMENT | Invalid argument(s).

Definition at line 298 of file tc.c.

References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.

Referenced by main().

    00299 {
    00300   // Check for valid input.
    00301   if (channel >= TC_NUMBER_OF_CHANNELS)
    00302     return TC_INVALID_ARGUMENT;
    00303
    00304   // This function is only available in WAVEFORM mode.
    00305   if (Tst_bits(tc->channel[channel].cmr, AVR32_TC_WAVE_MASK))
    00306     Wr_bitfield(tc->channel[channel].rc, AVR32_TC_RC_MASK, value);
    00307
    00308   return value;
    00309 }