LINUX核心中斷(ioremap,內部watchdog中斷,外部中斷)

來源:互聯網
上載者:User

標籤:

一:ioremap

    在核心中有關與物理地址到虛擬位址的映射全都是有mmu,統一開啟,而物理地址到虛擬位址的映射關係全都存在一張對應的表格裡面,這張表,在開啟mmu的時候一起建好,比如在建表的時候是將物理地址0x11111111映射到44444444,那麼問題就是: 比如以後我們如果要將0x11111111的地址映射到66666666地址怎麼辦?在核心中,通過特定的物理地址到虛擬位址的自動對應映射通過ioremap()函數來實現

    

  1 #include <linux/init.h>  2 #include <linux/thread_info.h>  3 #include <linux/module.h>  4 #include <linux/sched.h>  5 #include <linux/errno.h>  6 #include <linux/kernel.h>  7 #include <linux/module.h>  8 #include <linux/slab.h>  9 #include <linux/input.h> 10 #include <linux/init.h> 11 #include <linux/serio.h> 12 #include <linux/delay.h> 13 #include <linux/clk.h> 14 #include <linux/miscdevice.h> 15 #include <linux/io.h> 16 #include <linux/ioport.h> 17 #include <asm/uaccess.h> 18  19 #include <linux/gpio.h> 20 #include <mach/gpio.h> 21 #include <plat/gpio-cfg.h> 22  23  24 MODULE_LICENSE("GPL"); 25 MODULE_AUTHOR("bunfly"); 26  27 unsigned long gpio_virt = 0; 28  29 int test_init() 30 { 31     void __iomem *p; 32  33     p = request_mem_region(0x11000000,SZ_4K,"gpio");//註冊記憶體的映射資訊 34     if(p==NULL) 35     { 36         printk("request error!\n"); 37         return 1; 38     } 39  40     gpio_virt = ioremap(0x11000000,SZ_4K); 41     //ioremap實體記憶體到虛擬記憶體映射 42     *(unsigned long *)(gpio_virt  + 0x2e0)  =1; 43     *(unsigned long *)(gpio_virt  + 0x2e4)  =0; 44     printk("hello led!\n"); 45  46     printk("phys: %p\n",virt_to_phys(gpio_virt)); 47  48 return 0; 49 } 50  51 void test_exit() 52 { 53     printk("bye bye!\n"); 54     iounmap(gpio_virt); 55     release_mem_region(0x11000000,SZ_4K); 56     //退出的時候將映射的虛擬記憶體取消 57 } 58  59 module_init(test_init); 60 module_exit(test_exit); 61  62  63  64 

 

   以上是通過映射的方法,把實體記憶體映射到虛擬記憶體,然後通過操作虛擬記憶體來點燈

核心在分配的時候,註冊分配的名字,其中的註冊資訊可以在板子的目錄下面查看:

  cat  /proc/iomem

  

注意:

  在模組運行之前,為了消除核心中內建的LED模組的影響,需要將內建的LED模組:

      在linux_3 下make  menuconfig

  


     在儲存退出之後,重新make成zImage檔案,下載到板子,運行。

 

二:內部watch看門狗中斷

   

 

LINUX核心中斷(ioremap,內部watchdog中斷,外部中斷)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.