亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
123456下一頁(yè)
最近訪問板塊 發(fā)新帖
查看: 18017 | 回復(fù): 56
打印 上一主題 下一主題

請(qǐng)教一個(gè)ADC0809驅(qū)動(dòng)的問題,高人進(jìn) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2008-11-17 15:54 |只看該作者 |倒序?yàn)g覽
這個(gè)驅(qū)動(dòng)一直看不怎么懂,去問客服,客服也不說(shuō) 說(shuō)什么是程序員寫得 不知道 郁悶死了
這個(gè)是華恒ARM9-S3C2410的試驗(yàn)箱的一個(gè)  ad0809模塊的驅(qū)動(dòng)程序
/* driver/char/adc0809.c
*  this is a adc0809 char device driver.
* Any problem pls contact support@hhcn.com
*/
#include <module.h>
#include <linux/fs.h>
#include <linux/iobuf.h>
#include <linux/major.h>
#include <linux/blkdev.h>
#include <linux/capability.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch/cpu_s3c2410.h>
#include <asm/io.h>
#include <linux/vmalloc.h>

#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <asm/irq.h>
#include <asm/arch/hardware.h>
#include <asm/arch/irqs.h>

#include "adc0809_ioctl.h"

#define ADC0809_MAJOR 231
/*define the adc0809 major node is 231*/


#define adc0809_sle (*(volatile unsigned long *)ADC_GPACON)
#define adc0809_sle_data (*(volatile unsigned long *)ADC_GPADATA)

unsigned long ADC_GPACON, ADC_GPADATA;
unsigned long ADC_0, ADC_1, ADC_2, ADC_3, ADC_4, ADC_5, ADC_6, ADC_7;
unsigned long ADC_DATA;

unsigned long adc_write_addr;
unsigned long adc_read_addr;


devfs_handle_t devfs_adc;

void adc0809_interrupt(int,void *,struct pt_regs *);

int  adc0809_open(struct inode *, struct file *);
int  adc0809_release(struct inode *, struct file *);
int  adc0809_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
ssize_t adc0809_read(struct file *, char * , size_t , loff_t *);
ssize_t adc0809_write(struct file *, const char *, size_t , loff_t *);

static struct file_operations adc0809_fops = {
       ioctl:          adc0809_ioctl,
       open:           adc0809_open,
       read:           adc0809_read,
       write:          adc0809_write,
       release:        adc0809_release,
};

unsigned long data;
unsigned long addr;

void adc0809_interrupt(int irq,void *d,struct pt_regs *regs)
{
/*clear interrupt register for INT 2*/
printk("********************** adc0809_interrupt *********************\n");
SRCPND &= (~0x00000004);    //clear interrupt (bit2)
INTPND = INTPND;
//  EINTPEND &= (~0x00000004);  //bit2

printk("interrupt process!\n");

//udelay(100000);
adc_read_addr = ioremap(0x10000020,4);

/* read ad converter's result */
data = (*(volatile unsigned long *) adc_read_addr);

}

/*
* Open/close code for raw IO.
*/
int adc0809_open(struct inode *inode, struct file *filp)
{
adc_read_addr = ADC_DATA;

printk("open ok\n");
return 0;
}

ssize_t adc0809_read(struct file *filp, char * buf,
                size_t size, loff_t *offp)
{
char key;
key = data;
data = 0;
if(key == 0){
//printk("adc0809_read:have no data to read\n");
return 0;
}
put_user(key,buf);

return 1;
}

ssize_t adc0809_write(struct file *filp, const char *buf,
                 size_t size, loff_t *offp)
這個(gè)寫函數(shù)什么時(shí)候調(diào)用,運(yùn)行,起什么作用的?看了測(cè)試程序沒有調(diào)用,哪放在這里有什么用,僅僅是因?yàn)?br /> 驅(qū)動(dòng)程序框架是這樣嗎?
{
  char key;
  if (get_user(key, buf))
      return -EFAULT;
  printk("adc0809_write:adc_write_addr=0x%x; key = %c\n",adc_write_addr,key);

(*(volatile unsigned char *) adc_write_addr) = key;
  //put_user(key,buf);
  return 1;
}

