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

📄 为系统处理器编写linux设备驱动程序_qqread_com.htm

📁 S3C44B0x下的ADS7843触摸屏驱动资料与代码
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<!-- saved from url=(0050)http://www.qqread.com/linux/2006/10/y216810_2.html -->
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>为系统处理器编写Linux设备驱动程序_QQread.com</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META http-equiv=Content-Language content=zh-CN>
<META content=为系统处理器编写Linux设备驱动程序 name=description><LINK 
href="为系统处理器编写Linux设备驱动程序_QQread_com.files/qqread2007style.css" type=text/css 
rel=stylesheet>
<SCRIPT language=javascript 
src="为系统处理器编写Linux设备驱动程序_QQread_com.files/article.js"></SCRIPT>

<META content="MSHTML 6.00.2900.3157" name=GENERATOR></HEAD>
<BODY>
<DIV class=top>
<DIV class=top_1><SPAN class=font_1>频道直达</SPAN> - <A title=专题频道 
href="http://www.qqread.com/z/" target=_blank>专题</A> - <A title=新闻频道 
href="http://www.qqread.com/news/" target=_blank>新闻</A> - <A title=电脑技巧 
href="http://www.qqread.com/skill/" target=_blank>技巧</A> - <A title=组网建网 
href="http://www.qqread.com/network/" target=_blank>组网</A> - <A title=程序开发 
href="http://www.qqread.com/program/" target=_blank>开发</A> - <A title=安全技术 
href="http://www.qqread.com/safe/" target=_blank>安全</A> - <A title=编程频道 
href="http://www.qqread.com/netprogram/" target=_blank>web编程</A> - <A title=图像处理 
href="http://www.qqread.com/photohandle/" target=_blank>图像</A> - <A title=操作系统 
href="http://www.qqread.com/os/" target=_blank>操作系统</A> - <A title=数据库 
href="http://www.qqread.com/database/" target=_blank>数据库</A> - <A title=巧巧教育 
href="http://edu.qqread.com/" target=_blank>教育</A> - <A title=巧巧旅游 
href="http://travel.qqread.com/" target=_blank>旅游</A> - <A title=巧巧健康 
href="http://health.qqread.com/" target=_blank>健康</A> - <A title=巧巧时尚 
href="http://fashion.qqread.com/" target=_blank>时尚</A> - <A title=驱动下载 
href="http://down.qqread.com/" target=_blank>驱动</A> - <A title=巧巧软件园 
href="http://down.qqread.com/soft/" target=_blank>软件</A> - <A title=网络游戏 
href="http://www.qqread.com/netgame/" target=_blank>游戏</A> - <A title=多媒体 
href="http://www.qqread.com/multimedia/" target=_blank>多媒体</A> - <A title=企业解决方案 
href="http://www.qqread.com/erp/" target=_blank>ERP</A> - <A title=技术讨论组 
href="http://group.qqread.com/" target=_blank>讨论组</A></DIV>
<DIV class=top_2>
<DIV class=top_2_1 id=logo><A href="http://www.qqread.com/"><IMG height=28 
alt=巧巧电脑IT频道Logo216810 
src="为系统处理器编写Linux设备驱动程序_QQread_com.files/QQReadTeach.gif" width=145 
border=0></A></DIV>
<DIV class=top_2_2 id=loc><A href="http://www.qqread.com/">首页</A> &gt; <A 
href="http://www.qqread.com/">电脑教程</A> &gt; <A title=操作系统 
href="http://www.qqread.com/os/index.html">操作系统</A> &gt; <A title=Linux 
href="http://www.qqread.com/linux/index.html">Linux</A> &gt; 正文</DIV>
<DIV class=top_2_3><A href="http://www.qqread.com/linux/rank/" 
target=_blank>阅读排行榜</A> | <A style="CURSOR: pointer" 
onclick=window.external.addFavorite(document.location.href,document.title)>收藏此文</A> 
| <A title=巧巧读书首页 style="CURSOR: pointer" 
onclick="window.external.addFavorite('http://www.qqread.com/','巧巧读书首页')">收藏本站</A> 
| <A 
onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.qqread.com/');return(false);" 
href="http://www.qqread.com/">设为首页</A></DIV></DIV></DIV>
<DIV class=main>
<DIV class=left>
<DIV>
<SCRIPT src="为系统处理器编写Linux设备驱动程序_QQread_com.files/travel.js" 
type=text/javascript></SCRIPT>
</DIV>
<DIV class=left_1>
<H1 id=w_tt>为系统处理器编写Linux设备驱动程序</H1>来源:&nbsp;作者:&nbsp;出处:巧巧读书&nbsp;<SPAN 
id=rdate>2006-10-11</SPAN>&nbsp;<A title=技术论坛 href="http://group.qqread.com/" 
target=_blank>进入讨论组</A></DIV>
<DIV class=left_2><SPAN class=font_3>关 键 词:</SPAN><A class=link_keywords 
href="http://www.qqread.com/linux/index.html" 
target=_blank>linux</A>&nbsp;&nbsp;<A class=link_keywords 
href="http://www.qqread.com/keys/opera/index.html" 
target=_blank>opera</A>&nbsp;&nbsp;<A class=link_keywords 
href="http://www.qqread.com/keys/os/index.html" 
target=_blank>os</A>&nbsp;&nbsp;<A class=link_keywords 
href="http://www.qqread.com/keys/unix/index.html" 
target=_blank>unix</A>&nbsp;&nbsp;<A class=link_keywords 
href="http://www.qqread.com/keys/word/index.html" 
target=_blank>word</A>&nbsp;&nbsp; 
<DIV id=gglink></DIV></DIV>
<DIV class=left_4><A 
href="http://www.qqread.com/linux/2006/10/y216810.html">上一页</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810.html">1</A>&nbsp;<FONT 
color=#ff0000>2</FONT>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_3.html">3</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_4.html">4</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_3.html">下一页</A>&nbsp;</DIV>
<DIV class=left_3 id=artcnt>
<DIV class=left_6_1>
<UL>·<A title="Core 2 Duo与Core Duo处理器对比测试" 
  href="http://www.qqread.com/hardware/cpu/testing/2006/09/p208414.html" 
  target=_blank>Core 2 Duo与Core Duo处理器对比测试</A><BR>·<A 
  title="未来趋势 AMD低功耗双核3800+处理器评测" 
  href="http://www.qqread.com/hardware/cpu/testing/2006/09/y207530.html" 
  target=_blank>未来趋势 AMD低功耗双核3800+处理器评</A><BR>·<A title="采用酷睿2核心 奔腾E双核处理器深入评测" 
  href="http://www.qqread.com/hardware/cpu/testing/2007/03/w305402.html" 
  target=_blank>采用酷睿2核心 奔腾E双核处理器深入评</A><BR>·<A title=你真的了解“双核处理器”吗? 
  href="http://www.qqread.com/pcbase/2006/06/o956123041.html" 
  target=_blank>你真的了解“双核处理器”吗?</A><BR>·<A title=Intel和AMD双核心处理器的比较 
  href="http://www.qqread.com/pcbase/2006/06/v743122041.html" 
  target=_blank>Intel和AMD双核心处理器的比较</A><BR>·<A title="跨越3GHz门槛 AMD X2 6000+处理器测试" 
  href="http://www.qqread.com/hardware/cpu/testing/2007/03/j299852.html" 
  target=_blank>跨越3GHz门槛 AMD X2 6000+处理器测试</A><BR>·<A 
  title="2G轻取3.8G Conroe平台对阵老款P4处理器" 
  href="http://www.qqread.com/hardware/cpu/testing/2006/06/y488128031.html" 
  target=_blank>2G轻取3.8G Conroe平台对阵老款P4处理</A><BR>·<A 
  title="省电就是省钱 低功耗AM2处理器选购指导" 
  href="http://www.qqread.com/hardware/cpu/buying/2006/09/u208415.html" 
  target=_blank>省电就是省钱 低功耗AM2处理器选购指导</A><BR>·<A title="狸猫换太子 揭露盒装双核PD处理器黑幕" 
  href="http://www.qqread.com/hardware/cpu/using/2006/06/k521128031.html" 
  target=_blank>狸猫换太子 揭露盒装双核PD处理器黑幕</A><BR>·<A title="穷人法拉利 AMD最新AM2闪龙处理器快速测试" 
  href="http://www.qqread.com/hardware/cpu/testing/2006/06/r499128031.html" 
  target=_blank>穷人法拉利 AMD最新AM2闪龙处理器快速</A></UL></DIV>
