Menu

RTOS part 2 video

anh
2022-07-04
2022-07-04
  • anh

    anh - 2022-07-04

    I have a question that when do we use CPU register (LR, R12, R3, R2, R1, R0) in starting thread like in video without assign temp value ((--sp) = 0x0000000CU; / for R12 /, .... ). Can you give me example or we can use that template for all type of thread not only blink led ?
    /
    fabricate Cortex-M ISR stack frame for blinky1 /
    (--sp) = (1U << 24); / xPSR /
    (--sp) = (uint32_t)OSThread_handler; / PC /
    (--sp) = 0x0000000EU; / LR /
    (--sp) = 0x0000000CU; / R12 /
    (--sp) = 0x00000003U; / R3 /
    (--sp) = 0x00000002U; / R2 /
    (--sp) = 0x00000001U; / R1 /
    (--sp) = 0x00000000U; / R0 */

     
  • Quantum Leaps

    Quantum Leaps - 2022-07-04

    Hi Anh,
    I probably don't quite understand your question, but the code to "fabricate" a stack frame for a thread is generic for any thread.

    Can you give me example or we can use that template for all type of thread not only blink led ?

    Again, your code snippet does not correspond to any presented code (e.g., nowhere in the publish code I can find (--sp) = (uint32_t)OSThread_handler;), but in the presented code is part of the "MiROS" RTOS and specifically the QSThread_start() function:

    void OSThread_start(
        OSThread *me,
        OSThreadHandler threadHandler,
        void *stkSto, uint32_t stkSize)
    {
        /* round down the stack top to the 8-byte boundary
    
        * NOTE: ARM Cortex-M stack grows down from hi -> low memory
        */
        uint32_t *sp = (uint32_t *)((((uint32_t)stkSto + stkSize) / 8) * 8);
        uint32_t *stk_limit;
    
        *(--sp) = (1U << 24);  /* xPSR */
        *(--sp) = (uint32_t)threadHandler; /* PC */
        *(--sp) = 0x0000000EU; /* LR  */
        *(--sp) = 0x0000000CU; /* R12 */
        *(--sp) = 0x00000003U; /* R3  */
        *(--sp) = 0x00000002U; /* R2  */
        *(--sp) = 0x00000001U; /* R1  */
        *(--sp) = 0x00000000U; /* R0  */
        /* additionally, fake registers R4-R11 */
        *(--sp) = 0x0000000BU; /* R11 */
        *(--sp) = 0x0000000AU; /* R10 */
        *(--sp) = 0x00000009U; /* R9 */
        *(--sp) = 0x00000008U; /* R8 */
        *(--sp) = 0x00000007U; /* R7 */
        *(--sp) = 0x00000006U; /* R6 */
        *(--sp) = 0x00000005U; /* R5 */
        *(--sp) = 0x00000004U; /* R4 */
    ...
    

    Finally, this post probably belongs to the comment section immediately after the corresponding video lesson. A post in this forum appears out of context.

    --MMS

     

    Last edit: Quantum Leaps 2022-07-04
  • anh

    anh - 2022-07-04

    Yeah. Thank you, Quantum Leaps.
    I'm sorry, I just missing information when I copy code.
    According to your reply, "the code to "fabricate" a stack frame for a thread is generic for any thread". So I can use this "fabricate" for all threads, regardless that thread do many thing than blink led only.
    And I post this, because I have had some comments on your video on youtube, but I have not got your reply. Sorry for posting it on this forum.

     

    Last edit: anh 2022-07-04
  • Quantum Leaps

    Quantum Leaps - 2022-07-04

    Hi Anh,

    So I can use this "fabricate" for all threads, regardless that thread do many thing than blink led only.

    Yes, the "MiROS" RTOS that is being built in the video lessons 22-27 is intended to be functional for any threads and the "Blinky" is just an example thread. You're apparently only at "RTOS part-2", so please watch the rest of the lessons on "RTOS". You'll see more examples of multiple threads as well as different schedulers and many other interesting features. Stay tuned!

    BTW, the "MiROS" RTOS is available on GitHub, so you can take a look...

    --MMS

     

    Last edit: Quantum Leaps 2022-07-04

Log in to post a comment.

MongoDB Logo MongoDB