软中断处理流程图及代码如下
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
XScuGic InterrruptInst;
int InterruptInit(XScuGic *InstancePtr, u16 DeviceId) ;
int InterruptConnnect(XScuGic *InstancePtr, u16 IntId, void * Handler,void *CallBackRef) ;
void SoftHandler(void *CallbackRef) ;
int main()
{
int Status ;
Status = InterruptInit(&InterrruptInst, INTC_DEVICE_ID) ;//初始化中断
if (Status != XST_SUCCESS)
return XST_FAILURE ;
InterruptConnnect(&InterrruptInst, SoftIntrIdToCpu0, (void *)SoftHandler, (void *)&InterrruptInst) ;//连接中断
}
int InterruptInit(XScuGic *InstancePtr, u16 DeviceId)
{
XScuGic_Config *IntcConfig;
int Status ;
IntcConfig = XScuGic_LookupConfig(DeviceId);
Status = XScuGic_CfgInitialize(InstancePtr, IntcConfig, IntcConfig->CpuBaseAddress) ;
if (Status != XST_SUCCESS)
return XST_FAILURE ;
/*初始化异常处理
* Initialize the exception table
*/
Xil_ExceptionInit();
/*注册异常处理回调函数到CPU
* Register the interrupt controller handler with the exception table
*/
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
InstancePtr);
/*使能异常处理
* Enable non-critical exceptions
*/
Xil_ExceptionEnable();
return XST_SUCCESS ;
}
//连接软中断信号并注册中断回掉函数
int InterruptConnnect(XScuGic *InstancePtr, u16 IntId, void * Handler,void *CallBackRef)
{
int Status ;
Status = XScuGic_Connect(InstancePtr, IntId,(Xil_InterruptHandler)Handler,CallBackRef) ;
if (Status != XST_SUCCESS)
return XST_FAILURE ;
XScuGic_Enable(InstancePtr, IntId) ;//使能中断控制器中的软中断
return XST_SUCCESS ;
}
void SoftHandler(void *CallbackRef)
{
xil_printf("Soft Interrupt from CPU1\r\n") ;
soft_flag = 1 ;
}