/* * ======== taskLoad ======== */ Void task(UArg arg1, UArg arg2) { UInt count = 1; Int status = Ipc_S_SUCCESS; UInt16 remoteProcId = MultiProc_getId("HOST"); do { status = Ipc_attach(remoteProcId); } while (status < 0); Notify_registerEvent(remoteProcId, 0, SHUTDOWN, (Notify_FnNotifyCbck)notifyCallbackFxn, 0); while (shutdownFlag == FALSE) { Semaphore_pend(sem, BIOS_WAIT_FOREVER); /* Benchmark how long it takes to flip all the bits */ Log_write1(UIABenchmark_start, (xdc_IArg)"Reverse"); reverseBits(buffer, sizeof(buffer)); Log_write1(UIABenchmark_stop, (xdc_IArg)"Reverse"); Log_print1(Diags_USER1, "count = %d", count++); } /* Start shutdown process */ Notify_unregisterEvent(remoteProcId, 0, SHUTDOWN, (Notify_FnNotifyCbck)notifyCallbackFxn, 0); do { status = Ipc_detach(remoteProcId); } while (status < 0); Ipc_stop(); }
/* * ======== ThreadSupport_runStub ======== */ Void ThreadSupport_runStub(UArg input, UArg discard) { ThreadSupport_Handle obj = (ThreadSupport_Handle)input; ti_sysbios_knl_Semaphore_Handle bios6sem; bios6sem = ThreadSupport_Instance_State_join_sem(obj); Log_write1(ThreadSupport_L_start, (IArg)obj); obj->startFxn(obj->startFxnArg); Log_write1(ThreadSupport_L_finish, (IArg)obj); Semaphore_post(bios6sem); }
/* * ======== Swi_run ======== * Set up and run Swi. * Enter with Hwi's disabled * Calls Swi function with interrupts enabled * Exits with Hwi's enabled * When no Swis are running, curQ is NULL */ Void Swi_run(Swi_Object *swi) { UInt saved_curTrigger = Swi_module->curTrigger; Swi_Object *saved_curSwi = Swi_module->curSwi; Queue_Handle saved_curQ = Swi_module->curQ; BIOS_ThreadType prevThreadType; #ifndef ti_sysbios_knl_Swi_DISABLE_ALL_HOOKS Int i; #endif Swi_module->curQ = swi->readyQ; Swi_module->curSwi = swi; Swi_module->curTrigger = swi->trigger; swi->trigger = swi->initTrigger; swi->posted = FALSE; Swi_module->locked = FALSE; /* unlock the scheduler while */ /* Swi is running */ /* set thread type to Swi */ prevThreadType = BIOS_setThreadType(BIOS_ThreadType_Swi); Hwi_enable(); #ifndef ti_sysbios_knl_Swi_DISABLE_ALL_HOOKS for (i = 0; i < Swi_hooks.length; i++) { if (Swi_hooks.elem[i].beginFxn != NULL) { Swi_hooks.elem[i].beginFxn(swi); } } #endif Log_write3(Swi_LM_begin, (UArg)swi, (UArg)swi->fxn, (UArg)prevThreadType); (swi->fxn)(swi->arg0, swi->arg1); Log_write1(Swi_LD_end, (UArg)swi); #ifndef ti_sysbios_knl_Swi_DISABLE_ALL_HOOKS for (i = 0; i < Swi_hooks.length; i++) { if (Swi_hooks.elem[i].endFxn != NULL) { Swi_hooks.elem[i].endFxn(swi); } } #endif Hwi_disable(); /* restore thread type */ BIOS_setThreadType(prevThreadType); Swi_module->locked = TRUE; /* relock the scheduler */ Swi_module->curQ = saved_curQ; Swi_module->curSwi = saved_curSwi; Swi_module->curTrigger = saved_curTrigger; }
/* * ======== ThreadSupport_join ======== */ Bool ThreadSupport_join(ThreadSupport_Handle obj, Error_Block* eb) { ti_sysbios_knl_Semaphore_Handle bios6sem; bios6sem = ThreadSupport_Instance_State_join_sem(obj); Semaphore_pend(bios6sem, BIOS_WAIT_FOREVER); Log_write1(ThreadSupport_L_join, (IArg)obj); return (TRUE); }
/* * ======== taskLoad ======== */ Void taskLoad(Void) { Bool flag; Types_Timestamp64 startTime; Types_Timestamp64 currentTime; Types_FreqHz freq; UInt32 count; Int loops; /* Have this task use ~50% of the CPU */ Timestamp_getFreq(&freq); count = freq.lo / 1000 / 1000 * (Clock_tickPeriod/ 2); while (TRUE) { Semaphore_pend(loadSem, BIOS_WAIT_FOREVER); Log_write1(UIABenchmark_start, (xdc_IArg)"running"); Timestamp_get64(&startTime); flag = TRUE; loops = 0; while (flag == TRUE) { Timestamp_get64(¤tTime); loops++; // TODO deal with wrap if (startTime.lo + count <= currentTime.lo) { flag = FALSE; Log_write1(UIABenchmark_stop, (xdc_IArg)"running"); Log_write1(UIABenchmark_stop, (xdc_IArg)"whole"); } } } }
Void interrupt Hwi_dispatchFIQC() { Hwi_Object *hwi; Int intNum; intNum = Hwi_cpIntc.HIPIR[0]; /* disable host interrupt 0 (FIQ) */ Hwi_cpIntc.HIDISR = 0; Hwi_cpIntc.SICR = intNum; /* clear interrupt */ hwi = Hwi_module->dispatchTable[intNum]; Log_write4(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)BIOS_ThreadType_Main, (IArg)intNum); (hwi->fxn)(hwi->arg); Log_write1(Hwi_LD_end, (IArg)hwi); /* enable host interrupt 0 (FIQ) */ Hwi_cpIntc.HIEISR = 0; }
/* * ======== Clock_logTick ======== */ Void Clock_logTick() { Log_write1(Clock_LM_tick, (UArg)Clock_module->ticks); }
/* * ======== Clock_workFunc ======== * Service Clock Queue for TickMode_PERIODIC */ Void Clock_workFunc(UArg arg0, UArg arg1) { Queue_Elem *elem; UInt hwiKey, count; UInt32 time, compare; Clock_Object *obj; Queue_Handle clockQ; hwiKey = Hwi_disable(); time = Clock_module->ticks; count = Clock_module->swiCount; Clock_module->swiCount = 0; Hwi_restore(hwiKey); /* Log when count > 1, meaning Clock_swi is delayed */ if (count > 1) { Log_write1(Clock_LW_delayed, (UArg)count); } compare = time - count; /* * Here count can be zero. When Clock_tick() runs it increments * swiCount and posts the Clock_workFunc. In Clock_workFunc we * get the value of swiCount atomically. Before we read swiCount, an * interrupt could occur, Clock_tick() will post the swi again. * That post is unnecessary as we are getting ready to process that * tick. The next time this swi runs the count will be zero. */ while (count) { compare = compare + 1; count = count - 1; /* Traverse clock queue */ clockQ = Clock_Module_State_clockQ(); elem = Queue_head(clockQ); while (elem != (Queue_Elem *)(clockQ)) { obj = (Clock_Object *)elem; elem = Queue_next(elem); /* if event has timed out */ if ((obj->active == TRUE) && (obj->currTimeout == compare)) { if (obj->period == 0) { /* oneshot? */ /* mark object idle */ obj->active = FALSE; } else { /* periodic */ /* refresh timeout */ obj->currTimeout += obj->period; } Log_write2(Clock_LM_begin, (UArg)obj, (UArg)obj->fxn); /* call handler */ obj->fxn(obj->arg); } } } }
/* * ======== Hwi_dispatchIRQC ======== * Configurable IRQ interrupt dispatcher. */ Void Hwi_dispatchIRQC(Hwi_Irp irp) { /* * Enough room is reserved above the isr stack to handle * as many as 16 32-bit stack resident local variables. * If the dispatcher requires more than this, you must * handle this in Hwi_Module_startup(). */ Hwi_Object *hwi; BIOS_ThreadType prevThreadType; UInt intNum; Char *oldTaskSP; Int tskKey; Int swiKey; Int i; /* save irp somewhere that survives the stack switch */ Hwi_module->irp = irp; if (Hwi_dispatcherTaskSupport) { tskKey = TASK_DISABLE(); /* * If this is a non-nested interrupt, * tskkey is saved on the task stack. * It must not be referenced again until * switching back to the task stack!!!! * All other local variables will be * on the isr stack. */ } /* * Switch to Hwi stack if not already on it. * This step, and the corresponding switch back to the task * stack are performed outside the "if (Hwi_dispatcherTaskSupport)" * conditionals because sometimes the generated code placed a copy * of Hwi_dispatcherTaskSupport on the task stack for use below. */ oldTaskSP = Hwi_switchToIsrStack(); /* * all references to local variables beyond this point * will be on the isr stack */ if (Hwi_dispatcherSwiSupport) { swiKey = SWI_DISABLE(); } /* set thread type to Hwi */ prevThreadType = BIOS_setThreadType(BIOS_ThreadType_Hwi); /* Porcess ALL pending and enabled interrupts */ do { intNum = Hwi_l1Intc.SIR_IRQ; /* get current L1 int num */ if (intNum == 0) { /* is from L2? */ intNum = Hwi_l2Intc.SIR_IRQ; /* get current L2 int num */ intNum += 32; /* force to linear index */ } hwi = Hwi_module->dispatchTable[intNum]; hwi->irp = Hwi_module->irp; #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the begin hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].beginFxn != NULL) { Hwi_hooks.elem[i].beginFxn((IHwi_Handle)hwi); } } #endif Log_write5(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)prevThreadType, (IArg)intNum, hwi->irp); (hwi->fxn)(hwi->arg); Hwi_disable(); Log_write1(Hwi_LD_end, (IArg)hwi); #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the end hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].endFxn != NULL) { Hwi_hooks.elem[i].endFxn((IHwi_Handle)hwi); } } #endif if (intNum > 31) { /* is from L2? */ Hwi_l2Intc.CONTROL = L2_NEW_IRQ_AGR;/* force NEW_IRQ_AGR */ } Hwi_l1Intc.CONTROL = L1_NEW_IRQ_AGR; /* force NEW_IRQ_AGR */ } /* loop thru all active and enabled IRQ ints */ while (Hwi_l1Intc.ITR & ~Hwi_l1Intc.MIR & Hwi_module->irq0Mask); /* Run Swi scheduler */ if (Hwi_dispatcherSwiSupport) { SWI_RESTORE(swiKey); } /* restore thread type */ BIOS_setThreadType(prevThreadType); /* * Switch back to Task stack if at bottom of Hwi stack * While it seems that this step should be placed in the * "if (Hwi_dispatcherTaskSupport)" conditional below, * some code generators placed a copy of the Hwi_dispatcherTaskSupport * constant on the task stack (see above comment), which would * make the test below bogus as it would be being performed on * on the ISR stack... */ Hwi_switchToTaskStack(oldTaskSP); /* Run Task scheduler */ if (Hwi_dispatcherTaskSupport) { /* tskKey fetched from task stack if this is a non-nested interrupt */ TASK_RESTORE(tskKey); /* returns with ints disabled */ } }
/* * ======== Hwi_dispatchIRQC ======== * Configurable IRQ interrupt dispatcher. */ Void Hwi_dispatchIRQC() { /* * Enough room is reserved above the isr stack to handle * as many as 16 32-bit stack resident local variables. * If the dispatcher requires more than this, you must * handle this in Hwi_Module_startup(). */ Hwi_Object *hwi; BIOS_ThreadType prevThreadType; Int intNum; Char *oldTaskSP; Int tskKey; Int swiKey; Int i; if (Hwi_dispatcherTaskSupport) { tskKey = TASK_DISABLE(); /* * If this is a non-nested interrupt, * tskkey is saved on the task stack. * It must not be referenced again until * switching back to the task stack!!!! * All other local variables will be * on the isr stack. */ } /* * Switch to Hwi stack if not already on it. * This step, and the corresponding switch back to the task * stack are performed outside the "if (Hwi_dispatcherTaskSupport)" * conditionals because sometimes the generated code placed a copy * of Hwi_dispatcherTaskSupport on the task stack for use below. */ oldTaskSP = Hwi_switchToIsrStack(); /* * all references to local variables beyond this point * will be on the isr stack */ if (Hwi_dispatcherSwiSupport) { swiKey = SWI_DISABLE(); } /* set thread type to Hwi */ prevThreadType = BIOS_setThreadType(BIOS_ThreadType_Hwi); /* read interrupt index */ intNum = Hwi_cpIntc.HIPIR[1]; /* disable host interrupt 1 (IRQ) */ Hwi_cpIntc.HIDISR = 1; hwi = Hwi_module->dispatchTable[intNum]; hwi->irp = Hwi_module->irp; #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the begin hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].beginFxn != NULL) { Hwi_hooks.elem[i].beginFxn((IHwi_Handle)hwi); } } #endif Log_write5(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)prevThreadType, (IArg)intNum, hwi->irp); /* call the user's isr */ if (Hwi_dispatcherAutoNestingSupport) { (hwi->handler)(hwi, intNum); } else { /* clear the interrupt status for this int */ Hwi_cpIntc.SICR = intNum; (hwi->fxn)(hwi->arg); /* re-enable IRQ */ Hwi_cpIntc.HIEISR = 1; } Log_write1(Hwi_LD_end, (IArg)hwi); #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the end hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].endFxn != NULL) { Hwi_hooks.elem[i].endFxn((IHwi_Handle)hwi); } } #endif /* Run Swi scheduler */ if (Hwi_dispatcherSwiSupport) { SWI_RESTORE(swiKey); } /* restore thread type */ BIOS_setThreadType(prevThreadType); /* * Switch back to Task stack if at bottom of Hwi stack * While it seems that this step should be placed in the * "if (Hwi_dispatcherTaskSupport)" conditional below, * some code generators placed a copy of the Hwi_dispatcherTaskSupport * constant on the task stack (see above comment), which would * make the test below bogus as it would be being performed on * on the ISR stack... */ Hwi_switchToTaskStack(oldTaskSP); /* Run Task scheduler */ if (Hwi_dispatcherTaskSupport) { /* tskKey fetched from task stack if this is a non-nested interrupt */ TASK_RESTORE(tskKey); /* returns with ints disabled */ } }
/* * ======== releaseTaskLoad ======== */ Void releaseTaskLoad(UArg arg0) { Log_write1(UIABenchmark_start, (xdc_IArg)"whole"); Semaphore_post(loadSem); }
/* * ======== Hwi_dispatchIRQC ======== * Configurable IRQ interrupt dispatcher. */ Void Hwi_dispatchIRQC(Hwi_Irp irp) { /* * Enough room is reserved above the isr stack to handle * as many as 16 32-bit stack resident local variables. * This space is reserved for the Swi scheduler. * * If the swi scheduler requires more than this, you must * handle this in Hwi_Module_startup(). */ Hwi_Object *hwi; BIOS_ThreadType prevThreadType; UInt intNum; Int swiKey; Int i; /* save irp for ROV call stack view */ Hwi_module->irp = irp; if (Hwi_dispatcherSwiSupport) { swiKey = SWI_DISABLE(); } /* set thread type to Hwi */ prevThreadType = BIOS_setThreadType(BIOS_ThreadType_Hwi); /* Porcess ALL pending and enabled interrupts */ do { intNum = Hwi_l1Intc.SIR_IRQ; /* get current L1 int num */ if (intNum == 0) { /* is from L2? */ intNum = Hwi_l2Intc.SIR_IRQ; /* get current L2 int num */ intNum += 32; /* force to linear index */ } hwi = Hwi_module->dispatchTable[intNum]; hwi->irp = Hwi_module->irp; #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the begin hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].beginFxn != NULL) { Hwi_hooks.elem[i].beginFxn((IHwi_Handle)hwi); } } #endif Log_write5(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)prevThreadType, (IArg)intNum, hwi->irp); (hwi->fxn)(hwi->arg); Hwi_disable(); Log_write1(Hwi_LD_end, (IArg)hwi); #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the end hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].endFxn != NULL) { Hwi_hooks.elem[i].endFxn((IHwi_Handle)hwi); } } #endif if (intNum > 31) { /* is from L2? */ Hwi_l2Intc.CONTROL = L2_NEW_IRQ_AGR;/* force NEW_IRQ_AGR */ } Hwi_l1Intc.CONTROL = L1_NEW_IRQ_AGR; /* force NEW_IRQ_AGR */ } /* loop thru all active and enabled IRQ ints */ while (Hwi_l1Intc.ITR & ~Hwi_l1Intc.MIR & Hwi_module->irq0Mask); /* Run Swi scheduler */ if (Hwi_dispatcherSwiSupport) { SWI_RESTORE(swiKey); } /* restore thread type */ BIOS_setThreadType(prevThreadType); }
/* * ======== Hwi_dispatchCore ======== * Configurable dispatcher. */ Void Hwi_dispatchCore(Int intNum) { /* * Enough room is reserved above the isr stack to handle * as many as 16 32-bit stack resident local variables. * If the dispatcher requires more than this, you must * handle this in Hwi_Module_startup(). */ Hwi_Object *hwi; BIOS_ThreadType prevThreadType; UInt16 oldIER, disableMask, restoreMask; Int swiKey; Int i; Hwi_FuncPtr fxn; UArg arg; /* save away intNum in module state because it might be saved on stack */ Hwi_module->intNum = intNum; /* * pre-read local copies of the variables used * within to eliminate memory fetch nops */ hwi = Hwi_module->dispatchTable[intNum]; fxn = hwi->fxn; arg = hwi->arg; if (Hwi_dispatcherIrpTrackingSupport) { hwi->irp = IRP; } if (Hwi_dispatcherAutoNestingSupport) { disableMask = hwi->disableMask; restoreMask = hwi->restoreMask; } if (Hwi_dispatcherSwiSupport) { swiKey = SWI_DISABLE(); } /* set thread type to Hwi */ prevThreadType = BIOS_setThreadType(BIOS_ThreadType_Hwi); #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the begin hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].beginFxn != NULL) { Hwi_hooks.elem[i].beginFxn((IHwi_Handle)hwi); } } #endif Log_write5(Hwi_LM_begin, (IArg)hwi, (IArg)hwi->fxn, (IArg)prevThreadType, (IArg)intNum, hwi->irp); /* call the user's isr */ if (Hwi_dispatcherAutoNestingSupport) { oldIER = IER; IER &= ~disableMask; _enable_interrupts(); (fxn)(arg); _disable_interrupts(); IER |= (restoreMask & oldIER); } else { (fxn)(arg); } Log_write1(Hwi_LD_end, (IArg)hwi); #ifndef ti_sysbios_hal_Hwi_DISABLE_ALL_HOOKS /* call the end hooks */ for (i = 0; i < Hwi_hooks.length; i++) { if (Hwi_hooks.elem[i].endFxn != NULL) { Hwi_hooks.elem[i].endFxn((IHwi_Handle)hwi); } } #endif /* Run Swi scheduler */ if (Hwi_dispatcherSwiSupport) { SWI_RESTORE(swiKey); } /* restore thread type */ BIOS_setThreadType(prevThreadType); }