Last week, I found that the value pxCurrentTCB is different from the instruction address of my task created. After discuss with Dr Shawn, he told me that the value of pxCurrentTCB should be different from the instruction address of task created inside elf file. The pxCurrentTCB is holding the stack address of a task. So I found my concept is wrong and pxCurrentTCB is holding the correct stack address.

When the task created by calling function xTaskCreate, a TCB will be created into the stack. The pxCurrentTCB will holding the highest priority of the task address in the stack. When function xPortStartScheduler is called, the portRESTORE_CONTEXT macro will let stack pointer to retrieve the pxCurrentTCB value and follow by loading the correct data into the register. But before this, we have to make sure the stack is initialized into the correct arrangement in order to let registers load the correct data into it.

By further investigation into the memory of simulator, I found that my stack is initialized incorrectly. So that causes my task unable to run in the system. From the stack initialization, the pxCode is holding return address of the task created. I found that I misplaced this variable. This causes the register with return address function cannot retrieve correct value and miss direction. After my register correctly load the value of return address, the task run in the simulator.

Currently, I only able to run one task in the system. The OS cannot execute two task, so next week I will trying to implement multitasking function in the OS.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.