Pages

Saturday, June 7, 2014

Using Raspberry Pi's GPIO as an interrupt source III

In my previous experiments using the GPIO as our interrupt source, I merely respond to interrupts by printing a kernel message whenever the tasklet is executed.

On this experiment, I'll explore another way of handling hardware interrupts by using a threaded irq. This threaded irq isr is different from a normal isr, this now allows us to communicate with much slower hardware such as the ones connected via the i2c bus. 

You can get the source code for this here.

I've stripped down the original chip_i2c driver to provide only sysfs attributes (chip_led and chip_switch), it does not anymore provide the char device functionality. I also removed some mutex (as mutex are bad when used from within an isr context), instead I rely mostly on the assumption that there is only one device that maybe controlling the smbus (master) at any one point of time - I maybe wrong here, so please hit comments.

Again to get the module working, we need to add the i2c board info for this in the board setup routine described in my previous blog. I2C doesn't support enumeration the likes of usb and pci, so the kernel needs to know about the device beforehand, otherwise the device won't be loaded into the kernel. Details on the board setup and the original chip_i2c driver is here.



No comments: