![]() |
S32 SDK
|
Low Power Interrupt Timer Peripheral Driver.
Each LPIT timer channel can be configured to run in one of 4 modes:
32-bit Periodic Counter: In this mode the counter will load and then decrement down to zero. It will then set the timer interrupt flag and assert the output pre-trigger.
Dual 16-bit Periodic Counter: In this mode, the counter will load and then the lower 16-bits will decrement down to zero, which will assert the output pre-trigger. The upper 16-bits will then decrement down to zero, which will negate the output pre-trigger and set the timer interrupt flag.
32-bit Trigger Accumulator: In this mode, the counter will load on the first trigger rising edge and then decrement down to zero on each trigger rising edge. It will then set the timer interrupt flag and assert the output pre-trigger.
32-bit Trigger Input Capture: In this mode, the counter will load with 0xFFFF_FFFF and then decrement down to zero. If a trigger rising edge is detected, it will store the inverse of the current counter value in the load value register, set the timer interrupt flag and assert the output pre-trigger.
In these modes, the timer channel operation is further controlled by Trigger Control bits (TSOT, TSOI, TROT) which control the load, reload, start and restart of the timer channels.
The Driver uses structures for configuration. Each structure contains members that are specific to its respective functionality. There are lpit_user_config_t and lpit_user_channel_config_t.
Each LPIT timer channel has a corresponding interrupt handler. The LPIT Driver does not define interrupt handler internally. These interrupt handler methods can be defined by the user application. There are two ways to add an LPIT interrupt handler:
LPITx_Handler(void)
(x denotes instance number) are not defined, the linker use a default ISR. An error will be generated if methods with the same name are defined multiple times. This method works regardless of the placement of the interrupt vector table (Flash or RAM).INT_SYS_InstallHandler()
method. This can be used to dynamically change the ISR at run-time. This method works only if the interrupt vector table is located in RAM.The LPIT Driver does not handle clock setup (from PCC) configuration. This is handled by the Clock Manager. The driver assumes that clock configurations have been made, so it is the user's responsibility to set up clocking and pin configurations correctly.
Data Structures | |
struct | lpit_module_information_t |
Hardware information of LPIT module Implements : lpit_module_information_t_Class. More... | |
struct | lpit_user_config_t |
LPIT configuration structure. More... | |
struct | lpit_user_channel_config_t |
Structure to configure the channel timer. More... | |
Macros | |
#define | MAX_PERIOD_COUNT (0xFFFFFFFFU) |
Max period in count of all operation mode except for dual 16 bit periodic counter mode. More... | |
#define | MAX_PERIOD_COUNT_IN_DUAL_16BIT_MODE (0x1FFFEU) |
Max period in count of dual 16 bit periodic counter mode. More... | |
#define | MAX_PERIOD_COUNT_16_BIT (0xFFFFU) |
Max count of 16 bit. More... | |
Enumerations | |
enum | lpit_timer_modes_t { LPIT_PERIODIC_COUNTER = 0x00U, LPIT_DUAL_PERIODIC_COUNTER = 0x01U, LPIT_TRIGGER_ACCUMULATOR = 0x02U, LPIT_INPUT_CAPTURE = 0x03U } |
Mode options available for the LPIT timer Implements : lpit_timer_modes_t_Class. More... | |
enum | lpit_trigger_source_t { LPIT_TRIGGER_SOURCE_EXTERNAL = 0x00U, LPIT_TRIGGER_SOURCE_INTERNAL = 0x01U } |
Trigger source options. More... | |
enum | lpit_period_units_t { LPIT_PERIOD_UNITS_COUNTS = 0x00U, LPIT_PERIOD_UNITS_MICROSECONDS = 0x01U } |
Unit options for LPIT period. More... | |
Initialization and De-initialization | |
void | LPIT_DRV_Init (uint32_t instance, const lpit_user_config_t *userConfig) |
Initializes the LPIT module. More... | |
void | LPIT_DRV_Deinit (uint32_t instance) |
De-Initializes the LPIT module. More... | |
status_t | LPIT_DRV_InitChannel (uint32_t instance, uint32_t channel, const lpit_user_channel_config_t *userChannelConfig) |
Initializes the LPIT channel. More... | |
Timer Start and Stop | |
void | LPIT_DRV_StartTimerChannels (uint32_t instance, uint32_t mask) |
Starts the timer channel counting. More... | |
void | LPIT_DRV_StopTimerChannels (uint32_t instance, uint32_t mask) |
Stops the timer channel counting. More... | |
Timer Period | |
status_t | LPIT_DRV_SetTimerPeriodByUs (uint32_t instance, uint32_t channel, uint32_t periodUs) |
Sets the timer channel period in microseconds. More... | |
status_t | LPIT_DRV_SetTimerPeriodInDual16ModeByUs (uint32_t instance, uint32_t channel, uint16_t periodHigh, uint16_t periodLow) |
Sets the timer channel period in microseconds. More... | |
uint64_t | LPIT_DRV_GetTimerPeriodByUs (uint32_t instance, uint32_t channel) |
Gets the timer channel period in microseconds. More... | |
uint64_t | LPIT_DRV_GetCurrentTimerUs (uint32_t instance, uint32_t channel) |
Gets the current timer channel counting value in microseconds. More... | |
void | LPIT_DRV_SetTimerPeriodByCount (uint32_t instance, uint32_t channel, uint32_t count) |
Sets the timer channel period in count unit. More... | |
void | LPIT_DRV_SetTimerPeriodInDual16ModeByCount (uint32_t instance, uint32_t channel, uint16_t periodHigh, uint16_t periodLow) |
Sets the timer channel period in count unit. More... | |
uint32_t | LPIT_DRV_GetTimerPeriodByCount (uint32_t instance, uint32_t channel) |
Gets the current timer channel period in count unit. More... | |
uint32_t | LPIT_DRV_GetCurrentTimerCount (uint32_t instance, uint32_t channel) |
Gets the current timer channel counting value in count. More... | |
Interrupt | |
uint32_t | LPIT_DRV_GetInterruptFlagTimerChannels (uint32_t instance, uint32_t mask) |
Gets the current interrupt flag of timer channels. More... | |
void | LPIT_DRV_ClearInterruptFlagTimerChannels (uint32_t instance, uint32_t mask) |
Clears the interrupt flag of timer channels. More... | |
#define MAX_PERIOD_COUNT (0xFFFFFFFFU) |
Max period in count of all operation mode except for dual 16 bit periodic counter mode.
Definition at line 56 of file lpit_driver.h.
#define MAX_PERIOD_COUNT_16_BIT (0xFFFFU) |
Max count of 16 bit.
Definition at line 60 of file lpit_driver.h.
#define MAX_PERIOD_COUNT_IN_DUAL_16BIT_MODE (0x1FFFEU) |
Max period in count of dual 16 bit periodic counter mode.
Definition at line 58 of file lpit_driver.h.
enum lpit_period_units_t |
Unit options for LPIT period.
This is used to determine unit of timer period Implements : lpit_period_units_t_Class
Enumerator | |
---|---|
LPIT_PERIOD_UNITS_COUNTS |
Period value unit is count |
LPIT_PERIOD_UNITS_MICROSECONDS |
Period value unit is microsecond |
Definition at line 106 of file lpit_driver.h.
enum lpit_timer_modes_t |
Mode options available for the LPIT timer Implements : lpit_timer_modes_t_Class.
Definition at line 79 of file lpit_driver.h.
Trigger source options.
This is used for both internal and external trigger sources. The actual trigger options available is SoC specific, user should refer to the reference manual. Implements : lpit_trigger_source_t_Class
Enumerator | |
---|---|
LPIT_TRIGGER_SOURCE_EXTERNAL |
Use external trigger |
LPIT_TRIGGER_SOURCE_INTERNAL |
Use internal trigger |
Definition at line 94 of file lpit_driver.h.
void LPIT_DRV_ClearInterruptFlagTimerChannels | ( | uint32_t | instance, |
uint32_t | mask | ||
) |
Clears the interrupt flag of timer channels.
This function clears the interrupt flag of timer channels after their interrupt event occurred.
[in] | instance | LPIT module instance number |
[in] | mask | The interrupt flag clearing mask that decides which channels will be cleared interrupt flag
|
Definition at line 646 of file lpit_driver.c.
void LPIT_DRV_Deinit | ( | uint32_t | instance | ) |
De-Initializes the LPIT module.
This function disables LPIT module. In order to use the LPIT module again, LPIT_DRV_Init must be called.
[in] | instance | LPIT module instance number |
Definition at line 125 of file lpit_driver.c.
uint32_t LPIT_DRV_GetCurrentTimerCount | ( | uint32_t | instance, |
uint32_t | channel | ||
) |
Gets the current timer channel counting value in count.
This function returns the real-time timer channel counting value, the value in a range from 0 to timer channel period. Need to make sure the running time does not exceed the timer channel period.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
Definition at line 592 of file lpit_driver.c.
uint64_t LPIT_DRV_GetCurrentTimerUs | ( | uint32_t | instance, |
uint32_t | channel | ||
) |
Gets the current timer channel counting value in microseconds.
This function returns an absolute time stamp in microseconds. One common use of this function is to measure the running time of a part of code. Call this function at both the beginning and end of code. The time difference between these two time stamps is the running time. The return counting value here makes sense if the operation mode of timer channel is 32 bit periodic counter or dual 16 bit periodic counter or 32-bit trigger input capture. Need to make sure the running time will not exceed the timer channel period.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
Definition at line 457 of file lpit_driver.c.
uint32_t LPIT_DRV_GetInterruptFlagTimerChannels | ( | uint32_t | instance, |
uint32_t | mask | ||
) |
Gets the current interrupt flag of timer channels.
This function gets the current interrupt flag of timer channels. In compare modes, the flag sets to 1 at the end of the timer period. In capture modes, the flag sets to 1 when the trigger asserts.
[in] | instance | LPIT module instance number. |
[in] | mask | The interrupt flag getting mask that decides which channels will be got interrupt flag.
|
Definition at line 625 of file lpit_driver.c.
uint32_t LPIT_DRV_GetTimerPeriodByCount | ( | uint32_t | instance, |
uint32_t | channel | ||
) |
Gets the current timer channel period in count unit.
This function returns current period of timer channel given as argument.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
Definition at line 558 of file lpit_driver.c.
uint64_t LPIT_DRV_GetTimerPeriodByUs | ( | uint32_t | instance, |
uint32_t | channel | ||
) |
Gets the timer channel period in microseconds.
This function gets the timer channel period in microseconds. The returned period here makes sense if the operation mode of timer channel is 32 bit periodic counter or dual 16 bit periodic counter.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
Definition at line 398 of file lpit_driver.c.
void LPIT_DRV_Init | ( | uint32_t | instance, |
const lpit_user_config_t * | userConfig | ||
) |
Initializes the LPIT module.
This function resets LPIT module, enables the LPIT module, configures LPIT module operation in Debug and DOZE mode. The LPIT configuration structure shall be passed as arguments. This configuration structure affects all timer channels. This function should be called before calling any other LPIT driver function.
This is an example demonstrating how to define a LPIT configuration structure:
[in] | instance | LPIT module instance number. |
[in] | userConfig | Pointer to LPIT configuration structure. |
Definition at line 90 of file lpit_driver.c.
status_t LPIT_DRV_InitChannel | ( | uint32_t | instance, |
uint32_t | channel, | ||
const lpit_user_channel_config_t * | userChannelConfig | ||
) |
Initializes the LPIT channel.
This function initializes the LPIT timers by using a channel, this function configures timer channel chaining, timer channel mode, timer channel period, interrupt generation, trigger source, trigger select, reload on trigger, stop on interrupt and start on trigger. The timer channel number and its configuration structure shall be passed as arguments. Timer channels do not start counting by default after calling this function. The function LPIT_DRV_StartTimerChannels must be called to start the timer channel counting. In order to re-configures the period, call the LPIT_DRV_SetTimerPeriodByUs or LPIT_DRV_SetTimerPeriodByCount.
This is an example demonstrating how to define a LPIT channel configuration structure:
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
[in] | userChannelConfig | Pointer to LPIT channel configuration structure |
Definition at line 152 of file lpit_driver.c.
void LPIT_DRV_SetTimerPeriodByCount | ( | uint32_t | instance, |
uint32_t | channel, | ||
uint32_t | count | ||
) |
Sets the timer channel period in count unit.
This function sets the timer channel period in count unit. The counter period of a running timer channel can be modified by first setting a new load value, the value will be loaded after the timer channel expires. To abort the current cycle and start a timer channel period with the new value, the timer channel must be disabled and enabled again.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
[in] | count | Timer channel period in count unit |
Definition at line 504 of file lpit_driver.c.
status_t LPIT_DRV_SetTimerPeriodByUs | ( | uint32_t | instance, |
uint32_t | channel, | ||
uint32_t | periodUs | ||
) |
Sets the timer channel period in microseconds.
This function sets the timer channel period in microseconds when timer channel mode is 32 bit periodic or dual 16 bit counter mode. The period range depends on the frequency of the LPIT functional clock and operation mode of timer channel. If the required period is out of range, use the suitable mode if applicable. This function is only valid for one single channel.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
[in] | periodUs | Timer channel period in microseconds |
Definition at line 274 of file lpit_driver.c.
void LPIT_DRV_SetTimerPeriodInDual16ModeByCount | ( | uint32_t | instance, |
uint32_t | channel, | ||
uint16_t | periodHigh, | ||
uint16_t | periodLow | ||
) |
Sets the timer channel period in count unit.
This function sets the timer channel period in count unit when timer channel mode is dual 16 periodic counter mode. The counter period of a running timer channel can be modified by first setting a new load value, the value will be loaded after the timer channel expires. To abort the current cycle and start a timer channel period with the new value, the timer channel must be disabled and enabled again.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
[in] | periodHigh | Period of higher 16 bit in count unit |
[in] | periodLow | Period of lower 16 bit in count unit |
Definition at line 532 of file lpit_driver.c.
status_t LPIT_DRV_SetTimerPeriodInDual16ModeByUs | ( | uint32_t | instance, |
uint32_t | channel, | ||
uint16_t | periodHigh, | ||
uint16_t | periodLow | ||
) |
Sets the timer channel period in microseconds.
This function sets the timer channel period in microseconds when timer channel mode is dual 16 bit periodic counter mode. The period range depends on the frequency of the LPIT functional clock and operation mode of timer channel. If the required period is out of range, use the suitable mode if applicable. This function is only valid for one single channel.
[in] | instance | LPIT module instance number |
[in] | channel | Timer channel number |
[in] | periodHigh | Period of higher 16 bit in microseconds |
[in] | periodLow | Period of lower 16 bit in microseconds |
Definition at line 345 of file lpit_driver.c.
void LPIT_DRV_StartTimerChannels | ( | uint32_t | instance, |
uint32_t | mask | ||
) |
Starts the timer channel counting.
This function allows starting timer channels simultaneously . After calling this function, timer channels are going operate depend on mode and control bits which controls timer channel start, reload and restart.
[in] | instance | LPIT module instance number |
[in] | mask | Timer channels starting mask that decides which channels will be started
|
Definition at line 224 of file lpit_driver.c.
void LPIT_DRV_StopTimerChannels | ( | uint32_t | instance, |
uint32_t | mask | ||
) |
Stops the timer channel counting.
This function allows stop timer channels simultaneously from counting. Timer channels reload their periods respectively after the next time they call the LPIT_DRV_StartTimerChannels. Note that: In 32-bit Trigger Accumulator mode, the counter will load on the first trigger rising edge.
[in] | instance | LPIT module instance number |
[in] | mask | Timer channels stopping mask that decides which channels will be stopped
|
Definition at line 248 of file lpit_driver.c.