//__ioremap
int adc0809_release(struct inode *inode, struct file *filp)
{
       printk("release ok\n");
       return 0;
}

/*
* Deal with ioctls against the raw-device control interface, to bind
* and unbind other raw devices.
*/
int adc0809_ioctl(struct inode *inode,
                 struct file *flip,
                 unsigned int command,
                 unsigned long arg)
{
     int err = 0;
     switch (command) {
case IOCTRL_ADC_0:
adc_write_addr = ADC_0;
//printk("adc0809_ioctl: adc addr: %x\n",adc_write_addr);
/* start collect and convert */
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_1:
adc_write_addr = ADC_1;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_2:
adc_write_addr = ADC_2;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
給2通道地址所指向的空間賦值(char) arg,是啟動(dòng)轉(zhuǎn)換的意思嗎?賦任意值都可以嗎?這里賦select只是為了方便嗎?
上面這條語(yǔ)句和write()函數(shù)有什么聯(lián)系,除了賦值之外,會(huì)調(diào)用write()函數(shù)嗎?
return 0;
case IOCTRL_ADC_3:
adc_write_addr = ADC_3;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_4:
adc_write_addr = ADC_4;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_5:
adc_write_addr = ADC_5;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_6:
adc_write_addr = ADC_6;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
case IOCTRL_ADC_7:
adc_write_addr = ADC_7;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
default:
err = -EINVAL;
     }
     // adc_read_addr = ADC_DATA;
     adc_write_addr = ADC_2;
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
   
     return err;
}

int __init adc0809_init(void)
{
static int result;
unsigned long gpfup;
volatile unsigned int bankcon2;

printk("*********************adc0809_init**************\n");

ADC_GPACON = (unsigned int)ioremap(0x56000000,4);
ADC_GPADATA = ioremap(0x56000004,4);

ADC_0 = ioremap(0x10000010,4);
ADC_1 = ioremap(0x10002010,4);
ADC_2 = ioremap(0x10004010,4);
ADC_3 = ioremap(0x10006010,4);
ADC_4 = ioremap(0x10008010,4);
ADC_5 = ioremap(0x1000a010,4);
ADC_6 = ioremap(0x1000c010,4);
ADC_7 = ioremap(0x1000e010,4);

ADC_DATA = ioremap(0x10000020,4);
這是對(duì)讀數(shù)據(jù)進(jìn)行地址映射,這個(gè)地址和CPLD的邏輯關(guān)系有關(guān)對(duì)嗎?
如果我自己要外接一個(gè)0809,如果我片選信號(hào)用GPB0,那么這個(gè)讀寄存器的地址是否可以設(shè)置為0x56000014
或者任意一個(gè)地址都可以嗎,我想應(yīng)該不可以吧,因?yàn)槲易约和饨?809并沒有用CPLD設(shè)置好的邏輯。

bankcon2=(volatile unsigned int)ioremap(0x4800000c,4);
*(volatile unsigned int*)bankcon2 |= 3<<13;
/* select NGCS2 */
adc0809_sle |= 0x2000;
adc0809_sle_data &= (~0x2000);改語(yǔ)句是將13位清0,上一條已經(jīng)將13位設(shè)置第二功能片選,那么按照2410手冊(cè)
數(shù)據(jù)控制寄存器應(yīng)該是讀到不確定的值,將13為清0又是什么意思?
  上面是片選選中NGCS2,其中的邏輯關(guān)系是否已經(jīng)由CPLD設(shè)置好了?

adc_read_addr = ADC_DATA;

/* set external irq rising edge */
set_external_irq(IRQ_EINT2, EXT_RISING_EDGE, GPIO_PULLUP_DIS);

/* set EINT2 pull up */
gpfup = ioremap(0x56000058,4);
(*(volatile unsigned long *)gpfup) = 0;

printk("adc0809_irq : EXTERNAL_IRQ = %d\n",IRQ_EINT2);

