<?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中的主题 Using rand() with MQX lite</title>
    <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489361#M15943</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am using a Kinetis K70, KDS 3.0.0, and MQX Lite.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to use srand() and rand()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have noticed that if I call srand or rand within a MQX lite task, I get a hard fault.&lt;/P&gt;&lt;P&gt;However, if I call srand in the main.c, prior to PEX_RTOS_START, rand will work fine in MQX tasks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there a MQX setting or something I need to do. I would rather not modify main.c since it was generated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to reproduce the problem with a fresh project with MQX lite added.&lt;/P&gt;&lt;P&gt;This code produces a hard fault at the call of srand&lt;/P&gt;&lt;P&gt;void Task1_task(uint32_t task_init_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; int counter = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; srand(50);&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(1)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; counter = rand();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But adding srand here, makes it start working..&lt;/P&gt;&lt;P&gt;int main(void)&lt;/P&gt;&lt;P&gt;/*lint -restore Enable MISRA rule (6.3) checking. */&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Write your local variable definition here */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; PE_low_level_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** End of Processor Expert internal initialization.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Write your code here */&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* For example: for(;;) { } */&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;srand(10);&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Don't write any code pass this line, or it will be deleted during code generation. ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; #ifdef PEX_RTOS_START&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PEX_RTOS_START();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Startup of the selected RTOS. Macro is defined by the RTOS component. */&lt;/P&gt;&lt;P&gt;&amp;nbsp; #endif&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** End of RTOS startup code.&amp;nbsp; ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; for(;;){}&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/&lt;/P&gt;&lt;P&gt;} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 18 Mar 2016 12:59:07 GMT</pubDate>
    <dc:creator>ETCTim</dc:creator>
    <dc:date>2016-03-18T12:59:07Z</dc:date>
    <item>
      <title>Using rand() with MQX lite</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489361#M15943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;I am using a Kinetis K70, KDS 3.0.0, and MQX Lite.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to use srand() and rand()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have noticed that if I call srand or rand within a MQX lite task, I get a hard fault.&lt;/P&gt;&lt;P&gt;However, if I call srand in the main.c, prior to PEX_RTOS_START, rand will work fine in MQX tasks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If there a MQX setting or something I need to do. I would rather not modify main.c since it was generated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was able to reproduce the problem with a fresh project with MQX lite added.&lt;/P&gt;&lt;P&gt;This code produces a hard fault at the call of srand&lt;/P&gt;&lt;P&gt;void Task1_task(uint32_t task_init_data)&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; int counter = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; srand(50);&lt;/P&gt;&lt;P&gt;&amp;nbsp; while(1)&lt;/P&gt;&lt;P&gt;&amp;nbsp; {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; counter = rand();&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But adding srand here, makes it start working..&lt;/P&gt;&lt;P&gt;int main(void)&lt;/P&gt;&lt;P&gt;/*lint -restore Enable MISRA rule (6.3) checking. */&lt;/P&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Write your local variable definition here */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; PE_low_level_init();&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** End of Processor Expert internal initialization.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ***/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* Write your code here */&lt;/P&gt;&lt;P&gt;&amp;nbsp; /* For example: for(;;) { } */&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; &lt;SPAN style="color: #e23d39;"&gt;srand(10);&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Don't write any code pass this line, or it will be deleted during code generation. ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; #ifdef PEX_RTOS_START&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PEX_RTOS_START();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Startup of the selected RTOS. Macro is defined by the RTOS component. */&lt;/P&gt;&lt;P&gt;&amp;nbsp; #endif&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** End of RTOS startup code.&amp;nbsp; ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/&lt;/P&gt;&lt;P&gt;&amp;nbsp; for(;;){}&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/&lt;/P&gt;&lt;P&gt;} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Mar 2016 12:59:07 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489361#M15943</guid>
      <dc:creator>ETCTim</dc:creator>
      <dc:date>2016-03-18T12:59:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using rand() with MQX lite</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489362#M15944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Robbins:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;KDS is using GNU library for srand() and rand(). Have you tried to increase the task stack to see if it works?&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, 06 Apr 2016 03:25:29 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489362#M15944</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2016-04-06T03:25:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using rand() with MQX lite</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489363#M15945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Daniel,&lt;/P&gt;&lt;P&gt;Thanks for the help, but that didn't seem to work.&lt;/P&gt;&lt;P&gt;I ave a PE/MQX lite project with nothing but 1 task calling srand and rand.&lt;/P&gt;&lt;P&gt;If I don't call Srand in main.c, it will crash the first time it is called in the task in mqx_tasks.c&lt;/P&gt;&lt;P&gt;I upped the stack to 4000 (for a task that does nothing, and it still crashes).&lt;/P&gt;&lt;P&gt;I also tried making it a floating point task, and turned on the FP context switch, but that didn't help either.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any other ideas?&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Apr 2016 14:35:09 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489363#M15945</guid>
      <dc:creator>ETCTim</dc:creator>
      <dc:date>2016-04-20T14:35:09Z</dc:date>
    </item>
    <item>
      <title>Re: Using rand() with MQX lite</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489364#M15946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tim:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There seems have an issue in the srand function in KDS library, what causes the hard fault. It happens only with MQX Lite.&lt;/P&gt;&lt;P&gt;The workaround is just like you mentioned, calling srand in main function instead of MQX-Lite task.&lt;/P&gt;&lt;P&gt;Thank you very much for your feedback.&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, 14 Dec 2016 07:36:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489364#M15946</guid>
      <dc:creator>danielchen</dc:creator>
      <dc:date>2016-12-14T07:36:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using rand() with MQX lite</title>
      <link>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489365#M15947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I also have exactly same issue. But in my side , i am using FREERTOS. Any solution found ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 Feb 2017 07:41:55 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MQX-Software-Solutions/Using-rand-with-MQX-lite/m-p/489365#M15947</guid>
      <dc:creator>maheswarangurus</dc:creator>
      <dc:date>2017-02-28T07:41:55Z</dc:date>
    </item>
  </channel>
</rss>

