Priorites of taks

I am trying to understand how do we decide a task priority in free rtos programming. I have been seen in free rtos documents but struggling

Atmel Studio 7

Device: ATmega32A
OS: Window 10

Free RTOS :10.3.0.

[code] #include <stdlib.h>

#include <string.h>

#ifdef GCC_MEGA_AVR
/* EEPROM routines used only with the WinAVR compiler. */
#include <avr/eeprom.h>
#endif

/* Scheduler include files. */
#include “FreeRTOS.h”
#include “task.h”
#include “croutine.h”

void vTask1( void *pvParameters )
{
const char pcTaskName = “Task 1 is running\r\n”;
volatile uint32_t ul; /
volatile to ensure ul is not optimized away. */

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

}

void vTask2( void *pvParameters )
{
const char pcTaskName = “Task 2 is running\r\n”;
volatile uint32_t ul; /
volatile to ensure ul is not optimized away. */

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

}

void vTask3( void *pvParameters )
{
const char pcTaskName = “Task 3 is running\r\n”;
volatile uint32_t ul; /
volatile to ensure ul is not optimized away. */

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

}

int main( void )
{
xTaskCreate( vTask1, “Task 1”, 1000, NULL, 2, NULL );
xTaskCreate( vTask2, “Task 2”, 1000, NULL, 1, NULL );
xTaskCreate( vTask2, “Task 2”, 1000, NULL, 3, NULL );

vTaskStartScheduler();

for( ;; );

}
[/code]

How to set task priorities in the code ?

You mean changing the initial prio specified by xTaskCreate ?
Use vTaskPrioritySet. It‘s all well documented e.g. here
BTW: In your example you‘re launching Task2 twice…

second task should be run first time
first task should be run second time
Third task should be run third time
int main( void )
{
xTaskCreate( vTask1, “Task 1”, 1000, NULL, 2, NULL );
xTaskCreate( vTask2, “Task 2”, 1000, NULL, 1, NULL );
xTaskCreate( vTask3, “Task 3”, 1000, NULL, 3, NULL );

vTaskStartScheduler();

for( ;; );

}

Now Am I selecting priority in the correct way

Recommend reading the book here: https://www.freertos.org/Documentation/RTOS_book.html

Setting the priority is fairly easy, you provide it in the call when you create the task (or call vTaskPrioritySet to change it latter).

Figuring out the right priorities can be harder, and is really based on meeting the system requirements.

On the other hand, since all of the tasks are primarily compute bound (except for the occasional call to vPrintString which might block), the natural priority for these tasks in my mind would be priority 0 (or the same as the Idle task). Placing these tasks at any higher priority will likely starve the idle task, and if some of these tasks are at a higher priority than others, they will likely starve the lower priority tasks.