element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
Personal Blogs
  • Members
  • More
Personal Blogs
Legacy Personal Blogs Zynq: Custom IP IRQ
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Blog Post Actions
  • Subscribe by email
  • More
  • Cancel
  • Share
  • Subscribe by email
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: dhmarinov
  • Date Created: 5 Mar 2019 9:21 AM Date Created
  • Views 1582 views
  • Likes 3 likes
  • Comments 2 comments
  • zynq
  • custom ip
  • interrupts
Related
Recommended

Zynq: Custom IP IRQ

dhmarinov
dhmarinov
5 Mar 2019

Hello there,

 

          Recently I had to work with the interrupt features of Zynq and encountered some challenges.

Thankfully I managed to solve them so I decided to share the information in case other people encounter the same issue.

I know there are a lot of tutorials out there that explain how the interrupts work and how to set them up,

however, most of them describe how to connect interrupt coming from Xilinx IP or from PS peripheral.

Unfortunately there are some things that are not that obvious when having an interrupt from a custom IP.

For this example the setup is very simple – the PS and a counter, which sends one 10ns pulse each second.

image

Packaging the IP

 

No matter what the IP is doing the most important thing when packaging is to declare the output pin as an interrupt.

This happens by right-clicking on the pin and interring it as interrupt.

 

image

 

Once this is done, the signal can be connected to the PS. If this step is skipped then the interrupt will not show in the xparameters.h,

which means that the user cannot include it in the IRQ functionality in the software part.  Therefore the IP has to be re-packaged.

image

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

 

Connecting to the GIC

 

I’m not going to describe how the interrupts work in detail, however, if you are interested, you can check out the following tutorial.

In an essence when configuring the GIC there is a lot of Xilinx defined code that can be reused, no matter where the IRQ comes from or what is it supposed to do.

In fact the most important piece of code is the XScuGic_Connect function.

image

This is used to connect the interrupt source to the GIC and the IRQ handler (i.e. the function that should be executed once the interrupt is received).

The first parameter is pointer to the GIC instance, the second is the ID of the IRQ source, the third is the handler and the fourth is a callback reference.

image

 

The problem I encountered here is the last parameter of the function. If you look through the above mentioned tutorial you will see that the argument is an instance of the peripheral (&my_Timer).

The problem is that such an instance does not exist if you have a custom IP. It took me a while to found out what to do. It turns out the answer is quite simple - put it to 0.

And it works!!!

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

I have included a screenshot of the code, but if you want to try it yourself, then you can fetch it from my Github.

 

image

 

