工程师您好, 我们调试C6678为实现和FPGA的通信,现使用CSL配置15号中断,代码如下,在不使用while(a!=1){}(void GPIO_init()函数的最后一行)等待中断到来,而在main()中while(1)执行MAC层程序代码时,接收不到中断,这是为什么?为什么不是:在main()里的while(1)循环中正常执行自己的工程代码,在FPGA中断到来时再执行中断处理函数intIsr(),执行完后再返回继续执行程序代码? 使用while(a!=1){}在GPIO_init函数中等待终端到来时,可以持续接收到中断,这里我想再请教一个问题:为什么每次接收到中断,程序都从最开始的初始化执行一遍,且中断函数中的中断次数不累加,每次进来都为0,然后置1?
GPIO初始化函数:
CSL_GpioHandle hGpio;
int demoFail = 0;
/* Interrupt module Declarations */
CSL_IntcContext intcContext;
CSL_IntcEventHandlerRecord EventHandler[30];
CSL_IntcObj intcObj;
CSL_IntcHandle hTest;
CSL_IntcGlobalEnableState state;
CSL_IntcEventHandlerRecord EventRecord;
CSL_IntcParam vectId;
CSL_GpioHandle hGpio;
void GPIO_init()
{
int pinNum = 0;
int bankNum = 0;
/************************************************
*************** INTC Configuration *************
************************************************/
printf ("Debug: GEM-INTC Configuration…\n");
/* INTC module initialization */
intcContext.eventhandlerRecord = EventHandler;
intcContext.numEvtEntries = 10;
if (CSL_intcInit(&intcContext) != CSL_SOK)
{
printf("Error: GEM-INTC initialization failed\n");
return;
}
/* Enable NMIs */
if (CSL_intcGlobalNmiEnable() != CSL_SOK)
{
printf("Error: GEM-INTC global NMI enable failed\n");
return;
}
/* Enable global interrupts */
if (CSL_intcGlobalEnable(&state) != CSL_SOK)
{
printf ("Error: GEM-INTC global enable failed\n");
return;
}
/* Open the INTC Module for Vector ID: 4 and Event ID: 90 (GPIO_n in C6678)*/
vectId = CSL_INTC_VECTID_4;
hTest = CSL_intcOpen (&intcObj, 89, &vectId , NULL);//89:GPIO_15
if (hTest == NULL)
{
printf("Error: GEM-INTC Open failed\n");
return;
}
/* Register an call-back handler which is invoked when the event occurs. */
EventRecord.handler = &intIsr;//intIsr;
EventRecord.arg = 0;//hTest
if (CSL_intcPlugEventHandler(hTest,&EventRecord) != CSL_SOK)
{
printf("Error: GEM-INTC Plug event handler failed\n");
return;
}
/* Enabling the events. */
if (CSL_intcHwControl(hTest,CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK)
{
printf("Error: GEM-INTC CSL_INTC_CMD_EVTENABLE command failed\n");
return;
}
printf ("Debug: GEM-INTC Configuration Completed\n");
// 1. Init Flag
a = 0;
printf("a = %d\n",a);
// 2. Trigger GPIO_0 in Core0
pinNum = 15;
bankNum = 0;
// Open the CSL GPIO Module 0
hGpio = CSL_GPIO_open (0);
// Set GPIO pin number 0 as an output pin
CSL_GPIO_setPinDirOutput (hGpio, pinNum);
// Set interrupt detection on GPIO pin 0 to rising edge
CSL_GPIO_setRisingEdgeDetect (hGpio, pinNum);
// Enable GPIO per bank interrupt for bank zero
CSL_GPIO_bankInterruptEnable (hGpio, bankNum);
// Toggle GPIO_0 pin to trigger GPIO interrupt
CSL_GPIO_clearOutputData (hGpio, pinNum); //GPIO_0=0
CSL_GPIO_setOutputData (hGpio, pinNum); //GPIO_0=1
return;
// 3. Wait for entering into ISR
//while(a!=1){}//必使用?
中断处理函数:
volatile int a = 0;
Uint32 int_cnt = 0;//中断次数统计
interrupt void intIsr()
{
a = 1;
int_cnt++;//不累加?
//if( int_cnt % 32 == 0 )
//{
SWrite_Flag = 1;
SRIO_Data_SWrite( 0x90000000, FPGA_SRIO_BASE_ADDR, 512 );
printf("GPIO INTR %d\t%d\n",int_cnt,SWrite_Flag);
//}
return ;
}
Thomas Yang1:
程序架构设计不太合理,响应一次中断后,程序就退出了,改改程序架构吧,比如设计成前后台模式 前台while'循环,后台就是GPIO中断
Siyan Zhu1:
回复 Thomas Yang1:
工程师您好,正如问题中所述,在main()中的while(1){}循环中,收不到中断。能不能详细一点说明如何修改?
Thomas Yang1:
回复 Siyan Zhu1:
第一次中断后,a=1后,while循环就退出了,程序就结束了?
Siyan Zhu1:
回复 Thomas Yang1:
不是的,根本进不去中断处理函数。(CSL配置中断需要使用vector.asm文件映射吗)
Thomas Yang1:
回复 Siyan Zhu1:
没有SYSBIOS的话,中断向量表都是需要的,你参看下置顶帖中的STK呢,里面有GPIO, interrupt例子