Showing posts with label Device Driver. Show all posts
Showing posts with label Device Driver. Show all posts

Thursday, 10 October 2013

Basic program to make the module in Kernel Space and add it into the process

Write the program with the file extension ".c" . After that, make the Makefile. Then execute the Makefile by writing make. after that insert the module in the Process by writing insmod <filename>.ko . Then check the Kernel module by writing the command dmesg|less. For removing the module from the Process write rmmod <filename>.ko.

//basic.c
#include<linux/init.h>
#include<linux/module.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("RAJ");

static int hello_init(void)
{
printk(KERN_ALERT "HELLO , THERE \n");
return 0;

}


static int hello_exit(void)
{
printk(KERN_ALERT "Goodbye everyone i m gonna find u and kill you \n");
return 0;
}

module_init(hello_init);
module_exit(hello_exit);


Tutorial :

Program in a KERNEL to be use by user for open,close,read and write, along with the USER program to access Kernel program, with make file.

-----------------------------------------------------------------------------------------------------

/* Program to make a kernel to be accessed by the user */
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/kdev_t.h>
#include<linux/fs.h>
#include<linux/cdev.h>
#include<asm/uaccess.h>
MODULE_LICENSE("GPL");
struct cdev rss_str;
int major=0;
int minor=0;
dev_t rss;
void rss_reg();
static int rss_init()
{
printk("intializing module\n");
rss_reg();
return 0; }
static void rss_release()
{
printk("Exiting module\n");
cdev_del(&rss_str);
unregister_chrdev_region(rss,1);
}
// READ file

Blogroll

Copyright © 2013 RAJ PRAJAPATI (raj@electronicsrj.com)

Comments

About Projects

We also Provide support in making Electronics Projects at different level at Cheapest price. Contact Us for the further help.