Specifications

At runtime, you can obtain the current value of the system clock by calling the alt_nticks() function.
This function returns the elapsed time in system clock ticks since reset. You can get the system clock rate,
in ticks per second, by calling the function alt_ticks_per_second(). The HAL timer driver initializes
the tick frequency when it creates the instance of the system clock.
The standard UNIX function gettimeofday() is available to obtain the current time. You must first
calibrate the time of day by calling settimeofday(). In addition, you can use the times() function to
obtain information about the number of elapsed ticks. The prototypes for these functions appear in
times.h.
For more information about the use of these functions, refer to the "HAL API Reference" chapter.
Related Information
HAL BSP Settings on page 6-1
HAL API Reference on page 14-1
Alarms
You can register functions to be executed at a specified time using the HAL alarm facility. A software
program registers an alarm by calling the function alt_alarm_start():
int alt_alarm_start(alt_alarm* alarm,
alt_u32 nticks,
alt_u32 (*callback) (void* context),
void* context);
The function callback() is called after nticks have elapsed. The input argument context is passed as
the input argument to callback() when the call occurs. The HAL does not use the context parameter. It
is only used as a parameter to the callback() function.
Your code must allocate the alt_alarm structure, pointed to by the input argument alarm. This data
structure must have a lifetime that is at least as long as that of the alarm. The best way to allocate this
structure is to declare it as a static or global. alt_alarm_start() initializes *alarm.
The callback function can reset the alarm. The return value of the registered callback function is the
number of ticks until the next call to callback. A return value of zero indicates that the alarm should be
stopped. You can manually cancel an alarm by calling alt_alarm_stop().
One alarm is created for each call to alt_alarm_start(). Multiple alarms can run simultaneously.
Alarm callback functions execute in an exception context. This imposes functional restrictions which you
must observe when writing an alarm callback.
For more information about the use of these functions, refer to the "Exception Handling" chapter.
Example 6–8. Using a Periodic Alarm Callback Function
#include <stddef.h>
#include <stdio.h>
#include "sys/alt_alarm.h"
#include "alt_types.h"
/*
* The callback function.
*/
alt_u32 my_alarm_callback (void* context)
{
/* This function is called once per second */
return alt_ticks_per_second();
}
NII5V2
2015.05.14
Alarms
6-15
Developing Programs Using the Hardware Abstraction Layer
Altera Corporation
Send Feedback