Event group

Using an event group static EventGroupHandle_t tcpserver_event_group; //Create it tcpserver_event_group = xEventGroupCreate(); //Set the state when say a connection happens or is lost xEventGroupSetBits(tcpserver_event_group, CONNECTED_BIT); xEventGroupClearBits(tcpserver_event_group, CONNECTED_BIT); //Wait for connected xEventGroupWaitBits(tcpserver_event_group, CONNECTED_BIT, false, true, portMAX_DELAY); //Stalls (with timeout)      

Read More

Event handler

You can subscribe to be notified of ESP events using this In your initialise ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); Event handler fucntion //*************************************** //*************************************** //********** ESP EVENT HANDLER ********** //*************************************** //*************************************** //Call this at startup: //ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) ); static esp_err_t event_handler(void *ctx, system_event_t *event) { switch(event->event_id) { case SYSTEM_EVENT_STA_START: //WiFi connected break; case SYSTEM_EVENT_STA_GOT_IP: //WiFi […]

Read More

FreeRTOS Tick Rate

Defaint is 100Hz / 10mS You can change it with make menuconfig: Component config > FreeRTOS > Tick Rate (Hz) Whacking it all the way up to 1000 will cause some things to be affected as the scheduler has less time to deal with calling different tasks.  

Read More

Priority

Priority Each task is assigned a priority from 0 to (configMAX_PRIORITIES – 1 ), (configMAX_PRIORITIES is defined  in FreeRTOSConfig.h). Low priority numbers denote low priority tasks. The idle task has priority zero (tskIDLE_PRIORITY). The task placed into the Running state by the scheduler is always the highest priority task that is able to run – higher priority tasks […]

Read More

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