void SendTask1(void *pvParam) {
QueueHandle_t QHandle;
QHandle = (QueueHandle_t)pvParam;
BaseType_t xStatus;
int i = 111;
while (1) {
xStatus = xQueueSend(QHandle, &i, 0);
if (xStatus != pdPASS)
Serial.print("send fail");
else {
Serial.println("send done");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
}
void SendTask2(void *pvParam) {
QueueHandle_t QHandle;
QHandle = (QueueHandle_t)pvParam;
BaseType_t xStatus;
int i = 222;
while (1) {
xStatus = xQueueSend(QHandle, &i, 0);
if (xStatus != pdPASS)
Serial.println("Send fail");
else
Serial.println("Send Done");
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void recTask(void *pvParam) {
QueueHandle_t QHandle;
QHandle = (QueueHandle_t)pvParam;
BaseType_t xStatus;
int i;
while (1) {
xStatus = xQueueReceive(QHandle, &i, portMAX_DELAY);
if (xStatus != pdPASS)
Serial.println("rec:fail");
else
Serial.print("rec:" );
Serial.println(i);
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
QueueHandle_t QHandle;
if (QHandle != NULL) {
Serial.println("Create queue scuccessfully");
xTaskCreate(SendTask1, "SendTask1", 1024 * 5, (void*)QHandle, 1, NULL);
xTaskCreate(SendTask2, "SendTask2", 1024 * 5, (void*)QHandle, 1, NULL);
xTaskCreate(recTask, "recTask", 1024 * 5, (void*)QHandle, 2, NULL);
}
else {
Serial.println("cant't create queue");
}
}
void loop() {
}