/*
 *  ======== 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);
}
/*
 *  ======== Power_setConstraint ========
 *  Declare an operational constraint.
 */
Void Power_setConstraint(Power_Constraint constraint)
{
    UInt key;

    key = Hwi_disable();
    Power_module->constraintsMask |= constraint;
    ti_sysbios_family_arm_cc26xx_Power_constraintCounts[
        Intrinsics_maxbit(constraint)]++;
    Hwi_restore(key);
}
/*
 *  ======== Power_releaseConstraint ========
 *  Release a previously declared constraint.
 */
Void Power_releaseConstraint(Power_Constraint constraint)
{
    UInt key;
    UInt8 count;

    key = Hwi_disable();

    count = ti_sysbios_family_arm_cc26xx_Power_constraintCounts[
        Intrinsics_maxbit(constraint)];

    Assert_isTrue(count != 0, Power_A_tooManyCallsReleaseConstraint);

    ti_sysbios_family_arm_cc26xx_Power_constraintCounts[
        Intrinsics_maxbit(constraint)] = count - 1;

    if (count == 1) {
        Power_module->constraintsMask &= ~constraint;
    }

    Hwi_restore(key);
}
Example #5
0
Void Swi_restoreHwi(UInt swiKey)
{
    Queue_Handle curQ, maxQ;
    Swi_Object *swi;

    if (swiKey == FALSE) {
        if (Swi_module->curSet && (Core_getId() == 0)) {
            /* Remember current Swi priority */
            curQ = Swi_module->curQ;

            /* determine current highest priority Q */
            maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                        (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));

            /* Run all Swis of higher priority than the current Swi priority */
            /* Will pre-empt any currently running swi. */
            while (maxQ > curQ) {
                swi = (Swi_Object *)Queue_dequeue(maxQ);

                /* remove from curSet if last one in this ready list */
                if (Queue_empty(maxQ)) {
                    Swi_module->curSet &= ~swi->mask;
                }

                Swi_run(swi);

                if (Swi_module->curSet == 0) {
                    break;
                }
                maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                        (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));
            }
        }
        Swi_module->locked = FALSE;
    }
}
Example #6
0
/*
 *  ======== Swi_runLoop ========
 */
Void Swi_runLoop()
{
    Queue_Handle curQ, maxQ;
    Swi_Object *swi;

    /* Remember current Swi priority */
    curQ = Swi_module->curQ;

    /* refresh maxQ */
    maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) +
           (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));

    /*
     * Run all Swis of higher priority than
     * the current Swi priority.
     * Will pre-empt any currently running swi.
     */
    do {
        swi = (Swi_Object *)Queue_dequeue(maxQ);

        /* remove from curSet if last one in this ready list */
        if (Queue_empty(maxQ)) {
            Swi_module->curSet &= ~swi->mask;
        }

        Swi_run(swi);

        if (Swi_module->curSet == 0) {
            break;
        }

        maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) +
               (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));
    }
    while (maxQ > curQ);
}
Example #7
0
Void Swi_schedule()
{
    Queue_Handle curQ, maxQ;
    UInt hwiKey;
    UInt tskKey;

    /* Remember current Swi priority */
    curQ = Swi_module->curQ;

    hwiKey = Hwi_disable();     /* required for Swi's posted from Tasks */

    /* determine current highest priority Q */
    maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));

    if (maxQ > curQ) {
        if (BIOS_taskEnabled) {
            tskKey = TASK_DISABLE();  /* required for Swi's posted from Tasks */

            /* Switch stacks and call Swi_runLoop() */
            ti_sysbios_family_xxx_Hwi_switchAndRunFunc(&Swi_runLoop);
        }
        else {
            /* Call Swi_runLoop() */
            Swi_runLoop();
        }

        /* MUST(!) unlock the scheduler before enabling interrupts */
        Swi_module->locked = FALSE;

        Hwi_restore(hwiKey);

        if (BIOS_taskEnabled) {
            TASK_RESTORE(tskKey);
        }
    }
    else {
        Swi_module->locked = FALSE;

        Hwi_restore(hwiKey);
    }
}
Example #8
0
Void Swi_schedule()
{
    Queue_Handle curQ, maxQ;
    Swi_Object *swi;
    UInt hwiKey;
    UInt tskKey;
    Char *oldTaskSP;
    volatile Bool taskEnabled;

    /* Remember current Swi priority */
    curQ = Swi_module->curQ;

    hwiKey = Hwi_disable();     /* required for Swi's posted from Tasks */

    /* determine current highest priority Q */
    maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));

    if (maxQ > curQ) {

        if (BIOS_taskEnabled) {
            tskKey = TASK_DISABLE();    /* required for Swi's posted from Tasks */

            /* Switch to HWI stack if not already on it */
            oldTaskSP = ti_sysbios_family_xxx_Hwi_switchToIsrStack();

            /* must refresh local variables after stack switch */

            /* refresh curQ */
            curQ = Swi_module->curQ;

            /* refresh maxQ */
            maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                        (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));
            /* set local variable inited after stack switch */
            taskEnabled = TRUE;  
        }
        else {
            taskEnabled = FALSE;
        }

        /* 
         * Run all Swis of higher priority than 
         * the current Swi priority.
         * Will pre-empt any currently running swi. 
         */
        do {
            swi = (Swi_Object *)Queue_dequeue(maxQ);

            /* remove from curSet if last one in this ready list */
            if (Queue_empty(maxQ)) {
                Swi_module->curSet &= ~swi->mask;
            }

            Swi_run(swi);

            if (Swi_module->curSet == 0) {
                break;
            }
            
            maxQ = (Queue_Handle)((UInt8 *)(Swi_module->readyQ) + 
                        (UInt)(Intrinsics_maxbit(Swi_module->curSet)*(2*sizeof(Ptr))));
        } 
        while (maxQ > curQ);

        /* check local variable inited after stack switch */
        if (taskEnabled) {
            /* Switch back to Task stack if at bottom of HWI stack */
            ti_sysbios_family_xxx_Hwi_switchToTaskStack(oldTaskSP);
        }

        /* MUST(!) unlock the scheduler before enabling interrupts */
        Swi_module->locked = FALSE;
        
        Hwi_restore(hwiKey);

        if (BIOS_taskEnabled) {
            TASK_RESTORE(tskKey);
        }
    }
    else {
        Swi_module->locked = FALSE;

        Hwi_restore(hwiKey);
    }
}