Thanks for the attention and have fun!

  • Sign in to reply
  • dhmarinov
    dhmarinov over 2 years ago

    Hi Victor,

     

    The code looks fine, but the problem may be in the hardware - did you make sure that the interrupt source is maked as suck i.e. when packaging the IP you have to indicate that the interrup is such a signal.

    You can find out whether that has been done correctly if you find the interrup in the xparameters.h.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • vricardoas
    vricardoas over 2 years ago

    Dear Dimitar,

    I highly appreciate your post, it is very informative.

    It is been a while that I have a similar problem, and I still have it!!

    I tried what you said on your post, however it did not worked for me.

    I have made a Custom IP and I want to use the interrupt services, but I am not able to generate any interrupt from my Custom IP. At this point I am not sure if the problem is related with the SW or with the HW vhdl Template.

    I include my code, so if you have a chance, please check it and tell me if you found my mistake.

    Thank you very much in advance,

    Kind Regards,

    Victor.

     

    #include <stdio.h>

    #include <stdlib.h>

    #include <unistd.h>

    #include "xil_printf.h"

    //#include "./LFSR_HY_v1_0/src/LFSR_HY.h"

    #include "LFSR_HY_INT_Driver.h"

    #include "xparameters.h"

    /***********For interruption***********/

    #include "xscugic.h"

    #include "xil_exception.h"

    /***********DEFINES***********/

    //LFSR

    #define LFSR_HY_INT_BASE_ADDR        XPAR_LFSR_HY_INT_0_S00_AXI_BASEADDR

    #define S_Freq_Div_Select     LFSR_HY_INT_S00_AXI_SLV_REG0_OFFSET

    #define S_UpDown             LFSR_HY_INT_S00_AXI_SLV_REG1_OFFSET

    #define S_trig                 LFSR_HY_INT_S00_AXI_SLV_REG2_OFFSET

    #define S_seq                 LFSR_HY_INT_S00_AXI_SLV_REG3_OFFSET

    #define S_registro             LFSR_HY_INT_S00_AXI_SLV_REG4_OFFSET

    #define S_Clk_seq             LFSR_HY_INT_S00_AXI_SLV_REG5_OFFSET

     

    #define LFSR_HY_INT_DEVICE_ID         XPAR_LFSR_HY_INT_0_DEVICE_ID

    #define LFSR_HY_INT_INTERRUPT_ID     XPAR_FABRIC_LFSR_HY_INT_0_IRQ_INTR

    //SCUGIC

    #define INTC_DEVICE_ID        XPAR_PS7_SCUGIC_0_DEVICE_ID

    //---------------------Structure declarations-----------------------------//

    XScuGic INTC_inst;                //An instance of global interrupt controller

    LFSR_HY_INT LFSR_HY_INT_inst;    //An instance of our custom IP

    //-----------------------Prototype functions------------------------------//

    void LFSR_HY_INT_Handler(void *CallbackRef);

    void XScuGicSetup();

    //------------------------Interrupt Handler-------------------------------//

    void LFSR_HY_INT_Handler(void *CallbackRef){

        xil_printf("\r\n Interrupt Handler");

        //Disable the interrupt

        LFSR_HY_INT_DisableInterrupt(&LFSR_HY_INT_inst, 0x1);

        xil_printf("\r\n Interrupt Disable");

        //ACK the interrupt

        LFSR_HY_INT_ACKInterrupt(&LFSR_HY_INT_inst, 0x1);

        xil_printf("\r\n ACK Interrupt");

        //Enable the interrupt

        LFSR_HY_INT_EnableInterrupt(&LFSR_HY_INT_inst, 0x1);

        xil_printf("\r\n Interrupt Enable");

    }

    //------------------------Interrupt Controller Setup-------------------------------//

    void XScuGicSetup(){

     

        /* Initialize the interrupt controller driver so that it is ready to use.*/

        static XScuGic_Config * IntcConfig;

        IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);

        XScuGic_CfgInitialize(&INTC_inst, IntcConfig, IntcConfig->CpuBaseAddress);

     

        //Enable our custom interrupt

        LFSR_HY_INT_EnableInterrupt(&LFSR_HY_INT_inst, 0x1);

        LFSR_HY_INT_GlobalEnableInterrupt(&LFSR_HY_INT_inst, 0x1);

        /*

         * Connect the interrupt controller interrupt handler to the hardware

         * interrupt handling logic in the ARM processor.

         */

        Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,

                                    (Xil_ExceptionHandler)XScuGic_InterruptHandler,

                                    (void*)&INTC_inst);

        Xil_ExceptionEnable(); //Enable interrupts in the ARM

        /*

        * Connect a device driver handler that will be called when an

        * interrupt for the device occurs, the device driver handler performs

        * the specific interrupt processing for the device

        */

        XScuGic_Connect(&INTC_inst,

                        LFSR_HY_INT_INTERRUPT_ID,

                        (Xil_ExceptionHandler)LFSR_HY_INT_Handler,  //Xil_InterruptHandler

                        0);

     

        //Enable our custom interrupt AGAIN...

        LFSR_HY_INT_EnableInterrupt(&LFSR_HY_INT_inst, 0x1);

        LFSR_HY_INT_GlobalEnableInterrupt(&LFSR_HY_INT_inst, 0x1);

        //Enable Global Interrupt Controller

        XScuGic_Enable(&INTC_inst, LFSR_HY_INT_INTERRUPT_ID);

        xil_printf("\r\n Interrupt Ready To Go!!");

    }

     

    int main()

    {

        /* LFSR driver initialization */

        //LFSR_HY_INT_Reg_SelfTest((void *) LFSR_HY_INT_BASE_ADDR); //checks the read/write registers

        LFSR_HY_INT_mWriteReg(LFSR_HY_INT_BASE_ADDR, S_Freq_Div_Select, 0);

        LFSR_HY_INT_mWriteReg(LFSR_HY_INT_BASE_ADDR, S_UpDown, 0);

     

        u32 reloj = 0;

        u32 trigger = 0;

        u32 sequence = 0;

        u32 registro = 0;

     

        xil_printf("Serial Connection started.\n\r");

        LFSR_HY_INT_Init(&LFSR_HY_INT_inst, LFSR_HY_INT_BASE_ADDR);

        XScuGicSetup();

        while(1){

        }

     

    return 0;

    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube