Quality RTOS & Embedded Software

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




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) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

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

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

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

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists