#include <stdio.h>
#include <stdlib.h>
#include <driver/gpio.h>
#include "esp_err.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define LED_PIN GPIO_NUM_21
#define TASK_1_NAME "task 1"
#define TASK_1_STACK_SIZE (configMINIMAL_STACK_SIZE * 4)
#define TASK_1_PRIORITY (tskIDLE_PRIORITY + 1)
#define TASK_2_NAME "task 2"
#define TASK_2_STACK_SIZE (configMINIMAL_STACK_SIZE * 4)
#define TASK_2_PRIORITY (tskIDLE_PRIORITY + 2)
// Declaração das funções
static void task_1(void *arg);
static void task_2(void *arg);
// Declaração dos handles
static TaskHandle_t xtask_handle_1 = NULL;
static TaskHandle_t xtask_handle_2 = NULL;
void app_main(void)
{
BaseType_t xReturn = pdPASS;
xReturn = xTaskCreate(&task_1,
TASK_1_NAME,
TASK_1_STACK_SIZE,
NULL,
TASK_1_PRIORITY,
&xtask_handle_1);
if (xReturn != pdPASS || xtask_handle_1 == NULL) {
printf("Erro ao criar a task 1\n");
}
xReturn = xTaskCreate(&task_2,
TASK_2_NAME,
TASK_2_STACK_SIZE,
NULL,
TASK_2_PRIORITY,
&xtask_handle_2);
if (xReturn != pdPASS || xtask_handle_2 == NULL) {
printf("Erro ao criar a task 2\n");
}
while (1) {
vTaskDelay(pdMS_TO_TICKS(10000));
}
}
static void task_1(void *arg)
{
uint8_t count = 0;
while (true) {
if (count == 4) {
vTaskSuspend(xtask_handle_2);
}
if (count > 9) {
vTaskResume(xtask_handle_2);
}
count++;
ESP_LOGE("main", "%s tick : %d count: %d", __func__, xTaskGetTickCount(), count);
vTaskDelay(pdMS_TO_TICKS(500));
}
}
static void task_2(void *arg)
{
gpio_pad_select_gpio(LED_PIN);
gpio_set_direction (LED_PIN, GPIO_MODE_OUTPUT);
while (true) {
gpio_set_level(LED_PIN, 0);
vTaskDelay(500 / portTICK_RATE_MS);
gpio_set_level(LED_PIN, 1);
vTaskDelay(500 / portTICK_RATE_MS);
}
}
Loading
franzininho-wifi
franzininho-wifi