Specifications
...
/* The alt_alarm must persist for the duration of the alarm. */
static alt_alarm alarm;
...
if (alt_alarm_start (&alarm,
alt_ticks_per_second(),
my_alarm_callback,
NULL) < 0)
{
printf ("No system clock available\n");
}
Related Information
Exception Handling on page 8-1
Timestamp Driver
Sometimes you want to measure time intervals with a degree of accuracy greater than that provided by
HAL system clock ticks. The HAL provides high resolution timing functions using a timestamp driver. A
timestamp driver provides a monotonically increasing counter that you can sample to obtain timing
information. The HAL only supports one timestamp driver in the system.
You specify a hardware timer peripheral as the timestamp device by manipulating BSP settings. The
Altera-provided timestamp driver uses the timer that you specify.
If a timestamp driver is present, the following functions are available:
• alt_timestamp_start()
• alt_timestamp()
Calling alt_timestamp_start() starts the counter running. Subsequent calls to alt_timestamp()
return the current value of the timestamp counter. Calling alt_timestamp_start() again resets the
counter to zero. The behavior of the timestamp driver is undefined when the counter reaches (2
32
- 1).
You can obtain the rate at which the timestamp counter increments by calling the function
alt_timestamp_freq(). This rate is typically the hardware frequency of the Nios II processor system—
usually millions of cycles per second. The timestamp drivers are defined in the alt_timestamp.h header file.
For more information about the use of these functions, refer to the HAL API Reference chapter of the Nios
II Software Developer’s Handbook.
Example 6–9. Using the Timestamp to Measure Code Execution Time
#include <stdio.h>
#include "sys/alt_timestamp.h"
#include "alt_types.h"
int main (void)
{
alt_u32 time1;
alt_u32 time2;
alt_u32 time3;
if (alt_timestamp_start() < 0)
{
printf ("No timestamp device available\n");
}
else
{
time1 = alt_timestamp();
func1(); /* first function to monitor */
time2 = alt_timestamp();
func2(); /* second function to monitor */
time3 = alt_timestamp();
6-16
Timestamp Driver
NII5V2
2015.05.14
Altera Corporation
Developing Programs Using the Hardware Abstraction Layer
Send Feedback