Quality RTOS & Embedded Software

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


Loading

Issue in Running multiple Tasks

Posted by abdullahshafiq on December 21, 2017

I am a beginner at freeRTOS and trying to make multiple tasks. When I run Example 2(provided in Example Codes) in Windows 10, it runs perfectly and I get the following output:- Task 1 is running Task 2 is running Task 1 is running and so on

But when I run the same code on my FRDM-K64F board, Task 2 Does'nt even run and I only get :- Task 1 is running Task 1 is running Task 1 is running ... The code on FRDM-K64F is as follows:-

~~~

include "FreeRTOS.h"
include "task.h"
include "queue.h"
include "timers.h"

/* Freescale includes. */

include "fsldeviceregisters.h"
include "fsldebugconsole.h"
include "board.h"
include "pin_mux.h"
include "clock_config.h"

/******************************************************************************* * Definitions ******************************************************************************/

/* Task priorities. */

define hellotaskPRIORITY (configMAX_PRIORITIES - 1)

/******************************************************************************* * Prototypes ******************************************************************************/ static void hello_task(void *pvParameters);

/******************************************************************************* * Code *****************************************************************************/ /! * @brief Application entry point. */

define mainDELAYLOOPCOUNT ( 0xffffff )

/* The task function. */ void vTaskFunction( void *pvParameters );

/* Define the strings that will be passed in as the task parameters. These are defined const and off the stack to ensure they remain valid when the tasks are executing. */ const char *pcTextForTask1 = "Task 1 is runningrn"; const char *pcTextForTask2 = "Task 2 is runningrn";

int main(void) { /* Init board hardware. */ BOARDInitPins(); BOARDBootClockRUN(); BOARD_InitDebugConsole();

xTaskCreate(	vTaskFunction,
                                "Task 1",				
                                1000,					
                                (void*)pcTextForTask1,	
                                 1,						/* This task will run at priority 1. */
                                 NULL );					/* We are not using the task handle. */

xTaskCreate( vTaskFunction, "Task 2", 1000, (void*)pcTextForTask2, 1, NULL );
vTaskStartScheduler();

/* The following line should never be reached because vTaskStartScheduler()
will only return if there was not enough FreeRTOS heap memory available to
create the Idle and (if configured) Timer tasks.  Heap management, and
techniques for trapping heap exhaustion, are described in the book text. */
for( ;; );
return 0;

}

void vTaskFunction( void *pvParameters ) { char *pcTaskName; volatile uint32_t ul;

/* The string to print out is passed in via the parameter.  Cast this to a
character pointer. */
pcTaskName = ( char * ) pvParameters;

/* As per most tasks, this task is implemented in an infinite loop. */
for( ;; )
{
	/* Print out the name of this task. */
	printf( pcTaskName );

	/* Delay for a period. */
	for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ )
	{
		/* This loop is just a very crude delay implementation.  There is
		nothing to do in here.  Later exercises will replace this crude
		loop with a proper delay/sleep function. */
	}
}

}

~~~


Issue in Running multiple Tasks

Posted by rtel on December 21, 2017

Have you installed the FreeRTOS interrupt handlers? See the "Special note to ARM Cortex-M users" in the to Q1 on this page of the FAQ: https://www.freertos.org/FAQHelp.html


Issue in Running multiple Tasks

Posted by abdullahshafiq on December 22, 2017

Sorry I am a little confused, my freeRTOSConfig.h already contains ~~~

define vPortSVCHandler SVC_Handler
define xPortPendSVHandler PendSV_Handler
define xPortSysTickHandler SysTick_Handler

~~~ I tried commenting out these three lines but it resulted my code to get stuck in these loop shown in the attached picture. Please help me

Attachments

2.JPG (108003 bytes)

Issue in Running multiple Tasks

Posted by abdullahshafiq on December 22, 2017

I have also been experimenting with the task priorities. If I keep the priority 1 or 2 of both the tasks, task1 keeps on running. If I keep priority of both the tasks greater than 2(I tested on 3,4,5) Task 2 Keeps on running.


Issue in Running multiple Tasks

Posted by rtel on December 22, 2017

Just sounds like the interrupts are not installed.

Are you calling FreeRTOS API functions from interrupts?

I see you have the three lines in your FreeRTOSConfig.h, but are the interrupt actually getting installed? If the vector table is populated with functions called SVCHandler, PendSVHandler and SysTick_Handler, which is normal, then they should be.


Issue in Running multiple Tasks

Posted by abdullahshafiq on December 28, 2017

The Issue was resolved by adding calling xTaskDelay(10) in the while loop of both functions. ~~~ static void hellotask1(void *pvParameters) { for (;;) { PRINTF("Task 1 .rn"); xTaskDelay(10); } } static void hellotask2(void *pvParameters) { for (;;) { PRINTF("Task 2 rn"); xTaskDelay(10); } } ~~~ Another solutions was to set #define configUSETIMESLICING to 1 and the both tasks ran without xTaskDelay function. Is there an another solution?


