Skip to content

Commit 9152b95

Browse files
committed
added flash switch watchdog
1 parent 5d27f99 commit 9152b95

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

main/gpio.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,36 @@
2424
#include "sdkconfig.h"
2525
#include "freertos/FreeRTOS.h"
2626
#include "freertos/task.h"
27+
#include "esp_log.h"
2728
#include "esp_system.h"
2829

2930
#include "gpio.h"
3031

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+
3157
void gpio_init(void) {
3258
/* LEDs */
3359
gpio_reset_pin(GPIO_GREENLED);
@@ -71,6 +97,19 @@ void gpio_init(void) {
7197
gpio_set_direction(GPIO_QX2, GPIO_MODE_OUTPUT);
7298
gpio_set_direction(GPIO_QY1, GPIO_MODE_OUTPUT);
7399
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);
74113
}
75114

76115
void gpio_transceiver_disable(void) {

main/gpio.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void gpio_transceiver_enable(void);
4848
* - GPIO17
4949
*/
5050

51+
#define GPIO_FLASH 0
5152
#define GPIO_ADB 4
5253
#define GPIO_CLICK 2
5354
#define GPIO_QX1 12

0 commit comments

Comments
 (0)