1 使用FreeRTOS队列
#include <Arduino.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define USE_MULTCORE 1
QueueHandle_t xQueue;
void xTaskOne(void *xTask1)
{
while (1)
{
USBSerial.printf("Task1 \r\n");
delay(500);
}
}
void xTaskTwo(void *xTask2)
{
while (1)
{
USBSerial.printf("Task2 \r\n");
delay(1000);
}
}
void Send_Task(void *arg)
{
int i = 0;
while (1)
{
if (xQueueSend(xQueue, (void *)&i, 0) == pdPASS)
{
USBSerial.printf("Send!\n");
}
else
{
USBSerial.printf("Cannot send!\n");
}
i++;
vTaskDelay(1000 / portTICK_RATE_MS);
}
}
void Rce_Task(void *arg)
{
int j;
while (1)
{
if (xQueueReceive(xQueue, (void *)&j, 0) == pdPASS)
{
USBSerial.printf("Rce ! j = %d.\n", j);
}
vTaskDelay(1000 / portTICK_RATE_MS);
}
}
void app_main(void)
{
xQueue = xQueueCreate(10, sizeof(int));
if (xQueue == NULL)
{
USBSerial.printf("The queue cannot be created !\n");
}
else
{
xTaskCreate(Send_Task, "Send_Task", 2048, NULL, 1, NULL);
xTaskCreate(Rce_Task, "Rce_Task", 2048, NULL, 1, NULL);
}
}
void setup()
{
USBSerial.begin(115200);
app_main();
}
void loop()
{
}