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

📄 s3c2410-adc.c~

📁 本驱动是LINUX下开发的S3C2410的8通道的ADC驱动.可以直接insmod使用.包含测试程序TEST.
💻 C~
字号:
/* * s3c2410-adc.c * * S3C2410 ADC  *  exclusive with s3c2410-ts.c * * Author: SeonKon Choi <bushi@mizi.com> * Date  : $Date: 2003/01/20 14:24:49 $  * * $Revision: 1.1.2.6 $ *   Fri Dec 03 2002 SeonKon Choi <bushi@mizi.com>   - initial * * This file is subject to the terms and conditions of the GNU General Public * License.  See the file COPYING in the main directory of this archive * for more details. */#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/miscdevice.h>#include <linux/proc_fs.h>#include <linux/sched.h>#include <linux/irq.h>#include <linux/delay.h>#include <asm/hardware.h>#include <asm/semaphore.h>#include <asm/uaccess.h>#include <asm/arch/cpu_s3c2410.h>//#undef DEBUG//#define DEBUG#define	ADC_MINOR	251#define	ADC_INx 	ADC_IN1#define PCLK		s3c2410_get_bus_clk(GET_PCLK)//50000000#define ADC_FREQ	2500000 // max freq: 2500000(2.5MHz)#define vPRSCVL 	(PCLK/ADC_FREQ -1)#ifdef DEBUG#define DPRINTK(x...) {printk(__FUNCTION__"(%d): ",__LINE__);printk(##x);}#else#define DPRINTK(x...) (void)(0)#endif#define START_ADC_AIN(x) \	{ \		ADCCON = PRESCALE_EN | PRSCVL(vPRSCVL) | ADC_INPUT((x)) ; \		ADCCON |= ADC_START; \		while(!(ADCCON & 0x8000));\	}static struct semaphore adc_lock;int s3c2410_adc_read(int ain, int a){	int tmpp,ret = 0;	down(&adc_lock);	START_ADC_AIN(ain);	ret = ADCDAT0 ;	up(&adc_lock);	DPRINTK("AIN[%d]=0x%04x, ADCCON=0x%x 0x%x\n", ain, ret, ADCCON, GPCON(PORTG_OFS));	return (ret & 0x3ff);}/*static int adc_open(struct inode *inode, struct file *file){	    int i;	ADCCON |= ADC_START;	DPRINTK("ADCCON=0x%x 0x%x\n", ADCCON, GPCON(PORTG_OFS));	return 0;}static int adc_close(struct inode *inode, struct file *file){		ADCCON &= ~ADC_START;	return 0;}*/ssize_t adc_read(struct file *file, char *buf, size_t count, loff_t *ppos){	unsigned long i,data;	ssize_t retval;	data = s3c2410_adc_read(ADC_INx,1);			retval = put_user(data, (unsigned long *)buf);	if (!retval)		retval = count;//	retval = copy_to_user(buf, &data, count) ? -EFAULT : count;		return retval;}static struct file_operations adc_fops = {	owner:		THIS_MODULE,	read:		adc_read,//	open:		adc_open,//	release:	adc_close,};static struct miscdevice adc_dev={	ADC_MINOR,	"adc",	&adc_fops};int __init s3c2410_adc_init(void){	int ret,nPreScaler;	init_MUTEX(&adc_lock);	misc_register(&adc_dev);	/* normal ADC */	ADCTSC = 0; //XP_PST(NOP_MODE);	/* add by R.X Huang *///	nPreScaler = PCLK/ADC_FREQ -1;	//  ADCCON=(1<<14)|(nPreScaler<<6)|ADC_INPUT(ADC_INx)|(0<<2)|(1<<1);//enable prescaler,ain2,normal,start by read	return 0;irq_err:	return 1;}module_init(s3c2410_adc_init);#ifdef MODULEvoid __exit s3c2410_adc_exit(void){#ifdef CONFIG_PROC_FS	remove_proc_entry("driver/adc", NULL);#endif	misc_deregister(&adc_dev);}module_exit(s3c2410_adc_exit);MODULE_LICENSE("GPL");#endif

⌨️ 快捷键说明

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