Is eternal spinlock possible?

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

Is eternal spinlock possible?

Postby whoyoume » Wed Jun 19, 2019 3:26 am

Hello people,
Id like to run the code as below.
while(1) {
while((PORT & 0x20)=0);
doit();
}
But system reboot occurs.
If possible, could anybody tell me how ?
Thank you.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Is eternal spinlock possible?

Postby ESP_Sprite » Wed Jun 19, 2019 7:29 am

Normally, this should not reboot. Can you give a bit more context: the SDK you use, the actual code that reboots?

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

Re: Is eternal spinlock possible?

Postby whoyoume » Wed Jun 19, 2019 12:03 pm

First, I have to say that I have solved the problem by disabling WDT in menuconfig.

Then, I show the source code and monitor output.

Thank you.

---------------------------------------------
source code
---------------------------------------------

void app_main()
{
portMUX_TYPE mutex = portMUX_INITIALIZER_UNLOCKED;
portENTER_CRITICAL(&mutex);
gpio_set_direction(PIN, GPIO_MODE_OUTPUT);
for (int k = 0; k < 3; k++)
{
PORT |= (1 << PIN);
for (unsigned int i = 0; i < 0x1fffff; i++) asm volatile("nop\n\t");
PORT &= ~(1 << PIN);
for (unsigned int i = 0; i < 0x1fffff; i++) asm volatile("nop\n\t");
}
while (1);
portEXIT_CRITICAL(&mutex);
}

---------------------------------------------
monitor output
---------------------------------------------

ets Jun 8 2016 00:22:57

rst:0x7 (TG0WDT_SYS_RESET),boot:0x12 (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:6436
load:0x40078000,len:11304
load:0x40080400,len:6752
entry 0x40080768
W (172) boot: PRO CPU has been reset by WDT.
W (172) boot: WDT reset info: PRO CPU PC=0x400d1f19
0x400d1f19: app_main at C:/tmp/msys32/home/koichi/esp32_al422b_ov7670/main/esp32
_al422b_ov7670.c:257 (discriminator 1)

W (173) boot: WDT reset info: APP CPU PC=0x400e2496 (waiti mode)
0x400e2496: esp_pm_impl_waiti at C:/tmp/msys32/opt/esp-idf/components/esp32/pm_e
sp32.c:493

I (180) boot: ESP-IDF v4.0-dev-489-gc2aef48a5 2nd stage bootloader
I (187) boot: compile time 23:54:47
I (191) boot: Enabling RNG early entropy source...
I (197) boot: SPI Speed : 40MHz
I (201) boot: SPI Mode : DIO
I (205) boot: SPI Flash Size : 4MB
I (209) boot: Partition Table:
I (213) boot: ## Label Usage Type ST Offset Length
I (220) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (228) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (235) boot: 2 factory factory app 00 00 00010000 00100000
I (243) boot: End of partition table
I (247) esp_image: segment 0: paddr=0x00010020 vaddr=0x3f400020 size=0x0889c ( 3
4972) map
I (268) esp_image: segment 1: paddr=0x000188c4 vaddr=0x3ffb0000 size=0x01e88 (
7816) load
I (272) esp_image: segment 2: paddr=0x0001a754 vaddr=0x40080000 size=0x00400 (
1024) load
0x40080000: _WindowOverflow4 at C:/tmp/msys32/opt/esp-idf/components/freertos/xt
ensa_vectors.S:1779

I (277) esp_image: segment 3: paddr=0x0001ab5c vaddr=0x40080400 size=0x054b4 ( 2
1684) load
I (294) esp_image: segment 4: paddr=0x00020018 vaddr=0x400d0018 size=0x12480 ( 7
4880) map
0x400d0018: _flash_cache_start at ??:?

I (321) esp_image: segment 5: paddr=0x000324a0 vaddr=0x400858b4 size=0x02618 (
9752) load
0x400858b4: vPortYieldOtherCore at C:/tmp/msys32/opt/esp-idf/components/freertos
/port.c:403

I (330) boot: Loaded app from partition at offset 0x10000
I (330) boot: Disabling RNG early entropy source...
I (332) cpu_start: Pro cpu up.
I (336) cpu_start: Application information:

...

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Is eternal spinlock possible?

Postby ESP_Sprite » Thu Jun 20, 2019 4:36 am

Please do not do that. ESP-IDF is not made to have interrupts disabled for a long time while you're bitbanging data; the watchdog timer is there for a reason. Have you tried using one of the many, many peripherals the ESP32 has to do stuff like this fully automatically instead?

whoyoume
Posts: 23
Joined: Fri Sep 07, 2018 2:42 am

Re: Is eternal spinlock possible?

Postby whoyoume » Thu Jun 20, 2019 2:20 pm

Thank you for your advise. All that I need is H/W interrupt which guarantees a delay less than several tens or hundreds of micro seconds. I think the delay guaranteed on ESP32 is several tens of msec, so I tried that attempt.

Actually, I will not do eternal spinlock. I will send data to serve via wifi, which the interrupt handler get, once per hour. A task switch is to be occurred at the time.

If you know, could you let me know how long the delay on ESP32 is.

Thank you.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Is eternal spinlock possible?

Postby ESP_Sprite » Fri Jun 21, 2019 2:31 am

Can you explain a bit more about what you're trying to achieve? Are you trying to implement a protocol in software or something?

Who is online

Users browsing this forum: No registered users and 115 guests