Altera HWLIB  16.0
The Altera HW Manager API Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
The Global Timer Manager API

Description

This functional group handles setting and reading various parameters of the global 64-bit incrementing counter. There is one 64-bit continuously incrementing counter for all CPU cores and it is clocked by PERIPHCLK. This section manages the comparator value, compare enable, auto-increment value, auto-increment enable, and interrupt enable for the CPU that this code is running on (referenced as CPU_GLOBAL_TMR).

Functions

ALT_STATUS_CODE alt_globaltmr_uninit (void)
 
ALT_STATUS_CODE alt_globaltmr_init (void)
 
ALT_STATUS_CODE alt_globaltmr_stop (void)
 
ALT_STATUS_CODE alt_globaltmr_start (void)
 
ALT_STATUS_CODE alt_globaltmr_get (uint32_t *highword, uint32_t *lowword)
 
uint64_t alt_globaltmr_get64 (void)
 
uint32_t alt_globaltmr_counter_get_low32 (void)
 
uint32_t alt_globaltmr_counter_get_hi32 (void)
 
ALT_STATUS_CODE alt_globaltmr_comp_set (uint32_t highword, uint32_t loword)
 
ALT_STATUS_CODE alt_globaltmr_comp_set64 (uint64_t compval)
 
ALT_STATUS_CODE alt_globaltmr_comp_get (uint32_t *highword, uint32_t *lowword)
 
uint64_t alt_globaltmr_comp_get64 (void)
 
ALT_STATUS_CODE alt_globaltmr_comp_mode_start (void)
 
ALT_STATUS_CODE alt_globaltmr_comp_mode_stop (void)
 
bool alt_globaltmr_is_comp_mode (void)
 
uint32_t alt_globaltmr_prescaler_get (void)
 
ALT_STATUS_CODE alt_globaltmr_prescaler_set (uint32_t val)
 
ALT_STATUS_CODE alt_globaltmr_autoinc_set (uint32_t inc)
 
uint32_t alt_globaltmr_autoinc_get (void)
 
ALT_STATUS_CODE alt_globaltmr_autoinc_mode_start (void)
 
ALT_STATUS_CODE alt_globaltmr_autoinc_mode_stop (void)
 
bool alt_globaltmr_is_autoinc_mode (void)
 
uint32_t alt_globaltmr_maxcounter_get (void)
 
ALT_STATUS_CODE alt_globaltmr_int_disable (void)
 
ALT_STATUS_CODE alt_globaltmr_int_enable (void)
 
bool alt_globaltmr_int_is_enabled (void)
 
ALT_STATUS_CODE alt_globaltmr_int_clear_pending (void)
 
bool alt_globaltmr_int_is_pending (void)
 
bool alt_globaltmr_int_if_pending_clear (void)
 

Function Documentation

ALT_STATUS_CODE alt_globaltmr_uninit ( void  )

Uninitialize the Global timer module

ALT_STATUS_CODE alt_globaltmr_init ( void  )

Initialize the Global timer module

ALT_STATUS_CODE alt_globaltmr_stop ( void  )

Stops the global timer counter compare function for this CPU and disables its interrupt. It does not stop the global timer itself. This function is identical to calling alt_gpt_tmr_stop() with a tmr_id of CPU_GLOBAL_TMR.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_globaltmr_start ( void  )

Starts the global timer compare function for this CPU, enables its interrupt function and, if free-running mode is selected also enables its auto-increment function. If the global timer is not yet running, it starts the timer. This function is identical to calling alt_gpt_tmr_start() with a tmr_id of CPU_GLOBAL_TMR.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_globaltmr_get ( uint32_t *  highword,
uint32_t *  lowword 
)

Returns the current counter value of the 64-bit global timer.

Parameters
highwordLocation used to return the most significant 32-bit word of the current global timer count.
lowwordLocation used to return the least significant 32-bit word of the current global timer count.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
uint64_t alt_globaltmr_get64 ( void  )

Returns the current counter value of the 64-bit global timer. This function is identical to alt_globaltmr_get() except that the value is returned as a 64-bit unsigned integer rather than as two 32-bit words.

Return values
uint64_tThe current value of the 64-bit counter.
uint32_t alt_globaltmr_counter_get_low32 ( void  )

Returns the 32 low-order bits of the global timer. This is identical to calling alt_gpt_counter_get() with a tmr_id equal to CPU_GLOBAL_TMR. Use alt_globaltmr_get() or alt_globaltmr_get64() to obtain the full 64-bit timer value.

Return values
uint32_tThe current 32-bit counter value.
uint32_t alt_globaltmr_counter_get_hi32 ( void  )

Returns the 32 higher-order bits of the global timer. Use alt_globaltmr_get() or alt_globaltmr_get64() to obtain the full 64-bit timer value.

Return values
uint32_tThe current 32-bit counter value.
ALT_STATUS_CODE alt_globaltmr_comp_set ( uint32_t  highword,
uint32_t  loword 
)

Sets the value of the 64-bit global timer comparator for this CPU. The global timer increments its count and when it reaches this value or above, it triggers the following actions. If the interrupt is enabled, it forwards an interrupt request to the core. If free-run mode is selected, it adds the auto-increment value to the value of the global counter and the resulting sum is saved as the new comparator value.

Parameters
highwordThe 32 MSBits of the new comparator value.
lowordThe 32 LSBits of the new comparator value.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_comp_set64 ( uint64_t  compval)

Sets the value of the 64-bit global timer comparator for this CPU. The global timer increments its count and when it reaches this value or above, it triggers the following actions. If the interrupt is enabled, it forwards an interrupt request to the core. If free-run mode is selected, it adds the auto-increment value to the value of the global counter and the resulting sum is saved as the new comparator value.

