TQ210LED驅(qū)動(dòng)流水燈_第1頁(yè)
TQ210LED驅(qū)動(dòng)流水燈_第2頁(yè)
TQ210LED驅(qū)動(dòng)流水燈_第3頁(yè)
TQ210LED驅(qū)動(dòng)流水燈_第4頁(yè)
TQ210LED驅(qū)動(dòng)流水燈_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、TQ210 LED軀動(dòng)及測(cè)試1.編寫led馳朋1.1在系筑中創(chuàng)建目錄/home/share/led/1. #mkdir -p /home/share/led更翎代円進(jìn)人led目錄1. #cd /home/share/led1.2創(chuàng)建瀾碼文件led_driver.c1. #vim led_driver.c復(fù)諛代西溫碼內(nèi)容見附件一。保存退岀.1.3 61 i 并編輯 Makefile在該目錄下僑建Makefile文件,務(wù)驅(qū)動(dòng)程序編譯成模挾。#vim Makefile內(nèi)容如下:1. oj-m +=led_driver.o2. CURRENT_PATH := /home/share/led3. LIN

2、UX_KERNEL ?= /home/share/learning/linux-2.6.354. #LINUX_KERNEL_PATH := $(LINUX_KERNEL)5. default:6. S(MAKE) -C $(LINUX_KERNEL) m=$(CURRENT_PATH) modules7. clean:8. S(MAKE) -C $(LINUX_KERNEL) M=S(CURRENT_PATH) clean盯(代瑪2. 編譯TQ210 使用天 IS 提供交叉編譯器,路徑:/home/share/tmp/opt/EmbedSky/4.4.6/bin在該目錄下直接make即可#m

3、ake3. i 試 led ® 動(dòng)涮試代侶:見附件二使用交叉編譯工具編譯程序:1.# arm-linux-gcc -o led Jest ledjest.c將生成的可執(zhí)行程序 led_test M M 到 nfs 文件糸 /home/share/nfsboot/rootfs 中/mnt目錄下;在趙級(jí)終端上控制開發(fā)板。掛敎好nfs文件系統(tǒng):1. #mount -t nfs 1 :/home/share/nfsboot/rootfs -o nolock /mnt進(jìn)人桂我在/mnt目錄下的nfs文件糸統(tǒng)內(nèi)并且進(jìn)人內(nèi)部/mnt目錄下:#cd /mnt 此目錄是開發(fā)版的子目

4、錄#cd /mnt 此目錄是掛教的宿主機(jī)上的nfs文件系筑的子目錄執(zhí)行可執(zhí)行文件:1 # ./ledJest岀規(guī)段錯(cuò)誤提示,原因參數(shù)不正確,il需要輸人led的序號(hào),以及開關(guān)指令。測(cè)試程序沒有做好參數(shù)檢査,所以會(huì)段錯(cuò)鍥在代碼中對(duì)age進(jìn)行WBiffl可。#./led_test 2 on 打開第二 fled#./led_test 2 off 關(guān)掉第二個(gè) led開發(fā)板上兩個(gè)LED燈均能正確腔制,至此led馳動(dòng)及測(cè)試代網(wǎng)試驗(yàn)完成。附件-led驅(qū)動(dòng)涮碼* drivers/char/tq210_leds.c* tt®簡(jiǎn)要:* 該驅(qū)動(dòng)注冊(cè)一個(gè)字符設(shè)備“/dev/led”,用于2個(gè)LEDO*函數(shù)簡(jiǎn)

5、介:* static void tq210_debug_leds(unsigned int emd,unsigned long arg),用于內(nèi)核驅(qū) 動(dòng)調(diào)試*提供的外部接口:* ioctol(struct inode *inode,struct file *file,unsigned int brightness);* 用于LED的亮,滅。”調(diào)用實(shí)弘*提供控制臺(tái),金令式的測(cè)試程序。*1 #include <linux/miscdevice.h>2. #include <linux/input.h>3. #include <linux/clk.h>4.5.6.

6、7.&3.34.35.#include <linux/delay.h>include <asm/io.h>#include <asm/uaccess.h>#include <mach/map.h>#include <mach/gpio.h>/include <mach/gpio-bank.h>#include <mach/regs-gpio.h>include

7、<plat/rgpio-core.h>include <plat/gpio-cfg.h>include <plat/gpio-cfg-helpers.h>#define DEVICENAME W/*應(yīng)用程序執(zhí)0 iodKfd, cmd. arg)BJ的第2個(gè)參U 7廠the second parameter that application program execute*/ define IOCTL_GPIO_ON1define IOCTL_GPIO_O阡0/*用來福定LED所用的GPIO引関*/*appoint the pin the LED will

