task ending

nobody wrote on Wednesday, August 23, 2006:


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()



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!


dmwilliams66 wrote on Thursday, August 24, 2006:

I second the implied request for an automatic TaskDelete() on return from a task!

nobody wrote on Thursday, August 24, 2006:

I see there is necessary to modify tasks.c and port.c (I write for GCC_SAM7):

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 = ( portSTACK_TYPE ) pxExit /*0xaaaaaaaa*/;    /* R14 */ <===== LR
    *pxTopOfStack = ( portSTACK_TYPE ) pxOriginalTOS; /* Stack used when task starts goes in R13. */
    *pxTopOfStack = ( portSTACK_TYPE ) 0x12121212;    /* R12 */


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
        the    top of stack variable is updated. */
        pxNewTCB->pxTopOfStack = pxPortInitialiseStack( pxTopOfStack, pvTaskCode, pvTaskExit, pvParameters );

void pvTaskExit() {

another possiblility is to modify port.c only with extern usage for vTaskDelete… (without modyfying taskCreate…)

best regards

nobody wrote on Thursday, 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?

nobody wrote on Thursday, 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?

rtel wrote on Thursday, August 24, 2006:

My preference was to structure tasks as:

void vATask( void *pvParameters )
________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.