zynq 中断
#include "stdio.h"
#include "xparameters.h"
#include "xgpiops.h"
#include "xscugic.h"
#include "sleep.h"
//ps_led
#define MIO15_LED 15
#define MIO47_KEY 47
#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
//GPIO的中断号 52
#define GPIO_INTERRUPT_ID XPAR_XGPIOPS_0_INTR
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID
XGpioPs_Config *ConfigPtr;
XGpioPs Gpio;
XScuGic Intc;
XScuGic_Config *IntcConfig;
void IntrHandler();
void SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio,u16 GpioIntrId);
u32 key_press;
int main(){
u32 led_value = 0;
printf("GPIO interupt TEST !");
//根据器件id,查找器件的配置信息,
ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
//初始化GPIO驱动
XGpioPs_CfgInitialize(&Gpio, ConfigPtr,ConfigPtr->BaseAddr);
//把gpio的方向设置为输出(0:输入,1:输出)
XGpioPs_SetDirectionPin(&Gpio, MIO15_LED, 1);
//设置输出使能(0:关闭/1:打开)
XGpioPs_SetOutputEnablePin(&Gpio, MIO15_LED, 1);
XGpioPs_SetDirectionPin(&Gpio, MIO47_KEY, 0x0);
SetupInterruptSystem(&Intc, &Gpio, GPIO_INTERRUPT_ID);
while(1){
if(key_press){
led_value = ~led_value;
key_press = 0;
XGpioPs_WritePin(&Gpio, MIO15_LED,led_value);
XGpioPs_IntrClearPin(&Gpio, MIO47_KEY);
usleep(200000);
XGpioPs_IntrEnablePin(&Gpio, MIO47_KEY);
}
}
return 0;
}
void SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio,u16 GpioIntrId)
{
/*
* Initialize the interrupt controller driver so that it is ready to
* use.
*/
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
XScuGic_CfgInitialize(GicInstancePtr, IntcConfig,IntcConfig->CpuBaseAddress);
/*
* Connect the interrupt controller interrupt handler to the hardware
* interrupt handling logic in the processor.
*/
//初始化异常
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,GicInstancePtr);
/* 使能处理器中断 */
Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
//关联中断处理函数
XScuGic_Connect(GicInstancePtr, GpioIntrId,(Xil_ExceptionHandler)IntrHandler,(void *)Gpio);
/*设置中断类型 */
XGpioPs_SetIntrTypePin(Gpio, MIO47_KEY, XGPIOPS_IRQ_TYPE_EDGE_FALLING);
/* 打开中断使能 */
XGpioPs_IntrEnablePin(Gpio, MIO47_KEY);
/*为GPIO器件使能中断 */
XScuGic_Enable(GicInstancePtr, GpioIntrId);
}
void IntrHandler(){
printf("interupt detected!\n\r");
key_press = 1;
XGpioPs_IntrDisablePin(&Gpio, MIO47_KEY);
}
最新文章
- ajax+表单验证+验证码生成例子
- JDE函数--获取当前登录人的描述
- Zabbix的安装与部署---问题处理(php65.6.28 mysqli 报错误 处理)
- H - Can you answer these queries? - (区间查询更新)
- ubuntu14.04下arm-linux-gcc 4.5.1的安装与配置
- Android 开发笔记 “SQLite”
- springMVC源码分析--ControllerBeanNameHandlerMapping(八)
- [ SSH框架 ] Hibernate框架学习之三
- RabbitMQ+Spring 结合使用
- codeforces / project Euler 泛做
- C++动态链接库方法调用
- vmware不能装ghost系统怎么解决
- Tomcat解决中文乱码并部署项目
- ERROR 000732:Output Geodatabase:Dataset Database Connections\Connection to localhost.sde\SDE.Dataset does not exist or is not supported
- Pandas 使用笔记
- DDD实战进阶第一波(三):开发一般业务的大健康行业直销系统(搭建支持DDD的轻量级框架二)
- Struts2学习:Action获取properties文件的值
- 详解掩膜mask
- [转载]论asp.net out、ref、return
- java编写编译器和解释器