<?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>MQX Software Solutions中的主题 Re: Bug with _time_delay()?</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Bug-with-time-delay/m-p/428095#M14278</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Luke:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_time_delay function translated time into number of ticks. Basically it just counts the requested number of timer interrupts. If you want to delay one tick for example, you need to count 2 ticks. &lt;/P&gt;&lt;P&gt;Argument of _time_delay() function is minimum number of milliseconds to suspend the task because time between last tick and call of _time_delay could vary in range 0..1 tick. I think that is the reason to add the additional tick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_time_delay is useful when you wish to just release the CPU to other tasks for some time, it is not useful for precise delays,&amp;nbsp; for that case you need to consider different features, most likely driver by hardware timer modules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Nov 2015 08:30:28 GMT</pubDate>
    <dc:creator>danielchen</dc:creator>
    <dc:date>2015-11-25T08:30:28Z</dc:date>
    <item>
      <title>Bug with _time_delay()?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Bug-with-time-delay/m-p/428094#M14277</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I’ve recently started to move a project across from MQX 3.8 to MQX 4.2, and have discovered that there is a change in functionality on the &lt;SPAN style="font-family: courier new,courier;"&gt;_time_delay()&lt;/SPAN&gt; function. I believe in MQX 3.8, &lt;SPAN style="font-family: courier new,courier;"&gt;_time_delay()&lt;/SPAN&gt; would always round &lt;EM&gt;down&lt;/EM&gt; the given delay to the nearest tick, where as in MQX 4.2, it will round &lt;EM&gt;up&lt;/EM&gt; to the nearest tick, but &lt;EM&gt;also&lt;/EM&gt; add an additional tick. I performed some simple tests by toggling an output and observing this on an oscilloscope, and have found that MQX 4.2 increases the requested time by 1 tick. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I started to dig into the &lt;SPAN style="font-family: courier new,courier;"&gt;_time_delay()&lt;/SPAN&gt; function in MQX 4.2, there indeed has been some code changes since MQX 3.8; a comment found in &lt;SPAN style="font-family: courier new,courier;"&gt;_time_delay()&lt;/SPAN&gt;is as follows: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="pastedImage_7.png"&gt;&lt;img src="https://community.nxp.com/t5/image/serverpage/image-id/29751i4E9163D46D32DE05/image-size/large?v=v2&amp;amp;px=999" role="button" title="pastedImage_7.png" alt="pastedImage_7.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now it seems that by adding “time_per_tick[ms] - 1” to the “required_time[ms]” is an attempt to force the ticks to round up, which I think it will.&amp;nbsp; But I do not understand why there is the addition of the +1 tick - I believe this to be the problem. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I first noticed this when trying to get the ethernet PHY drivers going (phy_lan8720.c). Within &lt;SPAN style="font-size: 10pt; font-family: courier new,courier; color: black; background: white none repeat scroll 0% 0%;"&gt;phy_lan8720_init()&lt;/SPAN&gt; there is a loop that spins an appropriate amount of times to simulate a 3s timeout on detecting the completion of the auto negotiation. In MQX 3.8, this loop takes 3 seconds to timeout, but in MQX 4.2, this loop takes 6 seconds to timeout. It appears that with a system tick resolution of 5ms, and requesting a &lt;SPAN style="font-family: courier new,courier;"&gt;_time_delay(5)&lt;/SPAN&gt;, we actually get a 10ms delay (+100% error) - this explains why my loop delay of 3s is now 6s on MQX 4.2.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would suspect that for larger delays, this 1 tick is barely noticable, but when your delay is 1 tick, or thereabouts, this error is quite noticable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have I understood this correctly?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Nov 2015 02:44:49 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Bug-with-time-delay/m-p/428094#M14277</guid>
      <dc:creator>Treskewl</dc:creator>
      <dc:date>2015-11-20T02:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Bug with _time_delay()?</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Bug-with-time-delay/m-p/428095#M14278</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Hi Luke:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_time_delay function translated time into number of ticks. Basically it just counts the requested number of timer interrupts. If you want to delay one tick for example, you need to count 2 ticks. &lt;/P&gt;&lt;P&gt;Argument of _time_delay() function is minimum number of milliseconds to suspend the task because time between last tick and call of _time_delay could vary in range 0..1 tick. I think that is the reason to add the additional tick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;_time_delay is useful when you wish to just release the CPU to other tasks for some time, it is not useful for precise delays,&amp;nbsp; for that case you need to consider different features, most likely driver by hardware timer modules.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Nov 2015 08:30:28 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Bug-with-time-delay/m-p/428095#M14278</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2015-11-25T08:30:28Z</dc:date>
    </item>
  </channel>
</rss>

