// Use only core 1 for demo purposes
#if CONFIG_FREERTOS_UNICORE
static const BaseType_t app_cpu = 0;
#else
static const BaseType_t app_cpu = 1;
#endif
// Settings
static const uint8_t msg_queue_len = 3;
// Globals
static QueueHandle_t msg_queue;
//*****************************************************************************
// Tasks
// Task: wait for item on queue and print it
void receive_Messages( void *parameters ) {
String item;
// Loop forever
while (1) {
if (xQueueReceive(msg_queue, (void *)&item, 0) == pdTRUE) {
Serial.println(item);
}
// Serial.println(item);
// Wait before trying again
vTaskDelay(300 / portTICK_PERIOD_MS);
}
}
void Send_Messages( void *parameters ) {
while(1){
static float num = (921.5695);
String (num1) = String (num,4); // static int num = 0;
if (xQueueSend( msg_queue, (void *)&num1, 10) != pdTRUE ) {
Serial.println("Queue full");
}
num = num + 1; // num++;
// Wait before trying again
vTaskDelay(500 / portTICK_PERIOD_MS);
}
}
//*****************************************************************************
// Main (runs as its own task with priority 1 on core 1)
void setup() {
// Configure Serial
Serial.begin(115200);
// Wait a moment to start (so we don't miss Serial output)
vTaskDelay(1000 / portTICK_PERIOD_MS);
Serial.println();
Serial.println("---FreeRTOS Queue Demo---");
// Create queue
msg_queue = xQueueCreate(msg_queue_len, sizeof(String));
// Start print task
xTaskCreatePinnedToCore(receive_Messages,
"Receive Messages",
1024,
NULL,
1,
NULL,
app_cpu);// app_cpu
xTaskCreatePinnedToCore(Send_Messages,
"Send Messages",
1024,
NULL,
1,
NULL,
app_cpu);//app_cpu
}
void loop() {
/*
static int num = 0;
String num1 = (String) num; // static int num = 0;
// Try to add item to queue for 10 ticks, fail if queue is full
if (xQueueSend(msg_queue, (void *)&num, 10) != pdTRUE) {
Serial.println("Queue full");
}
num = num + 1; // num++;
// Wait before trying again
vTaskDelay(1000 / portTICK_PERIOD_MS);
*/
}