/*
 *  ======== Task_schedule ========
 *  Find highest priority task and invoke it.
 *
 *  Must be called with interrupts disabled.
 */
Void Task_schedule()
{
    Queue_Handle maxQ;
    Task_Object *prevTask;
    Task_Object *curTask;
#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    Int i;
#endif

    do {
        Task_module->workFlag = 0;

        /* stall until a task is ready */
        while (Task_module->curSet == 0) {
            Task_allBlockedFunction();
        }

        /* Determine current max ready Task priority */
        maxQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) +
                (UInt)(Intrinsics_maxbit(Task_module->curSet)*(2*sizeof(Ptr))));

        /* if a higher priority task is ready - switch to it */
        if (maxQ > Task_module->curQ) {
            prevTask = Task_module->curTask;
            Task_module->curQ = maxQ;
            Task_module->curTask = Queue_head(maxQ);
            curTask = Task_module->curTask;

            if (Task_checkStackFlag) {
                Task_checkStacks(prevTask, curTask);
            }
	
#if !defined(ti_sysbios_knl_Task_DISABLE_ALL_HOOKS) \
    || (xdc_runtime_Log_DISABLE_ALL == 0)
            /* It's safe to enable intrs here */
            Hwi_enable();

#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
            for (i = 0; i < Task_hooks.length; i++) {
                if (Task_hooks.elem[i].switchFxn != NULL) {
                    Task_hooks.elem[i].switchFxn(prevTask, curTask);
                }
            }
#endif

            Log_write4(Task_LM_switch, (UArg)prevTask, (UArg)prevTask->fxn,
                       (UArg)curTask, (UArg)curTask->fxn);

            /* Hard-disable intrs - this fxn is called with them disabled */
            Hwi_disable();
#endif
            Task_SupportProxy_swap((Ptr)&prevTask->context,
                            (Ptr)&curTask->context);
        }
    } while (Task_module->workFlag);
}
Example #2
0
/*
 *  ======== Task_startup ========
 */
Void Task_startup()
{
    Queue_Handle maxQ;
    Task_Object *prevTask;
    Task_Struct dummyTask;
    Int i;

    Hwi_disable();      /* re-enabled in Task_enter of first task */

    /* Use dummyTask as initial task to swap from */
    prevTask = Task_handle(&dummyTask);

    /* stall until a task is ready */
    while (Task_module->curSet == 0) {
        Task_allBlockedFunc();
    }

    /* Determine current max ready Task priority */
    maxQ = (Queue_Handle)((UInt8 *)(Task_module->readyQ) + 
                (UInt)(Intrinsics_maxbit(Task_module->curSet)*(2*sizeof(Ptr))));

    Task_module->curQ = maxQ;
    Task_module->curTask = Queue_head(maxQ);

    /* we've done the scheduler's work */
    Task_module->workFlag = 0;

    /* Signal that we are entering task thread mode */
    BIOS_setThreadType(BIOS_ThreadType_Task);
        
    /* should be safe to enable intrs here */
    Hwi_enable();

#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    /* Run switch hooks for first real Task */
    for (i = 0; i < Task_hooks.length; i++) {
        if (Task_hooks.elem[i].switchFxn != NULL) {
            Task_hooks.elem[i].switchFxn(NULL, Task_module->curTask);
        }
    }
#endif

    Log_write4(Task_LM_switch, (UArg)0, (UArg)0, 
               (UArg)Task_module->curTask, 
               (UArg)Task_module->curTask->fxn);

    /* must leave this function with ints disabled */
    Hwi_disable();

    /* inform dispatcher that we're running on task stack */
    Hwi_switchFromBootStack();  

    /* start first task by way of enter() */
    Task_SupportProxy_swap((Ptr)&prevTask->context,
                (Ptr)&Task_module->curTask->context);
}