FreeRTOS component quiries and information

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeRTOS component quiries and information

755 Views
arunkumar1989
Contributor I

Hello all,

I have until now done all my projects without using any RTOS.As of now i am taking some baby steps into the world of RTOS.

I have chosen the FreeRTOS components in code-warrior to get started.

After some reading and a little tinkering i got a sample program working and running.

I have a few questions regarding the way the RTOS works....

 

I am currently using the MK60FN1MOVLQF15 micro controller.

I have setup two tasks which blinks 2 separate LEDs.

Here's the task creation code

 

[code]

void CreateTasks(void) {

    if (FRTOS1_xTaskCreate(

            led_blink1Task,  /* pointer to the task */

            "led_blink1", /* task name for kernel awareness debugging */

            configMINIMAL_STACK_SIZE + 0, /* task stack size */

            (void*)NULL, /* optional task startup argument */

            tskIDLE_PRIORITY + 0,  /* initial priority */

            (xTaskHandle*)NULL /* optional task handle to create */

    ) != pdPASS) {

        /*lint -e527 */

        for(;;){}; /* error! probably out of memory */

        /*lint +e527 */

    }

    if (FRTOS1_xTaskCreate(

            led_blink2Task,  /* pointer to the task */

            "led_blink2", /* task name for kernel awareness debugging */

            configMINIMAL_STACK_SIZE + 0, /* task stack size */

            (void*)NULL, /* optional task startup argument */

            tskIDLE_PRIORITY + 0,  /* initial priority */

            (xTaskHandle*)NULL /* optional task handle to create */

    ) != pdPASS) {

        /*lint -e527 */

        for(;;){}; /* error! probably out of memory */

        /*lint +e527 */

    }

}

[/code]

 

Both leds are blinking as per the task.

Now if i change the task priority (tskIDLE_PRIORITY + 0,  /* initial priority */) from 0 to 1,of the second task,then only this task is being executed.

Why is this happening,will there ever be a case when the task with priority 0 will be executed?

 

Also each task uses a lot of HEAP size(2048 bytes),is this normal?

If i want to add more tasks i need to add 2048 bytes for every additional task or else i get stuck inside the FRTOS1_vApplicationMallocFailedHook() event.

So for two tasks i had to assign 4048 bytes into the HEAP stack.Is this normal?

 

Thanks for all you help

Arun

Labels (1)
Tags (2)
0 Kudos
Reply
1 Reply

531 Views
FreeRTOS_org
Contributor IV

[ All attempts to format the code in this post failed!]

FreeRTOS (and in fact, all RTOS of this class) will always execute the highest priority task that is able to run.  A task is not able to run if it is in the Blocked state.  You don't show the code for the task that blinks the LED, but I suspect it is not entering the Blocked state, and therefore whichever is the highest priority will always run.  For example.  If you code is like this:

void vTask1( void *pvParameters ) { volatile uint32_t x;      for( ;; )     {         ToggleLED();                  /* Busy wait until it is time to toggle again. */         for( i = 0; i < 0xfffff; i++ )         {             __asm volatile ( "NOP" );         }     } }

Then the code will always be running - either toggling the LED or sitting in the for( i = ... ) loop.  That will starve the lower priority task of all processing time.  It is also loosing some of the major benefits of using an RTOS, and that is to separate timing from functionality (for maintainability, simplicity, code size, etc. reasons) and to make your system completely event driven (to ensure CPU cycles are only used when there is actually processing to perform, no CPU cycles are wasted polling anything, and so you can fit a lot more functionality into your application).

On the other hand, if you were to implement the same functionality like this:

void vTask1( void *pvParameters ) { const TickType_T xBlockTime = pdMS_TO_TICKS( 500 );      for( ;; )     {         ToggleLED();         vTaskDelay( xBlockTime );     } }

Then the task would enter the blocked state for 500ms in between each LED toggle.  While it was in the blocked state the lower priority task would run.  When the lower priority task was in the blocked state the idle task would run and you could put the processor into a low power mode - or run other functionality, or whatever.

With regards to the amount of heap used - that will depend on your configMINIMAL_STACK_SIZE setting.  There is an FAQ on how big to make the stack.  The FAQ also provides links to functionality in FreeRTOS that allows you to monitor the stack usage.

0 Kudos
Reply