#### rt694157

Joined Dec 15, 2019
68
I have been visited on the page 49-53 https://www.freertos.org/wp-content...eal_Time_Kernel-A_Hands-On_Tutorial_Guide.pdf I do not understand complete example code

C:
void vTask1( void *pvParameters )
{
volatile uint32_t ul; /* volatile to ensure ul is not optimized away. */

for( ;; )
{
/* Print out the name of this task. */
/* Delay for a period. */
for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ )
{

}
}
}

{
volatile uint32_t ul; /* volatile to ensure ul is not optimized away. */

for( ;; )
{
/* Print out the name of this task. */
/* Delay for a period. */
for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ )
{

}
}
}

int main( void )
{

"Task 1", /* Text name for the task. This is to facilitate debugging only. */
1000, /* Stack depth - small microcontrollers will use much
less stack than this. */
NULL, /* This example does not use the task parameter. */
1, /* This task will run at priority 1. */
NULL ); /* This example does not use the task handle. */
/* Create the other task in exactly the same way and at the same priority. */
/* Start the scheduler so the tasks start executing. */

/* If all is well then main() will never reach here as the scheduler will
now be running the tasks. If main() does reach here then it is likely that
there was insufficient heap memory available for the idle task to be created.
for( ;; );
}
What is main purpose of the code ?

#### Papabravo

Joined Feb 24, 2006
16,822
To demonstrate the creation of two tasks, which are each scheduled and run by the procedure vTaskScheduler() which never returns. You can see that a task is running because it prints a message to that effect and then enters a delay loop. Since both tasks have the same priority, they should alternate, and you should see about the same number of lines printed by each task. We can't see the rest of the code so I don't know what mechanism the scheduler will use to preempt the runnning task.

#### rt694157

Joined Dec 15, 2019
68
To demonstrate the creation of two tasks, which are each scheduled and run by the procedure vTaskScheduler() which never returns. You can see that a task is running because it prints a message to that effect and then enters a delay loop. Since both tasks have the same priority, they should alternate, and you should see about the same number of lines printed by each task. We can't see the rest of the code so I don't know what mechanism the scheduler will use to preempt the runnning task.

What's difference between task scheduling and task priority's, both are the same for me

#### Papabravo

Joined Feb 24, 2006
16,822
At any time there is one and only one task which is "Running".

The purpose of the function vTaskScheduler() is to allow the "Running" task to execute for some period of time, When the time expires, vTaskScheduler() will preempt the "Running" task and place it in a "Suspended" state. It will then pick the highest priority task from a "Ready To Run" list and make it the "Running" task. That is not all that happens in vTaskScheduler(), but that is the basic function.

#### rt694157

Joined Dec 15, 2019
68
At any time there is one and only one task which is "Running".

The purpose of the function vTaskScheduler() is to allow the "Running" task to execute for some period of time, When the time expires, vTaskScheduler() will preempt the "Running" task and place it in a "Suspended" state. It will then pick the highest priority task from a "Ready To Run" list and make it the "Running" task. That is not all that happens in vTaskScheduler(), but that is the basic function.
so priority decide which task will run and when it will run and Scheduler decode time for task for example run task A for 100ns , run Task B for 200ns and Run task C for 300ns

#### Papabravo

Joined Feb 24, 2006
16,822
so priority decide which task will run and when it will run and Scheduler decode time for task for example run task A for 100ns , run Task B for 200ns and Run task C for 300ns

There may be other factors involved in the decision, but that is the general idea. Besides priority, you might want to consider how long the task wants to run, and how long it has been since the last time it ran.

#### rt694157

Joined Dec 15, 2019
68
At any time there is one and only one task which is "Running".

The purpose of the function vTaskScheduler() is to allow the "Running" task to execute for some period of time, When the time expires, vTaskScheduler() will preempt the "Running" task and place it in a "Suspended" state. It will then pick the highest priority task from a "Ready To Run" list and make it the "Running" task. That is not all that happens in vTaskScheduler(), but that is the basic function.
If I want to prioritize the tasks, do I have to pass the priority number in function? as shown passing the priority number in function

Code:
int main( void )
{

}