AVR XMEGA Timer internals
[AVR XMEGA Timer]

Collaboration diagram for AVR XMEGA Timer internals:

Data Structures

struct  timer
 Timer data. More...

Defines

#define TIMER_SELECT(func, timer_id,...)   timer##timer_id##_##func##_priv(__VA_ARGS__)
 Select a timer function.

Functions

static void tc_timer_irq_handler (void *int_data)
 TC compare interrupt handler.
void tc_timer_init (uint8_t tc_id, void *regs, struct timer *timer, timer_callback_t callback)
 Common initialization for timers.
timer_res_t tc_timer_set_resolution (uint8_t tc_id, uint32_t resolution)
 Get best TC clock selection for specified resolution.
uint32_t tc_timer_get_resolution (uint8_t tc_id, timer_res_t timer_res)
 Get resolution in Hz for TC clock selection.
void tc_timer_write_resolution (uint8_t tc_id, struct timer *timer, timer_res_t timer_res)
 Update clock selection for TC.
void tc_timer_start (uint8_t tc_id, struct timer *timer)
 Enable, reset and start TC.
void tc_timer_set_alarm (uint8_t tc_id, struct timer *timer, uint16_t delay)
 Configure new alarm on TC.
void tc_timer_stop (uint8_t tc_id, struct timer *timer)
 Stop and disable TC.
uint16_t tc_timer_get_time (uint8_t tc_id, struct timer *timer)
 Get current time of TC.

Define Documentation

#define TIMER_SELECT ( func,
timer_id,
...   )     timer##timer_id##_##func##_priv(__VA_ARGS__)

Select a timer function.

For internal use only.

This macro is needed to expand macros properly that are passed in as IDs. In addition it reduces these kind of macros to one set instead of several ones for each function.

Parameters:
func Function name.
timer_id ID of timer to use.
... Variadic arguments.

Definition at line 127 of file timer_xmega.h.


Function Documentation

uint32_t tc_timer_get_resolution ( uint8_t  tc_id,
timer_res_t  timer_res 
)

Get resolution in Hz for TC clock selection.

For internal use only.

Parameters:
tc_id ID of TC.
timer_res Clock selection for TC.
Returns:
TC resolution in Hz.

Definition at line 241 of file tc_timer_xmega.c.

References tc_get_resolution().

uint16_t tc_timer_get_time ( uint8_t  tc_id,
struct timer timer 
)

Get current time of TC.

For internal use only.

Returns the current time of the TC, if it is enabled.

Parameters:
tc_id ID of the TC.
timer Pointer to timer struct.
Returns:
Time of TC, or 0 if it is disabled.

Definition at line 372 of file tc_timer_xmega.c.

References assert, cpu_irq_restore(), cpu_irq_save(), timer::regs, tc_pclk_is_enabled(), and tc_read_reg16.

void tc_timer_init ( uint8_t  tc_id,
void *  regs,
struct timer timer,
timer_callback_t  callback 
)

Common initialization for timers.

For internal use only.

Stores data needed for the timer: TC base address, default clock selection and callback function. The TC is reset, and compare channel A enabled before the TC is left disabled.

Parameters:
tc_id ID of TC.
regs Base address of TC
timer Pointer to timer struct.
callback Pointer to callback function.

Definition at line 134 of file tc_timer_xmega.c.

References assert, timer::callback, timer::clksel, intc_set_irq_data, timer::intlvl, timer::regs, TC_BF, TC_BIT, TC_CLKSEL_OFF, TC_CMD_RESET, tc_disable_pclk(), tc_enable_pclk(), tc_select_clock(), tc_write_reg8, and unhandled_case.

static void tc_timer_irq_handler ( void *  int_data  )  [static]

TC compare interrupt handler.

For internal use only.

This handler is executed when compare channel A of the TC is triggered and an alarm has been set. It disables the compare interrupt, but leaves the TC running. If a callback function has been set for the timer, it is called directly by this handler.

Parameters:
int_data Pointer to a timer struct.

Definition at line 67 of file tc_timer_xmega.c.

References assert, timer::callback, timer::regs, TC_BF, and tc_write_reg8.

void tc_timer_set_alarm ( uint8_t  tc_id,
struct timer timer,
uint16_t  delay 
)

Configure new alarm on TC.

For internal use only.

Sets a new compare value for compare channel A and enables its interrupt.

Parameters:
tc_id ID of the TC.
timer Pointer to timer struct.
delay Delay for timer alarm.

Definition at line 295 of file tc_timer_xmega.c.

References assert, timer::clksel, cpu_irq_restore(), cpu_irq_save(), timer::intlvl, timer::regs, TC_BF, TC_BIT, TC_CLKSEL_OFF, tc_disable_pclk(), tc_enable_pclk(), tc_pclk_is_enabled(), tc_read_reg16, tc_write_reg16, and tc_write_reg8.

timer_res_t tc_timer_set_resolution ( uint8_t  tc_id,
uint32_t  resolution 
)

Get best TC clock selection for specified resolution.

For internal use only.

Returns the clock selection for the TC that gives a resolution equal to or better than the one specified, assuming the system clock allows for it. If the desired resolution is not attainable, the clock selection for maximum rate is returned.

Parameters:
tc_id ID if TC.
resolution Desired TC resolution in Hz.
Returns:
Clock selection for TC.

Definition at line 227 of file tc_timer_xmega.c.

References tc_select_clock().

void tc_timer_start ( uint8_t  tc_id,
struct timer timer 
)

Enable, reset and start TC.

For internal use only.

Parameters:
tc_id ID of the TC.
timer Pointer to timer struct.

Definition at line 274 of file tc_timer_xmega.c.

References assert, timer::clksel, timer::regs, TC_BF, TC_CMD_RESTART, tc_enable_pclk(), and tc_write_reg8.

void tc_timer_stop ( uint8_t  tc_id,
struct timer timer 
)

Stop and disable TC.

For internal use only.

Parameters:
tc_id ID of TC.
timer Pointer to timer struct.

Definition at line 349 of file tc_timer_xmega.c.

References assert, timer::regs, TC_BF, TC_CLKSEL_OFF, tc_disable_pclk(), and tc_write_reg8.

void tc_timer_write_resolution ( uint8_t  tc_id,
struct timer timer,
timer_res_t  timer_res 
)

Update clock selection for TC.

For internal use only.

Stores new clock selection, and updates the current clock selection of the TC if it is enabled.

Parameters:
tc_id ID of the TC.
timer Pointer to timer struct.
timer_res New clock selection for TC.

Definition at line 257 of file tc_timer_xmega.c.

References assert, timer::clksel, timer::regs, and tc_write_reg8.

Generated on Thu Apr 29 14:10:01 2010 for display-demo by  doxygen 1.6.3