{"id":7029,"date":"2024-07-20T17:01:03","date_gmt":"2024-07-20T09:01:03","guid":{"rendered":""},"modified":"2024-07-20T17:01:03","modified_gmt":"2024-07-20T09:01:03","slug":"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09","status":"publish","type":"post","link":"https:\/\/mushiming.com\/7029.html","title":{"rendered":"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09"},"content":{"rendered":"

\n <\/path> \n<\/svg> <\/p>\n

\u524d\u8a00\uff1a<\/h2>\n

\u4e3a\u4e86\u65b9\u4fbf\u67e5\u770b\u535a\u5ba2\uff0c\u7279\u610f\u7533\u8bf7\u4e86\u4e00\u4e2a\u516c\u4f17\u53f7\uff0c\u9644\u4e0a\u4e8c\u7ef4\u7801\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u53ef\u4ee5\u5173\u6ce8\uff0c\u548c\u6211\u4e00\u8d77\u8ba8\u8bba\u5b66\u4e60\uff0c\u4e00\u8d77\u4eab\u53d7\u6280\u672f\uff0c\u4e00\u8d77\u6210\u957f\u3002<\/p>\n

\"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09<\/p>\n


\n

1. \u7b80\u4ecb<\/strong><\/h3>\n

UCOSII \u662f\u4e00\u4e2a\u53ef\u4ee5\u57fa\u4e8e ROM \u8fd0\u884c\u7684\u3001\u53ef\u88c1\u51cf\u7684\u3001\u62a2\u5360\u5f0f\u3001\u5b9e\u65f6\u591a\u4efb\u52a1\u5185\u6838\uff0c\u5177\u6709\u9ad8\u5ea6\u53ef\u79fb\u690d\u6027<\/strong>\uff0c\u7279\u522b\u9002\u5408\u4e8e\u5fae\u5904\u7406\u5668\u548c\u63a7\u5236\u5668\uff0c\u662f\u548c\u5f88\u591a\u5546\u4e1a\u64cd\u4f5c\u7cfb\u7edf\u6027\u80fd\u76f8\u5f53\u7684\u5b9e\u65f6\u64cd\u4f5c\u7cfb\u7edf(RTOS)\u3002<\/p>\n

1.1 UCOSII \u4f53\u7cfb\u7ed3\u6784\u56fe<\/h4>\n

\"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09<\/p>\n

UCOSII \u7684\u79fb\u690d\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4fee\u6539\uff1a os_cpu.h\u3001 os_cpu_a.asm \u548c os_cpu.c\u7b49\u4e09\u4e2a\u6587\u4ef6\u3002<\/p>\n

os_cpu.h\uff1a \u8fdb\u884c\u6570\u636e\u7c7b\u578b\u7684\u5b9a\u4e49\uff0c\u4ee5\u53ca\u5904\u7406\u5668\u76f8\u5173\u4ee3\u7801\u548c\u51e0\u4e2a\u51fd\u6570\u539f\u578b\uff1b<\/p>\n

os_cpu_a.asm\uff1a\u662f\u79fb\u690d\u8fc7\u7a0b\u4e2d\u9700\u8981\u6c47\u7f16\u5b8c\u6210\u7684\u4e00\u4e9b\u51fd\u6570\uff0c\u4e3b\u8981\u5c31\u662f\u4efb\u52a1\u5207\u6362\u51fd\u6570\uff1b<\/p>\n

os_cpu.c\uff1a\u5b9a\u4e49\u4e00\u4e9b\u7528\u6237 HOOK \u51fd\u6570\u3002<\/p>\n

\u5b9a\u65f6\u5668\u7684\u4f5c\u7528\uff1a\u4e3a UCOSII \u63d0\u4f9b\u7cfb\u7edf\u65f6\u949f\u8282\u62cd\uff0c\u5b9e\u73b0\u4efb\u52a1\u5207\u6362\u548c\u4efb\u52a1\u5ef6\u65f6\u7b49\u529f\u80fd\u3002\u8fd9
\u4e2a\u65f6\u949f\u8282\u62cd\u7531 OS_TICKS_PER_SEC\uff08\u5728 os_cfg.h \u4e2d\u5b9a\u4e49\uff09\u8bbe\u7f6e\uff0c\u4e00\u822c\u6211\u4eec\u8bbe\u7f6eUCOSII \u7684\u7cfb\u7edf\u65f6\u949f\u8282\u62cd\u4e3a 1ms~100ms\uff0c\u5177\u4f53\u6839\u636e\u4f60\u6240\u7528\u5904\u7406\u5668\u548c\u4f7f\u7528\u9700\u8981\u6765\u8bbe\u7f6e\u3002\u672c\u7ae0\uff0c\u5229\u7528 STM32\u7684 SYSTICK \u5b9a\u65f6\u5668\u6765\u63d0\u4f9b UCOSII \u65f6\u949f\u8282\u62cd\u3002<\/p>\n

1.2 \u4efb\u52a1<\/strong><\/h4>\n

\u4efb\u52a1\uff1a\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u6b7b\u5faa\u73af\u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5b9e\u73b0\u4e00\u5b9a\u7684\u529f\u80fd\uff0c\u4e00\u4e2a\u5de5\u7a0b\u53ef\u4ee5\u6709\u5f88\u591a\u8fd9\u6837\u7684\u4efb\u52a1\uff08\u6700\u591a 255 \u4e2a\uff09\uff0c UCOSII \u5bf9\u8fd9\u4e9b\u4efb\u52a1\u8fdb\u884c\u8c03\u5ea6\u7ba1\u7406\uff0c \u8ba9\u8fd9\u4e9b\u4efb\u52a1\u53ef\u4ee5<\/strong>\u5e76\u53d1\u5de5\u4f5c<\/strong>\uff08\u6ce8\u610f\u4e0d\u662f\u540c\u65f6\u5de5\u4f5c\uff0c\u5e76\u53d1\u53ea\u662f\u5404\u4efb\u52a1\u8f6e\u6d41\u5360\u7528 CPU<\/strong>\uff0c\u800c\u4e0d\u662f\u540c\u65f6\u5360\u7528\uff0c\u4efb\u4f55\u65f6\u5019\u8fd8\u662f\u53ea\u6709 1\u4e2a\u4efb\u52a1\u80fd\u591f\u5360\u7528 CPU\uff09\uff0c \u8fd9\u5c31\u662f UCOSII \u6700\u57fa\u672c\u7684\u529f\u80fd\u3002<\/p>\n

Ucos \u4efb\u52a1\u7684\u4e00\u822c\u683c\u5f0f\u4e3a\uff1a<\/strong><\/p>\n

void<\/span> MyTask (<\/span>void<\/span> *<\/span>pdata)<\/span> { \n   <\/span> \u4efb\u52a1\u51c6\u5907\u5de5\u4f5c\u2026 While<\/span>(<\/span>1<\/span>)<\/span>\/\/\u6b7b\u5faa\u73af<\/span> { \n   <\/span> \u4efb\u52a1 MyTask \u5b9e\u4f53\u4ee3\u7801;<\/span> OSTimeDlyHMSM<\/span>(<\/span>x,<\/span>x,<\/span>x,<\/span>x)<\/span>;<\/span>\/\/\u8c03\u7528\u4efb\u52a1\u5ef6\u65f6\u51fd\u6570\uff0c\u91ca\u653e cpu \u63a7\u5236\u6743\uff0c<\/span> }<\/span> }<\/span> <\/code><\/pre>\n

1.3 \u4efb\u52a1\u4f18\u5148\u7ea7<\/strong><\/h4>\n

ucos \u4e2d\uff0c\u6bcf\u4e2a\u4efb\u52a1\u90fd\u6709\u552f\u4e00\u7684\u4e00\u4e2a\u4f18\u5148\u7ea7\u3002\u4f18\u5148\u7ea7\u662f\u4efb\u52a1\u7684\u552f\u4e00\u6807\u8bc6\u3002\u5728 UCOSII\u4e2d\uff0c\u4f7f\u7528 CPU \u7684\u65f6\u5019\uff0c\u4f18\u5148\u7ea7\u9ad8\uff08\u6570\u503c\u5c0f\uff09\u7684\u4efb\u52a1\u6bd4\u4f18\u5148\u7ea7\u4f4e\u7684\u4efb\u52a1\u5177\u6709\u4f18\u5148\u4f7f\u7528\u6743<\/strong>\uff0c\u5373\u4efb\u52a1\u5c31\u7eea\u8868\u4e2d\u603b\u662f\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u4efb\u52a1\u83b7\u5f97 CPU \u4f7f\u7528\u6743\uff0c\u53ea\u6709\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u8ba9\u51fa CPU \u4f7f\u7528\u6743\uff08\u6bd4\u5982\u5ef6\u65f6\uff09\u65f6\uff0c\u4f4e\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u624d\u80fd\u83b7\u5f97 CPU \u4f7f\u7528\u6743\u3002 UCOSII \u4e0d\u652f\u6301\u591a\u4e2a\u4efb\u52a1\u4f18\u5148\u7ea7\u76f8\u540c\uff0c\u4e5f\u5c31\u662f\u6bcf\u4e2a\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u5fc5\u987b\u4e0d\u4e00\u6837\u3002<\/p>\n

1.4 \u4efb\u52a1\u5806\u6808<\/strong><\/h4>\n

\u5b58\u50a8\u5668\u4e2d\u7684\u8fde\u7eed\u5b58\u50a8\u7a7a\u95f4<\/strong>\u3002\u4e3a\u4e86\u6ee1\u8db3\u4efb\u52a1\u5207\u6362\u548c\u54cd\u5e94\u4e2d\u65ad\u65f6\u4fdd\u5b58 CPU \u5bc4\u5b58\u5668\u4e2d\u7684\u5185\u5bb9\u4ee5\u53ca\u4efb\u52a1\u8c03\u7528\u5176\u4ed6\u51fd\u6570\u65f6\u7684\u9700\u8981\uff0c\u6bcf\u4e2a\u4efb\u52a1\u90fd\u6709\u81ea\u5df1\u7684\u5806\u6808\u3002\u5728\u521b\u5efa\u4efb\u52a1\u7684\u65f6\u5019\uff0c\u4efb\u52a1\u5806\u6808\u662f\u4efb\u52a1\u521b\u5efa\u7684\u4e00\u4e2a\u91cd\u8981\u5165\u53e3\u53c2\u6570\u3002<\/p>\n

1.5 \u4efb\u52a1\u63a7\u5236\u5757 OS_TCB<\/strong><\/h4>\n

\u7528\u6765\u8bb0\u5f55\u4efb\u52a1\u5806\u6808\u6307\u9488\uff0c\u4efb\u52a1\u5f53\u524d\u72b6\u6001\u4ee5\u53ca\u4efb\u52a1\u4f18\u5148\u7ea7\u7b49\u4efb\u52a1\u5c5e\u6027\u3002UCOSII \u7684\u4efb\u4f55\u4efb\u52a1\u90fd\u662f\u901a\u8fc7\u4efb\u52a1\u63a7\u5236\u5757\uff08TCB\uff09\u7684\u4e1c\u897f\u6765\u63a7\u5236\u7684\uff0c\u4e00\u65e6\u4efb\u52a1\u521b\u5efa\u4e86\uff0c\u4efb\u52a1\u63a7\u5236\u5757 OS_TCB \u5c31\u4f1a\u88ab\u8d4b\u503c\u3002\u6bcf\u4e2a\u4efb\u52a1\u7ba1\u7406\u5757\u6709 3 \u4e2a\u6700\u91cd\u8981\u7684\u53c2\u6570\uff1a<\/p>\n

1.\u4efb\u52a1\u51fd\u6570\u6307\u9488\uff1b<\/strong><\/p>\n

2.\u4efb\u52a1\u5806\u6808\u6307\u9488\uff1b<\/strong><\/p>\n

3.\u4efb\u52a1\u4f18\u5148\u7ea7\uff1b<\/strong><\/p>\n

\u4efb\u52a1\u63a7\u5236\u5757\u5c31\u662f\u4efb\u52a1\u5728\u7cfb\u7edf\u91cc\u9762\u7684\u8eab\u4efd\u8bc1\u3002<\/p>\n

1.6 \u4efb\u52a1\u5c31\u7eea\u8868<\/strong><\/h4>\n

\u7528\u6765\u8bb0\u5f55\u7cfb\u7edf\u4e2d\u6240\u6709\u5904\u4e8e\u5c31\u7eea\u72b6\u6001\u7684\u4efb\u52a1\u3002\u5b83\u662f\u4e00\u4e2a\u4f4d\u56fe\uff0c\u7cfb\u7edf\u4e2d\u6bcf\u4e2a\u4efb\u52a1\u90fd\u5728\u8fd9\u4e2a\u56fe\u4e2d\u5360\u636e\u4e00\u4e2a\u8fdb\u5236\u4f4d\uff0c\u8be5\u4f4d\u7f6e\u7684\u72b6\u6001\uff081 \u6216\u8005 0\uff09\u5c31\u8868\u793a\u4efb\u52a1\u662f\u5426\u5904\u4e8e\u5c31\u7eea\u72b6\u6001\u3002<\/p>\n

1.7 \u4efb\u52a1\u8c03\u5ea6<\/strong><\/h4>\n

\u4e00\u662f\u5728\u4efb\u52a1\u5c31\u7eea\u8868\u4e2d\u67e5\u627e\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u5c31\u7eea\u4efb\u52a1\uff0c\u4e8c\u662f\u5b9e\u73b0\u4efb\u52a1\u7684\u5207\u6362\u3002\u6bd4\u5982\u8bf4\uff0c\u5f53\u4e00\u4e2a\u4efb\u52a1\u91ca\u653e cpu \u63a7\u5236\u6743\u540e\uff0c\u8fdb\u884c\u4e00\u6b21\u4efb\u52a1\u8c03\u5ea6\uff0c\u8fd9\u4e2a\u65f6\u5019\u4efb\u52a1\u8c03\u5ea6\u5668\u9996\u5148\u8981\u53bb\u4efb\u52a1\u5c31\u7eea\u8868\u67e5\u8be2\u4f18\u5148\u7ea7\u6700\u9ad8\u7684\u5c31\u7eea\u4efb\u52a1\uff0c\u67e5\u5230\u4e4b\u540e\uff0c\u8fdb\u884c\u4e00\u6b21\u4efb\u52a1\u5207\u6362\uff0c\u8f6c\u800c\u53bb\u6267\u884c\u4e0b\u4e00\u4e2a\u4efb\u52a1\u3002<\/p>\n

1.8 \u72b6\u6001\u5207\u6362<\/strong><\/h4>\n

UCOSII \u7684\u6bcf\u4e2a\u4efb\u52a1\u90fd\u662f\u4e00\u4e2a\u6b7b\u5faa\u73af\u3002\u6bcf\u4e2a\u4efb\u52a1\u90fd\u5904\u5728\u4ee5\u4e0b 5 \u79cd\u72b6\u6001\u4e4b\u4e00\u7684\u72b6\u6001\u4e0b\uff0c\u8fd9 5\u79cd\u72b6\u6001\u662f**\uff1a\u7761\u7720\u72b6\u6001\u3001 \u5c31\u7eea\u72b6\u6001\u3001 \u8fd0\u884c\u72b6\u6001\u3001 \u7b49\u5f85\u72b6\u6001(\u7b49\u5f85\u67d0\u4e00\u4e8b\u4ef6\u53d1\u751f)\u548c\u4e2d\u65ad\u670d\u52a1\u72b6\u6001\u3002**<\/p>\n

\u7761\u7720\u72b6\u6001\uff1a<\/strong> \u4efb\u52a1\u5728\u6ca1\u6709\u88ab\u914d\u5907\u4efb\u52a1\u63a7\u5236\u5757\u6216\u88ab\u5265\u593a\u4e86\u4efb\u52a1\u63a7\u5236\u5757\u65f6\u7684\u72b6\u6001\u3002<\/p>\n

\u5c31\u7eea\u72b6\u6001\uff1a<\/strong> \u7cfb\u7edf\u4e3a\u4efb\u52a1\u914d\u5907\u4e86\u4efb\u52a1\u63a7\u5236\u5757\u4e14\u5728\u4efb\u52a1\u5c31\u7eea\u8868\u4e2d\u8fdb\u884c\u4e86\u5c31\u7eea\u767b\u8bb0\uff0c\u4efb\u52a1\u5df2\u7ecf\u51c6\u5907\u597d\u4e86\uff0c\u4f46\u7531\u4e8e\u8be5\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u6bd4\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u4f4e\uff0c \u8fd8\u6682\u65f6\u4e0d\u80fd\u8fd0\u884c\uff0c\u8fd9\u65f6\u4efb\u52a1\u7684\u72b6\u6001\u53eb\u505a\u5c31\u7eea\u72b6\u6001\u3002<\/p>\n

\u8fd0\u884c\u72b6\u6001\uff1a<\/strong> \u8be5\u4efb\u52a1\u83b7\u5f97 CPU \u4f7f\u7528\u6743\uff0c\u5e76\u6b63\u5728\u8fd0\u884c\u4e2d\uff0c\u6b64\u65f6\u7684\u4efb\u52a1\u72b6\u6001\u53eb\u505a\u8fd0\u884c\u72b6\u6001\u3002<\/p>\n

\u7b49\u5f85\u72b6\u6001\uff1a<\/strong> \u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\uff0c\u9700\u8981\u7b49\u5f85\u4e00\u6bb5\u65f6\u95f4\u6216\u9700\u8981\u7b49\u5f85\u4e00\u4e2a\u4e8b\u4ef6\u53d1\u751f\u518d\u8fd0\u884c\u65f6\uff0c\u8be5\u4efb\u52a1\u5c31\u4f1a\u628a CPU \u7684\u4f7f\u7528\u6743\u8ba9\u7ed9\u522b\u7684\u4efb\u52a1\u800c\u4f7f\u4efb\u52a1\u8fdb\u5165\u7b49\u5f85\u72b6\u6001\u3002<\/p>\n

\u4e2d\u65ad\u670d\u52a1\u72b6\u6001\uff1a<\/strong> \u4e00\u4e2a\u6b63\u5728\u8fd0\u884c\u7684\u4efb\u52a1\u4e00\u65e6\u54cd\u5e94\u4e2d\u65ad\u7533\u8bf7\u5c31\u4f1a\u4e2d\u6b62\u8fd0\u884c\u800c\u53bb\u6267\u884c\u4e2d\u65ad\u670d\u52a1\u7a0b\u5e8f\uff0c\u8fd9\u65f6\u4efb\u52a1\u7684\u72b6\u6001\u53eb\u505a\u4e2d\u65ad\u670d\u52a1\u72b6\u6001\u3002<\/p>\n

5\u79cd\u72b6\u6001\u4e4b\u95f4\u7684\u8f6c\u6362\u5982\u4e0b\u56fe\uff1a<\/p>\n

\"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09<\/p>\n

2.UCOS\u76f8\u5173\u51fd\u6570<\/strong><\/h3>\n

2.1 \u5efa\u7acb\u4efb\u52a1\u51fd\u6570<\/strong><\/h4>\n

\u5982\u679c\u60f3\u8ba9 UCOSII \u7ba1\u7406\u7528\u6237\u7684\u4efb\u52a1\uff0c\u5fc5\u987b\u5148\u5efa\u7acb\u4efb\u52a1\u3002 UCOSII \u63d0\u4f9b\u4e86 2 \u4e2a\u5efa\u7acb\u4efb\u52a1\u7684\u51fd\u6570\uff1a OSTaskCreat \u548c OSTaskCreatExt<\/strong>\uff0c\u4e00\u822c\u7528 OSTaskCreat \u51fd\u6570\u6765\u521b\u5efa\u4efb\u52a1\u3002<\/p>\n

\u8be5\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/p>\n

OSTaskCreate<\/span>(<\/span>void<\/span>(<\/span>*<\/span>task)<\/span>(<\/span>void<\/span>*<\/span>pd)<\/span>,<\/span>void<\/span>*<\/span>pdata,<\/span>OS_STK*<\/span>ptos,<\/span>INTU prio)<\/span>\uff1b <\/code><\/pre>\n

task\uff1a\u662f\u6307\u5411\u4efb\u52a1\u4ee3\u7801\u7684\u6307\u9488\uff1b<\/p>\n

pdata\uff1a\u662f\u4efb\u52a1\u5f00\u59cb\u6267\u884c\u65f6\uff0c\u4f20\u9012\u7ed9\u4efb\u52a1\u7684\u53c2\u6570\u7684\u6307\u9488\uff1b<\/p>\n

ptos\uff1a\u662f\u5206\u914d\u7ed9\u4efb\u52a1\u7684\u5806\u6808\u7684\u6808\u9876\u6307\u9488\uff1b<\/p>\n

prio \uff1a\u662f\u5206\u914d\u7ed9\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u3002<\/p>\n

\u6bcf\u4e2a\u4efb\u52a1\u90fd\u6709\u81ea\u5df1\u7684\u5806\u6808\uff0c\u5806\u6808\u5fc5\u987b\u7533\u660e\u4e3a OS_STK \u7c7b\u578b\uff0c\u5e76\u4e14\u7531\u8fde\u7eed\u7684\u5185\u5b58\u7a7a\u95f4\u7ec4
\u6210\u3002\u53ef\u4ee5\u9759\u6001\u5206\u914d\u5806\u6808\u7a7a\u95f4\uff0c\u4e5f\u53ef\u4ee5\u52a8\u6001\u5206\u914d\u5806\u6808\u7a7a\u95f4\u3002<\/p>\n

2.2 \u4efb\u52a1\u5220\u9664\u51fd\u6570<\/strong><\/h4>\n

\u4efb\u52a1\u5220\u9664\uff0c\u5176\u5b9e\u5c31\u662f\u628a\u4efb\u52a1\u7f6e\u4e8e\u7761\u7720\u72b6\u6001<\/strong>\u3002 UCOSII\u63d0\u4f9b\u7684\u4efb\u52a1\u5220\u9664\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/p>\n

INT8U OSTaskDel<\/span>(<\/span>INT8U prio)<\/span>\uff1b <\/code><\/pre>\n

\u53c2\u6570 prio \uff1a\u8981\u5220\u9664\u7684\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\uff0c\u53ef\u89c1\u8be5\u51fd\u6570\u662f\u901a\u8fc7\u4efb\u52a1\u4f18\u5148\u7ea7\u6765\u5b9e\u73b0\u4efb\u52a1\u5220\u9664\u7684\u3002<\/p>\n

\u7279\u522b\u6ce8\u610f\uff1a<\/strong> \u4efb\u52a1\u4e0d\u80fd\u968f\u4fbf\u5220\u9664\uff0c\u5fc5\u987b\u5728\u786e\u4fdd\u88ab\u5220\u9664\u4efb\u52a1\u7684\u8d44\u6e90\u88ab\u91ca\u653e\u7684\u524d\u63d0\u4e0b\u624d\u80fd\u5220\u9664\uff01<\/p>\n

2.3 \u8bf7\u6c42\u4efb\u52a1\u5220\u9664\u51fd\u6570<\/strong><\/h4>\n

\u524d\u9762\u63d0\u5230\uff0c\u5fc5\u987b\u786e\u4fdd\u88ab\u5220\u9664\u4efb\u52a1\u7684\u8d44\u6e90\u88ab\u91ca\u653e\u7684\u524d\u63d0\u4e0b\u624d\u80fd\u5c06\u5176\u5220\u9664\uff0c\u6240\u4ee5\u901a\u8fc7\u5411\u88ab\u5220\u9664\u4efb\u52a1\u53d1\u9001\u5220\u9664\u8bf7\u6c42\uff0c\u6765\u5b9e\u73b0\u4efb\u52a1\u91ca\u653e\u81ea\u8eab\u5360\u7528\u8d44\u6e90\u540e\u518d\u5220\u9664\u3002<\/p>\n

UCOSII \u63d0\u4f9b\u7684\u8bf7\u6c42\u5220\u9664\u4efb\u52a1\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/p>\n

INT8U OSTaskDelReq<\/span>(<\/span>INT8U prio)<\/span>\uff1b <\/code><\/pre>\n

\u901a\u8fc7\u4f18\u5148\u7ea7\u6765\u786e\u5b9a\u88ab\u8bf7\u6c42\u5220\u9664\u4efb\u52a1\u3002<\/p>\n

2.4 \u4efb\u52a1\u6302\u8d77\u51fd\u6570<\/strong><\/h4>\n

\u4efb\u52a1\u6302\u8d77\u548c\u4efb\u52a1\u5220\u9664\u6709\u70b9\u7c7b\u4f3c\uff0c\u4f46\u662f\u53c8\u6709\u533a\u522b\uff0c\u4efb\u52a1\u6302\u8d77\u53ea\u662f\u5c06\u88ab\u6302\u8d77\u4efb\u52a1\u7684\u5c31\u7eea\u6807\u5fd7\u5220\u9664\uff0c\u5e76\u505a\u4efb\u52a1\u6302\u8d77\u8bb0\u5f55\uff0c\u5e76\u6ca1\u6709\u5c06\u4efb\u52a1\u63a7\u5236\u5757\u4efb\u52a1\u63a7\u5236\u5757\u94fe\u8868\u91cc\u9762\u5220\u9664\uff0c \u4e5f\u4e0d\u9700\u8981\u91ca
\u653e\u5176\u8d44\u6e90\uff0c \u800c\u4efb\u52a1\u5220\u9664\u5219\u5fc5\u987b\u5148\u91ca\u653e\u88ab\u5220\u9664\u4efb\u52a1\u7684\u8d44\u6e90\uff0c\u5e76\u5c06\u88ab\u5220\u9664\u4efb\u52a1\u7684\u4efb\u52a1\u63a7\u5236\u5757\u4e5f\u7ed9\u5220\u4e86\u3002\u88ab\u6302\u8d77\u7684\u4efb\u52a1\uff0c\u5728\u6062\u590d\uff08\u89e3\u6302\uff09\u540e\u53ef\u4ee5\u7ee7\u7eed\u8fd0\u884c\u3002<\/p>\n

UCOSII \u63d0\u4f9b\u7684\u4efb\u52a1\u6302\u8d77\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/p>\n

INT8U OSTaskSuspend<\/span>(<\/span>INT8U prio)<\/span>\uff1b <\/code><\/pre>\n

2.5 \u4efb\u52a1\u6062\u590d\u51fd\u6570<\/h4>\n

\u6709\u4efb\u52a1\u6302\u8d77\u51fd\u6570\uff0c\u5c31\u6709\u4efb\u52a1\u6062\u590d\u51fd\u6570\uff0c\u901a\u8fc7\u8be5\u51fd\u6570\u5c06\u88ab\u6302\u8d77\u7684\u4efb\u52a1\u6062\u590d\uff0c\u8ba9\u8c03\u5ea6\u5668\u80fd
\u591f\u91cd\u65b0\u8c03\u5ea6\u8be5\u51fd\u6570\u3002<\/p>\n

UCOSII \u63d0\u4f9b\u7684\u4efb\u52a1\u6062\u590d\u51fd\u6570\u539f\u578b\u4e3a\uff1a<\/p>\n

INT8U OSTaskResume<\/span>(<\/span>INT8U prio)<\/span>\uff1b <\/code><\/pre>\n

3. \u79fb\u690d UCOSII<\/strong><\/h3>\n

3.1 \u79fb\u690d UCOUS<\/strong><\/h4>\n

3.2 \u7f16\u5199\u4efb\u52a1\u51fd\u6570\u5e76\u8bbe\u7f6e\u5176\u5806\u6808\u5927\u5c0f\u548c\u4f18\u5148\u7ea7\u7b49\u53c2\u6570<\/strong><\/h4>\n

\u7f16\u5199\u4efb\u52a1\u51fd\u6570\uff0c\u4ee5\u4fbf UCOSII \u8c03\u7528\u3002<\/p>\n

\u8bbe\u7f6e\u51fd\u6570\u5806\u6808\u5927\u5c0f\uff0c\u8fd9\u4e2a\u9700\u8981\u6839\u636e\u51fd\u6570\u7684\u9700\u6c42\u6765\u8bbe\u7f6e\uff0c\u5982\u679c\u4efb\u52a1\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf\u591a\uff0c\u5d4c\u5957\u5c42\u6570\u591a\uff0c\u90a3\u4e48\u76f8\u5e94\u7684\u5806\u6808\u5c31\u5f97\u5927\u4e00\u4e9b\uff0c\u5982\u679c\u5806\u6808\u8bbe\u7f6e\u5c0f\u4e86\uff0c\u5f88\u53ef\u80fd\u51fa\u73b0\u7684\u7ed3\u679c\u5c31\u662f CPU\u8fdb\u5165 HardFault\uff0c\u9047\u5230\u8fd9\u79cd\u60c5\u51b5\uff0c\u5c31\u5fc5\u987b\u628a\u5806\u6808\u8bbe\u7f6e\u5927\u4e00\u70b9\u4e86\u3002\u53e6\u5916\uff0c\u6709\u4e9b\u5730\u65b9\u8fd8\u9700\u8981\u6ce8\u610f\u5806\u6808\u5b57\u8282\u5bf9\u9f50\u7684\u95ee\u9898<\/strong>\uff0c\u5982\u679c\u4efb\u52a1\u8fd0\u884c\u51fa\u73b0\u83ab\u540d\u5176\u5999\u7684\u9519\u8bef\uff08\u6bd4\u5982\u7528\u5230 sprintf \u51fa\u9519\uff09\uff0c\u8bf7\u8003\u8651\u662f\u4e0d\u662f\u5b57\u8282\u5bf9\u9f50\u7684\u95ee\u9898\u3002<\/p>\n

\u8bbe\u7f6e\u4efb\u52a1\u4f18\u5148\u7ea7\uff0c \u8fd9\u4e2a\u9700\u8981\u6839\u636e\u4efb\u52a1\u7684\u91cd\u8981\u6027\u548c\u5b9e\u65f6\u6027\u8bbe\u7f6e\uff0c\u9ad8\u4f18\u5148\u7ea7\u7684\u4efb\u52a1\u6709\u4f18\u5148\u4f7f\u7528 CPU \u7684\u6743\u5229\u3002<\/p>\n

3.3 \u521d\u59cb\u5316 UCOSII\uff0c\u5e76\u5728 UCOSII \u4e2d\u521b\u5efa\u4efb\u52a1<\/strong><\/h4>\n

\u8c03\u7528 OSInit\uff0c\u521d\u59cb\u5316 UCOSII\uff0c\u901a\u8fc7\u8c03\u7528 OSTaskCreate \u51fd\u6570\u521b\u5efa\u6211\u4eec\u7684\u4efb\u52a1\u3002<\/p>\n

3.4 \u542f\u52a8 UCOSII<\/strong><\/h4>\n

\u8c03\u7528 OSStart\uff0c\u542f\u52a8 UCOSII\u3002<\/p>\n

4. \u8f6f\u4ef6\u914d\u7f6e<\/strong><\/h3>\n

4.1 UCOSII \u6e90\u7801\u8bf4\u660e<\/strong><\/h4>\n

\"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff09<\/p>\n

UCOSII-CORE\uff1a\u662fUCOSII \u7684\u6838\u5fc3\u6e90\u7801\uff0c\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u53d8\u52a8\u3002<\/p>\n

UCOSII-PORT \uff1a\u79fb\u690d UCOSII \u8981\u4fee\u6539\u7684 3 \u4e2a\u4ee3\u7801\uff0c\u8fd9\u4e2a\u5728\u79fb\u690d\u7684\u65f6\u5019\u5b8c\u6210\u3002<\/p>\n

UCOSII-CONFIG \uff1a UCOSII \u7684\u914d\u7f6e\u90e8\u5206\uff0c\u4e3b\u8981\u7531\u7528\u6237\u6839\u636e\u81ea\u5df1\u7684\u9700\u8981\u5bf9 UCOSII\u8fdb\u884c\u88c1\u526a\u6216\u5176\u4ed6\u8bbe\u7f6e\u3002<\/p>\n

4.2 UCOSII \u7b80\u6613\u6d4b\u8bd5<\/strong><\/h4>\n
#include<\/span> \"led.h\"<\/span><\/span> #include<\/span> \"delay.h\"<\/span><\/span> #include<\/span> \"sys.h\"<\/span><\/span> #include<\/span> \"includes.h\"<\/span> <\/span> \/UCOSII\u4efb\u52a1\u8bbe\u7f6e\/\/\/<\/span> \/\/START \u4efb\u52a1<\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u4f18\u5148\u7ea7<\/span> #define<\/span> START_TASK_PRIO 10 <\/span>\/\/\u5f00\u59cb\u4efb\u52a1\u7684\u4f18\u5148\u7ea7\u8bbe\u7f6e\u4e3a\u6700\u4f4e<\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u5806\u6808\u5927\u5c0f<\/span> #define<\/span> START_STK_SIZE 64<\/span> \/\/\u4efb\u52a1\u5806\u6808 <\/span> OS_STK START_TASK_STK[<\/span>START_STK_SIZE]<\/span>;<\/span> \/\/\u4efb\u52a1\u51fd\u6570<\/span> void<\/span> start_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span>;<\/span> \/\/LED0\u4efb\u52a1<\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u4f18\u5148\u7ea7<\/span> #define<\/span> LED0_TASK_PRIO 7 <\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u5806\u6808\u5927\u5c0f<\/span> #define<\/span> LED0_STK_SIZE 64<\/span> \/\/\u4efb\u52a1\u5806\u6808 <\/span> OS_STK LED0_TASK_STK[<\/span>LED0_STK_SIZE]<\/span>;<\/span> \/\/\u4efb\u52a1\u51fd\u6570<\/span> void<\/span> led0_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span>;<\/span> \/\/LED1\u4efb\u52a1<\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u4f18\u5148\u7ea7<\/span> #define<\/span> LED1_TASK_PRIO 6 <\/span> \/\/\u8bbe\u7f6e\u4efb\u52a1\u5806\u6808\u5927\u5c0f<\/span> #define<\/span> LED1_STK_SIZE 64<\/span> \/\/\u4efb\u52a1\u5806\u6808<\/span> OS_STK LED1_TASK_STK[<\/span>LED1_STK_SIZE]<\/span>;<\/span> \/\/\u4efb\u52a1\u51fd\u6570<\/span> void<\/span> led1_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span>;<\/span> int<\/span> main<\/span>(<\/span>void<\/span>)<\/span> { \n   <\/span> delay_init<\/span>(<\/span>)<\/span>;<\/span> \/\/\u5ef6\u65f6\u51fd\u6570\u521d\u59cb\u5316 <\/span> NVIC_PriorityGroupConfig<\/span>(<\/span>NVIC_PriorityGroup_2)<\/span>;<\/span>\/\/ \u8bbe\u7f6e\u4e2d\u65ad\u4f18\u5148\u7ea7\u5206\u7ec42<\/span> LED_Init<\/span>(<\/span>)<\/span>;<\/span> \/\/\u521d\u59cb\u5316\u4e0eLED\u8fde\u63a5\u7684\u786c\u4ef6\u63a5\u53e3<\/span> OSInit<\/span>(<\/span>)<\/span>;<\/span> OSTaskCreate<\/span>(<\/span>start_task,<\/span>(<\/span>void<\/span> *<\/span>)<\/span>0<\/span>,<\/span>(<\/span>OS_STK *<\/span>)<\/span>&<\/span>START_TASK_STK[<\/span>START_STK_SIZE-<\/span>1<\/span>]<\/span>,<\/span>START_TASK_PRIO )<\/span>;<\/span>\/\/\u521b\u5efa\u8d77\u59cb\u4efb\u52a1<\/span> OSStart<\/span>(<\/span>)<\/span>;<\/span> }<\/span> \/\/\u5f00\u59cb\u4efb\u52a1<\/span> void<\/span> start_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span> { \n   <\/span> OS_CPU_SR cpu_sr=<\/span>0<\/span>;<\/span> pdata =<\/span> pdata;<\/span> OS_ENTER_CRITICAL<\/span>(<\/span>)<\/span>;<\/span> \/\/\u8fdb\u5165\u4e34\u754c\u533a(\u65e0\u6cd5\u88ab\u4e2d\u65ad\u6253\u65ad) <\/span> OSTaskCreate<\/span>(<\/span>led0_task,<\/span>(<\/span>void<\/span> *<\/span>)<\/span>0<\/span>,<\/span>(<\/span>OS_STK*<\/span>)<\/span>&<\/span>LED0_TASK_STK[<\/span>LED0_STK_SIZE-<\/span>1<\/span>]<\/span>,<\/span>LED0_TASK_PRIO)<\/span>;<\/span> OSTaskCreate<\/span>(<\/span>led1_task,<\/span>(<\/span>void<\/span> *<\/span>)<\/span>0<\/span>,<\/span>(<\/span>OS_STK*<\/span>)<\/span>&<\/span>LED1_TASK_STK[<\/span>LED1_STK_SIZE-<\/span>1<\/span>]<\/span>,<\/span>LED1_TASK_PRIO)<\/span>;<\/span> OSTaskSuspend<\/span>(<\/span>START_TASK_PRIO)<\/span>;<\/span> \/\/\u6302\u8d77\u8d77\u59cb\u4efb\u52a1.<\/span> OS_EXIT_CRITICAL<\/span>(<\/span>)<\/span>;<\/span> \/\/\u9000\u51fa\u4e34\u754c\u533a(\u53ef\u4ee5\u88ab\u4e2d\u65ad\u6253\u65ad)<\/span> }<\/span> \/\/LED0\u4efb\u52a1<\/span> void<\/span> led0_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span> { \n   <\/span> while<\/span>(<\/span>1<\/span>)<\/span> { \n   <\/span> LED0=<\/span>0<\/span>;<\/span> delay_ms<\/span>(<\/span>80<\/span>)<\/span>;<\/span> LED0=<\/span>1<\/span>;<\/span> delay_ms<\/span>(<\/span>920<\/span>)<\/span>;<\/span> }<\/span>;<\/span> }<\/span> \/\/LED1\u4efb\u52a1<\/span> void<\/span> led1_task<\/span>(<\/span>void<\/span> *<\/span>pdata)<\/span> { \n   <\/span> while<\/span>(<\/span>1<\/span>)<\/span> { \n   <\/span> LED1=<\/span>0<\/span>;<\/span> delay_ms<\/span>(<\/span>300<\/span>)<\/span>;<\/span> LED1=<\/span>1<\/span>;<\/span> delay_ms<\/span>(<\/span>300<\/span>)<\/span>;<\/span> }<\/span>;<\/span> }<\/span> <\/code><\/pre>\n
\n

\u53c2\u8003\uff1a<\/strong><\/p>\n

    \n
  1. \u539f\u5b50\u5e93\u51fd\u6570\u624b\u518c<\/li>\n
  2. \u7b2c3\u7ae0 \u5185\u6838\u7ed3\u6784<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"STM32\u5b66\u4e60\u7b14\u8bb0\u4e00\u4e00UCOSII\uff081\uff091.\u7b80\u4ecbUCOSII\u662f\u4e00\u4e2a\u53ef\u4ee5\u57fa\u4e8eROM\u8fd0\u884c\u7684\u3001\u53ef\u88c1\u51cf\u7684\u3001\u62a2\u5360\u5f0f\u3001\u5b9e\u65f6\u591a\u4efb\u52a1\u5185\u6838\uff0c\u5177\u6709\u9ad8\u5ea6\u53ef\u79fb\u690d\u6027\uff0c...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7029"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=7029"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/7029\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=7029"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=7029"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=7029"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}