加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

xilinx工具SDK测试中断函数

(2019-04-03 16:47:21)
标签:

中断函数

zynq

vivado

xilinx

分类: 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)
{

}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有