Hi,
I am using lpcopen_3_02_lpcxpresso_xpresso4337.
When I call Chip_TIMER_Reset(LPC_TIMER2); with no optimisation it takes 480nS but when I call it with -01 optimisation it takes 1.76uS.
This isobviously unexpected. The optimised assembler looks good.
What it interesting is that most of the time is the while loop in Chip_TIMER_Reset();
I cannot see how this is possible.
I suspect the implementation of Chip_TIMER_Reset() is incorrect. It seems overly complicated compared to the CMSIS libraries. Why is TC set to a non zero value in the code below? When it is set to zero the function is much faster.
/* Resets the timer terminal and prescale counts to 0 */
void Chip_TIMER_Reset(LPC_TIMER_T *pTMR)
{
uint32_t reg;
/* Disable timer, set terminal count to non-0 */
reg = pTMR->TCR;
pTMR->TCR = 0;
pTMR->TC = 1;
/* Reset timer counter */
pTMR->TCR = TIMER_RESET;
/* Wait for terminal count to clear */
while (pTMR->TC != 0) {}
/* Restore timer state */
pTMR->TCR = reg;
}
But the CMSIS library code is as follows and seems to do the same thing:
void TIM_ResetCounter(LPC_TIMERn_Type *TIMx)
{
CHECK_PARAM(PARAM_TIMx(TIMx));
TIMx->TCR |= TIM_RESET;
TIMx->TCR &= ~TIM_RESET;
}
Can someone explain>