Zynq GPIO 中断
/*
* Copyright (c) 2009-2012 Xilinx, Inc. All rights reserved.
*
* Xilinx, Inc.
* XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
* COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
* ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR
* STANDARD, XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION
* IS FREE FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE
* FOR OBTAINING ANY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
* XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
* THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO
* ANY WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE
* FROM CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE.
*
*/ /*
* helloworld.c: simple test application
*
* This application configures UART 16550 to baud rate 9600.
* PS7 UART (Zynq) is not initialized by this application, since
* bootrom/bsp configures it to baud rate 115200
*
* ------------------------------------------------
* | UART TYPE BAUD RATE |
* ------------------------------------------------
* uartns550 9600
* uartlite Configurable only in HW design
* ps7_uart 115200 (configured by bootrom/bsp)
*/ #include <stdio.h>
#include "platform.h"
#include "xgpiops.h" #include "xparameters.h"
#include "xstatus.h"
#include "xscugic.h"
#include "xil_exception.h" //void print(char *str); #define GPIO_DIR 0x0000 /*All work in input mode*/
#define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID //
#define INTC_DEVICE_ID XPAR_SCUGIC_SINGLE_DEVICE_ID //
#define GPIO_INTERRUPT_ID XPAR_XGPIOPS_0_INTR // All gpio in four banks to one output (IRQ ID#52) to interrupt controller /************************** Function Prototypes ******************************/ static void IntrHandler(void *CallBackRef, int Bank, u32 Status);
static int SetupInterruptSystem(XScuGic *Intc, XGpioPs *Gpio, u16 GpioIntrId);
int ScuGicInterruptSetup(XScuGic *IntcInstancePtr, u16 DeviceId); /************************** Variable Definitions *****************************/ /*
* The following are declared globally so they are zeroed and so they are
* easily accessible from a debugger.
*/
static XGpioPs Gpio; /* The Instance of the GPIO Driver */ XScuGic IntcInstance; /* The Instance of the Interrupt Controller Driver */ int main()
{
init_platform(); print("Hello World\n\r"); /*****************************************************************/
//Set GPIO Interrupt
/*****************************************************************/
XGpioPs_Config *ConfigPtr;
int Status = ;
XGpioPs Gpio;
/*
* Initialize the Gpio driver.
*/
//printf("Initialize the Gpio driver.\n\r");
ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
if (ConfigPtr == NULL) {
return XST_FAILURE;
} XGpioPs_CfgInitialize(&Gpio, ConfigPtr, ConfigPtr->BaseAddr); /*
* Setup direction register of bank2, so that all the pins are configured as inputs.
*/
//printf("Set gpio direction.\n\r");
XGpioPs_SetDirection(&Gpio, , GPIO_DIR); // bank2 set to all input #ifdef GPIOIOTEST
//printf("GPIO bank2 value is 0x%x \n\r",i);
// set gpio direction output,'1' for output
XGpioPs_SetDirection(&Gpio, , 0xff);
// set gpio output enable
XGpioPs_SetOutputEnable(&Gpio, , 0xff);
// write value
XGpioPs_Write(&Gpio, , 0xff);
#endif /***********************************************************************/
/* How to Set Interrupt */
/***********************************************************************/ IntCtl_Init(); // GPIO is Num.52 interrupt
Status = SetupInterruptSystem(&IntcInstance, &Gpio, GPIO_INTERRUPT_ID); if (Status != XST_SUCCESS) {
print("Set GPIO interrupt Failure \n\r");
}
else{
print("Set GPIO interrupt Successful \n\r");
} /***********************************************************************/ while()
{
sleep();
print("While(1) ing \n\r");
} return ;
} /*****************************************************************************/
/**
*
* This function is used by the TestAppGen generated application to setup
* the interrupt controller.
*
* @param IntcInstancePtr is the reference to the Interrupt Controller
* instance.
* @param DeviceId is device ID of the Interrupt Controller Device,
* typically XPAR_<INTC_instance>_DEVICE_ID value from
* xparameters.h.
*
* @return XST_SUCCESS to indicate success, otherwise XST_FAILURE.
*
* @note None.
*
******************************************************************************/
int IntCtl_Init(void)
{
int Status; Status = ScuGicInterruptSetup(&IntcInstance, XPAR_PS7_SCUGIC_0_DEVICE_ID);
if (Status == ) {
print("ScuGic Interrupt Setup PASSED\r\n");
}
else {
print("ScuGic Interrupt Setup FAILED\r\n");
}
} /*****************************************************************************/
/**
*
* This function is used by the TestAppGen generated application to setup
* the interrupt controller.
*
* @param IntcInstancePtr is the reference to the Interrupt Controller
* instance.
* @param DeviceId is device ID of the Interrupt Controller Device,
* typically XPAR_<INTC_instance>_DEVICE_ID value from
* xparameters.h.
*
* @return XST_SUCCESS to indicate success, otherwise XST_FAILURE.
*
* @note None.
*
******************************************************************************/
int ScuGicInterruptSetup(XScuGic *IntcInstancePtr, u16 DeviceId)
{ int Status;
static XScuGic_Config *GicConfig; /*
* Initialize the interrupt controller driver so that it is ready to
* use.
*/
GicConfig = XScuGic_LookupConfig(DeviceId);
if (NULL == GicConfig) {
return XST_FAILURE;
} Status = XScuGic_CfgInitialize(IntcInstancePtr, GicConfig, GicConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
} /*
* Initialize the exception table.
*/
Xil_ExceptionInit(); /*
* Connect the interrupt controller interrupt handler to the hardware
* interrupt handling logic in the processor.
*/
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
IntcInstancePtr); /*
* Enable exceptions.
*/
Xil_ExceptionEnable(); return XST_SUCCESS; }
/*****************************************************************************/
/**
*
* This function sets up the interrupt system for the example. It enables rasing
* edge interrupts for all the pins of bank 2 in the GPIO device.
*
* @param GicInstancePtr is a pointer to the XScuGic driver Instance.
* @param GpioInstancePtr contains a pointer to the instance of the GPIO
* component which is going to be connected to the interrupt
* controller.
* @param GpioIntrId is the interrupt Id and is typically
* XPAR_<GICPS>_<GPIOPS_instance>_VEC_ID value from
* xparameters.h.
*
* @return XST_SUCCESS if successful, otherwise XST_FAILURE.
*
* @note None.
*
****************************************************************************/
static int SetupInterruptSystem(XScuGic *GicInstancePtr, XGpioPs *Gpio, u16 GpioIntrId)
{
int Status; XScuGic_Config *IntcConfig; /* Instance of the interrupt controller */ /*
* Connect the device driver handler that will be called when an
* interrupt for the device occurs, the handler defined above performs
* the specific interrupt processing for the device.
*
*
*/
printf("Connect the device driver handler to interrupt processing \n\r");
Status = XScuGic_Connect(GicInstancePtr, GpioIntrId,
(Xil_ExceptionHandler)XGpioPs_IntrHandler,
(void *)Gpio);
if (Status != XST_SUCCESS) {
return Status;
} /*
* @param GpioInstancePtr contains a pointer to the instance of the GPIO
* component which is going to be connected to the interrupt
* controller.
* @param set Interrupt Type 0 level ,1 edge
* @param Interrupt Polarity 1 rising or high level ,0 falling or low level
* @param Interrupt Any Edge Sensitive 0 single edge, 1 both edge
* Enable rising edge interrupts for all the pins in bank 2.
*/ XGpioPs_SetIntrType(Gpio, , 0xffffffff, 0xFFFFFFFF, 0x00); // rising edge only /*
* Set the handler for gpio interrupts.
*/
printf("Set the handler for gpio interrupts.\n\r");
XGpioPs_SetCallbackHandler(Gpio, (void *)Gpio, IntrHandler); /*
* Enable the GPIO interrupts of Bank 2.
*/
printf("Enable the GPIO interrupts of Bank 2.\n\r");
XGpioPs_IntrEnable(Gpio, , 0xffffffff); /*
* Enable the interrupt for the GPIO device.
*/
printf("Enable the interrupt for the GPIO device. \n\r");
XScuGic_Enable(GicInstancePtr, GpioIntrId); /*
* Enable interrupts in the Processor.
*/
printf("Enable interrupts in the Processor \n\r");
Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ); return XST_SUCCESS;
} /****************************************************************************/
/**
* This function is the user layer callback function for the bank 0 interrupts of
* the GPIO device. It checks if all the switches have been pressed to stop the
* interrupt processing and exit from the example.
*
* @param CallBackRef is a pointer to the upper layer callback reference.
* @param Status is the Interrupt status of the GPIO bank.
*
* @return None.
*
* @note None.
*
******************************************************************************/
static void IntrHandler(void *CallBackRef, int Bank, u32 Status)
{
// Is it necessary to close interrupt ?
printf("Enter interrupt \n\r"); /*
* Do nothing if the intr is generated for a different bank.
*/
if (Bank == ) { switch (Status)
{
// Get interrupt source
case :
printf("The trigger is EMIO GPIO 0 of bank %d \n\r", Bank);
break; }
} else {
return;
}
}
Zynq GPIO 中断的更多相关文章
- Linux Zynq GPIO中断
注册中断:对每个pin进行循环遍历for (pin_num = 0; pin_num < min_t(int, ZYNQ_GPIO_NR_GPIOS, (int)chip->ngpio) ...
- 在xilinxFPGA上使用microblaze及自写GPIO中断
很久很久没有更新过博客了,今天来扒一扒FPGA上CPU软核的使用. 主要完成的功能:使用的开发板是nexys 4 DDR,板上有16个switch以及16个LED,需要完成microblaze对led ...
- LPC1788的外部中断和GPIO中断
首先是gpio中断,这一点和1768不同,1768使用的中断时和eint3共用中断通道,到了1788,专门为gpio开辟了中断 #ifndef __JOYPAD_H_ #define __JOYPAD ...
- LPC1768外部中断与GPIO中断
LPC1768的外部中断严格来说只有四个,分别是EINT0,EINT1,EINT2,EINT3,技术手册上有如下说明 控制这四个外部中断靠以下寄存器 这三个寄存器的0 1 2 3位分别代表中断的0 1 ...
- esp8266 SDK开发之GPIO中断
先秀一下自己焊的板子,黑的开关用于复位,蓝的开关用于烧录程序. 首先要明确的是esp8622的大多数管脚都有多个功能, 比如可以用来当做GPIO管脚,还可以用来当做SPI管脚. 如下图所示 使用PIN ...
- TI-RTOS 之 GPIO中断(按键)
TI-RTOS 之 GPIO中断(按键) 前面已经用过LED, 定时器,这次来了解GPIO的中断是怎么用的,从CC1310+TI-RTOS的例程可以直接找到相应的例子程序,它的关键是在于要使能中断,也 ...
- MSP430 G2553 LaunchPad GPIO中断
P1.P2端口上的每个管脚都支持外部中断.P1端口的所有管脚都对应同一个中断向量(Interrupt Vector),类似的,P2端口的所有管脚都对应另一个中断向量:通过PxIFG寄存器来判断中断来源 ...
- S02_CH08_ ZYNQ 定时器中断实验
S02_CH08_ ZYNQ 定时器中断实验 上一章实现了PS接受来自PL的中断,本章将在ZYNQ的纯PS里实现私有定时器中断.每隔一秒中断一次,在中断函数里计数加1,通过串口打印输出. 8.1中断原 ...
- A20 GPIO中断类型差别结果迥异的问题思考
A20GPIO中断类型差别结果迥异的问题思考 最近在使用全志A20做开发时,发现在处理中断的时候,用电平触发模式,报中断比较乱,用边沿触发则很稳定,不会乱报.笔者感到比较困惑,笔者用电平触发写的cod ...
随机推荐
- C\C++宏大全
一.标准预定义宏The standard predefined macros are specified by the relevant language standards, so they are ...
- selenium+python自动化88-批量操作循环点击报错:Element not found in the cache - perhaps the page has changed since it was looked up
前言 selenium定位一组元素,批量操作循环点击的时候会报错:Element not found in the cache - perhaps the page has changed since ...
- PhpStorm 对 AngularJS 的支持
非常喜爱用AngularJS来构建web应用程序的前端吗? PhpStorm 使得在其上进行 AngularJS 相关的工作同其它得到IDE支持的编程语言的工作一样容易! AD:51CTO首届中国AP ...
- Add Two Numbers(from leetcode python 链表)
给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 -& ...
- Vue侦听器watch
虽然计算属性在大多数情况下更合适,但有时也需要一个自定义的侦听器.这就是为什么 Vue 通过 watch 选项提供了一个更通用的方法,来响应数据的变化.当需要在数据变化时执行异步或开销较大的操作时,这 ...
- yaha分词
yaha分词:https://github.com/jannson/yaha
- CCPlatformConfig(设置执行平台 iOS android win32等。。。)
#ifndef __CC_PLATFORM_CONFIG_H__ #define __CC_PLATFORM_CONFIG_H__ /** Config of cocos2d-x project, p ...
- 解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a severe error has occured)
如题 解决方案如下: 1.先把eclipse关闭.2.在管理器转到你的android SDK 的platform-tools下3.键入adb kill-server ,如果adb关闭了会提示 serv ...
- Git学习笔记一--创建版本库、添加文件、提交文件等
Git,是Linus花了两周时间用C写的一个分布式版本控制系统.牛该怎么定义? 其实,很多人都不care谁写了Git,只在乎它是免费而且好用的!So do I! 下面开始我们的学习: 1.Git安装( ...
- freemarker的list指令小技术归纳
1.问题:当数据超过3位的时候,freemarker会自动用逗号截取,例如2,311 解决方法(一种即可): (1)加.toString(),如:${(data).toString()} (2)加?c ...