<?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>Kinetis MicrocontrollersのトピックRe: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
    <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091040#M57697</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Myke,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this different behavior is because the wireless examples don't provide flexibility adding queues&amp;nbsp;or tasks, we want to avoid any code that could delay the connectivity process in the BLE stack.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, our example could implement Tickless following the next guide&amp;nbsp;&lt;A href="https://community.nxp.com/docs/DOC-341045"&gt;Connectivity Software: Implement tickless mode in FreeRTOS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please do not hesitate to contact us for any further questions that you have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mario&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 18 Jun 2020 01:49:44 GMT</pubDate>
    <dc:creator>mario_castaneda</dc:creator>
    <dc:date>2020-06-18T01:49:44Z</dc:date>
    <item>
      <title>FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091031#M57688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm starting new project with FreeRTOS running at Kinetis MKW36 MCU with Bluetooth. I'm going to reuse NXP Bluetooth stack and example &lt;SPAN&gt;C&amp;nbsp;&lt;/SPAN&gt;code for Bluetooth. In all NXP examples I've seen the Time Slice scheduler for RTOS is&amp;nbsp;disabled (#define configUSE_TIME_SLICING 0). So RTOS task switching has to be done explicitly. Is there any reason why the&amp;nbsp;&lt;SPAN&gt;Time Slice scheduler is disables? For example&amp;nbsp;that the&amp;nbsp;Bluetooth stack or C code examples are not "compatible" with&amp;nbsp;Time Slice&amp;nbsp;scheduler?&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV style="position: absolute; left: 244px; top: 102px;"&gt;&lt;DIV class="gtx-trans-icon"&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2020 11:20:11 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091031#M57688</guid>
      <dc:creator>kohoutm2</dc:creator>
      <dc:date>2020-06-12T11:20:11Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091032#M57689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree: having &lt;SPAN style="font-size: 10.5pt; color: #666666;"&gt;configUSE_TIME_SLICING &lt;/SPAN&gt;set to zero is very unusual, and I don't know what the reasons in the stack examples would be. And you don't have to do task switching explicitly (the scheduler is still preemptive and not cooperative), but the scheduler will *not* balance time between tasks of equal priority. Means if your highest priority task does not block and if there are other task with the same priority, the scheduler will not switch to another task of equal priority at tick time.&lt;/P&gt;&lt;P&gt;It only means that context switches will happen less, and that a task having the CPU will keep it having. If (what I don't hope) the stack would rely on someting (e.g. to create a kind of critical section?), I would challenge the architcture and doing something as this won't be very reliable anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this helps,&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Jun 2020 15:33:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091032#M57689</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2020-06-12T15:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091033#M57690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;Thanks for the answer. The questions still persist. Is it safe to use &lt;SPAN&gt;Time Slice scheduler together with&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;Bluetooth stack and example&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff; border: 0px;"&gt;C&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff;"&gt;code?&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="color: #51626f; background-color: #ffffff; border: 0px;"&gt;&lt;SPAN style="color: #51626f;"&gt;As I look at other NXP&amp;nbsp;FreeRTOS&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff;"&gt;Kinetis MKW36&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="color: #51626f;"&gt;examples (without Bluetooth) the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="background-color: #ffffff; color: #51626f; "&gt;Time Slice scheduler is always disabled. And some FreeRTOS examples relay on Time Slice scheduler&amp;nbsp;to be disabled because there is missing correct task synchronization. It makes me nervous because I have selected NXP for new project and I do not want to be in troubles in later project phase.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Jun 2020 09:22:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091033#M57690</guid>
      <dc:creator>kohoutm2</dc:creator>
      <dc:date>2020-06-13T09:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091034#M57691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Martin and Erich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I wanted to enter this conversation on a few points and ask a few questions about how your are doing things.&amp;nbsp; I'm running several FreeRTOS applications with "&lt;SPAN style="color: #51626f; background-color: #ffffff;"&gt;#define configUSE_TIME_SLICING 0&lt;/SPAN&gt;" and letting my application select the appropriate executing task without any issues.&amp;nbsp; I believe that I've archtected&amp;nbsp;my applications in such a way that I won't experience the issues that you do.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First off,&amp;nbsp;let me say that I think the FreeRTOS examples are terrible; they do not provide anything close to a good example of how the&amp;nbsp;demo interface should be used in a FreeRTOS application.&amp;nbsp; Most often, they seem to be the bare metal code with just "xTaskCreate" for the functions and a "vTaskStartScheduler" with&amp;nbsp;minimal thought to things like task priorities, stack sizes or how a user would use their code in their applications.&amp;nbsp; I&amp;nbsp;seriously recommend not trying to use the FreeRTOS demo code in applications - start with the bare metal examples and port them into FreeRTOS tasks that perform the work that you require.&amp;nbsp;&amp;nbsp;If an author of these examples is out there and offended; please contact me for my opinion on how they should be written to provide meaningful examples to users.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While I'm dissing NXP FreeRTOS code, I'm also going to say that one of the things I've learned is to &lt;STRONG&gt;NOT&lt;/STRONG&gt; use the FreeRTOS drivers in the SDKs.&amp;nbsp; The reason is somewhat subtle and philosophical - the drivers, from what I can see are well written but they're written for the general case; the code is architected in a way that it would work well in a multi-user system in which multiple tasks are going to access the resource but when we're talking about single purpose MCU, they're overly complex and not optimized for&amp;nbsp;virtually all applications that users are going to be developing for.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We're blessed with inexpensive chips with a plethora of IO options - that means that the goal of an application should be that each device provides a single function and each peripheral on the device has it's own specific IO.&amp;nbsp; This probably seems wasteful and inefficient, but I would argue that it greatly simplifies hardware system design as well as application software development and debugging and will result in a cheaper overall product.&amp;nbsp;&amp;nbsp;The only interfaces that I would consider sharing are I2C and CAN (as "intraSystem" tasks below) as communication data packets&amp;nbsp;include the destination address and there's no need to complicate things with semaphores and mutexes.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My first questions to you are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Why do you have any data processing tasks that are of the same priority?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;Why do you have multiple data processing tasks?&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;How are you breaking up your task functions and how do you expect them to operate?&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In my (Free)RTOS applications, I have four types of tasks:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Execution initiated by a hardware interrupt (Typically Intersystem Communications and User Inputs)&lt;/LI&gt;&lt;LI&gt;Execution initiated by a timer delay (Typically&amp;nbsp;repeating Sensor functions)&lt;/LI&gt;&lt;LI&gt;Execution initiated by another task (User Interface Processing)&lt;/LI&gt;&lt;LI&gt;Always executing (What I call a "Data Processing" Task/The Basic Application)&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These tasks are prioritized using the include file:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;/*&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; * Task_priorities.h&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; *&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; * Created on: Apr. 29, 2020&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; * Author: myke&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt; */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#ifndef TASK_PRIORITIES_H_&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#define TASK_PRIORITIES_H_&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#if ((defined configMAX_PRIORITIES) &amp;amp;&amp;amp; (10 &amp;gt; configMAX_PRIORITIES))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#error TOO FEW configMAX_PRIORITIES&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#elif (!(defined&amp;nbsp;&lt;SPAN style="background-color: #f6f6f6;"&gt;configMAX_PRIORITIES))&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#error configMAX_PRIORITIES NOT Defined&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;#endif&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;enum { interS&lt;/SPAN&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;ystemTask_Priority&amp;nbsp; &amp;nbsp;= (configMAX_PRIORITIES - 2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, intraSystemTask_Priority&amp;nbsp; &amp;nbsp;= (configMAX_PRIORITIES - 3)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, sensorTask_Priority&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; = (configMAX_PRIORITIES - 4)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, actuatorTask_Priority&amp;nbsp; &amp;nbsp; &amp;nbsp; = (configMAX_PRIORITIES - 5)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, fileSystemTask_Priority&amp;nbsp; &amp;nbsp; = (configMAX_PRIORITIES - 6)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, userInterfaceTask_Priority = (configMAX_PRIORITIES - 7)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, consoleTask_Priority&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;= (configMAX_PRIORITIES - 8)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;, dataProcessing_Priority&amp;nbsp; &amp;nbsp; = (configMAX_PRIORITIES - 9)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;};&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;#endif /* TASK_PRIORITIES_H_ */&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I prioritize tasks&amp;nbsp;using the philosophy that for a&amp;nbsp;task to execute as fast as possible, all the called tasks are a higher priority.&amp;nbsp;&amp;nbsp;By doing this, I don't have any task starvation issues.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just to explain the task functions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;interSystem - Communications with other (typically host) systems.&amp;nbsp; Examples are&amp;nbsp;USB, Ethernet, BT &amp;amp; UART.&amp;nbsp; If the application is an I2C&amp;nbsp;or CAN multi-master or slave then these interfaces could be considered at this level&lt;/LI&gt;&lt;LI&gt;intraSystem - Communications with devices within the application.&amp;nbsp; This typcally is I2C, CAN, SPI, UART&lt;/LI&gt;&lt;LI&gt;sensor - ADC, Digital Inputs, Temperature sensors, etc.&amp;nbsp; If they are not on the chip, then the task communicates with the interface task at the "intraSystem" level (higher priority).&amp;nbsp; I should point out that the run time task for run time stats (&lt;A href="https://mcuoneclipse.com/2018/08/02/tutorial-using-runtime-statistics-with-amazon-freertos-v10/"&gt;Erich's Code&lt;/A&gt;) is run at this priority level and I use it for&amp;nbsp;measuring dataProcessing delays.&amp;nbsp;&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;actuator - Digital Outputs, PWM, etc.&amp;nbsp; The assumption here is that some actuators may require sensor data for correct operation&lt;/LI&gt;&lt;LI&gt;fileSystem - At the lowest level simple non-volatile storage of data.&amp;nbsp; At&amp;nbsp;a higher level, a FAT file system&lt;/LI&gt;&lt;LI&gt;userInterface - LEDs, LCDs, etc.&amp;nbsp; Buttons, knobs are all "sensors" and their values are requested from the userInteface&lt;/LI&gt;&lt;LI&gt;consoleTask - USB device/UART/Telnet to access system and provide monitoring/debug interface&lt;/LI&gt;&lt;LI&gt;dataProcessing - Doing the work using data from higher priority tasks and sending commands to&amp;nbsp;other tasks&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How are you architecting your applications?&amp;nbsp; I should point out that in the structure above, I only&amp;nbsp;expect that the userInterface and dataProcessing tasks operate autonomously.&amp;nbsp; Side tasks that operate autonomously very quickly complicate things and makes debugging/validating the application much more difficult.&amp;nbsp; The userInterface provides information to the user and may save user inputs until required by the dataProcessing task or send them directly to the dataProcessing task - in rereading what I've written, I'm giving the impression that userInterface operates continuously and that's not the case; userInterface waits on a timer or message from another task to execute.&amp;nbsp;&amp;nbsp;For all intents and purposes dataProcessing replaces the FreeRTOS IDLE task and is continuously operating (although the console task may halt&amp;nbsp;dataProcessing if a user is connected and needs to directly access different system function tasks).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I feel like I'm missing something the way that you are&amp;nbsp;architecting and specifying your&amp;nbsp;data processing tasks - could you please describe them?&amp;nbsp; I'm curious to know if my model would work with them.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now, FreeRTOS is a bit different from other RTOS's I've worked with as sending a message doesn't automatically call the scheduler - after putting the message on the receiving task's queue, execution returns to the caller which I think is part of your issues.&amp;nbsp; To work with this, I use a "send/receive" process in which the sender is blocked (which initiates the scheduler) until it receives a reply from the receiver (after which the receiver waits for another message, becoming blocked and causing the scheduler to resume caller execution).&amp;nbsp; For example to send a request message and wait for&amp;nbsp;its completion I use the method:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;void static inline flashMsgTXRX(struct flashQueueMsg* txMsg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&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; , struct flashQueueMsg* rxMsg) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; xQueueSend(flashQUEUE_Handle&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;, (void*)txMsg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;, portMAX_DELAY);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; xQueueReceive(flashRXQUEUE_Handle&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , (void*)rxMsg&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; , portMAX_DELAY);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This actually works really well with the priority scheme as the higher priority tasks are blocked waiting for a message to come in, at which point they service the request and then reply that it is complete.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I must confess there is one case that I do cheat on getting data from tasks (that my old university RTOS professor would probably roast me for) and that is getting simple data that a task is storing - rather than sending a message requesting the data and then waiting to receive it I access the variable in the task using the inline method:&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;uint32_t static inline rtpSensorValueRead(uint32_t dimension) {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;extern volatile uint32_t rtpSensorValue[2];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;&amp;nbsp; return rtpSensorValue[dimension];&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'andale mono', monospace;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In deference to my professor; he was adament that a task could not directly access any data in another task - this code prevents a task from modifying the other task's variable, which is in the spirit of the professor's dictum.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It should be noted that FreeRTOS&amp;nbsp;provides a copy of the message to the receiver, not the actual data or a pointer to the data so the rule of not accessing another task's data is followed and by always waiting for a response, I don't get into a situation where the sender continues updating its data which may result in a race condition.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I *think* I have shown how I have architeched my FreeRTOS applications in such a way that&amp;nbsp;I am not going to experience the issues that you are having, but I'd be interested in your comments back.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Jun 2020 03:02:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091034#M57691</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-14T03:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091035#M57692</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi myke,&lt;/P&gt;&lt;P&gt;Lots of points raised by you. I feel this would deserve its own thread instead of diverting this one.&lt;/P&gt;&lt;P&gt;It reminds me about one (or more?) articles I have drafted up but never released on that subject.&lt;/P&gt;&lt;P&gt;There is nothing 'wrong' with your approach, but there are certainly alternatives.&lt;/P&gt;&lt;P&gt;As for FreeRTOS and task priorities, I try to keep the number of priorities small (say 4 to 5), with having the 'urgent and short running' ones in the top priority range and the 'less urgent and longer running' in the lower priority band.&lt;/P&gt;&lt;P&gt;As for IPC (interprocess communication) I'm using mixed methods: from direct task notification to semaphore up to message queues with pointers to the data. I architect things in a way so I can be agnostic of the scheduler details except that 'it is running in preemptive mode': with this I don't have issues running tasks at the same priority, but usually I avoid to run any task at IDLE priority except the IDLE task.&lt;/P&gt;&lt;P&gt;As for the NXP examples: to me they are what they are: simple examples. Nothing really suited (or even intended) to end up in 'production' code. I use them simply as an inspiration and as starting point for my own implementation. And I think this is the main purpose of example code anyway.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Erich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2020 08:35:17 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091035#M57692</guid>
      <dc:creator>ErichStyger</dc:creator>
      <dc:date>2020-06-15T08:35:17Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091036#M57693</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;An alternative to FreeROTS is&amp;nbsp;uCOS-II and uCOS-III where they and&amp;nbsp; most of their stacks are now Open Source&amp;nbsp;&lt;/P&gt;&lt;P&gt;With Apache License.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/SiliconLabs?q=uC-&amp;amp;type=&amp;amp;language="&gt;https://github.com/SiliconLabs?q=uC-&amp;amp;type=&amp;amp;language=&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="https://doc.micrium.com/display/ucos/" title="https://doc.micrium.com/display/ucos/"&gt;https://doc.micrium.com/display/ucos/&lt;/A&gt;&amp;nbsp;&lt;A href="https://github.com/SiliconLabs?q=uC-&amp;amp;type=&amp;amp;language="&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/A&gt;&lt;A class="link-titled" href="https://www.micrium.com/rtos/licensing/" title="https://www.micrium.com/rtos/licensing/"&gt;Licensing | Micrium&lt;/A&gt;&amp;nbsp;&lt;A href="https://github.com/SiliconLabs?q=uC-&amp;amp;type=&amp;amp;language="&gt;https://github.com/SiliconLabs?q=uC-&amp;amp;type=&amp;amp;language=&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;While I'm biased, you find my name in the first edition of the uCOS-II book, I've always thought they were better written than FreeRTOS.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2020 12:41:06 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091036#M57693</guid>
      <dc:creator>bobpaddock</dc:creator>
      <dc:date>2020-06-15T12:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091037#M57694</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Erich,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanx for the reply.&amp;nbsp; I would welcome this being its own thread as I think discussions about task organization and prioritization would be useful to everyone here.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm hard on the FreeRTOS demos and think they are unacceptable because they are a resource for new FreeRTOS developers.&amp;nbsp; I have been writing RTOS code for literally 35 years and when I moved over to FreeRTOS from MQX and looked at the NXP demo code I was really given a very poor impression of FreeRTOS and it wasn't until I went to&amp;nbsp;&lt;A href="https://freertos.org/"&gt;freertos.org&lt;/A&gt;&amp;nbsp;that I could see that FreeRTOS was a serious tool.&amp;nbsp; If your first experience with FreeRTOS (and RTOS's in general) comes primarily from the NXP demos, you're going to have a lot of problems going forwards when you are creating more complex applications.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would love to have a discussion regarding your approach to prioritizing tasks - I'm curious as to how you (and other people) plan out your applications.&amp;nbsp; I came up with the categorization of the tasks over many years (including several RTOS's including uCONS-III; sorry &lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/bobpaddock"&gt;bobpaddock&lt;/A&gt;) because I found that when mapping out custom priorities for an application to be wasteful in terms of time, invited discussion between team members, and with the tasks categorized with set priorities that are predefined.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm curious about people's vision of the application this is exemplified by your comment about prioritizing tasks that are "urgent and short running" - I've found that over the years the two rarely coexist.&amp;nbsp; This is why I place my communciations/sensor tasks as the highest priority and keep their operation as short as possible but processing the incoming data is done at a much lower priority and can be done calmly without worrying about starving other tasks.&amp;nbsp; As I alluded to in my long email I tend to model my task code as providing a single primary application in the device and minimize peripheral sharing.&amp;nbsp; Most of the examples that I see are much more general, designed for multiple tasks sharing the resource (hence my comment about the FreeRTOS drivers), and I question this approach for Kinets/LPC and other SoC applications because it's more complex, requires more resources/code with the associated execution overhead and is generally not required when you look at the application from a high level.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe I'm completely off base with this view and I'd be interested in understanding what kind of applications people are doing with FreeRTOS - I'm doing robotics primarily but with fairly complex UIs (the next one will have a touch screen OLED UI and I'm planning on adding streaming video from an onboard camera) and intersystem communications (USB HID and CDC, BT and TCP/IP) and I can usually define the application to be one primary data processing task with the console task providing the user with direct control over the hardware if required.&amp;nbsp; I have one (QNX) application where I have multiple data processing tasks and rather than relying on the RTOS to provide time slicing, I scheduled their execution using a round robin - the primary requirement was for deterministic execution of the data processing tasks.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Going back to the original point, I would like to see FreeRTOS examples where there&amp;nbsp;tasks at the same priority level where one is being starved - you and &lt;SPAN style="color: #646464; background-color: #ffffff;"&gt;&lt;SPAN&gt;&lt;A class="jx-jive-macro-user" href="https://community.nxp.com/people/kohoutm2@o2active.cz"&gt;kohoutm2@o2active.cz&lt;/A&gt;‌ seem to have this issue with #define&amp;nbsp;&lt;SPAN style="color: #666666; background-color: #ffffff;"&gt;configUSE_TIME_SLICING 0.&amp;nbsp;&amp;nbsp;I'm curious to see what's happening here and what are the application requirements that resulted in this situation.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #646464; background-color: #ffffff;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #646464; background-color: #ffffff;"&gt;&lt;SPAN style="background-color: #ffffff; color: #666666; "&gt;myke&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Jun 2020 17:54:30 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091037#M57694</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-15T17:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091038#M57695</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Myke,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope you are doing great.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The BLE example codes are not defined with&amp;nbsp;configUSE_TIME_SLICING, this is because the BLE Stack, it requires specific time defined as the specification. For example, the BLE defines a connection interval is defined at the beginning of the connection, so every wake up the device must receive or transmit some data for not lose the connection.&amp;nbsp;The BLE stack has the highest priority.&amp;nbsp;For FreeRTOS OS only, mutexes are implemented with the priority inheritance mechanism.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For better information please look at the&amp;nbsp;Connectivity Framework Reference Manual documentation included in the SDK.&lt;/P&gt;&lt;P&gt;Also, you could look at the next community post, how to create tasks and queues.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.nxp.com/docs/DOC-345523"&gt;Using the QN908x FreeRTOS BLE Abstraction Layer Stack to create Tasks and Queues.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mario&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2020 01:19:31 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091038#M57695</guid>
      <dc:creator>mario_castaneda</dc:creator>
      <dc:date>2020-06-16T01:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091039#M57696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey Mario,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm doing excellent, I hope you are doing at least as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for&amp;nbsp;replying - I didn't realize that FreeRTOS tickless operation was not possible in BT enabled chips.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I look at the link (&lt;A _jive_internal="true" href="https://community.nxp.com/docs/DOC-345523"&gt;Using the QN908x FreeRTOS BLE Abstraction Layer Stack to create Tasks and Queues.&lt;/A&gt;) I can follow it but I would comment that it is *very* device specific&amp;nbsp;and somewhat indicative of the experience the writer has with the systems although the use of the "OSA_MsgQCreate" API doesn't match what I have in the SDK RM.&amp;nbsp; Not having the code indented in the link makes it a lot harder to follow - I know that's a problem when you're cut and pasting code into the quote box.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The overall&amp;nbsp;approach to&amp;nbsp;how the task and message queue are specified in the link is good but it is not followed in the various FreeRTOS demos that are importable in MCUXpresso (which is exactly what I'm complaining about) -&amp;nbsp;in the examples I've downloaded&amp;nbsp;there is&amp;nbsp;code (I can't find it right now) where task and other RTOS resources are allocated within other running tasks at arbitrary times which makes reading through the application and understanding the execution flow very difficult.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, I'm not looking for code that can be imported directly into an application, but code that can be followed and easily understood and not leaving&amp;nbsp;the new user asking why something like an "xTaskCreate" appears in an unexpected place in a task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyway, in my non-BT chip enabled applications, I am able to run tickless without any task starvation issues which is what I was curious about in the first place.&amp;nbsp; I'm still (and always) curious about how people architect their code so I can learn from their approach to doing things.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Again, thank you for the example and keep well,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;myke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Jun 2020 03:08:01 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091039#M57696</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-16T03:08:01Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091040#M57697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Myke,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is great.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason for this different behavior is because the wireless examples don't provide flexibility adding queues&amp;nbsp;or tasks, we want to avoid any code that could delay the connectivity process in the BLE stack.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, our example could implement Tickless following the next guide&amp;nbsp;&lt;A href="https://community.nxp.com/docs/DOC-341045"&gt;Connectivity Software: Implement tickless mode in FreeRTOS&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please do not hesitate to contact us for any further questions that you have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Mario&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2020 01:49:44 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091040#M57697</guid>
      <dc:creator>mario_castaneda</dc:creator>
      <dc:date>2020-06-18T01:49:44Z</dc:date>
    </item>
    <item>
      <title>Re: FreeRTOS Time Slice scheduler and Bluetooth C code</title>
      <link>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091041#M57698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanx Mario.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 18 Jun 2020 13:16:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/Kinetis-Microcontrollers/FreeRTOS-Time-Slice-scheduler-and-Bluetooth-C-code/m-p/1091041#M57698</guid>
      <dc:creator>myke_predko</dc:creator>
      <dc:date>2020-06-18T13:16:23Z</dc:date>
    </item>
  </channel>
</rss>

