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!
/* 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–;
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() {
vTaskDelete(NULL);
}
another possiblility is to modify port.c only with extern usage for vTaskDelete… (without modyfying taskCreate…)
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…