I have written SPI character device driver in kernel space. I can now able to communicate through the following function from user space.
1.open("/dev/rfk_spi", O_RDWR);
2.write(fd,buf,sizeof(buf)/sizeof(buf[0]));
3.read(fd,tab,sizeof(tab)/sizeof(tab[0]));
But, I want to implement some more function which have some argument and return type. And I want to access this function from user space program.Suppose
1.unsigned char function1(unsigned int,unsigned char*);
2.void function2(struct student record);
Then how to write the code in kernel space/user space to exchange data.
These are my kernel function:
1.static int spi_open(struct inode *inode,struct file *filp) {}
2.static int spi_release(struct inode *inode,struct file *filp){}
3.static ssize_t spi_read(struct file *filp,char __user *buf,size_t count,loff_t *f_ops){}
4.static ssize_t spi_write(struct file *filp,const char __user *buf,size_t count,loff_t *f_ops){}
static const struct file_operations spi_fops =
{
.owner=THIS_MODULE,
.open=spi_open,
.read=spi_read,
.release=spi_release,
.write=spi_write,
};
static struct miscdevice misc =
{
.minor = MISC_DYNAMIC_MINOR,
.name = DEVICE_NAME,
.fops = &spi_fops,
};
6.static int __init spi_init(void){}
7.static void __exit spi_exit(void){}
module_init(spi_init);
module_exit(spi_exit);
MODULE_LICENSE("GPL");
Please guide me to solve my problem!
UPDATE- As working on suggestions of @jjm, Now I get the following reply:
I have cross compiled the chardev.c ,chardev.h and make chardev.ko
root@rfk-desktop:# ls
chardev.c chardev.h chardev.ko chardev.mod.c chardev.mod.o chardev.o ioctl ioctl.c Makefile modules.order Module.symvers
root@rfk-desktop:# file chardev.ko
chardev.ko: ELF 32-bit LSB relocatable, ARM, version 1 (SYSV), not stripped
root@rfk-desktop:# file ioctl
ioctl: ELF 32-bit LSB executable, ARM, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.32, stripped
I copied the file to my development board and register
[root@FriendlyARM 2.6.32.2-FriendlyARM]# modprob chardev
[root@FriendlyARM 2.6.32.2-FriendlyARM]# mknod char_dev c 100 0
But when I am running the test program :)
[root@FriendlyARM /mnt]# ./ioctl
Can't open device file: char_dev
Please reply where I am missing?
UPDATE- Every thing works fine no problem!!!& I shall post the updated source code with detailed description very shortly!!
Please,any one could tell me why I am getting -Ve marks!! Is there any information wrong ? or missing? anything else?