simple-task.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #include <stdio.h>
  2. #include "freertos/FreeRTOS.h"
  3. #include "freertos/task.h"
  4. #include "driver/gpio.h"
  5. #define LED_RED GPIO_NUM_2
  6. #define LED_GREEN GPIO_NUM_4
  7. #define LED_BLUE GPIO_NUM_5
  8. struct led_task_parameters_t
  9. {
  10. gpio_num_t led_gpio;
  11. TickType_t blink_time;
  12. char led_name[10];
  13. };
  14. static led_task_parameters_t red_led_gpio = {LED_RED, 2000,"Red"};
  15. static led_task_parameters_t blue_led_gpio = {LED_BLUE, 2000,"Blue"};
  16. static led_task_parameters_t green_led_gpio = {LED_GREEN, 2000,"Green"};
  17. void led_task(void *pvParameter)
  18. {
  19. gpio_num_t led_gpio = ((led_task_parameters_t *)pvParameter)-> led_gpio;
  20. TickType_t blink_time = ((led_task_parameters_t *)pvParameter)-> blink_time;
  21. char *led_name = ((led_task_parameters_t *)pvParameter)-> led_name;
  22. uint8_t led_value = 0;
  23. gpio_reset_pin(led_gpio);
  24. gpio_set_direction(led_gpio, GPIO_MODE_OUTPUT);
  25. while (1) {
  26. gpio_set_level(led_gpio, led_value);
  27. led_value = !led_value;
  28. //printf("%s \n",led_name);
  29. //printf("%d \n",(xPortGetFreeHeapSize()));
  30. printf("%d in %s \n",(uxTaskGetStackHighWaterMark(NULL)),led_name);
  31. vTaskDelay(blink_time / portTICK_PERIOD_MS);
  32. }
  33. vTaskDelete( NULL );
  34. }
  35. extern "C" void app_main()
  36. {
  37. xTaskCreate(
  38. &led_task, // task function
  39. "red_led_task", // task name
  40. 2048, // stack size in words
  41. &red_led_gpio, // pointer to parameters
  42. 5, // priority
  43. NULL); // out pointer to task handle
  44. xTaskCreate(
  45. &led_task, // task function
  46. "blue_led_task", // task name
  47. 2048, // stack size in words
  48. &blue_led_gpio, // pointer to parameters
  49. 5, // priority
  50. NULL); // out pointer to task handle
  51. xTaskCreate(
  52. &led_task, // task function
  53. "green_led_task", // task name
  54. 2048, // stack size in words
  55. &green_led_gpio, // pointer to parameters
  56. 5, // priority
  57. NULL); // out pointer to task handle
  58. }