<?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 tickless freertos LPTM in S32K</title>
    <link>https://community.nxp.com/t5/S32K/tickless-freertos-LPTM/m-p/808868#M2914</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I try to use FreeRTOS on S32K144, but I am blocked on a timing problem.&lt;/P&gt;&lt;P&gt;I use the tickless feature with LPTM.&lt;/P&gt;&lt;P&gt;For periodic task without any external interrupt I have no problems.&lt;/P&gt;&lt;P&gt;But, when I&amp;nbsp;have external interrupt&amp;nbsp;I have a problem. The calculation&amp;nbsp; when something other than the tick interrupt ended the sleep seems to be ok for me. But I have sometimes extra time, so my periodic task drift ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any ideas for my problem ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the source code used :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Determine if LPTM interrupt occured */&lt;BR /&gt; if(isTimerInterruptFire == TRUE )&lt;BR /&gt; {&lt;BR /&gt; isTimerInterruptFire = FALSE;&lt;BR /&gt; uint32_t ulCalculatedLoadValue;&lt;/P&gt;&lt;P&gt;/* The tick interrupt is already pending, and the LPTM count&lt;BR /&gt; reloaded with ulReloadValue. Reset the&lt;BR /&gt; CMR register with whatever remains of this tick&lt;BR /&gt; period. */&lt;BR /&gt; ulCalculatedLoadValue = ulTimerCountsForOneTick - luw_time_ref;&lt;/P&gt;&lt;P&gt;/* Don't allow a tiny value, or values that have somehow&lt;BR /&gt; underflowed because the post sleep hook did something&lt;BR /&gt; that took too long. */&lt;BR /&gt; if( ( ulCalculatedLoadValue &amp;lt; ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue &amp;gt; ulTimerCountsForOneTick ) )&lt;BR /&gt; {&lt;BR /&gt; ulCalculatedLoadValue = ( ulTimerCountsForOneTick );&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CMR = ulCalculatedLoadValue;&lt;/P&gt;&lt;P&gt;/* As the pending tick will be processed as soon as this&lt;BR /&gt; function exits, the tick value maintained by the tick is stepped&lt;BR /&gt; forward by one less than the time spent waiting. */&lt;BR /&gt; ulCompleteTickPeriods = xExpectedIdleTime - 1UL;&lt;BR /&gt; }&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; /* Something other than the tick interrupt ended the sleep.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; How many complete tick periods passed while the processor&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; was waiting? */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; ulCompleteTickPeriods = luw_time_ref / ulTimerCountsForOneTick;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt; /* The reload value is set to whatever fraction of a single tick&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; period remains. */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ulCompletedSysTickDecrements = ulTimerCountsForOneTick - (luw_time_ref - ulCompleteTickPeriods*ulTimerCountsForOneTick);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; /* The reload value is set to whatever fraction of a single tick&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; period remains. */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; LPTMR0-&amp;gt;CMR = ulCompletedSysTickDecrements;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;/* Restart LPTM so it runs from CMR register&lt;BR /&gt; again, then set CMR register back to its standard&lt;BR /&gt; value. */&lt;BR /&gt; LPTMR0-&amp;gt;CSR |= LPTMR_CSR_TEN(1); // timer enable&lt;BR /&gt; vTaskStepTick( ulCompleteTickPeriods );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot !&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Jul 2018 13:56:34 GMT</pubDate>
    <dc:creator>david_lion1</dc:creator>
    <dc:date>2018-07-12T13:56:34Z</dc:date>
    <item>
      <title>tickless freertos LPTM</title>
      <link>https://community.nxp.com/t5/S32K/tickless-freertos-LPTM/m-p/808868#M2914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I try to use FreeRTOS on S32K144, but I am blocked on a timing problem.&lt;/P&gt;&lt;P&gt;I use the tickless feature with LPTM.&lt;/P&gt;&lt;P&gt;For periodic task without any external interrupt I have no problems.&lt;/P&gt;&lt;P&gt;But, when I&amp;nbsp;have external interrupt&amp;nbsp;I have a problem. The calculation&amp;nbsp; when something other than the tick interrupt ended the sleep seems to be ok for me. But I have sometimes extra time, so my periodic task drift ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Do you have any ideas for my problem ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here the source code used :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* Determine if LPTM interrupt occured */&lt;BR /&gt; if(isTimerInterruptFire == TRUE )&lt;BR /&gt; {&lt;BR /&gt; isTimerInterruptFire = FALSE;&lt;BR /&gt; uint32_t ulCalculatedLoadValue;&lt;/P&gt;&lt;P&gt;/* The tick interrupt is already pending, and the LPTM count&lt;BR /&gt; reloaded with ulReloadValue. Reset the&lt;BR /&gt; CMR register with whatever remains of this tick&lt;BR /&gt; period. */&lt;BR /&gt; ulCalculatedLoadValue = ulTimerCountsForOneTick - luw_time_ref;&lt;/P&gt;&lt;P&gt;/* Don't allow a tiny value, or values that have somehow&lt;BR /&gt; underflowed because the post sleep hook did something&lt;BR /&gt; that took too long. */&lt;BR /&gt; if( ( ulCalculatedLoadValue &amp;lt; ulStoppedTimerCompensation ) || ( ulCalculatedLoadValue &amp;gt; ulTimerCountsForOneTick ) )&lt;BR /&gt; {&lt;BR /&gt; ulCalculatedLoadValue = ( ulTimerCountsForOneTick );&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;LPTMR0-&amp;gt;CMR = ulCalculatedLoadValue;&lt;/P&gt;&lt;P&gt;/* As the pending tick will be processed as soon as this&lt;BR /&gt; function exits, the tick value maintained by the tick is stepped&lt;BR /&gt; forward by one less than the time spent waiting. */&lt;BR /&gt; ulCompleteTickPeriods = xExpectedIdleTime - 1UL;&lt;BR /&gt; }&lt;BR /&gt;&lt;STRONG&gt;else&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; {&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; /* Something other than the tick interrupt ended the sleep.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; How many complete tick periods passed while the processor&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; was waiting? */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; ulCompleteTickPeriods = luw_time_ref / ulTimerCountsForOneTick;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt; /* The reload value is set to whatever fraction of a single tick&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; period remains. */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ulCompletedSysTickDecrements = ulTimerCountsForOneTick - (luw_time_ref - ulCompleteTickPeriods*ulTimerCountsForOneTick);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; /* The reload value is set to whatever fraction of a single tick&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; period remains. */&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt; LPTMR0-&amp;gt;CMR = ulCompletedSysTickDecrements;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;/* Restart LPTM so it runs from CMR register&lt;BR /&gt; again, then set CMR register back to its standard&lt;BR /&gt; value. */&lt;BR /&gt; LPTMR0-&amp;gt;CSR |= LPTMR_CSR_TEN(1); // timer enable&lt;BR /&gt; vTaskStepTick( ulCompleteTickPeriods );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot !&amp;nbsp;&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Jul 2018 13:56:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/S32K/tickless-freertos-LPTM/m-p/808868#M2914</guid>
      <dc:creator>david_lion1</dc:creator>
      <dc:date>2018-07-12T13:56:34Z</dc:date>
    </item>
  </channel>
</rss>

