Hi everyone
I am trying to create a timer for 1000 milliseconds using TIMER0 in NXP PN7462 but it will generate a ~1050 milliseconds timer
and that will create an issue for me so help me to resolve this issue.
Here I share the code for that timer.
static void vAPP_TXTime_Off_Timer_Callback(void)
{
//GPIO LOW
}
void vAPP_Timer0_ConfigureTimer (phhalTimer_Timers_t * psTimer,uint32_t dwTimePeriod, pphhalTimer_CallbackFun_t pCallBackFunc)
{
phStatus_t Status = PH_ERR_INVALID_PARAMETER;
//set callback function and time period
psTimer->pCallBackFunc = pCallBackFunc;
psTimer->dwTimePeriod = dwTimePeriod;
//Set fix count for 1 sec
psTimer->dwTimeOutRegVal = 3412;//count for 1 sec
Status = PH_ERR_SUCCESS;
}
Timer_StartTimer (
phhalTimer_Timers_t * psTimer,
phhalTimer_Mode_t eRunMode)
{
phhalTimer_Regs_t *psTimerRegs;
phhalTimer_Id_t eTMode;
eTMode = psTimer->bTimerId;
psTimerRegs = (phhalTimer_Regs_t *)(TIMERS_TIMER0_CONTROL_REG + (uint32_t)(eTMode * PHHAL_HWTIMER_REGS_SIZE));
psTimerRegs->dwCtrlReg = (uint32_t)eRunMode;
/* set timeout wrt units. */
psTimerRegs->dwTimeoutReg = psTimer->dwTimeOutRegVal;
if (psTimer->dwTimeOutRegVal)
{
/* Enable interrupt. */
PH_REG_SET(TIMERS_INT_SET_ENABLE_REG, (1UL << eTMode) );
}
return PH_ERR_SUCCESS;
}
void vAPP_Timer0_Start ( uint32_t dwTimerInterval, void *pTimerCallback )
{
uint32_t dwTimerVal = 0;
phhalTimer_Units_t eTimerUnit = E_TUNIT_MILLI_SECS;
// Check if the Timer Period passed in greater than specified milliseconds
// and needs to be converted into seconds.
if(dwTimerInterval > 4096)
{
dwAPP_Tx_Off_TimerInterval_Remaining = dwTimerInterval - 4096;
dwTimerVal = 4096;
}
else
{
dwAPP_Tx_Off_TimerInterval_Remaining = 0;
dwTimerVal = dwTimerInterval;
}
// Request the Timer 0
if (phAPP_Timer_RequestTimer0(eTimerUnit, &pstHAL_HostTxOffTimer) != PH_ERR_SUCCESS)
return;
// Configure the Timer with the Time Period and Call back
vAPP_Timer0_ConfigureTimer(pstHAL_HostTxOffTimer, dwTimerVal , (pphhalTimer_CallbackFun_t)pTimerCallback);
// Start the timer in free running mode
Timer_StartTimer(pstHAL_HostTxOffTimer, E_TIMER_FREE_RUNNING);
// Set the Timer Status as Timer Started
bAPP_Tx_Off_Timer_Status = 1;
}
main()
{
//GPPIO HIGH
vAPP_Timer0_Start(3412,&vAPP_TXTime_Off_Timer_Callback)
}