S32 SDK

Detailed Description

Programmable Delay Block Peripheral Driver.

Overview

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 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 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. 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.

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

Three kinds of typical use cases are designed for the PDB module.

These are the examples to initialize and configure the PDB driver for typical use cases.

Normal Timer/Counter:

#define PDB_INSTANCE 0UL
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)
{
pdb_timer_config_t PdbTimerConfig;
PdbTimerConfig.seqErrIntEnable = false;
PdbTimerConfig.clkPreDiv = PDB_CLK_PREDIV_BY_8;
PdbTimerConfig.continuousModeEnable = true;
PdbTimerConfig.dmaEnable = false;
PdbTimerConfig.intEnable = true;
PDB_DRV_Init(instance, &PdbTimerConfig);
PDB_DRV_SetTimerModulusValue(instance, 0xFFFU);
gPdbIntCounter = 0U;
gPdbInstance = instance;
while (gPdbIntCounter < 20U) {}
PRINTF("PDB Timer's delay interrupt generated.\r\n");
PDB_DRV_Deinit(instance);
PRINTF("OK.\r\n");
}
void PDB_IRQHandler()
{
if (gPdbIntCounter >= 0xFFFFU)
{
gPdbIntCounter = 0U;
}
else
{
gPdbIntCounter++;
}
}
#if PDB_INSTANCE < 1
void PDB0_IRQHandler(void)
{
PDB_IRQHandler();
}
#elif PDB_INSTANCE < 2
void PDB1_IRQHandler(void)
{
PDB_IRQHandler();
}
#endif

Trigger for ADC module:

void PDB_TEST_AdcPreTrigger(uint32_t instance)
{
pdb_timer_config_t PdbTimerConfig;
pdb_adc_pretrigger_config_t PdbAdcPreTriggerConfig;
PdbTimerConfig.seqErrIntEnable = false;
PdbTimerConfig.clkPreDiv = PDB_CLK_PREDIV_BY_8;
PdbTimerConfig.continuousModeEnable = false;
PdbTimerConfig.dmaEnable = false;
PdbTimerConfig.intEnable = false;
PDB_DRV_Init(instance, &PdbTimerConfig);
PdbAdcPreTriggerConfig.adcPreTriggerIdx = 0U;
PdbAdcPreTriggerConfig.preTriggerEnable = true;
PdbAdcPreTriggerConfig.preTriggerOutputEnable = true;
PdbAdcPreTriggerConfig.preTriggerBackToBackEnable = false;
PDB_DRV_ConfigAdcPreTrigger(instance, 0U, &PdbAdcPreTriggerConfig);
PDB_DRV_SetTimerModulusValue(instance, 0xFFFU);
PDB_DRV_SetAdcPreTriggerDelayValue(instance, 0U, 0U, 0xFFU);
while (1U != PDB_DRV_GetAdcPreTriggerFlags(instance, 0U, 1U)) {}
PRINTF("PDB ADC PreTrigger generated.\r\n");
PDB_DRV_Deinit(instance);
PRINTF("OK.\r\n");
}

Data Structures

struct  pdb_adc_pretrigger_config_t
 Defines the type of structure for configuring ADC's pre_trigger. More...
 

Functions

void PDB_DRV_Init (const uint32_t instance, const pdb_timer_config_t *userConfigPtr)
 Initializes the PDB counter and triggers input. More...
 
void PDB_DRV_Deinit (const uint32_t instance)
 De-initializes the PDB module. More...
 
void PDB_DRV_SoftTriggerCmd (const uint32_t instance)
 Triggers the PDB with a software trigger. More...
 
uint32_t PDB_DRV_GetTimerValue (const uint32_t instance)
 Gets the current counter value in the PDB module. More...
 
bool PDB_DRV_GetTimerIntFlag (const uint32_t instance)
 Gets the PDB interrupt flag. More...
 
void PDB_DRV_ClearTimerIntFlag (const uint32_t instance)
 Clears the interrupt flag. More...
 
