需求如下:
DSP同时使用SRIO中断及UART中断(本项目仅使用单核,不考虑多核),目前遇到的问题如下:
网上找到的例程,都是针对单种外设进行CIC配置,我单独配置SRIO中断或者UART中断,都能正常,但如果两种外设都要使用,且使用中断,就会出现无法同时使用的情况,经过多次排查,感觉还是中断配置的地方有问题,疑问之处已经用黄底标出,请帮看下!具体代码段如下:
CSL_CPINTC_Handle hnd; //两种中断需要创建2个Handle吗?
CSL_IntcContext intcContext;
CSL_IntcEventHandlerRecord EventHandler[30];//里面是用到几个中断就有几个EventHandler子元素?
CSL_IntcGlobalEnableState state;//多种中断能否共用?
CSL_IntcEventHandlerRecord EventRecord;
//SRIO读数
CSL_IntcObj intcObj_read;
CSL_IntcHandle read_handle;
CSL_IntcParam vectId_read;
//UART
CSL_IntcObj intcObj_uart;
CSL_IntcHandle uart_handle;
CSL_IntcParam vectId_uart;
uint8_t eventId_uart;
#define host_event 2//SRIO主机中断
#define sys_event CSL_INTC0_INTDST0//0x70
/************************************************
*************** INTC Configuration *************
************************************************/
/* INTC module initialization */
intcContext.eventhandlerRecord = EventHandler; intcContext.numEvtEntries = 2; //此处为1不行,如果改成1的话连单个中断都不能用,请问是什么原因?
if (CSL_intcInit(&intcContext) != CSL_SOK) {
return -1;
}
/* Enable NMIs */
if (CSL_intcGlobalNmiEnable() != CSL_SOK) {
return -1;
}
/* Enable global interrupts */
if (CSL_intcGlobalEnable(&state) != CSL_SOK) {
return -1;
}
/**************************************************
************* CPINTC-0 Configuration *************
**************************************************/
/* Open the handle to the CPINT Instance */
hnd = CSL_CPINTC_open(0);
//此处为0,如果要配两种中断,是否需要再单独创建hnd1 = CSL_CPINTC_open(0) or CSL_CPINTC_open(1)??
if (hnd == 0) {
return -1;
}
/* Disable all host interrupts. */
CSL_CPINTC_disableAllHostInterrupt(hnd);
/* Configure no nesting support in the CPINTC Module. */
CSL_CPINTC_setNestingMode(hnd, CPINTC_NO_NESTING);
/* We now map System Interrupt INTDST0 to channel 2 */
CSL_CPINTC_mapSystemIntrToChannel(hnd, sys_event, host_event); //CIC0 Event Inputs:RapidIO interrupt INTDST0
//uart
/*
* Map system interrupt to channel
* channel: CIC0_OUT(8+20*n) (n is core num) = 8
*/
CSL_CPINTC_mapSystemIntrToChannel(hnd, CSL_INTC0_UARTINT, 8);
CSL_CPINTC_clearSysInterrupt(hnd, CSL_INTC0_UARTINT);
/* We now enable system interrupt */
CSL_CPINTC_enableSysInterrupt(hnd, sys_event);
//uart
CSL_CPINTC_enableSysInterrupt(hnd, CSL_INTC0_UARTINT);
/* We enable host interrupts. */
CSL_CPINTC_enableHostInterrupt(hnd, host_event);
//uart
CSL_CPINTC_enableHostInterrupt(hnd, 8);
/* Enable all host interrupts also. */
CSL_CPINTC_enableAllHostInterrupt(hnd);
/* clear system interrupt */
CSL_CPINTC_clearSysInterrupt(hnd,sys_event);//CSL_INTC0_INTDST0:0x00000070
vectId_read = CSL_INTC_VECTID_4;// CPU interrupt number
read_handle = CSL_intcOpen(&intcObj_read, 62, &vectId_read, NULL);//62-CIC0_OUT(2),
/* Open INTC, event ID 30/104 maps to CPU interrupt vector 13 */
vectId_uart = CSL_INTC_VECTID_13;
uart_handle = CSL_intcOpen(&intcObj_uart, CSL_GEM_INTC0_OUT8_OR_INTC1_OUT8, &vectId_uart, NULL);
if(uart_handle == NULL) {
//uart_printf("Open intc_uart failed!\n");
return -1;
}
//INTSEL7-4,11-8,15-12
if (read_handle == NULL) {
return -1;
}
if (uart_handle == NULL) {
return -1;
}
//不太能理解的是,多中断配置,是要先配一种,还是两种并行去配?下面这句绑定的最为可疑,标黄的地方如果是1,甚至会直接覆盖[0]的配置
/* 这里将中断服务函数和中断源联系起来 */
/* Bind ISR to Interrupt */
EventHandler[0].handler = (CSL_IntcEventHandler) &read_isr_handler;
EventHandler[0].arg = (void *)0;
EventHandler[2].handler = (CSL_IntcEventHandler) &uart_isr;
EventHandler[2].arg = (void *)CSL_INTC0_UARTINT;
if (CSL_intcPlugEventHandler(read_handle, &EventHandler[0]) != CSL_SOK) {
return -1;
}
if (CSL_intcPlugEventHandler(uart_handle, &EventHandler[2]) != CSL_SOK) {
return -1;
}
/* clean event */
CSL_intcHwControl(read_handle, CSL_INTC_CMD_EVTCLEAR, NULL);
CSL_intcHwControl(uart_handle, CSL_INTC_CMD_EVTCLEAR, NULL);
/* 使能刚才配置的两种中断通路 /
/ Enabling the read events. */
if (CSL_intcHwControl(read_handle, CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK) {
return -1;
}
if (CSL_intcHwControl(uart_handle, CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK) {
return -1;
}