static BOOL Intr_EnableGlobalInterrupts(VOID) { CSL_Status intStat; CSL_CPINTC_Handle hnd; //If already initialized return to caller if( bIntcInitialized ) { return TRUE; } #ifdef _STE_BOOT context.numEvtEntries = 12; context.eventhandlerRecord = EventHandler; //Enable CSL Intc Module intStat = CSL_intcInit(&context); if (intStat != CSL_SOK) { #ifdef DEBUG printf("INTR: Initialization error.\n"); #endif } /* Enable NMIs */ intStat = CSL_intcGlobalNmiEnable(); if (intStat != CSL_SOK) { #ifdef DEBUG printf("INTR: Error while enabling NMI.\n"); #endif } /* Enable all interrupts */ intStat = CSL_intcGlobalEnable(&state); if (intStat != CSL_SOK) { #ifdef DEBUG printf("INTR: Error while enabling interrupt.\n"); #endif } #endif //Enable CIC Module bIntcInitialized = TRUE; //Initialize the CSL CIC Module //intStat = CSL_cicInit(&CicContext); //commented by nachi hnd = CSL_CPINTC_open (0); // Inserted for new chip (Opens CPINTC Instance 0) if (hnd != CSL_SOK) { #ifdef _STE_APP LOG_TRACE0( "INTR : CIC init error"); #endif return FALSE; } return TRUE; }
//配置uPP的中断 void upp_intc_setup_my(int (*isr)(void *)) { //初始化开始 intcContext_uPP.eventhandlerRecord = EventHandler_uPP; //事件句柄记录指针 intcContext_uPP.numEvtEntries = 50; //事件入口数目 CSL_intcInit(&intcContext_uPP); //初始化中断上下文对象变量,返回状态CSL_SOK // Enable NMIs使能非可屏蔽中断 CSL_intcGlobalNmiEnable(); //Enable global interrupts使能全局中断 CSL_intcGlobalEnable(&intc_state_uPP); /***************** interrupt configration for UPP接口 **************************/ /* open CPINTC0 to map the UPP completetion ISR event to the host interrupt */ hnd_UPP = CSL_CPINTC_open(0); if (hnd_UPP == 0) { printf ("Error: Unable to open CPINTC-1\n"); return; } glbCpintcHnd[2] = (CSL_CPINTC_RegsOvly)hnd_UPP; //需要根据应用修改UPP产生的事件编号及CPINTC输出channel号 CSL_CPINTC_mapSystemIntrToChannel (hnd_UPP, CSL_INTC0_RPINT, 9); CSL_CPINTC_enableSysInterrupt (hnd_UPP, CSL_INTC0_RPINT); CSL_CPINTC_enableHostInterrupt (hnd_UPP, 9); CSL_CPINTC_enableAllHostInterrupt(hnd_UPP); vectId_uPP = CSL_INTC_VECTID_4; hIntcUpp= CSL_intcOpen (&intcObjUpp, CSL_GEM_INTC0_OUT_9_PLUS_20_MUL_N, &vectId_uPP , NULL); gpioHandler.handler = (CSL_IntcEventHandler)&upp_isr;//事件句柄指针 gpioHandler.arg = 0; //传递给参数的句柄指针 CSL_intcPlugEventHandler(hIntcUpp, &gpioHandler); //建立事件和句柄的映射关系 CSL_intcHwControl(hIntcUpp,CSL_INTC_CMD_EVTCLEAR,NULL); CSL_intcHwControl(hIntcUpp, CSL_INTC_CMD_EVTENABLE, NULL); /***************** interrupt configration for UPP接口 **************************/ }
/* * ============================================================================= * @func IntcInit * * @arg * NONE * * @desc * 初始化中断 * * @return * NONE * * ============================================================================= */ void IntcInit() { /*初始化开始*/ intcContext_uPP.eventhandlerRecord = EventHandler_uPP; //事件句柄记录指针 intcContext_uPP.numEvtEntries = 50; //事件入口数目 /* 初始化结束,前面的初始化过程只需要一次,如果需要增加中断处理,直接添加中断矢量 和事件号即可,无需再次初始化,否则会覆盖掉前面的配置(包括事件和其中断服务程序的映射表等)*/ /*初始化中断上下文对象变量,返回状态CSL_SOK*/ CSL_intcInit(&intcContext_uPP); /*使能非可屏蔽中断*/ CSL_intcGlobalNmiEnable(); /*使能全局中断*/ CSL_intcGlobalEnable(&intc_state_uPP); if(coreNum == 0) { /************************ 1.中断配置-----收图 **************************/ ///////////////////////////第一步:EDMACC_GINT事件作为system interrupt通过CPINTC映射到host interrupt//////////// /* open CPINTC0 to map the EDMA completetion ISR event to the host interrupt */ hnd_EDMA_uPP = CSL_CPINTC_open(0); if (hnd_EDMA_uPP == 0) { printf ("Error: Unable to open CPINTC-1\n"); return; } glbCpintcHnd[1] = (CSL_CPINTC_RegsOvly)hnd_EDMA_uPP; //需要根据应用修改EDMA产生的事件编号及CPINTC输出channel号 //tms320c6657.pdf中"EDMA产生的事件编号"对应"CIC0 Event Inputs的22号",System Event Mapping的CIC0_OUT(8+20*n)的"8"为host interrupt CSL_CPINTC_mapSystemIntrToChannel (hnd_EDMA_uPP, CSL_INTC0_CPU_3_2_EDMACC_GINT, 8);//system interrupt maping to host interrupt CSL_CPINTC_enableSysInterrupt (hnd_EDMA_uPP, CSL_INTC0_CPU_3_2_EDMACC_GINT); CSL_CPINTC_enableHostInterrupt (hnd_EDMA_uPP, 8); CSL_CPINTC_enableAllHostInterrupt(hnd_EDMA_uPP); /***************** interrupt configration for EDMA completed ***************/ //////////////////////////////////////第二步:host interrupt号转换为Event ID号,并绑定中断向量号///////////////////////// /* Opening a intc handle for edma event */ vectId_uPP = CSL_INTC_VECTID_7; //打开中断向量句柄,建立事件与中断之间的映射关系 //CSL_GEM_INTC0_OUT_8_PLUS_20_MUL_N 即CIC0_OUT(8+20*n)中8+20*n为Event ID hIntcEdma_uPP = CSL_intcOpen (&intcObjEdma_uPP, CSL_GEM_INTC0_OUT_8_PLUS_20_MUL_N, \ &vectId_uPP , NULL); /* Association of an EDMA event handler with the INTC routine 关联EDMA事件句柄到INTC程序*/ EventRecord_uPP.handler = &eventEdmaHandler;//EDMA事件句柄指针 EventRecord_uPP.arg = (void*)(hModule_uPP);//hModule_uPP是EMDA通道句柄 CSL_intcPlugEventHandler(hIntcEdma_uPP,&EventRecord_uPP); //建立事件和句柄的映射关系 CSL_intcHwControl(hIntcEdma_uPP,CSL_INTC_CMD_EVTCLEAR,NULL); /* Enabling event edma 使能EDMA收图完成中断 */ CSL_intcHwControl(hIntcEdma_uPP,CSL_INTC_CMD_EVTENABLE,NULL); /* Hook up the EDMA event with an completion code function handler */ EdmaEventHook(CSL_EDMA3_CHA_GPINT0, ImgEDMARecCompleted_INT);//收图完成中断 /***************** interrupt configration for EDMA completed ***************/ /*****************2.中断配置-----UPP接口 **************************/ ////////////////////////////////////////////////用来与FPGA通信,接收图像////////////////////////////////////////////////////////////////// /* open CPINTC0 to map the UPP completetion ISR event to the host interrupt */ hnd_UPP = CSL_CPINTC_open(0); if (hnd_UPP == 0) { printf ("Error: Unable to open CPINTC-1\n"); return; } glbCpintcHnd[2] = (CSL_CPINTC_RegsOvly)hnd_UPP; //需要根据应用修改UPP产生的事件编号及CPINTC输出channel号 //CSL_INTC0_RPINT为upp的system interrupt ,9为CIC0_OUT(9+20*n)中的host interrupt CSL_CPINTC_mapSystemIntrToChannel (hnd_UPP, CSL_INTC0_RPINT, 9); CSL_CPINTC_enableSysInterrupt (hnd_UPP, CSL_INTC0_RPINT); CSL_CPINTC_enableHostInterrupt (hnd_UPP, 9); CSL_CPINTC_enableAllHostInterrupt(hnd_UPP); vectId_uPP = CSL_INTC_VECTID_4; //绑定中断向量,即host interrupt转换为event id之后进入INTC绑定vectId_uPP hIntcUpp= CSL_intcOpen (&intcObjUpp, CSL_GEM_INTC0_OUT_9_PLUS_20_MUL_N, &vectId_uPP , NULL); gpioHandler.handler = (CSL_IntcEventHandler)&upp_isr;//事件句柄指针 gpioHandler.arg = 0; //传递给参数的句柄指针 CSL_intcPlugEventHandler(hIntcUpp, &gpioHandler); //建立事件和句柄的映射关系 CSL_intcHwControl(hIntcUpp,CSL_INTC_CMD_EVTCLEAR,NULL); CSL_intcHwControl(hIntcUpp, CSL_INTC_CMD_EVTENABLE, NULL); /***************** interrupt configration for UPP接口 **************************/ } }
int upp_isr() { int status = 0; CSL_CPINTC_Handle hnd; Uint32 rawStatus=0; int interrupt_status = uppRegs->UPIER; while (interrupt_status != 0) { if (interrupt_status & upp_int_EOLI) { uppRegs->UPIER = upp_int_EOLI; // clear EOLI // Handle EOLI... } if (interrupt_status & upp_int_EOWI) { uppRegs->UPIER = upp_int_EOWI; // clear EOWI // Handle EOWI... } if (interrupt_status & upp_int_ERRI) { uppRegs->UPIER = upp_int_ERRI; // clear ERRI // Handle ERRI... status = -1; } if (interrupt_status & upp_int_UORI) { uppRegs->UPIER = upp_int_UORI; // clear UORI // Handle UORI... } if (interrupt_status & upp_int_DPEI) { uppRegs->UPIER = upp_int_DPEI; // clear DPEI // Handle DPEI... } if (interrupt_status & upp_int_EOLQ) { uppRegs->UPIER = upp_int_EOLQ; // clear EOLQ // Handle EOLQ... } if (interrupt_status & upp_int_EOWQ) { uppRegs->UPIER = upp_int_EOWQ; // clear EOWQ // Handle EOWQ... valid = 1; first_flag = 0; } if (interrupt_status & upp_int_ERRQ) { uppRegs->UPIER = upp_int_ERRQ; // clear ERRQ // Handle ERRQ... status = -1; } if (interrupt_status & upp_int_UORQ) { uppRegs->UPIER = upp_int_UORQ; // clear UORQ // Handle UORQ... } if (interrupt_status & upp_int_DPEQ) { uppRegs->UPIER = upp_int_DPEQ; // clear DPEQ // Handle DPEQ... } //uppRegs->UPEOI = 0; // loop again if any interrupts are left interrupt_status = uppRegs->UPIER; } // end of while // write end of interrupt vector to allow future calls hnd = CSL_CPINTC_open(0); CSL_CPINTC_getRawInterruptStatus(hnd, 4, &rawStatus); CSL_CPINTC_clearSysInterrupt(hnd,(CSL_CPINTCSystemInterrupt) rawStatus); *((volatile unsigned int *)(0x02600290)) = rawStatus; uppRegs->UPEOI = 0; status = 0; upp_test_exit: return status; } // end of function