#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);
}

最新文章

  1. ajax+表单验证+验证码生成例子
  2. JDE函数--获取当前登录人的描述
  3. Zabbix的安装与部署---问题处理(php65.6.28 mysqli 报错误 处理)
  4. H - Can you answer these queries? - (区间查询更新)
  5. ubuntu14.04下arm-linux-gcc 4.5.1的安装与配置
  6. Android 开发笔记 “SQLite”
  7. springMVC源码分析--ControllerBeanNameHandlerMapping(八)
  8. [ SSH框架 ] Hibernate框架学习之三
  9. RabbitMQ+Spring 结合使用
  10. codeforces / project Euler 泛做
  11. C++动态链接库方法调用
  12. vmware不能装ghost系统怎么解决
  13. Tomcat解决中文乱码并部署项目
  14. ERROR 000732:Output Geodatabase:Dataset Database Connections\Connection to localhost.sde\SDE.Dataset does not exist or is not supported
  15. Pandas 使用笔记
  16. DDD实战进阶第一波(三):开发一般业务的大健康行业直销系统(搭建支持DDD的轻量级框架二)
  17. Struts2学习:Action获取properties文件的值
  18. 详解掩膜mask
  19. [转载]论asp.net out、ref、return
  20. java编写编译器和解释器

热门文章

  1. idea如何引入外部jar包
  2. GDB调用
  3. element3 form表单校验对象里面有对象的情况
  4. C#中DataTable新增列、删除列、更改列名、交换列位置
  5. npm config set registry https://registry.npm.taobao.org
  6. Jenkins拉取GitHub上代码
  7. Vue源码主体分析
  8. [CSP-S2019] Emiya 家今天的饭
  9. Jmeter性能测试入门到项目实战03
  10. 常见的SPA首屏优化方式