/*
* 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 中断的更多相关文章

  1. Linux Zynq GPIO中断

    注册中断:对每个pin进行循环遍历for (pin_num = 0; pin_num < min_t(int, ZYNQ_GPIO_NR_GPIOS,  (int)chip->ngpio) ...

  2. 在xilinxFPGA上使用microblaze及自写GPIO中断

    很久很久没有更新过博客了,今天来扒一扒FPGA上CPU软核的使用. 主要完成的功能:使用的开发板是nexys 4 DDR,板上有16个switch以及16个LED,需要完成microblaze对led ...

  3. LPC1788的外部中断和GPIO中断

    首先是gpio中断,这一点和1768不同,1768使用的中断时和eint3共用中断通道,到了1788,专门为gpio开辟了中断 #ifndef __JOYPAD_H_ #define __JOYPAD ...

  4. LPC1768外部中断与GPIO中断

    LPC1768的外部中断严格来说只有四个,分别是EINT0,EINT1,EINT2,EINT3,技术手册上有如下说明 控制这四个外部中断靠以下寄存器 这三个寄存器的0 1 2 3位分别代表中断的0 1 ...

  5. esp8266 SDK开发之GPIO中断

    先秀一下自己焊的板子,黑的开关用于复位,蓝的开关用于烧录程序. 首先要明确的是esp8622的大多数管脚都有多个功能, 比如可以用来当做GPIO管脚,还可以用来当做SPI管脚. 如下图所示 使用PIN ...

  6. TI-RTOS 之 GPIO中断(按键)

    TI-RTOS 之 GPIO中断(按键) 前面已经用过LED, 定时器,这次来了解GPIO的中断是怎么用的,从CC1310+TI-RTOS的例程可以直接找到相应的例子程序,它的关键是在于要使能中断,也 ...

  7. MSP430 G2553 LaunchPad GPIO中断

    P1.P2端口上的每个管脚都支持外部中断.P1端口的所有管脚都对应同一个中断向量(Interrupt Vector),类似的,P2端口的所有管脚都对应另一个中断向量:通过PxIFG寄存器来判断中断来源 ...

  8. S02_CH08_ ZYNQ 定时器中断实验

    S02_CH08_ ZYNQ 定时器中断实验 上一章实现了PS接受来自PL的中断,本章将在ZYNQ的纯PS里实现私有定时器中断.每隔一秒中断一次,在中断函数里计数加1,通过串口打印输出. 8.1中断原 ...

  9. A20 GPIO中断类型差别结果迥异的问题思考

    A20GPIO中断类型差别结果迥异的问题思考 最近在使用全志A20做开发时,发现在处理中断的时候,用电平触发模式,报中断比较乱,用边沿触发则很稳定,不会乱报.笔者感到比较困惑,笔者用电平触发写的cod ...

随机推荐

  1. 基于tiny4412的Linux内核移植(支持device tree)(二)

    作者信息 作者: 彭东林 邮箱:pengdonglin137@163.com QQ:405728433 平台简介 开发板:tiny4412ADK + S700 + 4GB Flash 要移植的内核版本 ...

  2. SpringMVC_入门项目

    本项目是SpringMVC的入门项目,用于演示SpringMVC的项目配置.各层结构,功能较简单 一.Eclipse中创建maven项目 二.pom.xml添加依赖 1 2 3 4 5 6 7 8 9 ...

  3. UNICODE串转换成char类型串的四种方法

    1. 调用 WideCharToMultiByte() API int WideCharToMultiByte (     UINT    CodePage,                //1 U ...

  4. RawCap抓取本地回环接口数据包

    RawCap.exe --help ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 D: ...

  5. vue-cli 配置路由之间跳转传递参数

    1.有2种方式去传参,如下代码: <template> <div> <div>这里是首页</div> <router-link :to=" ...

  6. dbus启动失败:Couldn't connect to system bus: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

    在没有开启x窗口的shell下启动dbus相关程序时会如上错误,详细原因如下: This is not considered to be a bug. Auto-launching D-Bus ses ...

  7. Mac OS X 10.10 执行 Eclipse 提示须要安装 Java

  8. .Net Framemwork 之 值类型和引用类型的存储

    C#把数据类型分为两种:值类型 和 引用类型.值类型存储在堆栈中,而引用类型存储在托管堆上. 一.值类型和引用类型变量的存储 首先,变量是存储信息的基本单元,而对于计算机内部来说,变量就相当于一块内存 ...

  9. python中,== 与 is 之间区别

    在python中,== 与 is 之间既有区别,又有联系,本文将通过实际代码的演示,力争能够帮助读到这篇文章的朋友以最短的时间理清二者的关系,并深刻理解它们在内存中的实现机制. 扯淡的话不多说,下面马 ...

  10. vue - webpack.dev.conf.js for FriendlyErrorsPlugin

    描述:webpack网页端友好的报错信息就来自它 官网:https://www.npmjs.com/package/friendly-errors-webpack-plugin new Friendl ...