<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>

            最簡單的Linux驅動程序

            時間:2024-09-09 07:20:15 Linux認證 我要投稿
            • 相關推薦

            最簡單的Linux驅動程序

              你正在學習linux嗎?你知道最簡單的Linux驅動程序是怎么樣的嗎?下面yjbys小編為大家提供最簡單的Linux驅動程序,希望對大家有所幫助!

              #include

              #include //兩個必須頭文件

              MODULE_LICENSE("Dual BSD/GPL");//GPL協議

              static char *whom = "world";//insmod傳入參數是用到

              static int howmany = 1;//insmod傳入參數是用到

              module_param(howmany,int,S_IRUGO);//傳入參數要用module_param宏來聲明。這樣我們就可以使用insmod命令

              //時傳入參數,其實是模塊讓這些參數對insmod命令可見

              module_param(whom,charp,S_IRUGO);

              unsigned int i;

              static int hello_init(void)

              {

              printk(KERN_ALERT "Hello,world\n");

              for(i=0;i

              printk(KERN_ALERT "hello %s\n",whom);

              return 0;

              }

              static void hello_exit(void)

              {

              printk(KERN_ALERT "Goodbye, cruel world\n");

              }

              module_init(hello_init);

              module_exit(hello_exit);

              下面是Makefile文件

              obj-m += hello.o//obj-m編譯成模塊

              KERDIR = /work/linux-2.6.30.4//內核所在目錄

              modules:

              make -C $(KERDIR) M=`pwd` modules//-C表示進入到后面目錄里編譯,M=` `指定編譯好的文件所在目錄

              clean:

              rm -rf *.o *~core .depend *.cmd *.ko *.mod.c *.tmp_versions

              下面是加載模塊時情況

              [root@cgyl2010 ~]#insmod hello.ko howmany=10 whom="Mom"

              Hello,world

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              hello Mom

              這樣就可以通過insmoa命令傳進來的參數來控制我們要實現的現象(這里是打印情況),有時候會比較方便。

            【最簡單的Linux驅動程序】相關文章:

            Linux認證考點03-19

            Linux認證的概念03-25

            Linux認證概念03-19

            Linux認證優勢03-19

            學習Linux的忠告03-21

            Linux認證系統管理:linux下搭建ftp03-08

            Linux認證基本介紹03-12

            Linux認證賬戶映射01-23

            Linux基本指令大全11-23

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院