When creating 3 tasks:
- void vReceiveTask(void *pvParameters)
- void vTransmitTask(void *pvParameters)
- void vEmulateLoad(void *pvParameters)
- static QueueHandle_t xControlQueue = NULL;
- static TaskHandle_t xReceiveTask = NULL, xTransmitTask = NULL;
- static TaskHandle_t xEmulateLoad = NULL;
- typedef struct {
- void *data;
- uint32_t data_len;
- } message;
- void vEmulateLoad(void *pvParameters) {
- message msg;
- /*SIMPLE DATA GENERATION*/
- srand(time(NULL));
- uint32_t arr_size = (uint32_t)pow(2, PACKETS_UNIQUE_NUM);
- uint8_t arr[arr_size];
- for (uint8_t i = 0; i < arr_size; ++i) {
- arr[i] = (uint8_t)rand();
- }
- msg.data = (void *)arr;
- msg.data_len = sizeof(arr);
- for (;;) {
- if (xQueueSend(xControlQueue, &msg, pdMS_TO_TICKS(100)) != pdTRUE)
- ESP_LOGE(TAG, "[FreeRTOS] xControlQueue: FULL");
- else
- ESP_LOGI(TAG, "[FreeRTOS] xControlQueue: Item added");
- vTaskDelay(pdMS_TO_TICKS(1000));
- }
- vTaskDelete(NULL);
- }
- void app_main(void){
- BaseType_t xReturned __attribute__((unused));
- // Initialize xControlQueue
- xControlQueue = xQueueCreate(QUEUE_SIZE, sizeof(message));
- assert(xControlQueue && "[FreeRTOS] Failed to create xControlQueue");
- ESP_LOGI(TAG, "[FreeRTOS] xControlQueue is set");
- // Initialize task emulating the load
- xReturned = xTaskCreatePinnedToCore(vEmulateLoad, "xEmulateLoad", 4096, NULL,
- (tskIDLE_PRIORITY + 1), &xEmulateLoad, 0);
- assert(xReturned == pdPASS && "[FreeRTOS] Failed to create xEmulateLoad");
- ESP_LOGI(TAG, "[FreeRTOS] xEmulateLoad is set");
- // Initialize RX Task
- xReturned = xTaskCreatePinnedToCore(vReceiveTask, "xReceiveTask", 4096, NULL,
- (tskIDLE_PRIORITY + 1), &xReceiveTask, 1);
- assert(xReturned == pdPASS && "[FreeRTOS] Failed to create xReceiveTask");
- ESP_LOGI(TAG, "[FreeRTOS] xReceiveTask is set");
- // Initialize TX Task
- xReturned =
- xTaskCreatePinnedToCore(vTransmitTask, "xTransmitTask", 4096, NULL,
- (tskIDLE_PRIORITY + 1), &xTransmitTask, 1);
- assert(xReturned == pdPASS && "[FreeRTOS] Failed to create xTransmitTask");
- ESP_LOGI(TAG, "[FreeRTOS] xTransmitTask is set");
- printf("Core %d: xReceiveTask\n", xTaskGetCoreID(xReceiveTask));
- printf("Core %d: xTransmitTask\n", xTaskGetCoreID(xTransmitTask));
- printf("Core %d: xEmulateLoad\n", xTaskGetCoreID(xEmulateLoad));
- }
Regarding 2 other tasks: I can't share their code but I can say that they're responsible for half-duplex radiocommunication and both of them go to the blocked state after creation:
- vReceiveTask() is in Blocked state until a Notification comes from ISR
- vTransmitTask() is in Blocked state until a Notification comes from vReceiveTask()
Any suggestions where I could make a mistake?