ticks_diff_get () is not correctly working

Hi,

Please check below for the ticks_diff_get () function.

static __INLINE uint32_t ticks_diff_get(uint32_t ticks_now, uint32_t ticks_old)
{
return ((ticks_now - ticks_old) & MAX_RTC_COUNTER_VAL);
}

I think this is wrong because it will give a wrong value when ticks_now is smaller than ticks_old.

Therefore, does it need to cast to a signed value like below?

static __INLINE uint32_t ticks_diff_get(uint32_t ticks_now, uint32_t ticks_old)
{
return ( (int32_t) (ticks_now - ticks_old) & MAX_RTC_COUNTER_VAL);
}

If you don't agree, can you explain why?

Appreciate your help.

Thanks.

Related