Issue in Running multiple Tasks

Posted by abdullahshafiq on December 28, 2017

The Pdf manual cleared up a lot of my confusions !! Thanks a lot


Issue in Running multiple Tasks

Posted by abdullahshafiq on January 23, 2018

Hello, I am running freeRTOS with the default SDK provided by NXP. I have two tasks named User1 and User2. I am learning semaphores and interrupts. I suspend both the tasks and want them to run when a switch is presses(SW3 on FRDM-64F) therefore I added the Resum function for both tasks in the Switch's ISR. Whenever I press the switch I get stuck up in Config Assert. ~~~ if( ulCurrentInterrupt >= portFIRSTUSERINTERRUPT_NUMBER ) { /* Look up the interrupt's priority. */ ucCurrentPriority = pcInterruptPriorityRegisters[ ulCurrentInterrupt ]; configASSERT( ucCurrentPriority >= ucMaxSysCallPriority ); } ~~~

In this Case ulCurrentInterrupt is 75 which I cross checked from the Interrupt Vector Table. However ucCurrentPriority gets a value of 0. When I try to view the value of pcInterruptPriorityRegisters[ ulCurrentInterrupt ]; it gives me Details:0x20030000 Default:0x20030000 Decimal:537067520

In freeRTOSConfig.h Following is the interrupt Config: -``

~~~

define configPRIOBITS __NVICPRIOBITS // __NVICPRIO_BITS = 4
define configLIBRARYLOWESTINTERRUPTPRIORITY ((1U << (configPRIOBITS)) - 1) //15
define configLIBRARYMAXSYSCALLINTERRUPTPRIORITY 2
define configKERNELINTERRUPTPRIORITY (configLIBRARYLOWESTINTERRUPTPRIORITY << (8 - configPRIOBITS)) //240
define configMAXSYSCALLINTERRUPTPRIORITY (configLIBRARYMAXSYSCALLINTERRUPTPRIORITY << (8 - configPRIOBITS)) //32

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS standard names. */

define vPortSVCHandler SVC_Handler
define xPortPendSVHandler PendSV_Handler
define xPortSysTickHandler SysTick_Handler`

~~~

My Source Code is as follows :- ~~~ /******************************************************************************* * Variables ******************************************************************************/ SemaphoreHandlet gatekeeper = 0; TaskHandlet user1handle; TaskHandle_t user2handle;

void access() { PRINTF("in aceessrn");

} static void user1(void *arg) { if(xSemaphoreTake(gatekeeper, 1000)) { PRINTF("uSer 1 got aceessrn"); access(); xSemaphoreGive(gatekeeper); } else PRINTF("uSer 1 didnt aceessrn");

vTaskSuspend(NULL);

} static void user2(void *arg) { if(xSemaphoreTake(gatekeeper, 1000)) { PRINTF("uSer 2 got aceessrn"); access(); xSemaphoreGive(gatekeeper); } else PRINTF("uSer 2 didnt aceessrn");

		vTaskSuspend(NULL);

}

void BOARDSWIRQ_HANDLER(void) { xTaskResumeFromISR(user1handle); xTaskResumeFromISR(user2handle); }

int main(void) { SYSMPUType *base = SYSMPU; BOARDInitPins(); BOARDBootClockRUN(); BOARDInitDebugConsole(); /* Disable SYSMPU. */ base->CESR &= ~SYSMPUCESRVLD_MASK; gatekeeper = xSemaphoreCreateMutex();

if((xTaskCreate( user1, "user1", INITTHREADSTACKSIZE, NULL, INITTHREADPRIO, &user1handle )) == pdPASS) PRINTF("Task user 1 creation successfull rn"); if((xTaskCreate( user2, "user2", INITTHREADSTACKSIZE, NULL, INITTHREADPRIO, &user2handle )) == pdPASS) PRINTF("Task user 2 creation successfull rn");

vTaskStartScheduler();

return 0;

}

~~~


Issue in Running multiple Tasks

Posted by rtel on January 23, 2018

If you are calling a FreeRTOS API function from an interrupt then the priority of the interrupt must be at or below configMAXSYSCALLINTERRUPT_PRIORITY - which on an ARM means a numerically lower number. All interrupts default to a priority of 0 - which is the highest priority - so you must manually set the interrupt's priority to a lower logical (higher numerical) value before using it. More information is here (this is more complex than it needs to be on a Cortex-M):

https://www.freertos.org/RTOS-Cortex-M3-M4.html


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


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

Careers

FreeRTOS and other careers at AWS.


Latest News

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


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

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

Xilinx Microblaze and Zynq partner