![]() |
S32 SDK
|
Low Power Timer Peripheral Driver.
The LPTMR is a configurable general-purpose 16-bit counter that has two operational modes: Timer and Pulse-Counter.
Depending on the configured operational mode, the counter in the LPTMR can be incremented using a clock input (Timer mode) or an event counter (external events like button presses or internal events from different trigger souces).
In Timer mode, the LPTMR increments the internal counter from a selectable clock source. An optional 16-bit prescaler can be configured.
In Pulse-Counter Mode, the LPTMR counter increments from a selectable trigger source, input pin, which can be an external event (like a button press) or internal events (like triggers from TRGMUX).
An optional 16-bit glitch-fiter can be configured to reject events that have a duration below a set period.
Before configuring the LPTMR, the peripheral clock must be must be enabled from the PCC module.
The peripheral clock must not be confused with the counter clock, which is selectable within the LPTMR.
The LPTMR driver allows configuring the LPTMR for Pulse-Counter Mode or Timer Mode via the general configuration structure.
Configurable options:
Some of the features exposed by the API are targeted specifically for Timer Mode or Pulse-Counter Mode. For example, configuring the Compare Value in microseconds makes sense only for Timer Mode, so therefor it is restricted for use in Pulse-Counter mode.
For any invalid configuration the functions will either return an error code or trigger DEV_ASSERT (if enabled). For more details, please refer to each function description.
Data Structures | |
struct | lptmr_config_t |
Defines the configuration structure for LPTMR. More... | |
Enumerations | |
enum | lptmr_counter_units_t { LPTMR_COUNTER_UNITS_TICKS = 0x00U, LPTMR_COUNTER_UNITS_MICROSECONDS = 0x01U } |
Defines the LPTMR counter units available for configuring or reading the timer compare value. More... | |
LPTMR Driver Functions | |
void | LPTMR_DRV_InitConfigStruct (lptmr_config_t *const config) |
Initialize a configuration structure with default values. More... | |
void | LPTMR_DRV_Init (const uint32_t instance, const lptmr_config_t *const config, const bool startCounter) |
Initialize a LPTMR instance with values from an input configuration structure. More... | |
void | LPTMR_DRV_SetConfig (const uint32_t instance, const lptmr_config_t *const config) |
Configure a LPTMR instance. More... | |
void | LPTMR_DRV_GetConfig (const uint32_t instance, lptmr_config_t *const config) |
Get the current configuration of a LPTMR instance. More... | |
void | LPTMR_DRV_Deinit (const uint32_t instance) |
De-initialize a LPTMR instance. More... | |
status_t | LPTMR_DRV_SetCompareValueByCount (const uint32_t instance, const uint16_t compareValueByCount) |
Set the compare value in counter tick units, for a LPTMR instance. More... | |
void | LPTMR_DRV_GetCompareValueByCount (const uint32_t instance, uint16_t *const compareValueByCount) |
Get the compare value in counter tick units, of a LPTMR instance. More... | |
status_t | LPTMR_DRV_SetCompareValueByUs (const uint32_t instance, const uint32_t compareValueUs) |
Set the compare value for Timer Mode in microseconds, for a LPTMR instance. More... | |
void | LPTMR_DRV_GetCompareValueByUs (const uint32_t instance, uint32_t *const compareValueUs) |
Get the compare value in microseconds, of a LPTMR instance. More... | |
bool | LPTMR_DRV_GetCompareFlag (const uint32_t instance) |
Get the current state of the Compare Flag of a LPTMR instance. More... | |
void | LPTMR_DRV_ClearCompareFlag (const uint32_t instance) |
Clear the Compare Flag of a LPTMR instance. More... | |
bool | LPTMR_DRV_IsRunning (const uint32_t instance) |
Get the run state of a LPTMR instance. More... | |
void | LPTMR_DRV_SetInterrupt (const uint32_t instance, const bool enableInterrupt) |
Enable/disable the LPTMR interrupt. More... | |
uint16_t | LPTMR_DRV_GetCounterValueByCount (const uint32_t instance) |
Get the current counter value in counter tick units. More... | |
void | LPTMR_DRV_StartCounter (const uint32_t instance) |
Enable the LPTMR / Start the counter. More... | |
void | LPTMR_DRV_StopCounter (const uint32_t instance) |
Disable the LPTMR / Stop the counter. More... | |
void | LPTMR_DRV_SetPinConfiguration (const uint32_t instance, const lptmr_pinselect_t pinSelect, const lptmr_pinpolarity_t pinPolarity) |
Set the Input Pin configuration for Pulse Counter mode. More... | |
Defines the LPTMR counter units available for configuring or reading the timer compare value.
Implements : lptmr_counter_units_t_Class
Enumerator | |
---|---|
LPTMR_COUNTER_UNITS_TICKS | |
LPTMR_COUNTER_UNITS_MICROSECONDS |
Definition at line 44 of file lptmr_driver.h.
void LPTMR_DRV_ClearCompareFlag | ( | const uint32_t | instance | ) |
Clear the Compare Flag of a LPTMR instance.
[in] | instance | - LPTMR instance number |
void LPTMR_DRV_Deinit | ( | const uint32_t | instance | ) |
De-initialize a LPTMR instance.
[in] | instance | - LPTMR instance number |
bool LPTMR_DRV_GetCompareFlag | ( | const uint32_t | instance | ) |
Get the current state of the Compare Flag of a LPTMR instance.
[in] | instance | - LPTMR instance number |
void LPTMR_DRV_GetCompareValueByCount | ( | const uint32_t | instance, |
uint16_t *const | compareValueByCount | ||
) |
Get the compare value in counter tick units, of a LPTMR instance.
[in] | instance | - LPTMR instance number |
[out] | compareValueByCount | - pointer to current compare value, in counter ticks |
void LPTMR_DRV_GetCompareValueByUs | ( | const uint32_t | instance, |
uint32_t *const | compareValueUs | ||
) |
Get the compare value in microseconds, of a LPTMR instance.
[in] | instance | - LPTMR instance number |
[out] | compareValueUs | - pointer to current compare value, in microseconds |
void LPTMR_DRV_GetConfig | ( | const uint32_t | instance, |
lptmr_config_t *const | config | ||
) |
Get the current configuration of a LPTMR instance.
[in] | instance | - LPTMR instance number |
[out] | config | - pointer to the output configuration structure |
uint16_t LPTMR_DRV_GetCounterValueByCount | ( | const uint32_t | instance | ) |
Get the current counter value in counter tick units.
[in] | instance | - LPTMR instance number |
void LPTMR_DRV_Init | ( | const uint32_t | instance, |
const lptmr_config_t *const | config, | ||
const bool | startCounter | ||
) |
Initialize a LPTMR instance with values from an input configuration structure.
When (counterUnits == LPTMR_COUNTER_UNITS_MICROSECONDS) the function will automatically configure the timer for the input compareValue in microseconds. The input params for 'prescaler' and 'bypassPrescaler' will be ignored - their values will be adapted by the function, to best fit the input compareValue (in microseconds) for the operating clock frequency.
LPTMR_COUNTER_UNITS_MICROSECONDS may only be used for LPTMR_WORKMODE_TIMER mode. Otherwise the function shall not convert 'compareValue' in ticks and this is likely to cause erroneous behavior.
When (counterUnits == LPTMR_COUNTER_UNITS_TICKS) the function will use the 'prescaler' and 'bypassPrescaler' provided in the input config structure.
[in] | instance | - LPTMR instance number |
[in] | config | - pointer to the input configuration structure |
[in] | startCounter | - flag for starting the counter immediately after configuration |
void LPTMR_DRV_InitConfigStruct | ( | lptmr_config_t *const | config | ) |
Initialize a configuration structure with default values.
[out] | config | - pointer to the configuration structure to be initialized |
bool LPTMR_DRV_IsRunning | ( | const uint32_t | instance | ) |
Get the run state of a LPTMR instance.
[in] | instance | - LPTMR instance number |
status_t LPTMR_DRV_SetCompareValueByCount | ( | const uint32_t | instance, |
const uint16_t | compareValueByCount | ||
) |
Set the compare value in counter tick units, for a LPTMR instance.
[in] | instance | - LPTMR instance number |
[in] | compareValueByCount | - the compare value in counter ticks, to be written |
status_t LPTMR_DRV_SetCompareValueByUs | ( | const uint32_t | instance, |
const uint32_t | compareValueUs | ||
) |
Set the compare value for Timer Mode in microseconds, for a LPTMR instance.
[in] | instance | - LPTMR peripheral instance number |
[in] | compareValueUs | - compare value in microseconds |
void LPTMR_DRV_SetConfig | ( | const uint32_t | instance, |
const lptmr_config_t *const | config | ||
) |
Configure a LPTMR instance.
When (counterUnits == LPTMR_COUNTER_UNITS_MICROSECONDS) the function will automatically configure the timer for the input compareValue in microseconds. The input params for 'prescaler' and 'bypassPrescaler' will be ignored - their values will be adapted by the function, to best fit the input compareValue (in microseconds) for the operating clock frequency.
LPTMR_COUNTER_UNITS_MICROSECONDS may only be used for LPTMR_WORKMODE_TIMER mode. Otherwise the function shall not convert 'compareValue' in ticks and this is likely to cause erroneous behavior.
When (counterUnits == LPTMR_COUNTER_UNITS_TICKS) the function will use the 'prescaler' and 'bypassPrescaler' provided in the input config structure.
[in] | instance | - LPTMR instance number |
[in] | config | - pointer to the input configuration structure |
void LPTMR_DRV_SetInterrupt | ( | const uint32_t | instance, |
const bool | enableInterrupt | ||
) |
Enable/disable the LPTMR interrupt.
[in] | instance | - LPTMR instance number |
[in] | enableInterrupt | - the new state of the LPTMR interrupt enable flag. |
void LPTMR_DRV_SetPinConfiguration | ( | const uint32_t | instance, |
const lptmr_pinselect_t | pinSelect, | ||
const lptmr_pinpolarity_t | pinPolarity | ||
) |
Set the Input Pin configuration for Pulse Counter mode.
[in] | instance | - LPTMR instance number |
[in] | pinSelect | - LPTMR pin selection |
[in] | pinPolarity | - polarity on which to increment counter (rising/falling edge) |
void LPTMR_DRV_StartCounter | ( | const uint32_t | instance | ) |
Enable the LPTMR / Start the counter.
[in] | instance | - LPTMR instance number |
void LPTMR_DRV_StopCounter | ( | const uint32_t | instance | ) |
Disable the LPTMR / Stop the counter.
[in] | instance | - LPTMR instance number |