From: Vladimir Garistov Date: Mon, 8 Apr 2024 08:11:26 +0000 (+0300) Subject: FEAT: FreeRTOS Serial.print example X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=e328f49a952744a0c21cfaf3fcfe0093a4e7fea8;p=vmks.git FEAT: FreeRTOS Serial.print example --- diff --git a/Examples/FreeRTOS/freertos_serial/freertos_serial.ino b/Examples/FreeRTOS/freertos_serial/freertos_serial.ino new file mode 100644 index 0000000..5729311 --- /dev/null +++ b/Examples/FreeRTOS/freertos_serial/freertos_serial.ino @@ -0,0 +1,55 @@ +#define THREAD_STACK_SIZE 1024 + +static void say_name(__attribute__((unused)) void *args); +static void error(void); + +SemaphoreHandle_t uart_mutex; + +TaskHandle_t asen_handle = NULL; +TaskHandle_t boris_handle = NULL; + +void setup() +{ + uart_mutex = xSemaphoreCreateMutex(); + if (uart_mutex == NULL) + { + error(); + } + + Serial.begin(115200); + delay(1000); + + xTaskCreate(say_name, "asen", THREAD_STACK_SIZE, NULL, 1, &asen_handle); + xTaskCreate(say_name, "Boris", THREAD_STACK_SIZE, NULL, 1, &boris_handle); + + delay(1000); + vTaskSuspend(asen_handle); + vTaskSuspend(boris_handle); +} + +void loop() +{} + +static void say_name(__attribute__((unused)) void *args) +{ + char *name = pcTaskGetName(NULL); + + while (true) + { + //while (xSemaphoreTake(uart_mutex, portMAX_DELAY) != pdTRUE); + Serial.print(name); + Serial.println(" kazva Zdravei!"); + /* + if (xSemaphoreGive(uart_mutex) != pdTRUE) + { + error(); + } + */ + vTaskDelay(100 / portTICK_PERIOD_MS); + } +} + +static void error(void) +{ + while (true); +}