I have the following code:
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_log.h"
#include "driver/pulse_cnt.h"
#include "driver/gpio.h"
#include "esp_sleep.h"
#include "config.h"
#include "speed_calculations.h"
#define ESP_INTR_FLAG_DEFAULT 0
static QueueHandle_t gpio_evt_queue = NULL;
static void IRAM_ATTR gpio_isr_handler(void* arg)
{
uint32_t gpio_num = (uint32_t) arg;
xQueueSendFromISR(gpio_evt_queue, &gpio_num, NULL);
}
static void gpio_task_handler(void* arg)
{
uint32_t io_num;
for (;;) {
if (xQueueReceive(gpio_evt_queue, &io_num, portMAX_DELAY)) {
printf("GPIO[%"PRIu32"] intr, val: %d\n", io_num, gpio_get_level(io_num));
}
}
}
void app_main()
{
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_POSEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = CONFIG_GPIO_FRONT_WHEEL | CONFIG_GPIO_REAR_WHEEL;
io_conf.pull_up_en = 1;
gpio_config(&io_conf);
gpio_set_intr_type(CONFIG_GPIO_FRONT_WHEEL | CONFIG_GPIO_REAR_WHEEL, GPIO_INTR_ANYEDGE);
gpio_evt_queue = xQueueCreate(10, sizeof(uint32_t));
xTaskCreate(gpio_task_handler, "gpio_task_handler", 2048, NULL, 10, NULL);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
gpio_isr_handler_add(CONFIG_GPIO_FRONT_WHEEL, gpio_isr_handler, (void*) CONFIG_GPIO_FRONT_WHEEL);
gpio_isr_handler_add(CONFIG_GPIO_REAR_WHEEL, gpio_isr_handler, (void*) CONFIG_GPIO_FRONT_WHEEL);
printf("Minimum free heap size: %"PRIu32" bytes\n", esp_get_minimum_free_heap_size());
while (1) {
printf("cnt: %d\n", 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
How can I fix it?