This week I am trying to implement the stack initialization to the system. Other than that, the FreeRTOS required programmer to make functions to save and restore context of the system during tasks switching.
Every tasks in FreeRTOS required to save into the stack. The task is assigned to the stack during creating task into the system. Once the task is needed to be run, the stack pointer will restore to the particular stack address. And the minimal task space is assigned in FreeRTOS in “configMINIMAL_STACK_SIZE” in the config file.
Stack is a section of memory which used to save the program. The stack pointer like an arrow will point to the particular stack when program is running. Other than that, program cannot be save beyond the limit of stack address, it will be overflow and fail to create the program.
FreeRTOS need to initialize the general register and stack pointer into the stack. When context switching process is needed, the scheduler will save the current register context data into the stack and switch the next context data into the register. After the context is finished, the register will restore back the previous context data into the register and continue the following section. In the save and restore processes, those code are wrote in assembly language based on RISCV manner, which using load and store operation.
When a task run in FreeRTOS, the TaskStartScheduler() will restore the stack section of created task to the registers, which a variable called pxCurrentTCB is holding the address of task stack pointer can retrieve. For current progress of my OS, I still failed to load the address of stack to registers. The pxCurrentTCB are not holding the correct stack address. Next week, I will still working to solve this problem and make a task run in the OS.