This is the code:
main.c
Code: Select all
void app_main()
{
ledInit();
esp_err_t err = nvs_flash_init();
printf("Hello!!!\n");
}
Code: Select all
#ifndef LED_H
#define LED_H
#include <stdint.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
//Prototype
void ledInit(void);
void blinkLedTask(void *pvParameter);
void setLed(TickType_t, uint8_t);
//led pin
const gpio_num_t RLED = 2;
const gpio_num_t GLED = 4;
const gpio_num_t BLED = 5;
//blink mode (ms)
const TickType_t NOBLINK=2;
const TickType_t INITBLINK=1000;
const TickType_t ERRORBLINK=500;
const TickType_t OPERATIONBLINK=30;
//Constant
const bool LEDOFF = 0;
const bool LEDON = 1;
#endif //LED_H
Code: Select all
#include "led.h"
TickType_t ledMode = 0;
uint8_t ledColor = 0;
void ledInit(void)
{
//R
gpio_pad_select_gpio(RLED);
gpio_set_direction(RLED, GPIO_MODE_OUTPUT);
gpio_set_level(RLED, LEDON);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_set_level(RLED, LEDOFF);
//G
gpio_pad_select_gpio(GLED);
gpio_set_direction(GLED, GPIO_MODE_OUTPUT);
gpio_set_level(GLED, LEDON);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_set_level(GLED, LEDOFF);
//B
gpio_pad_select_gpio(BLED);
gpio_set_direction(BLED, GPIO_MODE_OUTPUT);
gpio_set_level(BLED, LEDON);
vTaskDelay(500 / portTICK_PERIOD_MS);
gpio_set_level(BLED, LEDOFF);
//Run task
xTaskCreate(&blinkLedTask, "blinkLedTask", 2048, NULL, 5, NULL);
}
void setLed(TickType_t blinkMode, uint8_t color)
{
ledMode = blinkMode; //Imposta la velocità del lampeggio
ledColor = color; //Imposta il colore del led
}
void blinkLedTask(void *pvParameter)
{
static bool ledStatus = false;
while (1)
{
printf("ledMode: %d ledColor: %d\n", ledMode, ledColor); //for debug
if (ledMode == NOBLINK)
ledStatus = true;
else
ledStatus = !ledStatus;
//all leds off
gpio_set_level(RLED, LEDOFF);
gpio_set_level(GLED, LEDOFF);
gpio_set_level(BLED, LEDOFF);
//power on selected led
gpio_set_level(ledColor, ledStatus);
//vTaskDelay(500 / portTICK_PERIOD_MS);
vTaskDelay(ledMode / portTICK_PERIOD_MS);
}
}
Code: Select all
vTaskDelay(ledMode / portTICK_PERIOD_MS)
Code: Select all
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
- IDLE (CPU 0)
- IDLE (CPU 1)
Tasks currently running:
CPU 0: blinkLedTask
CPU 1: ipc1
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
- IDLE (CPU 0)
- IDLE (CPU 1)
Tasks currently running:
CPU 0: blinkLedTask
CPU 1: ipc1
Task watchdog got triggered. The following tasks did not reset the watchdog in time:
- IDLE (CPU 0)
- IDLE (CPU 1)
Tasks currently running:
CPU 0: blinkLedTask
CPU 1: ipc1
Code: Select all
vTaskDelay(500 / portTICK_PERIOD_MS)
I tried to verify ledMode and ledColor value in "blinkLedTask" and I've seen that If I write "vTaskDelay(500 / portTICK_PERIOD_MS)" the value of these variables is ok.
If I write "vTaskDelay(ledMode / portTICK_PERIOD_MS)" ledMode and ledColor are equal to zero.
What can generate this problem?
Thanks.
Best regards.
Stefano