element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • 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 Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development How to detect and handle UIO interrupt.
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 4 replies
  • Subscribers 315 subscribers
  • Views 868 views
  • Users 0 members are here
Related

How to detect and handle UIO interrupt.

1saadzia
1saadzia over 7 years ago

Dear Experts

I need help regarding interrupt handling using UIO. I am using Vivado 2015.4 and Petalinux 2015.4. The board used is Zedboard.

I made the following vivado project attached as image. The interrupts from AXI and Fabric (PL-PS) are enabled. 

Afterwards i was able to export it as UIO and it shows in /dev as uio0.

My code is as follows: 
 

/* 
 * File:   main.c
 * Author: fss
 *
 * Created on August 23, 2017, 12:35 PM
 */
#include <sys/mman.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <poll.h>
#include <fcntl.h>
#include <errno.h>

#define GPIO_DATA_OFFSET 0x00 
#define GPIO_TRI_OFFSET 0x04 
#define GPIO_DATA2_OFFSET 0x08 
#define GPIO_TRI2_OFFSET 0x0C 
#define GPIO_GLOBAL_IRQ 0x11C 
#define GPIO_IRQ_CONTROL 0x128 
#define GPIO_IRQ_STATUS 0x120

unsigned int get_memory_size(char *sysfs_path_file)
{ 
    FILE *size_fp; 
    unsigned int size; 
    // open the file that describes the memory range size that is based on the 
    // reg property of the node in the device tree 
    size_fp = fopen(sysfs_path_file, "r"); 
    if (size_fp == NULL) { 
        printf("unable to open the uio size file\n"); 
        exit(-1); 
    } 
    // get the size which is an ASCII string such as 0xXXXXXXXX and then be stop 
    // using the file 
    fscanf(size_fp, "0x%08X", &size); 
    fclose(size_fp); 
    return size; 
} 


void reg_write(void *reg_base, unsigned long offset, unsigned long value) 
{ 
    *((volatile unsigned long *)(reg_base + offset)) = value; 
} 

unsigned long reg_read(void *reg_base, unsigned long offset) 
{ 
    return *((volatile unsigned long *)(reg_base + offset)); 
} 

uint8_t wait_for_interrupt(int fd_int, void *gpio_ptr) 
{ 
    static unsigned int count = 0, bntd_flag = 0, bntu_flag = 0; 
        int flag_end=0;
    int pending = 0; 
    int reenable = 1; 
    unsigned int reg; 
    unsigned int value; 
    // block (timeout for poll) on the file waiting for an interrupt 
    struct pollfd fds = {
        .fd = fd_int,
        .events = POLLIN,
    };

    int ret = poll(&fds, 1, 100);
    printf("ret is : %d\n", ret);
    if (ret >= 1) {
        read(fd_int, (void *)&reenable, sizeof(int));   // &reenable -> &pending
        // channel 1 reading 
        value = reg_read(gpio_ptr, GPIO_DATA_OFFSET); 
        if ((value & 0x00000001) != 0) { 
                    printf("Interrupt recieved");
        } 
    
        count++; 
        usleep(50000); // anti rebond 
        if(count == 10) 
            flag_end = 1; 
        // the interrupt occurred for the 1st GPIO channel so clear it 
        reg = reg_read(gpio_ptr, GPIO_IRQ_STATUS); 
        if (reg != 0) 
            reg_write(gpio_ptr, GPIO_IRQ_STATUS, 1);  
        // re-enable the interrupt in the interrupt controller thru the 
        // the UIO subsystem now that it's been handled 
        write(fd_int, (void *)&reenable, sizeof(int));
    } 
    return ret;
} 


int main(void)
{
    
    int fd = open("/dev/uio0", O_RDWR);
    if (fd < 0) {
        perror("open");
        exit(EXIT_FAILURE);
    }
    int gpio_size = get_memory_size("/sys/class/uio/uio0/maps/map0/size");
    /* mmap the UIO devices */
    void * ptr_axi_gpio = mmap(NULL, gpio_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
    while (1) 
    {
       wait_for_interrupt(fd,ptr_axi_gpio); 
    }

    close(fd);
    exit(EXIT_SUCCESS);
}

 

But the issue is that this code is not catching the interrupt. Kindly help me in this. Any suggestion/links are more than welcomed

Regards


Fullscreen contentimage_86636.html Download
<html><head><title>Jive SBS</title></head>
<body><font face="arial,helvetica,sans-serif">
<b>Error</b><br><font size="-1">
An general error occurred while processing your request.
</font></font></body></html>
  • Sign in to reply
  • Cancel
  • 1saadzia
    0 1saadzia over 7 years ago

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • 1saadzia
    0 1saadzia over 7 years ago

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • 1saadzia
    0 1saadzia over 7 years ago

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • jafoste4
    0 jafoste4 over 7 years ago

    Hello saadzia,

    Please ask your question over at Digilent as they are the main point of contact for educational support.

    --Josh

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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 © 2025 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

  • X
  • Facebook
  • linkedin
  • YouTube