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; } }
/* * ======== 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); }
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); } }