]> kolegite.com Git - vmks.git/commitdiff
FEAT: FreeRTOS Serial.print example
authorVladimir Garistov <vl.garistov@gmail.com>
Mon, 8 Apr 2024 08:11:26 +0000 (11:11 +0300)
committerVladimir Garistov <vl.garistov@gmail.com>
Mon, 8 Apr 2024 08:11:26 +0000 (11:11 +0300)
Examples/FreeRTOS/freertos_serial/freertos_serial.ino [new file with mode: 0644]

diff --git a/Examples/FreeRTOS/freertos_serial/freertos_serial.ino b/Examples/FreeRTOS/freertos_serial/freertos_serial.ino
new file mode 100644 (file)
index 0000000..5729311
--- /dev/null
@@ -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);
+}