FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [April 2012 Threads] Question about StackPosted 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 StackPosted 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 StackPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|