{"id":1807,"date":"2023-04-08T21:13:16","date_gmt":"2023-04-08T12:13:16","guid":{"rendered":"https:\/\/deanzasystems.jp\/?p=1807"},"modified":"2023-04-08T21:17:14","modified_gmt":"2023-04-08T12:17:14","slug":"esp32-freertos-criticalsection%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6","status":"publish","type":"post","link":"https:\/\/deanzasystems.jp\/?p=1807","title":{"rendered":"ESP32 FreeRTOS CriticalSection\u306b\u3064\u3044\u3066"},"content":{"rendered":"\n<p class=\"has-regular-font-size wp-block-paragraph\">ESP32 \u306a\u3089Arduino\u3092\u4f7f\u3063\u3066\u3044\u308b\u65b9\u304c\u591a\u3044\u3068\u601d\u3046\u3002FreeRTOS\u3092\u3064\u304b\u3063\u3066\u3044\u308b\u3068\u5e7e\u5ea6\u3068\u306a\u304f\u3001\u3053\u3053\u3067\u30bf\u30b9\u30af\u306e\u30c7\u30a3\u30b9\u30d1\u30c3\u30c1\u304c\u767a\u751f\u3057\u3066\u6b32\u3057\u304f\u306a\u3044\u306a\u3042\u3001\u3068\u601d\u3046\u3053\u3068\u304c\u3042\u308b\u306f\u305a\u3002<\/p>\n\n\n\n<p class=\"has-regular-font-size wp-block-paragraph\">\u3067\u3001\u7c21\u5358\u306b\u601d\u3044\u3064\u304f\u306e\u304c\u5272\u308a\u8fbc\u307f\u7981\u6b62\uff01<\/p>\n\n\n\n<p class=\"has-regular-font-size wp-block-paragraph\">Disable Interrupt \u7684\u306aC\u3067\u3042\u308cC++\u3067\u3042\u308c\u30a2\u30bb\u30f3\u30d6\u30ea\u3067\u3042\u308c\u3001\u3048\u3048\u3044\u6b62\u3081\u3061\u3083\u3048\u3001\u3063\u3066\u65b9\u6cd5\u3067\u3059\u306d\u3002\u3053\u308c\u3092FreeRTOS\u3067\u5b9f\u73fe\u3059\u308b\u306b\u306f\u30fb\u30fb\u30fb<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">portENTER_CRITICAL(mux)\nportEXIT_CRITICAL(mux)\n\n\u304c\u51fa\u3066\u304d\u307e\u3059\u3002\n\u8abf\u3079\u3066\u307f\u308b\u3068\u3001\u30de\u30af\u30ed\u3067\n\n#define taskENTER_CRITICAL(mux)  portENTER_CRITICAL(mux)\r\n#define taskEXIT_CRITICAL(mux)  portEXIT_CRITICAL(mux)\r\n#define taskENTER_CRITICAL_ISR(mux)  portENTER_CRITICAL_ISR(mux)\r\n#define taskEXIT_CRITICAL_ISR(mux)  portEXIT_CRITICAL_ISR(mux)\n\n\u3068\u306a\u3063\u3066\u3044\u3066\u3001FreeRTOS\u7684\u306a\u65b9\u8a00\u306e\u3088\u3046\u3067\u3059\u306d\u3002\n\n\u30cd\u30c3\u30c8\u3067\u591a\u304f\u8aac\u660e\u3067\u4f7f\u308f\u308c\u3066\u3044\u308b\u306e\u306f\u3001 Serial.print() \u3092 \u30af\u30ea\u30c6\u30a3\u30ab\u30eb\u30bb\u30af\u30b7\u30e7\u30f3\u3067\u631f\u307f\u8fbc\u3080\u4f8b\u984c\u3002\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u3002\n\nportMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;\ntaskENTER_CRITICAL( &amp;mux ) ;\r\nSerial.println( \"Task1 \u207b Hel\" );\nSerial.println( \"lo world.\" );\ntaskEXIT_CRITICAL( &amp;mux );\n\n\u3067 \"Hello world.\" \u304c\u9014\u4e2d\u3067\u9014\u5207\u308c\u306a\u3044\u3053\u3068\u3092\u78ba\u8a8d\u3059\u308b\u3088\u3046\u306a\u3082\u306e\u3002\n\u3067\u3082\u305d\u3082\u305d\u3082print\u6587\u306fprintf \u7a0b\u3067\u306f\u306a\u3044\u306b\u3057\u3066\u3082\u5927\u304d\u306a\u95a2\u6570\u306a\u306e\u3067\u5b9f\u884c\u6642\u9593\u3082\u9577\u3044\u3002\n\u306a\u306e\u3067\u3001\u9577\u3044\u6587\u5b57\u5217\u3084\u8fbc\u307f\u5165\u3063\u305f\u6642\u9593\u306e\u304b\u304b\u308b\u51e6\u7406\u3092taskENTER_CRITICAL( &amp;mux ) ;\u3067\u631f\u3080\u3068 Gru panic \u3092\u8d77\u3053\u3057\u3066ESP32\u304c\u30ea\u30bb\u30c3\u30c8\u3057\u3066\u3057\u307e\u3046\u3053\u3068\u304c\u3042\u308b\u3002\n\u3064\u307e\u308a\u30c7\u30a3\u30b9\u30d1\u30c3\u30c1\u7981\u6b62\u3068\u3044\u3046\u3088\u308a\u3001FreeRTOS\u5916\u3067CPU\u305d\u306e\u3082\u306e\u306e\u5272\u308a\u8fbc\u307f\u304c\u7981\u6b62\u3055\u308c\u3066\u3057\u307e\u3063\u3066\u3044\u308b\u3088\u3046\u306b\u898b\u3048\u308b\u3002\n\u3044\u3065\u308c\u306b\u3057\u3066\u3082\u3001\u30b5\u30f3\u30d7\u30eb\u3068\u3057\u3066\u306f\u5206\u304b\u308a\u3084\u3059\u304f\u3066\u826f\u3044\u306e\u3060\u304c\u3001\u5b9f\u969b\u306e\u30b3\u30fc\u30c9\u3067\u306fprint\u6587\u3067\u4f7f\u3046\u306e\u306f\u8ce2\u660e\u3067\u306f\u306a\u3044\u3088\u3046\u306b\u601d\u3048\u308b\u3002\n\u30c7\u30d0\u30c3\u30b0\u306b\u3057\u3066\u3082\u3001\u4ed6\u306e\u6a5f\u5668\u3068\u306e\u901a\u4fe1\u3067\u3042\u308c\u3001print out\u3057\u305f\u3044\u3068\u304d\u306f\u3001\u4e00\u3064\u306e\u30bf\u30b9\u30af\u306b\u4e00\u3064\u306e\u51fa\u529b\u5148\u3092\u30a2\u30b5\u30a4\u30f3\u3057\u3066\u3001\u30c7\u30d0\u30a4\u30b9\u30ec\u30d9\u30eb\u3067\u6392\u4ed6\u51e6\u7406\u3057\u306a\u304f\u3066\u3082\u3001\u5909\u6570\u3078\u306e\u66f8\u304d\u8fbc\u307f\u3060\u3051\u6392\u4ed6\u51e6\u7406\u3055\u308c\u3066\u3044\u308c\u3070\u3001\u7a7a\u304d\u6642\u9593\u306b\u5916\u90e8\u30c7\u30d0\u30a4\u30b9\u3078\u968f\u6642 print \u3057\u3066\u3044\u304f\u3088\u3046\u306a\u69cb\u6210\u306b\u3057\u305f\u65b9\u304c\u7cbe\u795e\u885b\u751f\u4e0a\u3082\u3088\u3055\u305d\u3046\u3060\u3002\n\n\n volatile  uint64_t  val;\n\n taskENTER_CRITICAL( &amp;mux );\r\n val |= 0xff00;\r\n taskEXIT_CRITICAL( &amp;mux );\n\nvolatile \u306e\u5909\u6570\u3092\u89e6\u308b\u3068\u304d\u306f\u9006\u306b\u7d76\u5bfe\u306b\u5b88\u3089\u306a\u3044\u3068\u884c\u3051\u306a\u3044\u5834\u5408\u304c\u591a\u3044\u3068\u601d\u3046\u3057\u3001\u3053\u3053\u3053\u305d\u4f7f\u3046\u5834\u6240\u304b\u3068\u601d\u3046\u3002\n\n\n\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ESP32 \u306a\u3089Arduino\u3092\u4f7f\u3063\u3066\u3044\u308b\u65b9\u304c\u591a\u3044\u3068\u601d\u3046\u3002FreeRTOS\u3092\u3064\u304b\u3063\u3066\u3044\u308b\u3068\u5e7e\u5ea6\u3068\u306a\u304f\u3001\u3053\u3053\u3067\u30bf\u30b9\u30af\u306e\u30c7\u30a3\u30b9\u30d1\u30c3\u30c1\u304c\u767a\u751f\u3057\u3066\u6b32\u3057\u304f\u306a\u3044\u306a\u3042\u3001\u3068\u601d\u3046\u3053\u3068\u304c\u3042\u308b\u306f\u305a\u3002 \u3067\u3001\u7c21\u5358\u306b\u601d\u3044\u3064\u304f\u306e\u304c\u5272\u308a\u8fbc\u307f\u7981\u6b62\uff01 Di [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1809,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[5],"tags":[],"class_list":["post-1807","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-embedded"],"_links":{"self":[{"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/posts\/1807","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1807"}],"version-history":[{"count":2,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/posts\/1807\/revisions"}],"predecessor-version":[{"id":1810,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/posts\/1807\/revisions\/1810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=\/wp\/v2\/media\/1809"}],"wp:attachment":[{"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1807"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1807"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/deanzasystems.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1807"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}