This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/DRA718: TI-RTOS Stack memory

Part Number: DRA718
Other Parts Discussed in Thread: SYSBIOS

Tool/software: TI-RTOS

Hi

     We use the CCSv6.1 to creat a RTSC platform for our project.

     We want to specify the stack loction in DDR, so we allocate a section in RTSC plarform.

------------------------------------map file-------------------------------------------

MEMORY CONFIGURATION

         name            origin    length      used     unused   attr    fill
----------------------  --------  ---------  --------  --------  ----  --------
  ISRAM_CODE            00800000   00004000  00000620  000039e0  RW X
  ISRAM_DATA            00804000   00044000  0003b678  00008988  RW X
  L1PSRAM               00e00000   00008000  00000000  00008000  RW X
  L1DSRAM               00f00000   00008000  00000000  00008000  RW 
  SDRAM_CODE            8e000000   00300000  0012cec0  001d3140  RW X
  SDRAM_DATA            8e300000   00400000  0035fb5a  000a04a6  RW X
  SDRAM_STACK           8e700000   00100000  00001000  000ff000  RW X
  NOCACHED_DATA         9f000000   00400000  000424f0  003bdb10  RWIX


SEGMENT ALLOCATION MAP

run origin  load origin   length   init length attrs members
----------  ----------- ---------- ----------- ----- -------
00800000    00800000    00000620   00000620    r-x
  00800000    00800000    00000620   00000620    r-x InternalCode
00804000    00804000    0003b678   00000000    rw-
  00804000    00804000    0003b678   00000000    rw- InternalData
8e000000    8e000000    0012ccc0   0012ccc0    r-x
  8e000000    8e000000    000000a0   000000a0    r-x .text:_c_int00
  8e0000a0    8e0000a0    0012cc20   0012cc20    r-x .text
8e12d000    8e12d000    00000200   00000200    r-x
  8e12d000    8e12d000    00000200   00000200    r-x .vecs
8e300000    8e300000    001f867c   00000000    rw-
  8e300000    8e300000    001f867c   00000000    rw- .far
8e4f8680    8e4f8680    0015de72   0015de72    r--
  8e4f8680    8e4f8680    0015de72   0015de72    r-- .const
8e6564f8    8e6564f8    0000682c   00000000    rw-
  8e6564f8    8e6564f8    0000682c   00000000    rw- .fardata
8e65cd24    8e65cd24    00000430   00000430    r--
  8e65cd24    8e65cd24    00000430   00000430    r-- .switch
8e65d158    8e65d158    000002d8   00000000    rw-
  8e65d158    8e65d158    00000029   00000000    rw- .bss
  8e65d188    8e65d188    00000188   00000000    rw- .neardata
  8e65d310    8e65d310    00000120   00000000    rw- .cio
8e65d430    8e65d430    00002738   00002738    r--
  8e65d430    8e65d430    00002738   00002738    r-- .cinit
8e700000    8e700000    00001000   00000000    rw-
  8e700000    8e700000    00001000   00000000    rw- .stack
9f000000    9f000000    000424f0   00000000    rw-
  9f000000    9f000000    000424f0   00000000    rw- NoCacheData

------------------------------------map file-------------------------------------------

   Then we run our project ,  and we output the  address of the  loacl variable in our TSK, the

    addr =0x8e398588 is still in data section.  and 0x8e398588 - 0x8e300000  = 0x98588 < 0x35fb5a ...... It's strange.

    Please help take a look.

    Thx.

    

  • Hello,

    The stack section specified in the linker command is only used by the MAIN context in a SYS/BIOS application. Separate stacks are created for each task which reduces potential for one task stack to corrupt another. Then, when the BIOS scheduler switches tasks, the SP for the CPU is modified as part the context switch.

    If you want to supply a stack size and pointer for a given task, you can use the Task_Params structure when creating the task. See software-dl.ti.com/.../Task.html

    To allocate this chunk of memory, you can declare a global memory buffer and use compiler pragmas to assist with placement into the memory section of interest. Otherwise, you can create a Heap instance with the desired base address and length, and use the xdc.runtime.Memory API to allocate from that Heap instance.

    Thanks,
    Stephen
  • sHi,

    As you say, separate stacks are created for each task, but this stack is form where?

    We Need to create it fof BIOS ,otherwise how does it know which memeory it can use ?

    I want to analyse where the stack and heap is created for the BIOS.

    I saw that there some configurations in cfg files,such as bellow:

    Program.stack = 0x40000;          //  whate this stack for ?
    BIOS.heapSize = 0x100000;      //  As I see the locate variable addr is here. Does the stacks for each tsk is from here ?
    Program.heap = 0x40000;          //  whate this heap for ?

  • Hello,

    I would encourage you to review the documentation for xdc.cfg.Program under rtsc.eclipse.org/.../index.html and for ti.sysbios.BIOS under software-dl.ti.com/.../index.html.

    BIOS.heapSize will override Program.heap setting. This will be used as the default heap instance for allocating objects like Tasks, Semaphores, etc., and also used for runtime memory operations like Memory_alloc/malloc. Program.stack will create the default stack which is used just after the program has finished initialization.

    As I mentioned in the previous post, this stack is not passed onto each task that is created. This is because the stack would then have to be divided by the number of tasks you have created. Instead, each Task instance will allocate a separate stack to be used. If you don't specify the stack through the Task_Params, then the Task module will use the BIOS default heap as the memory pool from which the Task stack is allocated.

    Otherwise, you can supply information in Task_Params. Please refer to the Task_Params structure in the above sysbios link for the ti.sysbios.knl.Task module. You will see that you can supply a stack in multiple ways:

    • Use .stack and .stackSize to provide a pre-allocated stack pointer.  I described how to do this in the previous post.
    • Use .stackHeap to provide a separate Heap instance besides the default.  There are many ways to create the heaps
    • If configuring statically, use .stackSection to provide a memory section the configuration scripts and linker can use to pre-allocate your stack in.

    Thanks,

    Stephen

  • Hi

    Thanks for your help,I had a further understanding on the BOIS .

    Thanks.