




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
LED顯示控制+文件系統(tǒng)定制系名:專業(yè):指導(dǎo)教師:姓名:學(xué)號(hào):班級(jí):組員:科目:二○一年月目錄一、設(shè)計(jì)任務(wù)和技術(shù)要求:.二、器件介紹……………三、設(shè)計(jì)代碼:………………………….四、設(shè)計(jì)結(jié)果:..五、系統(tǒng)評(píng)價(jià):.六、心得體會(huì):.一、設(shè)計(jì)任務(wù)和技術(shù)要求:編寫LED驅(qū)動(dòng)程序,驅(qū)動(dòng)程序采用手動(dòng)定義設(shè)備名稱〔自己姓名拼音_led〕和主設(shè)備號(hào),設(shè)備號(hào)必須是系統(tǒng)尚未使用的設(shè)備號(hào)編寫對(duì)應(yīng)驅(qū)動(dòng)的makefile文件將驅(qū)動(dòng)程序編譯成模塊,并實(shí)現(xiàn)模塊的加載及卸載編寫驅(qū)動(dòng)測(cè)試程序,要求運(yùn)行該測(cè)試程序后,能夠?qū)ed設(shè)備翻開成功與否做出判斷;能夠顯示led控制菜單項(xiàng)選擇項(xiàng)〔至少2個(gè)控制選項(xiàng)〕,例如,選擇“1〞,led等循環(huán)點(diǎn)亮;選擇“2〞,指定led1燈點(diǎn)亮編寫對(duì)應(yīng)測(cè)試程序的makefile文件文件系統(tǒng)定制要求:制作文件系統(tǒng)類型為yaffs的文件系統(tǒng);文件系統(tǒng)啟動(dòng)時(shí)顯示小組成員信息;文件系統(tǒng)啟動(dòng)時(shí)需要按提示輸入用戶名信息;文件系統(tǒng)成功掛載后,通過串口傳送剛剛編寫的led控制程序,并運(yùn)行該led控制程序,要求能夠按照規(guī)定的控制方式實(shí)現(xiàn)led燈的控制二、設(shè)計(jì)代碼程序清單:應(yīng)用程序測(cè)試leds_test.c如下:#include<stdio.h>#include<stdlib.h>#include<unistd.h>#include<sys/ioctl.h>#defineIOCTL_LED_ON1#defineIOCTL_LED_OFF5#defineIOCTL_LED_RUN3voidusage(char*exename){ printf("Usage:\n"); printf("%s<led_no><on/off>\n",exename); printf("led_no=1,2,3or4\n");}intmain(intargc,char**argv){ unsignedintled_no; intfd=-1;unsignedintcount=10; if(argc>3||argc==1) gotoerr; fd=open("/dev/cylled",0);//翻開設(shè)備 if(fd<0){ printf("Can'topen/dev/fdwled,\n"); return-1; } if(argc==2){ if(!strcmp(argv[1],"run")) { ioctl(fd,IOCTL_LED_RUN,count);//運(yùn)行跑馬燈}else{ gotoerr; } } if(argc==3){ led_no=strtoul(argv[1],NULL,0)-1;//操作哪個(gè)LED? if(led_no>3) gotoerr; if(!strcmp(argv[2],"on")){ ioctl(fd,IOCTL_LED_ON,led_no);//點(diǎn)亮 }elseif(!strcmp(argv[2],"off")){ ioctl(fd,IOCTL_LED_OFF,led_no);//熄滅 }else{ gotoerr; } } close(fd); return0;err:按鍵驅(qū)動(dòng):/*
*linux/drivers/char/mini210_buttons.c
*
*Thisprogramisfreesoftware;youcanredistributeitand/ormodify
*itunderthetermsoftheGNUGeneralPublicLicenseversion2as
*publishedbytheFreeSoftwareFoundation.
*/
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/fs.h>
#include<linux/init.h>
#include<linux/delay.h>
#include<linux/poll.h>
#include<linux/irq.h>
#include<asm/irq.h>
#include<asm/io.h>
#include<linux/interrupt.h>
#include<asm/uaccess.h>
#include<mach/hardware.h>
#include<linux/platform_device.h>
#include<linux/cdev.h>
#include<linux/miscdevice.h>
#include<mach/map.h>
#include<mach/gpio.h>
#include<mach/regs-clock.h>
#include<mach/regs-gpio.h>
#defineDEVICE_NAME"buttons"
structbutton_desc{
intgpio;
intnumber;
char*name;
structtimer_listtimer;
};
staticstructbutton_descbuttons[]={
{S5PV210_GPH2(0),0,"KEY0"},
{S5PV210_GPH2(1),1,"KEY1"},
{S5PV210_GPH2(2),2,"KEY2"},
{S5PV210_GPH2(3),3,"KEY3"},
{S5PV210_GPH3(0),4,"KEY4"},
{S5PV210_GPH3(1),5,"KEY5"},
{S5PV210_GPH3(2),6,"KEY6"},
{S5PV210_GPH3(3),7,"KEY7"},
};
staticvolatilecharkey_values[]={
'0','0','0','0','0','0','0','0'
};
staticDECLARE_WAIT_QUEUE_HEAD(button_waitq);
staticvolatileintev_press=0;
staticvoidmini210_buttons_timer(unsignedlong_data)
{
structbutton_desc*bdata=(structbutton_desc*)_data;
intdown;
intnumber;
unsignedtmp;
tmp=gpio_get_value(bdata->gpio);
/*activelow*/
down=!tmp;
printk("KEY%d:%08x\n",bdata->number,down);
number=bdata->number;
if(down!=(key_values[number]&1)){
key_values[number]='0'+down;
ev_press=1;
wake_up_interruptible(&button_waitq);
}
}
staticirqreturn_tbutton_interrupt(intirq,void*dev_id)
{
structbutton_desc*bdata=(structbutton_desc*)dev_id;
mod_timer(&bdata->timer,jiffies+msecs_to_jiffies(40));
returnIRQ_HANDLED;
}
staticintmini210_buttons_open(structinode*inode,structfile*file)
{
intirq;
inti;
interr=0;
for(i=0;i<ARRAY_SIZE(buttons);i++){
if(!buttons[i].gpio)
continue;
setup_timer(&buttons[i].timer,mini210_buttons_timer,
(unsignedlong)&buttons[i]);
irq=gpio_to_irq(buttons[i].gpio);
err=request_irq(irq,button_interrupt,IRQ_TYPE_EDGE_BOTH,
buttons[i].name,(void*)&buttons[i]);
if(err)
break;
}
if(err){
i--;
for(;i>=0;i--){
if(!buttons[i].gpio)
continue;
irq=gpio_to_irq(buttons[i].gpio);
disable_irq(irq);
free_irq(irq,(void*)&buttons[i]);
del_timer_sync(&buttons[i].timer);
}
return-EBUSY;
}
ev_press=1;
return0;
}
staticintmini210_buttons_close(structinode*inode,structfile*file)
{
intirq,i;
for(i=0;i<ARRAY_SIZE(buttons);i++){
if(!buttons[i].gpio)
continue;
irq=gpio_to_irq(buttons[i].gpio);
free_irq(irq,(void*)&buttons[i]);
del_timer_sync(&buttons[i].timer);
}
return0;
}
staticintmini210_buttons_read(structfile*filp,char__user*buff,
size_tcount,loff_t*offp)
{
unsignedlongerr;
if(!ev_press){
if(filp->f_flags&O_NONBLOCK)
return-EAGAIN;
else
wait_event_interruptible(button_waitq,ev_press);
}
ev_press=0;
err=copy_to_user((void*)buff,(constvoid*)(&key_values),
min(sizeof(key_values),count));
returnerr?-EFAULT:min(sizeof(key_values),count);
}
staticunsignedintmini210_buttons_poll(structfile*file,
structpoll_table_struct*wait)
{
unsignedintmask=0;
poll_wait(file,&button_waitq,wait);
if(ev_press)
mask|=POLLIN|POLLRDNORM;
returnmask;
}
staticstructfile_operationsdev_fops={
.owner=THIS_MODULE,
.open=mini210_buttons_open,
.release=mini210_buttons_close,
.read=mini210_buttons_read,
.poll=mini210_buttons_poll,
};
staticstructmiscdevicemisc={
.minor=MISC_DYNAMIC_MINOR,
.name=DEVICE_NAME,
.fops=&dev_fops,
};
staticint__initbutton_dev_init(void)
{
intret;
ret=misc_register(&misc);
printk(DEVICE_NAME"\tinitialized\n");
returnret;
}
staticvoid__exitbutton_dev_exit(void)
{
misc_deregister(&misc);
}
module_init(button_dev_init);
module_exit(button_dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("FriendlyARMInc.");程序cylled.c如下〔基于實(shí)驗(yàn)11的代碼進(jìn)行更改〕:#include<linux/kernel.h>#include<linux/module.h>#include<linux/miscdevice.h>#include<linux/fs.h>#include<linux/types.h>#include<linux/moduleparam.h>#include<linux/slab.h>#include<linux/ioctl.h>#include<linux/cdev.h>#include<linux/delay.h>#include<mach/gpio.h>#include<mach/regs-gpio.h>#include<plat/gpio-cfg.h>#defineDEVICE_NAME"cylled"#defineLED_MAJOR222#defineIOCTL_LED_ON1#defineIOCTL_LED_OFF5#defineIOCTL_LED_RUN3%定義三個(gè)宏#defineLED_NUM ARRAY_SIZE(led_gpios)staticintled_gpios[]={ S5PV210_GPJ2(0), S5PV210_GPJ2(1), S5PV210_GPJ2(2), S5PV210_GPJ2(3),};staticlongmini210_leds_ioctl(structfile*filp,unsignedintcmd,unsignedlongarg){ inti; intj; switch(cmd) { caseIOCTL_LED_RUN:%定義RUN,用了兩個(gè)for循環(huán)。 for(i=0;i<arg;i++) { for(j=0;j<4;j++) { gpio_set_value(led_gpios[j],0); msleep(100); gpio_set_value(led_gpios[j],1); } } break; caseIOCTL_LED_ON: if(arg>LED_NUM) { return-EINVAL; } gpio_set_value(led_gpios[arg],0); break; caseIOCTL_LED_OFF: if(arg>LED_NUM) { return-EINVAL; } gpio_set_value(led_gpios[arg],1); break; default: return-EINVAL; } return0;}staticstructfile_operationsmini210_led_dev_fops={ .owner =THIS_MODULE, .unlocked_ioctl=mini210_leds_ioctl,};staticint__initmini210_led_dev_init(void){ intret; inti; for(i=0;i<LED_NUM;i++) { ret=gpio_request(led_gpios[i],"LED"); if(ret) { printk("%s:requestGPIO%dforLEDfailed,ret=%d\n",DEVICE_NAME,led_gpios[i],ret); returnret; } s3c_gpio_cfgpin(led_gpios[i],S3C_GPIO_OUTPUT); gpio_set_value(led_gpios[i],1); } ret=register_chrdev(LED_MAJOR,DEVICE_NAME,&mini210_led_dev_fops); if(ret<0) { printk("%scan'tregi
溫馨提示
- 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ì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 黑龍江職業(yè)學(xué)院《司法法律社會(huì)工作》2023-2024學(xué)年第二學(xué)期期末試卷
- 新疆大學(xué)《水資源系統(tǒng)分析》2023-2024學(xué)年第二學(xué)期期末試卷
- 上海立信會(huì)計(jì)金融學(xué)院《數(shù)據(jù)挖掘與智能分析雙語(yǔ)》2023-2024學(xué)年第二學(xué)期期末試卷
- 山西旅游職業(yè)學(xué)院《用戶界面設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 遼寧省交通高等專科學(xué)?!堆b飾工程計(jì)量與計(jì)價(jià)設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東茂名農(nóng)林科技職業(yè)學(xué)院《建筑設(shè)計(jì)》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣東舞蹈戲劇職業(yè)學(xué)院《基礎(chǔ)醫(yī)學(xué)概論》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025年福建省安全員考試題庫(kù)及答案
- 廣西工業(yè)職業(yè)技術(shù)學(xué)院《器樂合奏2》2023-2024學(xué)年第二學(xué)期期末試卷
- 2025貴州省安全員-B證考試題庫(kù)附答案
- be動(dòng)詞的否定句和一般疑問句2
- (2.1.1)-1.1-1.2舞臺(tái)服裝概念特征
- GB/T 26559-2011機(jī)械式停車設(shè)備分類
- GB/T 22919.2-2008水產(chǎn)配合飼料第2部分:軍曹魚配合飼料
- 數(shù)字化轉(zhuǎn)型中數(shù)據(jù)底座湖倉(cāng)一體化
- 典范英語(yǔ)8-1-刺猬女孩艾蜜
- 《教育管理學(xué)》課件
- 水平井套內(nèi)不動(dòng)管柱滑套多段壓裂工藝技術(shù)全解課件
- 凈水設(shè)備技術(shù)參數(shù)要求
- 腦血管造影護(hù)理課件
- 稱呼禮儀精品課件
評(píng)論
0/150
提交評(píng)論