Co-routines

Co-routines are rarely used these days and there are no plans to develop them further in FreeRTOS

Read More

.Tasks general

The basics ESP-IDF uses FreeRTOS and this is a “tasks” based Operating System. The FreeRTOS default tick rate is 100Hz (you can configure this, but 100 is a good tradeoff between ISR overhead and responsiveness). This means portTICK_PERIOD_MS is 10 (10ms per tick). If you use a vTaskDelay < 10mS, it is effectively a 0 […]

Read More

Semaphores

Semaphores are typically used for both synchronization and mutual exclusion in access to resources. Semaphore example #include "semphr.h" //Create semphore SemaphoreHandle_t SemaphoreHandle1 = NULL; SemaphoreHandle1 = xSemaphoreCreateMutex(); //Use sempahore xSemaphoreTake(SemaphoreHandle1, portMAX_DELAY); //Do something… xSemaphoreGive(SemaphoreHandle1);  

Read More

Background Timers

Get time in uS since powerup int64_t esp_timer_get_time() esp_timer_get_time() returns 64-bit time since startup, in microseconds. int64 = 292,471 years before overflow at uS resolution! Unlike gettimeofday function, values returned by esp_timer_get_time() start from zero after startup of the chip wakes up from deep sleep and do not have timezone or DST adjustments applied.    

Read More

Hardware Timers

ESP32 has 4 individual hardware timers, arranged as 2 timers x 2 timer groups. All 4 are 64-bit generic timers based on 16-bit prescalers and 64-bit auto-reload-capable up / down counters. Resources https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/timer.html CMakeLists.txt REQUIRES Ensure the following is added to the REQUIRES section of your CMakeLists.txt file in the \main folder: Example using Timer […]

Read More

.Interrupts General

What can you do in interrupts In ISR functions you can do only simple thing, not time consuming operations. Disable interrupts You can suspend interrupts and context switches by calling  portDISABLE_INTERRUPTS and the interrupts on that core should stop firing, stopping task switches as well. Call portENABLE_INTERRUPTS after you're done

Read More

Creating tasks

TaskScheduler vTaskStartScheduler(); //<<<This FreeRTOS call is not required as the scheduler is already started before app_main() call Create New xTask Tasks should never return (i.e. be a continuous loop). xTaskCreate( [pointer to the function which will execute when the task is scheduled to run], [descriptive name for the the task, up to 16 chars, mainly […]

Read More