consolidate all repos to one for archive
This commit is contained in:
116
semester_4/namenska_programska_oprema/Naloga_6/xpo_modul.c
Normal file
116
semester_4/namenska_programska_oprema/Naloga_6/xpo_modul.c
Normal file
@@ -0,0 +1,116 @@
|
||||
#include <linux/atomic.h>
|
||||
#include <linux/cdev.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/device.h>
|
||||
#include <linux/init.h>
|
||||
#include <linux/kernel.h> /* for sprintf() */
|
||||
#include <linux/module.h>
|
||||
#include <linux/printk.h>
|
||||
#include <linux/types.h>
|
||||
#include"xpo_modul.h"
|
||||
|
||||
MODULE_AUTHOR("NIKOLA");
|
||||
MODULE_DESCRIPTION("Simple kernel driver skeleton");
|
||||
MODULE_LICENSE("GPL");
|
||||
|
||||
|
||||
static int major; // major number of device driver
|
||||
#define DEVICE_NAME "xpo_modul"
|
||||
|
||||
static struct class *cls;
|
||||
|
||||
static int __init xpo_driver_init(void)
|
||||
{
|
||||
pr_info("xpo: driver INIT\n");
|
||||
|
||||
major = register_chrdev(0, DEVICE_NAME, &xpo_fops);
|
||||
|
||||
if (major < 0) {
|
||||
pr_alert("xpo: registering char device failed with %d\n", major);
|
||||
return major;
|
||||
} else {
|
||||
pr_info("xpo: registering char device %d\n", major);
|
||||
}
|
||||
|
||||
cls = class_create(THIS_MODULE, DEVICE_NAME);
|
||||
|
||||
device_create(cls, NULL, MKDEV(major, 0), NULL, DEVICE_NAME);
|
||||
|
||||
pr_info("xpo: Device created on /dev/%s\n", DEVICE_NAME);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void xpo_driver_exit(void)
|
||||
{
|
||||
pr_info("xpo: driver EXIT\n");
|
||||
|
||||
device_destroy(cls, MKDEV(major, 0));
|
||||
|
||||
class_destroy(cls);
|
||||
|
||||
unregister_chrdev(major, DEVICE_NAME);
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
module_init(xpo_driver_init);
|
||||
module_exit(xpo_driver_exit);
|
||||
|
||||
// abcdefghijklmnopqrstuvwxyz
|
||||
|
||||
static unsigned char xpo_map[256] =
|
||||
{
|
||||
[0 ... 255] = 0,
|
||||
|
||||
[2] = '1',
|
||||
[3] = '2',
|
||||
[4] = '3',
|
||||
[5] = '4',
|
||||
[6] = '5',
|
||||
[7] = '6',
|
||||
[8] = '7',
|
||||
[9] = '8',
|
||||
[10] = '9',
|
||||
[11] = '0',
|
||||
|
||||
[16] = 'q',
|
||||
[17] = 'w',
|
||||
[18] = 'e',
|
||||
[19] = 'r',
|
||||
[20] = 't',
|
||||
[21] = 'z',
|
||||
[22] = 'u',
|
||||
[23] = 'i',
|
||||
[24] = 'o',
|
||||
[25] = 'p',
|
||||
|
||||
[30] = 'a',
|
||||
[31] = 's',
|
||||
[32] = 'd',
|
||||
[33] = 'f',
|
||||
[34] = 'g',
|
||||
[35] = 'h',
|
||||
[36] = 'j',
|
||||
[37] = 'k',
|
||||
[37] = 'l',
|
||||
|
||||
[44] = 'y',
|
||||
[45] = 'x',
|
||||
[46] = 'c',
|
||||
[47] = 'v',
|
||||
[48] = 'b',
|
||||
[49] = 'n',
|
||||
[50] = 'm'
|
||||
};
|
||||
|
||||
ssize_t xpo_read(struct file *filep, char *buff, size_t count, loff_t *offp )
|
||||
{
|
||||
unsigned char c = inb(0x60); // 0x60 - which key down
|
||||
char buf[20];
|
||||
sprintf(buf, "%u - znak: %c", c, xpo_map[c]);
|
||||
|
||||
printk("xpo - signal: %s\n", buf);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user