This functional group handles setting and reading the general purpose timer counters and the global timer.
ALT_STATUS_CODE alt_gpt_counter_set |
( |
ALT_GPT_TIMER_t |
tmr_id, |
|
|
uint32_t |
val |
|
) |
| |
For tmr_id = CPU_PRIVATE_TMR, OSC1_TMR0, OSC1_TMR1, SP_TMR0, or SP_TMR1, sets the countdown value of the specified timer and the value that the counter will reset to (in rollover mode) or if restarted (in one-shot mode). It does not automatically start the counter.
For tmr_id = CPU_GLOBAL_TMR, this function sets the auto-increment value instead, which is similar in function to setting the reset value of the other timers. The effect of this function is identical to using alt_globaltmr_autoinc_set().
- Parameters
-
tmr_id | The timer identifier. |
val | The 32-bit counter value to load. |
- Return values
-
ALT_E_SUCCESS | The operation was successful. |
ALT_E_ERROR | The operation failed. |
ALT_E_BAD_ARG | Invalid input argument. |
For tmr_id = CPU_PRIVATE_TMR, OSC1_TMR0, OSC1_TMR1, SP_TMR0, or SP_TMR1, returns the current counter value of the specified timer.
For tmr_id = CPU_GLOBAL_TMR, returns the 32 low-order bits of the counter and is identical to the result returned by alt_globaltmr_counter_get_low32(). Use alt_globaltmr_get() to obtain the full 64-bit timer value.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current 32-bit counter value. |
For tmr_id = CPU_PRIVATE_TMR, OSC1_TMR0, OSC1_TMR1, SP_TMR0, or SP_TMR1, returns the counter value that is set to be reloaded when the specified timer hits zero.
For tmr_id = CPU_GLOBAL_TMR, returns the value that will autoincrement the comparator value, which defines the time until the next comparator interrupt is triggered. This is similar in function to the reset value of the other timers. It is identical to the result returned by alt_globaltmr_autoinc_get().
The value returned does not take into CPU_PRIVATE_TMR and CPU_GLOBAL_TMR. The prescaler value may be obtained with alt_gpt_prescaler_get().
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The reset counter value currently set. |
0 | An error occurred. |
Returns the maximum counter value available for the specified timer. Valid for CPU_PRIVATE_TMR, OSC1_TMR0, OSC1_TMR1, SP_TMR0, SP_TMR1, and CPU_GLOBAL_TMR.
The value returned does not factor in the value of the clock prescaler available for CPU_PRIVATE_TMR and CPU_GLOBAL_TMR.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The maximum counter value available for this timer. |
0 | An error occurred. |
ALT_STATUS_CODE alt_gpt_prescaler_set |
( |
ALT_GPT_TIMER_t |
tmr_id, |
|
|
uint32_t |
val |
|
) |
| |
Sets the clock prescaler value of the specified timer. Valid for CPU_PRIVATE_TMR and CPU_GLOBAL_TMR. Returns an error if called with a tmr_id of OSC1_TMR0, OSC1_TMR1, SP_TMR0, or SP_TMR1 since they have no prescaler.
- Parameters
-
tmr_id | The timer identifier. |
val | The 32-bit prescaler value to load. Valid range is 0-255. |
- Return values
-
ALT_E_SUCCESS | The operation was successful. |
ALT_E_ERROR | The operation failed. |
ALT_E_BAD_ARG | Invalid input argument. |
Returns the clock prescaler value of the specified timer. Valid for CPU_PRIVATE_TMR and CPU_GLOBAL_TMR. Returns zero if called with a tmr_id of OSC1_TMR0, OSC1_TMR1, SP_TMR0, or SP_TMR1 since they have no prescaler.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The prescaler value. Valid range is 1-256. Zero indicates an error. |
Returns the integer portion of the current countdown frequency of the specified timer. This is equal to 1/period of the specified timer.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
unint32_t | The integer portion of the repeat frequency of the given timer, measured in Hertz (cycles per second). |
Returns the current period of the specified timer measured in seconds. If the result is less than 64, alt_gpt_millisecs_get() will give a more precise result.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current period of the given timer, measured in seconds. |
Returns the current period of the specified timer measured in milliseconds.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current period of the given timer, measured in milliseconds. Returns 0 if result cannot fit in 32 bits. alt_gpt_time_get() can be used to obtain measurements of longer periods. alt_gpt_microsecs_get() can be used to obtain more precise measurements of shorter periods. |
Returns the current period of the specified timer measured in milliseconds.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current period of the given timer, measured in microseconds. Returns 0 if result cannot fit in 32 bits. alt_gpt_millisecs_get() and alt_gpt_time_get() can be used to obtain measurements of longer periods. |
Returns the current time until the specified timer counts down to zero, measured in seconds.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current 32-bit counter value. |
Returns the current time until the specified timer counts down to zero, measured in milliseconds.
Returns 0xFFFFFFFF if the value is too large to be expressed in 32 bits.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current 32-bit counter value. |
Returns the current time until the specified timer counts down to zero, measured in microseconds.
Returns 0xFFFFFFFF if the value is too large to be expressed in 32 bits.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current 32-bit counter value. |
Returns the current time until the specified timer counts down to zero, measured in nanoseconds.
Returns 0xFFFFFFFF if the value is too large to be expressed in 32 bits.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The current 32-bit counter value. |
Returns the maximum available period of the specified timer measured in seconds.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The maximum period of the given timer, measured in seconds. Returns 0 if result cannot fit in 32 bits. |
Returns the maximum available period of the specified timer measured in milliseconds.
- Parameters
-
tmr_id | The timer identifier. |
- Return values
-
uint32_t | The maximum period of the given timer, measured in milliseconds. Returns 0 if result cannot fit in 32 bits. |