See Quick Start Guide for the XMEGA TC Driver.
This is a driver for the AVR XMEGA Timer Counter (TC). It provides functions for enabling, disabling and configuring the TC modules.
This driver depends on the following modules:
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Timer Counter (TC). | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the Timer Counter (TC). | |
Timer Counter (TC) interrupt management | |
This group provides functions to configure TC module interrupts. | |
AWeX extension driver | |
This group provides low level drivers to configure AWeX extension. | |
Hi-Res extension driver | |
This group provides low level drivers to configure Hi-Res extension. | |
Macros | |
#define | tc_is_tc0(void) ((uint16_t)tc&0x40 ? false : true) |
Macro to check if type of passed TC is TC0_t. More... | |
#define | tc_is_tc1(void) ((uint16_t)tc&0x40 ? true : false) |
Macro to check if type of passed TC is TC1_t. More... | |
Typedefs | |
typedef void(* | tc_callback_t )(void) |
Interrupt event callback function type. More... | |
Enumerations | |
enum | tc_cc_channel_mask_enable_t { TC_CCAEN = TC0_CCAEN_bm, TC_CCBEN = TC0_CCBEN_bm, TC_CCCEN = TC0_CCCEN_bm, TC_CCDEN = TC0_CCDEN_bm } |
Timer Counter Capture Compare Channel index. More... | |
enum | tc_cc_channel_t { TC_CCA = 1, TC_CCB = 2, TC_CCC = 3, TC_CCD = 4 } |
Timer Counter Capture Compare Channel index. More... | |
enum | tc_dir_t { TC_UP = 0, TC_DOWN = 1 } |
Timer Counter Direction. More... | |
enum | TC_INT_LEVEL_t { TC_INT_LVL_OFF = 0x00, TC_INT_LVL_LO = 0x01, TC_INT_LVL_MED = 0x02, TC_INT_LVL_HI = 0x03 } |
TC interrupt levels. More... | |
enum | tc_wg_mode_t { TC_WG_NORMAL = TC_WGMODE_NORMAL_gc, TC_WG_FRQ = TC_WGMODE_FRQ_gc, TC_WG_SS = TC_WGMODE_SS_gc, TC_WG_DS_T = TC_WGMODE_DS_T_gc, TC_WG_DS_TB = TC_WGMODE_DS_TB_gc, TC_WG_DS_B = TC_WGMODE_DS_B_gc } |
Timer Counter Waveform Generator mode. More... | |
Functions | |
static bool | tc_cc_buffer_is_valid (volatile void *tc, enum tc_cc_channel_t channel_index) |
Reports is Capture/Compare Buffer is valid. More... | |
static void | tc_clear_cc_interrupt (volatile void *tc, enum tc_cc_channel_t channel_index) |
Clears Capture/Compare interrupt. More... | |
static void | tc_clear_error (volatile void *tc) |
Clears the Error flag. More... | |
static void | tc_clear_overflow (volatile void *tc) |
Clears the Overflow flag. More... | |
void | tc_disable (volatile void *tc) |
Disable TC. More... | |
static void | tc_disable_cc_channels (volatile void *tc, enum tc_cc_channel_mask_enable_t disablemask) |
Disables Compare/Capture channel. More... | |
static void | tc_disable_delay (volatile void *tc) |
Disables delay. More... | |
void | tc_enable (volatile void *tc) |
Enable TC. More... | |
static void | tc_enable_cc_channels (volatile void *tc, enum tc_cc_channel_mask_enable_t enablemask) |
Enables Compare/Capture channel. More... | |
static void | tc_enable_delay (volatile void *tc) |
Enables delay (used for 32bit timer mode) More... | |
static uint32_t | tc_get_resolution (volatile void *tc) |
Get real resolution for a specified TC. More... | |
static bool | tc_is_cc_interrupt (volatile void *tc, enum tc_cc_channel_t channel_index) |
Reports if Capture/Compare interrupt has occurred. More... | |
static bool | tc_is_overflow (volatile void *tc) |
Tests if the Overflow flag is set. More... | |
static void | tc_lock_update_buffers (volatile void *tc) |
Locks the Update of the Buffered registers. More... | |
static bool | tc_period_buffer_is_valid (volatile void *tc) |
Tests if the Period Buffer is valid. More... | |
static uint16_t | tc_read_cc (volatile void *tc, enum tc_cc_channel_t channel_index) |
Reads the Capture value. More... | |
static uint16_t | tc_read_cc_buffer (volatile void *tc, enum tc_cc_channel_t channel_index) |
Reads the Capture/Compare Buffer value. More... | |
static TC_CLKSEL_t | tc_read_clock_source (volatile void *tc) |
Read Timer Clock Source. More... | |
static uint16_t | tc_read_count (volatile void *tc) |
Reads the Counter value of the Timer. More... | |
static bool | tc_read_error (volatile void *tc) |
Tests if the Error flag is set. More... | |
static uint16_t | tc_read_period (volatile void *tc) |
Reads the Period value of the Timer. More... | |
static uint16_t | tc_read_period_buffer (volatile void *tc) |
Reads the Period Buffer value of the Timer. More... | |
static void | tc_reset (volatile void *tc) |
Reset the Timer. More... | |
static void | tc_restart (volatile void *tc) |
Restart the Timer. More... | |
static void | tc_set_8bits_mode (volatile void *tc) |
Configures the Timer in Byte mode. More... | |
static void | tc_set_direction (volatile void *tc, enum tc_dir_t dir) |
Configure Timer Direction. More... | |
static void | tc_set_input_capture (volatile void *tc, TC_EVSEL_t eventsource, TC_EVACT_t eventaction) |
Enables Input capture mode. More... | |
static void | tc_set_resolution (volatile void *tc, uint32_t resolution) |
Select clock for a specified TC and resolution. More... | |
static void | tc_set_wgm (volatile void *tc, enum tc_wg_mode_t wgm) |
Configures TC in the specified Waveform generator mode. More... | |
static void | tc_unlock_update_buffers (volatile void *tc) |
Unlocks the Update of the Buffered registers. More... | |
static void | tc_update (volatile void *tc) |
Update the Timer. More... | |
static void | tc_write_cc (volatile void *tc, enum tc_cc_channel_t channel_index, uint16_t value) |
Writes the CC value. More... | |
static void | tc_write_cc_buffer (volatile void *tc, enum tc_cc_channel_t channel_index, uint16_t buffer_value) |
Writes the Capture/Compare Buffer value. More... | |
static void | tc_write_clock_source (volatile void *tc, TC_CLKSEL_t TC_CLKSEL_enum) |
Configure Timer Clock Source. More... | |
static void | tc_write_count (volatile void *tc, uint16_t cnt_value) |
Write the Counter value of the Timer. More... | |
static void | tc_write_period (volatile void *tc, uint16_t per_value) |
Writes the Period value of the Timer. More... | |
static void | tc_write_period_buffer (volatile void *tc, uint16_t per_buf) |
Writes the Period Buffer value of the Timer. More... | |
#define tc_is_tc0 | ( | void | ) | ((uint16_t)tc&0x40 ? false : true) |
Macro to check if type of passed TC is TC0_t.
Referenced by tc_cc_buffer_is_valid(), tc_clear_cc_interrupt(), tc_disable_cc_channels(), tc_enable_cc_channels(), tc_is_cc_interrupt(), tc_read_cc(), tc_read_cc_buffer(), tc_write_cc(), and tc_write_cc_buffer().
#define tc_is_tc1 | ( | void | ) | ((uint16_t)tc&0x40 ? true : false) |
Macro to check if type of passed TC is TC1_t.
Referenced by tc_cc_buffer_is_valid(), tc_clear_cc_interrupt(), tc_disable_cc_channels(), tc_enable_cc_channels(), tc_is_cc_interrupt(), tc_read_cc(), tc_read_cc_buffer(), tc_write_cc(), and tc_write_cc_buffer().
typedef void(* tc_callback_t)(void) |
Interrupt event callback function type.
The interrupt handler can be configured to do a function callback, the callback function must match the tc_callback_t type.
enum tc_cc_channel_t |
enum tc_dir_t |
enum TC_INT_LEVEL_t |
enum tc_wg_mode_t |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Clears the Error flag.
tc | Pointer to TC module. |
|
inlinestatic |
Clears the Overflow flag.
tc | Pointer to TC module. |
Referenced by play_game(), and record_buttons().
void tc_disable | ( | volatile void * | tc | ) |
Disable TC.
Disables the TC.
tc | Pointer to TC module |
References cpu_irq_restore(), cpu_irq_save(), SLEEPMGR_IDLE, sleepmgr_unlock_mode(), sysclk_disable_module(), SYSCLK_HIRES, SYSCLK_PORT_C, SYSCLK_PORT_D, SYSCLK_PORT_E, SYSCLK_PORT_F, SYSCLK_TC0, and SYSCLK_TC1.
Referenced by dma_transfer_is_complete(), and pwm_disable().
|
inlinestatic |
|
inlinestatic |
Disables delay.
tc | Pointer to TC module. |
void tc_enable | ( | volatile void * | tc | ) |
Enable TC.
Enables the TC.
tc | Pointer to TC module |
References cpu_irq_restore(), cpu_irq_save(), SLEEPMGR_IDLE, sleepmgr_lock_mode(), sysclk_enable_module(), SYSCLK_HIRES, SYSCLK_PORT_C, SYSCLK_PORT_D, SYSCLK_PORT_E, SYSCLK_PORT_F, SYSCLK_TC0, and SYSCLK_TC1.
Referenced by init_save_timer(), main(), pwm_init(), qdec_enabled_tc(), qdec_enabled_tc_freq(), run_dma_triggered_with_callback(), sha204h_timer_init(), sound_init(), and start_debounce_timer().
|
inlinestatic |
Enables Compare/Capture channel.
tc | Pointer to TC module. |
enablemask | CC channel |
References tc_is_tc0, and tc_is_tc1.
Referenced by main(), pwm_start(), and qdec_enabled_tc_freq().
|
inlinestatic |
Enables delay (used for 32bit timer mode)
tc | Pointer to TC module. |
|
inlinestatic |
Get real resolution for a specified TC.
This function returns the resolution which the specified clock selection of TC will result in. The resolution of a TC is synonymous with its clock frequency.
tc | Pointer of TC module to get resolution for. |
References sysclk_get_per_hz(), and tc_read_clock_source().
Referenced by qdec_enabled_tc_freq(), sha204h_start_timer(), and start_debounce_timer().
|
inlinestatic |
|
inlinestatic |
Tests if the Overflow flag is set.
tc | Pointer to TC module. |
Referenced by play_game(), and record_buttons().
|
inlinestatic |
Locks the Update of the Buffered registers.
tc | Pointer to TC module. |
|
inlinestatic |
Tests if the Period Buffer is valid.
tc | Pointer to TC module. |
|
inlinestatic |
Reads the Capture value.
tc | Pointer to TC module. |
channel_index | Channel x |
References TC_CCA, TC_CCB, TC_CCC, TC_CCD, tc_is_tc0, and tc_is_tc1.
Referenced by cca_callback(), example_overflow_interrupt_callback(), and qdec_get_frequency().
|
inlinestatic |
|
inlinestatic |
Read Timer Clock Source.
tc | Pointer to TC module. |
Referenced by tc_get_resolution().
|
inlinestatic |
Reads the Counter value of the Timer.
tc | Pointer to TC module. |
Referenced by qdec_get_position().
|
inlinestatic |
Tests if the Error flag is set.
tc | Pointer to TC module. |
|
inlinestatic |
Reads the Period value of the Timer.
tc | Pointer to TC module. |
|
inlinestatic |
Reads the Period Buffer value of the Timer.
tc | Pointer to TC module. |
|
inlinestatic |
Reset the Timer.
tc | Pointer to TC module. |
|
inlinestatic |
Restart the Timer.
tc | Pointer to TC module. |
Referenced by sha204h_start_timer().
|
inlinestatic |
Configures the Timer in Byte mode.
tc | Pointer to TC module. |
|
inlinestatic |
Configure Timer Direction.
tc | Pointer to TC module. |
dir | Timer direction : |
References TC_UP.
Referenced by run_dma_triggered_with_callback().
|
inlinestatic |
Enables Input capture mode.
tc | Pointer to TC module. |
eventsource | Source for the capture |
eventaction | Event action capture type |
Referenced by main(), qdec_enabled_tc(), and qdec_enabled_tc_freq().
|
inlinestatic |
Select clock for a specified TC and resolution.
This function configures the clock selection, as prescaled CLKper, for a specified TC that gives a resolution at least as high as the one specified. The resolution of a TC is synonymous with its clock frequency.
tc | ID of TC to get clock selection for. |
resolution | Desired resolution for the TC in Hz. |
References sysclk_get_per_hz(), and tc_write_clock_source().
Referenced by main(), qdec_enabled_tc_freq(), run_dma_triggered_with_callback(), sha204h_start_timer(), and start_debounce_timer().
|
inlinestatic |
Configures TC in the specified Waveform generator mode.
tc | Pointer to TC module. |
wgm | : waveform generator |
Referenced by main(), pwm_init(), sha204h_timer_init(), and start_debounce_timer().
|
inlinestatic |
Unlocks the Update of the Buffered registers.
tc | Pointer to TC module. |
|
inlinestatic |
Update the Timer.
tc | Pointer to TC module. |
|
inlinestatic |
|
inlinestatic |
Writes the Capture/Compare Buffer value.
tc | Pointer to TC module. |
channel_index | CC Channel |
buffer_value | Counter Buffer value |
References TC_CCA, TC_CCB, TC_CCC, TC_CCD, tc_is_tc0, and tc_is_tc1.
Referenced by example_cca_interrupt_callback(), example_ccb_interrupt_callback(), and pwm_set_duty_cycle_percent().
|
inlinestatic |
Configure Timer Clock Source.
tc | Pointer to TC module. |
TC_CLKSEL_enum | Clock source selection |
Referenced by pwm_init(), pwm_start(), pwm_stop(), qdec_enabled_tc(), sound_start_timer(), sound_stop_timer(), start_save_timer(), tc_set_resolution(), and timeout_callback().
|
inlinestatic |
Write the Counter value of the Timer.
tc | Pointer to TC module. |
cnt_value | Counter value : |
Referenced by pwm_timer_reset(), qdec_enabled_tc(), qdec_enabled_tc_freq(), and qdec_reset_position().
|
inlinestatic |
Writes the Period value of the Timer.
tc | Pointer to TC module. |
per_value | Period value : PER |
Referenced by init_save_timer(), main(), pwm_start(), qdec_enabled_tc(), qdec_enabled_tc_freq(), run_dma_triggered_with_callback(), sha204h_start_timer(), sound_init(), and start_debounce_timer().
|
inlinestatic |
Writes the Period Buffer value of the Timer.
tc | Pointer to TC module. |
per_buf | Period Buffer value : PERH/PERL |