21
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

M5Stackでマルチタスク処理を実行する

Last updated at Posted at 2018-06-16

###目的
M5stackはCPU:ESP32を内臓しており、マルチタスク処理に対応している。
M5stackでマルチタスク処理を行う。

###方法
xTaskCreatePinnedToCore()関数を使うことで実装できる。

xTaskCreatePinnedToCore(タスクの関数名,"タスク名",スタックメモリサイズ,NULL,タスク優先順位,
タスクハンドルポインタ,Core ID);

###サンプルソース

#include <M5Stack.h>
void task0(void* arg) {
  int cnt = 0;
  while (1) {
    printf("task2 thread_cnt=%ld\n", cnt++);
    delay(1000);
  }
}
void task1(void* arg) {
  int cnt = 0;
  while (1) {
    printf("task1 thread_cnt=%ld\n", cnt++);
    delay(1500);
  }
}

void setup() {
  Serial.begin(115200);
  xTaskCreatePinnedToCore(task0, "Task0", 4096, NULL, 1, NULL, 0);
  xTaskCreatePinnedToCore(task1, "Task1", 4096, NULL, 1, NULL, 1);
}

void loop() {
  static int cnt = 0;
  printf("Maintask thread_cnt=%ld\n", cnt++);
  delay(1200);
}


実行画面
Screenshot from 2018-06-16 13:08:13.png

###参考:
Docs » API Reference » System API » FreeRTOS
http://esp-idf.readthedocs.io/en/latest/api-reference/system/freertos.html

-ESP32でデュアルコアを使おう!
https://kerikeri.top/posts/2017-06-24-esp32-dual-core/

-マルチタスク・デュアルコアの実験(ESP-WROOM-32)
https://garretlab.web.fc2.com/arduino/lab/esp32_task/index.html

21
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?