<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>记录点滴 &#187; 嵌入式</title>
	<atom:link href="http://ganquan.org/blog/category/%e5%b5%8c%e5%85%a5%e5%bc%8f/feed/" rel="self" type="application/rss+xml" />
	<link>http://ganquan.org/blog</link>
	<description>http://ganquan.org</description>
	<lastBuildDate>Sun, 05 Feb 2012 14:51:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>拍照紀念</title>
		<link>http://ganquan.org/blog/2010/04/photo-memory/</link>
		<comments>http://ganquan.org/blog/2010/04/photo-memory/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 15:28:01 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[嵌入式]]></category>
		<category><![CDATA[生活点滴]]></category>

		<guid isPermaLink="false">http://ganquan.org/blog/?p=1089</guid>
		<description><![CDATA[經過整個團隊20天努力，項目預期效果實現，一切OK。從學長，老師，同學身上都學習到了不少知識，收穫很多。後續我繼續玩這個板子的機會可能不多了，拍照紀念一下。9.7寸的電子紙，比市面上很多電子紙閱讀器都要大40%左右，看起來很舒服。 這個sketcher程序是板子的demo。]]></description>
			<content:encoded><![CDATA[<p><span style="font-size: medium;">經過整個團隊20天努力，項目預期效果實現，一切OK。從學長，老師，同學身上都學習到了不少知識，收穫很多。後續我繼續玩這個板子的機會可能不多了，拍照紀念一下。9.7寸的電子紙，比市面上很多電子紙閱讀器都要大40%左右，</span><span style="font-size: medium;">看起來很舒服。</span></p>
<p><span style="font-size: medium;">這個sketcher程序是板子的demo。</span></p>
<p style="text-align: center;"><span style="font-size: medium;"><a href="http://ganquan.org/blog/wp-content/uploads/2010/04/IMAG0046.jpg"><img class="aligncenter size-full wp-image-1090" title="IMAG0046" src="http://ganquan.org/blog/wp-content/uploads/2010/04/IMAG0046.jpg" alt="" width="640" height="428" /></a><br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2010/04/photo-memory/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>移植2.6.32内核到mini2440开发板</title>
		<link>http://ganquan.org/blog/2009/12/2-6-32-port-to-mini2440/</link>
		<comments>http://ganquan.org/blog/2009/12/2-6-32-port-to-mini2440/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 08:02:01 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[嵌入式]]></category>

		<guid isPermaLink="false">http://ganquan.org/blog/?p=598</guid>
		<description><![CDATA[转载请注明出处：http://ganquan.org，谢谢。本文链接是http://ganquan.org/blog/2009/12/2-6-32-port-to-mini2440/ 过程非常简单，麻烦的是如果出问题，就要要一遍又一遍的编译。 先上图： 友善官方的Qtopia系统我早就看烦了，直接启动进入字符界面 下面是移植步骤， 1.www.kernel.org下载内核代码，修改构架和编译器 2.修改时钟频率，mini2440开发板用的是12M晶振，修改arch/arm/mach-s3c2440/mach-smdk2440.c 把下面代码中的16934400改为12000000，如果不改串口会出现乱码 static void __init smdk2440_map_io(void) { s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc)); s3c24xx_init_clocks(12000000); s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs)); } 3.修改mini2440的lcd配置，有两个地方要修改，第一是修改LCD屏幕的参数，第二是修改fbi 修改LCD屏幕参数，mini2440使用的是3.5寸的屏幕，在arch/arm/mach-s3c2440/mach-smdk2440.c中，写入 3.1修改LCD参数结构。 #define LCD_WIDTH 240 #define LCD_HEIGHT 320 #define LCD_PIXCLOCK 170000 #define LCD_RIGHT_MARGIN 25 #define LCD_LEFT_MARGIN 0 #define LCD_HSYNC_LEN 4 #define LCD_UPPER_MARGIN 1 #define LCD_LOWER_MARGIN 4 #define LCD_VSYNC_LEN 1 修改lcd参数结构为： static struct s3c2410fb_display mini2440_lcd_cfg __initdata [...]]]></description>
			<content:encoded><![CDATA[<p>转载请注明出处：http://ganquan.org，谢谢。本文链接是<span id="sample-permalink">http://ganquan.org/blog/2009/12/<span id="editable-post-name" title="点击编辑这部分固定链接">2-6-32-port-to-mini2440</span>/</span></p>
<p>过程非常简单，麻烦的是如果出问题，就要要一遍又一遍的编译。</p>
<p>先上图：</p>
<p style="text-align: center;">友善官方的Qtopia系统我早就看烦了，直接启动进入字符界面</p>
<p><img class="aligncenter size-full wp-image-599" title="img_3676" src="http://ganquan.org/blog/wp-content/uploads/2009/12/img_3676.jpg" alt="img_3676" width="540" height="303" /></p>
<p>下面是移植步骤，</p>
<p><strong><span style="font-size: large;">1.</span></strong>www.kernel.org下载内核代码，修改构架和编译器</p>
<p><strong><span style="font-size: large;">2.</span></strong>修改时钟频率，mini2440开发板用的是12M晶振，修改arch/arm/mach-s3c2440/mach-smdk2440.c</p>
<p>把下面代码中的16934400改为12000000，如果不改串口会出现乱码</p>
<blockquote><p><span style="font-size: medium;">static void __init smdk2440_map_io(void)<br />
{<br />
s3c24xx_init_io(smdk2440_iodesc, ARRAY_SIZE(smdk2440_iodesc));<br />
s3c24xx_init_clocks(12000000);<br />
s3c24xx_init_uarts(smdk2440_uartcfgs, ARRAY_SIZE(smdk2440_uartcfgs));<br />
}</span><span style="font-size: medium;"><br />
</span></p></blockquote>
<p><strong><span style="font-size: large;">3.</span></strong>修改mini2440的lcd配置，有两个地方要修改，第一是修改LCD屏幕的参数，第二是修改fbi</p>
<p>修改LCD屏幕参数，mini2440使用的是3.5寸的屏幕，在arch/arm/mach-s3c2440/mach-smdk2440.c中，写入</p>
<ul>
<li><strong><span style="font-size: medium;">3.1</span></strong>修改LCD参数结构。</li>
</ul>
<blockquote><p><span style="font-size: medium;">#define LCD_WIDTH 240<br />
#define LCD_HEIGHT 320<br />
#define LCD_PIXCLOCK 170000</span></p>
<p><span style="font-size: medium;">#define LCD_RIGHT_MARGIN 25<br />
#define LCD_LEFT_MARGIN 0<br />
#define LCD_HSYNC_LEN 4</span></p>
<p><span style="font-size: medium;">#define LCD_UPPER_MARGIN 1<br />
#define LCD_LOWER_MARGIN 4<br />
#define LCD_VSYNC_LEN 1</span></p>
<p><span style="font-size: medium;">修改lcd参数结构为：</span></p>
<p><span style="font-size: medium;">static struct s3c2410fb_display mini2440_lcd_cfg __initdata = {</span></p>
<p><span style="font-size: medium;">#if !defined (LCD_CON5)<br />
.lcdcon5    = S3C2410_LCDCON5_FRM565 |<br />
S3C2410_LCDCON5_INVVLINE |<br />
S3C2410_LCDCON5_INVVFRAME |<br />
S3C2410_LCDCON5_PWREN |<br />
S3C2410_LCDCON5_HWSWP,<br />
#else<br />
.lcdcon5    = LCD_CON5,<br />
#endif</span></p>
<p><span style="font-size: medium;">.type        = S3C2410_LCDCON1_TFT,</span></p>
<p><span style="font-size: medium;">.width        = LCD_WIDTH,<br />
.height        = LCD_HEIGHT,</span></p>
<p><span style="font-size: medium;">.pixclock    = LCD_PIXCLOCK,<br />
.xres        = LCD_WIDTH,<br />
.yres        = LCD_HEIGHT,<br />
.bpp        = 16,<br />
.left_margin    = LCD_LEFT_MARGIN + 1,<br />
.right_margin    = LCD_RIGHT_MARGIN + 1,<br />
.hsync_len    = LCD_HSYNC_LEN + 1,<br />
.upper_margin    = LCD_UPPER_MARGIN + 1,<br />
.lower_margin    = LCD_LOWER_MARGIN + 1,<br />
.vsync_len    = LCD_VSYNC_LEN + 1,<br />
};</span></p></blockquote>
<ul>
<li><strong><span style="font-size: medium;">3.2</span></strong><span style="font-size: small;">修改fbi</span></li>
</ul>
<blockquote><p><span style="font-size: medium;">static struct s3c2410fb_mach_info smdk2440_fb_info __initdata = {<br />
.displays    = &amp;smdk2440_lcd_cfg,<br />
.num_displays    = 1,<br />
.default_display = 0,</span></p>
<p><span style="font-size: medium;">.gpccon =       0xaa955699,<br />
.gpccon_mask =  0xffc003cc,<br />
.gpcup =        0x0000ffff,<br />
.gpcup_mask =   0xffffffff,</span></p>
<p><span style="font-size: medium;">.gpdcon =       0xaa95aaa1,<br />
.gpdcon_mask =  0xffc0fff0,<br />
.gpdup =        0x0000faff,<br />
.gpdup_mask =   0xffffffff,</span></p>
<p><span style="font-size: medium;">.lpcsel        = 0xf82,<br />
};</span></p></blockquote>
<p><strong><span style="font-size: large;">4.</span></strong>修改nand分区表，修改arch/arm/plat-s3c24xx/common-smdk.c，这个根据自己的情况来写，照抄是没用滴。</p>
<blockquote><p><span style="font-size: medium;">static struct mtd_partition smdk_default_nand_part[] = {<br />
[0] = {<br />
.name    = “bootloader”,<br />
.size    = 0&#215;00060000,<br />
.offset    = 0,<br />
},<br />
[1] = {<br />
.name    = “kernel”,<br />
.offset = 0&#215;00060000,<br />
.size    = 0&#215;00200000,<br />
},<br />
[2] = {<br />
.name    = “root”,<br />
.offset = 0&#215;00260000,<br />
.size    = 0x3fd80000,<br />
}<br />
};</span></p></blockquote>
<p><strong><span style="font-size: large;">5.</span></strong>修改machine ID，修改arch/arm/tools/mach-types，填写自己的machine ID</p>
<blockquote><p>s3c2440            ARCH_S3C2440        S3C2440            1999</p></blockquote>
<p><strong><span style="font-size: large;">6.</span></strong>给内核打yaffs文件系统的补丁。去http://www.aleph1.co.uk/cgi-bin/viewcvs.cgi/下载GNU tarball，解压后进入yaffs2目录，给内核打补丁</p>
<blockquote><p><span style="font-size: medium;">./patch-ker.sh c ~/kernel/linux-2.6.32</span></p></blockquote>
<p>补丁打好后，在内核代码目录下的fs目录新增了yaffs2目录和相关配置文件</p>
<p><span style="font-size: large;"><strong>7.</strong></span>因为2410和2440很多地方是一样的，可以用2410的配置文件为基础来配置内核。在内核代码主目录下执行：</p>
<blockquote><p><span style="font-size: medium;">make s3c2410_defconfig</span></p></blockquote>
<p>这个命令其实就是把arch/arm/configs/s3c2410_defconfig文件拷贝过来命名为.config，所以也可以自己cp。其实在2.6.31版内核中就已经加入了对mini2440开发板的支持，但是我没有选。</p>
<p>配置内核这里没有什么好说的，按照自己的需求来配置。</p>
<p>注意两个问题：</p>
<p>（1）编译后的镜像大小不要超过分区配额</p>
<p>（2）不要裁剪太狠了，把一些基本支持都去掉了，这样一些设备就用不了啦</p>
<p>开始编译。我的机器配置是Core 2 T5500 1.66G，2.5G 内存，运行Debian Lenny 5.0.3，编译10分钟左右就OK了。</p>
<p>网卡驱动我一直没有移植成功。后面弄好了再写上来。</p>
<p>EOF</p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/12/2-6-32-port-to-mini2440/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>mini2440 button驱动分析</title>
		<link>http://ganquan.org/blog/2009/08/mini2440-button%e9%a9%b1%e5%8a%a8%e5%88%86%e6%9e%90/</link>
		<comments>http://ganquan.org/blog/2009/08/mini2440-button%e9%a9%b1%e5%8a%a8%e5%88%86%e6%9e%90/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 17:34:21 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[嵌入式]]></category>
		<category><![CDATA[驱动]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=372</guid>
		<description><![CDATA[基本上读懂了，有些几个地方还不明白。 由于wp-syntax插件显示代码实在让我看着眼睛难受，我决定换一种方式贴代码。点击下面的链接试试： mini2440 button驱动注释 mini2440 leds驱动注释]]></description>
			<content:encoded><![CDATA[<p>基本上读懂了，有些几个地方还不明白。</p>
<p>由于wp-syntax插件显示代码实在让我看着眼睛难受，我决定换一种方式贴代码。点击下面的链接试试：</p>
<p><a href="http://www.imganquan.org/code/modules/mini2440_buttons.c.html" target="_blank">mini2440 button驱动注释</a></p>
<p><a href="http://www.imganquan.org/code/modules/mini2440_leds.c.html" target="_blank">mini2440 leds驱动注释</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/mini2440-button%e9%a9%b1%e5%8a%a8%e5%88%86%e6%9e%90/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>volatile关键字</title>
		<link>http://ganquan.org/blog/2009/08/volatile%e5%85%b3%e9%94%ae%e5%ad%97/</link>
		<comments>http://ganquan.org/blog/2009/08/volatile%e5%85%b3%e9%94%ae%e5%ad%97/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 03:47:44 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[嵌入式]]></category>
		<category><![CDATA[程序设计]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=367</guid>
		<description><![CDATA[用它声明的类型变量表示可以被某些编译器未知的因素更改，比如：操作系统、硬件或者其它线程等。遇到这个关键字声明的变量，编译器对访问该变量的代码就不再进行优化，从而可以提供对特殊地址的稳定访问。在嵌入式系统中，用来作为硬件动作的结果。 例如，通过一个串口接收到一个字符，结果串口状态寄存器更新，这完全在程序流程之外发生。最好就把该寄存器声明为volatile，编译器不会试图优化一个volatile寄存器，而是每次重载它。所以在嵌入式设备的程序中，将所有外设寄存器声明为volatile是一个好习惯。]]></description>
			<content:encoded><![CDATA[<p>用它声明的类型变量表示可以被某些编译器未知的因素更改，比如：操作系统、硬件或者其它线程等。遇到这个关键字声明的变量，编译器对访问该变量的代码就不再进行优化，从而可以提供对特殊地址的稳定访问。在嵌入式系统中，用来作为硬件动作的结果。</p>
<p>例如，通过一个串口接收到一个字符，结果串口状态寄存器更新，这完全在程序流程之外发生。最好就把该寄存器声明为volatile，编译器不会试图优化一个volatile寄存器，而是每次重载它。所以在嵌入式设备的程序中，将所有外设寄存器声明为volatile是一个好习惯。</p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/volatile%e5%85%b3%e9%94%ae%e5%ad%97/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mini2440 LED驱动详解</title>
		<link>http://ganquan.org/blog/2009/08/mini2440-led%e9%a9%b1%e5%8a%a8%e8%af%a6%e8%a7%a3/</link>
		<comments>http://ganquan.org/blog/2009/08/mini2440-led%e9%a9%b1%e5%8a%a8%e8%af%a6%e8%a7%a3/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 13:22:01 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[嵌入式]]></category>
		<category><![CDATA[驱动]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=357</guid>
		<description><![CDATA[从最简单的LED驱动入手，彻底细致的分析一遍mini2440的LED驱动。 官方手册上写，mini2440的四个LED与CPU的GPIO相连，LED1, LED2, LED3, LED4分别对应的 是GPB5, GPB6, GPB7, GPB8。那什么是GPIO呢？ GPIO是通用输入输出口的简称，只需要设置相应的CPU寄存器，就可以改变引脚的用途。 控制硬件，其实就是控制对应的寄存器。 四个LED的采用GPBCON寄存器上的4组2bit位来配置对应引脚的状态。4组2bit位的功能都 一样：00表示输入，01表示输出，10为特殊功能，11是保留的。 LED1对应的是GPB5, GPB5使用[11:10]位 LED2对应的是GPB6, GPB6使用[12:13]位 LED3对应的是GPB7, GPB7使用[14:15]位 LED4对应的是GPB8, GPB8使用[16:17]位 驱动需要先设置LED为输出状态，也就是要把对应的GPBX设置为01。 四个LED采用CPBDAT寄存器来对应4个LED的数值状态，GPBDAT5就对应GPB5，GPBDAT6就对 应GPB6，以此类推。手册上写低电平有效，就是说当GPBDAT寄存器位置为0时，LED就发光。 在三星官方的手册S3C2440.pdf中描述的寄存器状态如下： GPB8 [17:16] 00 = Input 01 = Output 10 = nXDREQ1 11 = Reserved GPB7 [15:14] 00 = Input 01 = Output 10 = nXDACK1 11 = Reserved GPB6 [13:12] [...]]]></description>
			<content:encoded><![CDATA[<p>从最简单的LED驱动入手，彻底细致的分析一遍mini2440的LED驱动。</p>
<p>官方手册上写，mini2440的四个LED与CPU的GPIO相连，LED1, LED2, LED3, LED4分别对应的<br />
是GPB5, GPB6, GPB7, GPB8。那什么是GPIO呢？</p>
<p>GPIO是通用输入输出口的简称，只需要设置相应的CPU寄存器，就可以改变引脚的用途。<br />
控制硬件，其实就是控制对应的寄存器。</p>
<p>四个LED的采用GPBCON寄存器上的4组2bit位来配置对应引脚的状态。4组2bit位的功能都<br />
一样：00表示输入，01表示输出，10为特殊功能，11是保留的。<br />
LED1对应的是GPB5, GPB5使用[11:10]位<br />
LED2对应的是GPB6, GPB6使用[12:13]位<br />
LED3对应的是GPB7, GPB7使用[14:15]位<br />
LED4对应的是GPB8, GPB8使用[16:17]位<br />
驱动需要先设置LED为输出状态，也就是要把对应的GPBX设置为01。</p>
<p>四个LED采用CPBDAT寄存器来对应4个LED的数值状态，GPBDAT5就对应GPB5，GPBDAT6就对<br />
应GPB6，以此类推。手册上写低电平有效，就是说当GPBDAT寄存器位置为0时，LED就发光。</p>
<p>在三星官方的手册S3C2440.pdf中描述的寄存器状态如下：<br />
GPB8 [17:16] 00 = Input 01 = Output<br />
10 = nXDREQ1 11 = Reserved<br />
GPB7 [15:14] 00 = Input 01 = Output<br />
10 = nXDACK1 11 = Reserved<br />
GPB6 [13:12] 00 = Input 01 = Output<br />
10 = nXBREQ 11 = reserved<br />
GPB5 [11:10] 00 = Input 01 = Output<br />
10 = nXBACK 11 = reserved</p>
<p>GPBDAT Bit Description<br />
GPB[10:0] [10:0] When the port is configured as input port, the corresponding<br />
bit is the pin state. When the port is configured as output port, the pin state is the same<br />
as the corresponding bit. When the port is configured as functional pin, the<br />
undefined value will be read.</p>
<p>贴出添加注释后的代码，非常简单的驱动。</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &lt;linux/miscdevice.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/delay.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/irq.h&gt;</span>
<span style="color: #339933;">#include &lt;mach/regs-gpio.h&gt;</span>
<span style="color: #339933;">#include &lt;mach/hardware.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/kernel.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/module.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/init.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/mm.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/fs.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/types.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/delay.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/moduleparam.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/slab.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/errno.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/ioctl.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/cdev.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/string.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/list.h&gt;</span>
<span style="color: #339933;">#include &lt;linux/pci.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/uaccess.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/atomic.h&gt;</span>
<span style="color: #339933;">#include &lt;asm/unistd.h&gt;</span>
&nbsp;
<span style="color: #339933;">#define DEVICE_NAME &quot;leds&quot; /* /dev目录下的设备名 */</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* GPBX */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> led_table <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	S3C2410_GPB5<span style="color: #339933;">,</span>
	S3C2410_GPB6<span style="color: #339933;">,</span>
	S3C2410_GPB7<span style="color: #339933;">,</span>
	S3C2410_GPB8<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #808080; font-style: italic;">/* GPBX的输出状态 */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> led_cfg_table <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	S3C2410_GPB5_OUTP<span style="color: #339933;">,</span>
	S3C2410_GPB6_OUTP<span style="color: #339933;">,</span>
	S3C2410_GPB7_OUTP<span style="color: #339933;">,</span>
	S3C2410_GPB8_OUTP<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* 驱动接口函数
* ioctl的内核空间版本和用户控件的版本不同
* 内核版为：
* int (*ioctl)( struct inode *inode, struct file *file, unsigned int
* cmd, unsigned long arg);
* */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> sbc2440_leds_ioctl<span style="color: #009900;">&#40;</span>
	<span style="color: #993333;">struct</span> inode <span style="color: #339933;">*</span>inode<span style="color: #339933;">,</span>
	<span style="color: #993333;">struct</span> file <span style="color: #339933;">*</span>file<span style="color: #339933;">,</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">int</span> cmd<span style="color: #339933;">,</span>
	<span style="color: #993333;">unsigned</span> <span style="color: #993333;">long</span> arg<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">switch</span><span style="color: #009900;">&#40;</span>cmd<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">:</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000dd;">1</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>arg <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #0000dd;">4</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* Invalid argument,非法参数 */</span>
		<span style="color: #009900;">&#125;</span>
       <span style="color: #808080; font-style: italic;">/* 设置数据寄存器GPBDAT
		* 低电平有效，用户程序传来的cmd取反
		* */</span>
		s3c2410_gpio_setpin<span style="color: #009900;">&#40;</span>led_table<span style="color: #009900;">&#91;</span>arg<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #339933;">!</span>cmd<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
		<span style="color: #b1b100;">return</span> <span style="color: #339933;">-</span>EINVAL<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* 接口对象 */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> file_operations dev_fops <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	.<span style="color: #202020;">owner</span>	<span style="color: #339933;">=</span>	THIS_MODULE<span style="color: #339933;">,</span>
	.<span style="color: #202020;">ioctl</span>	<span style="color: #339933;">=</span>	sbc2440_leds_ioctl<span style="color: #339933;">,</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* 设备对象 */</span>
<span style="color: #993333;">static</span> <span style="color: #993333;">struct</span> miscdevice misc <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span>
	.<span style="color: #202020;">minor</span> <span style="color: #339933;">=</span> MISC_DYNAMIC_MINOR<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* 动态设备号 */</span>
	.<span style="color: #202020;">name</span> <span style="color: #339933;">=</span> DEVICE_NAME<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* 将在/dev目录生成led设备 */</span>
	.<span style="color: #202020;">fops</span> <span style="color: #339933;">=</span> <span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>dev_fops<span style="color: #339933;">,</span> <span style="color: #808080; font-style: italic;">/* 驱动接口 */</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">int</span> __init dev_init<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #993333;">int</span> ret<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #993333;">int</span> i<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> <span style="color: #0000dd;">4</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #808080; font-style: italic;">/*设置GPIO对应的配置寄存器GPIOCON为输出状态*/</span>
		s3c2410_gpio_cfgpin<span style="color: #009900;">&#40;</span>led_table<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> led_cfg_table<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #808080; font-style: italic;">/*设置GPIO对应的数据寄存器GPIODAT为低电平
		 *在模块加载结束后，四个LED应该是全部都是发光状态*/</span>
		s3c2410_gpio_setpin<span style="color: #009900;">&#40;</span>led_table<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	ret <span style="color: #339933;">=</span> misc_register<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>misc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 注册设备 */</span>
&nbsp;
	printk <span style="color: #009900;">&#40;</span>DEVICE_NAME<span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>initialized<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* dmesg */</span>
&nbsp;
	<span style="color: #b1b100;">return</span> ret<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #993333;">static</span> <span style="color: #993333;">void</span> __exit dev_exit<span style="color: #009900;">&#40;</span><span style="color: #993333;">void</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	misc_deregister<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>amp<span style="color: #339933;">;</span>misc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                     <span style="color: #808080; font-style: italic;">/* 注销设备 */</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
module_init<span style="color: #009900;">&#40;</span>dev_init<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 声明加载模块初始化函数 */</span>
module_exit<span style="color: #009900;">&#40;</span>dev_exit<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 声明卸载模块清除函数 */</span>
MODULE_LICENSE<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;GPL&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 许可证声明 */</span>
MODULE_AUTHOR<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;FriendlyARM Inc.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #808080; font-style: italic;">/* 作者信息 */</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/mini2440-led%e9%a9%b1%e5%8a%a8%e8%af%a6%e8%a7%a3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NFS开发环境建立</title>
		<link>http://ganquan.org/blog/2009/08/nfs%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%bb%ba%e7%ab%8b/</link>
		<comments>http://ganquan.org/blog/2009/08/nfs%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%bb%ba%e7%ab%8b/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 15:55:27 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[嵌入式]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=352</guid>
		<description><![CDATA[晚上在学校里转了好几个卖电脑配件的地方，都没有卖usb转串口线的，继续找，最后在老综合楼复印店找到了，只剩最后一个，35元。既然是最后一个，就肯定讲不了价，我和店家商量如果系统不能识别就退货，他同意了，咬牙拿下。 回到宿舍赶紧接上开发板，然后火速装上minicom，立即测试，太爽了，一切OK。这下就可以NFS开发了。 基本步骤如下，比较容易，后面有时间再细致的补一下笔记。 1.debian上安装nfs-kernel-server，配置好nfs-server 2.按照手册上的方法把环境配出来 3.配置好minicom，用minicom进入板子的shell 4.在板子上挂载笔记本上的开发目录 5.运行程序不用下载到板子了，在minicom中./myapp就可以了 对Linux很亲热，所以很顺手。感慨一下，Linux这个东西真的太猛了，这么多方便的方式给我选择： a.可以在笔记本上开发，编译链接得到elf之后用U盘拷贝到板子 b.用串口下载到板子 c.用ftp上传到板子 d.用NFS方式，都不用下载到板子了，这样相当于把板子的FLASH扩大了，因为是用笔记本的硬盘当FLASH，这个是最佳方式。 上述3个方式中，windows不装linux虚拟机的情况下可以使用前三个。还是原生使用linux爽啊，以后就用最佳方式NFS了。]]></description>
			<content:encoded><![CDATA[<p>晚上在学校里转了好几个卖电脑配件的地方，都没有卖usb转串口线的，继续找，最后在老综合楼复印店找到了，只剩最后一个，35元。既然是最后一个，就肯定讲不了价，我和店家商量如果系统不能识别就退货，他同意了，咬牙拿下。</p>
<p>回到宿舍赶紧接上开发板，然后火速装上minicom，立即测试，太爽了，一切OK。这下就可以NFS开发了。</p>
<p>基本步骤如下，比较容易，后面有时间再细致的补一下笔记。</p>
<p>1.debian上安装nfs-kernel-server，配置好nfs-server</p>
<p>2.按照手册上的方法把环境配出来</p>
<p>3.配置好minicom，用minicom进入板子的shell</p>
<p>4.在板子上挂载笔记本上的开发目录</p>
<p>5.运行程序不用下载到板子了，在minicom中./myapp就可以了</p>
<p>对Linux很亲热，所以很顺手。感慨一下，Linux这个东西真的太猛了，这么多方便的方式给我选择：</p>
<p>a.可以在笔记本上开发，编译链接得到elf之后用U盘拷贝到板子</p>
<p>b.用串口下载到板子</p>
<p>c.用ftp上传到板子</p>
<p>d.用NFS方式，都不用下载到板子了，这样相当于把板子的FLASH扩大了，因为是用笔记本的硬盘当FLASH，这个是最佳方式。</p>
<p>上述3个方式中，windows不装linux虚拟机的情况下可以使用前三个。还是原生使用linux爽啊，以后就用最佳方式NFS了。</p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/nfs%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e5%bb%ba%e7%ab%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>misc设备</title>
		<link>http://ganquan.org/blog/2009/08/misc%e8%ae%be%e5%a4%87/</link>
		<comments>http://ganquan.org/blog/2009/08/misc%e8%ae%be%e5%a4%87/#comments</comments>
		<pubDate>Wed, 19 Aug 2009 11:28:31 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[嵌入式]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=350</guid>
		<description><![CDATA[手册上说LED是misc设备，我在开发板上看/dev/leds，给出的是字符设备，这就奇怪了。我以前只知道有字符设备，块设备，对misc没有一点概念。赶紧google一下： 杂项设备（misc device） 杂项设备也是在嵌入式系统中用得比较多的一种设备驱动。在 Linux 内核的include\linux目录下有Miscdevice.h文件，要把自己定义的misc device从设备定义在这里。其实是因为这些字符设备不符合预先确定的字符设备范畴，所有这些设备采用主编号10，一起归于misc device，其实misc_register就是用主标号10调用register_chrdev()的。 也就是说，misc设备其实也就是特殊的字符设备。]]></description>
			<content:encoded><![CDATA[<p>手册上说LED是misc设备，我在开发板上看/dev/leds，给出的是字符设备，这就奇怪了。我以前只知道有字符设备，块设备，对misc没有一点概念。赶紧google一下：</p>
<p><strong>杂项设备（misc device）<br />
</strong>杂项设备也是在嵌入式系统中用得比较多的一种设备驱动。在 Linux 内核的include\linux目录下有Miscdevice.h文件，要把自己定义的misc device从设备定义在这里。其实是因为这些字符设备不符合预先确定的字符设备范畴，所有这些设备采用主编号10，一起归于misc device，其实misc_register就是用主标号10调用register_chrdev()的。</p>
<p>也就是说，misc设备其实也就是特殊的字符设备。</p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/misc%e8%ae%be%e5%a4%87/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>在mini2440上的helloworld</title>
		<link>http://ganquan.org/blog/2009/08/%e5%9c%a8mini2440%e4%b8%8a%e7%9a%84helloworld/</link>
		<comments>http://ganquan.org/blog/2009/08/%e5%9c%a8mini2440%e4%b8%8a%e7%9a%84helloworld/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 14:07:41 +0000</pubDate>
		<dc:creator>ganquan</dc:creator>
				<category><![CDATA[嵌入式]]></category>

		<guid isPermaLink="false">http://imganquan.org/blog/?p=343</guid>
		<description><![CDATA[搭建开发环境很容易，跟着手册做，官方是在fedora上搭建的，我在debian上也非常顺利。第一个程序，拍照纪念。]]></description>
			<content:encoded><![CDATA[<p>搭建开发环境很容易，跟着手册做，官方是在fedora上搭建的，我在debian上也非常顺利。第一个程序，拍照纪念。</p>
<p style="text-align: center;"><img class="size-full wp-image-344 aligncenter" title="img_2986" src="http://ganquan.org/blog/wp-content/uploads/2009/08/img_2986.jpg" alt="img_2986" width="600" height="337" /></p>
]]></content:encoded>
			<wfw:commentRss>http://ganquan.org/blog/2009/08/%e5%9c%a8mini2440%e4%b8%8a%e7%9a%84helloworld/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

