In the MRE below, the Consumer Task has a higher priority than the Producer Task. So, when the Producer sets the Event Group bit, I would expect the Consumer Task to preempt it, do its printing, and then block itself again BEFORE the (lower priority) Producer Task resumes executing. Therefore, it seems that the printing sequence should be:
Code: Select all
[338536][I][sketch_aug28a.ino:24] producerFunction(): Producer Function: Setting Event Bits
[338537][I][sketch_aug28a.ino:34] consumerFunction(): Consumer Task Received Event Bit
[338536][I][sketch_aug28a.ino:26] producerFunction(): Producer Function: Event Bits Set
Code: Select all
[338536][I][sketch_aug28a.ino:24] producerFunction(): Producer Function: Setting Event Bits
[338536][I][sketch_aug28a.ino:26] producerFunction(): Producer Function: Event Bits Set
[338537][I][sketch_aug28a.ino:34] consumerFunction(): Consumer Task Received Event Bit
Thanks.
Code:
Code: Select all
#include "Arduino.h"
void producerFunction(void *pvParameters);
void consumerFunction(void *pvParameters);
EventGroupHandle_t controlGroupHandle;
void setup() {
Serial.begin(115200);
vTaskDelay(2000);
log_i("Starting");
controlGroupHandle = xEventGroupCreate();
xTaskCreatePinnedToCore(consumerFunction, "Consumer Task 1", 2000, NULL, 6, NULL, CONFIG_ARDUINO_RUNNING_CORE);
vTaskDelay(500);
xTaskCreatePinnedToCore(producerFunction, "Producer Task", 2000, NULL, 2, NULL, CONFIG_ARDUINO_RUNNING_CORE);
}
void producerFunction(void *pvParameters) {
log_i("Producer Task Started\n");
for (;;) {
vTaskDelay(2000);
log_i("Producer Function: Setting Event Bits");
xEventGroupSetBits(controlGroupHandle, 1);
log_i("Producer Function: Event Bits Set");
}
}
void consumerFunction(void *pvParameters) {
log_i("Consumer Task Started");
for (;;) {
xEventGroupWaitBits(controlGroupHandle, 1, pdTRUE, pdFALSE, portMAX_DELAY);
log_i("Consumer Task Received Event Bit");
}
}
void loop() {
}