Skip to content

Instantly share code, notes, and snippets.

@cversek
Created May 12, 2023 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cversek/02f6d00af270ee2eb31ff25b27b8a076 to your computer and use it in GitHub Desktop.
Save cversek/02f6d00af270ee2eb31ff25b27b8a076 to your computer and use it in GitHub Desktop.
check behavior of FreeRTOS QueueReceive Timeout
#include <STM32FreeRTOS.h>
// Define the LED pin is attached
const uint8_t LED_PIN = LED_BUILTIN;
// We need a handle for ul
xTaskHandle waitTaskHandle = NULL;
QueueHandle_t mQueue;
// Wait Task, wait for Notify using a finite timeout
// Wait Task
static void WaitTask(void* arg) {
UNUSED(arg);
int data;
// Sleep for 5000 milliseconds.
vTaskDelay(pdMS_TO_TICKS(5000));
while (1) {
Serial.println(F("BEFORE xQueueReceive"));
// this SHOULD block for 5 sec before timing out
if (xQueueReceive(mQueue,&data,pdMS_TO_TICKS(5000)) == pdTRUE){
Serial.print(F("xQueueReceive got data: "));Serial.println(data);
} else{
Serial.println(F("xQueueReceive TIMED OUT"));
}
}
}
// Blink Task
static void BlinkTask(void* arg) {
UNUSED(arg);
pinMode(LED_PIN, OUTPUT);
while (1) {
// Sleep for 500 milliseconds.
vTaskDelay(pdMS_TO_TICKS(500));
Serial.println("LED on");
// Turn LED on.
digitalWrite(LED_PIN, HIGH);
// Sleep for 500 milliseconds.
vTaskDelay(pdMS_TO_TICKS(500));
Serial.println("LED off");
// Turn LED off.
digitalWrite(LED_PIN, LOW);
}
}
void setup() {
portBASE_TYPE s1, s2;
Serial.begin(9600);
while (!Serial){}; //WAIT FOR SERIAL CONNECTION TO OPEN
// create the queue
mQueue = xQueueCreate(1, 1);
// create task at priority one
s1 = xTaskCreate(BlinkTask, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);
// create task at priority one
s2 = xTaskCreate(WaitTask, NULL, configMINIMAL_STACK_SIZE, NULL, 1, &waitTaskHandle);
// check for creation errors
if (s1 != pdPASS || s2 != pdPASS ) {
Serial.println(F("Creation problem"));
while(1);
}
// start scheduler
vTaskStartScheduler();
Serial.println("Insufficient RAM");
while(1);
}
void loop() {
// put your main code here, to run repeatedly:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment