Presentation is loading. Please wait.

Presentation is loading. Please wait.

Device Driver_Skeleton

Similar presentations


Presentation on theme: "Device Driver_Skeleton"— Presentation transcript:

1 Device Driver_Skeleton

2 a. Device Driver skeleton.c #include <linux/module.h>
#include <linux/fs.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/major.h> MODULE_LICENSE("GPL"); int result; int skeleton_open(struct inode *inode, struct file *filp) { printk("Device Open!!\n"); return 0; } int skeleton_release(struct inode *inode, struct file *filp) { printk("Device Release!!\n"); int skeleton_read(struct file *filp, const char *buf, size_t count, loff_t *f_pos){ printk("Device Read!!\n"); int skeleton_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { printk("Device Ioctl!!\n");

3 a. Device Driver skeleton.c
int skeleton_write(struct file *filp, unsigned int *buf, size_t count, loff_t *f_pos) { printk("Device Write!!\n"); return 0; } struct file_operations skeleton_fops = { .open = skeleton_open, .release= skeleton_release, .read = skeleton_read, .unlocked_ioctl = skeleton_ioctl, .write = skeleton_write, }; static int skeleton_init(void) printk("skeleton module init!!\n"); result = register_chrdev(0, "skeleton!!", &skeleton_fops); printk("major number=%d\n", result); static void skeleton_exit(void) printk("skeleton module exit!!\n"); module_init(skeleton_init); module_exit(skeleton_exit);

4 a. Device Driver Makefile
CC := /usr/local/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-eabi-gcc KDIR := /Smart4412Linux/Development/Source/Kernel/kernel_4412 obj-m := skeleton.o build : make -C $(KDIR) SUBDIRS=$(PWD) modules clean : rm -rf *.o *.ko *.mod.c *.order *.symvers

5 a. Device Driver userapp.c #include <stdio.h>
#include <fcntl.h> #include <unistd.h> #include <stdlib.h> #include <string.h> int main() { int fd; fd = open("/dev/skeleton", O_RDWR); printf("Device Driver Test Application\n"); read(fd, 0, 0); ioctl(fd, NULL, 0); close(fd); return 0; }

6 a. Device Driver Applicaton Build # make

7 a. Device Driver DeviceDriver module Build
# arm-linux-gnueabihf-gcc userapp.c –o userapp

8 a. Device Driver insmod # insmod skeleton.ko
# mknod /dev/skeleton c 248 0 # ./userapp # lsmod # dmesg


Download ppt "Device Driver_Skeleton"

Similar presentations


Ads by Google