8000 Mon Jan 16 15:18:42 CST 2017 · EagleSmith/esp32-snippets@a4db3b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a4db3b1

Browse files
author
kolban
committed
Mon Jan 16 15:18:42 CST 2017
1 parent 27a4422 commit a4db3b1

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

gpio/interrupts/test_intr.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Test interrupt handling on a GPIO.
3+
* In this fragment we watch for a change on the input signal
4+
* of GPIO 25. When it goes high, an interrupt is raised which
5+
* adds a message to a queue which causes a task that is blocking
6+
* on the queue to wake up and process the interrupt.
7+
*/
8+
#include <driver/gpio.h>
9+
#include <esp_log.h>
10+
#include <freertos/FreeRTOS.h>
11+
#include <freertos/queue.h>
12+
#include <freertos/task.h>
13+
14+
#include "sdkconfig.h"
15+
16+
static char tag[] = "test_intr";
17+
static QueueHandle_t q1;
18+
19+
#define TEST_GPIO (25)
20+
static void handler(void *args) {
21+
gpio_num_t gpio;
22+
gpio = TEST_GPIO;
23+
xQueueSendToBackFromISR(q1, &gpio, NULL);
24+
}
25+
26+
void test1_task(void *ignore) {
27+
ESP_LOGD(tag, ">> test1_task");
28+
gpio_num_t gpio;
29+
q1 = xQueueCreate(10, sizeof(gpio_num_t));
30+
31+
gpio_config_t gpioConfig;
32+
gpioConfig.pin_bit_mask = GPIO_SEL_25;
33+
gpioConfig.mode = GPIO_MODE_INPUT;
34+
gpioConfig.pull_up_en = GPIO_PULLUP_DISABLE;
35+
gpioConfig.pull_down_en = GPIO_PULLDOWN_ENABLE;
36+
gpioConfig.intr_type = GPIO_INTR_POSEDGE;
37+
gpio_config(&gpioConfig);
38+
39+
gpio_install_isr_service(0);
40+
gpio_isr_handler_add(TEST_GPIO, handler, NULL );
41+
while(1) {
42+
ESP_LOGD(tag, "Waiting on interrupt queue");
43+
BaseType_t rc = xQueueReceive(q1, &gpio, portMAX_DELAY);
44+
ESP_LOGD(tag, "Woke from interrupt queue wait: %d", rc);
45+
}
46+
vTaskDelete(NULL);
47+
}

0 commit comments

Comments
 (0)
0