<DIV class=left_6_1 id=w_hzh></DIV>
<P style="TEXT-INDENT: 2em"><B>字符设备驱动程序实例:触摸屏设备驱动程序</B> 
<P style="TEXT-INDENT: 2em">EP9312触摸屏控制器因其数据只能按顺序获取而被列为<A 
href="http://www.qqread.com/linux/index.html" 
target=_blank>Linux</A>字符设备。触摸屏字符驱动程序的执行是相当简单的--设备向操作系统注册,并通过文档系统特殊文件进行访问。有关硬件代码包含在文档操作表的一套函数中。我们将从内核初始化开始,解释该驱动程序的执行情况。 

<P style="TEXT-INDENT: 2em">初始化EP9312触摸屏的函数是: <BR clear=all>
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE> int __init ep93xx_ts_init(void)</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">该函数处理2项工作:当设备被中断驱动时获取设备IRQ和在操作系统内注册触摸屏设备。 
<P style="TEXT-INDENT: 2em">函数request_irq() 
在请求IRQ时被调用,并注册中断处理器函数以在设备发生系统中断时处理所需的任务。 
<P style="TEXT-INDENT: 2em">而函数 register_chrdev() 则是用来注册字符设备的。该函数表现形式如下: 
<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>int register_chrdev(unsigned int major,
  const char * name,
        struct file_operations *fops)</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">该函数安装了字符设备硬件的内核接口。主要编号用于把驱动程序映射到 /dev 
