ctc8631 wrote on Monday, May 22, 2017:
Hello, I’m new freeRTOS learner, I’m trying to understand v9.0 source code about task.c,
When I want to create a new task, using xTaskCreate(), it will later call prvInitialiseNewTask(), there are some code I’m confused here,
#if( portSTACK_GROWTH < 0 )
{
pxTopOfStack = pxNewTCB->pxStack + ( ulStackDepth - ( uint32_t ) 1 );
pxTopOfStack = ( StackType_t * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ~( ( portPOINTER_SIZE_TYPE ) portBYTE_ALIGNMENT_MASK ) ) );
}
I’m not sure why to calculate topStack need to minus 1,
I read pxPortInitialiseStack(), and found that everytime it need stack space, it will minus position first, then use space,
So I really not sure why to -1 when calculate topStack first time, and need alignment it later, did this waste space?
thanks =)