國(guó)嵌全部實(shí)驗(yàn)手冊(cè)課程5內(nèi)核驅(qū)動(dòng)深入_第1頁
國(guó)嵌全部實(shí)驗(yàn)手冊(cè)課程5內(nèi)核驅(qū)動(dòng)深入_第2頁
國(guó)嵌全部實(shí)驗(yàn)手冊(cè)課程5內(nèi)核驅(qū)動(dòng)深入_第3頁
國(guó)嵌全部實(shí)驗(yàn)手冊(cè)課程5內(nèi)核驅(qū)動(dòng)深入_第4頁
國(guó)嵌全部實(shí)驗(yàn)手冊(cè)課程5內(nèi)核驅(qū)動(dòng)深入_第5頁
已閱讀5頁,還剩132頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

Linux國(guó)嵌嵌入式LINUX 歸屬國(guó)嵌(簡(jiǎn)稱“國(guó)嵌所有1.1:kobject #cd/home/guoqian/5-4-1#cpkobject.ko#ls#ls #ls/sys/kobject_test/ #cat#echo1234>/ #ls 件系統(tǒng)相似,相比于proc文件系統(tǒng),使用sysfs導(dǎo)出內(nèi)核數(shù)據(jù)的方式實(shí)驗(yàn)1.2:bus#cd/home/guoqian/5-4-2#cpbus.ko#ls#ls#ls被調(diào)用,函數(shù)完成總線/sys/bus/my_bus的。#ls#ls表明總線設(shè)備/sys/devices/my_bus0被。9.總線屬性文件信#cat#ls/sys/bus#ls1.3:device#cd/home/guoqian/5-4-3#cpdevice.ko#ls#ls#ls/sys/devices/my_bus0/#ls加設(shè)備/sys/bus/my_bus/devices/my_dev、設(shè)備#cat#ls/sys/devices/my_bus0實(shí)驗(yàn)1.4:driver#cd/home/guoqian/5-4-4#cpdriver.ko#ls#ls#insmodbus.ko打印輸出語句Driverfounddevicewhichmydrivercanhandle!”;除了驅(qū)動(dòng),函數(shù)my_driver_init還調(diào)用函數(shù)#ls#ls#cat#ls實(shí)驗(yàn)1.5:tform驅(qū)動(dòng)模使用tform驅(qū)動(dòng)模型改寫按鍵驅(qū)動(dòng)程序#cd/home/guoqian/5-4-5 configARCH=arm<>ButtonsdriverforFriendlyARMMini2440/QQ2440developmentboards#make#cpt_device.kot_buttons.ko#insmodt_device.ko#insmodt_buttons.ko說明:在加載t_buttons內(nèi)核模塊時(shí),模塊初始化函數(shù)buttons_init被調(diào)用,該函數(shù)完成t_driver的定義和配方式為平臺(tái)設(shè)備定義的名字和驅(qū)動(dòng)的名字是否一致;如果匹配成功,說明的驅(qū)動(dòng)能驅(qū)動(dòng)該設(shè)備,則驅(qū)動(dòng)中函數(shù)mini2440_buttons_probe(t_buttons.c)被調(diào)斷的,以及采用混雜型字符設(shè)備驅(qū)動(dòng)的方式按鍵#ls-l/dev/*|grep#arm-linux-gcc–staticapp-button.c–oapp-button#cpapp-button/nfsroot/rootfs/tmp運(yùn)試程#rmmodt_buttons.ko#rmmodt_device.ko總結(jié):tform是一種虛擬的總線,tform驅(qū)動(dòng)與傳統(tǒng)的設(shè)實(shí)驗(yàn) init{printk(KERN_INFO"%sEthernetDriver,V%s\n",CARDNAME,/*平臺(tái)驅(qū)動(dòng)return}.driver= =.owner= = .suspend= =答:當(dāng)平臺(tái)驅(qū)動(dòng)時(shí),內(nèi)核會(huì)在平臺(tái)總線上去遍歷所有代碼drivers/base/tform.c),匹配方式為平臺(tái)設(shè)備定義的名字和驅(qū)動(dòng)的名字是否一致;如果匹配成功,說明的驅(qū)動(dòng)能驅(qū)動(dòng)該設(shè)備,則probe函數(shù)被調(diào)用。 { structboard_info*db;/* structure*/constunsignedchar*mac_src;intret=0;inti;u32/*Initnetworkdeviceif(!ndev)dev_err(&pdev->dev,"couldnotallocatedevice.\n");return-ENOMEM;}SET_NETDEV_DEV(ndev,&pdev->dev);/*setupboardinfostructure*/db=netdev_priv(ndev);memset(db,0,sizeof(*db));db->ndev=ndev; IORESOURCE_MEM,0); IORESOURCE_MEM,1); IORESOURCE_IRQ,0);if(db->addr_res==NULL||db->data_res==NULL||db->irq_res==NULL){ret=-ENOENT;goto}iosize=res_size(db-/*I/Odb->addr_req=request_mem_region(db->addr_res->start,if(db->addr_req==NULL)dev_err(db->dev,"cannotclaimaddressregarea\n");ret=-EIO;goto}/*映射if(db->io_addr==NULL)dev_err(db->dev,"failedtoioremapaddressreg\n");ret=-EINVAL;goto}iosize=res_size(db-db->data_req=request_mem_region(db->data_res->start,if(db->data_req==NULL)dev_err(db->dev,"cannotclaimdataregarea\n");ret=-EIO;goto}db->io_data=ioremap(db->data_res->start,iosize);if(db->io_data==NULL){dev_err(db->dev,"failedtoioremapdatareg\n");ret=-EINVAL;goto}/*fillinparametersfornet-devstructurendev->base_addr=(unsignedlong)db->io_addr;ndev->irq=db->irq_res->start;/*ensureatleastwehaveadefaultsetofIOroutines指針/*checktoseeifanythingisbeingover-riddenif(pdata!=NULL)/*checktoseeifthedriverwantstoover-ride*defaultIOwidthdm9000_set_io(db,1);dm9000_set_io(db,2);dm9000_set_io(db,4);/*checktoseeifthereareanyIO*over-ridesif(pdata->inblk!=db->inblk=pdata-if(pdata->outblk!=db->dumpblk=pdata-db->flags=pdata-}/*復(fù)位/*trymultipletimes,DM9000sometimesgetsthereadwrong*/for(i=0;i<8;i++) =ior(db,id_val|=(u32)ior(db,DM9000_VIDH)<<8;id_val|=(u32)ior(db,DM9000_PIDL)<<16;if(id_val==DM9000_ID)}if(id_val!=DM9000_ID)dev_err(db->dev,"wrongid:0x%08x\n",id_val);ret=-ENODEV;goto}/*IdentifywhattypeofDM9000weareworkingonid_val=ior(db,switch(id_val)casecasedb->type=TYPE_DM9000B; %02x DM9000E\n",id_val);db->type=}/*fromthispointweassumethatwehavefounda/*driversystemfunction = =&dm9000_timeout;ndev->watchdog_timeo=msecs_to_jiffies(watchdog); =&dm9000_stop; =&dm9000_ethtool_ops; =&dm9000_ioctl; =0x1f; =0; =0; =ndev; db- =printk("NowusethedefaultMACaddress:mac_src="friendly-arm";/*tryreadingthenodeaddressfromtheattachedEEPROM*/for(i=0;i<6;i+= NULL){mac_src="tform}/*tryreadingfrommacmac_src="chip";for(i=0;i<6;}Please"setusingifconfig\n",ndev-/*網(wǎng)卡驅(qū)動(dòng)ret=if(ret==printk(KERN_INFO"%s:dm9000%cat%p,%pIRQ%dMAC:%pM(%s)\n",ndev->name,dm9000_type_to_char(db->type),db->io_addr,db->io_data,ndev->irq,}{board_info_t*db= if/*IfthereisnoIRQtypespecified,defaulttosomething ltheuserthatthisisaproblemif(irqflags==dev_warn(db->dev,"WARNING:noIRQresourceflags/*中斷irqflags|= /*InitializeDM9000board/*Initdrivervariable*/ t=0;} net_device*dev){unsignedlongboard_info_t*db=netdev_priv(dev);dm9000_dbg(db,3,"%s:\n", if(db-> t>1)return1;/*MovedatatoDM9000TXRAM*/(db->outblk)(db->io_data,skb->data,skb->len);dev->stats.tx_bytes+=skb->len;db- /*TXcontrol:Firstpacketimmedia ysend,secondpacketqueue*/if(db- t==1)/*SetTXlengthtoDM9000*/iow(db,DM9000_TXPLH,skb->len>>/*IssueTXpollingcommandiow(db,DM9000_TCR,TCR_TXREQ);/* complete*/dev->trans_start=jiffies;/*savethetimestamp}else/*Secondpacketdb->queue_pkt_len=skb->len;} thisSKB*/}{structnet_device*dev=dev_id;intint_status;u8reg_save; /*Arealinterruptcoming/*holdersofdb->lockmustalwaysblockIRQs*/spin_lock_irqsave(&db->lock,flags);/*Savepreviousregisteraddress*/reg_save=readb(db->io_addr);/*Disableallinterrupts/*GotDM9000interruptstatusint_status=ior(db,DM9000_ISR); /*GotISR*/iow(db,DM9000_ISR,int_status);/*ClearISRstatus*/if if(int_status&ISR_PRS)/*TrnasmitInterruptcheckif(int_status&ISR_PTS)if(db->type!=TYPE_DM9000E)/*firealink-changerequest*/}}/*Re-enableinterruptmask*//*Restorepreviousregisteraddress*/writeb(reg_save,db->io_addr);}中斷狀態(tài)寄存器判斷出是否是接收中斷,接著使用函數(shù)dm9000_rx處理接收到的數(shù)據(jù)。{board_info_t*db=structsk_buff*skb;u8rxbyte,*rdptr;intRxLen;/*Checkpacketreadyornot*/do{ /*Dummyread/*Getmostupdateddata*/rxbyte=readb(db->io_data);/*Statuscheck:thisbytemustbe0or1*/if(rxbyte>DM9000_PKT_RDY){ request}

iow(db,DM9000_RCR,0x00);/*StopDevice*/iow(db,DM9000_ISR,IMR_PAR);/* if(rxbyte!=DM9000_PKT_RDY)/*Apacketreadynow GoodPacket=true;RxLen=le16_to_cpu(rxhdr.RxLen);if length%04x\n",/*PacketStatuscheck*/if(RxLen<0x40){GoodPacket=ifdev_dbg(db->dev,"RX:BadPacket}}if(rxhdr.RxStatus&(RSR_FOE|RSR_CE|RSR_AE|RSR_PLE|RSR_RWTO|GoodPacket=if(rxhdr.RxStatus&{if(netif_msg_rx_err(db))}{if(netif_msg_rx_err(db))dev_dbg(db->dev,"crcerror\n");}{ifdev_dbg(db->dev,"lengtherror\n");}}/*MovedatafromDM9000if&&((skb=dev_alloc_skb(RxLen+4))!={skb_reserve(skb,rdptr=(u8*)skb_put(skb,RxLen-dev->stats.rx_bytes+=RxLen;/*Passtoupperlayer}else/*needtodumpthepacket'sdata}}while(rxbyte==}2.2#cd/home/guoqian/5-5-2#cploopback.ko#insmod由于網(wǎng)絡(luò)接口驅(qū)動(dòng)本身特點(diǎn),在/dev下沒有設(shè)備節(jié)在/dev下創(chuàng)建設(shè)備節(jié)點(diǎn)#ifconfiglotest2.3:input#cd/home/guoqian/5-5-3#cd/home/guoqian/4-3-1/linux-2.6.29 configARCH=arm<>ButtonsdriverforFriendlyARMMini2440/QQ2440developmentboards#make#cpinput_button.ko ;向系統(tǒng)報(bào)告輸入類型,輸入設(shè)#cat#ls-l/dev/*|grep#arm-linux-gcc-staticapp-input.c-oapp-input#cpapp-input/nfsroot/rootfs/tmp運(yùn)試程2.4:s3c2440輸入子系統(tǒng)驅(qū)動(dòng);static init{/*獲取時(shí)鐘,觸摸屏是掛載在APBBUS上的設(shè)備,需要時(shí)鐘控制,見第7章*/adc_clock=clk_get(NULL,"adc");if(!adc_clock){printk(KERN_ERR"failedtogetadcclocksource\n");return-ENOENT;}if(base_addr==NULL){printk(KERN_ERR"Failedtoremapregisterblock\n");return-ENOMEM;}/*ConfigureGPIOs*/s3c2410_ts_connect*GPIO設(shè)置*/ /*ADCTSC0xd3將觸摸屏置為等待中斷模式,等待/*Initialiseinputstuffif(!input_dev){printk(KERN_ERR"Unabletoallocatetheinputdevice!!\n");}dev=應(yīng))的的類型,觸摸屏設(shè)置為支持同步(EN_SYN)、dev->evbit[0]=BIT(EV_SYN)|BIT(EV_KEY)|dev->name=s3c2410ts_name;dev->id.bustype=BUS_RS232;dev->id.vendor=0xDEAD;/*INT_TC,INT_ADC中斷,問題:兩種中斷的產(chǎn)生/*Getirqsprintk(KERN_ERR"s3c2410_ts.c:CouldnotallocatetsIRQ_ADC!\n");return-EIO;}if(request_irq(IRQ_TC,stylus_updown,printk(KERN_ERR"s3c2410_ts.c:CouldnotallocatetsIRQ_TC!\n");return-EIO;}printk(KERN_INFO"%ssuccessfullyloaded\n",/*Allwentok,soregistertotheinputsystem/*輸入設(shè)備}staticirqreturn_tstylus_updown(intirq,void{unsignedlongdata0;unsignedlongdata1;intupdown;中信號(hào)量因?yàn)樾菝卟贿m合使用在ISR中,但{OwnADC=updown=(!(data0&S3C2410_ADCDAT0_UPDOWN))&&(!(data1&S3C2410_ADCDAT0_UPDOWN));updown=1 updown=0 if(updown)}elseOwnADC=0;}}}{unsignedlongdata0;unsignedlongdata1;intupdown;data0=ioread32(base_addr+S3C2410_ADCDAT0);data1=ioread32(base_addr+S3C2410_ADCDAT1);updown=(!(data0&S3C2410_ADCDAT0_UPDOWN))&&(!(data1&if(updown)if(count!={longxp=yp;/*求平均值xp>>=yp>>=/*同步}

xp=yp=count=完畢

AUTOPST,}elsecount=等待觸摸的階段*//*同步if{OwnADC=}}}{unsignedlongdata0;unsignedlongif(OwnADC)xp+=data0&S3C2410_ADCDAT0_XPDATA_MASK;yp+=data1&if(count<(1<<2))|AUTOPST,base_addr+S3C2410_ADCTSC);|}else}}}if(updown)if(count!={longxp=yp;/*求平均值xp>>=yp>>=/*同步}xp=yp=count=完畢

AUTOPST,}updownISR,如果能獲取ADC_LOCK則調(diào)用啟動(dòng)1個(gè)時(shí)間滴答的定時(shí)器,停止ADC,也就是說在這個(gè)時(shí)3.1:RTL-8139PCIRTC-8139pci網(wǎng)卡,既是一個(gè)pci總線驅(qū)動(dòng),又是一個(gè)網(wǎng)絡(luò)設(shè)static {/*whenwe'reamodule,wealwaysprintaversion*evenifno8139boardis/*PCI驅(qū)動(dòng)}/*pci_driver定義 = = = #ifdefCONFIG_PM = #endif/*CONFIG_PM*/drivers/pci/pci-driver.c)ID和驅(qū)動(dòng)注冊(cè)的id_table是否一致;如果匹配成功,說明的驅(qū)動(dòng)能驅(qū)動(dòng)該設(shè)備,則probe函數(shù)被調(diào)用。static conststructpci_device_id{dev=rtl8139_init_board(pdev);if(IS_ERR(dev))dev->netdev_ops=&rtl8139_netdev_ops;dev->ethtool_ops=&rtl8139_ethtool_ops;dev->watchdog_timeo=TX_TIMEOUT;DPRINTK("abouttoregisterdevicenamed%s(%p)...\n",dev->name,dev);/*網(wǎng)卡驅(qū)動(dòng)i=register_netdev(dev);if(i)gotoerr_out;} devinitstructnet_device*rtl8139_init_board(structpci_dev*pdev){/*devandprivzeroedinalloc_etherdev/*分配dev=alloc_etherdev(sizeof/*enabledevice(incl.PCIPMwakeupandhotplug/*PCI驅(qū)動(dòng)使用PCI設(shè)備的任何資源(I/O中斷)之前,驅(qū)動(dòng)必須使能設(shè)備rc=pci_enable_device(pdev);if(rc)gotopio_start=pci_resource_start(pdev,0);pio_end=pci_resource_end(pdev,0);pio_flags=pci_resource_flags(pdev,0);pio_len=pci_resource_len(pdev,0);mmio_start=pci_resource_start(pdev,1);mmio_end=pci_resource_end(pdev,1);mmio_flags=pci_resource_flags(pdev,1);mmio_len=pci_resource_len(pdev,1);rc=pci_request_regions(pdev,DRV_NAME);if(rc)gotoerr_out;/*enablePCIbus-masteringif(use_io)/*I/O地址映射ioaddr=pci_iomap(pdev,0,0);if(!ioaddr){dev_err(&pdev->dev,"cannotmapPIO,rc=-goto}dev->base_addr=pio_start;tp->regs_len=pio_len;}else/*ioremapMMIOregion/*I/O地址映射ioaddr=pci_iomap(pdev,1,0);if(ioaddr==NULL){}

use_io=1;gotodev->base_addr=(long)ioaddr;tp->regs_len=mmio_len;}/*復(fù)位} = = = rtl8139_start_xmit/*網(wǎng)絡(luò)接口數(shù)據(jù) = = #ifdefCONFIG_NET_POLL_CONTROLLER {/*中斷retval=request_irq(dev->irq,rtl8139_interrupt,IRQF_SHARED,dev->name,dev);iftp->tx_bufs=dma_alloc_coherent(&tp->pci_dev->dev,TX_BUF_TOT_LEN,&tp->tx_bufs_dma,GFP_KERNEL);tp->rx_ring=dma_alloc_coherent(&tp->pci_dev->dev,RX_BUF_TOT_LEN,&tp->rx_ring_dma,GFP_KERNEL);}{status=RTL_R16Ifnotrunningstartitnow.if(status&if(netif_rx_schedule_prep(&tp-{RTL_W16_F(IntrMask,}}if(st

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(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)論