云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 嵌入式系统设计AD转换器

嵌入式系统设计AD转换器

  • 62 次阅读
  • 3 次下载
  • 2025/6/18 7:03:16

#define ADC_READY 0 #define NOP_MODE 0 #define X_AXIS_MODE 1 #define Y_AXIS_MODE 2 #define WAIT_INT_MODE 3 /* ... */

#define ADCCON_ECFLG (1 << 15) #define PRESCALE_ENDIS (1 << 14) #define PRESCALE_DIS (PRESCALE_ENDIS*0) #define PRESCALE_EN (PRESCALE_ENDIS*1)

#define PRSCVL(x) (x << 6) #define ADC_INPUT(x) (x << 3) #define ADCCON_STDBM (1 << 2) /* 1: standby mode, 0: normal mode */ #define ADC_NORMAL_MODE FClrBit(ADCCON, ADCCON_STDBM) #define ADC_STANDBY_MODE (ADCCON_STDBM*1) #define ADCCON_READ_START (1 << 1)

#define ADC_START_BY_RD_DIS FClrBit(ADCCON, ADCCON_READ_START) #define ADC_START_BY_RD_EN (ADCCON_READ_START*1) #define ADC_START (1 << 0)

s3c2410-adc.c

/*

* s3c2410-adc.c *

* S3C2410 ADC

* exclusive with s3c2410-ts.c *

* Author: SeonKon Choi * Date : $Date: 2003/01/20 14:24:49 $ *

* $Revision: 1.1.2.6 $ * 2004-6-14 add a device by threewater

Fri Dec 03 2002 SeonKon Choi - 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

24

#include #include #include

#include #include #include

#include #include #include

#include \

#undef DEBUG //#define DEBUG #ifdef DEBUG

#define DPRINTK(x...) {printk(__FUNCTION__\#else

#define DPRINTK(x...) (void)(0) #endif

#define DEVICE_NAME \#define ADCRAW_MINOR 1

static int adcMajor = 0;

typedef struct { struct semaphore lock; wait_queue_head_t wait; int channel; int prescale; }ADC_DEV;

static ADC_DEV adcdev;

#define START_ADC_AIN(ch, prescale) \\ do{ \\ ADCCON = PRESCALE_EN | PRSCVL(prescale) | ADC_INPUT((ch)) ; \\ ADCCON |= ADC_START; \\ }while(0)

static void adcdone_int_handler(int irq, void *dev_id, struct pt_regs *reg) {

25

wake_up(&adcdev.wait); }

static ssize_t s3c2410_adc_write(struct file *file, const char *buffer, size_t count, loff_t * ppos) { int data; if(count!=sizeof(data)){ //error input data size DPRINTK(\ input data must be %d\\n\ return 0; } copy_from_user(&data, buffer, count); adcdev.channel=ADC_WRITE_GETCH(data); adcdev.prescale=ADC_WRITE_GETPRE(data); DPRINTK(\ return count; }

static ssize_t s3c2410_adc_read(struct file *filp, char *buffer, size_t count, loff_t *ppos) { int ret = 0; if (down_interruptible(&adcdev.lock)) return -ERESTARTSYS; START_ADC_AIN(adcdev.channel, adcdev.prescale); interruptible_sleep_on(&adcdev.wait); ret = ADCDAT0; ret &= 0x3ff; DPRINTK(\ copy_to_user(buffer, (char *)&ret, sizeof(ret)); up(&adcdev.lock); return sizeof(ret); }

static int s3c2410_adc_open(struct inode *inode, struct file *filp)

26

{ init_MUTEX(&adcdev.lock); init_waitqueue_head(&(adcdev.wait)); adcdev.channel=0; adcdev.prescale=0xff; MOD_INC_USE_COUNT; DPRINTK( \ return 0; }

static int s3c2410_adc_release(struct inode *inode, struct file *filp) { MOD_DEC_USE_COUNT; DPRINTK( \ return 0; }

static struct file_operations s3c2410_fops = { owner: THIS_MODULE, open: s3c2410_adc_open, read:s3c2410_adc_read, write: s3c2410_adc_write, release: s3c2410_adc_release, };

#ifdef CONFIG_DEVFS_FS

static devfs_handle_t devfs_adc_dir, devfs_adcraw; #endif

int __init s3c2410_adc_init(void) { int ret; /* normal ADC */ ADCTSC = 0; //XP_PST(NOP_MODE); ret = request_irq(IRQ_ADC_DONE, adcdone_int_handler, DEVICE_NAME, NULL); if (ret) { return ret; }

27

SA_INTERRUPT,

搜索更多关于: 嵌入式系统设计AD转换器 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

#define ADC_READY 0 #define NOP_MODE 0 #define X_AXIS_MODE 1 #define Y_AXIS_MODE 2 #define WAIT_INT_MODE 3 /* ... */ #define ADCCON_ECFLG (1 << 15) #define PRESCALE_ENDIS (1 << 14) #define PRESCALE_DIS (PRESCALE_ENDIS*0) #define PRESCALE_EN (PRESCALE_ENDIS*1) #define PRSCVL(x) (x << 6) #define ADC_INPUT(x) (x << 3) #define ADCCON_STDBM (1 << 2) /* 1: standby mo

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com