Userspace I/O

From krtkl wiki
Revision as of 02:56, 25 January 2018 by Bush (talk | contribs) (Created page with "==== Boot Arguments ==== <pre>uio_pdrv_genirq.of_id=krtkl,generic-uio,ui_pdrv</pre> ==== Device Tree Bindings ==== <pre> axi_gpio0: gpio@41200000 { reg = <0x4120000...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Boot Arguments

uio_pdrv_genirq.of_id=krtkl,generic-uio,ui_pdrv

Device Tree Bindings

axi_gpio0: gpio@41200000 {
        reg = <0x41200000 0x10000>;
        compatible = "krtkl,generic-uio,ui_pdrv";
        interrupt-parent = <&intc>;
        interrupts = <0 29 4>; 
};

Application Interface

/* Open the UIO device */
fd = open("/dev/uio0", O_RDWR | O_SYNC);

/* Map the memory */
iomem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);

/* Close the UIO device */
close(fd);

/* Apply the offset to the memory */
iomem += offset / sizeof(void *);

/* Point structure to memory */
dev = (struct peripheral *)iomem;

/* Perform read/write operations using structure pointer */
dev->ier = (1 << 0);

/* Unmask the interrupt */
en = 1;
write(fd, &en, sizeof(en));

/* Wait for an interrupt with blocking read */
read(fd, &nirq, sizeof(nirq));

/* Handle the interrupt */
if (nirq) {
        stat = dev->isr;           /* Read interrupt  status */
        if (stat)
                dev->isr = stat;   /* Clear interrupt on device */

        data = dev->data;
}

/* Unmap the memory when finished */
munmap(iomem, size);

fd = open("/dev/uio0", O_RDWR | O_SYNC);

/* Map the Nth memory map by specifying offset of N * PAGE_SIZE */
iomem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, PAGE_SIZE);

close(fd);

/* Perform memory operations */
msync(iomem, size, MS_SYNC);

munmap(iomem, size);