/*FUNCTION********************************************************************* * * Function Name : PDB_DRV_Init * Description : Initialize the PDB counter and trigger input for PDB module. * It resets PDB registers and enables the clock for PDB. So it should be * called before any operation to PDB module. After initialized, the PDB can * ack as a triggered timer, which lays the foundation for other features in * PDB module. * *END*************************************************************************/ pdb_status_t PDB_DRV_Init(uint32_t instance, const pdb_timer_config_t *userConfigPtr) { assert(instance < PDB_INSTANCE_COUNT); PDB_Type * base = g_pdbBase[instance]; if (!userConfigPtr) { return kStatus_PDB_InvalidArgument; } /* Enable the clock gate from clock manager. */ CLOCK_SYS_EnablePdbClock(instance); /* Reset the registers for PDB module to reset state. */ PDB_HAL_Init(base); PDB_HAL_Enable(base); PDB_HAL_ConfigTimer(base, userConfigPtr); /* Configure NVIC. */ if (userConfigPtr->intEnable) { INT_SYS_EnableIRQ(g_pdbIrqId[instance] );/* Enable PDB interrupt in NVIC level.*/ } else { INT_SYS_DisableIRQ(g_pdbIrqId[instance] );/* Disable PDB interrupt in NVIC level.*/ } return kStatus_PDB_Success; }
/************************************************************************* * Function Name: PDB_init * Parameters: none * Return: none * Description: PDB module initialization *************************************************************************/ void PDB_init(void) { pdb_timer_config_t pdbUserConfig; PDB_HAL_Init(PDB0_BASE_PTR); PDB_HAL_SetAdcPreTriggerOutputEnable(PDB0_BASE_PTR, 0, (1U<<0)|(1U<<1), true); PDB_HAL_SetAdcPreTriggerEnable(PDB0_BASE_PTR, 0, (1U<<0)|(1U<<1), true); PDB_HAL_SetAdcPreTriggerBackToBackEnable(PDB0_BASE_PTR, 0, (1U<<1), true); PDB_HAL_SetAdcPreTriggerDelayValue(PDB0_BASE_PTR, 0, 0, (PWM_MODULO / 6)); // Set load register mode pdbUserConfig.loadValueMode = kPdbLoadValueImmediately; // Select PDB external trigger source, it is from FTM0 pdbUserConfig.triggerInput = kPdbTrigger8; PDB_HAL_ConfigTimer(PDB0_BASE_PTR,&pdbUserConfig); PDB_HAL_Enable(PDB0_BASE_PTR); PDB_HAL_SetTimerModulusValue(PDB0_BASE_PTR, 0x7fff); PDB_HAL_SetLoadValuesCmd(PDB0_BASE_PTR); // Set load register mode pdbUserConfig.clkPreDiv = kPdbClkPreDivBy1; pdbUserConfig.loadValueMode = kPdbLoadValueAtNextTrigger; // Select PDB external trigger source, it is from FTM0 pdbUserConfig.triggerInput = kPdbTrigger8; pdbUserConfig.seqErrIntEnable = true; pdbUserConfig.clkPreMultFactor = kPdbClkPreMultFactorAs1; PDB_HAL_ConfigTimer(PDB0_BASE_PTR,&pdbUserConfig); PDB_HAL_SetLoadValuesCmd(PDB0_BASE_PTR); enable_irq(g_pdbIrqId[0]); set_irq_priority(g_pdbIrqId[0], ISR_PRIORITY_PDB0); }