{"id":89968,"date":"2026-08-04T11:24:38","date_gmt":"2026-08-04T03:24:38","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/89968.html"},"modified":"2026-08-04T11:24:38","modified_gmt":"2026-08-04T03:24:38","slug":"freertos%ef%bc%8812%ef%bc%89%ef%bc%9a%e4%ba%8b%e4%bb%b6%e6%a0%87%e5%bf%97%e7%bb%84%e5%ae%9e%e9%aa%8c","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/89968.html","title":{"rendered":"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c"},"content":{"rendered":"<h2>\u5b9e\u9a8c\u73b0\u8c61<\/h2>\n<p>\u5b9e\u9a8c\u6b65\u9aa4&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"619\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260804032436-6a715b74bd251.png\" width=\"1804\" \/><\/p>\n<p>\u5b9e\u9a8c\u73b0\u8c61&#xff1a;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"627\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260804032437-6a715b7555a9f.png\" width=\"954\" \/><\/p>\n<h2>\u9879\u76ee\u521b\u5efa<\/h2>\n<p>\u590d\u5236Freertos_\u4e8c\u503c\u4fe1\u53f7\u91cf\u5b9e\u9a8c\u6587\u4ef6&#xff0c;\u7c98\u8d34\u5e76\u4e14\u91cd\u547d\u540d\u4e3aFreertos_\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c&#xff0c;\u8fdb\u5165keil&#xff0c;\u5220\u9664\u65e0\u5173\u9879&#xff0c;\u5305\u62ec\u4e8c\u503c\u4fe1\u53f7\u91cf\u7684\u521b\u5efa&#xff0c;task1\u548ctask2\u4e2d\u7684\u64cd\u4f5c&#xff0c;\u5728\u6587\u4ef6\u5934\u4e0a\u52a0\u4e0a#include &#034;event_groups.h&#034;&#xff0c;\u5c06task1\u4e0etask2\u7684\u4efb\u52a1\u4f18\u5148\u7ea7\u4e92\u6362&#xff0c;\u4e0b\u65b9\u662f\u5220\u9664\u5b8c\u540e\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;FreeRTOS.h&#034;<br \/>\n#include &#034;task.h&#034;<br \/>\n#include &#034;queue.h&#034;<br \/>\n#include &#034;led.h&#034;<br \/>\n#include &#034;key.h&#034;<br \/>\n#include &#034;serial.h&#034;<br \/>\n#include &#034;semphr.h&#034;<br \/>\n#include &#034;event_groups.h&#034;<\/p>\n<p>\/* \u4efb\u52a1\u53c2\u6570 *\/<br \/>\n#define START_TASK_SIZE  128<br \/>\n#define START_TASK_PRIO  1<br \/>\n#define TASK1_SIZE       256<br \/>\n#define TASK1_PRIO       3<br \/>\n#define TASK2_SIZE       256<br \/>\n#define TASK2_PRIO       2<\/p>\n<p>TaskHandle_t start_task_handle;<br \/>\nTaskHandle_t task1_handle;<br \/>\nTaskHandle_t task2_handle;<\/p>\n<p>void Start_task(void *pvParameters);<br \/>\nvoid task_1(void *pvParameters);<br \/>\nvoid task_2(void *pvParameters);<\/p>\n<p>void FreeRTOS_Task(void)<br \/>\n{<br \/>\n    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);<br \/>\n    Key_Init();<br \/>\n    LED_Init();<br \/>\n    Serial_Init();<\/p>\n<p>    xTaskCreate((TaskFunction_t)Start_task, &#034;Start_task&#034;, START_TASK_SIZE, NULL, START_TASK_PRIO, &amp;start_task_handle);<br \/>\n    vTaskStartScheduler();<br \/>\n}<\/p>\n<p>void Start_task(void *pvParameters)<br \/>\n{<br \/>\n    taskENTER_CRITICAL();           \/\/ \u8fdb\u5165\u4e34\u754c\u533a&#xff0c;\u786e\u4fdd\u4efb\u52a1\u521b\u5efa\u8fc7\u7a0b\u4e0d\u88ab\u4e2d\u65ad<br \/>\n    xTaskCreate((TaskFunction_t)task_1, &#034;task_1&#034;, TASK1_SIZE, NULL, TASK1_PRIO, &amp;task1_handle);<br \/>\n    xTaskCreate((TaskFunction_t)task_2, &#034;task_2&#034;, TASK2_SIZE, NULL, TASK2_PRIO, &amp;task2_handle);<br \/>\n    taskEXIT_CRITICAL();<br \/>\n    vTaskDelete(NULL);              \/\/ \u5220\u9664\u542f\u52a8\u4efb\u52a1\u81ea\u8eab<br \/>\n}<\/p>\n<p>void task_1(void *pvParameters)<br \/>\n{<\/p>\n<p>    while(1)<br \/>\n    {<\/p>\n<p>    }<br \/>\n}<\/p>\n<p>void task_2(void *pvParameters)<br \/>\n{<br \/>\n    while(1)<br \/>\n    {<\/p>\n<p>}<br \/>\n}<\/p>\n<p>\u6765\u5230start_task\u51fd\u6570&#xff0c;\u5728\u8fd9\u4e2a\u51fd\u6570\u8fd9\u91cc\u521b\u5efa\u4e8b\u4ef6\u6807\u5fd7\u7ec4&#xff0c;\u5728\u521b\u5efa\u4e4b\u524d\u5e94\u8be5\u5728\u6587\u4ef6\u5934\u5b9a\u4e49\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u7684\u53e5\u67c4&#xff1a;EventGroupHandle_t eventgroup_handle&#xff0c;\u968f\u540e\u5728start_task\u51fd\u6570\u8fd9\u91cc\u521b\u5efa\u4e8b\u4ef6\u6807\u5fd7\u7ec4&#xff0c;\u5177\u4f53\u4ee3\u7801\u5982\u4e0b&#xff1a;<\/p>\n<p>\/**<br \/>\n * &#064;brief \u542f\u52a8\u4efb\u52a1&#xff1a;\u521b\u5efa\u4e8b\u4ef6\u7ec4\u548c\u4e24\u4e2a\u5e94\u7528\u4efb\u52a1&#xff0c;\u7136\u540e\u5220\u9664\u81ea\u8eab<br \/>\n *\/<br \/>\nvoid Start_task(void *pvParameters)<br \/>\n{<br \/>\n    taskENTER_CRITICAL();<\/p>\n<p>    \/* \u521b\u5efa\u4e8b\u4ef6\u7ec4 *\/<br \/>\n    eventgroup_handle &#061; xEventGroupCreate();<br \/>\n    if (eventgroup_handle &#061;&#061; NULL)<br \/>\n    {<br \/>\n        Serial_Sendstring(&#034;event group create failed\\\\r\\\\n&#034;);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        Serial_Sendstring(&#034;event group create successful\\\\r\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    xTaskCreate((TaskFunction_t)task_1, &#034;task_1&#034;,<br \/>\n                TASK1_SIZE, NULL, TASK1_PRIO, &amp;task1_handle);<br \/>\n    xTaskCreate((TaskFunction_t)task_2, &#034;task_2&#034;,<br \/>\n                TASK2_SIZE, NULL, TASK2_PRIO, &amp;task2_handle);<\/p>\n<p>    taskEXIT_CRITICAL();<br \/>\n    vTaskDelete(NULL);<br \/>\n}<\/p>\n<p>\u968f\u540e\u6765\u5230task1&#xff0c;\u5728task1\u4e2d\u5e94\u8be5\u5b8c\u6210\u6309\u952e\u626b\u63cf&#xff0c;\u6d88\u6296\u540e\u5c06\u6309\u952e\u4e8b\u4ef6\u901a\u77e5\u7ed9\u4e8b\u4ef6\u7ec4&#xff0c;KEY1 (keynum &#061;&#061; 1) \u8bbe\u7f6e\u4f4d0 (0x01)&#xff0c;KEY2 (keynum &#061;&#061; 2) \u8bbe\u7f6e\u4f4d1 (0x02)&#xff0c;\u4e0b\u65b9\u662f\u5177\u4f53\u4ee3\u7801&#xff1a;<\/p>\n<p>\/**<br \/>\n * &#064;brief \u4efb\u52a11&#xff1a;\u6309\u952e\u626b\u63cf&#xff0c;\u6d88\u6296\u540e\u5c06\u6309\u952e\u4e8b\u4ef6\u901a\u77e5\u7ed9\u4e8b\u4ef6\u7ec4<br \/>\n *        &#8211; KEY1 (keynum &#061;&#061; 1) \u8bbe\u7f6e\u4f4d0 (0x01)<br \/>\n *        &#8211; KEY2 (keynum &#061;&#061; 2) \u8bbe\u7f6e\u4f4d1 (0x02)<br \/>\n *        \u5305\u542b\u5b8c\u6574\u7684\u4e0a\u5347\u6cbf\u6d88\u6296\u903b\u8f91&#xff0c;\u786e\u4fdd\u5355\u6b21\u6309\u952e\u53ea\u54cd\u5e94\u4e00\u6b21<br \/>\n *\/<br \/>\nvoid task_1(void *pvParameters)<br \/>\n{<br \/>\n    uint8_t keynum;<br \/>\n    uint8_t last_key &#061; 0;       \/\/ \u8bb0\u5f55\u4e0a\u4e00\u6b21\u7684\u6309\u952e\u72b6\u6001&#xff0c;\u68c0\u6d4b\u4e0a\u5347\u6cbf<\/p>\n<p>    while (1)<br \/>\n    {<br \/>\n        keynum &#061; Key_GetNum();  \/\/ \u8bfb\u53d6\u5f53\u524d\u6309\u952e\u503c<\/p>\n<p>        \/* \u6309\u952e\u6d88\u6296&#xff1a;\u4ec5\u5f53\u6309\u952e\u4ece\u672a\u6309\u4e0b\u53d8\u4e3a\u6309\u4e0b\u65f6&#xff08;\u4e0a\u5347\u6cbf&#xff09;\u624d\u5904\u7406 *\/<br \/>\n        if (keynum !&#061; 0 &amp;&amp; last_key &#061;&#061; 0)<br \/>\n        {<br \/>\n            vTaskDelay(30);                     \/\/ \u6d88\u6296\u5ef6\u65f6 30 ms<br \/>\n            if (Key_GetNum() &#061;&#061; keynum)         \/\/ \u518d\u6b21\u8bfb\u53d6\u786e\u8ba4\u6309\u952e\u4ecd\u6309\u4e0b<br \/>\n            {<br \/>\n                if (keynum &#061;&#061; 1)                \/\/ PB1 \u6309\u4e0b<br \/>\n                {<br \/>\n                    xEventGroupSetBits(eventgroup_handle, 0x01);<br \/>\n                    Serial_Sendstring(&#034;PB1 pressed, set bit 0\\\\r\\\\n&#034;);<br \/>\n                }<br \/>\n                else if (keynum &#061;&#061; 2)           \/\/ PB2 \u6309\u4e0b<br \/>\n                {<br \/>\n                    xEventGroupSetBits(eventgroup_handle, 0x02);<br \/>\n                    Serial_Sendstring(&#034;PB2 pressed, set bit 1\\\\r\\\\n&#034;);<br \/>\n                }<br \/>\n            }<br \/>\n        }<\/p>\n<p>        last_key &#061; keynum;      \/\/ \u66f4\u65b0\u4e0a\u4e00\u6b21\u72b6\u6001<br \/>\n        vTaskDelay(10);         \/\/ 10 ms \u626b\u63cf\u4e00\u6b21&#xff0c;\u964d\u4f4e CPU \u5360\u7528<br \/>\n    }<br \/>\n}<\/p>\n<p>\u968f\u540e\u6765\u5230task2&#xff0c;\u7b49\u5f85\u4e8b\u4ef6\u7ec4\u4e2d\u7684\u6240\u6709\u4e8b\u4ef6\u4f4d\u88ab\u8bbe\u7f6e&#xff0c;\u8bfb\u53d6\u540e\u6e05\u9664\u8be5\u4f4d&#xff0c;\u5e76\u6253\u5370\u5f53\u524d\u89e6\u53d1\u7684\u4e8b\u4ef6\u4f4d&#xff0c;\u4e0b\u65b9\u662ftask2\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>\/**<br \/>\n * &#064;brief \u4efb\u52a12&#xff1a;\u7b49\u5f85\u4e8b\u4ef6\u7ec4\u4e2d\u7684\u6240\u6709\u4e8b\u4ef6\u4f4d\u88ab\u8bbe\u7f6e&#xff0c;<br \/>\n *        \u8bfb\u53d6\u540e\u6e05\u9664\u8be5\u4f4d&#xff0c;\u5e76\u6253\u5370\u5f53\u524d\u89e6\u53d1\u7684\u4e8b\u4ef6\u4f4d<br \/>\n *\/<br \/>\nvoid task_2(void *pvParameters)<br \/>\n{<br \/>\n    EventBits_t event_bit &#061; 0;<\/p>\n<p>    while (1)<br \/>\n    {<br \/>\n        \/*<br \/>\n         * \u7b49\u5f85\u4e8b\u4ef6\u4f4d 0x01 \u548c 0x02 \u90fd\u88ab\u7f6e\u4e00<br \/>\n         * \u53c2\u6570\u8bf4\u660e&#xff1a;<br \/>\n         *   &#8211; \u7b2c\u4e09\u53c2\u6570 pdTRUE&#xff1a;\u51fd\u6570\u9000\u51fa\u65f6\u4f1a\u6e05\u9664\u89e6\u53d1\u7b49\u5f85\u7684\u90a3\u4e9b\u4f4d&#xff08;\u8fd9\u91cc\u662f0x01\u62160x02&#xff09;<br \/>\n         *   &#8211; \u7b2c\u56db\u53c2\u6570 pdTRUE&#xff1a;\u7b49\u5f85\u6240\u6709\u4f4d\u7f6e\u4e00<br \/>\n         *\/<br \/>\n        event_bit &#061; xEventGroupWaitBits(eventgroup_handle,<br \/>\n                                        0x01 | 0x02,   \/* \u611f\u5174\u8da3\u7684\u4e8b\u4ef6\u4f4d *\/<br \/>\n                                        pdTRUE,        \/* \u9000\u51fa\u65f6\u6e05\u9664\u8fd9\u4e9b\u4f4d *\/<br \/>\n                                        pdTRUE,       \/* \u7b49\u5f85\u6240\u6709\u4f4d *\/<br \/>\n                                        portMAX_DELAY);\/* \u6c38\u4e45\u963b\u585e\u7b49\u5f85 *\/<br \/>\n        \/*<br \/>\n         * event_bit \u8fd4\u56de\u503c\u662f\u6210\u529f\u8bfb\u53d6\u65f6\u6574\u4e2a\u4e8b\u4ef6\u7ec4\u7684\u5f53\u524d\u503c&#xff08;\u6e05\u9664\u524d&#xff09;&#xff0c;<br \/>\n         * \u4e0e\u7b49\u5f85\u6761\u4ef6\u5339\u914d\u7684\u4f4d\u4f1a\u88ab\u7f6e\u4f4d\u3002<br \/>\n         *\/<br \/>\n        Serial_Sendstring(&#034;Event triggered: &#034;);<br \/>\n        Serial_SendHex(event_bit);<br \/>\n        Serial_Sendstring(&#034;\\\\r\\\\n&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u4e0b\u65b9\u662f\u5b8c\u6574\u7684\u4ee3\u7801&#xff1a;<\/p>\n<p>#include &#034;stm32f10x.h&#034;<br \/>\n#include &#034;FreeRTOS.h&#034;<br \/>\n#include &#034;task.h&#034;<br \/>\n#include &#034;queue.h&#034;<br \/>\n#include &#034;led.h&#034;<br \/>\n#include &#034;key.h&#034;<br \/>\n#include &#034;serial.h&#034;<br \/>\n#include &#034;semphr.h&#034;<br \/>\n#include &#034;event_groups.h&#034;<\/p>\n<p>\/* \u4efb\u52a1\u53c2\u6570 *\/<br \/>\n#define START_TASK_SIZE  128<br \/>\n#define START_TASK_PRIO  1<br \/>\n#define TASK1_SIZE       256<br \/>\n#define TASK1_PRIO       3<br \/>\n#define TASK2_SIZE       256<br \/>\n#define TASK2_PRIO       2<\/p>\n<p>\/* \u4efb\u52a1\u53e5\u67c4 *\/<br \/>\nTaskHandle_t start_task_handle;<br \/>\nTaskHandle_t task1_handle;<br \/>\nTaskHandle_t task2_handle;<\/p>\n<p>\/* \u4e8b\u4ef6\u7ec4\u53e5\u67c4 *\/<br \/>\nEventGroupHandle_t eventgroup_handle;<\/p>\n<p>void Start_task(void *pvParameters);<br \/>\nvoid task_1(void *pvParameters);<br \/>\nvoid task_2(void *pvParameters);<\/p>\n<p>\/**<br \/>\n * &#064;brief \u7cfb\u7edf\u5165\u53e3&#xff0c;\u521b\u5efa\u542f\u52a8\u4efb\u52a1\u5e76\u5f00\u542f\u8c03\u5ea6\u5668<br \/>\n *\/<br \/>\nvoid FreeRTOS_Task(void)<br \/>\n{<br \/>\n    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);<br \/>\n    Key_Init();<br \/>\n    LED_Init();<br \/>\n    Serial_Init();<\/p>\n<p>    xTaskCreate((TaskFunction_t)Start_task, &#034;Start_task&#034;,<br \/>\n                START_TASK_SIZE, NULL, START_TASK_PRIO, &amp;start_task_handle);<br \/>\n    vTaskStartScheduler();<br \/>\n}<\/p>\n<p>\/**<br \/>\n * &#064;brief \u542f\u52a8\u4efb\u52a1&#xff1a;\u521b\u5efa\u4e8b\u4ef6\u7ec4\u548c\u4e24\u4e2a\u5e94\u7528\u4efb\u52a1&#xff0c;\u7136\u540e\u5220\u9664\u81ea\u8eab<br \/>\n *\/<br \/>\nvoid Start_task(void *pvParameters)<br \/>\n{<br \/>\n    taskENTER_CRITICAL();<\/p>\n<p>    \/* \u521b\u5efa\u4e8b\u4ef6\u7ec4 *\/<br \/>\n    eventgroup_handle &#061; xEventGroupCreate();<br \/>\n    if (eventgroup_handle &#061;&#061; NULL)<br \/>\n    {<br \/>\n        Serial_Sendstring(&#034;event group create failed\\\\r\\\\n&#034;);<br \/>\n    }<br \/>\n    else<br \/>\n    {<br \/>\n        Serial_Sendstring(&#034;event group create successful\\\\r\\\\n&#034;);<br \/>\n    }<\/p>\n<p>    xTaskCreate((TaskFunction_t)task_1, &#034;task_1&#034;,<br \/>\n                TASK1_SIZE, NULL, TASK1_PRIO, &amp;task1_handle);<br \/>\n    xTaskCreate((TaskFunction_t)task_2, &#034;task_2&#034;,<br \/>\n                TASK2_SIZE, NULL, TASK2_PRIO, &amp;task2_handle);<\/p>\n<p>    taskEXIT_CRITICAL();<br \/>\n    vTaskDelete(NULL);<br \/>\n}<\/p>\n<p>\/**<br \/>\n * &#064;brief \u4efb\u52a11&#xff1a;\u6309\u952e\u626b\u63cf&#xff0c;\u6d88\u6296\u540e\u5c06\u6309\u952e\u4e8b\u4ef6\u901a\u77e5\u7ed9\u4e8b\u4ef6\u7ec4<br \/>\n *        &#8211; KEY1 (keynum &#061;&#061; 1) \u8bbe\u7f6e\u4f4d0 (0x01)<br \/>\n *        &#8211; KEY2 (keynum &#061;&#061; 2) \u8bbe\u7f6e\u4f4d1 (0x02)<br \/>\n *        \u5305\u542b\u5b8c\u6574\u7684\u4e0a\u5347\u6cbf\u6d88\u6296\u903b\u8f91&#xff0c;\u786e\u4fdd\u5355\u6b21\u6309\u952e\u53ea\u54cd\u5e94\u4e00\u6b21<br \/>\n *\/<br \/>\nvoid task_1(void *pvParameters)<br \/>\n{<br \/>\n    uint8_t keynum;<br \/>\n    uint8_t last_key &#061; 0;       \/\/ \u8bb0\u5f55\u4e0a\u4e00\u6b21\u7684\u6309\u952e\u72b6\u6001&#xff0c;\u68c0\u6d4b\u4e0a\u5347\u6cbf<\/p>\n<p>    while (1)<br \/>\n    {<br \/>\n        keynum &#061; Key_GetNum();  \/\/ \u8bfb\u53d6\u5f53\u524d\u6309\u952e\u503c<\/p>\n<p>        \/* \u6309\u952e\u6d88\u6296&#xff1a;\u4ec5\u5f53\u6309\u952e\u4ece\u672a\u6309\u4e0b\u53d8\u4e3a\u6309\u4e0b\u65f6&#xff08;\u4e0a\u5347\u6cbf&#xff09;\u624d\u5904\u7406 *\/<br \/>\n        if (keynum !&#061; 0 &amp;&amp; last_key &#061;&#061; 0)<br \/>\n        {<br \/>\n            vTaskDelay(30);                     \/\/ \u6d88\u6296\u5ef6\u65f6 30 ms<br \/>\n            if (Key_GetNum() &#061;&#061; keynum)         \/\/ \u518d\u6b21\u8bfb\u53d6\u786e\u8ba4\u6309\u952e\u4ecd\u6309\u4e0b<br \/>\n            {<br \/>\n                if (keynum &#061;&#061; 1)                \/\/ PB1 \u6309\u4e0b<br \/>\n                {<br \/>\n                    xEventGroupSetBits(eventgroup_handle, 0x01);<br \/>\n                    Serial_Sendstring(&#034;PB1 pressed, set bit 0\\\\r\\\\n&#034;);<br \/>\n                }<br \/>\n                else if (keynum &#061;&#061; 2)           \/\/ PB2 \u6309\u4e0b<br \/>\n                {<br \/>\n                    xEventGroupSetBits(eventgroup_handle, 0x02);<br \/>\n                    Serial_Sendstring(&#034;PB2 pressed, set bit 1\\\\r\\\\n&#034;);<br \/>\n                }<br \/>\n            }<br \/>\n        }<\/p>\n<p>        last_key &#061; keynum;      \/\/ \u66f4\u65b0\u4e0a\u4e00\u6b21\u72b6\u6001<br \/>\n        vTaskDelay(10);         \/\/ 10 ms \u626b\u63cf\u4e00\u6b21&#xff0c;\u964d\u4f4e CPU \u5360\u7528<br \/>\n    }<br \/>\n}<\/p>\n<p>\/**<br \/>\n * &#064;brief \u4efb\u52a12&#xff1a;\u7b49\u5f85\u4e8b\u4ef6\u7ec4\u4e2d\u7684\u6240\u6709\u4e8b\u4ef6\u4f4d\u88ab\u8bbe\u7f6e&#xff0c;<br \/>\n *        \u8bfb\u53d6\u540e\u6e05\u9664\u8be5\u4f4d&#xff0c;\u5e76\u6253\u5370\u5f53\u524d\u89e6\u53d1\u7684\u4e8b\u4ef6\u4f4d<br \/>\n *\/<br \/>\nvoid task_2(void *pvParameters)<br \/>\n{<br \/>\n    EventBits_t event_bit &#061; 0;<\/p>\n<p>    while (1)<br \/>\n    {<br \/>\n        \/*<br \/>\n         * \u7b49\u5f85\u4e8b\u4ef6\u4f4d 0x01 \u548c 0x02 \u90fd\u88ab\u7f6e\u4e00<br \/>\n         * \u53c2\u6570\u8bf4\u660e&#xff1a;<br \/>\n         *   &#8211; \u7b2c\u4e09\u53c2\u6570 pdTRUE&#xff1a;\u51fd\u6570\u9000\u51fa\u65f6\u4f1a\u6e05\u9664\u89e6\u53d1\u7b49\u5f85\u7684\u90a3\u4e9b\u4f4d&#xff08;\u8fd9\u91cc\u662f0x01\u62160x02&#xff09;<br \/>\n         *   &#8211; \u7b2c\u56db\u53c2\u6570 pdTRUE&#xff1a;\u7b49\u5f85\u6240\u6709\u4f4d\u7f6e\u4e00<br \/>\n         *\/<br \/>\n        event_bit &#061; xEventGroupWaitBits(eventgroup_handle,<br \/>\n                                        0x01 | 0x02,   \/* \u611f\u5174\u8da3\u7684\u4e8b\u4ef6\u4f4d *\/<br \/>\n                                        pdTRUE,        \/* \u9000\u51fa\u65f6\u6e05\u9664\u8fd9\u4e9b\u4f4d *\/<br \/>\n                                        pdTRUE,       \/* \u7b49\u5f85\u6240\u6709\u4f4d *\/<br \/>\n                                        portMAX_DELAY);\/* \u6c38\u4e45\u963b\u585e\u7b49\u5f85 *\/<br \/>\n        \/*<br \/>\n         * event_bit \u8fd4\u56de\u503c\u662f\u6210\u529f\u8bfb\u53d6\u65f6\u6574\u4e2a\u4e8b\u4ef6\u7ec4\u7684\u5f53\u524d\u503c&#xff08;\u6e05\u9664\u524d&#xff09;&#xff0c;<br \/>\n         * \u4e0e\u7b49\u5f85\u6761\u4ef6\u5339\u914d\u7684\u4f4d\u4f1a\u88ab\u7f6e\u4f4d\u3002<br \/>\n         *\/<br \/>\n        Serial_Sendstring(&#034;Event triggered: &#034;);<br \/>\n        Serial_SendHex(event_bit);<br \/>\n        Serial_Sendstring(&#034;\\\\r\\\\n&#034;);<br \/>\n    }<br \/>\n}<\/p>\n<p>\u82e5\u6709\u9519\u8bef&#xff0c;\u8fd8\u671b\u6d77\u6db5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u9a8c\u73b0\u8c61\u5b9e\u9a8c\u6b65\u9aa4&#xff1a;\u5b9e\u9a8c\u73b0\u8c61&#xff1a;\u9879\u76ee\u521b\u5efa\u590d\u5236Freertos_\u4e8c\u503c\u4fe1\u53f7\u91cf\u5b9e\u9a8c\u6587\u4ef6&#xff0c;\u7c98\u8d34\u5e76\u4e14\u91cd\u547d\u540d\u4e3aFreertos_\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c&#xff0c;\u8fdb\u5165keil&#xff0c;\u5220\u9664\u65e0\u5173\u9879&#xff0c;\u5305\u62ec\u4e8c\u503c\u4fe1\u53f7\u91cf\u7684\u521b\u5efa&#xff0c;task1\u548ctask2\u4e2d\u7684\u64cd\u4f5c&#xff0c;\u5728\u6587\u4ef6\u5934\u4e0a\u52a0\u4e0a#include \\&#8221;event_groups.h\\&#8221;&#xff0c;\u5c06task1\u4e0etask2\u7684\u4efb\u52a1\u4f18\u5148\u7ea7\u4e92\u6362&#xff0c;\u4e0b\u65b9\u662f\u5220\u9664\u5b8c\u540e\u7684\u4ee3\u7801&amp;#<\/p>\n","protected":false},"author":2,"featured_media":89966,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[217],"topic":[],"class_list":["post-89968","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-stm32"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/89968.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5b9e\u9a8c\u73b0\u8c61\u5b9e\u9a8c\u6b65\u9aa4&#xff1a;\u5b9e\u9a8c\u73b0\u8c61&#xff1a;\u9879\u76ee\u521b\u5efa\u590d\u5236Freertos_\u4e8c\u503c\u4fe1\u53f7\u91cf\u5b9e\u9a8c\u6587\u4ef6&#xff0c;\u7c98\u8d34\u5e76\u4e14\u91cd\u547d\u540d\u4e3aFreertos_\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c&#xff0c;\u8fdb\u5165keil&#xff0c;\u5220\u9664\u65e0\u5173\u9879&#xff0c;\u5305\u62ec\u4e8c\u503c\u4fe1\u53f7\u91cf\u7684\u521b\u5efa&#xff0c;task1\u548ctask2\u4e2d\u7684\u64cd\u4f5c&#xff0c;\u5728\u6587\u4ef6\u5934\u4e0a\u52a0\u4e0a#include &quot;event_groups.h&quot;&#xff0c;\u5c06task1\u4e0etask2\u7684\u4efb\u52a1\u4f18\u5148\u7ea7\u4e92\u6362&#xff0c;\u4e0b\u65b9\u662f\u5220\u9664\u5b8c\u540e\u7684\u4ee3\u7801&amp;#\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/89968.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-04T03:24:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260804032436-6a715b74bd251.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89968.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/89968.html\",\"name\":\"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-04T03:24:38+00:00\",\"dateModified\":\"2026-08-04T03:24:38+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/89968.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/89968.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/89968.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/89968.html","og_locale":"zh_CN","og_type":"article","og_title":"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5b9e\u9a8c\u73b0\u8c61\u5b9e\u9a8c\u6b65\u9aa4&#xff1a;\u5b9e\u9a8c\u73b0\u8c61&#xff1a;\u9879\u76ee\u521b\u5efa\u590d\u5236Freertos_\u4e8c\u503c\u4fe1\u53f7\u91cf\u5b9e\u9a8c\u6587\u4ef6&#xff0c;\u7c98\u8d34\u5e76\u4e14\u91cd\u547d\u540d\u4e3aFreertos_\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c&#xff0c;\u8fdb\u5165keil&#xff0c;\u5220\u9664\u65e0\u5173\u9879&#xff0c;\u5305\u62ec\u4e8c\u503c\u4fe1\u53f7\u91cf\u7684\u521b\u5efa&#xff0c;task1\u548ctask2\u4e2d\u7684\u64cd\u4f5c&#xff0c;\u5728\u6587\u4ef6\u5934\u4e0a\u52a0\u4e0a#include \"event_groups.h\"&#xff0c;\u5c06task1\u4e0etask2\u7684\u4efb\u52a1\u4f18\u5148\u7ea7\u4e92\u6362&#xff0c;\u4e0b\u65b9\u662f\u5220\u9664\u5b8c\u540e\u7684\u4ee3\u7801&amp;#","og_url":"https:\/\/www.wsisp.com\/helps\/89968.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-04T03:24:38+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2026\/08\/20260804032436-6a715b74bd251.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/89968.html","url":"https:\/\/www.wsisp.com\/helps\/89968.html","name":"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-04T03:24:38+00:00","dateModified":"2026-08-04T03:24:38+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/89968.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/89968.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/89968.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"FreeRTOS\uff0812\uff09\uff1a\u4e8b\u4ef6\u6807\u5fd7\u7ec4\u5b9e\u9a8c"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89968","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=89968"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/89968\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/89966"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=89968"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=89968"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=89968"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=89968"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}