Хорошо.Таким образом, этот вопрос кажется довольно простым.Я пытаюсь зажечь светодиод через внешнее аппаратное прерывание в течение 10 секунд. После чего должно произойти прерывание по таймеру, которое должно выключить светодиод (в противном случае задача должна оставаться в спящем режиме - для более поздней части).
Этомой код.
#define TIMER_DIVIDER 16
#define TIMER_SCALE (TIMER_BASE_CLK/TIMER_DIVIDER)
#define TIMER_INTERVAL0_SEC (10)
#define TEST_WITHOUT_RELOAD 0
#define ESP_INTR_FLAG_DEFAULT 0
#define GPIO_OUTPUT_IO_0 18
#define GPIO_INPUT_IO_0 4
#define GPIO_INPUT_PIN_SEL (1ULL<<GPIO_INPUT_IO_0)
#define GPIO_OUTPUT_PIN_SEL (1ULL<<GPIO_OUTPUT_IO_0)
enter code here
typedef struct{
int type;
int timer_group;
int timer_idx;
uint64_t timer_counter_value;
int element;
}timer_event_t;
static int level;
xQueueHandle led;
//void *msg=NULL;
static void IRAM_ATTR gpio_isr_handler(TaskHandle_t Handle)
{
// if(level)
// level=0;
// else
level=1;
// xTaskResumeFromISR(Handle);
// puts("In Interrupt");
// fflush(stdout);
timer_event_t msg;
msg.element=1;
xQueueSendFromISR(led,&msg,NULL);
//imer_start(TIMER_GROUP_0,TIMER_0);
// printf("Msg Sentfro ISR\n");
}
/*
void routine(void *arv)
{
//while(1)
//{
//printf("LED %d",level);
//fflush(stdout);
//}//gpio_set_level(GPIO_OUTPUT_IO_0,level);
}*/
static void IRAM_ATTR timer_group0_isr(void *p)
{
// if(level)
level=0;
// else
// level=1;
timer_pause(TIMER_GROUP_0,TIMER_0);
}
static void example_tg0_timer_init(int timer_idx,bool auto_reload,double timer_interval_sec)
{
timer_config_t config;
config.divider=TIMER_DIVIDER;
config.counter_dir=TIMER_COUNT_UP;
config.counter_en=TIMER_PAUSE;
config.alarm_en=TIMER_ALARM_EN;
config.intr_type=TIMER_INTR_LEVEL;
config.auto_reload=auto_reload;
timer_init(TIMER_GROUP_0,timer_idx,&config);
timer_set_counter_value(TIMER_GROUP_0,timer_idx,0x00000000ULL);
timer_set_alarm_value(TIMER_GROUP_0,timer_idx,timer_interval_sec * TIMER_SCALE);
timer_enable_intr(TIMER_GROUP_0,timer_idx);
// timer_isr_register(TIMER_GROUP_0,timer_idx,timer_group0_isr,(void*)timer_idx,ESP_INTR_FLAG_IRAM,NULL);
timer_isr_register(TIMER_GROUP_0,timer_idx,timer_group0_isr,(void*)timer_idx,ESP_INTR_FLAG_IRAM,NULL);
timer_start(TIMER_GROUP_0,timer_idx);
timer_pause(TIMER_GROUP_0,timer_idx);
printf("T Init \n");
}
void timer_1(void *par)
{
timer_event_t temp;
vTaskDelay(200/portTICK_PERIOD_MS);
example_tg0_timer_init(TIMER_0,TEST_WITHOUT_RELOAD,TIMER_INTERVAL0_SEC);
// gpio_set_direction(GPIO_OUTPUT_IO_0,GPIO_MODE_OUTPUT);
while(1)
{
xQueueReceive(led,&temp,portMAX_DELAY);
printf("Recieving %d\n",temp.element);
printf("Level %d\n",level);
// fflush(stdout);
//f( //printf("LED is %d",level);
if(level)//temp.element==1)
{
gpio_set_level(GPIO_OUTPUT_IO_0,level);
timer_start(TIMER_GROUP_0,TIMER_0);
vTaskDelay(1000/portTICK_PERIOD_MS);
fflush(stdout);
}
// else
// gpio_set_level(GPIO_OUTPUT_IO_0,0);
}
}
void app_main()
{
// msg=malloc(0);
led=xQueueCreate(10,sizeof(level));
xTaskCreate(timer_1,"Timer_1",2048,NULL,5,NULL);
gpio_config_t io_conf;
//askHandle_t routine=NULL;
// routine=malloc(0);
gpio_set_direction(GPIO_OUTPUT_IO_0,GPIO_MODE_OUTPUT);
//gpio_set_direction(GPIO_INPUT_IO_0,GPIO_MODE_INPUT);
io_conf.intr_type=GPIO_PIN_INTR_POSEDGE;
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = GPIO_INPUT_PIN_SEL;
io_conf.pull_down_en = 1;
gpio_config(&io_conf);
//gpio_set_intr_type(GPIO_INPUT_IO_0, _INTR_POSEDGE);
gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT);
// xTaskCreate(routine,"routine",2048,NULL,10,NULL);
gpio_isr_handler_add(GPIO_INPUT_IO_0,gpio_isr_handler,NULL);
// vTaskSuspend(routine);
printf("Ahoya\n"); //io_isr_handler_add(
fflush(stdout);
// int cnt=0;
/*hile(1)
{
printf("Level is %d \n",level);
gpio_set_level(GPIO_OUTPUT_IO_0,level);
vTaskDelay(1000/portTICK_PERIOD_MS);
fflush(stdout);
}
*/
}
И это то, что происходит через 10 секунд.
Guru Meditation Error: Core 0 panic'ed (Interrupt wdt timeout on CPU0)
Core 0 register dump:
PC : 0x40085a32 PS : 0x00060034 A0 : 0x800e2862 A1 : 0x3ffb0820
0x40085a32: vTaskExitCritical at /home/dhananjay/esp/esp-idf/components/freertos/tasks.c:4590
A2 : 0x3ffb0a7c A3 : 0x00060023 A4 : 0x00060023 A5 : 0x3ffb5530
A6 : 0x3ffb0044 A7 : 0x000009b6 A8 : 0x3ffb21e4 A9 : 0x3ffb4234
A10 : 0x3ffb4234 A11 : 0x00060023 A12 : 0x00060021 A13 : 0x3ffb5520
A14 : 0x00000003 A15 : 0x00060323 SAR : 0x0000001d EXCCAUSE: 0x00000005
EXCVADDR: 0x00000000 LBEG : 0x00000000 LEND : 0x00000000 LCOUNT : 0x00000000
Core 0 was running in ISR context:
EPC1 : 0x400e335e EPC2 : 0x00000000 EPC3 : 0x00000000 EPC4 : 0x40085a32
0x400e335e: esp_pm_impl_waiti at /home/dhananjay/esp/esp-idf/components/esp32/pm_esp32.c:487
0x40085a32: vTaskExitCritical at /home/dhananjay/esp/esp-idf/components/freertos/tasks.c:4590
Backtrace: 0x40085a32:0x3ffb0820 0x400e285f:0x3ffb0840 0x400821d7:0x3ffb0870 0x40081c1e:0x3ffb0890 0x400e335b:0x3ffb4140 0x400d14e3:0x3ffb4160 0x40085e4a:0x3ffb4180 0x400851fd:0x3ffb41a0
0x40085a32: vTaskExitCritical at /home/dhananjay/esp/esp-idf/components/freertos/tasks.c:4590
0x400e285f: timer_pause at /home/dhananjay/esp/esp-idf/components/driver/timer.c:273
0x400821d7: timer_group0_isr at /home/dhananjay/esp/timer/main/gpio_example_main.c:87
0x40081c1e: _xt_lowint1 at /home/dhananjay/esp/esp-idf/components/freertos/xtensa_vectors.S:1154
0x400e335b: esp_pm_impl_waiti at /home/dhananjay/esp/esp-idf/components/esp32/pm_esp32.c:487
0x400d14e3: esp_vApplicationIdleHook at /home/dhananjay/esp/esp-idf/components/esp32/freertos_hooks.c:86
0x40085e4a: prvIdleTask at /home/dhananjay/esp/esp-idf/components/freertos/tasks.c:4590
0x400851fd: vPortTaskWrapper at /home/dhananjay/esp/esp-idf/components/freertos/port.c:403
Rebooting...
ets Jun 8 2016 00:22:57
rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:6252
load:0x40078000,len:11164
ho 0 tail 12 room 4
load:0x40080400,len:6672
entry 0x40080764
I (31) boot: ESP-IDF v3.3-beta1-328-gabea9e4-dirty 2nd stage bootloader
I (31) boot: compile time 18:11:14
I (32) boot: Enabling RNG early entropy source...
I (37) boot: SPI Speed : 40MHz
I (42) boot: SPI Mode : DIO
I (46) boot: SPI Flash Size : 4MB
I (50) boot: Partition Table:
I (53) boot: ## Label Usage Type ST Offset Length
I (60) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (68) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (75) boot: 2 factory factory app 00 00 00010000 00100000
I (83) boot: End of partition table
I (87) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x061a4 ( 24996) map
I (105) esp_image: segment 1: paddr=0x000161cc vaddr=0x3ffb0000 size=0x0168c ( 5772) load
I (107) esp_image: segment 2: paddr=0x00017860 vaddr=0x40080000 size=0x00400 ( 1024) load
0x40080000: _WindowOverflow4 at /home/dhananjay/esp/esp-idf/components/freertos/xtensa_vectors.S:1779
I (114) esp_image: segment 3: paddr=0x00017c68 vaddr=0x40080400 size=0x07268 ( 29288) load
I (135) esp_image: segment 4: paddr=0x0001eed8 vaddr=0x00000000 size=0x01138 ( 4408)
I (137) esp_image: segment 5: paddr=0x00020018 vaddr=0x400d0018 size=0x133d0 ( 78800) map
0x400d0018: _flash_cache_start at ??:?
I (175) boot: Loaded app from partition at offset 0x10000
I (175) boot: Disabling RNG early entropy source...
I (175) cpu_start: Pro cpu up.
I (179) cpu_start: Application information:
I (183) cpu_start: Project name: gpio
I (188) cpu_start: App version: 1
I (193) cpu_start: Compile time: 18:01:57
I (198) cpu_start: Compile date: Feb 18 2019
I (203) cpu_start: ESP-IDF: v3.3-beta1-328-gabea9e4-dirty
I (210) cpu_start: Single core mode
I (214) heap_init: Initializing. RAM available for dynamic allocation:
I (221) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (227) heap_init: At 3FFB2620 len 0002D9E0 (182 KiB): DRAM
I (234) heap_init: At 3FFE0440 len 0001FBC0 (126 KiB): D/IRAM
I (240) heap_init: At 40078000 len 00008000 (32 KiB): IRAM
I (246) heap_init: At 40087668 len 00018998 (98 KiB): IRAM
I (252) cpu_start: Pro cpu start user code
I (270) cpu_start: Starting scheduler on PRO CPU.
I (271) gpio: GPIO[4]| InputEn: 1| OutputEn: 0| OpenDrain: 0| Pullup: 0| Pulldown: 1| Intr:1