📄 vid29.c
字号:
/************************************************
*Include files field
********************/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/config.h>
#include <linux/delay.h>
#include <linux/irq.h>
#include <linux/miscdevice.h>
#include <linux/poll.h>
#include <linux/spinlock.h>
#include <asm/hardware.h>
/************************************************
*Definition field
*****************/
#define MAJOR_NR 200
#define DEVICE_NAME "vid29"
static unsigned long vid29[] =
{
GPIO_B3,
GPIO_B2,
};
static int vid29_ioctl (struct inode *inode, struct file *fp, unsigned int cmd, unsigned long arg)
{
switch (cmd)
{
case 0:
case 1:
if (arg>1)
{
printk (DEVICE_NAME " : passing-in parameter \"arg\" .......... [ ERROR ]\n");
return -EINVAL;
}
write_gpio_bit (vid29[arg], cmd); /*set specific output pin*/
break;
default:
printk (DEVICE_NAME " : passing-in parameter \"cmd\" .......... [ ERROR ]\n");
return -ENOTTY;
}
return 0;
}
static struct file_operations vid29_fops =
{
owner : THIS_MODULE,
ioctl : vid29_ioctl,
};
static devfs_handle_t devfs_handle;
static int __init vid29_init (void)
{
int i;
int result;
result=register_chrdev (MAJOR_NR, DEVICE_NAME, &vid29_fops);
if (result<0)
{
printk (DEVICE_NAME " : getting major number %d .......... [ ERROR ]\n", MAJOR_NR);
return result;
}
devfs_handle=devfs_register (NULL, DEVICE_NAME, DEVFS_FL_DEFAULT, MAJOR_NR, 0, S_IFCHR | S_IRUSR | S_IWUSR, &vid29_fops, NULL);
for (i=0; i<2; i++) /*initialize output pins*/
{
set_gpio_ctrl (vid29[i] | GPIO_PULLUP_EN | GPIO_MODE_OUT);
}
printk (DEVICE_NAME " : initializing .......... [ OK ]\n");
return 0;
}
static void __exit vid29_exit (void)
{
devfs_unregister (devfs_handle);
unregister_chrdev (MAJOR_NR, DEVICE_NAME);
}
module_init (vid29_init);
module_exit (vid29_exit);
MODULE_LICENSE ("GPL");
/*
*********************************************************************
*
*End of code
*
*********************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -