//配置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接口  **************************/
}
BOOL Intr_EnableEvent(Intr *pThis)
{
	//CSL_Status          intStat;

	//If CIC Event is provided in Interrupt Table
	if(pThis->oIntrTableParam.bCicRequired == TRUE)
	{
		//intStat = CSL_cicHwControl(pThis->CicHandle, CSL_CIC_CMD_EVTENABLE, NULL); // modified for new Chip



				/* Enable the Host Interrupt. */
				CpIntc_enableHostInt(0,pThis->oIntrTableParam.HostInt );

				/* Enable the System Interrupt */
				CpIntc_enableSysInt(0, pThis->oIntrTableParam.SysInt);




		//if(intStat != CSL_SOK)
		//{
		//	#ifdef _STE_APP
    	//	LOG_TRACE0( "INTR : CIC HwControl to enable event ... Failed.\n");
		//	#endif
		//	return FALSE;
		//}
	}
	//else

	#ifdef _STE_APP

	//Clear the Interrupt Flag Register before Enabling
	//C64_clearIFR(1 << pThis->oIntrTableParam.eIntcVectorId );// DSPBIOS API
	Hwi_clearInterrupt( pThis->oIntrTableParam.eIntcVectorId);// not sure this is the equivalent or not :(
	//Enable the Vector interrupt
	//C64_enableIER(1 << pThis->oIntrTableParam.eIntcVectorId );// DSP BIOS API
	Hwi_enableInterrupt( pThis->oIntrTableParam.eIntcVectorId);// SYS BIOS API
	#endif
	#ifdef _STE_BOOT
	intStat = CSL_intcHwControl(pThis->oIntcHandle, CSL_INTC_CMD_EVTENABLE, NULL);
    if(intStat != CSL_SOK)
	{
		#ifdef DEBUG
    	printf("INTR: HwControl to enable event ... Failed.\n");
		#endif
	}
	#endif

	return TRUE;
}
BOOL Intr_DisableEvent(Intr *pThis)
{
	//CSL_Status          intStat;

	//If CIC Event is provided in the Interrupt table
	if(pThis->oIntrTableParam.bCicRequired == TRUE)
	{

		CpIntc_disableHostInt(0, pThis->oIntrTableParam.HostInt);//newly added for new Chip

		CpIntc_disableSysInt(0,  pThis->oIntrTableParam.SysInt);//newly added for new Chip
		//intStat = CSL_cicHwControl(pThis->CicHandle, CSL_CIC_CMD_EVTDISABLE, NULL); //disabled for new Chip
    	//if(intStat != CSL_SOK)
		//{
		//	#ifdef _STE_APP
    	//	LOG_TRACE0( "INTR : CIC HwControl to disable event ... Failed.\n");
		//	#endif
		//	return FALSE;
		//}
	}
	
	#ifdef _STE_APP
	//Disable the Vector interrupt
	//C64_disableIER(1 << pThis->oIntrTableParam.eIntcVectorId );// DSP BIOS API

	Hwi_disableInterrupt(pThis->oIntrTableParam.eIntcVectorId);// SYS BIOS API
	#endif
	#ifdef _STE_BOOT
	intStat = CSL_intcHwControl(pThis->oIntcHandle, CSL_INTC_CMD_EVTDISABLE, NULL);
    if(intStat != CSL_SOK)
	{
    	#ifdef DEBUG
    	printf("INTR: HwControl to disable event ... Failed.\n");
		#endif
	}
	#endif

	return TRUE;
}
/*
 * =============================================================================
 *   @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接口  **************************/
	}
}