disable_irq(IRQ_EINT2);
enable_irq(IRQ_EINT2);

/* request irq */
result=request_irq(IRQ_EINT2,&adc0809_interrupt,SA_INTERRUPT/*|SA_SHIRQ\*/,"adc0809",NULL);
if (result)
   {
     printk("Can't get assigned irq %d,result=%d\n",IRQ_EINT2,result);
    //              return result;
    }

/* register char device */
devfs_adc =
       devfs_register(NULL,"adc0809",DEVFS_FL_DEFAULT,
      ADC0809_MAJOR, 0,
            S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
      &adc0809_fops,NULL);
       return 0;
}

int __init adc0809_exit(void)
{
free_irq(IRQ_EINT2, adc0809_interrupt);
devfs_unregister(devfs_adc);
return 0;
}

/*
__initcall(adc0809_init);
*/
module_init(adc0809_init);
module_exit(adc0809_exit);

-------------------------------------------
總結(jié)一下,就是:
1.ssize_t adc0809_write(),這個(gè)寫函數(shù)什么時(shí)候調(diào)用,運(yùn)行,起什么作用的?看了測(cè)試程序沒有調(diào)用,哪放在這里有什么用,僅僅是因?yàn)轵?qū)動(dòng)程序框架是這樣嗎?
2.case IOCTRL_ADC_0:
adc_write_addr = ADC_0;  //為什么要不地址賦給adc_write_addr ,整個(gè)驅(qū)動(dòng)的獲取數(shù)據(jù)的過(guò)程都沒有看到有用        
                         //adc_write_addr,這個(gè)adc_write_addr 在整個(gè)驅(qū)動(dòng)中到底是干嘛用的???   
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
給0通道地址所指向的空間賦值(char) arg,是啟動(dòng)轉(zhuǎn)換的意思嗎?賦任意值都可以嗎?這里賦select只是為了方便嗎?上面這條語(yǔ)句和write()函數(shù)有什么聯(lián)系,除了賦值之外,會(huì)調(diào)用write()函數(shù)嗎?
3.中斷的作用是干嘛?難道是用來(lái)啟動(dòng)ADC0809讓他工作?????

希望有好心人能解答~~~~感激不盡~~~~
在線等~~~~~~~~~~~~~~~~~~~~~~~

論壇徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
2 [報(bào)告]
發(fā)表于 2008-11-17 16:02 |只看該作者

回復(fù) #1 ady2002 的帖子

貼代碼的時(shí)候,最好用【code】+【/code】把它組織一下,這樣看起來(lái)舒服一點(diǎn)

[ 本帖最后由 dreamice 于 2008-11-17 16:04 編輯 ]

論壇徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
3 [報(bào)告]
發(fā)表于 2008-11-17 16:10 |只看該作者
1.ssize_t adc0809_write(),這個(gè)寫函數(shù)什么時(shí)候調(diào)用,運(yùn)行,起什么作用的?看了測(cè)試程序沒有調(diào)用,哪放在這里有什么用,僅僅是因?yàn)轵?qū)動(dòng)程序框架是這樣嗎?
===> 如果你應(yīng)用程序要寫這個(gè)設(shè)備,那么就會(huì)調(diào)用到這個(gè)函數(shù),并把你寫的數(shù)據(jù)保存到adc_write_addr這個(gè)地址,實(shí)際上只寫了一個(gè)字節(jié)。

論壇徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
4 [報(bào)告]
發(fā)表于 2008-11-17 16:13 |只看該作者
2.case IOCTRL_ADC_0:
adc_write_addr = ADC_0;  //為什么要不地址賦給adc_write_addr ,整個(gè)驅(qū)動(dòng)的獲取數(shù)據(jù)的過(guò)程都沒有看到有用        
                         //adc_write_addr,這個(gè)adc_write_addr 在整個(gè)驅(qū)動(dòng)中到底是干嘛用的???   
