|
24 | 24 | #include "sdkconfig.h" |
25 | 25 | #include "freertos/FreeRTOS.h" |
26 | 26 | #include "freertos/task.h" |
| 27 | +#include "esp_log.h" |
27 | 28 | #include "esp_system.h" |
28 | 29 |
|
29 | 30 | #include "gpio.h" |
30 | 31 |
|
| 32 | +/* defines */ |
| 33 | +#define TAG "GPIO" |
| 34 | + |
| 35 | +/* global values */ |
| 36 | +QueueHandle_t q_flash = NULL; |
| 37 | + |
| 38 | +/* prototypes */ |
| 39 | +static void gpio_flash(void* arg); |
| 40 | +static void gpio_isr_handler(void* arg); |
| 41 | + |
| 42 | +static void gpio_flash(void* arg) { |
| 43 | + uint32_t gpio_num; |
| 44 | + |
| 45 | + (void)arg; |
| 46 | + |
| 47 | + ESP_LOGI(TAG, "flash task started on core %d", xPortGetCoreID()); |
| 48 | + while (1) { |
| 49 | + if (xQueueReceive(q_flash, &gpio_num, portMAX_DELAY)) { |
| 50 | + configASSERT(gpio_num == 0); |
| 51 | + ESP_LOGW(TAG, "flash switch changed, restarting"); |
| 52 | + esp_restart(); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
31 | 57 | void gpio_init(void) { |
32 | 58 | /* LEDs */ |
33 | 59 | gpio_reset_pin(GPIO_GREENLED); |
@@ -71,6 +97,19 @@ void gpio_init(void) { |
71 | 97 | gpio_set_direction(GPIO_QX2, GPIO_MODE_OUTPUT); |
72 | 98 | gpio_set_direction(GPIO_QY1, GPIO_MODE_OUTPUT); |
73 | 99 | gpio_set_direction(GPIO_QY2, GPIO_MODE_OUTPUT); |
| 100 | + |
| 101 | + /* Flash mode watchdog */ |
| 102 | + gpio_reset_pin(GPIO_FLASH); |
| 103 | + gpio_set_direction(GPIO_FLASH, GPIO_MODE_INPUT); |
| 104 | + q_flash = xQueueCreate(10, sizeof(uint32_t)); |
| 105 | + xTaskCreatePinnedToCore(gpio_flash, "FLASH", 2 * 1024, NULL, 10, NULL, 0); |
| 106 | + gpio_install_isr_service(0); |
| 107 | + gpio_isr_handler_add(GPIO_FLASH, gpio_isr_handler, (void*) GPIO_FLASH); |
| 108 | +} |
| 109 | + |
| 110 | +static void IRAM_ATTR gpio_isr_handler(void* arg) { |
| 111 | + uint32_t gpio_num = (uint32_t) arg; |
| 112 | + xQueueSendFromISR(q_flash, &gpio_num, NULL); |
74 | 113 | } |
75 | 114 |
|
76 | 115 | void gpio_transceiver_disable(void) { |
|
0 commit comments