-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* stat fixing timer SDK * Added functions for counting time, waiting time and enabling timer interupts. Fixed clock cycles counter. * Revision Added tests, comments and renamings * lower tolerances Lowered tolerances in tests, made time-tolerance frequency-dependent. * Remove useless define * added documentation and performed requested fixes on sdk * update exmaple_timer_sdk app * renamed function with name conflict * Fixed simulation errors * Update main.c (realxed error tolerance) --------- Co-authored-by: davide schiavone <davide@openhwgroup.org>
- Loading branch information
1 parent
2733542
commit 98dde53
Showing
5 changed files
with
348 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
|
||
# Timer SDK | ||
|
||
This SDK provides utilities for execution time measurements using HW timers. It includes functions to start, stop, reset, and configure timers, as well as to enable timer interrupts and measure elapsed time. | ||
|
||
## Usage | ||
|
||
The SDK provides a set of functions to interact with the HW Timer for various timing operations. | ||
|
||
### Initialize Timer for Counting Cycles | ||
|
||
This function configures the counter at the running clock frequency to count the number of clock cycles. Call this function before any of the other timer SDK functions. | ||
|
||
```c | ||
void timer_cycles_init(); | ||
``` | ||
|
||
### Start Timer | ||
|
||
Start the HW timer. | ||
|
||
```c | ||
void timer_start(); | ||
``` | ||
|
||
### Get Current Timer Value | ||
|
||
Retrieve the current value of the HW timer without stopping it. | ||
|
||
```c | ||
uint32_t timer_get_cycles(); | ||
``` | ||
|
||
### Complete timer reset | ||
|
||
Completely resets the HW counter, disabling all IRQs, counters, and comparators. | ||
```c | ||
void timer_reset(); | ||
``` | ||
|
||
### Stop and Reset Timer | ||
|
||
Retrieve the current value of the HW timer and stop it. | ||
|
||
```c | ||
uint32_t timer_stop(); | ||
``` | ||
|
||
### Set Timer Threshold | ||
|
||
Set the timer to go off once the counter value reaches the specified threshold. If the timer interrupts and the timer IRQ have been enabled, when the timer reaches that value an interrupt will be called. | ||
|
||
```c | ||
void timer_arm_set(uint32_t threshold); | ||
``` | ||
### Set Timer Threshold and Start | ||
Set the timer to go off once the counter value reaches the specified threshold, and start the timer. If the timer interrupts and the timer IRQ have been enabled, when the timer reaches that value an interrupt will be called. | ||
```c | ||
void timer_arm_start(uint32_t threshold); | ||
``` | ||
|
||
### Enable Timer IRQ | ||
|
||
Enable the timer interrupt request. | ||
|
||
```c | ||
void timer_irq_enable(); | ||
``` | ||
|
||
### Clear Timer IRQ | ||
|
||
Clear the timer interrupt request. | ||
|
||
```c | ||
void timer_irq_clear(); | ||
``` | ||
|
||
### Enable Timer Machine-level Interrupts | ||
|
||
Enable the timer machine-level interrupts for the X-Heep platform. | ||
|
||
```c | ||
void enable_timer_interrupt(); | ||
``` | ||
|
||
### Wait for Microseconds | ||
|
||
Block execution for a specified number of microseconds. This function is not precise for small numbers of microseconds. Enable timer interrupts with `enable_timer_interrupt()` before using this function. | ||
|
||
```c | ||
void timer_wait_us(uint32_t ms); | ||
``` | ||
### Get Execution Time in Microseconds | ||
Get the time taken to execute a certain number of cycles, returned as a float representing the time in microseconds. | ||
```c | ||
float get_time_from_cycles(uint32_t cycles); | ||
``` | ||
|
||
## Example Usage | ||
|
||
An example of utilization of the timer SDK can be found in `sw/applications/example_timer_sdk/main.c`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.