目录中的文档系统特殊文件。设备被赋予一个名称,以便内核识辨。此外,file_operations 结构具有对函数指针表的一个指针,该表指向硬件的相应函数。 
<P 
style="TEXT-INDENT: 2em">然而,仍然有一些字符设备不符合预先确定的字符设备范畴。这些设备就用主编号10一起归于"其他类型",注册设备用以下函数: 

<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE> int misc_register(struct miscdevice * misc)</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">misc_register()用主编号10调用 
register_chrdev(),设备名称和函数表指针通过miscdevice数据结构获得。同样,miscdevice 
数据结构还保存设备驱动程序所使用的次要号码。 
<P style="TEXT-INDENT: 2em">以下是在设备驱动程序代码内注册 EP9312 触摸屏采用的函数调用: 
<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>misc_register(&amp;ep93xx_ts_miscdev)</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">数据结构 ep93xx_ts_miscdev 是对触摸屏硬件的内核访问,定义如下: 
<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>static struct miscdevice ep93xx_ts_miscdev = 
  {
EP93XX_TS_MINOR, /* device minor number */
"ep93xx_ts", /* name of the device */
&amp;ep93xx_ts_fops /* device file operations */
/* table pointer */
        }</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">其他类型设备驱动程序采用次要号码区分设备。 
<P 
style="TEXT-INDENT: 2em">硬件接口函数在设备驱动器内即被静态定义,当设备注册时,由内核通过传递给操作系统的文档操作函数指针获得。指针列表定义如下: 

<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>static struct file_operations ep93xx_ts_fops =
  {
owner: THIS_MODULE,
read: ep93xx_ts_read,
write: ep93xx_ts_write,
poll: ep93xx_ts_poll,
open: ep93xx_ts_open,
release: ep93xx_ts_release,
fasync: ep93xx_ts_fasync,
        }</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">初始化触摸屏设备后,即需创建文档系统特殊文件,以便协助应用程序代码访问设备。创建 EP9312 
触摸屏特殊文件的 mknod 命令如下: 
<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>mknod /dev/misc/ep93xx_ts c 10 240</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em">该步骤即可在根目录系统下的初始化文档初始化 Linux 时得到执行,也可在命令提示里实现手动操作。 
<P style="TEXT-INDENT: 2em">以下是用户级应用代码的一个实例,通过文档系统特殊文件访问触摸屏设备: 
<P style="TEXT-INDENT: 2em">
<CENTER><CCID_NOBR>
<TABLE cellSpacing=0 borderColorDark=#ffffff cellPadding=2 width=400 
align=center borderColorLight=black border=1>
  <TBODY>
  <TR>
    <TD class=code style="FONT-SIZE: 9pt" bgColor=#e6e6e6><PRE><CCID_CODE>#define TS_DEV "/dev/misc/ep93xx_ts"
  int read_ts() 
  {
int fd, nbytes;
short data[3];
  fd = open("/dev/misc/ep93xx_ts", O_NONBLOCK); 
  if ( fd &lt; 0 ) 
{
printf("Unable to open touch screen device %s!\n", TS_DEV);
exit(1);
}
nbytes = read(pd_fd, data, sizeof(data)); 
close(fd);
if (nbytes != sizeof(data)) 
return 0;
return 1;
        }</CCID_CODE></PRE></TD></TR></TBODY></TABLE></CCID_NOBR></CENTER>
