This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

os_tsk_create_user() and number of bytes in stack

How does one figure out what size stack to use for a task?

This is to use for the library function:

OS_TID os_tsk_create_user(
    void (*task)(void),    /* Task to create */
    U8    priority,        /* Task priority (1-254) */
    void* stk,             /* Pointer to the task's stack */
    U16   size );          /* Number of bytes in the stack */

Is there a rule of thumb to go about this. Maybe, the number of function calls within the task and the amount and size of arguments passed?

  • "Maybe, the number of function calls within the task and the amount and size of arguments passed?"

    And also include local variables in those functions.

    I think you can look at the linker map file for static stack use.

  • Is there a way through a library call to check at run time percentage utilization of the user task stack?

  • Fill the stack with a magic pattern and then later do a memory dump and see how large percentage of the stack that got used.

  • By manually setting the stack (memset()) to A5 I can see its utilization. As expected the stack fills from the bottom up (push/pop instructions). One thing that I noticed is that the top of the stack has 3 bytes modified at addresses 0x20004D61, 0x20004D62, and 0x20004D63.

    What does RL-RTX place at the top of the stack?

    Pointer to Stack (Top): 0x20004D60
    Stack Size: 0x140
    Bottom of Stack: 0x20004EBF

    Magic Pattern/Stack Initialization: A5

    0x20004D60 A5 2E 5A E2 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004D70 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004D80 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004D90 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DA0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DB0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DC0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DD0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DE0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004DF0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E00 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E10 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E20 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E30 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E40 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E50 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E60 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E70 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E80 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004E90 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5
    0x20004EA0 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5 A5