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 ...
随机推荐
- TCP协议中的重传、慢启动、SACK、窗口的概念
重传机制 慢启动相关的几个状态说明该 SACK机制 窗口在TCP传输机制中的作用
- simple_strtoul()
//此函数有以下几点值得注意: //1.第一个参数中的const.一般在函数的形参中,如果我们只是希望调用者使用该参数,而不会去改变该参数 // 内容(一般是指针指向的内容),则可以声明为co ...
- 【JSP JSTL】<c:if>多个判断条件 + <c:foreach>满足条件跳出循环
有一个需求,将所拥有的权限存放于session中,现在JSP页面判断这些如果在所有权限中有某一个或者某几个,就显示相对应的页面内容 举一个例子,实现以上的逻辑,<c:if>多个判断条件 + ...
- 粗览Activiti Modeler操作和源代码
Activiti Model Editor组件 我的 了解ActivitiExplorer及其Vaadin实现方式博文里提到ActivitiExplorer使用的是Vaadin架构,但是Activit ...
- XenApp应用虚拟化介绍
https://wenku.baidu.com/view/635223c26137ee06eff91864.html
- 支持解析GitHub Flavored Markdown(GFM)的PHP库-Parsedown
网上搜索PHP的markdown解析库,只能找得到Michel的PHP Markdown,这个库很不错,但是他只能支持标准markdown和他自己定义的一套扩展php Markdown Extra.这 ...
- Less的安装与配置
Less的安装与配置 Less与Sass 先说一段题外话,很多初学者在选择CSS 预处理语言不免会感到犹豫,作为CSS 的两大预处理语言Less与Sass,各自都有着很广泛的使用群体,我究竟该选哪个好 ...
- ISP图像调试工程师——tone Mapping(ISP)
http://www.cnblogs.com/bigbigtree/p/3458797.html
- java 获取进程的processId
package us.mine.demo.jvm.util; import java.lang.management.ManagementFactory; import java.lang.manag ...
- Java 8 Stream 教程
Java 8 Stream Tutorial 本文采用实例驱动的方式,对JAVA8的stream API进行一个深入的介绍.虽然JAVA8中的stream API与JAVA I/O中的InputStr ...