21.6. HAL APIs and Macros
The Interval Timer IP core has two operating modes, System Clock and Timestamp Clock. These settings are controlled by selecting the timer_0 option for hal.sys_clk_timer and hal.timestamp_timer while generating the BSP drivers. When timer_0 is chosen as the System Clock, then it cannot be used as a timestamp clock and vice versa.
| Prototype | int alt_timestamp_start(void) |
| Parameters | - |
| Returns | The return value is 0 upon success and -1 if timestamp device has not been registered. |
| Description | Initialize the timestamp feature. |
| Prototype | alt_timestamp_type alt_timestamp (void) |
| Parameters | - |
| Returns | This function returns the current timestamp count. It returns -1 if the timer has run full. |
| Description | Returns the current timestamp count. |
| Prototype | alt_u32 alt_timestamp_freq(void) |
| Parameters | - |
| Returns | This function returns the number of timestamp ticks per second. This will be 0 if no timestamp device has been registered. |
| Description | Returns the number of timestamp ticks per second. |
IORD_ALTERA_AVALON_TIMER_CONTROL(base)
This macro can be used to read the control register value of the Timer core. From Control register the user can read ITO – whether Interrupt is enabled or not and CONT bit - counter runs continuously or not; for more information, refer to the control register.
IOWR_ALTERA_AVALON_TIMER_CONTROL(base, data)
The user can start or stop the timer by setting the START or STOP bits in the control register and can enable or disable interrupts by toggling the ITO bit; for more information, refer to the control register.
IORD_ALTERA_AVALON_TIMER_STATUS(base)
The status register has two defined bits. TO (timeout) bit is set to 1 when the internal counter reaches zero. RUN bit reads as 1 when the internal counter is running; otherwise, this bit reads as 0. More details in the control register.
IOWR_ALTERA_AVALON_TIMER_STATUS(base, data)
In Status Register only TO bit is writeable. Write 0 or 1 to the status register to clear the TO bit. More details in the control register.
IORD_ALTERA_AVALON_TIMER_PERIOD(base)
Reading the Period register returns the currently configured timeout period. In system clock mode, the register is loaded with a default value, while in timestamp mode, it defaults to the full-scale value, which can be modified by the user at runtime. For more details, refer to the Period register.
IOWR_ALTERA_AVALON_TIMER_PERIOD(base, data)
Using this macro, the user can write the new timeout value into the Period register. When the hardware is configured with Writeable period disabled, writing to the period registers cause the counter to reset to the fixed Timeout Period specified at system generation time. For more details, refer to the Period register.