Parameters
compvalThe new comparator value to set.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_comp_get ( uint32_t *  highword,
uint32_t *  lowword 
)

Returns the current 64-bit global timer comparator value for this CPU. The global timer increments its count and when it reaches this value or above, it triggers the following actions. If the interrupt is enabled, it forwards an interrupt request to the core. If free-run mode is selected, it adds the auto-increment value to the value of the global counter and the resulting sum is saved as the new comparator value. This value will increase by the auto-increment value each time the global timer reaches the comparator value.

Parameters
highwordPointer to location to store the 32 MSBits of the comparator value.
lowwordPointer to location to store the 32 LSBits of the comparator value.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
uint64_t alt_globaltmr_comp_get64 ( void  )

Returns the current 64-bit global timer comparator value for this CPU. The global timer increments its count and when it reaches this value or above, it triggers the following actions. If the interrupt is enabled, it forwards an interrupt request to the core. If free-run mode is selected, it adds the auto-increment value to the value of the global counter and the resulting sum is saved as the new comparator value. This value will increase by the auto-increment value each time the global timer reaches the comparator value. This function is identical to alt_globaltmr_comp_get() except that the value is returned in a 64-bit unsigned integer rather than as two 32-bit words.

Return values
uint64_tThe 64-bit value of the global timer comparator.
ALT_STATUS_CODE alt_globaltmr_comp_mode_start ( void  )

Enables the comparison function of the global timer for this CPU.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_comp_mode_stop ( void  )

Disables the comparison function of the global timer for this CPU.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
bool alt_globaltmr_is_comp_mode ( void  )

Returns the comparison mode selection of the global timer for this CPU.

Return values
FALSEComparison mode is not enabled.
TRUEComparison mode is enabled.
uint32_t alt_globaltmr_prescaler_get ( void  )

Returns the clock prescaler value of the global timer.

Return values
uint32_tThe prescaler value. Valid range is 0-255. Actual clock divisor ratio is this number plus one.
ALT_STATUS_CODE alt_globaltmr_prescaler_set ( uint32_t  val)

Sets the clock prescaler value of the global timer.

Parameters
valThe 8-bit prescaler value to load. Valid range is 0-255. Actual clock divisor ratio is this number plus one.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_autoinc_set ( uint32_t  inc)

Sets a 32-bit global timer auto-increment value in the global timer block for this CPU. The global timer continually increments its count and when it reaches the value set in the comparator register or above, if both comparison and free-run modes are selected, it adds the value set by this function to the comparator value and saves it as the new comparator value. This count then sets the time delay until the next global timer compare value is reached.

Parameters
incAuto-increment value to set.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
uint32_t alt_globaltmr_autoinc_get ( void  )

Returns the global timer auto-increment value for this CPU. When the global timer reaches the comparator value, if both comparison and free-run modes are selected this value is added to the previous comparator value and saved as the new comparator value.

Return values
uint32_tThe current comparator auto-increment value.
ALT_STATUS_CODE alt_globaltmr_autoinc_mode_start ( void  )

Enables the auto-increment function of the global timer for this CPU.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_autoinc_mode_stop ( void  )

Disables the auto-increment function of the global timer for this CPU.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
bool alt_globaltmr_is_autoinc_mode ( void  )

Returns the auto-increment selection of the global timer for this CPU.

Return values
FALSEAuto-increment mode is not enabled.
TRUEAuto-increment mode is enabled.
uint32_t alt_globaltmr_maxcounter_get ( void  )

Returns the maximum counter value available for CPU_GLOBAL_TMR.
The value returned does not factor in the value of the clock prescaler.

Return values
uint32_tThe maximum counter value available for this timer.
0An error occurred.
ALT_STATUS_CODE alt_globaltmr_int_disable ( void  )

Disables the interrupt from the global timer module. Identical to calling alt_gpt_int_disable() with tmr_id of CPU_GLOBAL_TMR.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
ALT_STATUS_CODE alt_globaltmr_int_enable ( void  )

Enables the interrupt of the global timer module. Identical to calling alt_gpt_int_enable() with tmr_id of CPU_GLOBAL_TMR. If global timer is not already running, this function attempts to start it.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
bool alt_globaltmr_int_is_enabled ( void  )

Return TRUE if the interrupt of the global timer module is enabled and FALSE if the interrupt is disabled or masked. Identical to calling alt_gpt_int_is_enabled() with tmr_id of CPU_GLOBAL_TMR.

Return values
TRUEThe timer interrupt is currently enabled.
FALSEThe timer interrupt is currently disabled.
ALT_STATUS_CODE alt_globaltmr_int_clear_pending ( void  )

Clear the pending interrupt status of the global timer module. Identical to calling alt_gpt_int_clear_pending() with tmr_id of CPU_GLOBAL_TMR.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_E_BAD_ARGInvalid input argument.
bool alt_globaltmr_int_is_pending ( void  )

Read the state (pending or not) of the interrupt of the global timer module without changing the interrupt state. Identical to calling alt_gpt_int_is_pending() with tmr_id of CPU_GLOBAL_TMR.

Return values
TRUEThe timer interrupt is currently pending.
FALSEThe timer interrupt is not currently pending.
bool alt_globaltmr_int_if_pending_clear ( void  )

Read the state of the interrupt of the global timer module and if the interrupt is set, clear it. Identical to calling alt_gpt_int_is_pending_and_clear() with tmr_id of CPU_GLOBAL_TMR.

Return values
TRUEThe timer interrupt was pending.
FALSEThe timer interrupt was not pending.