This section describes the programming interface of the LPTMR Peripheral driver. The LPTMR driver configures the LPTMR.
LPTMR Initialization
-
To initialize the LPTMR module, call the LPTMR_DRV_Init() function and pass in the user configuration data structure. This function automatically enables the LPTMR module and clock .
-
After the LPTMR_DRV_Init() function is called, call the LPTRM_DRV_Start to start the LPTMR.
-
To stop the LPTMR counter, call the LPTMR_DRV_Stop.
This is example code to configure the driver:
{
.freeRunningEnable = false,
.intEnable = true,
.compareValue = 1024,
.prescalerEnable = true,
.prescalerClockSource = kLptmrPrescalerClockSourceLpo,
.prescalerValue = kLptmrPrescalerDivede2,
};
LPTMR Interrupt
-
Enable the LPTMR interrupt. The LPTMR interrupt is enabled in the user configuration structure with the lptmr_user_config_t.intEnable=true.
-
Define the LPTMR IRQ function.
void LPTimer_IRQHandler()
{
if(true == LPTMR_DRV_IsIntPending(0))
{
LPTMR_DRV_ClearIntFlag(0);
}
lptmrIsrAssertCount++;
}
|
typedef void(* | lptmr_callback_t )(void) |
| Defines a type of the user-defined callback function.
|
|
struct lptmr_user_config_t |
This structure is used when initializing the LPTMR during the LPTMR_DRV_Init function call.
bool lptmr_user_config_t::freeRunningEnable |
True means enable free running
bool lptmr_user_config_t::prescalerEnable |
True means enable prescaler
The contents of this structure are internal to the driver and should not be modified by users. Contents of the structure are subject to change in future releases.
This function initializes the LPTMR. The LPTMR can be initialized as a time counter or pulse counter, which is determined by the timerMode in the lptmr_user_config_t. pinSelect and pinPolarity do not need to be configured while working as a time counter.
- Parameters
-
instance | The LPTMR peripheral instance number. |
userStatePtr | The pointer to the structure of the context memory, see lptmr_state_t. |
userConfigPtr | The pointer to the LPTMR user configure structure, see lptmr_user_config_t. |
- Returns
- kStatus_LPTMR_Success means succeed, otherwise means failed.
This function deinitializes the LPTMR. It disables the interrupt and turns off the LPTMR clock.
- Parameters
-
instance | The LPTMR peripheral instance number. |
- Returns
- kStatus_LPTMR_Success means succeed, otherwise means failed.
This function starts the LPTMR counter. Ensure that all necessary configurations are set before calling this function.
- Parameters
-
instance | The LPTMR peripheral instance number. |
- Returns
- kStatus_LPTMR_Success means success. Otherwise, means failure.
This function stops the LPTMR counter.
- Parameters
-
instance | The LPTMR peripheral instance number. |
- Returns
- kStatus_LPTMR_Success means success. Otherwise, means failure.
lptmr_status_t LPTMR_DRV_SetTimerPeriodUs |
( |
uint32_t |
instance, |
|
|
uint32_t |
us |
|
) |
| |
This function configures the LPTMR time period while the LPTMR is working as a time counter. After the time period in microseconds, the callback function is called. This function cannot be called while the LPTMR is working as a pulse counter. The value in microseconds (us) should be integer multiple of the clock source time slice. If the clock source is 1 kHz, then both 2000 µs and 3000 µs are valid while 2500 µs gets the same result as the 2000 µs, because 2500 µs cannot be generated in 1 kHz clock source.
- Parameters
-
instance | The LPTMR peripheral instance number. |
us | time period in microseconds. |
- Returns
- kStatus_LPTMR_Success means success. Otherwise, means failure.
uint32_t LPTMR_DRV_GetCurrentTimeUs |
( |
uint32_t |
instance | ) |
|
This function gets the current time while operating as a time counter. This function cannot be called while operating as a pulse counter.
- Parameters
-
instance | The LPTMR peripheral instance number. |
- Returns
- current time in microsecond unit.
lptmr_status_t LPTMR_DRV_SetPulsePeriodCount |
( |
uint32_t |
instance, |
|
|
uint32_t |
pulsePeriodCount |
|
) |
| |
This function configures the pulse period of the LPTMR while working as a pulse counter. After the count of pulsePeriodValue pulse is captured, the callback function is called. This function cannot be called while operating as a time counter.
- Parameters
-
instance | The LPTMR peripheral instance number. |
pulsePeriodCount | pulse period value. |
- Returns
- kStatus_LPTMR_Success means success. Otherwise, means failure.
uint32_t LPTMR_DRV_GetCurrentPulseCount |
( |
uint32_t |
instance | ) |
|
This function gets the current pulse count captured on the pulse input pin. This function cannot be called while operating as a time counter.
- Parameters
-
instance | The LPTMR peripheral instance number. |
- Returns
- pulse count captured on the pulse input pin.
This function installs the user-defined callback in the LPTMR module. When an LPTMR interrupt request is served, the callback is executed inside the ISR.
- Parameters
-
instance | LPTMR instance ID. |
userCallback | User-defined callback function. |
- Returns
- kStatus_LPTMR_Success means success. Otherwise, means failure.
void LPTMR_DRV_IRQHandler |
( |
uint32_t |
instance | ) |
|
This function is the driver-defined ISR in the LPTMR module. It includes the process for interrupt mode defined by the driver. Currently, it is called inside the system-defined ISR.
- Parameters
-
instance | LPTMR instance ID. |
LPTMR_Type* const g_lptmrBase[] |
const IRQn_Type g_lptmrIrqId[LPTMR_INSTANCE_COUNT] |