The section describes the programming interface of the TPM Peripheral driver. The TPM module is a timer that supports input capture, ouput compare, and generation of PWM signals. The current SDK driver supports supports all features.
TPM Initialization
-
To initialize the TPM driver, call the TPM_DRV_Init() function and pass the instance number of the relevant TPM. For example, to use TPM0, pass a value 0 to the initialization function.
-
Pass a user configuration structure tpm_general_config_t, as shown here:
typedef struct TpmGeneralConfig {
bool isDBGMode;
bool isGlobalTimeBase;
bool isTriggerMode;
bool isStopCountOnOveflow;
bool isCountReloadOnTrig;
TPM Generate a PWM signal
Call the TPM_DRV_PwmStart() function to generate a PWM signal. Use this structure to configure the different parameters related to this PWM signal.
typedef struct TpmPwmParam
{
uint32_t uFrequencyHZ;
uint32_t uDutyCyclePercent;
0=inactive signal(0% duty cycle)...
100=active signal (100% duty cycle).
The mode options are kTpmEdgeAlignedPWM and kTpmCenterAlignedPWM. For edge mode, the options are kTpmHighTrue and kTpmLowTrue. Specify the PWM signal frequency in Hertz and the duty cycle percentage (value between 0-100).
TPM Input Capture
Call the TPM_DRV_InputCaptureEnable() function to set up the channel for input capture. Use this enumeration to specify the capture mode:
typedef enum _tpm_input_capture_mode_t
{
kTpmRisingEdge = 1,
kTpmFallingEdge,
kTpmRiseOrFallEdge
To enable channel interrupts, use the intEnable argument of the function.
Call the TPM_DRV_GetChnVal() function to read the captured LPTPM counter value.
TPM Output Compare
Call the TPM_DRV_OutputCompareEnable() function to set up the channel for output compare. Use this enumeration to specify the compare mode:
typedef enum _tpm_output_compare_mode_t
{
kTpmOutputNone = 0,
kTpmToggleOutput,
kTpmClearOutput,
kTpmSetOutput,
kTpmHighPulseOutput,
kTpmLowPulseOutput
To enable channel interrupts, use the intEnable argument of the function. The matchVal argument of the function is written to the CnV register.
TPM Interrupt handler
The TPM driver provides an interrupt handler for the counter overflow and channel interrupts. These handlers clear the status bits.
To add more actions to the default handler, add calls to the functions inside the interrupt handlers TPMx_IRQHandler() function, where x=0, 1, 2 depending on the TPM instance.
|
tpm_status_t | TPM_DRV_Init (uint32_t instance, const tpm_general_config_t *info) |
| Initializes the TPM driver. More...
|
|
void | TPM_DRV_PwmStop (uint32_t instance, tpm_pwm_param_t *param, uint8_t channel) |
| Stops the channel PWM. More...
|
|
tpm_status_t | TPM_DRV_PwmStart (uint32_t instance, tpm_pwm_param_t *param, uint8_t channel) |
| Configures the duty cycle and frequency and starts outputting PWM on a specified channel. More...
|
|
void | TPM_DRV_SetTimeOverflowIntCmd (uint32_t instance, bool overflowEnable) |
| Enables or disables the timer overflow interrupt. More...
|
|
void | TPM_DRV_SetChnIntCmd (uint32_t instance, uint8_t channelNum, bool enable) |
| Enables or disables the channel interrupt. More...
|
|
void | TPM_DRV_SetClock (uint32_t instance, tpm_clock_mode_t clock, tpm_clock_ps_t clockPs) |
| Sets the TPM clock source. More...
|
|
uint32_t | TPM_DRV_GetClock (uint32_t instance) |
| Gets the TPM clock frequency. More...
|
|
void | TPM_DRV_CounterStart (uint32_t instance, tpm_counting_mode_t countMode, uint32_t countFinalVal, bool enableOverflowInt) |
| Starts the TPM counter. More...
|
|
void | TPM_DRV_CounterStop (uint32_t instance) |
| Stops the TPM counter. More...
|
|
uint32_t | TPM_DRV_CounterRead (uint32_t instance) |
| Reads back the current value of the TPM counter. More...
|
|
void | TPM_DRV_InputCaptureEnable (uint32_t instance, uint8_t channel, tpm_input_capture_mode_t mode, uint32_t countFinalVal, bool intEnable) |
| TPM input capture mode setup. More...
|
|
uint32_t | TPM_DRV_GetChnVal (uint32_t instance, uint8_t channel) |
| Reads back the current value of the TPM channel value. More...
|
|
void | TPM_DRV_OutputCompareEnable (uint32_t instance, uint8_t channel, tpm_output_compare_mode_t mode, uint32_t countFinalVal, uint32_t matchVal, bool intEnable) |
| TPM output compare mode setup. More...
|
|
void | TPM_DRV_Deinit (uint32_t instance) |
| Shuts down the TPM driver. More...
|
|
void | TPM_DRV_IRQHandler (uint32_t instance) |
| Action to take when an TPM interrupt is triggered. More...
|
|
|
TPM_Type *const | g_tpmBase [TPM_INSTANCE_COUNT] |
| Table of base addresses for TPM instances. More...
|
|
const IRQn_Type | g_tpmIrqId [TPM_INSTANCE_COUNT] |
| Table to save TPM IRQ numbers for TPM instances. More...
|
|
struct tpm_general_config_t |
User needs to set the relevant ones.
- Parameters
-
instance | The TPM peripheral instance number. |
info | Pointer to the TPM user configuration structure, see tpm_general_config_t. |
- Returns
- kStatusTpmSuccess means success; Otherwise means failure.
void TPM_DRV_PwmStop |
( |
uint32_t |
instance, |
|
|
tpm_pwm_param_t * |
param, |
|
|
uint8_t |
channel |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
param | PWM parameter to configure PWM options |
channel | The channel number. |
- Parameters
-
instance | The TPM peripheral instance number. |
param | PWM parameter to configure PWM options, see tpm_pwm_param_t. |
channel | The channel number. |
- Returns
- kStatusTpmSuccess means success; Otherwise means failure.
void TPM_DRV_SetTimeOverflowIntCmd |
( |
uint32_t |
instance, |
|
|
bool |
overflowEnable |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
overflowEnable | true: enable the timer overflow interrupt, false: disable |
void TPM_DRV_SetChnIntCmd |
( |
uint32_t |
instance, |
|
|
uint8_t |
channelNum, |
|
|
bool |
enable |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
channelNum | The channel number. |
enable | true: enable the channel interrupt, false: disable |
- Parameters
-
instance | The TPM peripheral instance number. |
clock | The TPM peripheral clock selection, see tpm_clock_mode_t. |
clockPs | The TPM peripheral clock prescale factor, see tpm_clock_ps_t. |
uint32_t TPM_DRV_GetClock |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The TPM peripheral instance number. |
- Returns
- The function returns the frequency of the TPM clock.
void TPM_DRV_CounterStart |
( |
uint32_t |
instance, |
|
|
tpm_counting_mode_t |
countMode, |
|
|
uint32_t |
countFinalVal, |
|
|
bool |
enableOverflowInt |
|
) |
| |
This function provides access to the TPM counter. The counter can run in up-counting and up-down counting modes.
- Parameters
-
instance | The TPM peripheral instance number. |
countMode | The TPM counter mode defined by tpm_counting_mode_t. |
countFinalVal | The final value that is stored in the MOD register. |
enableOverflowInt | true: enable timer overflow interrupt; false: disable |
void TPM_DRV_CounterStop |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The TPM peripheral instance number. |
uint32_t TPM_DRV_CounterRead |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The TPM peripheral instance number. |
- Returns
- The current value of the TPM counter.
void TPM_DRV_InputCaptureEnable |
( |
uint32_t |
instance, |
|
|
uint8_t |
channel, |
|
|
tpm_input_capture_mode_t |
mode, |
|
|
uint32_t |
countFinalVal, |
|
|
bool |
intEnable |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
channel | The channel number. |
mode | The TPM input mode defined by tpm_input_capture_mode_t. |
countFinalVal | The final value that is stored in the MOD register. |
intEnable | true: enable channel interrupt; false: disable |
uint32_t TPM_DRV_GetChnVal |
( |
uint32_t |
instance, |
|
|
uint8_t |
channel |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
channel | The channel number. |
- Returns
- The current value of the TPM channel value.
void TPM_DRV_OutputCompareEnable |
( |
uint32_t |
instance, |
|
|
uint8_t |
channel, |
|
|
tpm_output_compare_mode_t |
mode, |
|
|
uint32_t |
countFinalVal, |
|
|
uint32_t |
matchVal, |
|
|
bool |
intEnable |
|
) |
| |
- Parameters
-
instance | The TPM peripheral instance number. |
channel | The channel number. |
mode | The TPM output mode defined by tpm_output_compare_mode_t. |
countFinalVal | The final value that is stored in the MOD register. |
matchVal | The channel compare value stored in the CnV register |
intEnable | true: enable channel interrupt; false: disable |
void TPM_DRV_Deinit |
( |
uint32_t |
instance | ) |
|
- Parameters
-
instance | The TPM peripheral instance number. |
void TPM_DRV_IRQHandler |
( |
uint32_t |
instance | ) |
|
The timer overflow flag is checked and cleared if set.
- Parameters
-
instance | Instance number of the TPM module. |
TPM_Type* const g_tpmBase[TPM_INSTANCE_COUNT] |
const IRQn_Type g_tpmIrqId[TPM_INSTANCE_COUNT] |