12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include <stdio.h>
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "driver/gpio.h"
- #define LED_RED GPIO_NUM_2
- #define LED_GREEN GPIO_NUM_4
- #define LED_BLUE GPIO_NUM_5
- struct led_task_parameters_t
- {
- gpio_num_t led_gpio;
- TickType_t blink_time;
- char led_name[10];
- };
- static led_task_parameters_t red_led_gpio = {LED_RED, 2000,"Red"};
- static led_task_parameters_t blue_led_gpio = {LED_BLUE, 2000,"Blue"};
- static led_task_parameters_t green_led_gpio = {LED_GREEN, 2000,"Green"};
- void led_task(void *pvParameter)
- {
- gpio_num_t led_gpio = ((led_task_parameters_t *)pvParameter)-> led_gpio;
- TickType_t blink_time = ((led_task_parameters_t *)pvParameter)-> blink_time;
- char *led_name = ((led_task_parameters_t *)pvParameter)-> led_name;
- uint8_t led_value = 0;
- gpio_reset_pin(led_gpio);
- gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT);
- while (1) {
- gpio_set_level(led_gpio, led_value);
- led_value = !led_value;
- //printf("%s \n",led_name);
- //printf("%d \n",(xPortGetFreeHeapSize()));
- printf("%d in %s \n",(uxTaskGetStackHighWaterMark(NULL)),led_name);
- vTaskDelay(blink_time / portTICK_PERIOD_MS);
- }
- vTaskDelete( NULL );
- }
- extern "C" void app_main()
- {
- xTaskCreate(
- &led_task, // task function
- "red_led_task", // task name
- 2048, // stack size in words
- &red_led_gpio, // pointer to parameters
- 5, // priority
- NULL); // out pointer to task handle
- xTaskCreate(
- &led_task, // task function
- "blue_led_task", // task name
- 2048, // stack size in words
- &blue_led_gpio, // pointer to parameters
- 5, // priority
- NULL); // out pointer to task handle
- xTaskCreate(
- &led_task, // task function
- "green_led_task", // task name
- 2048, // stack size in words
- &green_led_gpio, // pointer to parameters
- 5, // priority
- NULL); // out pointer to task handle
- }
|