Monday, February 24, 2014

Task Management: Start Task Vs Activate Task

 ① About act_tsk()

The fair part of making a simple function into a task is done by act_tsk(). It does the job of setting up the stack memory, setting up the initial register values of the context as if the task now sleeping just before the task's start function. And, it has been called from task exit processing function. The argument will be the value set in the extended information. So, it needs to initialize particular registers to simulate the scenario which is depend on the ABI (Application Binary Interface) specification of the exeuction environment( CPU, compiler, etc). Other registers can be arbitrary values.

② Difference between the act_tsk and sta_tsk

Both are almost same except two things.
1) In sta_tsk(), the argument of the task function is passed from user. But, in act_tsk(), the extended information pointer is passed to the task start function.
2) In act_tsk(), the activation count is accumulated. But, sta_tsk() is not like that. It just starts the task.

③ uITRON implementation of sta_tsk()

ER sta_tsk(ID tskid, VP_INT stacd)
{
        Sanity check on arguments;
        Enter critical section;
        if (task is in the dormant state) {
                Move to the high address of stack space (bottom);
                Assume that the context is saved in the stack, so move up one
                context size from the bottom and assign it as current stack
                pointer of the context;
                /* The contents of registers when the task begins executing are
                   not guaranteed. So, not all of the registers but few
                  important registers of the context needs to be initialized */
                /* This will be hardware dependent portion */
                /* Especially, all special purpose register value needs to be initialized */
                /* As if ext_tsk is called by default when exiting the task function, */
                Initialize context's Link register (return address) = ext_tsk function
                According to task attributes such as enabled FPU,
                        Initialize/Enabling of the FPU related registers
                Initialize program status register
                context's program counter = task start address;
                context's argument register = stacd
                Initialize other values and counts of the context;
                status = READY;
                wake-up and suspend count and overrun count = 0;
                Add the task to the Ready Queue of priority
                If (the tw-task priority is higher than the current){
                        Call scheduler
                        Return error code from scheduler
                } else {
                        Exit critical section and return error code from it (E_OK)
                        (return E_OK)
                }
                exit critical section and return
        }
        exit critical section and return error code
}

④ uITRON Implementation of act_tsk()

ER act_tsk(ID tskid)
{
        Sanity check on arguments;
        Enter critical section;
        if (task is in the dormant state) {
                Move to the high address of stack space (bottom);
                Assume that the context is saved in the stack, so move up one
                context size from the bottom and assign it as current stack
                pointer of the context;
                /* The contents of registers when the task begins executing are
                   not guaranteed. So, not all of the registers but few
                  important registers of the context needs to be initialized */
                /* This will be hardware dependent portion */
                /* Especially, all special purpose register value needs to be initialized */
                /* As if ext_tsk is called by default when exiting the task function, */
                Initialize context's Link register (return address) = ext_tsk function
                According to task attributes such as enabled FPU,
                        Initialize/Enabling of the FPU related registers
                Initialize program status register
                context's program counter = task start address;
                context's argument register = argument passed using extended information
                Initialize other values and counts of the context;
                status = READY;
                wake-up and suspend count and overrun count = 0;
                Add the task in the ready queue
                Add the task to the Ready Queue of priority
                If (the tw-task priority is higher than the current){
                        Call scheduler
                        Return error code from scheduler
                } else {
                        Exit critical section and return error code from it (E_OK)
                        (return E_OK)
                }
                exit critical section and return
        }
        Otherwise, add the call into the activation count;
        If the activation count is more than the maximum,
                set it to the maximum and set error code to E_QOVR;
        exit critical section and return error code
}

If you want your task to run as many times as you revive it, then use act_tsk..

No comments: