{"id":229,"date":"2022-07-13T15:45:33","date_gmt":"2022-07-13T07:45:33","guid":{"rendered":"http:\/\/150.158.163.220\/?p=229"},"modified":"2022-12-20T11:32:39","modified_gmt":"2022-12-20T03:32:39","slug":"%e6%9d%a5%e4%b8%80%e8%b5%b7%e6%8a%8a%e6%97%b6%e9%97%b4%e5%88%87%e6%88%90%e7%89%87","status":"publish","type":"post","link":"https:\/\/zhewana.cn\/?p=229","title":{"rendered":"\u6765\u4e00\u8d77\u628a\u65f6\u95f4\u5207\u6210\u201c\u7247\u201d"},"content":{"rendered":"<h2>\u7b80\u4ecb<\/h2>\n<p><strong>\u65f6\u95f4\u7247\u8f6e\u8be2<\/strong>\u662f\u88f8\u673a\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\u5341\u5206\u5e38\u7528\u7684\u4e00\u79cd\u7a0b\u5e8f\u67b6\u6784\uff0c\u5176\u4e3b\u8981\u7684\u601d\u60f3\u662f\u5c06\u5355\u4e2a\u5b9a\u65f6\u5668\u7684\u65f6\u95f4\u65f6\u5206\u590d\u7528\uff0c\u53ef\u4ee5\u540c\u65f6\u5904\u7406\u591a\u79cd\u4e0d\u540c\u65f6\u95f4\u95f4\u9694\u7684\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n<p>\u7b14\u8005\u5728\u5f88\u4e45\u4e4b\u524d\u7684\u7535\u8d5b\u603b\u7ed3\u7684\u6587\u7ae0\u4e2d\u5c31\u66fe\u7ecf\u8bf4\u8fc7\uff0c\u81ea\u5df1\u5b9e\u73b0\u4e86\u4e00\u4e2a\u65f6\u95f4\u7247\u8f6e\u8be2\u67b6\u6784\u5e76\u4e14\u7528\u5728\u4e86\u7535\u8d5b\u4e2d\uff0c\u540e\u7eed\u53c8\u4e3a\u5176\u6dfb\u52a0\u4e86\u4e00\u4e9b\u5e38\u7528\u7684\u529f\u80fd\u3002\u4f46\u662f\u524d\u6bb5\u65f6\u95f4\u7b14\u8005\u81ea\u884c\u5ba1\u89c6\u7684\u65f6\u5019\u53d1\u73b0\u66fe\u7ecf\u67b6\u6784\u4e2d\u5176\u5b9e\u5b58\u5728\u4e00\u4e9b\u6bd4\u8f83\u4e25\u91cd\u7684\u95ee\u9898\uff0c\u4e8e\u662f\u5c06\u8be5\u67b6\u6784\u8fdb\u884c\u4e86\u7b80\u5355\u7684\u91cd\u6784\uff0c\u4ee3\u7801\u91cf--\u7684\u540c\u65f6\uff0c\u5b89\u5168\u6027++\u3002<\/p>\n<p>\u8be5\u67b6\u6784\u9762\u5411\u7684\u4f7f\u7528\u573a\u666f\u662f\u5bf9\u4e8e\u5b9e\u65f6\u6027\u8981\u6c42<strong>\u5e76\u4e0d\u5341\u5206\u4e25\u683c<\/strong>\u7684\u591a\u4efb\u52a1\u5f00\u53d1\u573a\u666f\u3002\u867d\u7136\u4efb\u52a1\u5bf9\u4e8e\u5904\u7406\u5668\u7684\u957f\u65f6\u95f4\u5360\u7528\u4f1a\u5bfc\u81f4\u6846\u67b6\u5185\u7684\u6240\u6709\u4efb\u52a1\u5b9e\u65f6\u6027\u5747\u53d7\u5230\u5f71\u54cd\uff0c\u4f46\u662f\u5f97\u76ca\u4e8e\u975e\u963b\u585e\u5f0f\u7684\u7ed3\u6784\uff0c\u6846\u67b6\u5916\u7684\u4ee3\u7801\u529f\u80fd\uff08\u5c24\u5176\u662f\u5904\u4e8e\u4e2d\u65ad\u5185\u7684\u5185\u5bb9\uff09\u7edd\u5927\u90e8\u5206\u5e76\u4e0d\u4f1a\u53d7\u5230\u5f71\u54cd\u3002<\/p>\n<h2>\u4f7f\u7528\u8bf4\u660e<\/h2>\n<p>\u8981\u4f7f\u7528<a href=\"https:\/\/github.com\/Zhewana\/TPF-TimePieceFramework\">TPF\u65f6\u95f4\u7247\u8f6e\u8be2\u6846\u67b6<\/a>\uff0c\u4f60\u9700\u8981\u5728\u4f60\u7684\u5de5\u7a0b\u4e2d\u505a\u51fa\u5982\u4e0b\u5904\u7406\uff1a<\/p>\n<ul>\n<li>\n<p>\u5c06TPF.c\u4ee5\u53caTPF.h\u52a0\u5165\u5230\u4f60\u7684\u5de5\u7a0b\u4e2d<\/p>\n<\/li>\n<li>\n<p>\u4e3a\u4f60\u7684<strong>\u6bcf\u4e2a\u4efb\u52a1<\/strong>\u5b9a\u4e49\u4e00\u4e2a<code>tptask_t<\/code>\u53e5\u67c4<\/p>\n<\/li>\n<li>\n<p>\u4e3a<strong>\u6bcf\u4e2a\u4efb\u52a1<\/strong>\u7f16\u5199\u4efb\u52a1\u5904\u7406\u51fd\u6570\uff0c\u51fd\u6570\u539f\u578b\u4e3a<code>void xx(void)<\/code><\/p>\n<\/li>\n<li>\n<p>\u4e3a<strong>\u6bcf\u4e2a\u4efb\u52a1<\/strong>\u8c03\u7528<code>TP_TaskInit<\/code>\u51fd\u6570\u8fdb\u884c\u4efb\u52a1\u521d\u59cb\u5316<\/p>\n<p>\u6ce8\uff1a\u8c03\u7528\u521d\u59cb\u5316\u51fd\u6570\u7684\u987a\u5e8f\u5c06\u4f1a\u51b3\u5b9a\u4f60\u7684\u4efb\u52a1\u8f6e\u8be2\u4f18\u5148\u7ea7\uff1b\u8d8a\u65e9\u521d\u59cb\u5316\u7684\u4efb\u52a1\uff0c\u8f6e\u8be2\u4f18\u5148\u7ea7\u8d8a\u9ad8\u3002\u521d\u59cb\u5316\u540e\u7684\u4efb\u52a1\u9ed8\u8ba4\u5904\u4e8e\u5c31\u7eea\u6001\u3002<\/p>\n<\/li>\n<li>\n<p>\u4ee5\u4e00\u4e2a\u56fa\u5b9a\u7684\u65f6\u95f4\u95f4\u9694\u8c03\u7528<code>TP_TickUpdate<\/code>\u51fd\u6570\uff0c\u53c2\u6570\u4e3a<strong>\u8c03\u7528\u5468\u671f<\/strong>\uff08ms\uff09<\/p>\n<\/li>\n<li>\n<p>\u5c06<code>TP_TaskHandler<\/code>\u51fd\u6570\u653e\u8fdb\u60a8\u7684\u4e3b\u5faa\u73af<code>while(1)<\/code>\u5185\u90e8<\/p>\n<\/li>\n<li>\n<p>\u89c2\u5bdf\u8fd0\u884c\u6548\u679c<\/p>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>\u8865\u5145\u8bf4\u660e\u4e0e\u793a\u4f8b<\/h2>\n<h3>\u7528\u6237\u51fd\u6570<\/h3>\n<p>\u6846\u67b6\u5185\u9762\u5411\u7528\u6237\u7684\u51fd\u6570\u5217\u8868\u603b\u7ed3\u5982\u4e0b\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th style=\"text-align: center;\">\u51fd\u6570\u540d<\/th>\n<th style=\"text-align: center;\">\u529f\u80fd<\/th>\n<th style=\"text-align: center;\">\u53c2\u6570<\/th>\n<th style=\"text-align: center;\">\u8fd4\u56de\u503c<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align: center;\">TP_TickUpdate<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u6846\u67b6\u65f6\u949f<\/td>\n<td style=\"text-align: center;\">\u66f4\u65b0\u5468\u671f<\/td>\n<td style=\"text-align: center;\">void<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_TaskHandler<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u5904\u7406\u51fd\u6570<\/td>\n<td style=\"text-align: center;\">void<\/td>\n<td style=\"text-align: center;\">void<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_TaskInit<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u521d\u59cb\u5316<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u53e5\u67c4,\u65f6\u95f4\u7247,\u5904\u7406\u51fd\u6570\u6307\u9488<\/td>\n<td style=\"text-align: center;\">tpStatus<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_TaskDelay<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u5ef6\u65f6<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u53e5\u67c4,\u5ef6\u65f6\u65f6\u95f4\uff08ms\uff09<\/td>\n<td style=\"text-align: center;\">tpStatus<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_GlobalDelay<\/td>\n<td style=\"text-align: center;\">\u6846\u67b6\u5ef6\u65f6<\/td>\n<td style=\"text-align: center;\">\u5ef6\u65f6\u65f6\u95f4\uff08ms\uff09<\/td>\n<td style=\"text-align: center;\">tpStatus<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_TaskTerminate<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u7ec8\u6b62<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u53e5\u67c4<\/td>\n<td style=\"text-align: center;\">tpStatus<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align: center;\">TP_TaskRework<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u6062\u590d<\/td>\n<td style=\"text-align: center;\">\u4efb\u52a1\u53e5\u67c4<\/td>\n<td style=\"text-align: center;\">tpStatus<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>\u4e3b\u5faa\u73af\u53ca\u4efb\u52a1\u5185\u5bb9<\/h3>\n<p>\u7531\u4e8e\u4efb\u52a1\u5904\u7406\u51fd\u6570\u662f\u653e\u5728\u4e3b\u5faa\u73af\u4e2d\u8f6e\u8be2\u7684\uff0c\u6545<strong>\u4e0d\u5efa\u8bae\u5728\u4e3b\u5faa\u73af\u4e2d\u4efb\u52a1\u5904\u7406\u51fd\u6570\u5916\u8fdb\u884c\u8017\u65f6\u5904\u7406<\/strong>\uff0c\u5426\u5219\u5c06\u5f71\u54cd\u5230\u6574\u4e2a\u6846\u67b6\u7684\u8fd0\u884c\u3002\u60a8\u4e5f\u53ef\u4ee5\u9009\u62e9\u5c06\u4efb\u52a1\u5904\u7406\u51fd\u6570\u653e\u5728\u5b9a\u65f6\u5668\u4e2d\u65ad\u4e2d\u8fd0\u884c<strong>\uff08\u5341\u5206\u4e0d\u63a8\u8350\uff09<\/strong>\uff0c\u6b64\u79cd\u60c5\u51b5\u4e0b\u8981\u4fdd\u8bc1\u5b9e\u65f6\u6027\u8bf7\u81f3\u5c11\u9075\u5faa\u4ee5\u4e0b\u89c4\u5219\uff1a<\/p>\n<ul>\n<li>\u4efb\u52a1\u5904\u7406\u51fd\u6570\u7684\u6267\u884c\u9891\u7387<strong>\u81f3\u5c11\u5e94\u5927\u4e8e\u7b49\u4e8e<\/strong>\u6846\u67b6\u65f6\u949f\u66f4\u65b0\u7684\u9891\u7387\u65b9\u53ef\u4fdd\u8bc1\u7cfb\u7edf\u5b9e\u65f6\u6027<\/li>\n<li>\u5168\u90e8\u4efb\u52a1\u6267\u884c\u603b\u65f6\u95f4\u5e94\u8fdc\u5c0f\u4e8e\u4e2d\u65ad\u5468\u671f<\/li>\n<\/ul>\n<h3>\u6570\u636e\u7ed3\u6784<\/h3>\n<p>\u6bcf\u4e2a\u4efb\u52a1\u91c7\u7528\u5982\u4e0b\u53e5\u67c4\u5b9e\u73b0\u4e0d\u540c\u4efb\u52a1\u4e4b\u95f4\u6570\u636e\u5206\u79bb\uff0c\u5f7c\u6b64\u72ec\u7acb\uff1a<\/p>\n<pre><code class=\"language-C\">typedef struct tptask_t {\n    struct tptask_t *last;\n    struct tptask_t *next;\n\n    uint8_t ID;\n    uint32_t timeoutTick;\n\n    taskStatus state;\n\n    uint32_t timePiece;\n\n    void (*pHandler)(void);\n} tptask_t;<\/code><\/pre>\n<p>\u4efb\u52a1\u5217\u8868\u91c7\u7528\u53cc\u5411\u94fe\u8868\u5b58\u50a8\uff0c\u4f46\u662f\u76ee\u524d\u7684\u529f\u80fd\u4e2d\u4ec5\u4ec5\u4f7f\u7528\u4e86\u5176\u4e2d\u5355\u5411\u7684\u90e8\u5206\uff0c\u91c7\u7528\u53cc\u5411\u94fe\u8868\u662f\u4e3a\u540e\u7eed\u6dfb\u52a0\u529f\u80fd\u505a\u51c6\u5907\u3002<\/p>\n<h3>\u793a\u4f8b<\/h3>\n<p>\u5b9e\u4f8b\u4e2d\u521b\u5efa\u4e24\u4e2a\u4efb\u52a1\uff1aBlink\u63a7\u5236LED\u95ea\u70c1\uff1bPrint\u7528\u4e8e\u6253\u5370\u6570\u636e\u3002<\/p>\n<p>\u4ec5\u63d0\u4f9bArm\u5185\u6838\u67b6\u6784STM32HAL\u5e93\u73af\u5883\u4e0b\u53c2\u8003\uff0c\u5176\u4f59\u540c\u7406\uff1a<\/p>\n<pre><code class=\"language-C\">\/\/------------  systick.c\/blablabla.c  -------------\/\/\n\/\/\u5b9a\u65f6\u5668\u51fd\u6570\uff0c\u4ee5\u5468\u671f\u4e3a1ms\u7684SysTick\u4e3a\u4f8b\nvoid SysTick_Handler(void){\n    TP_TickUpdate(1);\n}\n\n\/\/--------------------  main.c  ---------------------\/\/\n\ntptask_t blinkTask, printTask;\n\nvoid BlinkHandler() {\n    HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_13);\n    printf(&quot;Toggle GPIOC Pin13\\n&quot;);\n}\n\nvoid PrintHandler() {\n    static int a = 1;\n    printf(&quot;print:%d\\n&quot;, a++);\n    if (a == 100) {\n        TP_TaskTerminate(&amp;blinkTask);\n    } else if (a == 500) {\n        TP_TaskRework(&amp;blinkTask);\n    }\n}\n\nint main(void){\n    TP_TaskInit(&amp;blinkTask, 500, BlinkHandler);\n    TP_TaskInit(&amp;printTask, 50, PrintHandler);\n\n    while(1){\n        TP_TaskHandler();\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb \u65f6\u95f4\u7247\u8f6e\u8be2\u662f\u88f8\u673a\u5f00\u53d1\u7684\u8fc7\u7a0b\u4e2d\u5341\u5206\u5e38\u7528\u7684\u4e00\u79cd\u7a0b\u5e8f\u67b6\u6784\uff0c\u5176\u4e3b\u8981\u7684\u601d\u60f3\u662f\u5c06\u5355\u4e2a\u5b9a\u65f6\u5668\u7684\u65f6\u95f4\u65f6\u5206\u590d\u7528\uff0c\u53ef\u4ee5\u540c\u65f6\u5904 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[31,44],"class_list":["post-229","post","type-post","status-publish","format-standard","hentry","category-embedded","tag-31","tag-44"],"_links":{"self":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=229"}],"version-history":[{"count":1,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/zhewana.cn\/index.php?rest_route=\/wp\/v2\/posts\/229\/revisions\/230"}],"wp:attachment":[{"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhewana.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}