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] [August 2006 Threads] task endingPosted by Nobody/Anonymous on August 23, 2006 Hi,
I want to ask about task ending relevant to freeRTOS + lwIP + ppp thread. I think that on task stack should be return address. For example in pseudo-code:
void vtask() { ..... }
createTask(vtask);
When vtask() finish all operations the system will crash. There is no return address to vportYield for example or better to vTaskDelete(NULL)... There was assumed that a task always is infinite loop or is deletted manually from list. I can add this manually of couse but many OS do not require this!
Janusz
RE: task endingPosted by David Williams on August 24, 2006 I second the implied request for an automatic TaskDelete() on return from a task!
RE: task endingPosted by Nobody/Anonymous on August 24, 2006 I see there is necessary to modify tasks.c and port.c (I write for GCC_SAM7):
port.c: portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, pdTASK_CODE pxExit, void *pvParameters ) { portSTACK_TYPE *pxOriginalTOS;
pxOriginalTOS = pxTopOfStack;
/* Setup the initial stack of the task. The stack is set exactly as expected by the portRESTORE_CONTEXT() macro. */
/* First on the stack is the return address - which in this case is the start of the task. The offset is added to make the return address appear as it would within an IRQ ISR. */ *pxTopOfStack = ( portSTACK_TYPE ) pxCode + portINSTRUCTION_SIZE; pxTopOfStack--;
*pxTopOfStack = ( portSTACK_TYPE ) pxExit /*0xaaaaaaaa*/;/* R14 */ <===== LR pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */ pxTopOfStack--; *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;/* R12 */ pxTopOfStack--; ...... }
tasks.c, TaskCreate: .... /* Initialize the TCB stack to look as if the task was already running, but had been interrupted by the scheduler. The return address is set to the start of the task function. Once the stack has been initialised thetop of stack variable is updated. */ pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvTaskExit, pvParameters ); ....
void pvTaskExit() { vTaskDelete(NULL); }
another possiblility is to modify port.c only with extern usage for vTaskDelete... (without modyfying taskCreate...)
best regards Janusz
RE: task endingPosted by Nobody/Anonymous on August 24, 2006 in this moment I haven't target for tests but I will check it. Is it possible to work? What do you think?
RE: task endingPosted by Nobody/Anonymous on August 24, 2006 I have noticed there could be problem with GCC compiler/linker: Typicaly task is not called from code visibly for compiler because is running from OS task restore. Therefore compiler doesn't add return code!!! (the same is with register storing on the stack!). The poor way is call task visibly in place which is newer running but it does not look nice...
any ideas?
RE: task endingPosted by Richard on August 24, 2006 My preference was to structure tasks as:
void vATask( void *pvParameters ) { ____loop ____{ ________do task stuff here ____}
____/* We broke out of the loop. */ ____vTaskDelete( NULL ); }
This is explicit in what the behaviour is, portable (try to avoid chaning every port for a feature) and does not require any new kernel code.
However - if I'm in the minority then we can add it to the feature request list.
Regards.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|