4

I am trying to write a simple Linux kernel module that uses an existing I2C module. The existing i2c module requires an irq number (passed in through a i2c_board_info struct), which the i2c module then passes as the first parameter to request_threaded_irq(...).

I want that the irq I pass in is being triggered periodically (say, every 100ms), and I thought a tasklet was the proper way to go, but I don't see any way of translating a tasklet to an irq number that can be passed to request_threaded_irq(). Am I going about this the wrong way? Is there even a way to do what I'm trying?

myaut
  • 11,174
  • 2
  • 30
  • 62
sbell
  • 457
  • 6
  • 13
  • 1
    Am I understand it correctly that it's a real irq that triggered by hardware, but you **also** want the same handler function (ISR) to be called every 100 ms? If so, do you want to do that in the same driver or outside of it? I mean, you can create timer inside of the same driver and just execute handler on your timer tick. It will do? – Sam Protsenko Apr 08 '15 at 22:10
  • @SamProtsenko No, I don't have a real irq (from hardware). I'm wanting a tasklet (or something else in software) to spoof an irq, which the existing i2c module could use instead. – sbell Apr 08 '15 at 22:14
  • Ah! You want to trigger interrupt manually, from software. Understood. – Sam Protsenko Apr 08 '15 at 22:21
  • [Here](http://stackoverflow.com/questions/27865075/how-would-one-go-about-generating-artificial-interrupts-in-the-linux-kernel) is very similar question. But answers are overwhelming a bit, I guess. I would look into `do_IRQ()` function: if it's possible to generate interrupt using it, the rest can be done using regular timer. – Sam Protsenko Apr 08 '15 at 22:32
  • Ok, try this: **1**. Create kernel timer, like it described [here](http://stackoverflow.com/a/11098287/3866447). **2**. In timer handler generate your interrupt manually (via `do_IRQ()` on x86 or via `handle_IRQ()` on ARM). See details [here](https://www.safaribooksonline.com/library/view/understanding-the-linux/0596002130/ch04s06.html). If you manage to do so, please share your code as answer. If no -- add comment saying so and I will do that for you. Just don't want to ruin all the fun. Maybe I also a bit lazy :-D – Sam Protsenko Apr 08 '15 at 22:56
  • @SamProtsenko Thanks, I'll try this when I get in to work tomorrow – sbell Apr 08 '15 at 22:59
  • 1
    @SamProtsenko I couldn't get that to work. I ended up just hacking the original i2c module to remove the irq, and added a timer at that level. – sbell Apr 13 '15 at 19:34

0 Answers0