8、use*/static unsigned long gpiojable (=S5PV210.GPC0 ,S5PV210_GPC0(4)f;r用來描定gpio引腳的助能:輸出*/appoint the function of the pin:out put*/static unsigned int gpio.cfgjable =S3C_GPIO_SFN ,S3C_GPIO_SFN ,;/static char 0P=«-GPC0.31fGPC0_4-;#ifdef CONFIG_TQ210_DEBUG_LEDS static void tq210_debugJeds(un

9、signed int cmd,unsigned long arg)gpio_direction_output(gpiojablearg, cmd);6.67./s3c.gpio_setpin(gpiojablearg, cmd);static void toggleJed(unsigned int cmd.unsigned long arg)int loop=0:printk(-%s : led %ld toggl

10、e now: n;_func_,arg);for(;loop<11;loop+)cmd = loop%2;printkCleds %d %s narg+1.(cmd)ronYo ff);tq210_debug Jeds(cmd,arg);mdelay(1000);#endif/*決函數(shù)助能:Hff/dev/led投備,設(shè)備各是:/dev/led*fuction:open Zdev/led device .devce name: /dev/led*/static int tq210_gpio_open(struct inode *inode, struct file *file)int i

11、;int err;err = gpio_request(gpio_table0, ,GPC0_3,');if(err)printk(KERN_ERR “failed to request GPC0_3 for LVDS PWDN pinn-); return err;err = gpio_request(gpioJable1 , GPC0_4“); if(err)printk(KERN_ERR "failed to request GPC0_4 for LVDS PWDN pinrf);0.81.82.

12、5.96.97.return err;prlntk(KERN_INFO - leds opened1);for (i = 0; i < sizeof(gpiojable)/sizeof(unsigned long); i+)s3c_gpio_cfgpin(gpiojable, gpio.cfgjable);gpio_directionoutput(gpio_table, 0);/s3cgpio_setpin(gpio_table, 0);#ifdef CONFIG_TQ210_DEBUG_LEDSfor (i =

13、0; i < sizeof(gpiojable)/sizeof(unsigned long); i+)toggle Jed(1?i);#endifreturn 0;/*函數(shù)助能:用干控制led的亮滅*fuction:control the led /turn on & turn offcmd, arg為控仙個(gè)燈的亮滅取値X圍為0-1: cmd片IOCTL_GPIO_ON時(shí)亮,c md 為 IOCTL_GPIO_OFF 力滅Control byte is cmd; arg appointed which led wile be turn on or offjt can be 0 a

