<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 4.0.2 Tick timing incorrect after swapping clock configuration in MQX Software Solutions</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645882#M17123</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very long story made short, it appears that tick timing get bollixed after changing clock configurations.&lt;/P&gt;&lt;P&gt;Demo this by:&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf( "pre: %d\n", _time_get_hwticks_per_tick() );&lt;/P&gt;&lt;P&gt;_bsp_set_clock_configuration( &amp;lt;config other than startup&amp;gt; );&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf( "post: %d\n", _time_get_hwticks_per_tick() );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pre and post values the same... If core clock changes, _hwticks_per_tick should change.&lt;/P&gt;&lt;P&gt;Result of not changing is that time becomes non-monotonic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this a bug and not something messed up in my BSP, the bug is in _bsp_set_clock_configuration()&lt;/P&gt;&lt;P&gt;- It calls CPU_SetClockConfiguration()&lt;/P&gt;&lt;P&gt;- then calls hwtimer_set_freq() to update the timer modulo, but does not update kernel_data-&amp;gt;HW_TICKS_PER_TICK&lt;/P&gt;&lt;P&gt;- exits.&lt;/P&gt;&lt;P&gt;- any following tick-related call uses the bogus kernel_data-&amp;gt;HW_TICKS_PER_TICK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my BSP, I fixed the problem by calling _time_set_hwticks_per_tick() after the call to hwtimer_set_freq()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NXP: Bug in MQX or something mucked up in my BSP as it was built?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, in the process of chasing this down I came across _time_set_resolution() which states:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kernel_data-&amp;gt;HW_TICKS_PER_TICK = resolution * 1000;&lt;/P&gt;&lt;P&gt;... which is not correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 27 Jan 2017 00:32:38 GMT</pubDate>
    <dc:creator>fcw</dc:creator>
    <dc:date>2017-01-27T00:32:38Z</dc:date>
    <item>
      <title>4.0.2 Tick timing incorrect after swapping clock configuration</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645882#M17123</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very long story made short, it appears that tick timing get bollixed after changing clock configurations.&lt;/P&gt;&lt;P&gt;Demo this by:&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf( "pre: %d\n", _time_get_hwticks_per_tick() );&lt;/P&gt;&lt;P&gt;_bsp_set_clock_configuration( &amp;lt;config other than startup&amp;gt; );&lt;/P&gt;&lt;P&gt;&amp;nbsp; printf( "post: %d\n", _time_get_hwticks_per_tick() );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pre and post values the same... If core clock changes, _hwticks_per_tick should change.&lt;/P&gt;&lt;P&gt;Result of not changing is that time becomes non-monotonic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this a bug and not something messed up in my BSP, the bug is in _bsp_set_clock_configuration()&lt;/P&gt;&lt;P&gt;- It calls CPU_SetClockConfiguration()&lt;/P&gt;&lt;P&gt;- then calls hwtimer_set_freq() to update the timer modulo, but does not update kernel_data-&amp;gt;HW_TICKS_PER_TICK&lt;/P&gt;&lt;P&gt;- exits.&lt;/P&gt;&lt;P&gt;- any following tick-related call uses the bogus kernel_data-&amp;gt;HW_TICKS_PER_TICK&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my BSP, I fixed the problem by calling _time_set_hwticks_per_tick() after the call to hwtimer_set_freq()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NXP: Bug in MQX or something mucked up in my BSP as it was built?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, in the process of chasing this down I came across _time_set_resolution() which states:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; kernel_data-&amp;gt;HW_TICKS_PER_TICK = resolution * 1000;&lt;/P&gt;&lt;P&gt;... which is not correct.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 27 Jan 2017 00:32:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645882#M17123</guid>
      <dc:creator>fcw</dc:creator>
      <dc:date>2017-01-27T00:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: 4.0.2 Tick timing incorrect after swapping clock configuration</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645883#M17124</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Fred,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please check the below thread and let me know if this helps.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/thread/300484"&gt;MQX 3.8 _time_get() -&amp;amp;gt;_time_to_date defect&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Have a great day,&lt;BR /&gt;Sol &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-----------------------------------------------------------------------------------------------------------------------&lt;BR /&gt;Note: If this post answers your question, please click the Correct Answer button. Thank you!&lt;BR /&gt;-----------------------------------------------------------------------------------------------------------------------&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2017 22:38:47 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645883#M17124</guid>
      <dc:creator>soledad</dc:creator>
      <dc:date>2017-01-30T22:38:47Z</dc:date>
    </item>
    <item>
      <title>Re: 4.0.2 Tick timing incorrect after swapping clock configuration</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645884#M17125</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sol,&amp;nbsp; Thank you&amp;nbsp; for the reply, but that 3.8 thread isn't addressing the same problem. Many of the tick-related functions call the macro PSP_NORMALIZE_TICKS(tick_ptr) which for Kinetis, at least, resolves to _psp_normalize_ticks((PSP_TICK_STRUCT_PTR)(tick_ptr)).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at _psp_normalize_ticks() in mqx\mqx\source\psp\cortex_m\psp_tinm.c:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Line 45 assigns:&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; ticks_per_tick = kernel_data-&amp;gt;HW_TICKS_PER_TICK;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then in line 48:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; register uint32_t t = tick_ptr-&amp;gt;HW_TICKS[0] / ticks_per_tick;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I pointed out in my question is that when changing the clock configuration:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- hwtimer_set_freq() is called to update the&amp;nbsp;Systick timer modulo such that it continues to reset itself and generate an interrupt at a 200 Hz rate. For example, if MQX is configured for a 200 Hz RTOS tick with a 24 MHz core clock, hwtimer_set_freq() sets the modulo to 24000000/200 = 120000. If the core clock is changed to 96 MHz, the modulo becomes 96000000/200 = 480000.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Since kernel_data-&amp;gt;HW_TICKS_PER_TICK does not get updated when the core clock changes, the statement at line 48 in _psp_normalize_ticks() gets the wrong answer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-- Calling _time_set_hwticks_per_tick() as mentioned in the post updates kernel_data-&amp;gt;HW_TICKS_PER_TICK so _psp_normalize_ticks() gets the right answer.&amp;nbsp; The point is that it seems this should be done somewhere in _bsp_set_clock_configuration().&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fcw&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 04 Feb 2017 17:15:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/4-0-2-Tick-timing-incorrect-after-swapping-clock-configuration/m-p/645884#M17125</guid>
      <dc:creator>fcw</dc:creator>
      <dc:date>2017-02-04T17:15:46Z</dc:date>
    </item>
  </channel>
</rss>

