/* * ======== Watchdog_init ======== */ Void Watchdog_init( Void (*timerFxn)(Void) ) { Hwi_Params hwiParams; UInt key; Timer_Handle tHandle; Types_FreqHz tFreq; Watchdog_TimerRegs *timer; Int i; tHandle = Timer_Object_get(NULL, 0); Timer_getFreq(tHandle, &tFreq); /* get timer frequency */ for (i = 0; i < Watchdog_module->wdtCores; i++) { /* loop for SMP cores */ timer = (Watchdog_TimerRegs *) Watchdog_module->device[i].baseAddr; /* Check if timer is enabled by host-side */ if ((REG32(Watchdog_module->device[i].clkCtrl) & WATCHDOG_WDT_CLKCTRL_IDLEST_MASK) == WATCHDOG_WDT_CLKCTRL_IDLEST_MASK) { System_printf("Watchdog disabled: TimerBase = 0x%x ClkCtrl = 0x%x\n", timer, Watchdog_module->device[i].clkCtrl); continue; /* for next core */ } /* Configure the timer */ initTimer(timer, TRUE); /* Enable interrupt in BIOS */ Hwi_Params_init(&hwiParams); hwiParams.priority = 1; hwiParams.eventId = Watchdog_module->device[i].eventId; hwiParams.maskSetting = Hwi_MaskingOption_LOWER; key = Hwi_disable(); Hwi_create(Watchdog_module->device[i].intNum, (Hwi_FuncPtr) timerFxn, &hwiParams, NULL); Hwi_enableInterrupt(Watchdog_module->device[i].intNum); Hwi_restore(key); /* Enable timer */ while (timer->twps & WATCHDOG_TIMER_TWPS_W_PEND_TCLR); timer->tclr |= 1; Watchdog_module->status[i] = Watchdog_Mode_ENABLED; #ifdef SMP System_printf("Watchdog enabled: TimerBase = 0x%x SMP-Core = %d " "Freq = %d\n", timer, i, tFreq.lo); #else System_printf("Watchdog enabled: TimerBase = 0x%x Freq = %d\n", timer, tFreq.lo); #endif } /* Register callback function */ if (!IpcPower_registerCallback(IpcPower_Event_RESUME, Watchdog_restore, NULL)) { System_printf("Watchdog_restore registered as a resume callback\n"); } return; }
/* * ======== switchToWatchdogTimer ======== * * Use 250ms watchdog timer interrupt to drive the Clock tick * Stop the default Timer_A then start the watchdog timer. */ static void switchToWatchdogTimer() { Clock_TimerProxy_Handle clockTimer; static Hwi_Handle wdtHwi = NULL; /* Stop Timer_A currrently being used by Clock */ clockTimer = Clock_getTimerHandle(); Clock_TimerProxy_stop(clockTimer); MAP_WDT_A_holdTimer(); if (wdtHwi == NULL) { /* Create watchdog Timer Hwi */ wdtHwi = Hwi_create(19, clockTickFxn, NULL, NULL); /* set WDT to use 32KHz input, 250ms period */ MAP_WDT_A_initIntervalTimer(WDT_A_CLOCKSOURCE_XCLK, WDT_A_CLOCKITERATIONS_8192); } /* don't allow deeper than DEEPSLEEP1 */ Power_setConstraint(PowerMSP432_DISALLOW_DEEPSLEEP_1); /* Start watchdog Timer */ MAP_WDT_A_clearTimer(); MAP_WDT_A_startTimer(); /* hence, Clock_tick() will be called from 250ms watchdog timer interrupt */ }
/*! * ======== InterruptArm_intRegister ======== * Register ISR for remote processor interrupt */ Void InterruptArm_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { Hwi_Params hwiAttrs; UInt key; Assert_isTrue(intInfo->localIntId == DSP2ARM_CHIPINT0 || intInfo->localIntId == DSP2ARM_CHIPINT1, ti_sdo_ipc_Ipc_A_internal); Assert_isTrue(intInfo->remoteIntId == ARM2DSP_CHIPINT2 || intInfo->remoteIntId == ARM2DSP_CHIPINT3, ti_sdo_ipc_Ipc_A_internal); /* Disable global interrupts */ key = Hwi_disable(); /* Register interrupt for communication between ARM and DSP */ Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_SELF; hwiAttrs.arg = arg; InterruptArm_intClear(remoteProcId, intInfo); Hwi_create(intInfo->localIntId, (Hwi_FuncPtr)func, &hwiAttrs, NULL); /* Restore global interrupts */ Hwi_restore(key); Hwi_enableInterrupt(intInfo->localIntId); }
/*! * ======== InterruptHost_intRegister ======== */ Void InterruptHost_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Hwi_Params hwiAttrs; /* Make sure that we're trying to talk to the HOST */ Assert_isTrue(remoteProcId == MultiProc_getId("DSP"), ti_sdo_ipc_Ipc_A_invArgument); /* Disable global interrupts */ key = Hwi_disable(); InterruptHost_intClear(remoteProcId, intInfo); /* Register interrupt for communication between ARM and DSP */ Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_SELF; hwiAttrs.arg = arg; Hwi_create(HOSTINT, (Hwi_FuncPtr)func, &hwiAttrs, NULL); /* Enable the mailbox interrupt to the DSP */ REG32(MAILBOX_IRQENABLE_GPP) = 0x4; /* Mailbox 0 */ /* Restore global interrupts */ Hwi_restore(key); /* Unmask IVA_2_IRQ[10] to allow interrupt to come into DSP */ Hwi_enableInterrupt(HOSTINT); }
/*! * ======== InterruptDsp_intRegister ======== */ Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Int index; InterruptDsp_FxnTable *table; Hwi_Params hwiParams; /* Ensure that our ID is set correctly */ Assert_isTrue(InterruptDsp_dspProcId == MultiProc_self(), ti_sdo_ipc_Ipc_A_internal); /* Ensure that remoteProcId is valid */ Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_Ipc_A_invArgument); /* Ensure that proper intVectorId has been supplied */ Assert_isTrue(intInfo->intVectorId <= 15, ti_sdo_ipc_Ipc_A_internal); if (remoteProcId == InterruptDsp_hostProcId) { index = 0; } else if (remoteProcId == InterruptDsp_core0ProcId) { index = 1; } else { /* DSP cannot talk to CORE1 */ Assert_isTrue(FALSE, ti_sdo_ipc_Ipc_A_internal); } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDsp_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptDsp_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ InterruptDsp_module->numPlugged++; if (InterruptDsp_module->numPlugged == 1) { Hwi_Params_init(&hwiParams); hwiParams.eventId = DSPINT; Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)InterruptDsp_intShmStub, &hwiParams, NULL); /* Enable the interrupt */ Wugen_enableEvent(DSPINT); Hwi_enableInterrupt(intInfo->intVectorId); } /* Enable the mailbox interrupt to the DSP */ InterruptDsp_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== USBCDCD_init ======== */ void USBCDCD_init(void) { Hwi_Handle hwi; Error_Block eb; Error_init(&eb); /* Install interrupt handler */ hwi = Hwi_create(INT_USB0, USBCDCD_LoggerIdle_hwiHandler, NULL, &eb); if (hwi == NULL) { System_abort("Can't create USB Hwi"); } /* State specific variables */ state = USBCDCD_STATE_UNCONFIGURED; /* Set the USB stack mode to Device mode with VBUS monitoring */ USBStackModeSet(0, eUSBModeForceDevice, 0); /* Initialize the transmit buffer */ USBBufferInit(&txBuffer); /* * Pass our device information to the USB HID device class driver, * initialize the USB controller and connect the device to the bus. */ if (!USBDCDCInit(0, &serialDevice)) { System_abort("Error initializing the serial device"); } }
void interrupt_register() { hprpc_irq_handler_init(); /* Clear MSI0 interrupt */ *((unsigned int *)MSI0_IRQ_STATUS) = 0x1; *((unsigned int *)TI667X_IRQ_EOI) = 0x4; /* end of MSI0, event number=4 */ Hwi_Params_init(&hwiParams); /* set the argument you want passed to your ISR function */ hwiParams.arg = (Int32)&hwiParams; /* set the event id of the peripheral assigned to this interrupt */ hwiParams.eventId = 17; /* for MSI interrupt */ /* Enable the Hwi */ hwiParams.enableInt = TRUE; /* don't allow this interrupt to nest itself */ hwiParams.maskSetting = Hwi_MaskingOption_SELF; /* Configure interrupt 4 to invoke the hprpc_irq_handler. */ /* Automatically enables interrupt 4 by default */ /* set params.enableInt = FALSE if you want to control */ /* when the interrupt is enabled using Hwi_enableInterrupt() */ Hwi_create(INTC_VECTID, hprpc_irq_handler, &hwiParams, NULL); }
/*! * ======== InterruptDsp_intRegister ======== */ Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; UInt eventId; UInt combinedEventId; Int index; Hwi_Params params; InterruptDsp_FxnTable *table; Assert_isTrue(((remoteProcId < MultiProc_getNumProcsInCluster()) && (remoteProcId != MultiProc_self())), ti_sdo_ipc_Ipc_A_internal); index = PROCID(remoteProcId); /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDsp_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptDsp_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ eventId = InterruptDsp_dspInterruptTable[index]; InterruptDsp_module->numPlugged++; if (InterruptDsp_module->numPlugged == 1) { EventCombiner_dispatchPlug(eventId, (Hwi_FuncPtr)InterruptDsp_intShmStub, eventId, TRUE); Hwi_Params_init(¶ms); combinedEventId = eventId / EVENT_GROUP_SIZE; params.eventId = combinedEventId; params.arg = combinedEventId; params.enableInt = TRUE; Hwi_create(intInfo->intVectorId, &ti_sysbios_family_c64p_EventCombiner_dispatch, ¶ms, NULL); Hwi_enableInterrupt(intInfo->intVectorId); } else { EventCombiner_dispatchPlug(eventId, (Hwi_FuncPtr)InterruptDsp_intShmStub, eventId, TRUE); } /* Enable the mailbox interrupt to the DSP */ InterruptDsp_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== USBKBD_init ======== */ void USBKBD_init(void) { Hwi_Handle hwi; Error_Block eb; Semaphore_Params semParams; Error_init(&eb); /* Install interrupt handler */ hwi = Hwi_create(INT_USB0, USBKBD_hwiHandler, NULL, &eb); if (hwi == NULL) { System_abort("Can't create USB Hwi"); } /* RTOS primitives */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; semKeyboard = Semaphore_create(0, &semParams, &eb); if (semKeyboard == NULL) { System_abort("Can't create keyboard semaphore"); } semUSBConnected = Semaphore_create(0, &semParams, &eb); if (semUSBConnected == NULL) { System_abort("Can't create USB semaphore"); } gateKeyboard = GateMutex_create(NULL, &eb); if (gateKeyboard == NULL) { System_abort("Can't create keyboard gate"); } gateUSBWait = GateMutex_create(NULL, &eb); if (gateUSBWait == NULL) { System_abort("Could not create USB Wait gate"); } /* State specific variables */ state = USBKBD_STATE_UNCONFIGURED; kbLEDs = 0x00; /* Set the USB stack mode to Device mode with VBUS monitoring */ USBStackModeSet(0, eUSBModeForceDevice, 0); /* * Pass our device information to the USB HID device class driver, * initialize the USB controller and connect the device to the bus. */ if (!USBDHIDKeyboardInit(0, &keyboardDevice)) { System_abort("Error initializing the keyboard"); } }
/*! * ======== InterruptBenelli_intRegister ======== */ Void InterruptBenelli_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { Hwi_Params hwiAttrs; UInt key; UInt mbxIdx; Int index; InterruptBenelli_FxnTable *table; Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_Ipc_A_internal); /* Assert that our MultiProc id is set correctly */ Assert_isTrue((InterruptBenelli_benelliProcId == MultiProc_self()), ti_sdo_ipc_Ipc_A_internal); mbxIdx = MBX_BASEADDR_IDX(MBX_TABLE_IDX(remoteProcId, MultiProc_self())); index = PROCID(remoteProcId); intInfo->localIntId = InterruptBenelli_benelliInterruptTable[index]; /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptBenelli_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptBenelli_intClear(remoteProcId, intInfo); Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_LOWER; /* Make sure the interrupt only gets plugged once */ InterruptBenelli_module->numPlugged[mbxIdx]++; if (InterruptBenelli_module->numPlugged[mbxIdx] == 1) { Hwi_create(intInfo->localIntId, (Hwi_FuncPtr)InterruptBenelli_intShmMbxStub, &hwiAttrs, NULL); /* Interrupt_intEnable won't enable the Hwi */ Hwi_enableInterrupt(intInfo->localIntId); } InterruptBenelli_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/*! * ======== InterruptDsp_intRegister ======== */ Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Int index; InterruptDsp_FxnTable *table; Assert_isTrue(intInfo->intVectorId <= 15, ti_sdo_ipc_Ipc_A_internal); if (remoteProcId == InterruptDsp_hostProcId) { index = 0; } else if (remoteProcId == InterruptDsp_videoProcId) { index = 1; } else if (remoteProcId == InterruptDsp_vpssProcId) { index = 2; } else { Assert_isTrue(FALSE, ti_sdo_ipc_Ipc_A_internal); return; /* keep Coverity happy */ } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDsp_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptDsp_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ InterruptDsp_module->numPlugged++; if (InterruptDsp_module->numPlugged == 1) { /* Map the interrupt number to HWI vector */ Hwi_eventMap(intInfo->intVectorId, DSPINT); Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)InterruptDsp_intShmStub, NULL, NULL); Hwi_enableInterrupt(intInfo->intVectorId); } /* Enable the mailbox interrupt to the DSP */ InterruptDsp_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/*! * ======== InterruptM3_intRegister ======== */ Void InterruptM3_intRegister(Hwi_FuncPtr fxn) { Hwi_Params hwiAttrs; UInt key; hostProcId = MultiProc_getId("HOST"); dspProcId = MultiProc_getId("DSP"); sysm3ProcId = MultiProc_getId("CORE0"); appm3ProcId = MultiProc_getId("CORE1"); /* Disable global interrupts */ key = Hwi_disable(); userFxn = fxn; Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_LOWER; if (Core_getId() == 0) { Hwi_create(M3INT_MBX, (Hwi_FuncPtr)InterruptM3_isr, &hwiAttrs, NULL); /* InterruptM3_intEnable won't enable the Hwi */ Hwi_enableInterrupt(M3INT_MBX); } else { Hwi_create(M3INT, (Hwi_FuncPtr)InterruptM3_isr, &hwiAttrs, NULL); } /* Enable the mailbox interrupt to the M3 core */ InterruptM3_intEnable(); /* Restore global interrupts */ Hwi_restore(key); }
/*! * ======== InterruptArp32_intRegister ======== */ Void InterruptArp32_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Hwi_Params hwiAttrs; Error_Block eb; InterruptArp32_FxnTable *table; Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_Ipc_A_internal); /* Assert that our MultiProc id is set correctly */ Assert_isTrue((InterruptArp32_arp32ProcId == MultiProc_self()), ti_sdo_ipc_Ipc_A_internal); /* init error block */ Error_init(&eb); /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptArp32_module->fxnTable); table->func = func; table->arg = arg; InterruptArp32_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ InterruptArp32_module->numPlugged++; if (InterruptArp32_module->numPlugged == 1) { /* Register interrupt to remote processor */ Hwi_Params_init(&hwiAttrs); hwiAttrs.arg = arg; hwiAttrs.vectorNum = intInfo->intVectorId; Hwi_create(ARP32INT, (Hwi_FuncPtr)InterruptArp32_intShmStub, &hwiAttrs, &eb); } /* enable the mailbox and Hwi */ InterruptArp32_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/*! * ======== InterruptDsp_intRegister ======== */ Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Hwi_Params hwiAttrs; Error_Block eb; InterruptDsp_FxnTable *table; Assert_isTrue(intInfo->intVectorId <= 15, ti_sdo_ipc_Ipc_A_internal); /* init error block */ Error_init(&eb); /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDsp_module->fxnTable); table->func = func; table->arg = arg; InterruptDsp_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ InterruptDsp_module->numPlugged++; if (InterruptDsp_module->numPlugged == 1) { /* Register interrupt to remote processor */ Hwi_Params_init(&hwiAttrs); hwiAttrs.arg = arg; hwiAttrs.eventId = 90; Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)InterruptDsp_intShmStub, &hwiAttrs, &eb); /* enable the interrupt vector */ Hwi_enableInterrupt(intInfo->intVectorId); } /* Enable the mailbox interrupt to the DSP */ InterruptDsp_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== Pmu_setInterruptFunc ======== */ Void Pmu_setInterruptFunc(Pmu_IntHandlerFuncPtr interruptFunc) { Hwi_Params hwiParams; /* Set new interruptFunc */ Pmu_module->interruptFunc = interruptFunc; /* * If interruptFunc is not null and a Hwi has not already been * created, create one. */ if (interruptFunc && (!(Pmu_module->hwiHandle))) { Assert_isTrue(Pmu_intNum != (~0), Pmu_A_badIntNum); Hwi_Params_init(&hwiParams); Pmu_module->hwiHandle = Hwi_create(Pmu_intNum, Pmu_interruptHandler, &hwiParams, NULL); } }
/* * ======== EKS_LM4F232_initDMA ======== */ Void EKS_LM4F232_initDMA(Void) { if(DMA_count == -1) { Hwi_Params hwiParams; Hwi_Handle hwi; Hwi_Params_init(&hwiParams); hwi = Hwi_create(INT_UDMAERR, EKS_LM4F232_errorDMAHwi, &hwiParams, NULL); if (!hwi) { System_abort("Couldn't create DMA error hwi"); } SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); uDMAEnable(); uDMAControlBaseSet(EKS_LM4F232_DMAControlTable); DMA_count++; } }
/** * /fn InitializeLedUserSwitch * /brief Initialize led D1 und USR SW1. * /return void. */ static void InitializeLedUserSwitch() { uint32_t strength; uint32_t pinType; Hwi_Params buttonHWIParams; Hwi_Handle buttonHwi; Error_Block eb; // enable port N SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // LED2 GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); /* set pin gpio port to output */ GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1); /*configure pad as standard pin with default output current*/ GPIOPadConfigGet(GPIO_PORTN_BASE, GPIO_PIN_1, &strength, &pinType); GPIOPadConfigSet(GPIO_PORTN_BASE, GPIO_PIN_1, strength, GPIO_PIN_TYPE_STD); /* turn off led 1 */ GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0); /* configure switch 1 with pull up as input on GPIO_PIN_0 as pull-up pin */ GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0); GPIOPadConfigGet(GPIO_PORTJ_BASE, GPIO_PIN_0, &strength, &pinType); GPIOPadConfigSet(GPIO_PORTJ_BASE, GPIO_PIN_0, strength, GPIO_PIN_TYPE_STD_WPU); Error_init(&eb); Hwi_Params_init(&buttonHWIParams); buttonHWIParams.arg = 0; buttonHWIParams.enableInt = false; buttonHwi = Hwi_create(INT_GPIOJ_TM4C129, ButtonFunction, &buttonHWIParams, &eb); if (buttonHwi == NULL) { System_abort("Button Hardware interrupt create failed."); } Hwi_enableInterrupt(INT_GPIOJ_TM4C129); GPIOIntEnable(GPIO_PORTJ_BASE, GPIO_INT_PIN_0); }
/* * ======== HWI_dispatchPlug ======== * Plug the HWI dispatcher table. */ Void HWI_dispatchPlug(Int vecid, Fxn fxn, HWI_Attrs *attrs) { Hwi_Params hwiParams; Hwi_Handle hwi; Error_Block eb; if (attrs == NULL) { attrs = &HWI_ATTRS; } Hwi_Params_init(&hwiParams); Error_init(&eb); if (attrs->ierMask == 1) { hwiParams.maskSetting = Hwi_MaskingOption_SELF; } else { hwiParams.maskSetting = Hwi_MaskingOption_BITMASK; } hwiParams.disableMask = hwiParams.restoreMask = attrs->ierMask; hwiParams.arg = attrs->arg; hwiParams.enableInt = FALSE; /* * Tell the BIOS6 dispatcher not to ACK interrupts because the BIOS5 * dispatcher doesn't ACK interrupts */ hwiParams.enableAck = FALSE; hwi = Hwi_getHandle(vecid); if (hwi == NULL) { Hwi_create(vecid, (Hwi_FuncPtr)fxn, &hwiParams, &eb); } else { Hwi_reconfig(hwi, (Hwi_FuncPtr)fxn, &hwiParams); } }
/* * ======== Interrupt_intRegister ======== * Register ISR for remote processor interrupt */ Void Interrupt_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { Hwi_Params hwiAttrs; Interrupt_FxnTable *table; UInt pos; Assert_isTrue(intInfo != NULL, NULL); pos = MAP_RPROCID_TO_SRCC(remoteProcId, intInfo->localIntId); Log_print2(Diags_USER1, "Interrupt_intRegister: pos: %d, func: 0x%x\n", (IArg)pos, (IArg)func); /* setup the function table with client function and arg to call: */ table = &(Interrupt_module->fxnTable[pos]); table->func = func; table->arg = arg; /* Make sure the interrupt only gets plugged once */ Interrupt_module->numPlugged++; if (Interrupt_module->numPlugged == 1) { /* Clear all pending interrupts */ Interrupt_intClearAll(); /* Register interrupt to remote processor */ Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_SELF; hwiAttrs.arg = arg; hwiAttrs.eventId = Interrupt_INTERDSPINT; Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)Interrupt_isr, &hwiAttrs, NULL); Hwi_enableInterrupt(intInfo->intVectorId); } }
BOOL Intr_Init(Intr *pThis, IntrItem eIntrItem, Intr_Handler pfnIntr_Handler, VOID *pIntrHandlerArg) //(*pIntr_Handler)(void *),\ { //CSL_Status intStat; //guru:may be not required for C6678 #if 1 //Initialize Global interrupts //Intr_EnableGlobalInterrupts(); Hwi_enable(); #endif //Initialize Global interrupts //CSL_intcGlobalEnable(NULL); //Get the values from Interrupt Table DataBase IntrDB_GetIntrTableParam(&pThis->oIntrTableParam, eIntrItem); Hwi_Params_init(&pThis->oHwi); Error_init(&pThis->eb); //Check whether the Interrupt source uses CIC Module if(pThis->oIntrTableParam.bCicRequired == TRUE) { /* Map the System Interrupt i.e. the Interrupt Destination 0 interrupt to the DIO ISR Handler. */ CpIntc_dispatchPlug(pThis->oIntrTableParam.SysInt,(ti_sysbios_family_c66_tci66xx_CpIntc_FuncPtr) pfnIntr_Handler, (xdc_UArg)pIntrHandlerArg, FALSE); /* The configuration is for CPINTC0. We map system interrupt 112 to Host Interrupt 8. */ CpIntc_mapSysIntToHostInt(0,pThis->oIntrTableParam.SysInt,pThis->oIntrTableParam.HostInt ); /* Get the event id associated with the host interrupt. */ pThis->oHwi.eventId = CpIntc_getEventId(pThis->oIntrTableParam.HostInt); pThis->oHwi.arg = pThis->oIntrTableParam.HostInt; pThis->oHwi.maskSetting = Hwi_MaskingOption_NONE; //pThis->oHwi.priority = 3; pThis->oHwiHandle = Hwi_create((Int)pThis->oIntrTableParam.eIntcVectorId, (Hwi_FuncPtr)CpIntc_dispatch, &pThis->oHwi, &pThis->eb);// SYSBIOS API if(pThis->oHwiHandle==NULL) { #ifdef DEBUG LOG_TRACE0("INTR: Hwi not created ... Failed.\n"); #endif } } else { pThis->oHwi.eventId=pThis->oIntrTableParam.nIntcEventId; pThis->oHwi.maskSetting = Hwi_MaskingOption_NONE; //pThis->oHwi.priority = 3; //register the argument to be passed with the ISR pThis->oHwi.arg = (UArg)pIntrHandlerArg; pThis->oHwiHandle = Hwi_create((Int)pThis->oIntrTableParam.eIntcVectorId, (Hwi_FuncPtr)pfnIntr_Handler, &pThis->oHwi, &pThis->eb);// SYSBIOS API if(pThis->oHwiHandle==NULL) { #ifdef DEBUG LOG_TRACE0("INTR: Hwi not created ... Failed.\n"); #endif } } #ifdef _STE_APP //Initialize the oHwi object #endif #ifdef _STE_BOOT //Csl APIs or Hooking the Interrupt Event pThis->oIntcHandle = CSL_intcOpen (&pThis->oIntcObj, pThis->oIntrTableParam.nIntcEventId, &pThis->oIntrTableParam.eIntcVectorId, NULL); if ((pThis->oIntcHandle == NULL)) { #ifdef DEBUG printf ("INTR: Open... Failed.\n"); printf ("hIntc = 0x%x]\n", pThis->oIntcHandle); #endif } else { #ifdef DEBUG printf ("INTR: Open... Passed.\n"); #endif } pThis->oEventRecord.handler = (CSL_IntcEventHandler)pfnIntr_Handler; pThis->oEventRecord.arg = pIntrHandlerArg; CSL_intcPlugEventHandler(pThis->oIntcHandle, &pThis->oEventRecord); #endif return TRUE; }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; /* make sure id is not greater than number of 32-bit timer devices */ if (id >= Timer_numTimerDevices ) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_numTimerDevices; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } Timer_module->handles[obj->id] = obj; /* initialize the timer state object */ Timer_initObj(obj, tickFxn, params); /* create the Hwi object if function is specified */ if (obj->tickFxn != NULL) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, params->hwiParams); } else { Hwi_Params_init(&hwiParams); } hwiParams.eventId = Timer_module->device[obj->id].eventId; hwiParams.arg = (UArg)obj; obj->hwi = Hwi_create(obj->intNum, Timer_stub, &hwiParams, eb); if (obj->hwi == NULL) { return (4); } } else { obj->hwi = NULL; } status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== InterruptHost_intRegister ======== */ Void InterruptHost_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Int index; Error_Block eb; InterruptHost_FxnTable *table; /* init error block */ Error_init(&eb); if (remoteProcId == InterruptHost_dspProcId) { index = 0; } else if (remoteProcId == InterruptHost_videoProcId) { index = 1; } else if (remoteProcId == InterruptHost_vpssProcId) { index = 2; } else if (remoteProcId == InterruptHost_eveProcId) { index = 3; } else { Assert_isTrue(FALSE, ti_sdo_ipc_Ipc_A_internal); return; /* should never get here, but keep Coverity happy */ } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptHost_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptHost_intClear(remoteProcId, intInfo); if (remoteProcId == InterruptHost_eveProcId) { /* Register interrupt for eve mailbox */ Hwi_create(EVE_MAILBOX_HOSTINT, (Hwi_FuncPtr)InterruptHost_intEveShmStub, NULL, &eb); Hwi_enableInterrupt(EVE_MAILBOX_HOSTINT); } else { /* Make sure the interrupt only gets plugged once */ InterruptHost_module->numPlugged++; if (InterruptHost_module->numPlugged == 1) { /* Register interrupt for system mailbox */ Hwi_create(MAILBOX_HOSTINT, (Hwi_FuncPtr)InterruptHost_intShmStub, NULL, &eb); Hwi_enableInterrupt(MAILBOX_HOSTINT); } } /* Enable the mailbox interrupt to the HOST core */ InterruptHost_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/*! * ======== InterruptDucati_intRegister ======== */ Void InterruptDucati_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { Hwi_Params hwiAttrs; UInt key; Int index; InterruptDucati_FxnTable *table; Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_Ipc_A_internal); /* Assert that our MultiProc id is set correctly */ Assert_isTrue((InterruptDucati_videoProcId == MultiProc_self()) || (InterruptDucati_vpssProcId == MultiProc_self()), ti_sdo_ipc_Ipc_A_internal); /* * VPSS-M3 & VIDEO-M3 each have a unique interrupt ID for receiving * interrupts external to the Ducati subsystem. (M3DSSINT & M3VIDEOINT). * However, they have a separate interrupt ID for receving interrupt from * each other(M3INT). * * Store the interrupt id in the intInfo so it can be used during * intUnregiseter. */ if (remoteProcId == InterruptDucati_dspProcId) { index = 0; if ((BIOS_smpEnabled) || (Core_getId() == 0)) { intInfo->localIntId = M3VIDEOINT; } else { intInfo->localIntId = M3DSSINT; } } else if (remoteProcId == InterruptDucati_hostProcId) { index = 1; if ((BIOS_smpEnabled) || (Core_getId() == 0)) { intInfo->localIntId = M3VIDEOINT; } else { intInfo->localIntId = M3DSSINT; } } else { /* Going to the other M3 */ index = 2; intInfo->localIntId = M3INT; } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDucati_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptDucati_intClear(remoteProcId, intInfo); Hwi_Params_init(&hwiAttrs); hwiAttrs.maskSetting = Hwi_MaskingOption_LOWER; /* Make sure the interrupt only gets plugged once */ if (remoteProcId == InterruptDucati_videoProcId || remoteProcId == InterruptDucati_vpssProcId) { Hwi_create(intInfo->localIntId, (Hwi_FuncPtr)InterruptDucati_intShmDucatiStub, &hwiAttrs, NULL); } else { InterruptDucati_module->numPlugged++; if (InterruptDucati_module->numPlugged == 1) { Hwi_create(intInfo->localIntId, (Hwi_FuncPtr)InterruptDucati_intShmMbxStub, &hwiAttrs, NULL); /* Interrupt_intEnable won't enable the Hwi */ Hwi_enableInterrupt(intInfo->localIntId); } } InterruptDucati_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt arBit; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } Timer_module->handles[obj->id] = obj; /* determine controlReg 'ar' value (continuous / oneshot) */ arBit = (params->runMode == Timer_RunMode_CONTINUOUS) ? 1 : 0; obj->controlRegInit = ((arBit << 1) | (params->controlRegInit.ptv << 2) | (params->controlRegInit.ce << 5) | (params->controlRegInit.free << 6)); obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->arg = params->arg; obj->intNum = intNumDef[obj->id]; obj->tickFxn = tickFxn; /* extFreq.hi is ignored */ if (params->extFreq.lo) { obj->extFreq.lo = params->extFreq.lo; } if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_numTimerDevices) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_numTimerDevices; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } obj->runMode = params->runMode; obj->startMode = params->startMode; if (params->altclk && !Timer_supportsAltclk) { Error_raise(eb, Timer_E_noaltclk, id, 0); return (1); } obj->altclk = params->altclk; obj->period = params->period; obj->periodType = params->periodType; if (obj->altclk) { /* if using altclk the freq is always 16MHz */ obj->extFreq.lo = 16000000; obj->extFreq.hi = 0; } else { /* else use specified extFreq */ obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; } obj->arg = params->arg; obj->intNum = Timer_module->device[obj->id].intNum; obj->tickFxn = tickFxn; obj->prevThreshold = params->prevThreshold; obj->rollovers = 0; obj->savedCurrCount = 0; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = (UArg)obj; obj->hwi = Hwi_create (obj->intNum, Timer_isrStub, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; /* enable and reset the timer */ Timer_enableFunc(obj->id); Timer_initDevice(obj); if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== InterruptDsp_intRegister ======== */ Void InterruptDsp_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Int index; Hwi_Params hwiAttrs; Error_Block eb; InterruptDsp_FxnTable *table; Assert_isTrue(intInfo->intVectorId <= 15, ti_sdo_ipc_Ipc_A_internal); /* init error block */ Error_init(&eb); if (remoteProcId == InterruptDsp_hostProcId) { index = 0; } else if (remoteProcId == InterruptDsp_videoProcId) { index = 1; } else if (remoteProcId == InterruptDsp_vpssProcId) { index = 2; } else if (remoteProcId == InterruptDsp_eveProcId) { index = 3; } else { Assert_isTrue(FALSE, ti_sdo_ipc_Ipc_A_internal); return; /* keep Coverity happy */ } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptDsp_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptDsp_intClear(remoteProcId, intInfo); if (remoteProcId == InterruptDsp_eveProcId) { /* This should be called only once */ /* Register interrupt for eve internal mailbox */ Hwi_Params_init(&hwiAttrs); hwiAttrs.arg = arg; hwiAttrs.eventId = EVE_MAILBOX_DSPINT; Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)InterruptDsp_intEveShmStub, &hwiAttrs, &eb); Hwi_enableInterrupt(intInfo->intVectorId); } else { /* Make sure the interrupt only gets plugged once */ InterruptDsp_module->numPlugged++; if (InterruptDsp_module->numPlugged == 1) { /* Register interrupt for system mailbox */ Hwi_Params_init(&hwiAttrs); hwiAttrs.arg = arg; hwiAttrs.eventId = MAILBOX_DSPINT; Hwi_create(intInfo->intVectorId, (Hwi_FuncPtr)InterruptDsp_intShmStub, &hwiAttrs, &eb); Hwi_enableInterrupt(intInfo->intVectorId); } } /* Enable the mailbox interrupt to the DSP */ InterruptDsp_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } /* if timer id == 0 */ if (obj->id == 0) { obj->ctmid = 0; obj->intNum = 17; } else if (obj->id == 1) { obj->ctmid = 1; obj->intNum = 18; } obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } /* CTM doesn't need to be acknowledged, no stub required */ hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; status = Timer_postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== InterruptEve_intRegister ======== */ Void InterruptEve_intRegister(UInt16 remoteProcId, IInterrupt_IntInfo *intInfo, Fxn func, UArg arg) { UInt key; Int index; Hwi_Params hwiAttrs; Error_Block eb; InterruptEve_FxnTable *table; Assert_isTrue(remoteProcId < ti_sdo_utils_MultiProc_numProcessors, ti_sdo_ipc_Ipc_A_internal); /* Assert that our MultiProc id is set correctly */ Assert_isTrue((InterruptEve_eveProcId == MultiProc_self()), ti_sdo_ipc_Ipc_A_internal); /* init error block */ Error_init(&eb); if (remoteProcId == InterruptEve_hostProcId) { index = 0; } else if ((remoteProcId == InterruptEve_videoProcId) || (remoteProcId == InterruptEve_vpssProcId)) { index = 1; } else if (remoteProcId == InterruptEve_dspProcId) { index = 2; } else { Assert_isTrue(FALSE, ti_sdo_ipc_Ipc_A_internal); } /* Disable global interrupts */ key = Hwi_disable(); table = &(InterruptEve_module->fxnTable[index]); table->func = func; table->arg = arg; InterruptEve_intClear(remoteProcId, intInfo); /* Make sure the interrupt only gets plugged once */ InterruptEve_module->numPlugged++; if (InterruptEve_module->numPlugged == 1) { /* Register interrupt to remote processor */ Hwi_Params_init(&hwiAttrs); hwiAttrs.arg = arg; hwiAttrs.vectorNum = intInfo->intVectorId; Hwi_create(MAILBOX_EVEINT, (Hwi_FuncPtr)InterruptEve_intShmStub, &hwiAttrs, &eb); Hwi_enableInterrupt(MAILBOX_EVEINT); } /* enable the mailbox and Hwi */ InterruptEve_intEnable(remoteProcId, intInfo); /* Restore global interrupts */ Hwi_restore(key); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int status; Hwi_Params hwiParams; UInt tempId = 0xffff; if ((id != 0) && (id != Timer_ANY)) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } key = Hwi_disable(); if (id == Timer_ANY) { if ((Timer_anyMask & 1) && (Timer_module->availMask & 1)) { Timer_module->availMask &= ~(1); tempId = 0; } } else if (Timer_module->availMask & 1) { Timer_module->availMask &= ~(1); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (NO_TIMER_AVAIL); } else { obj->id = tempId; } Timer_module->handle = obj; obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (BAD_PERIOD); } } obj->arg = params->arg; obj->intNum = 15; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } hwiParams.arg = (UArg)obj; if (obj->runMode == Timer_RunMode_CONTINUOUS) { obj->hwi = Hwi_create (obj->intNum, Timer_periodicStub, &hwiParams, eb); } else { obj->hwi = Hwi_create (obj->intNum, Timer_oneShotStub, &hwiParams, eb); } if (obj->hwi == NULL) { return (NO_HWI_OBJ); } } else { obj->hwi = NULL; } status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }
/* * ======== Timer_Instance_init ======== * 1. Select timer based on id * 2. Mark timer as in use * 3. Save timer handle if necessary (needed by TimestampProvider on 64). * 4. Init obj using params * 5. Create Hwi if tickFxn !=NULL * 6. Timer_init() * 7. Timer configuration (wrt emulation, external frequency etc) * 8. Timer_setPeriod() * 9. Timer_start() */ Int Timer_Instance_init(Timer_Object *obj, Int id, Timer_FuncPtr tickFxn, const Timer_Params *params, Error_Block *eb) { UInt key; Int i, status; Hwi_Params hwiParams; UInt tempId = 0xffff; if (id >= Timer_NUM_TIMER_DEVICES) { if (id != Timer_ANY) { Error_raise(eb, Timer_E_invalidTimer, id, 0); return (1); } } key = Hwi_disable(); if (id == Timer_ANY) { for (i = 0; i < Timer_NUM_TIMER_DEVICES; i++) { if ((Timer_anyMask & (1 << i)) && (Timer_module->availMask & (1 << i))) { Timer_module->availMask &= ~(1 << i); tempId = i; break; } } } else if (Timer_module->availMask & (1 << id)) { Timer_module->availMask &= ~(1 << id); tempId = id; } Hwi_restore(key); obj->staticInst = FALSE; if (tempId == 0xffff) { Error_raise(eb, Timer_E_notAvailable, id, 0); return (2); } else { obj->id = tempId; } /* if timer id == 0, use systick */ if (obj->id == 0) { obj->ctmid = 0; obj->intNum = 15; } /* if timer id == 1, must select which CTM timer based on core id */ else { if (Core_getId() == 0) { obj->ctmid = 0; obj->intNum = 18; } else { obj->ctmid = 1; obj->intNum = 22; } } obj->runMode = params->runMode; obj->startMode = params->startMode; obj->period = params->period; obj->periodType = params->periodType; obj->extFreq.lo = params->extFreq.lo; obj->extFreq.hi = params->extFreq.hi; if (obj->periodType == Timer_PeriodType_MICROSECS) { if (!Timer_setPeriodMicroSecs(obj, obj->period)) { Error_raise(eb, Timer_E_cannotSupport, obj->period, 0); Hwi_restore(key); return (4); } } obj->arg = params->arg; obj->tickFxn = tickFxn; if (obj->tickFxn) { if (params->hwiParams) { Hwi_Params_copy(&hwiParams, (params->hwiParams)); } else { Hwi_Params_init(&hwiParams); } /* we'll enable the interrupt when we're ready */ hwiParams.enableInt = FALSE; /* SysTick needs to be acknowledged, use stub functions */ if (obj->id == 0) { hwiParams.arg = (UArg)obj; if (obj->runMode == Timer_RunMode_CONTINUOUS) { obj->hwi = Hwi_create (obj->intNum, Timer_periodicStub, &hwiParams, eb); } else { obj->hwi = Hwi_create (obj->intNum, Timer_oneShotStub, &hwiParams, eb); } } /* CTM doesn't need to be acknowledged, no stub required */ else { hwiParams.arg = obj->arg; obj->hwi = Hwi_create (obj->intNum, obj->tickFxn, &hwiParams, eb); } if (obj->hwi == NULL) { return (3); } } else { obj->hwi = NULL; } Timer_module->handles[obj->id] = obj; status = postInit(obj, eb); if (status) { return (status); } if (obj->startMode == Timer_StartMode_AUTO) { Timer_start(obj); } return (0); }