void PDB_DRV_LoadValuesCmd (const uint32_t instance)
 Executes the command of loading values. More...
 
void PDB_DRV_SetTimerModulusValue (const uint32_t instance, const uint32_t value)
 Sets the value of timer modulus. More...
 
void PDB_DRV_SetValueForTimerInterrupt (const uint32_t instance, const uint32_t value)
 Sets the value for the timer interrupt. More...
 
void PDB_DRV_ConfigAdcPreTrigger (const uint32_t instance, const 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 (const uint32_t instance, const uint32_t chn, const uint32_t preChnMask)
 Gets the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_ClearAdcPreTriggerFlags (const uint32_t instance, const uint32_t chn, const uint32_t preChnMask)
 Clears the ADC pre_trigger flag in the PDB module. More...
 
uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags (const uint32_t instance, const uint32_t chn, const uint32_t preChnMask)
 Gets the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_ClearAdcPreTriggerSeqErrFlags (const uint32_t instance, const uint32_t chn, const uint32_t preChnMask)
 Clears the ADC pre_trigger flag in the PDB module. More...
 
void PDB_DRV_SetAdcPreTriggerDelayValue (const uint32_t instance, const uint32_t chn, const uint32_t preChn, const uint32_t value)
 Sets the ADC pre_trigger delay value in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutEnable (const uint32_t instance, const uint32_t pulseChnMask, bool enable)
 Switches on/off the CMP pulse out in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutDelayForHigh (const uint32_t instance, const uint32_t pulseChn, const uint32_t value)
 Sets the CMP pulse out delay value for high in the PDB module. More...
 
void PDB_DRV_SetCmpPulseOutDelayForLow (const uint32_t instance, const uint32_t pulseChn, const uint32_t value)
 Sets the CMP pulse out delay value for low in the PDB module. More...
 

Function Documentation

void PDB_DRV_ClearAdcPreTriggerFlags ( const uint32_t  instance,
const uint32_t  chn,
const uint32_t  preChnMask 
)

Clears the ADC pre_trigger flag in the PDB module.

This function clears the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.

Definition at line 267 of file pdb_driver.c.

void PDB_DRV_ClearAdcPreTriggerSeqErrFlags ( const uint32_t  instance,
const uint32_t  chn,
const uint32_t  preChnMask 
)

Clears the ADC pre_trigger flag in the PDB module.

This function clears the ADC pre_trigger sequence error flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.

Definition at line 299 of file pdb_driver.c.

void PDB_DRV_ClearTimerIntFlag ( const uint32_t  instance)

Clears the interrupt flag.

This function clears the interrupt flag.

Parameters
instancePDB instance ID.

Definition at line 172 of file pdb_driver.c.

void PDB_DRV_ConfigAdcPreTrigger ( const uint32_t  instance,
const uint32_t  chn,
const pdb_adc_pretrigger_config_t configPtr 
)

Configures the ADC pre_trigger in the PDB module.

This function configures the ADC pre_trigger in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
configPtrPointer to the user configuration structure. See the "pdb_adc_pretrigger_config_t".

Definition at line 232 of file pdb_driver.c.

void PDB_DRV_Deinit ( const uint32_t  instance)

De-initializes the PDB module.

This function de-initializes the PDB module. Calling this function shuts down the PDB module and reduces the power consumption.

Parameters
instancePDB instance ID.

Definition at line 108 of file pdb_driver.c.

uint32_t PDB_DRV_GetAdcPreTriggerFlags ( const uint32_t  instance,
const uint32_t  chn,
const uint32_t  preChnMask 
)

Gets the ADC pre_trigger flag in the PDB module.

This function gets the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
Returns
Assertion of indicated flag.

Definition at line 251 of file pdb_driver.c.

uint32_t PDB_DRV_GetAdcPreTriggerSeqErrFlags ( const uint32_t  instance,
const uint32_t  chn,
const uint32_t  preChnMask 
)

Gets the ADC pre_trigger flag in the PDB module.

This function gets the ADC pre_trigger flags in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnMaskADC pre_trigger channels mask.
Returns
Assertion of indicated flag.

Definition at line 283 of file pdb_driver.c.

bool PDB_DRV_GetTimerIntFlag ( const uint32_t  instance)

Gets the PDB interrupt flag.

This function gets the PDB interrupt flag. It is asserted if the PDB interrupt occurs.

Parameters
instancePDB instance ID.
Returns
Assertion of indicated event.

Definition at line 157 of file pdb_driver.c.

uint32_t PDB_DRV_GetTimerValue ( const uint32_t  instance)

Gets the current counter value in the PDB module.

This function gets the current counter value.

Parameters
instancePDB instance ID.
Returns
Current PDB counter value.

Definition at line 141 of file pdb_driver.c.

void PDB_DRV_Init ( const uint32_t  instance,
const pdb_timer_config_t userConfigPtr 
)

Initializes the PDB counter and triggers input.

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
instancePDB instance ID.
userConfigPtrPointer to the user configuration structure. See the "pdb_user_config_t".

Definition at line 63 of file pdb_driver.c.

void PDB_DRV_LoadValuesCmd ( const uint32_t  instance)

Executes the command of loading values.

This function executes the command of loading values.

Parameters
instancePDB instance ID.

Definition at line 187 of file pdb_driver.c.

void PDB_DRV_SetAdcPreTriggerDelayValue ( const uint32_t  instance,
const uint32_t  chn,
const uint32_t  preChn,
const uint32_t  value 
)

Sets the ADC pre_trigger delay value in the PDB module.

This function sets Set the ADC pre_trigger delay value in the PDB module.

Parameters
instancePDB instance ID.
chnADC channel.
preChnADC pre_channel.
valueSetting value.

Definition at line 315 of file pdb_driver.c.

void PDB_DRV_SetCmpPulseOutDelayForHigh ( const uint32_t  instance,
const uint32_t  pulseChn,
const uint32_t  value 
)

Sets the CMP pulse out delay value for high in the PDB module.

This function sets the CMP pulse out delay value for high in the PDB module.

Parameters
instancePDB instance ID.
pulseChnPulse channel.
valueSetting value.

Definition at line 346 of file pdb_driver.c.

void PDB_DRV_SetCmpPulseOutDelayForLow ( const uint32_t  instance,
const uint32_t  pulseChn,
const uint32_t  value 
)

Sets the CMP pulse out delay value for low in the PDB module.

This function sets the CMP pulse out delay value for low in the PDB module.

Parameters
instancePDB instance ID.
pulseChnPulse channel.
valueSetting value.

Definition at line 362 of file pdb_driver.c.

void PDB_DRV_SetCmpPulseOutEnable ( const uint32_t  instance,
const uint32_t  pulseChnMask,
bool  enable 
)

Switches on/off the CMP pulse out in the PDB module.

This function switches the CMP pulse on/off in the PDB module.

Parameters
instancePDB instance ID.
pulseChnMaskPulse channel mask.
enableSwitcher to assert the feature.

Definition at line 331 of file pdb_driver.c.

void PDB_DRV_SetTimerModulusValue ( const uint32_t  instance,
const uint32_t  value 
)

Sets the value of timer modulus.

This function sets the value of timer modulus.

Parameters
instancePDB instance ID.
valueSetting value.

Definition at line 202 of file pdb_driver.c.

void PDB_DRV_SetValueForTimerInterrupt ( const uint32_t  instance,
const uint32_t  value 
)

Sets the value for the timer interrupt.

This function sets the value for the timer interrupt.

Parameters
instancePDB instance ID.
valueSetting value.

Definition at line 217 of file pdb_driver.c.

void PDB_DRV_SoftTriggerCmd ( const uint32_t  instance)

Triggers the PDB with a software trigger.

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
instancePDB instance ID.

Definition at line 126 of file pdb_driver.c.