The goal of this assignment is to complete the port of uCOS to the NUCLEO board. Much of the port is already complete (the easy part!). Your job is to implement the assembly language code for critical section entry and exit, and context switch.
- Download and unzip the uCOSPortHW project contained in the zip file: uCOSPortHW.zip
- Open the uCOSPortHW.eww workspace in the EWARM IDE.
- Make sure the uCOSPortHW project builds.
- Launch TeraTerm (Baud rate: 38400)
- Build and upload the project and start it running.
- Notice that it prints some initial messages on the UART but doesn’t get very far before hanging.
- Break into the program.
- Notice it is stuck in a tight loop at the label OSStartHang in the file os_cpu_a.asm.
- Your job is to read the explanatory comments and add missing code to file os_cpu_a.asm to achieve the following:
- Implement OS_CPU_SR_Save(). This function gets called throughout uCOS when entering a critical section. It should capture the current interrupt enable/disable status given by register PRIMASK, then disable interrupts, then return the captured status as the function’s return value.
- Implement OS_CPU_SR_Restore(). This function gets called throughout uCOS when exiting a critical section. It takes an argument consisting of the interrupt enable/disable status and copies it to the PRIMASK register, then returns.
- Implement ContextSwitch(). This code handles the PendSV exception. PendSV is only triggered by software in uCOS and only executes when no other interrupt is active. UCOS triggers PendSV by calling either OSCtxSw() or OSIntCtxSw() if it determines that a context switch is necessary.
- Clean your completed project by removing the Debug folder and zipping it into a file named uCOSPortHW_<YourUwNetId>.zip e.g. uCOSPortHW_janedoe.zip
- Submit your zip file by the due date.
- See Labrosse chapter 13 for the steps of OSCtxSw(). Note that on Cortex-M4 OSCtxSw() just triggers PendSV and the actual work of OSCtxSw() is done by your ContextSwitch.
- OSTBCur is a global pointer to the task block of the current task.
- OSTCBStkPtr is the first field of the task control block struct
- uCOS priorities are 1 byte so use appropriate assembly language data movement instructions, i.e. LDRB/STRB.
- In uCOS, priorities are unique. No two tasks can have the same priority therefore the priority of a task also doubles as its task ID.
- This uCOS port uses only the Main stack pointer (MSP) throughout. However the Process stack pointer (PSP) is used tangentially as a flag to indicate whether the initial context switch has occurred: 4 means no, 0 means yes.
- Your uDebugger diagnostic Hard Fault handler may be useful for debugging; just remove the portion that hacks into the stack and replace it by a spin loop instead of returning from the handler.