<P style="TEXT-INDENT: 2em"><B></B>&nbsp; <IMG height=9 alt=更多文章 
src="为系统处理器编写Linux设备驱动程序_QQread_com.files/dian_1.gif" width=11> 更多内容请看<A 
href="http://www.qqread.com/z/move/p/2.html" target=_blank><FONT 
color=#ff0033>Java依然精彩</FONT></A>&nbsp;&nbsp;<A 
href="http://www.qqread.com/z/linux/safe/index.html" target=_blank><FONT 
color=#ff0033>Linux安全应用宝典</FONT></A>&nbsp;&nbsp;<A 
href="http://www.qqread.com/z/linux/firewall/index.html" target=_blank><FONT 
color=#ff0033>Linux防火墙</FONT></A>专题,或<A class=font_12 title=在这里你会得到众多高手的技术帮助 
href="http://group.qqread.com/" target=_blank>进入讨论组</A>讨论。 </P>
<DIV class=left_6><IMG height=9 alt=更多专题 
src="为系统处理器编写Linux设备驱动程序_QQread_com.files/dian_1.gif" width=11> <SPAN 
class=font_4>【深 度 阅 读】</SPAN> 相 关 文 章 
<DIV class=left_6_1_1>
<LI><A title="潜力不容忽视 酷睿2 E6320处理器详测" 
href="http://www.qqread.com/hardware/cpu/testing/2007/05/r311379.html" 
target=_blank>潜力不容忽视 酷睿2 E6320处理器详测</A>
<LI><A title=双核/多核处理器在计算方面的优势 
href="http://www.qqread.com/pcbase/v773101041.html" 
target=_blank>双核/多核处理器在计算方面的优势</A>
<LI><A title=基于S3C2410处理器目标板的Linux移植 
href="http://www.qqread.com/linux/2006/10/f215625.html" 
target=_blank>基于S3C2410处理器目标板的Linux移植</A>
<LI><A title=双核心、多核心处理器发展趋势(1) 
href="http://www.qqread.com/hardware/cpu/v700122031.html" 
target=_blank>双核心、多核心处理器发展趋势(1)</A></LI></DIV></DIV></DIV>
<DIV class=left_4><A 
href="http://www.qqread.com/linux/2006/10/y216810.html">上一页</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810.html">1</A>&nbsp;<FONT 
color=#ff0000>2</FONT>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_3.html">3</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_4.html">4</A>&nbsp;<A 
href="http://www.qqread.com/linux/2006/10/y216810_3.html">下一页</A>&nbsp;</DIV>
<DIV class=left_12>【<A style="CURSOR: pointer" 
onclick=window.external.addFavorite(document.location.href,document.title)>收藏此文</A>】【<A 
href="javascript:doZoom(16)">大</A> <A href="javascript:doZoom(14)">中</A> <A 
href="javascript:doZoom(12)">小</A>】【<A href="javascript:doPrint()">打印</A>】【<A 
href="javascript:window.close()">关闭</A>】</DIV>
<DIV class=left_11><SPAN class=font_8>较早的文章:</SPAN><A title=Linux设备驱动框架、配置文件及加载 
href="http://www.qqread.com/linux/2006/10/y216809.html" 
target=_blank>Linux设备驱动框架、配置文件及加载</A><BR><BR><SPAN class=font_8>较新的文章:</SPAN><A 
title="使用Inotify 监控Linux 文件系统事件" 
href="http://www.qqread.com/linux/2006/10/u216811.html" target=_blank>使用Inotify 
监控Linux 文件系统事件</A><BR></DIV>
<DIV class=left_11 align=center>
<SCRIPT src="" type=text/javascript></SCRIPT>
</DIV>
<DIV class=left_10>
<DIV class=left_7><SPAN class=font_10>相关图文阅读</SPAN></DIV>

⌨️ 快捷键说明

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