⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 adc0809.c

📁 嵌入式下实验的新的驱动设计源代码
💻 C
字号:
#include <linux/config.h>#include <linux/utsname.h>#include <linux/kernel.h>#include <linux/major.h>#include <linux/string.h>#include <linux/fcntl.h>#include <linux/malloc.h>#include <linux/timer.h>#include <linux/module.h>#include <linux/init.h>#include <linux/poll.h>#include <asm/irq.h>#define ADC0809_IRQ_NUM		6#define ADC0809_MAJOR		58static DECLARE_WAIT_QUEUE_HEAD(Adc0809Wait);void delay(int n){	int i, j;	for(i = 0; i < 1000; i++)		for(j = 0; j < n; j++)			;}static int Adc0809Close(struct inode * inode, struct file * file){        MOD_DEC_USE_COUNT;	return 0;}static int Adc0809Open(struct inode * inode, struct file * file){        MOD_INC_USE_COUNT;	return 0;}static int Adc0809Read(struct file * file, char * buf, size_t count, loff_t *ppos){	char Value;        unsigned char *kbuf=kmalloc(16, GFP_KERNEL); 		*(unsigned long *)0xfc000000 = 0x0;	Value = *(unsigned char *)0xfc000000;	printk("ADC0809  Value = : 0x%02x\n", Value);	delay(2000);	*kbuf = Value;	copy_to_user(buf, kbuf, 1); 	kfree(kbuf);		return (0);}/* * select for mouse input */static unsigned int Adc0809Select(	struct file *file, 	struct poll_table_struct *wait){	poll_wait(file, &Adc0809Wait, wait);	return 0;}static int Adc0809Ioctl(        struct inode *inode,        struct file *file,        unsigned int cmd,        unsigned long arg){        switch(cmd) {		case 1:		{                     return 0;				}		case 0:		{		        Adc0809Read(inode, file, (char *)arg, 1);				return 0;		}		        default:                return -EINVAL;        }}struct file_operations Adc0809_fops = {	NULL,        NULL,	        read:	Adc0809Read,	poll:	Adc0809Select, 	/* select */		open:	Adc0809Open,	ioctl:	Adc0809Ioctl,	release:	Adc0809Close,        NULL,	NULL,			};int adc0809_init(void){        int     rc;        printk("adc0809............Support\n");	*(unsigned long *)0xff000180 |= 0x00120000;	*(unsigned long *)0xfc000000 = 0x0;        rc = register_chrdev(ADC0809_MAJOR, "adc0809", &Adc0809_fops);        if (rc < 0) {                printk(KERN_WARNING "adc0809: can't get Major %d\n",                        ADC0809_MAJOR);                return rc;         }		return 0;}void adc0809_cleanup(void){  unregister_chrdev(ADC0809_MAJOR, "adc0809");}	module_init(adc0809_init);module_exit(adc0809_cleanup);

⌨️ 快捷键说明

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