thecomet wrote on Wednesday, May 16, 2018:
While inspecting the context switch mechanism for msp430, I realized that in addition to all registers being pushed onto the stack, the critical nesting counter also has to be saved.
portSAVE_CONTEXT macro
/* Save the remaining registers. */
pushm_x #12, r15 ; Pushes registers r4 through r15 onto the stack
mov.w &usCriticalNesting, r14 ; Need to save the task specific critical nesting counter
push_x r14
mov_x &pxCurrentTCB, r12 ; copy pointer to TCB structure into r12
mov_x sp, 0( r12 ) ; pxTopOfStack is the first field in the TCB structure, so this copies the stack pointer into pxTopOfStack by dereferencing r12
endm
What is the reason for having a separate global variable usCriticalNesting and having to save/restore it every time a context switch occurs? Why not have usCriticalNesting be part of the TCB_t structure, which would make context switching easier?