OR1K support
|
Functions | |
int | or1k_timer_init (unsigned int hz) |
void | or1k_timer_set_period (uint32_t hz) |
void | or1k_timer_set_handler (void(*handler)(void)) |
void | or1k_timer_set_mode (uint32_t mode) |
void | or1k_timer_enable (void) |
uint32_t | or1k_timer_disable (void) |
void | or1k_timer_restore (uint32_t sr_tee) |
void | or1k_timer_pause (void) |
void | or1k_timer_reset (void) |
unsigned long | or1k_timer_get_ticks (void) |
void | or1k_timer_reset_ticks (void) |
The tick timer can be used for time measurement, operating system scheduling etc. By default it is initialized to continuously count the ticks of a certain period after calling or1k_timer_init(). The period can later be changed using or1k_timer_set_period().
The timer is controlled using or1k_timer_enable(), or1k_timer_disable(), or1k_timer_restore(), or1k_timer_pause(). After initialization it is required to enable the timer the first time using or1k_timer_enable(). or1k_timer_disable() only disables the tick timer interrupts, it does not disable the timer counting. If you plan to use a pair of or1k_timer_disable() and or1k_timer_enable() to protect sections of your code against interrupts you should use or1k_timer_disable() and or1k_timer_restore(), as it may be possible that the timer interrupt was not enabled before disabling it, enable would then start it unconditionally. or1k_timer_pause() pauses the counting.
In the default mode you can get the tick value using or1k_timer_get_ticks() and reset this value using or1k_timer_reset_ticks().
Example for using the default mode:
It is possible to change the mode of the tick timer using or1k_timer_set_mode(). Allowed values are the correct bit pattern (including the bit positions) for the TTMR register, it is recommended to use the macros defined in spr-defs.h. For example, implementing an operating system with scheduling decisions of varying duration favors the implementation of single run tick timer. Here, each quantum is started before leaving the operating system kernel. The counter can be restarted with or1k_timer_reset(). Example:
uint32_t or1k_timer_disable | ( | void | ) |
Disable timer interrupt
This disables the timer interrupt exception and returns the state of the interrupt exception enable flag before the call. This can be used with or1k_timer_restore() to implement sequences of code that are not allowed to be interrupted. Using or1k_timer_enable() will unconditionally enable the interrupt independent of the state before calling or1k_timer_disable(). For an example see Timer control.
void or1k_timer_enable | ( | void | ) |
Enable timer interrupt
Enable the timer interrupt exception, independent of the status before. If you want to enable the timer conditionally, for example to implement a non-interruptible sequence of code, you should use or1k_timer_restore(). See the description of or1k_timer_disable() for more details.
The enable will also restore the mode if the timer was paused previously.
unsigned long or1k_timer_get_ticks | ( | void | ) |
Get timer ticks
Get the global ticks of the default configuration. This will increment the tick counter according to the preconfigured period.
int or1k_timer_init | ( | unsigned int | hz | ) |
Initialize tick timer
This initializes the tick timer in default mode (see Timer control for details).
hz | Initial period of the tick timer |
void or1k_timer_pause | ( | void | ) |
Pause timer counter
Pauses the counter of the tick timer. The counter will hold its current value and it can be started again with or1k_timer_enable() which will restore the configured mode.
void or1k_timer_reset | ( | void | ) |
Reset timer counter
void or1k_timer_reset_ticks | ( | void | ) |
Reset timer ticks
Resets the timer ticks in default configuration to 0.
void or1k_timer_restore | ( | uint32_t | sr_tee | ) |
Restore timer interrupt exception flag
Restores the timer interrupt exception flag as returned by or1k_timer_disable(). See the description of or1k_timer_disable() and Timer control for details and an example.
sr_tee | Status of timer interrupt |
void or1k_timer_set_handler | ( | void(*)(void) | handler | ) |
Replace the timer interrupt handler
By default the tick timer is used to handle timer ticks. The user can replace this with an own handler for example when implementing an operating system.
handler | The callback function pointer to the handler |
void or1k_timer_set_mode | ( | uint32_t | mode | ) |
Set timer mode
The timer has different modes (see architecture manual). The default is to automatically restart counting (SPR_TTMR_RT), others are single run (SPR_TTMR_SR) and continuous run (SPR_TTMR_CR).
mode | a valid mode (use definitions from spr-defs.h as it is important that those are also at the correct position in the bit field!) |
void or1k_timer_set_period | ( | uint32_t | hz | ) |
Set period of timer
Set the period of the timer to a value in Hz. The frequency from the board support package is used to determine the match value.