Last active
May 1, 2020 20:36
-
-
Save dheeptuck/56537a5165a7e64c20f9ada232a7cf3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void OsInitThreadStack() | |
{ | |
/// Enter critical section | |
/// Disable interrupts | |
__asm("CPSID I"); | |
/// Make the TCB linked list circular | |
tcbs[0].nextPt = &tcbs[1]; | |
tcbs[1].nextPt = &tcbs[0]; | |
/// Setup stack for task0 | |
/// Setup the stack such that it is holding one task context. | |
/// Remember it is a descending stack and a context consists of 16 registers. | |
tcbs[0].stackPt = &TCB_STACK[0][STACKSIZE-16]; | |
/// Set the 'T' bit in stacked xPSR to '1' to notify processor | |
/// on exception return about the thumb state. V6-m and V7-m cores | |
/// can only support thumb state hence this should be always set | |
/// to '1'. | |
TCB_STACK[0][STACKSIZE-1] = 0x01000000; | |
/// Set the stacked PC to point to the task | |
TCB_STACK[0][STACKSIZE-2] = (int32_t)(Task0); | |
/// Setup stack for task1 | |
/// Setup the stack such that it is holding one task context. | |
/// Remember it is a descending stack and a context consists of 16 registers. | |
tcbs[1].stackPt = &TCB_STACK[1][STACKSIZE-16]; | |
/// Set the 'T' bit in stacked xPSR to '1' to notify processor | |
/// on exception return about the thumb state. V6-m and V7-m cores | |
/// can only support thumb state hence this should be always set | |
/// to '1'. | |
TCB_STACK[1][STACKSIZE-1] = 0x01000000; | |
/// Set the stacked PC to point to the task | |
TCB_STACK[1][STACKSIZE-2] = (int32_t)(Task1); | |
/// Make current tcb pointer point to task0 | |
pCurntTcb = &tcbs[0]; | |
/// Enable interrupts | |
__asm("CPSIE I "); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment