Interface to the timer module in the MIPS r4300 processor.
More...
Data Structures |
struct | timer_link |
| Timer structure. More...
|
Files |
file | timer.c |
| Timer Subsystem.
|
file | timer.h |
| Timer Subsystem.
|
Defines |
#define | read_count(x) asm volatile("mfc0 %0,$9\n\t nop \n\t" : "=r" (x) : ) |
| Read the count out of the count register.
|
#define | write_count(x) asm volatile("mtc0 %0,$9\n\t nop \n\t" : : "r" (x) ) |
| Write the count to the count register.
|
#define | write_compare(x) asm volatile("mtc0 %0,$11\n\t nop \n\t" : : "r" (x) ) |
| Set the compare register.
|
#define | TF_ONE_SHOT 0 |
| Timer should fire only once.
|
#define | TF_CONTINUOUS 1 |
| Timer should fire at a regular interval.
|
#define | TIMER_TICKS(us) ((int)((long long)(us) * 46875LL / 1000LL)) |
| Calculate timer ticks based on microseconds.
|
#define | TIMER_MICROS(tk) ((int)((long long)(tk) * 1000LL / 46875LL)) |
| Calculate microseconds based on timer ticks.
|
#define | TIMER_TICKS_LL(us) ((long long)(us) * 46875LL / 1000LL) |
| Calculate timer ticks based on microseconds.
|
#define | TIMER_MICROS_LL(tk) ((long long)(tk) * 1000LL / 46875LL) |
| Calculate microseconds based on timer ticks.
|
Typedefs |
typedef struct timer_link | timer_link_t |
| Timer structure.
|
Functions |
static int | __proc_timers (timer_link_t *head) |
| Process linked list of timers.
|
static void | timer_callback (void) |
| Timer callback function.
|
void | timer_init (void) |
| Initialize the timer subsystem.
|
timer_link_t * | new_timer (int ticks, int flags, void(*callback)(int ovfl)) |
| Create a new timer and add to list.
|
void | start_timer (timer_link_t *timer, int ticks, int flags, void(*callback)(int ovfl)) |
| Start a timer not currently in the list.
|
void | stop_timer (timer_link_t *timer) |
| Stop a timer and remove it from the list.
|
void | delete_timer (timer_link_t *timer) |
| Remove a timer from the list and delete it.
|
void | timer_close (void) |
| Free and close the timer subsystem.
|
long long | timer_ticks (void) |
| Return total ticks since timer was initialized.
|
Variables |
static timer_link_t * | TI_timers = 0 |
| Internal linked list of timers.
|
static long long | total_ticks |
| Total ticks elapsed since timer subsystem initialization.
|
Detailed Description
Interface to the timer module in the MIPS r4300 processor.
The timer subsystem allows code to receive a callback after a specified number of ticks or microseconds. It interfaces with the MIPS coprocessor 0 to handle the timer interrupt and provide useful timing services.
Before attempting to use the timer subsystem, code should call timer_init. After the timer subsystem has been initialized, a new one-shot or continuous timer can be created with new_timer. To remove an expired one-shot timer or a recurring timer, use delete_timer. To temporarily stop a timer, use stop_timer. To restart a stopped timer or an expired one-shot timer, use start_timer. Once code no longer needs the timer subsystem, a call to timer_close will free all continuous timers and shut down the timer subsystem. Note that timers removed with stop_timer or expired one-short timers will not be removed automatically and are the responsibility of the calling code to be freed, regardless of a call to timer_close.
Define Documentation
#define read_count |
( |
|
x | ) |
asm volatile("mfc0 %0,$9\n\t nop \n\t" : "=r" (x) : ) |
Read the count out of the count register.
- Parameters:
-
[out] | x | Variable to place count into |
#define TIMER_MICROS |
( |
|
tk | ) |
((int)((long long)(tk) * 1000LL / 46875LL)) |
Calculate microseconds based on timer ticks.
- Parameters:
-
[in] | tk | Ticks to convert to microseconds |
- Returns:
- Microseconds
Calculate microseconds based on timer ticks.
- Parameters:
-
[in] | tk | Ticks to convert to microseconds |
- Returns:
- Microseconds as a long long
#define TIMER_TICKS |
( |
|
us | ) |
((int)((long long)(us) * 46875LL / 1000LL)) |
Calculate timer ticks based on microseconds.
- Parameters:
-
[in] | us | Microseconds to convert to ticks |
- Returns:
- Timer ticks
Calculate timer ticks based on microseconds.
- Parameters:
-
[in] | us | Microseconds to convert to ticks |
- Returns:
- Timer ticks as a long long
#define write_compare |
( |
|
x | ) |
asm volatile("mtc0 %0,$11\n\t nop \n\t" : : "r" (x) ) |
Set the compare register.
This sets up the compare register so that when the count register equals the compare register, an interrupt will be generated.
- Parameters:
-
[in] | x | Value to write into the compare register |
#define write_count |
( |
|
x | ) |
asm volatile("mtc0 %0,$9\n\t nop \n\t" : : "r" (x) ) |
Write the count to the count register.
- Parameters:
-
[in] | x | Value to write into the count register |
Function Documentation
Process linked list of timers.
Walk the linked list of timers and call the callbacks of any that have expired.
- Note:
- This function will remove one-shot timers from the list after they have fired.
- Parameters:
-
[in] | head | Head of the linked list of timers |
- Return values:
-
1 | The list needs reprocessing |
0 | All timer operations were handled successfully |
Remove a timer from the list and delete it.
- Parameters:
-
[in] | timer | Timer structure to stop, remove and free |
Create a new timer and add to list.
- Parameters:
-
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT and TF_CONTINUOUS |
[in] | callback | Callback function to call when the timer expires |
- Returns:
- A pointer to the timer structure created
Start a timer not currently in the list.
- Parameters:
-
[in] | timer | Pointer to timer structure to reinsert and start |
[in] | ticks | Number of ticks before the timer should fire |
[in] | flags | Timer flags. See TF_ONE_SHOT and TF_CONTINUOUS |
[in] | callback | Callback function to call when the timer expires |
Stop a timer and remove it from the list.
- Note:
- This function does not free a timer structure, use delete_timer to do this.
- Parameters:
-
[in] | timer | Timer structure to stop and remove |
Timer callback function.
This function is called by the interrupt controller whenever compare == count.
Free and close the timer subsystem.
This function will ensure all recurring timers are deleted from the list before closing. One-shot timers that have expired will need to be manually deleted with delete_timer.
Return total ticks since timer was initialized.
- Returns:
- Then number of ticks since the timer was initialized