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.

DSP/BIOS 6 . thread creation during runtime

 

 Hi All,

 Can I create a task during runtime . ie the situation is as follws , I have a task  created from main . Inside the task handler for this task  I am calling another  task_create()  with a different task handler .

Will it work ? I tried that but the code crashes after some time ...

 

Regards,

Bushra

  • Grtns,

    So long that you have not dropped out of main and into DSP/BIOS, you should be able to create as many tasks as needed.

    Here is an example you should call from your main()

    void CreateTasks(void)
    {
     TSK_Handle hTask;

     TSK_Attrs  Atrbt;

     Atrbt.priority     = xx;
     Atrbt.stack        = NULL;
     Atrbt.stacksize    = yy;
     Atrbt.stackseg     = 1;
     Atrbt.environ      = NULL;
     Atrbt.name         = NULL;
     Atrbt.exitflag     = TRUE;
     Atrbt.initstackflag= FALSE;

     hTask = TSK_create((Fxn)First_Task, &Atrbt);
     if (hTask == NULL) sysabort("task creation error");
     Atrbt.priority     = nn;
     hTask = TSK_create((Fxn)Second_Task, &Atrbt);
     if (hTask == NULL) sysabort("task creation error");
     Atrbt.priority     = mm;
     hTask = TSK_create((Fxn)Third_Task, &Atrbt);
     if (hTask == NULL) sysabort("task creation error");
    }

    When you drop intoDSP/BIOs, you will crash your RT if you attempt to create a task in there.

    Regards,

  • Grtns,

    and here is a typical c_int00 content where it shows how you drop into BIOS

    _c_int00:
    b atomic
    zero b0
    mvc b0,ier
    nop 3
    atomic:
    mvkl __stack,SP
    mvkh __stack,SP
    mvkl __STACK_SIZE - 4,B0
    mvkh __STACK_SIZE - 4,B0
    add B0,SP,SP
    and ~7,SP,SP
    mvkl $bss,DP
    mvkh $bss,DP
    mvk 0,B3
    mvc B3,FADCR
    mvc B3,FMCR
    mvk 0,B3
    mvc B3,AMR
    mvc B3,CSR
    mvkl cinit,A4
    mvkh cinit,A4
    mv DP,B4
    mvkl __auto_init, B0
    mvkh __auto_init, B0
    b B0
    mvkl boot_ret, B3
    mvkh boot_ret, B3
    nop 3
    boot_ret:
    mvkl args,A0
    mvkh args,A0
    ldw *+A0[2],A6
    ldw *+A0[1],B4
    ldw *+A0[0],A4
    mvkl _main, B0
    mvkh _main, B0
    b B0
    mvkl main_ret, B3
    mvkh main_ret, B3
    nop 3
    main_ret:
    mvkl _BIOS_start, B0
    mvkh _BIOS_start, B0
    b B0
    mvkl BIOS_start_ret, B3
    mvkh BIOS_start_ret, B3
    nop 3
    BIOS_start_ret:

    Regards,

  • A further comment with regard to the original question on whether a BIOS task can dynamically create other tasks, the answer is yes, there is no restriction on that.

  • Dear David,

     Thanks for the answer . Is there any restrictions on the stackSize for these tasks , like the mother thread should have a bigger

    stackSize to support the child thread etc ... and upto how many levels this thread creation can be done .. like one thread spawns the other , this spawns another one etc ..

     

     

    Regards,

    Bushra .

  • Grtns, some notes.

    Rgrds,

    Dynamically created objects require additional code to support the dynamic operations. Statically-declared objects minimize memory footprint, since they do not include the additional create code.

     TSK Manager Properties
    The following global properties can be set for the TSK module in the TSK
    Manager Properties dialog of Gconf or in a Tconf script:
    ❏ Enable TSK Manager. If no tasks are used by the program other
    than TSK_idle, you can optimize the program by disabling the task
    manager. The program must then not use TSK objects created with
    either Tconf or the TSK_create function. If the task manager is
    disabled, the idle loop still runs and uses the system stack instead of
    a task stack.
    Tconf Name: ENABLETSK Type: Bool
    Example: bios.TSK.ENABLETSK = true;
    ❏ Object Memory. The memory segment that contains the TSK
    objects created with Tconf.
    Tconf Name: OBJMEMSEG Type: Reference
    Example: bios.TSK.OBJMEMSEG = prog.get("myMEM");
    ❏ Default stack size. The default size of the stack (in MADUs) used by
    tasks. You can override this value for an individual task you create
    with Tconf or TSK_create. The estimated minimum task size is
    shown in the status bar of Gconf. This property applies to TSK
    objects created both with Tconf and with TSK_create.
    Tconf Name: STACKSIZE Type: Int16
    Example: bios.TSK.STACKSIZE = 1024;
    ❏ Stack segment for dynamic tasks. The default memory segment to
    contain task objects created at run-time with the TSK_create
    function. The TSK_Attrs structure passed to the TSK_create function
    can override this default. If you select MEM_NULL for this property,
    creation of task objects at run-time is disabled.
    Tconf Name: STACKSEG Type: Reference
    Example: bios.TSK.STACKSEG = prog.get("myMEM");
    ❏ Default task priority. The default priority level for tasks that are
    created dynamically with TSK_create. This property applies to TSK
    objects created both with Tconf and with TSK_create.
    Tconf Name: PRIORITY Type: EnumInt
    Options: 1 to 15
    Example: bios.TSK.PRIORITY = 1;
    ❏ TSK tick driven by. Choose whether you want the system clock to
    be driven by the PRD module or by calls to TSK_tick and TSK_itick.
    This clock is used by TSK_sleep and functions such as SEM_pend
    that accept a timeout argument.
    Tconf Name: DRIVETSKTICK Type: EnumString
    Options: "PRD", "User"
    Example: bios.TSK.DRIVETSKTICK = "PRD";
    ❏ Create function. The name of a function to call when any task is
    created. This includes tasks that are created statically and those
    created dynamically using TSK_create. If you are using Tconf, do not
    add an underscore before the function name; Tconf adds the
    underscore needed to call a C function from assembly internally. The
    TSK_create topic describes the Create function.
    Tconf Name: CREATEFXN Type: Extern
    Example: bios.TSK.CREATEFXN =
    prog.extern("tskCreate");
    ❏ Delete function. The name of a function to call when any task is
    deleted at run-time with TSK_delete. The TSK_delete topic
    describes the Delete function.
    Tconf Name: DELETEFXN Type: Extern
    Example: bios.TSK.DELETEFXN =
    prog.extern("tskDelete");
    ❏ Exit function. The name of a function to call when any task exits.
    The TSK_exit topic describes the Exit function.
    Tconf Name: EXITFXN Type: Extern
    Example: bios.TSK.EXITFXN =
    prog.extern("tskExit");
    ❏ Call switch function. Check this box if you want a function to be
    called when any task switch occurs.
    Tconf Name: CALLSWITCHFXN Type: Bool
    Example: bios.TSK.CALLSWITCHFXN = false;
    ❏ Switch function. The name of a function to call when any task switch
    occurs. This function can give the application access to both the
    current and next task handles. The TSK Module topic describes the
    Switch function.
    Tconf Name: SWITCHFXN Type: Extern
    Example: bios.TSK.SWITCHFXN =
    prog.extern("tskSwitch");
    ❏ Call ready function. Check this box if you want a function to be
    called when any task becomes ready to run.
    Tconf Name: CALLREADYFXN Type: Bool
    Example: bios.TSK.CALLREADYFXN = false;
    ❏ Ready function. The name of a function to call when any task
    becomes ready to run. The TSK Module topic describes the Ready
    function.
    Tconf Name: READYFXN Type: Extern
    Example: bios.TSK.READYFXN =
    prog.extern("tskReady");