Skip to content
Snippets Groups Projects
Commit 41ac76ff authored by Florent Gluck's avatar Florent Gluck
Browse files

Updated course/12-Linux_device_drivers.pdf

Added labs/lab06-gpio_driver.pdf
parent 8e16ca52
No related branches found
No related tags found
No related merge requests found
No preview for this file type
File added
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/interrupt.h>
#include <linux/gpio.h>
// Operation prototypes
static int dev_open(struct inode *, struct file *);
// The driver's file operations
static const struct file_operations fops = {
.owner = THIS_MODULE,
.open = dev_open
};
/**
* Driver initialization code.
*/
static int __init xxx_dev_init(void) {
// TODO
// 1) Register the device by dynamically obtaining a major number
// 2) Create the class
// 3) Create the device in /dev
// 6) Request the necessary GPIOs
// 7) Register an IRQ handler per GPIO
pr_info("xxx: driver initialized\n");
return 0;
}
/**
* This function is called when the module is unloaded.
*/
static void __exit xxx_dev_exit(void) {
// TODO
// 1) Destroy the device
// 2) Destroy the class
// 4) Unregister the device
// 5) Free the IRQs
// 6) Free the GPIOs
pr_info("xxx: driver destroyed\n");
}
/**
* Open operation
*/
static int dev_open(struct inode *inod, struct file *f) {
pr_info("xxx: device opened\n");
return 0;
}
/**
* Joystick left IRQ handler
*/
static irqreturn_t mylab_left_irq_handler(int irq, void *dev_id) {
// TODO
// - Operations to be done when the left position of the joystick is triggered
// - At minimum, the joystick state must be updated
return (irqreturn_t) IRQ_HANDLED; // Announce that the IRQ has been handled correctly
}
module_init(xxx_dev_init);
module_exit(xxx_dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jaime Coder <jaime.coder@hesge.ch>");
MODULE_DESCRIPTION("template module");
MODULE_VERSION("0.1");
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment