{"id":176,"date":"2017-08-11T14:23:59","date_gmt":"2017-08-11T06:23:59","guid":{"rendered":"http:\/\/www.sinkland.cn\/?p=176"},"modified":"2019-08-17T15:05:16","modified_gmt":"2019-08-17T07:05:16","slug":"smlos%e5%8d%81-%e7%b3%bb%e7%bb%9f%e6%97%b6%e9%92%9f%e6%8e%a7%e5%88%b6","status":"publish","type":"post","link":"http:\/\/www.sinkland.cn\/?p=176","title":{"rendered":"SmlOS\u5341-\u7cfb\u7edf\u65f6\u949f\u63a7\u5236"},"content":{"rendered":"<h3>\u7b80\u4ecb<\/h3>\n<p>\u7cfb\u7edf\u65f6\u949f\u63a7\u5236\u4e5f\u662f\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u5fc5\u4e0d\u53ef\u5c11\u7684\u529f\u80fd\u4e86\u3002<\/p>\n<p>\u6bd4\u5982\u8bf4\u64cd\u4f5c\u7cfb\u7edf\u7684Sleep\u5b9e\u73b0\uff0c\u5e94\u7528\u5c42Timer\u5b9e\u73b0\uff0c\u65f6\u949f\u529f\u80fd\uff0c\u6570\u636e\u5305\u8d85\u65f6\u91cd\u4f20\u7b49\u529f\u80fd\uff0c\u5168\u90e8\u90fd\u662f\u4f9d\u8d56\u4e8e\u7cfb\u7edf\u65f6\u949f\u63a7\u5236\u3002<\/p>\n<p>\u90a3\u4e48\uff0c\u64cd\u4f5c\u7cfb\u7edf\u662f\u5982\u4f55\u77e5\u9053\u65f6\u95f4\u8fc7\u4e861s\u949f\u5462\uff1f<\/p>\n<p>\u8fd9\u4e00\u5207\u90fd\u8981\u4f9d\u8d56\u4e8e\u4e00\u4e2a\u5668\u4ef6: PIT<\/p>\n<hr \/>\n<h3>PIT\u7b80\u4ecb<\/h3>\n<blockquote><p>\n  PIT (Programmable Interval Timer) \u53ef\u7f16\u7a0b\u95f4\u9694\u5b9a\u65f6\u5668<\/p>\n<p>  \u7b80\u8981\u6765\u8bf4\u5c31\u662f\u6839\u636e\u8bbe\u5b9a\uff0c\u6bcf\u9694\u56fa\u5b9a\u5468\u671f\u5411cpu\u53d1\u4e00\u4e2a\u4e2d\u65ad\n<\/p><\/blockquote>\n<p>\u6bd4\u5982\u8bf4:\u6211\u8bbe\u5b9aPIT\u7684\u9891\u7387 1\/100 \u79d2\uff0c\u4e5f\u5c31\u662f\u8bf4PIT\u4e00\u79d2\u4f1a\u4ea7\u751f100\u6b21\u65f6\u949f\u4e2d\u65ad\u3002<\/p>\n<p>\u5982\u679c\u6211\u9700\u8981\u77e5\u9053\u65f6\u95f4\u662f\u5426\u8fc7\u4e861s\uff0c\u90a3\u4e48\u6211\u53ea\u8981\u6bcf\u6b21\u53d1\u751f\u65f6\u949f\u4e2d\u65ad\u5c31\u7d2f\u52a0\u4e00\u6b21\uff0c\u5f53\u7d2f\u52a0\u5230100\u7684\u65f6\u5019\u5c31\u662f1s\u4e86\u3002<\/p>\n<hr \/>\n<h3>PIT\u521d\u59cb\u5316<\/h3>\n<pre><code class=\"language-c \"> io_out8(PIT_CTRL, 0x34);\n io_out8(PIT_CNT0, 0x9c);\n io_out8(PIT_CNT0, 0x2e);\n<\/code><\/pre>\n<p>\u6570\u503c\u7684\u8bbe\u7f6e\u9700\u8981\u9605\u8bfb\u76f8\u5173\u786c\u4ef6\u624b\u518c\u3002<\/p>\n<p>\u8fd9\u91cc\u65f6\u949f\u8bbe\u5b9a\u4e2d\u65ad\u7684\u9891\u7387\u662f\u6bcf\u79d2\u6267\u884c100\u6b21\u3002<\/p>\n<p>\u521d\u59cb\u5316\u5b8cPIT\u540e\uff0c\u5c31\u53ef\u4ee5\u6536\u5230\u76f8\u5173\u4e2d\u65ad\u4e86\u3002<\/p>\n<p>\u65f6\u949f\u4e2d\u65ad\u5904\u7406\u51fd\u6570\uff0c\u6211\u4eec\u4e4b\u524d\u5df2\u7ecf\u6ce8\u518c\uff0c\u6700\u7ec8\u8df3\u8f6c\u5230 c\u5b9e\u73b0\u7684inthandler20\u51fd\u6570\u4e2d\u3002<\/p>\n<hr \/>\n<h3>\u8d85\u65f6\u7ba1\u7406\u539f\u7406<\/h3>\n<p>\u5047\u5982\u8bf4\u5e94\u7528\u5c42\u6709\u975e\u5e38\u591a\u7684\u65f6\u949f\u9700\u6c42\uff0c\u6bd4\u5982\u6709\u7b491s\uff0c\u6709\u7b4910\u79d2\u7684\uff0c<br \/>\n\u6709\u7b49100s\u7684\uff0c\u90a3\u4e48\u7cfb\u7edf\u8be5\u5982\u4f55\u652f\u6301\u5462\uff1f<\/p>\n<p>\u90a3\u4e48\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p>\u9996\u5148\uff0c\u6bcf\u4e2a\u8d85\u65f6\u7684\u9700\u6c42\u6211\u79f0\u4e4b\u4e3a\u4e00\u4e2a\u5b9a\u65f6\u5668\u3002<\/p>\n<p>\u7cfb\u7edf\u4f1a\u7ef4\u62a4\u4e00\u4e2a\u53d8\u91cf\uff0c\u6682\u65f6\u79f0\u4e4b\u4e3a\u7d2f\u8ba1\u65f6\u95f4(count)\u628a\uff0c\u5c31\u662f\u6bcf\u6b21\u65f6\u949f\u4e2d\u65ad\u90fd\u4f1a\u81ea\u589e\u4e00\uff0c\u6309\u7167\u73b0\u5728\u8bbe\u5b9a\u4e5f\u5c31\u662f\u4e00\u79d2\u589e\u52a0100\u6b21<\/p>\n<p>\u5047\u5982\u8bf4\u6709\u8fd9\u6837\u7684\u4e00\u4e2a\u60c5\u51b5\uff1a<\/p>\n<ul>\n<li>1.\u5728count = 0\u65f6, \u5e94\u7528\u5c42\u9700\u8981\u4e00\u4e2a\u5b9a\u65f6\u56685s\u540e\u901a\u77e5\u4ed6<\/p>\n<\/li>\n<li>\n<p>2.\u5230\u4e86count = 100\u65f6\uff0c \u5e94\u7528\u5c42\u9700\u8981\u4e00\u4e2a\u5b9a\u65f6\u56682s\u540e\u901a\u77e5<\/p>\n<\/li>\n<li>\n<p>3.\u5230\u4e86count = 200\u65f6\uff0c \u5e94\u7528\u5c42\u9700\u8981\u4e00\u4e2a\u5b9a\u65f6\u56684s\u540e\u901a\u77e5<\/p>\n<\/li>\n<\/ul>\n<p>\u90a3\u6211\u8981\u600e\u4e48\u505a\u5462\uff1f<\/p>\n<p>\u6709\u4eba\u53ef\u80fd\u4f1a\u8bf4\uff0c\u6211\u6328\u4e2a\u5224\u65ad\u5457\uff0c\u5728\u6bcf\u6b21\u4e2d\u65ad\u65f6\u5019\u6211\u90fd\u5224\u65ad\u4e0b\uff0c\u54ea\u4e2a\u5b9a\u65f6\u5668\u6709\u6ca1\u6709\u8d85\u65f6\u3002<\/p>\n<p>\u5982\u679c\u8fd9\u6837\u7684\u8bdd\uff0c\u5728\u5b9a\u65f6\u5668\u5f88\u591a\u7684\u60c5\u51b5\u4e0b\uff0c\u7cfb\u7edf\u6548\u7387\u4f1a\u975e\u5e38\u6162\u3002<\/p>\n<p>\u800c\u4e14\u5224\u65ad\u64cd\u4f5c\u65f6\u653e\u5728\u4e2d\u65ad\u51fd\u6570\u91cc\u9762\u7684\uff0c\u4e2d\u65ad\u51fd\u6570\u5982\u679c\u653e\u5165\u5f88\u591a\u5360\u65f6\u95f4\u7684\u64cd\u4f5c\uff0c\u90a3\u4e48\u4f1a\u53ef\u80fd\u5f71\u54cd\u5176\u4ed6\u4e2d\u65ad\u7684\u4ea7\u751f\uff0c\u6240\u4ee5\u4e2d\u65ad\u51fd\u6570\u9700\u8981\u5c3d\u91cf\u7b80\u77ed\u3002<\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u7528\u4e86\u4e00\u79cd\u529e\u6cd5\uff1a<strong>\u5224\u65ad\u6700\u8fd1\u8d85\u65f6\u7684\u5b9a\u65f6\u5668<\/strong><\/p>\n<p>\u4ee5\u4e0a\u9762\u7684\u95ee\u9898\u4e3a\u4f8b\u5b50<\/p>\n<p>\u7b2c\u4e00\u6b21\u5206\u914d(count = 0\uff0c\u5206\u914d5s):<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b9a\u65f6\u5668\u5e8f\u53f7<\/th>\n<th>\u8d85\u65f6\u65f6\u95f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>500 (\u5728count = 500\u7684\u65f6\u5019\u901a\u77e5)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b2c\u4e8c\u6b21\u5206\u914d(count = 100\uff0c\u5206\u914d2s):<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b9a\u65f6\u5668\u5e8f\u53f7<\/th>\n<th>\u8d85\u65f6\u65f6\u95f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>300<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>500 (\u5728count = 500\u7684\u65f6\u5019\u901a\u77e5)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b2c\u4e8c\u6b21\u5206\u914d(count = 200\uff0c\u5206\u914d4s):<\/p>\n<table>\n<thead>\n<tr>\n<th>\u5b9a\u65f6\u5668\u5e8f\u53f7<\/th>\n<th>\u8d85\u65f6\u65f6\u95f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>2<\/td>\n<td>300<\/td>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td>500 (\u5728count = 500\u7684\u65f6\u5019\u901a\u77e5)<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>600<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6ce8\u610f\u89c2\u5bdf:\u6211\u4eec\u5728\u6bcf\u6b21\u5206\u914d\u7684\u65f6\u5019\uff0c\u90fd\u8ba1\u7b97\u51fa\u8be5\u5b9a\u65f6\u5668\u7684\u9884\u671f\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/p>\n<p>\u4e14\u5bf9\u8d85\u65f6\u65f6\u95f4\u8fdb\u884c\u4e86\u6392\u5e8f\u3002<\/p>\n<p>\u90a3\u4e48\u6211\u5728\u4e2d\u65ad\u51fd\u6570\u4e2d\uff0c\u53ea\u8981\u5224\u65ad\u6700\u8fd1\u5373\u5c06\u8d85\u65f6\u7684\u5b9a\u65f6\u5668\uff0c\u53ea\u9700\u8981\u5224\u65ad\u4e00\u6b21\uff0c\u5927\u5927\u589e\u52a0\u4e86\u6548\u7387\u3002<\/p>\n<hr \/>\n<h3>\u5b9e\u73b0<\/h3>\n<p>\u8fd9\u91cc\u4ecb\u7ecd\u4e24\u4e2a\u91cd\u8981\u7684\u65f6\u949f\u7ba1\u7406\u7ed3\u6784\u4f53\uff1a<\/p>\n<pre><code class=\"language-c \">struct TIMERCTL\n{\n unsigned int count, next, using;\n struct TIMER *timers[MAX_TIMER];\n struct TIMER timers0[MAX_TIMER];\n};\n<\/code><\/pre>\n<blockquote><p>\n  count: \u7d2f\u8ba1\u8ba1\u6570\u5668<\/p>\n<p>  next: \u4e0b\u4e00\u4e2a\u8d85\u65f6\u65f6\u95f4<\/p>\n<p>  using: \u5f53\u524d\u6d3b\u52a8\u7684\u5b9a\u65f6\u5668\u6570\u91cf<\/p>\n<p>  timers: \u5b9a\u65f6\u5668\u7ed3\u6784\u6307\u9488\u6570\u7ec4\n<\/p><\/blockquote>\n<pre><code>(TIMER\u6307\u9488\u6709\u5e8f\u6570\u7ec4,\u6392\u5e8f\u7684\u65f6\u5019\u53ea\u79fb\u52a8\u6307\u9488,\u589e\u52a0\u6548\u7387)\n<\/code><\/pre>\n<blockquote><p>\n  timers0 \u5b9a\u65f6\u5668\u7ed3\u6784\u6570\u7ec4\n<\/p><\/blockquote>\n<p>\u4ee5\u53ca\u5355\u4e2a\u65f6\u949f\u7ed3\u6784\u4f53\uff1a<\/p>\n<pre><code class=\"language-c \">struct TIMER\n{\n unsigned int timeout, flags;\n struct FIFO8 *fifo;\n unsigned char data;\n};\n<\/code><\/pre>\n<blockquote><p>\n  timeout: \u76f8\u5bf9\u4e8e\u5f53\u524d\u65f6\u95f4\u7684\u9884\u5b9a\u65f6\u523b<\/p>\n<p>  flags: \u8bb0\u5f55\u5b9a\u65f6\u5668\u72b6\u6001<\/p>\n<p>  fifo: \u5b9a\u65f6\u5668\u961f\u5217\u6307\u9488<\/p>\n<p>  data: \u5b9a\u65f6\u5668\u6570\u636e\n<\/p><\/blockquote>\n<p>\u9996\u5148\u65f6\u949f\u7ba1\u7406\u8868\u4e2dcount\u6210\u5458\u5728\u6bcf\u6b21\u4e2d\u65ad\u6267\u884c\u540e\u90fd\u4f1a\u81ea\u52a0\u4e00\uff0c\u800cnext\u662f\u8bb0\u5f55\u4e0b\u4e00\u4e2a\u5373\u5c06\u8d85\u65f6\u7684\u65f6\u949f\u3002<\/p>\n<p>\u540c\u4e4b\u524d\u7684\u76f8\u5173\u7ba1\u7406\u8868\uff0ctimers\u662f\u7528\u6765\u6392\u5e8f\u7684\u6307\u9488\u6570\u7ec4\uff0c\u800ctimers0\u7528\u6765\u5206\u914d\u9700\u8981\u7ba1\u7406\u7684\u8d85\u65f6\u65f6\u949f\u3002<\/p>\n<p>\u8fd9\u91cc\u6700\u5927\u65f6\u949f\u6570\u91cf\u88ab\u6307\u5b9a\u4e3a500\u4e2a\u3002<\/p>\n<p>\u800c\u5728\u5355\u4e2a\u65f6\u949f\u7ed3\u6784\u7ed3\u6784\u4f53\u4e2d\uff0ctimeout\u662f\u5728\u6267\u884c\u8d85\u65f6\u8bbe\u7f6e\u7684\u64cd\u4f5c\u540e\uff0c\u52a0\u4e0acount\u7684\u65f6\u95f4\uff0c\u53ef\u4ee5\u7406\u89e3\u4e3a\u8d85\u65f6\u65f6\u523b\u3002<\/p>\n<p>\u5728\u65f6\u949f\u4e2d\u65ad\u4e2d\u4e00\u65e6\u53d1\u73b0\u6709\u65f6\u949f\u8d85\u65f6\uff0c\u90a3\u4e48\u5c31\u5411\u65f6\u949f\u6307\u5b9a\u7684FIFO\u961f\u5217\u91cc\uff0c\u5199\u5165\u7531data\u6307\u5b9a\u7684\u6570\u636e\uff0c\u4e5f\u5c31\u662f\u901a\u77e5\u8be5\u7ebf\u7a0b\u3002<\/p>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u65f6\uff0c\u6bcf\u6b21\u5206\u914d\u5b9a\u65f6\u5668(TIMER)\u7684\u65f6\u5019\uff0c\u7136\u540e\u5728timers\u7684\u6307\u9488\u6570\u7ec4\u4e2d\u6309\u7167timeout\u7684\u5927\u5c0f\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n<p>\u76f8\u5173\u7b97\u6cd5\u662f\u662f\u8fdb\u884c\u79fb\u4f4d\u7b97\u6cd5\uff0c\u56e0\u4e3a\u662f\u6307\u9488\u7684\u79fb\u52a8\uff0c\u6240\u4ee5\u79fb\u52a8\u7684\u603b\u91cf\u5e76\u975e\u5f88\u5927\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u7cfb\u7edf\u65f6\u949f\u63a7\u5236\u4e5f\u662f\u73b0\u4ee3\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u5fc5\u4e0d\u53ef\u5c11\u7684\u529f\u80fd\u4e86\u3002 \u6bd4\u5982\u8bf4\u64cd\u4f5c\u7cfb\u7edf\u7684Sleep\u5b9e\u73b0\uff0c\u5e94\u7528\u5c42Timer\u5b9e\u73b0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/176"}],"collection":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=176"}],"version-history":[{"count":1,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions"}],"predecessor-version":[{"id":177,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=\/wp\/v2\/posts\/176\/revisions\/177"}],"wp:attachment":[{"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=176"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sinkland.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}