Quality RTOS & Embedded Software

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




Loading

Question about Stack

Posted by Mohammad on April 26, 2012
hallo everyone,
i am using freertos with Codecomposer and the msp430f5438.
i have question about the stacksize, that will be given to tasks, when they are created,

in this example:
xTaskCreate( protReceiveByte, ( signed char * ) "protByte", 2000, NULL , tskIDLE_PRIORITY + 3, NULL );

the task protReceiveByte is beeing created and has 2000 as stacksize.
now this task usese another functions like "rbRead" or "pdSetHeader" and others, as to see in the code below:

void protReceiveByte(void *pvParameters)
{
char xReceivedMessage;
unsigned int uIntData;


for( ;; )
{



while (!rbIsEmpty(&Buffer))
{

xReceivedMessage = rbRead(&Buffer);
uIntData = (unsigned int)xReceivedMessage;


/* Zustand */
if (protInstance.state == PROT_STOP)
{
if(xReceivedMessage == PROT_START_SEQ)
{
protInstance.state = PROT_HEADER_1;
}
break;
}



/* Zustand */
if (protInstance.state == PROT_HEADER_1)
{
pdSetHeader(protInstance.protd, uIntData);
protInstance.state = PROT_HEADER_2;
break;
}


/* Zustand */
if (protInstance.state == PROT_HEADER_2)
{
pdAddToHeader(protInstance.protd, (256 * uIntData));

/* Check for valid/used header */
if(headerGetPayloadLength(pdGetHeader(protInstance.protd)) == 0)
{
protInstance.state = PROT_ERROR;
continue;
}
else {
protInstance.state = PROT_LENGTH_1;
break;
}
}


/* Zustand */
if (protInstance.state == PROT_LENGTH_1)
{
pdSetLength(protInstance.protd, uIntData);
protInstance.state = PROT_LENGTH_2;
break;
}

/* Zustand */
if (protInstance.state == PROT_LENGTH_2)
{
pdAddToLength(protInstance.protd, (256 * uIntData));
protInstance.pdLength = pdGetLength(protInstance.protd);


if (protInstance.pdLength < 1) {
protInstance.state = PROT_ERROR;
continue;
}
protInstance.byteCount = 0;

/* Check for a valid "header/payload length" combination */
if(protInstance.pdLength == headerGetPayloadLength(pdGetHeader(protInstance.protd)))
{
protInstance.state = PROT_DATA;
break;
}
else {
protInstance.state = PROT_ERROR;
continue;
}
}


/* Receive the data bytes */
if (protInstance.state == PROT_DATA)
{
pdSetByte(protInstance.protd, protInstance.byteCount, xReceivedMessage);
//pdInstance.data[protInstance.byteCount]=xReceivedMessage;
protInstance.byteCount++;
/* When all data bytes have been received, expect end sequence byte next. */
if(protInstance.byteCount == protInstance.pdLength) {
protInstance.state = PROT_END;
}
break;
}

/* Receive end sequence byte */
if (protInstance.state == PROT_END)
{
if(xReceivedMessage == PROT_END_SEQ)
{
/* Valid packet was received */
/* Create event */
xQueueSend(xPROTQueue,&pdInstance,0);



/* Reset protocol automaton */
protInstance.protd = &pdInstance; /* new, empty protocol data object */
protInstance.pdLength = 0; /* empty payload length */
protInstance.byteCount = 0; /* no payload bytes received */
protInstance.state = PROT_STOP; /* initial protocol automaton state */
break;
}
else
{
protInstance.state = PROT_ERROR;
continue;
}
}


/* Zustand */
if (protInstance.state == PROT_ERROR)
{
pdSetHeader(protInstance.protd, 0); /* reset header */
pdSetLength(protInstance.protd, 0); /* reset length */
protInstance.state = PROT_STOP; /* initial protocol automaton state */
break;
}

/* This code should never be reached, but go to PROT_ERROR if it happens. */
protInstance.state = PROT_ERROR;


}

}
}

now my question: did these functions get another stack on the RAM than the stack, that is given to the task, or it will be part of the created task, and have the same stack, that was given to this created task?

best Regards.

RE: Question about Stack

Posted by Dave on April 26, 2012
The stack allocated in this case is 2000 words, which on your chip is 4000 bytes. That is a big stack for such a tiny device.

The stack given to the task is no different to a normal stack. When a function is called the compiler will put the return address and possibly the function parameters on the stack itself. Any local variables inside the function will also get put on the stack by the compiler. This is just the same as what happens when you call a function from main(). FreeRTOS does not do this, the compiler and hardware do, using the chips stack pointer.

RE: Question about Stack

Posted by Mohammad on April 26, 2012
thanx davedoors for your reply.
now i understand it.

but because this task uses a lot of another functions and there variables, the stack for this task must be big.
i have no other choice.

in spite of this big stacksize, there is a stackoverflow ....

thanx again.


[ 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