(*(volatile unsigned char *) adc_write_addr) = (char) arg;
return 0;
給0通道地址所指向的空間賦值(char) arg,是啟動(dòng)轉(zhuǎn)換的意思嗎?賦任意值都可以嗎?這里賦select只是為了方便嗎?上面這條語(yǔ)句和write()函數(shù)有什么聯(lián)系,除了賦值之外,會(huì)調(diào)用write()函數(shù)嗎?
==>我想這個(gè)只是一個(gè)測(cè)試程序,這個(gè)地址是你用戶空間程序?qū)懴聛?lái)的數(shù)據(jù),最終寫到的那個(gè)地址。這個(gè)case,也就是把ADC_0寫到這個(gè)地址去,用ioctl來(lái)實(shí)現(xiàn)操作,而省去了用戶程序的寫傳遞。

[ 本帖最后由 dreamice 于 2008-11-17 16:26 編輯 ]

論壇徽章:
3
金牛座
日期:2014-06-14 22:04:062015年辭舊歲徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:45
5 [報(bào)告]
發(fā)表于 2008-11-17 16:16 |只看該作者
最后一個(gè)問題:
“//udelay(100000);
adc_read_addr = ioremap(0x10000020,4);

/* read ad converter's result */
data = (*(volatile unsigned long *) adc_read_addr);

看清楚這段程序。中斷的作用就是告訴你,設(shè)備接收到數(shù)據(jù)了。然后把數(shù)據(jù)映射到一個(gè)地址(adc_read_addr = ioremap(0x10000020,4);),最后把值傳遞給data這個(gè)全局變量,你的用戶空間的程序就可以read它了。

論壇徽章:
36
IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-10 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-16 06:20:0015-16賽季CBA聯(lián)賽之廣東
日期:2016-04-16 19:59:32IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-18 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-19 06:20:00每日論壇發(fā)貼之星
日期:2016-04-19 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-08 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-13 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-28 06:20:00每日論壇發(fā)貼之星
日期:2016-05-28 06:20:00
6 [報(bào)告]
發(fā)表于 2008-11-17 16:23 |只看該作者
ADC0809基本上是教學(xué)中最常用的ADC,單片機(jī)中舉例有就是用的這個(gè)芯片。這個(gè)芯片的操作比較簡(jiǎn)單,建議LZ看一下芯片手冊(cè),了解這個(gè)芯片的工作方法,然后再對(duì)照著驅(qū)動(dòng)看,應(yīng)該會(huì)比較快的理解

論壇徽章:
0
7 [報(bào)告]
發(fā)表于 2008-11-17 16:35 |只看該作者
原帖由 dreamice 于 2008-11-17 16:10 發(fā)表
1.ssize_t adc0809_write(),這個(gè)寫函數(shù)什么時(shí)候調(diào)用,運(yùn)行,起什么作用的?看了測(cè)試程序沒有調(diào)用,哪放在這里有什么用,僅僅是因?yàn)轵?qū)動(dòng)程序框架是這樣嗎?
===> 如果你應(yīng)用程序要寫這個(gè)設(shè)備,那么就會(huì)調(diào)用到 ...

多謝 版主的熱心講解~~~~
情況是這樣的,這個(gè)驅(qū)動(dòng)是用來(lái)數(shù)模轉(zhuǎn)換的,而測(cè)試程序只是用來(lái)讀取轉(zhuǎn)換后的數(shù)字,也就是說(shuō)根本沒有用到adc0809_write這個(gè)函數(shù)
我把測(cè)試程序代碼貼出來(lái) 相信大家能看的更清楚點(diǎn)哦呵呵
  1. /* adc0809_test.c
  2. *  this is a adc0809 char device driver test program.
  3. * Any problem pls contact [email]support@hhcn.com[/email]
  4. */
  5. #include <sys/types.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8. #include <sys/socket.h>
  9. #include <syslog.h>
  10. #include <signal.h>
  11. #include <errno.h>
  12. #include <unistd.h>
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <sys/socket.h>
  16. #include <syslog.h>
  17. #include <signal.h>

  18. #include "adc0809_ioctl.h"

  19. int main()
  20. {
  21.         int adc_fd,count;
  22.         int select = 0;       
  23.         int i = 0;
  24.         adc_fd = open("/dev/adc0809",O_RDWR);
  25.         if (adc_fd <= 0){
  26.                 printf("open adc0809 device error\n");
  27.                 return 0;
  28.         }

  29.         printf("please input which input do u want:\n");
  30.         scanf("%d",&select);
  31.         //ioctl(adc_fd,select,select);//start collect and convert
  32.         while(1)
  33.         {       
  34.                 char ret[2];
  35.                 ioctl(adc_fd,select,select);
  36.                 count = read(adc_fd,ret,1);//read ad converter's result
  37.                 if (count != 0){
  38.                   printf("key = %d\n", ret[0]);
  39.                 }
  40.                 sleep(3);
  41.         }       
  42.         close(adc_fd);
  43.         return 0;
  44. }

