From: Vladimir Garistov Date: Tue, 26 Mar 2024 11:18:29 +0000 (+0200) Subject: Added FreeRTOS blink example X-Git-Url: https://kolegite.com/gitweb/?a=commitdiff_plain;h=5ced0c54bef8e3339e7cb17378b819ecf48fe525;p=vmks.git Added FreeRTOS blink example --- diff --git a/Examples/FreeRTOS/freertos_blink/freertos_blink.ino b/Examples/FreeRTOS/freertos_blink/freertos_blink.ino new file mode 100644 index 0000000..7eada26 --- /dev/null +++ b/Examples/FreeRTOS/freertos_blink/freertos_blink.ino @@ -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