Driver for the TC (Timer/Counter).
The TC includes three identical 16-bit Timer/Counter channels. Each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse width modulation.
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... | |
Macros | |
#define | TC_INVALID_ARGUMENT (-1) |
TC driver functions return value in case of invalid argument(s). More... | |
#define | TC_NUMBER_OF_CHANNELS (sizeof(((avr32_tc_t *)0)->channel) / sizeof(avr32_tc_channel_t)) |
Number of timer/counter channels. More... | |
Functions | |
int | tc_configure_interrupts (volatile avr32_tc_t *tc, unsigned int channel, const tc_interrupt_t *bitfield) |
Enables various timer/counter interrupts. More... | |
int | tc_get_interrupt_settings (volatile avr32_tc_t *tc, unsigned int channel) |
Reads timer/counter interrupt settings. More... | |
int | tc_init_capture (volatile avr32_tc_t *tc, const tc_capture_opt_t *opt) |
Sets options for timer/counter capture initialization. More... | |
int | tc_init_waveform (volatile avr32_tc_t *tc, const tc_waveform_opt_t *opt) |
Sets options for timer/counter waveform initialization. More... | |
int | tc_read_ra (volatile avr32_tc_t *tc, unsigned int channel) |
Reads the channel's RA register and returns the value. More... | |
int | tc_read_rb (volatile avr32_tc_t *tc, unsigned int channel) |
Reads the channel's RB register and returns the value. More... | |
int | tc_read_rc (volatile avr32_tc_t *tc, unsigned int channel) |
Reads the channel's RC register and returns the value. More... | |
int | tc_read_sr (volatile avr32_tc_t *tc, unsigned int channel) |
Reads the status register. More... | |
int | tc_read_tc (volatile avr32_tc_t *tc, unsigned int channel) |
Reads the channel's TC counter and returns the value. More... | |
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. More... | |
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. More... | |
int | tc_start (volatile avr32_tc_t *tc, unsigned int channel) |
Starts a timer/counter. More... | |
int | tc_stop (volatile avr32_tc_t *tc, unsigned int channel) |
Stops a timer/counter. More... | |
void | tc_sync_start (volatile avr32_tc_t *tc) |
Start all TC channels simultaneously. More... | |
void | tc_sync_trigger (volatile avr32_tc_t *tc) |
Asserts a SYNC signal to generate a software trigger and reset all channels. More... | |
int | tc_write_ra (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value) |
Writes a value to the channel's RA register. More... | |
int | tc_write_rb (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value) |
Writes a value to the channel's RB register. More... | |
int | tc_write_rc (volatile avr32_tc_t *tc, unsigned int channel, unsigned short value) |
Writes a value to the channel's RC register. More... | |
External Clock Signal 0 Selection | |
#define | TC_CH0_EXT_CLK0_SRC_TCLK0 AVR32_TC_TC0XC0S_TCLK0 |
#define | TC_CH0_EXT_CLK0_SRC_NO_CLK AVR32_TC_TC0XC0S_NO_CLK |
#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_TCLK1 AVR32_TC_TC1XC1S_TCLK1 |
#define | TC_CH1_EXT_CLK1_SRC_NO_CLK AVR32_TC_TC1XC1S_NO_CLK |
#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_TCLK2 AVR32_TC_TC2XC2S_TCLK2 |
#define | TC_CH2_EXT_CLK2_SRC_NO_CLK AVR32_TC_TC2XC2S_NO_CLK |
#define | TC_CH2_EXT_CLK2_SRC_TIOA0 AVR32_TC_TC2XC2S_TIOA0 |
#define | TC_CH2_EXT_CLK2_SRC_TIOA1 AVR32_TC_TC2XC2S_TIOA1 |
Event/Trigger Actions on Output | |
#define | TC_EVT_EFFECT_NOOP AVR32_TC_NONE |
#define | TC_EVT_EFFECT_SET AVR32_TC_SET |
#define | TC_EVT_EFFECT_CLEAR AVR32_TC_CLEAR |
#define | TC_EVT_EFFECT_TOGGLE AVR32_TC_TOGGLE |
RC Compare Trigger Enable | |
#define | TC_NO_TRIGGER_COMPARE_RC 0 |
#define | TC_TRIGGER_COMPARE_RC 1 |
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 |
TIOA or TIOB External Trigger Selection | |
#define | TC_EXT_TRIG_SEL_TIOA 1 |
#define | TC_EXT_TRIG_SEL_TIOB 0 |
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 |
Edge Selection | |
#define | TC_SEL_NO_EDGE AVR32_TC_EEVTEDG_NO_EDGE |
#define | TC_SEL_RISING_EDGE AVR32_TC_EEVTEDG_POS_EDGE |
#define | TC_SEL_FALLING_EDGE AVR32_TC_EEVTEDG_NEG_EDGE |
#define | TC_SEL_EACH_EDGE AVR32_TC_EEVTEDG_BOTH_EDGES |
Burst Signal Selection | |
#define | TC_BURST_NOT_GATED AVR32_TC_BURST_NOT_GATED |
#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 |
Clock Invert | |
#define | TC_CLOCK_RISING_EDGE 0 |
#define | TC_CLOCK_FALLING_EDGE 1 |
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 |
#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 |
#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 |
#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 |
#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 |
#define TC_CLOCK_FALLING_EDGE 1 |
#define TC_CLOCK_RISING_EDGE 0 |
#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 |
#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 |
#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 |
#define TC_EXT_TRIG_SEL_TIOA 1 |
#define TC_EXT_TRIG_SEL_TIOB 0 |
#define TC_INVALID_ARGUMENT (-1) |
TC driver functions return value in case of invalid argument(s).
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 |
#define TC_NUMBER_OF_CHANNELS (sizeof(((avr32_tc_t *)0)->channel) / sizeof(avr32_tc_channel_t)) |
Number of timer/counter channels.
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 |
#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 |
#define TC_TRIGGER_COMPARE_RC 1 |
#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 |
int tc_configure_interrupts | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel, | ||
const tc_interrupt_t * | bitfield | ||
) |
Enables various timer/counter interrupts.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
bitfield | The interrupt enable configuration. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References tc_interrupt_t::covfs, tc_interrupt_t::cpas, tc_interrupt_t::cpbs, tc_interrupt_t::cpcs, Disable_global_interrupt, Enable_global_interrupt, tc_interrupt_t::etrgs, Is_global_interrupt_enabled, tc_interrupt_t::ldras, tc_interrupt_t::ldrbs, tc_interrupt_t::lovrs, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_get_interrupt_settings | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads timer/counter interrupt settings.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | The interrupt enable configuration organized according to tc_interrupt_t. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_init_capture | ( | volatile avr32_tc_t * | tc, |
const tc_capture_opt_t * | opt | ||
) |
Sets options for timer/counter capture initialization.
tc | Pointer to the TC instance to access. |
opt | Options for capture mode. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
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.
int tc_init_waveform | ( | volatile avr32_tc_t * | tc, |
const tc_waveform_opt_t * | opt | ||
) |
Sets options for timer/counter waveform initialization.
tc | Pointer to the TC instance to access. |
opt | Options for waveform generation. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
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.
int tc_read_ra | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads the channel's RA register and returns the value.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | RA register value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References Rd_bitfield, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_read_rb | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads the channel's RB register and returns the value.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | RB register value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References Rd_bitfield, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_read_rc | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads the channel's RC register and returns the value.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | RC register value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References Rd_bitfield, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_read_sr | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads the status register.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | Status register value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_read_tc | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Reads the channel's TC counter and returns the value.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
>=0 | TC counter value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References Rd_bitfield, TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
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.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
ext_clk_sig_src | External clock signal selection:
|
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
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.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_start | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Starts a timer/counter.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
int tc_stop | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel | ||
) |
Stops a timer/counter.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
0 | Success. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, and TC_NUMBER_OF_CHANNELS.
void tc_sync_start | ( | volatile avr32_tc_t * | tc | ) |
Start all TC channels simultaneously.
tc | Pointer to the TC instance to access. |
References TC_NUMBER_OF_CHANNELS.
void tc_sync_trigger | ( | volatile avr32_tc_t * | tc | ) |
Asserts a SYNC signal to generate a software trigger and reset all channels.
tc | Pointer to the TC instance to access. |
int tc_write_ra | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel, | ||
unsigned short | value | ||
) |
Writes a value to the channel's RA register.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
value | Value to write to the RA register. |
>=0 | Written value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, TC_NUMBER_OF_CHANNELS, Tst_bits, and Wr_bitfield.
int tc_write_rb | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel, | ||
unsigned short | value | ||
) |
Writes a value to the channel's RB register.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
value | Value to write to the RB register. |
>=0 | Written value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, TC_NUMBER_OF_CHANNELS, Tst_bits, and Wr_bitfield.
int tc_write_rc | ( | volatile avr32_tc_t * | tc, |
unsigned int | channel, | ||
unsigned short | value | ||
) |
Writes a value to the channel's RC register.
tc | Pointer to the TC instance to access. |
channel | The TC instance channel to access. |
value | Value to write to the RC register. |
>=0 | Written value. |
TC_INVALID_ARGUMENT | Invalid argument(s). |
References TC_INVALID_ARGUMENT, TC_NUMBER_OF_CHANNELS, Tst_bits, and Wr_bitfield.