Quality RTOS & Embedded Software

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


Loading

sample program gives wrong output

Posted by Angel Eyes on October 20, 2008

Hi I copied the preemptive multitasking program which I copied from the Coldfire RTOS port from the website ,

I am constantly getting the following output

Task 0 running.
Task 0 running.
Task 0 running.
Task 0 running.
.
.
.
and so on

Here is the code I have copied , what could be the problem ?

I feel that the task id is not getting passed properly

Please help .

Pasting the code section below . Thank you.

static void vTestTask( void *pvParameters );
static int task1id = 1;
static int task2id = 2;
static int task3id = 3;
static int task4id = 4;
xSemaphoreHandle xSemaphore = NULL;

portSHORT main( void )
{
xTaskCreate( vTestTask, "Task 1", 1000,(void *)&task1id, tskIDLE_PRIORITY + 2, NULL );
xTaskCreate( vTestTask, "Task 2", 1000,(void *)&task2id, tskIDLE_PRIORITY + 2, NULL );
xTaskCreate( vTestTask, "Task 3", 1000,(void *)&task3id, tskIDLE_PRIORITY + 2, NULL );
xTaskCreate( vTestTask, "Task 4", 1000,(void *)&task4id, tskIDLE_PRIORITY + 2, NULL );

my_printf("starting scheduler...\n");

vSemaphoreCreateBinary( xSemaphore );
vTaskStartScheduler();

return 0;
}
/*-----------------------------------------*/

static void vTestTask( void *pvParameters )
{

int taskId = *((int *)pvParameters);

for(;;)
{
if ( xSemaphoreTake( xSemaphore, 0 ) )
{
my_printf("Task %d running.\n", taskId);
xSemaphoreGive( xSemaphore );
}
}
}


RE: sample program gives wrong output

Posted by MEdwards on October 20, 2008
You call to xSemaphoreTask does not specify a block time so a context switch will not happen until a tick interrupt fires. This means the same task will run permanently between each tick.

Put a break point at the top of the vTestTask function and check that it gets hit 4 times. Once for each task. While there check the value of taskId to see if it is correct for each of the 4 occurrences. If not you will have to debug the stack.

RE: sample program gives wrong output

Posted by Angel Eyes on October 21, 2008
Hi ,

Actually the problem is with passing the taskID . I have created a simple task without semaphores and tried to see the task ID getting passed to the task. The value is always 0. What could be the problem ?

RE: sample program gives wrong output

Posted by Dave on October 21, 2008
The parameter is passed to the task on the stack so if it is wrong inside the task then it is probably in the wrong place on the stack. Are the values loaded into the other registers correct?

Which architecture is this running?

RE: sample program gives wrong output

Posted by Angel Eyes on October 21, 2008
ARM7T Architecture . I used the LPC 2106 architecture port and ported for Samsung 4510 processor , both have the same ARM core .

I am sorry I do not have a debug as I am using a version of the skyeye simulator which had a bug in the debug . I will be upgrading to a newer version of Skyeye shortly .

The tasks run flawlessly otherwise, I am using the UART to output characters within each task and it works fine .

RE: sample program gives wrong output

Posted by Angel Eyes on October 21, 2008

Let me upgrade to the newer Skyeye simulator and try to debug the stack . Probably I'll get to see the problem then .

RE: sample program gives wrong output

Posted by Angel Eyes on October 21, 2008
Hi ,

I am facing a strange problem now . Actually if you observe the code above , I found out that the static declaration of the variables e.g. task1d id not accepting any values if declared outside main . Only when I do the declaration without static within the main function does the values get passed in the tasks and I am able to access the pvparameters .

I have installed the newer version of Skyeye and debug is possible now , could anyone please help ?

Regards

RE: sample program gives wrong output

Posted by MEdwards on October 21, 2008
Looks like you have a startup code issue. Your startup code should initialize the static variables.

Using stack variables in main is not good as although the variables will get initialized when you enter main if you then use the main stack RAM for anything else the variables will be overwritten.

Check your linker script correctly describes the memory map of your mcu. Then check the startup code is correctly initializing your static variables.

RE: sample program gives wrong output

Posted by Angel Eyes on October 21, 2008
Hi Edward , ( beg your pardon if I spelt the name wrong )

You are right , the static variables are not described in the startup code , thank you for the lead . But what is the reason behind this , why do I need to declare these variables in the startup . Where do the static variables get stored ?

Also within the FreeRTOS code there are a lot of static declarations , but the startup that I am using does not initialise any of those static variables , the startup code is Samsung 4510 startup code .

Regards

RE: sample program gives wrong output

Posted by Dave on October 22, 2008
Seems you have a mismatch between your startup code and linker script. Or the startup code is just wrong. You will have to step through the startup code to see where your initialized variables get set to their proper values, then see why the statics you have are not included by looking at their addresses in the map file. Is your startup code getting executed at all in the simulator? Maybe it is jumping directly to main().

RE: sample program gives wrong output

Posted by Angel Eyes on October 22, 2008
Hi Dave ,

I single stepped through the code after I upgraded the simulator , it goes through the startup code . I also know this because the IRQ ISR and SWI calls happen from the startup code . Moreover I had to do some changes to the existing Samsung startup code because the requirement was to enter the main in the supervisor mode . So I am sure that the startup code is passed through.

However let me go through the code and check out . Also I ask this question again , the RTOS code itself has a lot of ststics in its code , how to take care of those then ?

Please note I am able to run the tasks otherwise . At least the strings that I intend to print within eash task gets printed faithfully with set task delays and task priorities .

Thank you .


RE: sample program gives wrong output

Posted by Angel Eyes on October 22, 2008
Also no static initialisation has been done in the startup code as far as I know . So I need to look into this .


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


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

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



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

Renesas

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