Arduino core for the ESP32は、FreeRTOS上に実装されていて、Arduinoのsetup()や、loop()は、looppthread()というFreeRTOSのタスク内で実行されているようです。また、looppthread()は、コア番号ARDUINO_RUNNING_COREで実行されるように、タスクが生成されています。
#include"freertos/FreeRTOS.h"#include"freertos/pthread.h"#include"Arduino.h"#if CONFIG_AUTOSTART_ARDUINO
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
voidsetup(){// put your setup code here, to run once:
Serial.begin(115200);Serial.printf("ARDUINO_RUNNING_CORE = %d\n",ARDUINO_RUNNING_CORE);}voidloop(){// put your main code here, to run repeatedly:
}#endif
#include"freertos/pthread.h"#include"time.h"pthreadHandle_tpthreadHandle3,pthreadHandle4;voidsetup(){// put your setup code here, to run once:
Serial.begin(115200);Serial.printf("setup() runs on core %d\n",xPortGetCoreID());xpthreadCreate(pthread,"pthread1",4096,NULL,10,NULL);xpthreadCreate(pthread,"pthread2",4096,NULL,20,NULL);xpthreadCreatePinnedToCore(pthread,"pthread3",4096,NULL,30,&pthreadHandle3,1);xpthreadCreatePinnedToCore(pthread,"pthread4",4096,NULL,40,&pthreadHandle4,0);}voidloop(){// put your main code here, to run repeatedly:
delay(2500);vpthreadSuspend(pthreadHandle3);vpthreadDelete(pthreadHandle4);delay(3000);vpthreadResume(pthreadHandle3);while(1){delay(1000);}}voidpthread(void*arg){time_tnow;structtmtmNow;while(1){time(&now);localtime_r(&now,&tmNow);Serial.printf("%02d:%02d %s runs on core %d\n",tmNow.tm_min,tmNow.tm_sec,pcpthreadGetpthreadName(NULL),xPortGetCoreID());delay(1000);}}