]> kolegite.com Git - vmks.git/commitdiff
Added FreeRTOS blink example
authorVladimir Garistov <vl.garistov@gmail.com>
Tue, 26 Mar 2024 11:18:29 +0000 (13:18 +0200)
committerVladimir Garistov <vl.garistov@gmail.com>
Tue, 26 Mar 2024 11:18:29 +0000 (13:18 +0200)
Examples/FreeRTOS/freertos_blink/freertos_blink.ino [new file with mode: 0644]

diff --git a/Examples/FreeRTOS/freertos_blink/freertos_blink.ino b/Examples/FreeRTOS/freertos_blink/freertos_blink.ino
new file mode 100644 (file)
index 0000000..7eada26
--- /dev/null
@@ -0,0 +1,45 @@
+#define LED1  17
+#define LED2  18
+
+#define THREAD_STACK_SIZE   1024
+
+typedef struct
+{
+  uint32_t t;
+  uint8_t pin;
+}
+blink_args_t;
+
+void blink(void *pvParameters);
+
+void setup()
+{
+  TaskHandle_t blink1_handle = NULL;
+  TaskHandle_t blink2_handle = NULL;
+
+  blink_args_t args1 = {t: 100 / portTICK_PERIOD_MS, pin: LED1},
+    args2 = {t: 500 / portTICK_PERIOD_MS, pin: LED2};
+
+  pinMode(LED1, OUTPUT);
+  pinMode(LED2, OUTPUT);
+  digitalWrite(LED1, LOW);
+  digitalWrite(LED2, LOW);
+  xTaskCreate(blink, "blink1", THREAD_STACK_SIZE, (void *) &args1, 1, &blink1_handle);
+  xTaskCreate(blink, "blink2", THREAD_STACK_SIZE, (void *) &args2, 2, &blink2_handle);
+}
+
+void loop()
+{}
+
+void blink(void *pvParameters)
+{
+  blink_args_t *args = (blink_args_t *) pvParameters;
+
+  while (1)
+  {
+    digitalWrite(args->pin, HIGH);
+    vTaskDelay(args->t / 2);
+    digitalWrite(args->pin, LOW);
+    vTaskDelay(args->t / 2);
+  }
+}
\ No newline at end of file