void SetupGPTimer(unsigned int nTimerNum,void *const pMemory,ADI_CALLBACK pfCallback, ADI_TMR_HANDLE *const phTimer, uint32_t nPeriod,uint32_t nWidth) { ADI_TMR_RESULT eTmrResult; /* Open the timer */ if( (eTmrResult = adi_tmr_Open (nTimerNum, pMemory, ADI_TMR_MEMORY, pfCallback, NULL, phTimer)) != ADI_TMR_SUCCESS) { /* Failed to open the timer handle the error here */ } /* * Use the GP timer's API's to configure and enable the timer * */ eTmrResult = adi_tmr_EnableDataInt(*phTimer,false); eTmrResult = adi_tmr_EnableStatusInt(*phTimer,false); /* Set the mode to PWM OUT */ eTmrResult = adi_tmr_SetMode(*phTimer, ADI_TMR_MODE_CONTINUOUS_PWMOUT); /* Set the IRQ mode to get interrupt after counts till TMR_PERIOD register value */ eTmrResult = adi_tmr_SetIRQMode(*phTimer, ADI_TMR_IRQMODE_PERIOD); /* Set the Period */ eTmrResult = adi_tmr_SetPeriod(*phTimer,nPeriod); /* Set the timer width */ eTmrResult = adi_tmr_SetWidth(*phTimer, nWidth); /* Enable the timer */ eTmrResult = adi_tmr_Enable(*phTimer, true); }
void GP_Timer6_Init(void) { ADI_TMR_RESULT eTmrResult = ADI_TMR_SUCCESS; /* Open the timer */ if( (eTmrResult = adi_tmr_Open ( GP_TIMER6_NUM, TimerMemory6, ADI_TMR_MEMORY, Timer6_ISR, NULL, &ghTimer6)) != ADI_TMR_SUCCESS) { printf("Timer open failed 0x%08X \n", eTmrResult); } // Set the mode to PWM OUT if((eTmrResult = adi_tmr_SetMode( ghTimer6, ADI_TMR_MODE_CONTINUOUS_PWMOUT)) != ADI_TMR_SUCCESS) { printf("Failed to open timer in PWM out mode 0x%08X \n", eTmrResult); } //Set the IRQ mode to get interrupt after timer counts to Delay + Width if((eTmrResult = adi_tmr_SetIRQMode( ghTimer6, ADI_TMR_IRQMODE_PERIOD)) != ADI_TMR_SUCCESS) { printf("Failed to set the timer IRQ mode 0x%08X \n", eTmrResult); } //Set the Period if((eTmrResult = adi_tmr_SetPeriod( ghTimer6, TIMER6_PERIOD)) != ADI_TMR_SUCCESS) { printf("Failed to set the timer Period 0x%08X \n", eTmrResult); } //Set the timer width if((eTmrResult = adi_tmr_SetWidth( ghTimer6, TIMER6_WIDTH)) != ADI_TMR_SUCCESS) { printf("Failed to set the timer Width 0x%08X \n", eTmrResult); } // Set the timer Delay if((eTmrResult = adi_tmr_SetDelay( ghTimer6, TIMER6_DELAY)) != ADI_TMR_SUCCESS) { printf("Failed to set the timer Delay 0x%08X \n", eTmrResult); } //Enable the timer to stop gracefully,used in PWM mode,set the PWM wave more graceful. if((eTmrResult = adi_tmr_EnableGracefulStop( ghTimer6, true)) != ADI_TMR_SUCCESS) { printf("Failed to enable the timer to stop gracefully 0x%08X \n", eTmrResult); } adi_tmr_Enable(ghTimer6, true); }