rename folder module
This commit is contained in:
@@ -1,29 +0,0 @@
|
|||||||
# Makefile
|
|
||||||
CC=gcc
|
|
||||||
CFLAGS = -W -Wall -pedantic -g -std=gnu99 -c
|
|
||||||
LDFLAGS = -static
|
|
||||||
RM = rm -f
|
|
||||||
|
|
||||||
TARGET = motor
|
|
||||||
OBJECTS = gpio.o
|
|
||||||
HEADERS = $(OBJECTS:.o=.h)
|
|
||||||
SOURCES = $(TARGET).c $(OBJECTS:.o=.c)
|
|
||||||
|
|
||||||
%.o: %.c
|
|
||||||
$(CC) $(CFLAGS) $< -o $@
|
|
||||||
|
|
||||||
.PHONY: all clean
|
|
||||||
|
|
||||||
all: $(TARGET)
|
|
||||||
|
|
||||||
clean:
|
|
||||||
$(RM) $(TARGET) $(TARGET).o $(OBJECTS) depend
|
|
||||||
|
|
||||||
depend: $(SOURCES) $(HEADERS)
|
|
||||||
$(CC) $(CPPFLAGS) -MM $(SOURCES) > $@
|
|
||||||
|
|
||||||
$(TARGET): $(TARGET).o $(OBJECTS)
|
|
||||||
$(CC) $(LDFLAGS) $^ -o $@
|
|
||||||
$(RM) depend $(TARGET).o $(OBJECTS)
|
|
||||||
|
|
||||||
include depend
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
static dev_t devno;
|
|
||||||
static struct cdev chardev;
|
|
||||||
static struct class *chardev_class;
|
|
||||||
static struct device *chardev_device[NUMBER_OF_MINOR_DEVICE];
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
MODULE_AUTHOR("Manuel Vögele, Siegfried Kienzle, Simon Wörner");
|
|
||||||
MODULE_DESCRIPTION(DEVICE_NAME "driver");
|
|
||||||
MODULE_LICENSE("GPL");
|
|
||||||
|
|
||||||
static int __init ModInit(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
printk(KERN_DEBUG DEVICE_NAME ": init");
|
|
||||||
|
|
||||||
if (alloc_chrdev_region(&devno, 0, NUMBER_OF_MINOR_DEVICE, DEVICE_NAME) < 0)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
cdev_init(&chardev, &fops);
|
|
||||||
chardev.owner = THIS_MODULE;
|
|
||||||
chardev.ops = &fops;
|
|
||||||
|
|
||||||
if (cdev_add(&chardev, devno, NUMBER_OF_MINOR_DEVICE)) {
|
|
||||||
pr_err(DEVICE_NAME ": cdev_add failed.");
|
|
||||||
goto free_device_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
chardev_class = class_create(THIS_MODULE, DEVICE_NAME);
|
|
||||||
|
|
||||||
if (IS_ERR(chardev_class)) {
|
|
||||||
pr_err(DEVICE_NAME ": no udev support\n");
|
|
||||||
goto free_cdev;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_MINOR_DEVICE; ++i)
|
|
||||||
{
|
|
||||||
#if NUMBER_OF_MINOR_DEVICE == 1
|
|
||||||
chardev_device[i] = device_create(chardev_class, NULL, devno + i, NULL, DEVICE_NAME);
|
|
||||||
#else
|
|
||||||
chardev_device[i] = device_create(chardev_class, NULL, devno + i, NULL, DEVICE_NAME "%d", i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (IS_ERR(chardev_device[i])) {
|
|
||||||
pr_err(DEVICE_NAME ": device create failed\n");
|
|
||||||
goto free_device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CUSTOM_INIT
|
|
||||||
CUSTOM_INIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
free_device:
|
|
||||||
for (; i > 0; --i) {
|
|
||||||
device_destroy(chardev_class, devno + i - 1);
|
|
||||||
}
|
|
||||||
class_destroy(chardev_class);
|
|
||||||
free_cdev:
|
|
||||||
cdev_del(&chardev);
|
|
||||||
free_device_number:
|
|
||||||
unregister_chrdev_region(devno, NUMBER_OF_MINOR_DEVICE);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __exit ModExit(void)
|
|
||||||
{
|
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
printk(KERN_DEBUG DEVICE_NAME ": exit");
|
|
||||||
|
|
||||||
#ifdef CUSTOM_EXIT
|
|
||||||
CUSTOM_EXIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = NUMBER_OF_MINOR_DEVICE; i > 0; --i) {
|
|
||||||
device_destroy(chardev_class, devno + i - 1);
|
|
||||||
}
|
|
||||||
class_destroy(chardev_class);
|
|
||||||
cdev_del(&chardev);
|
|
||||||
unregister_chrdev_region(devno, NUMBER_OF_MINOR_DEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
module_init( ModInit );
|
|
||||||
module_exit( ModExit );
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/cdev.h>
|
|
||||||
#include <linux/gpio.h>
|
|
||||||
#include <linux/kobject.h>
|
|
||||||
#include <linux/device.h>
|
|
||||||
#include <linux/uaccess.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "infrared_sensor";
|
|
||||||
#define NUMBER_OF_MINOR_DEVICE (1);
|
|
||||||
|
|
||||||
#include "infrared_sensor.def.h"
|
|
||||||
|
|
||||||
static unsigned int infrared_sensor_in_1 = 2;
|
|
||||||
static unsigned int infrared_sensor_in_2 = 3;
|
|
||||||
static unsigned int infrared_sensor_in_3 = 4;
|
|
||||||
static unsigned int infrared_sensor_in_4 = 17;
|
|
||||||
|
|
||||||
|
|
||||||
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = gpio_request(infrared_sensor_in_1, "rpi-gpio-1");
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_request failed %d\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = gpio_direction_output(infrared_sensor_in_1);
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_direction_input failed %d\n", err);
|
|
||||||
gpio_free(infrared_sensor_in_1);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printk("gpio 2 successfull configured\n");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
|
|
||||||
size_t max_bytes_to_read, loff_t *offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int infrared_sensor_close( struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct file_operations fops = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.open = infrared_sensor_open,
|
|
||||||
.release = infrared_sensor_close,
|
|
||||||
.read = infrared_sensor_read,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "infrared_sensor.h";
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
static dev_t devno;
|
|
||||||
static struct cdev chardev;
|
|
||||||
static struct class *chardev_class;
|
|
||||||
static struct device *chardev_device[NUMBER_OF_MINOR_DEVICE];
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
MODULE_AUTHOR("Manuel Vögele, Siegfried Kienzle, Simon Wörner");
|
|
||||||
MODULE_DESCRIPTION(DEVICE_NAME "driver");
|
|
||||||
MODULE_LICENSE("GPL");
|
|
||||||
|
|
||||||
static int __init ModInit(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
printk(KERN_DEBUG DEVICE_NAME ": init");
|
|
||||||
|
|
||||||
if (alloc_chrdev_region(&devno, 0, NUMBER_OF_MINOR_DEVICE, DEVICE_NAME) < 0)
|
|
||||||
return -EIO;
|
|
||||||
|
|
||||||
cdev_init(&chardev, &fops);
|
|
||||||
chardev.owner = THIS_MODULE;
|
|
||||||
chardev.ops = &fops;
|
|
||||||
|
|
||||||
if (cdev_add(&chardev, devno, NUMBER_OF_MINOR_DEVICE)) {
|
|
||||||
pr_err(DEVICE_NAME ": cdev_add failed.");
|
|
||||||
goto free_device_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
chardev_class = class_create(THIS_MODULE, DEVICE_NAME);
|
|
||||||
|
|
||||||
if (IS_ERR(chardev_class)) {
|
|
||||||
pr_err(DEVICE_NAME ": no udev support\n");
|
|
||||||
goto free_cdev;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < NUMBER_OF_MINOR_DEVICE; ++i)
|
|
||||||
{
|
|
||||||
#if NUMBER_OF_MINOR_DEVICE == 1
|
|
||||||
chardev_device[i] = device_create(chardev_class, NULL, devno + i, NULL, DEVICE_NAME);
|
|
||||||
#else
|
|
||||||
chardev_device[i] = device_create(chardev_class, NULL, devno + i, NULL, DEVICE_NAME "%d", i);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (IS_ERR(chardev_device[i])) {
|
|
||||||
pr_err(DEVICE_NAME ": device create failed\n");
|
|
||||||
goto free_device;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef CUSTOM_INIT
|
|
||||||
CUSTOM_INIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
free_device:
|
|
||||||
for (; i > 0; --i) {
|
|
||||||
device_destroy(chardev_class, devno + i - 1);
|
|
||||||
}
|
|
||||||
class_destroy(chardev_class);
|
|
||||||
free_cdev:
|
|
||||||
cdev_del(&chardev);
|
|
||||||
free_device_number:
|
|
||||||
unregister_chrdev_region(devno, NUMBER_OF_MINOR_DEVICE);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void __exit ModExit(void)
|
|
||||||
{
|
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
printk(KERN_DEBUG DEVICE_NAME ": exit");
|
|
||||||
|
|
||||||
#ifdef CUSTOM_EXIT
|
|
||||||
CUSTOM_EXIT
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (i = NUMBER_OF_MINOR_DEVICE; i > 0; --i) {
|
|
||||||
device_destroy(chardev_class, devno + i - 1);
|
|
||||||
}
|
|
||||||
class_destroy(chardev_class);
|
|
||||||
cdev_del(&chardev);
|
|
||||||
unregister_chrdev_region(devno, NUMBER_OF_MINOR_DEVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
module_init( ModInit );
|
|
||||||
module_exit( ModExit );
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/cdev.h>
|
|
||||||
#include <linux/gpio.h>
|
|
||||||
#include <linux/kobject.h>
|
|
||||||
#include <linux/device.h>
|
|
||||||
#include <linux/uaccess.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "infrared_sensor";
|
|
||||||
#define NUMBER_OF_MINOR_DEVICE (1);
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.def.h"
|
|
||||||
|
|
||||||
static unsigned int infrared_sensor_in_1 = 2;
|
|
||||||
|
|
||||||
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = gpio_request(infrared_sensor_in_1, "rpi-gpio-2");
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_request for in_1 failed %d\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = gpio_direction_input(infrared_sensor_in_3);
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_direction_input for in_1 failed %d\n", err);
|
|
||||||
gpio_free(infrared_sensor_in_1);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printk("gpio 2 successfull configured\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
|
|
||||||
size_t max_bytes_to_read, loff_t *offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int infrared_sensor_close( struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
printk( "driver_close called\n" );
|
|
||||||
gpio_free( infrared_sensor_in_1 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct file_operations fops = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.open = infrared_sensor_open,
|
|
||||||
.release = infrared_sensor_close,
|
|
||||||
.read = infrared_sensor_read,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.h";
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/cdev.h>
|
|
||||||
#include <linux/gpio.h>
|
|
||||||
#include <linux/kobject.h>
|
|
||||||
#include <linux/device.h>
|
|
||||||
#include <linux/uaccess.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "infrared_sensor";
|
|
||||||
#define NUMBER_OF_MINOR_DEVICE (1);
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.def.h"
|
|
||||||
|
|
||||||
static unsigned int infrared_sensor_in_2 = 3;
|
|
||||||
|
|
||||||
|
|
||||||
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = gpio_request(infrared_sensor_in_2, "rpi-gpio-2");
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_request for in_2 failed %d\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = gpio_direction_input(infrared_sensor_in_2);
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_direction_input for in_2 failed %d\n", err);
|
|
||||||
gpio_free(infrared_sensor_in_2);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printk("gpio 3 successfull configured\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
|
|
||||||
size_t max_bytes_to_read, loff_t *offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int infrared_sensor_close( struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
printk( "driver_close called\n" );
|
|
||||||
gpio_free( infrared_sensor_in_2 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct file_operations fops = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.open = infrared_sensor_open,
|
|
||||||
.release = infrared_sensor_close,
|
|
||||||
.read = infrared_sensor_read,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.h";
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/cdev.h>
|
|
||||||
#include <linux/gpio.h>
|
|
||||||
#include <linux/kobject.h>
|
|
||||||
#include <linux/device.h>
|
|
||||||
#include <linux/uaccess.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "infrared_sensor";
|
|
||||||
#define NUMBER_OF_MINOR_DEVICE (1);
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.def.h"
|
|
||||||
|
|
||||||
static unsigned int infrared_sensor_in_3 = 4;
|
|
||||||
|
|
||||||
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = gpio_request(infrared_sensor_in_3, "rpi-gpio-2");
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_request for in_3 failed %d\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = gpio_direction_input(infrared_sensor_in_3);
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_direction_input for in_3 failed %d\n", err);
|
|
||||||
gpio_free(infrared_sensor_in_3);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printk("gpio 4 successfull configured\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
|
|
||||||
size_t max_bytes_to_read, loff_t *offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int infrared_sensor_close( struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
printk( "driver_close called\n" );
|
|
||||||
gpio_free( infrared_sensor_in_3 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct file_operations fops = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.open = infrared_sensor_open,
|
|
||||||
.release = infrared_sensor_close,
|
|
||||||
.read = infrared_sensor_read,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.h";
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
#include <linux/init.h>
|
|
||||||
#include <linux/module.h>
|
|
||||||
#include <linux/kernel.h>
|
|
||||||
#include <linux/fs.h>
|
|
||||||
#include <linux/cdev.h>
|
|
||||||
#include <linux/gpio.h>
|
|
||||||
#include <linux/kobject.h>
|
|
||||||
#include <linux/device.h>
|
|
||||||
#include <linux/uaccess.h>
|
|
||||||
|
|
||||||
#define DEVICE_NAME "infrared_sensor";
|
|
||||||
#define NUMBER_OF_MINOR_DEVICE (1);
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.def.h"
|
|
||||||
|
|
||||||
static unsigned int infrared_sensor_in_4 = 17;
|
|
||||||
|
|
||||||
static int infrared_sensor_open(struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = gpio_request(infrared_sensor_in_4, "rpi-gpio-17");
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_request for in_4 failed %d\n", err);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
err = gpio_direction_input(infrared_sensor_in_3);
|
|
||||||
if (err) {
|
|
||||||
printk("gpio_direction_input for in_4 failed %d\n", err);
|
|
||||||
gpio_free(infrared_sensor_in_4);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
printk("gpio 17 successfull configured\n");
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ssize_t infrared_sensor_read( struct file *instance, char __user *buffer,
|
|
||||||
size_t max_bytes_to_read, loff_t *offset)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static int infrared_sensor_close( struct inode devfile, struct file *instance)
|
|
||||||
{
|
|
||||||
printk( "driver_close called\n" );
|
|
||||||
gpio_free( infrared_sensor_in_4 );
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static struct file_operations fops = {
|
|
||||||
.owner = THIS_MODULE,
|
|
||||||
.open = infrared_sensor_open,
|
|
||||||
.release = infrared_sensor_close,
|
|
||||||
.read = infrared_sensor_read,
|
|
||||||
};
|
|
||||||
|
|
||||||
#include "../_common/infrared_sensor.h";
|
|
||||||
Reference in New Issue
Block a user