14、nd 1;IOC TL_GPI0_0N:tum onJOCTL_GPIO_OFF:turn off.*/static long tq210_gpiojoctl(struct inode *inodefstruct file "file,unsigned int cmd.unsigned long arg)9& 99.arg -二 1;100.if (arg > sizeof(gpio_table)/sizeof(unsigned long)101.102.return -EINVAL:103.104.switch(cmd)105.106.case IOCTL_GPIO_

15、ON:107. i殳習(xí)循定引"的輸岀電平為110&gpio_direction_output(gpio_tablearg, 1);109./s3c_gpio.setpin(gpiojableargf 1);110.return 0;111.case IOCTL_GPIO_OFF:112./ fiSIB定引U的"岀電平片o113.gpio_direction_output(gpio_table(arg, 0);114./s3c_gpio_setpin(gpio_tablearg, 0);115.return 0;116.default:117.return -EINV

16、AL;11&119.1120. static int tq210gpio_close(struct inode *inode. struct file Mile)121. (122.gpiojree(gpio_table0);123.gpio_free(gpio_table1);124.printk(KERNNFO 'TQ210 LEDs driver successfully closen”);125.return 0;126 J127廠駆動(dòng)接口設(shè)ST/12&廠setting the interface of the driver*/ 129. static stru

17、ct file.operations devjops = 總結(jié)資料130.owner=THISMODULE,131.ioctl=tq210_gpiojoctl.132.open = tq210_gpio_open,133.release =tq210_gpio_close,134. ;135. /*設(shè)備箔椰的SS7136. 廠setting the architecture of the device*/137. static struct miscdevice misc = 138.minor = MISC_DYNAMIC_MINOR,139.name = DEVICE_NAME.140.f

18、ops = & devjops,141J;142. nuit設(shè)備,配貿(mào)對(duì)憊的io, nga«a§*/143. /*init the device, config the right IO and register the device*/144. static int _init devjnit(void)145. 146.int ret;147.int i;14&int err;149.#ifdef CONFIG.TQ210.DEBUG.LEDS150.err = gpio.request(gpio_table0, “GPC0_3”);151.if(err

19、)152.153.printk(KERNERR failed to request GPC0_3 for LVDS PWDN pinna);154.return err;155.156.err = gpioequest(gpio_table1, ,GPC0_4,);157.if(err)158.159.printk(KERN_ERR "failed to request GPC0.4 for LVDS PWDN pinng);160.return err;162.for (i = 0; i < sizeof(gpiojable)/sizeof(unsigned long); i

20、+)163.164./Opio.request(flpioJableOLgpio_name);165.s3cgpio_cfgpin(gpiojable, gpio_cfg_table);/ 配胃管問為聯(lián)出 config the pin to out put166.gpiodirectionoutputCgpiojable, 0);167./s3c_gpio_setpin(gpiojable? 0); 設(shè)凰管腳力低電平 config the pin tolow level16&s3c_gpio_setpull(gpiojable, S3C_GPIO_PULL_NONE);169.170.

21、#endif171.ret = misc_register(&misc);172.printk(KERNJNFO "TQ210 LEDs driver successfully probedW);173.#ifdef C0NFIG_TQ210_DEBUG_LEDS174.for (i = 0; i < sizeof(gpio_table)/sizeof(unsigned long); i+)175.176.toggle _led(1,i);177.17&#endif179.return ret;180 J181. r注軸設(shè)備182. 廠log out the d

22、evice*/183. static void _exit dev_exit(void)184. 185.misc_deregister(&misc);186.gpiojree(gpio_table0);187.gpiojree(gpio_table1);18&printk(KERNJNFO "TQ210 LEDs driver successfully exitnM);189.1190. moduleJnit(devJnit);191. module_exit(dev_exit);192. MODULEJJCENSEJGPL”);193. MODULE.AUTHOR

23、C.embedsky:);194. MODULEDESCRIPTIONCLEDS1 Driver);195. 件二led灑試霖硝196. 廠 FILENAM E:ledJest.C197. *AUTHOR:Michael Li198. *DATE:2013-06-03199. *DESCRIPTION:the test of the led driver200. * 7201. #include<stdio.h>202. #include<ftl.h>203. define DEVICENAME 7dev/ledB204. #define IOCTL_LED_ON 12

24、05. #define IOCTL_LED_OFF 0206. int main(int argc, char *argv)207. (20&FILE *fd;209.int led_no = 0;210.fd = (FILE *)open(DEVICENAME.O);211.if(argc < 3)212.213.printfCThe arguments you input are wrongn*);214.printf(aUSE:nM);215.printfCW./programtled-numberton/offn4);216.return -1;217.218./led.

25、no = strtoul(argv1.0.0) -1 ;/its wrong to set like this219.led_no = strtoul(argv1 L0,0);/operate the ledby input 1 and led_2 by input 2220.printfCiniH);221.if(!strcmp(argv2l-on")/turn on the led222.223.ioctl(fdJOCTL_LED_ON,led_no);224.printfCyou want the %d onn:led_no);225. 226. else if(!strcmp

26、(argv2,Moff)/turn off the led227. 22&ioctl(fdJOCTLLED_OFFJed_no);229. )230. elseprintfCerror!');231. return0;232. 233. W件三:海水燈234. rFILENAME:ledJest.c235. *AUTHOR:Michael Li236. *DATE:2013-06-03237. *DESCRIPTION:the test of the led driver.please refer to the label "usage:* below.238*/23

27、9. #include<stdio.h>240. #include<ftl.h>241. include <signal.h>242. /岸include <time.h>243. include <sys/time.h>244. define DEVICENAME 7dev/led"245. define IOCTL_LED_ON 1246. #define IOCTL_LED_OFF 0247. void sigoutime();24&void timerjnit();249. void delay(int ti

28、me);250. int time J = 0;251. int main(int argc, char *argv)252. 253. FILE *fd;254. int led_no = 0;255.int i = 0;fd = (FILE *)open(DEVICENAME.O);256.257.258.259.260.261.262.263.264.265.266.267.26&269.270.271.272.273.274.275.276.277.27&279.280.281.282.283.284.285.286.int delay_grade = 0;timerj

29、nitO;usage:if(argc < 3)printfCThe arguments you input are wrongn*);printfCUSE:nM);printf(,t./programt<right/left/both>t<1/2/3>n,);printfCi3:slow;2:faster;1:fastestn");printf(rteg: ./ledJIowtleftt1ntlet the led light start from left and the speed is the fastestna);return -1;if(!st

30、rcmp(argv ,T)delaygrade = 1;/20mselse if (!(argv2;2r)delay_grade = 15;/300mselse if(!(argv2,3)delay.grade = 50;/1selsedelaygrade = 30:/600msif(!strcmp(argv1l/lefr)/turn on the ledfor(i=0;i<40;i+)if(i%2)!=0)led_no = 1;287.28&289.290.291.292.293.294.295.296.297.29&299.300.301.302.303.304.305.306.307.308.309.310.311.312.313.314.315.316.317.318.elseled.no = 2;ioctl(fdJOCTL_LED_ONJed_no); printfCyou want the %d or)nled_no); delay(delay_grade);ioctl(fdJOCTL_LED_OFF Jed.no);Ielse if(!strcmp(argv1 ,Hrighf)/Aurn off th

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論