Nios® V Processor Software Developer Handbook

ID 743810
Date 5/26/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.7.1. System Clock Driver

The HAL system clock driver provides a periodic heartbeat, causing the system clock to increment on each beat. Software can use the system clock facilities to execute functions at specified times, and to obtain timing information. You select a specific hardware timer peripheral as the system clock device by manipulating BSP settings.

For more information about how to control BSP settings, refer to the HAL BSP Settings chapter.

The HAL provides implementations of the following standard UNIX functions: gettimeofday(), settimeofday(), and times(). The times returned by these functions are based on the HAL system clock.

The system clock measures time in clock ticks. If you are working with both hardware and software, do not confuse the HAL system clock with the clock signal driving the Nios® V processor hardware. The period of a HAL system clock tick is much longer than the hardware system clock. system.h defines the clock tick frequency.

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.