復(fù)制代碼


這while這個(gè)循環(huán)里,如果ioctl函數(shù)在while循環(huán)之外,一直read的數(shù)據(jù)是一樣的,只有循環(huán)的ioctl才能獲取新的數(shù)據(jù)
所以我猜想 ioctl這個(gè)函數(shù)是不是使能ADC0809芯片讓他工作,以觸發(fā)中斷,但是在驅(qū)動(dòng)中又看不懂到底是怎么觸發(fā)中斷的
很是不解啊。case IOCTRL_ADC_0: adc_write_addr = ADC_0;這兩句其實(shí)是選著相應(yīng)的ADC0809的管腳,也就是所
讀取相應(yīng)0809的管腳的轉(zhuǎn)換后的數(shù)據(jù)。希望版主能幫我仔細(xì)看看怎么回事 已經(jīng)苦惱一個(gè)月了~~~感激不盡啊

[ 本帖最后由 dreamice 于 2008-11-17 16:40 編輯 ]

論壇徽章:
0
8 [報(bào)告]
發(fā)表于 2008-11-17 16:36 |只看該作者
原帖由 Godbach 于 2008-11-17 16:23 發(fā)表
ADC0809基本上是教學(xué)中最常用的ADC,單片機(jī)中舉例有就是用的這個(gè)芯片。這個(gè)芯片的操作比較簡(jiǎn)單,建議LZ看一下芯片手冊(cè),了解這個(gè)芯片的工作方法,然后再對(duì)照著驅(qū)動(dòng)看,應(yīng)該會(huì)比較快的理解

這個(gè)我已經(jīng)看過(guò)了 也知道是怎么工作的哦  但是板子的ADC是連接在cpld上的 所以具體管腳怎么接的不是很不清楚

論壇徽章:
0
9 [報(bào)告]
發(fā)表于 2008-11-17 16:39 |只看該作者
原帖由 dreamice 于 2008-11-17 16:16 發(fā)表
最后一個(gè)問題:
“//udelay(100000);
adc_read_addr = ioremap(0x10000020,4);

/* read ad converter's result */
data = (*(volatile unsigned long *) adc_read_addr);

看清楚這段程序。中斷的作用 ...

恩 這個(gè)中斷內(nèi)的函數(shù)我是看的懂的

我是想知道  驅(qū)動(dòng)是通過(guò)什么方式來(lái)觸發(fā)這個(gè)中斷的,中斷觸發(fā)后 是不是會(huì)去配置一下ADC0809的相應(yīng)管腳
這一點(diǎn) 程序里看不見哦

論壇徽章:
36
IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-10 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-16 06:20:0015-16賽季CBA聯(lián)賽之廣東
日期:2016-04-16 19:59:32IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-18 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-19 06:20:00每日論壇發(fā)貼之星
日期:2016-04-19 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-08 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-13 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-28 06:20:00每日論壇發(fā)貼之星
日期:2016-05-28 06:20:00
10 [報(bào)告]
發(fā)表于 2008-11-17 16:39 |只看該作者
read對(duì)應(yīng)ADC0809的讀函數(shù)在哪里。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP