xilinx工具SDK测试中断函数
(2019-04-03 16:47:21)
标签:
中断函数zynqvivadoxilinx |
分类: FPGA |
#include
#include "platform.h"
#include "xil_printf.h"
#include "xscugic.h"
#include "sleep.h"
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
#define INTC XScuGic
#define INTC_HANDLER XScuGic_InterruptHandler
int interrupt_initialization();
void interrupt_handler(void);
void interrupt_callback(void);
INTC Intc;
int interrupt_flag = 0;
int main()
{
interrupt_initialization();
while(1){
if(interrupt_flag == 1){
interrupt_flag = 0;
sleep(20); // do some thing when interrupt occur
}
}
}
int interrupt_initialization()
{
//=============================================================//
XScuGic_Config *IntcConfig;
int Result;
INTC *IntcInstancePtr=&Intc;
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
if (NULL == IntcConfig) {
return XST_FAILURE;
}
Result = XScuGic_CfgInitialize(IntcInstancePtr,
IntcConfig,
IntcConfig->CpuBaseAddress);
if (Result != XST_SUCCESS) {
return XST_FAILURE;
}
//-----------------------the first
interrupt----------------------------------------------//
int IntrId=XPS_FPGA2_INT_ID; // one interrupt
XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId, 0xA0,
0x1); // rise edge can't get every time
Result = XScuGic_Connect(IntcInstancePtr, IntrId,
(Xil_ExceptionHandler)interrupt_handler,
interrupt_callback);
if (Result != XST_SUCCESS) {
return Result;
}
XScuGic_Enable(IntcInstancePtr, IntrId);
//-----------------------the second
interrupt----------------------------------------------//
IntrId=XPS_FPGA3_INT_ID;
//-------------------------------------------------------//
XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId, 0xA0,
0x1);
Result = XScuGic_Connect(IntcInstancePtr, IntrId,
(Xil_ExceptionHandler)interrupt_handler,
interrupt_callback);
if (Result != XST_SUCCESS) {
return Result;
}
XScuGic_Enable(IntcInstancePtr, IntrId);
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)INTC_HANDLER, IntcInstancePtr);
Xil_ExceptionEnable();
return XST_SUCCESS;
}
void interrupt_handler(void)
{
interrupt_flag = 1;
}
void interrupt_callback(void)
{
}