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 ...
随机推荐
- Inno Setup入门(二十四)——Inno Setup类参考(10)
这里介绍一下FolderTreeView 类. TFolderTreeView = class(TCustomFolderTreeView) property OnChange: TNotifyE ...
- 控制台+Owin搭建WebAPI接口服务
当没有iis环境.想快速启动几个api接口测试又觉得新建一个api项目麻烦?来使用控制台做宿主,快速改几个api测试吧! 1.新建控制台项目 2.安装以下相关依赖 Microsoft.AspNet.W ...
- 内核创建的用户进程printf不能输出一问的研究
转:http://www.360doc.com/content/09/0315/10/26398_2812414.shtml 一:前言上个星期同事无意间说起,在用核中创建的用户空间进程中,使用prin ...
- appium+python自动化50-生成定位对象模板templet(jinja2)
前言 每次自己写pageobject定位元素对象太繁琐,格式都差不多,只是换个定位方法,这种就可以才有模板的方式,批量生成pageobject定位元素对象的模板 python里面生成模板有两个模块可以 ...
- 使用神经网络识别手写数字Using neural nets to recognize handwritten digits
The human visual system is one of the wonders of the world. Consider the following sequence of handw ...
- NGUI自适应屏幕分辨率
unity官方承诺的新ui系统一直没有推出来,我们的UI使用的是原生的OnGUI系统,刚好UI需要改版,索性就想迁到NGUI上面来,于是看了一下NGUI源码,发现NGUI可以大大的降低DrawCall ...
- 流畅的python第七章函数装饰器和闭包学习记录
本章讨论的话题 python如何计算装饰器句法 python如何判断变量是不是局部的(通过函数内部是否给变量赋值过来判断是否是局部变量) 闭包存在的原因和工作原理(闭包是一种函数,它会保留定义函数时存 ...
- 【算法导论C++代码】最大子数组
#define Inf 65535 #include <iostream> using namespace std; void FindMaxCrossingSubarray(int *A ...
- 使用 session_destroy() 销毁session文件时 报 Trying to destroy uninitialized session 错误解决办法
在使用 sessio_destroy() 销毁session文件的时候,必须要先使用session_start() 来开启session 后才能删除session文件
- 转:让kindle更好的支持pdf
http://vislab.bjmu.edu.cn/blog/hwangxin/2012/10/read-scanned-pdfs-with-kindlepdfviewer/