{"id":1416,"date":"2024-07-25T08:59:25","date_gmt":"2024-07-25T00:59:25","guid":{"rendered":"https:\/\/swordofmorning.com\/?p=1416"},"modified":"2025-10-09T13:54:44","modified_gmt":"2025-10-09T05:54:44","slug":"rv1126-05","status":"publish","type":"post","link":"https:\/\/swordofmorning.com\/index.php\/2024\/07\/25\/rv1126-05\/","title":{"rendered":"RV1126 \u5b9a\u65f6\u7684\u9a71\u52a8\u7a0b\u5e8f"},"content":{"rendered":"<p>&emsp;&emsp;\u6211\u4eec\u671f\u671b\u4e00\u4e2a\u9a71\u52a8\u7a0b\u5e8f\u53ef\u4ee5\u95f4\u9694\u4e00\u79d2\u949f\u5b8c\u6210\u4e00\u6b21\u81ea\u52a0\u548cprint\u3002\u6211\u4eec\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u6765\u5b9e\u73b0\uff1a<\/p>\n<pre><code class=\"language-c\">#include &lt;linux\/module.h&gt;\n#include &lt;linux\/kernel.h&gt;\n#include &lt;linux\/timer.h&gt;\n#include &lt;linux\/jiffies.h&gt;\n\nstatic int count;\nstatic struct timer_list my_timer;\n\nstatic void my_timer_callback(struct timer_list *timer)\n{\n    count++;\n    pr_info(&quot;-------Timer Count: %d\\n&quot;, count);\n\n    \/\/ \u91cd\u65b0\u542f\u52a8\u5b9a\u65f6\u5668,\u5728 1 \u79d2\u540e\u89e6\u53d1\n    mod_timer(&amp;my_timer, jiffies + HZ);\n}\n\nstatic int __init my_driver_init(void)\n{\n    pr_info(&quot;Initializing my_driver\\n&quot;);\n\n    \/\/ \u521d\u59cb\u5316\u5b9a\u65f6\u5668\n    timer_setup(&amp;my_timer, my_timer_callback, 0);\n\n    \/\/ \u542f\u52a8\u5b9a\u65f6\u5668,\u5728 1 \u79d2\u540e\u89e6\u53d1\n    mod_timer(&amp;my_timer, jiffies + HZ);\n\n    return 0;\n}\n\nstatic void __exit my_driver_exit(void)\n{\n    pr_info(&quot;Exiting my_driver\\n&quot;);\n\n    \/\/ \u5220\u9664\u5b9a\u65f6\u5668\n    del_timer(&amp;my_timer);\n}\n\nmodule_init(my_driver_init);\nmodule_exit(my_driver_exit);\n\nMODULE_LICENSE(&quot;GPL&quot;);\nMODULE_AUTHOR(&quot;Your Name&quot;);\nMODULE_DESCRIPTION(&quot;A simple driver with a timer&quot;);<\/code><\/pre>\n<p>&emsp;&emsp;\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>dmesg &gt; log<\/code>\u6765\u786e\u8ba4\u6548\u679c\uff1a<\/p>\n<pre><code class=\"language-log\">[   37.705643] -------Timer Count: 37\n[   38.718969] -------Timer Count: 38\n[   39.732309] -------Timer Count: 39\n[   40.745674] -------Timer Count: 40<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>&emsp;&emsp;\u6211\u4eec\u671f\u671b\u4e00\u4e2a\u9a71\u52a8\u7a0b\u5e8f\u53ef\u4ee5\u95f4\u9694\u4e00\u79d2\u949f\u5b8c\u6210\u4e00\u6b21\u81ea\u52a0\u548cprint\u3002\u6211\u4eec\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u6765\u5b9e\u73b0\uff1a #include &#038; &#8230","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[303],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1416"}],"collection":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/comments?post=1416"}],"version-history":[{"count":2,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1416\/revisions"}],"predecessor-version":[{"id":1418,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/posts\/1416\/revisions\/1418"}],"wp:attachment":[{"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/media?parent=1416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/categories?post=1416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/swordofmorning.com\/index.php\/wp-json\/wp\/v2\/tags?post=1416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}