嵌入式LED實(shí)驗(yàn)_第1頁(yè)
嵌入式LED實(shí)驗(yàn)_第2頁(yè)
嵌入式LED實(shí)驗(yàn)_第3頁(yè)
嵌入式LED實(shí)驗(yàn)_第4頁(yè)
嵌入式LED實(shí)驗(yàn)_第5頁(yè)
已閱讀5頁(yè),還剩13頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上石家莊鐵道大學(xué)嵌入式系統(tǒng)實(shí)驗(yàn)報(bào)告-實(shí)驗(yàn)四 LED 驅(qū)動(dòng)及控制實(shí)驗(yàn)實(shí)驗(yàn)者姓名:崔樂(lè)樂(lè)實(shí)驗(yàn)者學(xué)號(hào):同組人:孔維春實(shí)驗(yàn)者班級(jí):信1201-2所在學(xué)院:信息科學(xué)與技術(shù)學(xué)院課程編號(hào):L指導(dǎo)教師:劉展威報(bào)告完成日期:2015年4月 19 日1. 實(shí)驗(yàn)?zāi)康?了解 ARM 設(shè)備外圍電路結(jié)構(gòu)與接口原理 熟悉 Linux 系統(tǒng)下硬件驅(qū)動(dòng)編程 編程實(shí)現(xiàn)對(duì)嵌入式設(shè)備上 LED 燈的控制2. 實(shí)驗(yàn)內(nèi)容 閱讀 UP-Magic6410 平臺(tái)硬件文檔,熟悉 ARM 處理硬件外圍接口電路 編程實(shí)現(xiàn) UP-Magic6410 平臺(tái)設(shè)備上 LED 驅(qū)動(dòng)及應(yīng)用測(cè)試程序3. 實(shí)驗(yàn)環(huán)境 硬件:UP-Magic

2、6410 型嵌入式實(shí)驗(yàn)平臺(tái),PC 機(jī) Pentium 500 以上, 硬盤 40G 以上,內(nèi)存大于 256M 軟件:Vmware Workstation +Fedora Core 8 + MiniCom/Xshell + ARM-LINUX 交叉編譯開發(fā)環(huán)境4. 實(shí)驗(yàn)原理4.1 硬件接口原理 UP-Magic6410 魔法師實(shí)驗(yàn)套件 LED 硬件接口UP-Magic6410 魔法師實(shí)驗(yàn)套件上共有 5 個(gè) LED 顯示燈,分別接在 S3C6410X 處理器的 GPQ2、GPQ3、GPQ4、GPQ5、GPQ6 上。5 個(gè) LED 顯示燈分別共陽(yáng)極 3.3V 電壓,因此相應(yīng) GPIO 低電平點(diǎn)亮,高

3、電平熄滅。如圖 4.1.1 所示: S3C6410 處理器 GPIO 寄存器S3C6410X 處理器的 GPIO 作為控制 I/O 要進(jìn)行必要的設(shè)置才能對(duì)外設(shè)進(jìn)行正確控制,此實(shí)驗(yàn)將相應(yīng) I/O 設(shè)置為輸出模式,并向相應(yīng) I/O 數(shù)據(jù)寄存器進(jìn)行寫入數(shù)據(jù)便可控制 LED 的開關(guān)。如下表 4.1.2 給出的 S3C6410X GPIO 寄存器配置:GPQ IO 寄存器列表:GPQ 配置寄存器: GPQ 數(shù)據(jù)寄存器:4.2 關(guān)鍵代碼分析Linux 系統(tǒng)下,應(yīng)用程序不可直接操作底層硬件寄存器,必須經(jīng)過(guò)驅(qū)動(dòng)層來(lái)完成對(duì)硬件的操作。 驅(qū)動(dòng)程序分析:#include <linux/module.h>

4、#include <linux/kernel.h>#include <linux/fs.h>#include <linux/init.h>#include <linux/miscdevice.h>#include <linux/delay.h>#include <asm/irq.h>#include <asm/arch/regs-gpio.h>#include <asm/hardware.h>MODULE_LICENSE("GPL");#define DEVICE_NAME &q

5、uot;leds" /驅(qū)動(dòng)名稱#define DEVICE_MAJOR 231 /驅(qū)動(dòng)主設(shè)備號(hào)#define DEVICE_MINOR 0 /驅(qū)動(dòng)次設(shè)備號(hào)/聲明字符設(shè)備類結(jié)構(gòu)struct cdev *mycdev;struct class *myclass;dev_t devno;/ LED GPIO 列表static unsigned long led_table = S3C_GPQ2,S3C_GPQ3,S3C_GPQ4,S3C_GPQ5,S3C_GPQ6,;/ LED GPIO 輸出類型配置列表static unsigned int led_cfg_table = S3C_GPQ

