3

I'm trying to get an interrupt whenever the UART line gets data on the BeagleBone Black. However, I'm stuck on figuring out how to register the handler. I can use request_irq() to register GPIO interrupts for example, but trying to get the irq for the UART doesn't seem to work. I believe 73 is the right number, as after registering it, reading from /dev/ttyO1 (the UART dev file) throws an error, but the handler never triggers.

Am I approaching this right? What I'm currently trying is below. Thanks.

#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <asm/io.h>

#define KERNEL_NAME "TestKernel"
#define IRQ_NUMBER 73

int id = 8273643;

irq_handler_t handler(int irq, void* dev_id, struct pt_regs* regs)
{
    printk(KERN_ALERT KERNEL_NAME ": Handler called, irq: %d\n",  irq);
    return (irq_handler_t)IRQ_HANDLED;
}

static int __init driver_entry(void)
{
    int result = request_irq(IRQ_NUMBER, (irq_handler_t)handler, 0, "test", &id);
    printk(KERN_ALERT KERNEL_NAME ": Insert successful, result: %d\n", result);
    return result;
}

static void __exit driver_exit(void)
{
    free_irq(IRQ_NUMBER, NULL);
    printk(KERN_ALERT KERNEL_NAME ": Cleanup\n");
}

module_init(driver_entry);
module_exit(driver_exit);

MODULE_LICENSE("GPL");
Iluvatar
  • 1,537
  • 12
  • 13
  • You are loading the module, right? You might creating a driver which takes the IRQ number as a parameter and experiment with different numbers. – wallyk Dec 07 '16 at 04:04
  • Is the UART already configured to signal? Usually the driver has to initialize the UART as well as connect the GPIO to the UART. – wallyk Dec 07 '16 at 04:05
  • Yes, it's being loaded fine (seen with `dmesg`). Hm, is initializing something like what's happening in http://stackoverflow.com/questions/16594098/interrupts-in-uart-16550-and-linux-kernel? And what do mean connect the GPIO to the UART? – Iluvatar Dec 07 '16 at 04:07
  • 1
    Yes, UART initialization is needed to turn on the receiver, set the speed, framing characteristics, etc. I am not familiar with beagle, but typically small single board computers need to have devices enabled and if they are not hardwired (UART to CPU), then some logic needs to be configured. This is especially true on [SoC](https://en.wikipedia.org/wiki/System_on_a_chip) where there are maybe 5+ modes available for each GPIO. – wallyk Dec 07 '16 at 04:47

0 Answers0