// You'll likely need this in vanilla FreeRTOS
//#include timers.h
// only use core 1 for this demo
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
// Globals
static TimerHandle_t one_shot_timer = NULL;
TaskHandle_t task_handler;
// Called when one of the timers expires
void myTimerCallback(TimerHandle_t xTimer)
{
Serial.println("Timer called");
Serial.println("Sending Task1 to suspend state");
vTaskSuspend(task_handler);
}
void printMessage(void *params)
{
while(1)
{
Serial.println("Hello there!");
vTaskDelay(pdMS_TO_TICKS(500));
}
}
void setup()
{
// Configure Serial
Serial.begin(9600);
vTaskDelay(pdMS_TO_TICKS(1000));
BaseType_t status;
//task1 (print messages to serial monitor)
status = xTaskCreatePinnedToCore(printMessage,
"Print Message",
1024, // This is stack size in words, in bytes for a 32bit miccrocontroller each word is 4 bytes. so 1024*4 = 4096 bytes
NULL, // No parameters passed
1, // Priority
&task_handler,
app_cpu
);
if (status != pdTRUE)
{
Serial.println("Error Task1 creation failed");
}
one_shot_timer = xTimerCreate(
"One-shot timer", // Name of timer
5000 / portTICK_PERIOD_MS, // Period of timer (in ticks)
pdFALSE, // Auto-reload
(void *)0, // Timer ID
myTimerCallback); // Callback function
if (one_shot_timer == NULL)
{
Serial.println("Error timer creation failed");
}
xTimerStart(one_shot_timer, portMAX_DELAY);
Serial.println("Timer Called");
// Delete self task to show the timers will work with no user tasks
vTaskDelete(NULL);
}
void loop()
{
}
esp:0
esp:2
esp:4
esp:5
esp:12
esp:13
esp:14
esp:15
esp:16
esp:17
esp:18
esp:19
esp:21
esp:22
esp:23
esp:25
esp:26
esp:27
esp:32
esp:33
esp:34
esp:35
esp:3V3
esp:EN
esp:VP
esp:VN
esp:GND.1
esp:D2
esp:D3
esp:CMD
esp:5V
esp:GND.2
esp:TX
esp:RX
esp:GND.3
esp:D1
esp:D0
esp:CLK