|
Modules | |
| AVR XMEGA Timer internals | |
Typedefs | |
| typedef uint8_t | timer_res_t |
| Driver internal timer resolution type. | |
| typedef void(* | timer_callback_t )(struct timer *timer) |
| Timer callback function type. | |
Functions | |
| void | tc_timer_init (uint8_t tc_id, void *regs, struct timer *timer, timer_callback_t timer_callback) |
| Common initialization for timers. | |
| void | tc_timer_start (uint8_t tc_id, struct timer *timer) |
| Enable, reset and start TC. | |
| void | tc_timer_stop (uint8_t tc_id, struct timer *timer) |
| Stop and disable TC. | |
| void | tc_timer_set_alarm (uint8_t tc_id, struct timer *timer, uint16_t delay) |
| Configure new alarm on TC. | |
| uint16_t | tc_timer_get_time (uint8_t tc_id, struct timer *timer) |
| Get current time of TC. | |
| timer_res_t | tc_timer_set_resolution (uint8_t tc_id, uint32_t resolution) |
| Get best TC clock selection for specified resolution. | |
| void | tc_timer_write_resolution (uint8_t tc_id, struct timer *timer, timer_res_t resolution) |
| Update clock selection for TC. | |
| uint32_t | tc_timer_get_resolution (uint8_t tc_id, timer_res_t timer_res) |
| Get resolution in Hz for TC clock selection. | |
| static uint16_t | tc_timer_maximum_delta (void) |
| Returns the maximum delta for timers. | |
| static timer_res_t | tc_timer_read_resolution (struct timer *timer) |
| Read the currect clock selection of a timer. | |
The AVR XMEGA family features different modules that can be used as timers. A timer can be selected by using an ID. The valid IDs and the corresponding implementation are listed in the chip-specific section of this documentation (<chip/timer.h>) since the different devices feature different configurations.
Each AVR XMEGA TC-module corresponds to a single 16-bit timer, and this driver makes use of their compare channel A as the alarm trigger.
To enable a timer, config symbols CONFIG_TIMER_n must be defined, where n corresponds to the ID of the timer. CONFIG_TIMER_RESOLUTION must also be set to a value (in Hz) for the default TC clock rate to be set.
This driver will disable the TCs whenever they are not needed to conserve power.
The list below shows the relation between timer ID and its corresponding TC module:
| typedef void(* timer_callback_t)(struct timer *timer) |
Timer callback function type.
Pointer to the function to be called once a timer expires.
| timer | Pointer to the timer_t object that was associated with the current alarm/timer interrupt. |
Definition at line 86 of file timer_xmega.h.
| typedef uint8_t timer_res_t |
Driver internal timer resolution type.
Definition at line 74 of file timer_xmega.h.
| 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.
| tc_id | ID of TC. | |
| timer_res | Clock selection for TC. |
Definition at line 241 of file tc_timer_xmega.c.
References tc_get_resolution().
Get current time of TC.
For internal use only.
Returns the current time of the TC, if it is enabled.
| tc_id | ID of the TC. | |
| timer | Pointer to timer struct. |
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.
| 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 uint16_t tc_timer_maximum_delta | ( | void | ) | [inline, static] |
Returns the maximum delta for timers.
For internal use only.
Definition at line 86 of file tc_timer_xmega.h.
| static timer_res_t tc_timer_read_resolution | ( | struct timer * | timer | ) | [inline, static] |
Read the currect clock selection of a timer.
For internal use only.
| timer | Pointer to timer struct. |
Definition at line 99 of file tc_timer_xmega.h.
References timer::clksel.
Configure new alarm on TC.
For internal use only.
Sets a new compare value for compare channel A and enables its interrupt.
| 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.
| tc_id | ID if TC. | |
| resolution | Desired TC resolution in Hz. |
Definition at line 227 of file tc_timer_xmega.c.
References tc_select_clock().
Enable, reset and start TC.
For internal use only.
| 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.
Stop and disable TC.
For internal use only.
| 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.
| 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.
1.6.3