77.PS receiving key interrupts from PL

Source: Internet
Author: User

This article mainly introduces the interrupt request generated by the peripheral (PL), which is processed on the PS side.
At the PL end, the interrupt is generated by the key, and the PS is lit to illuminate the corresponding led.

The development Board used in this article is Zedboard
PC Development Environment Version: Vivado 2015.4 Xilinx SDK 2015.4

After building the hardware engineering, add ZYNQ IP double-click ZYNQ, open the Re-customize IP dialog box, enable irq_p2p

Enable to UART1

Click Run Connection Automation, follow the configuration, click OK

Add a Gpio IP, as configured, to enable interrupts. Click Run Connection Automation

Add a Gpio IP, follow the configuration, click OK

Axi_gpio_0 ip2intc_irpt and Zynq PS irq_f2p[0:0] connected together to build a good hardware system connection,

Generate a top-level file, click Generate Bitstream Software engineering to create a new Hello World project, add the following code
1#include <stdio.h>2#include"platform.h"3#include"Xparameters.h"4#include"xscugic.h"5#include"Xil_exception.h"6#include"xgpio.h"7 8 //parameter Definitions9 #defineintc_device_id xpar_ps7_scugic_0_device_id//device_id used to initialize functions, index array elementsTen #defineled_device_id xpar_axi_gpio_1_device_id One #definebtns_device_id xpar_axi_gpio_0_device_id A #defineintc_gpio_interrupt_id Xpar_fabric_axi_gpio_0_ip2intc_irpt_intr - #defineBtn_int Xgpio_ir_ch1_mask - #defineDELAY 100000000 the  - Xgpio LED; - Xgpio Btninst; - xscugic Intcinst; + Static intBtn_value; -  + //Function Protype A Static voidBtn_intr_handler (void*baseaddr_p); at Static intInterruptsystemsetup (Xscugic *xscugicinstanceptr); - Static intIntcinitfunction (U16 Deviceid,xgpio *gpioinstanceptr); -  - voidBtn_intr_handler (void*instanceptr) - { -UnsignedCharLed_val=0; in     //Ignore Additional button presses -     if((Xgpio_interruptgetstatus (&btninst) & btn_int)! =btn_int) to     { +         return; -         //Disable GPIO Interrupts theXgpio_interruptdisable (&btninst,btn_int); *     } $Btn_value = Xgpio_discreteread (&btninst,1);Panax Notoginseng     Switch(Btn_value) -     { the      Case 1: Led_val =0x01; Break;//led[7:0]=0x01 +      Case 2: Led_val =0x02; Break; A      Case 4: Led_val =0x03; Break;//Bright 1 and 2 the      Case 8: Led_val =0x04; Break; +      Case  -: Led_val =0x05; Break;//Bright 0 and 2 -     default: Break; $     } $  -Xgpio_discretewrite (&led,1, led_val); -     //acknowledge GPIO interrupts the(void) Xgpio_interruptclear (&btninst,btn_int); -     //Enable GPIO InterruptsWuyiXgpio_interruptenable (&btninst,btn_int); the } -  Wu intMainvoid) - { About     intstatus; $  -     //Key Initialization -Status = Xgpio_initialize (&btninst,btns_device_id); -     if(Status! = xst_success)returnxst_failure; A  +     //Initializing LEDs theStatus = Xgpio_initialize (&led,led_device_id); -     if(Status! = xst_success)returnxst_failure; $  the     //set the key IO direction to input theXgpio_setdatadirection (&btninst,1,0xFF); the     //set the direction of the LED IO to output theXgpio_setdatadirection (&led,1,0x00); -  in     //initializing the interrupt controller theStatus = Intcinitfunction (intc_device_id,&btninst); the     if(Status! = xst_success)returnxst_failure; About  the      while(1){} the  the     return 0; + } -  the intIntcinitfunction (U16 Deviceid,xgpio *gpioinstanceptr)Bayi { theXscugic_config *Intcconfig; the     intstatus; -  -     //Interrupt Controller Initialization theIntcconfig =Xscugic_lookupconfig (DeviceId); theStatus = Xscugic_cfginitialize (&INTCInst,IntcConfig,IntcConfig->cpubaseaddress); the     if(Status! = xst_success)returnxst_failure; the  -     //Call Interrupt Setup function theStatus = Interruptsystemsetup (&intcinst); the     if(Status! = xst_success)returnxst_failure; the 94     //Register GPIO Interrupt Handler theStatus = Xscugic_connect (&intcinst,intc_gpio_interrupt_id, (Xil_exceptionhandler) Btn_intr_handler, (void*) gpioinstanceptr); the     if(Status! = xst_success)returnxst_failure; the 98     //Enable GPIO Interrupts AboutXgpio_interruptenable (Gpioinstanceptr,1); - xgpio_interruptglobalenable (gpioinstanceptr);101 102     //Enable GPIO interrupts in the controller103Xscugic_enable (&intcinst,intc_gpio_interrupt_id);104  the     returnxst_success;106 }107 108 intInterruptsystemsetup (Xscugic *xscugicinstanceptr)109 { the     //Register GIC Interrupt Handler111 Xil_exceptionregisterhandler (Xil_exception_id_int, (Xil_exceptionhandler) Xscugic_interrupthandler, XSCUGICINSTANCEPTR); the xil_exceptionenable ();113  the     returnxst_success; the}
After the download, press the button to see the corresponding LED is lit

77.PS receiving key interrupts from PL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.