Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT




Loading

Need more detail of the uxPriority parameter in xCreateTask function

Posted by suxilong1 on October 28, 2015

Hi All ** i am new in learning FreeRTOS。 my project is running FreeRTOS in ESP8266(wifi SOC ) environment:VS2013+VisualGDB 5.0 at first i creat a new project。add two task in the main() ,and be aware of their different uxPriority **

~~~~ static const char *pcTextForTask1 = "Task 1 is runningrn"; static const char *pcTextForTask2 = "Task 2 is runningrn"; xTaskCreate(LEDBlinkTask, (signed char *)"Blink1", 256, (void *)pcTextForTask1, 1, NULL); xTaskCreate(LEDBlinkTask, (signed char *)"Blink2", 256, (void *)pcTextForTask2, 2, NULL); ~~~~

** and there is the LEDBlinkTask function:**

~~~~ static void RAMFUNC LEDBlinkTask(void *pvParameters) { char *pchar;

PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);

pchar = (char *)pvParameters;

for (int tick = 0;; tick++)
{
	vTaskDelay(s_LEDPeriod / portTICK_RATE_MS);
	gpio_output_conf(0, BIT2, BIT2, 0);
	vTaskDelay(s_LEDPeriod / portTICK_RATE_MS);
	gpio_output_conf(BIT2, 0, BIT2, 0);

	printf(pchar);
}

} ~~~~

**when s_LEDPeriod = 300 adn then running the project, i could seen that it prinft "Task 2 is running" and "Task 1 is running"

but when i decrease the s_LEDPeriod as lower than 10 , it was only printf "Task 2 is running",there is no more "Task 1 is running"

does anybody give me a hand , tell me what is the matter uxPriority with vTaskdelay

BR!!!!**


Need more detail of the uxPriority parameter in xCreateTask function

Posted by richard_damon on October 28, 2015

What is portTICKRATEMS set to? (You may need to trace back other defines) If s_LEDPeriod is set below it this would be expected as the delay becomes 0 ticks, or 'no delay'.


Need more detail of the uxPriority parameter in xCreateTask function

Posted by rtel on October 28, 2015

A few minor details before getting to the main point of your post:

sLEDPeriod / portTICKRATE_MS

The recommended way of doing this now is to use the code "pdMSTOTICKS( s_LEDPeriod )" - although both will still work.

xTaskCreate( ..., (signed char *)"Blink1", ...);

be careful as to where the string passed in as the task parameter is allocated. It will probably change with the compiler optimisation. If it is allocated in const memory then there will be problem, but if it is allocated on the stack of the function that creates the tasks then there could be a problem as you will end up with one task referencing the stack of another function - maybe the main() function or maybe another task - and that memory is likely to change.

The easiest thing to do is declare the strings as file scope constants, such as:

static const char *pcString1 = "Blink1";

and then pass in the pcString1 variable as the task parameter.

....now onto your question, in addition to Richard Damon's reply:

How is printf() implemented? Where is it sending its output?

printf() will often take a long time to execute, so may not be able to execute in time, and it is rarely re-entrant, which can cause corruption if two tasks try using it at the same time. For example, if the output goes to a UART and one task starts to print "hello", but half way through there is a switch to the other task, and that task prints "world", then the output may look something like "helworldlo" (a context switch occurred between the two 'l' characters.

You can protect printf from this type of problem using a mutex, or scheduler locking, etc.

Regards.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

FreeRTOS kernel V10 is available for immediate download. Now MIT licensed.


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS