<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > linux 基礎(chǔ)復(fù)習(xí)(9)設(shè)備驅(qū)動入門

          linux 基礎(chǔ)復(fù)習(xí)(9)設(shè)備驅(qū)動入門

          作者: 時間:2016-10-08 來源:網(wǎng)絡(luò) 收藏

          · get_free_page:獲得一個或幾個連續(xù)頁面。

          · get_dma_pages:獲得用于DMA傳輸?shù)捻撁妗?p>與之相對應(yīng)的釋放內(nèi)存用也有kfree或free_pages 族。

          kmalloc 函數(shù)語法要點

          所需頭文件 #i nclude

          函數(shù)原型 void *kmalloc(unsigned int len,int flags)

          Len:希望申請的字節(jié)數(shù)

          GFP_KERNEL:內(nèi)核內(nèi)存的通常分配方法,可能引起睡眠

          GFP_BUFFER:用于管理緩沖區(qū)高速緩存

          函數(shù)傳入值 flags GFP_ATOMIC:為中斷處理程序或其他運行于進(jìn)程上下文之外的代碼分

          配內(nèi)存,且不會引起睡眠

          GFP_USER:用戶分配內(nèi)存,可能引起睡眠

          GFP_HIGHUSER:優(yōu)先高端內(nèi)存分配

          _GFP_DMA:DMA數(shù)據(jù)傳輸請求內(nèi)存

          _GFP_HIGHMEN:請求高端內(nèi)存

          函數(shù)返回值 成功:寫入的數(shù)據(jù)長度

          失?。?EFAULT

          kfree函數(shù)的語法格式

          所需頭文件 #i nclude

          函數(shù)原型 void kfree(void * obj)

          函數(shù)傳入值 obj:要釋放的內(nèi)存指針

          函數(shù)返回值 成功:寫入的數(shù)據(jù)長度

          失?。?EFAULT

          get_free_ page類函數(shù)語法要點

          unsigned long get_zeroed_page(int flags)

          unsigned long __get_free_page(int flags)

          函數(shù)原型 unsigned long __get_free_page(int flags,unsigned long order)

          unsigned long __get_dma_page(int flags,unsigned long order)

          函數(shù)傳入值 flags:同kmalloc

          order:要請求的頁面數(shù),以2為底的對數(shù)

          函數(shù)返回值 成功:寫入的數(shù)據(jù)長度

          失?。?EFAULT

          free_page類函數(shù)語法要點

          所需頭文件 #i nclude

          函數(shù)原型 unsigned long free_page(unsigned long addr)

          unsigned long free_page(unsigned long addr)

          函數(shù)傳入值 flags:同kmalloc

          order:要請求的頁面數(shù),以2為底的對數(shù)

          函數(shù)返回值 成功:寫入的數(shù)據(jù)長度

          失?。?EFAULT

          printk類函數(shù)語法要點

          所需頭文件 #i nclude

          函數(shù)原型 int printk(const char * fmt,…)

          KERN_EMERG:緊急時間消息

          KERN_ALERT:需要立即采取動作的情況

          KERN_CRIT:臨界狀態(tài),通常涉及嚴(yán)重的硬件或軟件操作失敗

          KERN_ERR:錯誤報告

          函數(shù)傳入值 fmt: KERN_WARNING:對可能出現(xiàn)的問題提出警告

          日志級別 KERN_NOTICE:有必要進(jìn)行提示的正常情況

          KERN_INFO:提示性信息

          KERN_DEBUG:調(diào)試信息

          …:如printf一樣的格式說明

          函數(shù)返回值 成功:0

          失?。?1

          這些不同優(yōu)先級的信息可以輸出到控制臺上、/var/log/messages 里。其中,對輸出給控制臺的信息有一個特定的優(yōu)先級console_loglevel。若優(yōu)先級小于這個整數(shù)值時,則消息才能顯示到控制臺上,否則,消息會顯示在/var/log/messages 里。若不加任何優(yōu)先級選項,則消息默認(rèn)輸出到/var/log/messages 文件中。

          要開啟klogd和syslogd服務(wù),消息才能正常輸出。

          proc 文件系統(tǒng)

          /proc 文件系統(tǒng)是一個偽文件系統(tǒng),它是一種內(nèi)核和內(nèi)核模塊用來向進(jìn)程發(fā)送信息的機制。這個偽文件系統(tǒng)讓用戶可以和內(nèi)核內(nèi)部數(shù)據(jù)結(jié)構(gòu)進(jìn)行交互,獲取有關(guān)進(jìn)程的有用信息,在運行時通過改變內(nèi)核參數(shù)改變設(shè)置。與其他文件系統(tǒng)不同,/proc存在于內(nèi)存之中而不是硬盤上。讀者可以通過“ls”查看/proc文件系統(tǒng)的內(nèi)容。

          /proc文件系統(tǒng)主要目錄內(nèi)容

          screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new windownCTRL+Mouse wheel to zoom in/out';} onclick=if(!this.resized) {return true;} else {window.open(this.src);} alt= src=http://blogimg.chinaunix.net/blog/upfile2/080413215654.jpg onload=if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new windownCTRL+Mouse wheel to zoom in/out';} border=0>

          除此之外,還有一些是以數(shù)字命名的目錄,它們是進(jìn)程目錄。系統(tǒng)中當(dāng)前運行的每一個進(jìn)程都有對應(yīng)的一個目錄在/proc下,以進(jìn)程的PID 號為目錄名,它們是讀取進(jìn)程信息的接口。進(jìn)程目錄的結(jié)構(gòu)如下

          screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new windownCTRL+Mouse wheel to zoom in/out';} onclick=if(!this.resized) {return true;} else {window.open(this.src);} alt= src=http://blogimg.chinaunix.net/blog/upfile2/080413215720.jpg onload=if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new windownCTRL+Mouse wheel to zoom in/out';} border=0>

          用戶可以使用cat命令來查看其中的內(nèi)容。

          可以看到,/proc文件系統(tǒng)體現(xiàn)了內(nèi)核及進(jìn)程運行的內(nèi)容,在加載模塊成功后,讀者可以使用查看/proc/device文件獲得相關(guān)設(shè)備的主設(shè)備號。


          上一頁 1 2 3 下一頁

          關(guān)鍵詞:

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();