6、2_OUTP,S3C_GPQ3_OUTP,S3C_GPQ4_OUTP,S3C_GPQ5_OUTP,S3C_GPQ6_OUTP,;/ LED IOCTRL 處理函數(shù),主要完成從用戶空間傳遞數(shù)據(jù)進(jìn)行 GPIO 引腳設(shè)置功能static int uptech_leds_ioctl(struct inode *inode,struct file *file,unsigned intcmd,unsigned long arg)switch(cmd) case 0:case 1:if (arg > 6) return -EINVAL;/ LED GPIO 設(shè)置函數(shù)接口s3c_gpio_setpin(

7、led_tablearg, !cmd);return 0;default:return -EINVAL;/ 驅(qū)動(dòng)層 file_operations 接口函數(shù)初始化static struct file_operations uptech_leds_fops = .owner = THIS_MODULE,.ioctl = uptech_leds_ioctl,;/驅(qū)動(dòng)程序入口初始化函數(shù),設(shè)置 LED GPIO、向內(nèi)核注冊(cè)設(shè)備。static int _init uptech_leds_init(void)int ret;int i;/ 注冊(cè) LED 設(shè)備devno = MKDEV(DEVICE_MAJ

8、OR, DEVICE_MINOR);/獲取設(shè)備號(hào)mycdev = cdev_alloc();cdev_init(mycdev, &uptech_leds_fops);/初始化字符設(shè)備err = cdev_add(mycdev, devno, 1);/向系統(tǒng)添加 LED 設(shè)備if (err != 0)printk("s3c leds device register failed!n");myclass = class_create(THIS_MODULE, "leds");if(IS_ERR(myclass) printk("Err: f

9、ailed in creating class.n");return -1;/建立 LED 設(shè)備節(jié)點(diǎn)class_device_create(myclass,NULL, MKDEV(DEVICE_MAJOR,DEVICE_MINOR), NULL,DEVICE_NAME,DEVICE_MINOR);/ LED GPIO 配置初始化for (i = 0; i < 5; i+) s3c_gpio_cfgpin(led_tablei, led_cfg_tablei);s3c_gpio_setpin(led_tablei, 1);printk(DEVICE_NAME " ini

10、tializedn");return 0;/ 驅(qū)動(dòng)卸載函數(shù)static void _exit uptech_leds_exit(void)/ 注銷 LED 驅(qū)動(dòng)設(shè)備unregister_chrdev(LED_MAJOR, DEVICE_NAME);/ 聲明驅(qū)動(dòng)程序入口函數(shù)module_init(uptech_leds_init);/ 聲明驅(qū)動(dòng)程序出口函數(shù)module_exit(uptech_leds_exit); 應(yīng)用程序分析:#include <stdio.h>#include <stdlib.h>#include <unistd.h>#incl

11、ude <sys/ioctl.h>int main(int argc, char *argv)int i;int on;int led_number;int fd;/*根據(jù)命令行參數(shù)內(nèi)容,進(jìn)行控制。將命令行參數(shù) 1 設(shè)置成 LED number,參數(shù) 2 設(shè)置成 LED 點(diǎn)亮熄滅狀態(tài) on*/if (argc != 3 | sscanf(argv1, "%d", &led_number) != 1 | sscanf(argv2,"%d",&on) != 1 |on < 0 | on > 1 | led_number

12、 < 0 | led_number > 5) fprintf(stderr, "Usage:n");fprintf(stderr, "t ./led led_number on|offn");fprintf(stderr, "Options:n");fprintf(stderr, "t led_number from 0 to 4n");fprintf(stderr, "t on: 1 off: 0n");exit(1);/打開 LED 設(shè)備節(jié)點(diǎn)fd = open("/de

13、v/leds", 0);if (fd < 0) perror("open device /dev/leds");exit(1);/調(diào)用驅(qū)動(dòng)層 ioctrl 接口,實(shí)現(xiàn)對(duì) LED 控制ioctl(fd, on, led_number);for(i=0;i<100;i+)usleep(1000);/關(guān)閉 LED 設(shè)備接口close(fd);return 0;5. 實(shí)驗(yàn)步驟 實(shí)驗(yàn)?zāi)夸洠?UP-Magic6410/SRC/kernel/linux-2.6.21/UP-Magic6410/SRC/exp/diver/02_leds/ 在內(nèi)核中添加 LED 設(shè)備模

14、塊驅(qū)動(dòng)1、進(jìn)入宿主機(jī)中 UP-UP6410-II 型光盤內(nèi)核目錄:rootlocalhost # cd /UP-Magic6410/SRC/kernel/linux-2.6.21/2、運(yùn)行 make menuconfig 命令配置內(nèi)核對(duì) LED 模塊的相關(guān)支持選擇 Device Drivers ->選項(xiàng),如圖進(jìn)入 Character devices -> 菜單選擇<M> S3C LEDs Driver 模塊方式編譯 LED 驅(qū)動(dòng),如圖:退出保存配置:3、重新編譯內(nèi)核,運(yùn)行 make 命令rootlocalhost linux-2.6.21# makescripts/kc

15、onfig/conf -s arch/arm/KconfigCHK include/linux/version.hSYMLINK include/asm-arm/arch -> include/asm-arm/arch-s3cmake1: include/asm-arm/mach-types.h' is up to date.CHK include/linux/utsrelease.hCHK include/linux/compile.h最終在內(nèi)核源碼目錄的 drivers/char/目錄下生成 LED 驅(qū)動(dòng)程序 s3c-leds.korootlocalhost linux-2.

16、6.21# ls drivers/char/s3c-leds.kodrivers/char/s3c-leds.korootlocalhost linux-2.6.21#備注:以上在內(nèi)核中添加對(duì) LED 設(shè)備的支持的步驟,在 UP-Magic6410 設(shè)備出廠自帶內(nèi)核中已經(jīng)默認(rèn)添加進(jìn)入了, 用戶可以省略以上步驟。 以上步驟在于重現(xiàn)系統(tǒng)的構(gòu)造。 LED 相應(yīng)驅(qū)動(dòng)已經(jīng)在本實(shí)驗(yàn)?zāi)夸浀?driver 目錄下給出。 編譯 LED 應(yīng)用測(cè)試程序1、進(jìn)入實(shí)驗(yàn)?zāi)夸洠簉ootlocalhost # cd /UP-Magic6410/SRC/exp/driver/02_leds/rootlocalhost 02_l

17、eds# lsMakefile driver led.c led.o led.sh test_ledrootlocalhost 02_leds#2、清除中間代碼,重新編譯rootlocalhost 02_leds# make cleanrm -f test_led *.elf *.gdb *.orootlocalhost 02_leds#rootlocalhost 02_leds# makearm-linux-gcc -c -o led.o led.carm-linux-gcc -o test_led led.o lmrootlocalhost 02_leds# lsMakefile driv

18、er led.c led.o led.sh test_ledrootlocalhost 02_leds#當(dāng)前目錄下生成可執(zhí)行程序 test_led。 NFS 掛載實(shí)驗(yàn)?zāi)夸洔y(cè)試1、啟動(dòng) UP-Magic6410 實(shí)驗(yàn)系統(tǒng),連好網(wǎng)線、串口線。通過(guò)串口終端掛載宿主機(jī)實(shí)驗(yàn)?zāi)夸?。rootUP_6410 yaffs# mountnfs 192.168.1.145:/UP-Magic6410 /mnt/nfs/2、進(jìn)入串口終端的 NFS 共享實(shí)驗(yàn)?zāi)夸?。rootUP_6410 yaffs# cd /mnt/nfs/SRC/exp/driver/02_leds/rootUP_6410 02_leds# lsMa

19、kefile driver led.c led.o led.sh test_ledrootUP_6410 02_leds#3、加載 LED 驅(qū)動(dòng)程序。rootUP_6410 02_leds# insmod driver/s3c-leds.koleds initializedrootUP_6410 02_leds#此時(shí)會(huì)在 UP-Magic6410 型設(shè)備的/dev 目錄下產(chǎn)生/dev/leds 設(shè)備節(jié)點(diǎn)。4、執(zhí)行應(yīng)用程序測(cè)試該驅(qū)動(dòng)點(diǎn)亮 LED1rootUP_6410 02_leds# ./test_led 1 1 熄滅 LED1rootUP_6410 02_leds# ./test_led 1 0點(diǎn)亮 LED2rootUP_6410 02_leds# ./test_led 2 1熄滅 LED2rootUP_6410 02_leds# ./test_le

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論