This section describes the programming interface of the PDB Peripheral driver. The PDB peripheral driver configures the PDB (Programmable Delay Block). It handles the triggers for ADC and DAC and pulse out to the CMP and the PDB counter.
PDB Driver model building
There is one main PDB counter for all triggers. When the indicated external trigger input arrives, the PDB counter launches and is increased by setting clock. The counter trigger milestones for ADC and DAC pulse out to the CMP and the PDB counter and wait for the PDB counter. Once the PDB counter hits each milestone, also called the critical delay value, the corresponding event is triggered and the trigger signal is sent out to trigger other peripherals. Therefore, the PDB module is a collector and manager of triggers.
PDB Initialization
The core feature of the PDB module is a programmable timer/counter. Additional features enable and set the milestone for the corresponding trigger. Therefore, the PDB module is first initialized as a programmable timer. To initialize the PDB driver, a configuration structure of the of "pdb_user_config_t" type is required and should store an available configuration. The API of the PDB_DRV_StructInitUserConfigForSoftTrigger() function provides a configuration which the PDB can use. However, this configuration is not sufficient for user-specific use cases. The user should provide a configuration suitable for the application requirements. Call the API of PDB_DRV_Init() function to initialize the PDB timer/counter.
All triggers share the same counter. However, the DAC trigger does not share the same counting circle with other triggers. When the DAC's internal circle ends, the trigger is generated and the internal circle restarts.
The basic timing/counting step is set when initializing the main PDB counter:
The basic timing/counting step = F_BusClkHz / pdb_timer_config_t.clkPreDiv / pdb_timer_config_t.clkPreMultFactor
The F_BusClkHz is the frequency of bus clock in Hertz. The "clkPreDiv" and "clkPreMultFactor" are in the pdb_timer_config_t structure. All triggering milestones are based on this step.
PDB Call diagram
Four kinds of typical use cases are designed for the PDB module.
- Normal Timer/Counter. Normal Timer/Counter is the basic case. The Timer/Counter starts after the PDB is initialized and the milestone for the PDB Timer/Counter is set. After it is triggered and when the counter hits the milestone, the interrupt request occurs if enabled. In continuous mode, when the counter hits the upper limit, it returns zero and counts again.
- Trigger for ADC module. When the ADC trigger is enabled, a delay value for ADC trigger is set as the milestone. At least two ADC channel groups are provided. Likewise, there are more than two pre-triggers for ADC. Each pre-trigger is related to one channel group and can be enabled separately in the PDB module. When the PDB counter hits the milestone for the ADC pre-trigger, it triggers the ADC's conversion on the indicated channel group. To maximize the feature, the ADC should be configured to enable the hardware trigger mode.
- Trigger for the DAC module. A standalone DAC counter exists in the PDB module to trigger the DAC module. The user can set the upper limit for the DAC counter. Once the counter reaches the upper limit, it turns the DAC counter to zero and counts again. When the DAC counter hits the upper limit, a DAC trigger is generated to trigger the DAC. This trigger updates the pointer of the DAC buffer. Although the DAC counter has its own setting for the upper limit, it shares the same input trigger source, clock source, and reset control logic with the main PDB counter. When the PDB counter resets to zero, it forces the DAC counter to reset to zero. To maximize this feature, the DAC should be configured to enable the DAC buffer and hardware trigger mode.
- Trigger for pulse out to the CMP module. The pulse-out trigger is attached to the main PDB counter. There are two milestones for each pulse out channel, a milestone for level high and for level low, which makes a sample window for the CMP module.
These are the examples to initialize and configure the PDB driver for typical use cases.
Normal Timer/Counter:
#include "pdb_test.h"
static volatile uint32_t gPdbIntCounter = 0U;
static volatile uint32_t gPdbInstance = 0U;
static void PDB_ISR_Counter(void);
void PDB_TEST_NormalTimer(uint32_t instance)
{
gPdbIntCounter = 0U;
gPdbInstance = instance;
PDB_TEST_InstallCallback(instance, PDB_ISR_Counter);
while (gPdbIntCounter < 20U) {}
PRINTF("PDB Timer's delay interrupt generated.\r\n");
PRINTF("OK.\r\n");
}
static void PDB_ISR_Counter(void)
{
if (gPdbIntCounter >= 0xFFFFU)
{
gPdbIntCounter = 0U;
}
else
{
gPdbIntCounter++;
}
}
Trigger for ADC module:
#include "pdb_test.h"
void PDB_TEST_AdcPreTrigger(uint32_t instance)
{
PRINTF("PDB ADC PreTrigger generated.\r\n");
PRINTF("OK.\r\n");
}
|
pdb_status_t | PDB_DRV_Init (uint32_t instance, const pdb_timer_config_t *userConfigPtr) |
| Initializes the PDB counter and triggers input. More...
|
|
pdb_status_t | PDB_DRV_Deinit (uint32_t instance) |
| Deinitializes the PDB module. More...
|
|
void | PDB_DRV_SoftTriggerCmd (uint32_t instance) |
| Triggers the PDB with a software trigger. More...
|
|
uint32_t | PDB_DRV_GetTimerValue (uint32_t instance) |
| Gets the current counter value in the PDB module. More...
|
|
bool | PDB_DRV_GetTimerIntFlag (uint32_t instance) |
| Gets the PDB interrupt flag. More...
|
|
void | PDB_DRV_ClearTimerIntFlag (uint32_t instance) |
| Clears the interrupt flag. More...
|
|
void | PDB_DRV_LoadValuesCmd (uint32_t instance) |
| Executes the command of loading values. More...
|
|
void | PDB_DRV_SetTimerModulusValue (uint32_t instance, uint32_t value) |
| Sets the value of timer modulus. More...
|
|
void | PDB_DRV_SetValueForTimerInterrupt (uint32_t instance, uint32_t value) |
| Sets the value for the timer interrupt. More...
|
|
pdb_status_t | PDB_DRV_ConfigAdcPreTrigger (uint32_t instance, uint32_t chn, const pdb_adc_pretrigger_config_t *configPtr) |
| Configures the ADC pre_trigger in the PDB module. More...
|
|
uint32_t | PDB_DRV_GetAdcPreTriggerFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask) |
| Gets the ADC pre_trigger flag in the PDB module. More...
|
|
void | PDB_DRV_ClearAdcPreTriggerFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask) |
| Clears the ADC pre_trigger flag in the PDB module. More...
|
|
uint32_t | PDB_DRV_GetAdcPreTriggerSeqErrFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask) |
| Gets the ADC pre_trigger flag in the PDB module. More...
|
|
void | PDB_DRV_ClearAdcPreTriggerSeqErrFlags (uint32_t instance, uint32_t chn, uint32_t preChnMask) |
| Clears the ADC pre_trigger flag in the PDB module. More...
|
|
void | PDB_DRV_SetAdcPreTriggerDelayValue (uint32_t instance, uint32_t chn, uint32_t preChn, uint32_t value) |
| Sets the ADC pre_trigger delay value in the PDB module. More...
|
|
void | PDB_DRV_SetCmpPulseOutEnable (uint32_t instance, uint32_t pulseChnMask, bool enable) |
| Switches on/off the CMP pulse out in the PDB module. More...
|
|
void | PDB_DRV_SetCmpPulseOutDelayForHigh (uint32_t instance, uint32_t pulseChn, uint32_t value) |
| Sets the CMP pulse out delay value for high in the PDB module. More...
|
|
void | PDB_DRV_SetCmpPulseOutDelayForLow (uint32_t instance, uint32_t pulseChn, uint32_t value) |
| Sets the CMP pulse out delay value for low in the PDB module. More...
|
|
|
PDB_Type *const | g_pdbBase [] |
| Table of base addresses for PDB instances. More...
|
|
const IRQn_Type | g_pdbIrqId [PDB_INSTANCE_COUNT] |
| Table to save PDB IRQ enumeration numbers defined in the CMSIS header file. More...
|
|
struct pdb_adc_pretrigger_config_t |
This function initializes the PDB counter and triggers the input. It resets PDB registers and enables the PDB clock. Therefore, it should be called before any other operation. After it is initialized, the PDB can act as a triggered timer, which enables other features in PDB module.
- Parameters
-
instance | PDB instance ID. |
userConfigPtr | Pointer to the user configuration structure. See the "pdb_user_config_t". |
- Returns
- Execution status.
This function deinitializes the PDB module. Calling this function shuts down the PDB module and reduces the power consumption.
- Parameters
-
- Returns
- Execution status.
void PDB_DRV_SoftTriggerCmd |
( |
uint32_t |
instance | ) |
|
This function triggers the PDB with a software trigger. When the PDB is set to use the software trigger as input, calling this function triggers the PDB.
- Parameters
-
uint32_t PDB_DRV_GetTimerValue |
( |
uint32_t |
instance | ) |
|
This function gets the current counter value.
- Parameters
-
- Returns
- Current PDB counter value.
bool PDB_DRV_GetTimerIntFlag |
( |
uint32_t |
instance | ) |
|
This function gets the PDB interrupt flag. It is asserted if the PDB interrupt occurs.
- Parameters
-
- Returns
- Assertion of indicated event.
void PDB_DRV_ClearTimerIntFlag |
( |
uint32_t |
instance | ) |
|
This function clears the interrupt flag.
- Parameters
-
void PDB_DRV_LoadValuesCmd |
( |
uint32_t |
instance | ) |
|
This function executes the command of loading values.
- Parameters
-
instance | PDB instance ID. |
value | Setting value. |
void PDB_DRV_SetTimerModulusValue |
( |
uint32_t |
instance, |
|
|
uint32_t |
value |
|
) |
| |
This function sets the value of timer modulus.
- Parameters
-
instance | PDB instance ID. |
value | Setting value. |
void PDB_DRV_SetValueForTimerInterrupt |
( |
uint32_t |
instance, |
|
|
uint32_t |
value |
|
) |
| |
This function sets the value for the timer interrupt.
- Parameters
-
instance | PDB instance ID. |
value | Setting value. |
This function configures the ADC pre_trigger in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
configPtr | Pointer to the user configuration structure. See the "pdb_adc_pretrigger_config_t". |
- Returns
- Execution status.
uint32_t PDB_DRV_GetAdcPreTriggerFlags |
( |
uint32_t |
instance, |
|
|
uint32_t |
chn, |
|
|
uint32_t |
preChnMask |
|
) |
| |
This function gets the ADC pre_trigger flags in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
preChnMask | ADC pre_trigger channels mask. |
- Returns
- Assertion of indicated flag.
void PDB_DRV_ClearAdcPreTriggerFlags |
( |
uint32_t |
instance, |
|
|
uint32_t |
chn, |
|
|
uint32_t |
preChnMask |
|
) |
| |
This function clears the ADC pre_trigger flags in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
preChnMask | ADC pre_trigger channels mask. |
uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags |
( |
uint32_t |
instance, |
|
|
uint32_t |
chn, |
|
|
uint32_t |
preChnMask |
|
) |
| |
This function gets the ADC pre_trigger flags in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
preChnMask | ADC pre_trigger channels mask. |
- Returns
- Assertion of indicated flag.
void PDB_DRV_ClearAdcPreTriggerSeqErrFlags |
( |
uint32_t |
instance, |
|
|
uint32_t |
chn, |
|
|
uint32_t |
preChnMask |
|
) |
| |
This function clears the ADC pre_trigger sequence error flags in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
preChnMask | ADC pre_trigger channels mask. |
void PDB_DRV_SetAdcPreTriggerDelayValue |
( |
uint32_t |
instance, |
|
|
uint32_t |
chn, |
|
|
uint32_t |
preChn, |
|
|
uint32_t |
value |
|
) |
| |
This function sets Set the ADC pre_trigger delay value in the PDB module.
- Parameters
-
instance | PDB instance ID. |
chn | ADC channel. |
preChn | ADC pre_channel. |
value | Setting value. |
void PDB_DRV_SetCmpPulseOutEnable |
( |
uint32_t |
instance, |
|
|
uint32_t |
pulseChnMask, |
|
|
bool |
enable |
|
) |
| |
This function switches the CMP pulse on/off in the PDB module.
- Parameters
-
instance | PDB instance ID. |
pulseChnMask | Pulse channel mask. |
enable | Switcher to assert the feature. |
void PDB_DRV_SetCmpPulseOutDelayForHigh |
( |
uint32_t |
instance, |
|
|
uint32_t |
pulseChn, |
|
|
uint32_t |
value |
|
) |
| |
This function sets the CMP pulse out delay value for high in the PDB module.
- Parameters
-
instance | PDB instance ID. |
pulseChn | Pulse channel. |
value | Setting value. |
void PDB_DRV_SetCmpPulseOutDelayForLow |
( |
uint32_t |
instance, |
|
|
uint32_t |
pulseChn, |
|
|
uint32_t |
value |
|
) |
| |
This function sets the CMP pulse out delay value for low in the PDB module.
- Parameters
-
instance | PDB instance ID. |
pulseChn | Pulse channel. |
value | Setting value. |
PDB_Type* const g_pdbBase[] |
const IRQn_Type g_pdbIrqId[PDB_INSTANCE_COUNT] |