// 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 = 5;
// Settings
static const uint8_t buf_len = 255;
// Globals
static QueueHandle_t msg_queue1;
static QueueHandle_t msg_queue2;
// Tasks
// -------------------------------------------------------------
// Task 1 - Sending the data
void printMessage(void *parameters)
{
char c;
char buf[buf_len];
int item;
uint8_t idx = 0;
int led =100;
static int num;
memset(buf, 0, buf_len);
while(1)
{
// Read cahracters from serial
if (Serial.available() > 0)
{
c = Serial.read();
// Store received character to buffer if not over buffer limit
if (idx < buf_len - 1) {
buf[idx] = c;
idx++;
}
Serial.print("value obtained");
Serial.println(buf);
// Create a message buffer for print task
if (c == '\n') {
// The last character in the string is '\n', so we need to replace
// it with '\0' to make it null-terminated
buf[idx - 1] = '\0';
}
}
int led_delay =100;
// Send integer to other task via queue
// if (xQueueSend(msg_queue2, (void *)&led_delay, 10) != pdTRUE) {
// Serial.println("ERROR: Could not put item on delay queue.");
// }
if(xQueueReceive(msg_queue1,(void *)&item,0)==pdTRUE)
{
Serial.println(item);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
if (xQueueSend(msg_queue2,(void *)&buf,10)!=pdTRUE)
{
Serial.println("Queue Full");
}
num ++;
}
}
// Task 1 - Receiving the data
void ledFlash(void *parameters)
{
int buf = 100;
while(1)
{
if(xQueueReceive(msg_queue2,(void *)&buf,0)==pdTRUE)
{
Serial.print("hello");
Serial.println(buf);
}
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
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("---FreeRTOS Queue Demo---");
// Create queue
msg_queue1= xQueueCreate(msg_queue_len,sizeof(int));
msg_queue2= xQueueCreate(msg_queue_len,sizeof(int));
xTaskCreatePinnedToCore(printMessage,
"Print Messages",
4096,
NULL,
1,
NULL,
app_cpu);
xTaskCreatePinnedToCore(ledFlash,
"Print Messages",
4096,
NULL,
1,
NULL,
app_cpu);
// Delete "setup and loop" task
vTaskDelete(NULL);
}
void loop() {
static int num = 0;
if (xQueueSend(msg_queue1,(void *)&num,10)!=pdTRUE)
{
Serial.println("Queue Full");
}
num ++;
// Wait a moment to start (so we don't miss Serial output)
vTaskDelay(1000 / portTICK_PERIOD_MS);
}