Very long story made short, it appears that tick timing get bollixed after changing clock configurations.
Demo this by:
printf( "pre: %d\n", _time_get_hwticks_per_tick() );
_bsp_set_clock_configuration( <config other than startup> );
printf( "post: %d\n", _time_get_hwticks_per_tick() );
pre and post values the same... If core clock changes, _hwticks_per_tick should change.
Result of not changing is that time becomes non-monotonic.
If this a bug and not something messed up in my BSP, the bug is in _bsp_set_clock_configuration()
- It calls CPU_SetClockConfiguration()
- then calls hwtimer_set_freq() to update the timer modulo, but does not update kernel_data->HW_TICKS_PER_TICK
- exits.
- any following tick-related call uses the bogus kernel_data->HW_TICKS_PER_TICK
In my BSP, I fixed the problem by calling _time_set_hwticks_per_tick() after the call to hwtimer_set_freq()
NXP: Bug in MQX or something mucked up in my BSP as it was built?
Also, in the process of chasing this down I came across _time_set_resolution() which states:
kernel_data->HW_TICKS_PER_TICK = resolution * 1000;
... which is not correct.