UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Participant kvkhekale
Participant
308 Views
Registered: ‎11-17-2018

PS GPIO interrupt using UIO driver

Hello All,

I want to configure interrupts on PS GPIO in the userspace.

The interrupts will occur on the press of switch/button. 

I have included "gpio-keys" & "generic-uio" node in the device tree.

 

/include/ "system-conf.dtsi"
/ {
	psgpio: gpio@e000a000 {
	compatible = "xlnx,zynq-gpio-1.0";
	#gpio-cells = <2>;
	clocks = <&clkc 42>;
	emio-gpio-width = <64>;
	gpio-controller;
	interrupt-parent = <&intc>;
	interrupts = <0 20 4>;
	reg = <0xe000a000 0x1000>;
	};

	gpio-keys {
	compatible = "gpio-keys";
	#address-cells = <1>;
	#size-cells = <0>;
	autorepeat;
	sw54 {
	label = "sw50";
	gpios = <&gpio0 54 0>;
	linux,code = <108>; /* down */
	gpio-key,wakeup;
	autorepeat;
	};
	sw55 {
	label = "sw51";
	gpios = <&gpio0 55 0>;
	linux,code = <109>;
	gpio-key,wakeup;
	autorepeat;
	};
};

	gpio-leds {
    	compatible = "gpio-leds";
    	led-ds23 {
        label = "led-ds23";
        gpios = <&gpio0 58 0>;
        default-state = "on";
        linux,default-trigger = "heartbeat";
    	};
};

	uio0{ 
	compatible="generic-uio"; 
	status="okay"; 
	interrupt-controller; 
	interrupt-parent=<0x4>; 
	interrupts=<0x0 0x1e 0x4>;
	linux,code = <110>;
	reg = <0xe000a000 0x1000>;
	};

};

 

 

I have also changed kernel bootargs to following value.

Screenshot from 2019-05-21 11-58-48.png

 

I can see uio entry along with the switches in /proc/interrupts.

Screenshot from 2019-05-21 12-00-59.png

 

I can see uio entry inside /sys/class/uio/uio0 and /dev/uio

I have attached the code which I am running for getting interrupt on uio upon switch press.

The c code under execution doesnt cross the "read" call (Line No. 56, below the comment "wait for read").

#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>

#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>

#define UIO_DEVICE    "/dev/uio0"
#define MMAP_SIZE     0x1000

int main(int argc, char* argvp[])
{
  int retCode = 0;
  int uioFd;
  volatile uint32_t* counters;

  // Open uio device
  uioFd = open(UIO_DEVICE, O_RDWR);
  if(uioFd < 0)
  {
    fprintf(stderr, "Cannot open %s: %s\n", UIO_DEVICE, strerror(errno));
    return -1;
  }

  // Mmap memory region containing counters value
  counters = mmap(NULL, MMAP_SIZE, PROT_READ, MAP_SHARED, uioFd, 0);
  if(counters == MAP_FAILED)
  {
    fprintf(stderr, "Cannot mmap: %s\n", strerror(errno));
    close(uioFd);
    return -1;
  }

  // Interrupt loop
  while(1)
  {
    uint32_t intInfo;
    ssize_t readSize;
    // Acknowldege interrupt
    intInfo = 1;
    printf("Mmap done, waiting to write.. \n");
    if(write(uioFd, &intInfo, sizeof(intInfo)) < 0)
    {
      fprintf(stderr, "Cannot acknowledge uio device interrupt: %s\n",
        strerror(errno));
      retCode = -1;
      break;
    }

    // Wait for interrupt
    printf("Write done, waiting to read.. \n");
    readSize = read(uioFd, &intInfo, sizeof(intInfo));
    if(readSize < 0)
    {
      fprintf(stderr, "Cannot wait for uio device interrupt: %s\n",
        strerror(errno));
      retCode = -1;
      break;
    }

    // Display counter value
    printf("We got %lu interrupts, counter value: 0x%08x\n",
      intInfo, counters[0]);
  }

  // Should never reach
  munmap((void*)counters, MMAP_SIZE);
  close(uioFd);

  return retCode;
}

Even after manually watching /proc/interrupts, I am not getting uio count incremented on switch press. Following is the screenshot after both the switches are pressed.

Screenshot from 2019-05-21 12-04-29.png

 

 

 

The main thing I am not gettign here is about linking of uio driver to gpio driver ("gpio-keys", in this case) 

How uio will come to know about the interrupts occuring at PS-GPIO?

Why i am not getting uio interrupts after a switch press?

Please let me know way through this. A little hint will also be helpful.

Tags (4)
0 Kudos