s3c44b0-seg7.c

来自「linux操作系统的七段数码管的驱动程序」· C语言 代码 · 共 102 行

C
102
字号
#include	<linux/config.h>#include	<linux/module.h>#include	<linux/kernel.h>#include	<linux/init.h>#include	<asm/delay.h>#include	<asm/uaccess.h>#include	<linux/fs.h>#include	<linux/devfs_fs_kernel.h>//#undef	DEBUG#define		DEBUG#ifdef		DEBUG#define		DPRINTK(x... )	printk("s3c44b0_seg7:"##x)#else	#define		DPRINTK(x...)#endif#define		SEG7	*((volatile unsigned char *)0x08000000)#define		SEG7MUM	8#define		DEVICE_NAME	"s3c44b0_seg7"#define		DEVICESEG7_MINOR	1const 	char    nameseg7[]="seg7";const	char	snameseg7[]="0";static 	int	SEG7Major = 0;static	char	seg7status= 0xff;static	void	Updateseg7(void){	SEG7=0xff&seg7status;}static	ssize_t s3c44b0_Seg7_write(struct file *file,const char *buffer,size_t count, loff_t *ppos){	copy_from_user(&seg7status,buffer,sizeof(seg7status));	Updateseg7();		DPRINTK("write:	seg7=0x%x, count=%d\n",seg7status,count);	return sizeof(seg7status);}static	int	s3c44b0_Seg7_open(struct inode *inode,struct file *filp){	MOD_INC_USE_COUNT;	DPRINTK("open\n");	return 0;}static	int	s3c44b0_Seg7_release(struct inode *inode, struct file *filp){	MOD_DEC_USE_COUNT;	DPRINTK("release\n");	return 0;}static	struct	file_operations s3c44b0_fops = {	owner:	THIS_MODULE,	open:	s3c44b0_Seg7_open,	write:  s3c44b0_Seg7_write,	release:s3c44b0_Seg7_release,};#ifdef CONFIG_DEVFS_FSstatic	devfs_handle_t	devfs_s3c44b0_dir,devfs_s3c44b0raw;#endifstatic	int	__init	s3c44b0_Seg7_init(void){	int ret;	seg7status=0x00;	Updateseg7();			ret = register_chrdev(SEG7Major,DEVICE_NAME,&s3c44b0_fops);	if(ret<0)	{		printk(DEVICE_NAME "can't get major number\n");		return ret;	}	SEG7Major = ret;#ifdef	CONFIG_DEVFS_FS        devfs_s3c44b0_dir=devfs_mk_dir(NULL,nameseg7,NULL);	devfs_s3c44b0raw=devfs_register(devfs_s3c44b0_dir,snameseg7,DEVFS_FL_DEFAULT,SEG7Major,\					DEVICESEG7_MINOR,S_IFCHR|S_IRUSR|S_IWUSR,&s3c44b0_fops,NULL);#endif	printk(DEVICE_NAME "initialized\n");	return 0;}static	void	__exit	s3c44b0_Seg7_exit(void){#ifdef	CONFIG_DEVFS_FS	devfs_unregister(devfs_s3c44b0raw);	devfs_unregister(devfs_s3c44b0_dir);#endif	unregister_chrdev(SEG7Major, DEVICE_NAME);}module_init(s3c44b0_Seg7_init);module_exit(s3c44b0_Seg7_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("ZCY");MODULE_DESCRIPTION("SEG7 driver fo EB44b0");

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?