disable_irq not effective

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
jmi2
Posts: 21
Joined: Mon Oct 01, 2018 9:31 pm

Re: disable_irq not effective

Post by jmi2 » Fri Oct 05, 2018 10:28 am

Hi,

Thank you. I read that multiple times, before i opened this topic.
I was expecting deeper explanation. Especially “very soon” is miles a way from what is happening.
Also http://docs.micropython.org/en/latest/l ... n.schedule
is not helping to explain more.
I still don't understand, how can be callback from soft interrupt invoked, if main program is still doing something.
Is there hard timer interrupt of something, which triggers functions queued via micropython.schedule? Or how is main program interrupted, so that scheduled stuff can be executed?

thank you
best regards
jmi

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: disable_irq not effective

Post by Roberthh » Fri Oct 05, 2018 10:39 am

Your questions are about generic OS or formware design. And yes, there is a system timer interrupt, which stops executing of you main code in regular intervals and looks for other tasks to be scheduled.
The timer interrupt is like the Pin interrupt a hard one, relying on hardware mechanisms of the CPU. Whenever such a hard signal occurs, a Interrupt Service Routine is started. That is similar to a function call, where the addresses of the to be called fucntions have to be stored at predefined memory locations beforehand. That is far below the layers of Python bytecode supported by the RTOS of espressif. Part of that is saving the execution context of the interrupted program and restoring it when the execution is to be resumed. If the CPU has multiple cores, then application code execution may continue in all but one core, unless there is a conflict in ressources, like memory access or access to other peripheral units.
This mechanism is a basic one, to be found in almost every CPU design.

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: disable_irq not effective

Post by jedie » Fri Oct 05, 2018 10:51 am

Roberthh wrote:
Wed Oct 03, 2018 9:47 am

Code: Select all

p14.irq(trigger=Pin.IRQ_FALLING, handler=callback, hard=True)
Here on my ESP32 i get: TypeError: extra keyword arguments given

Is hard a extension on ESP8266 ?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: disable_irq not effective

Post by Roberthh » Fri Oct 05, 2018 11:17 am

Is hard a extension on ESP8266 ?
Yes and no. It is not supported in the ESP32 port, but in the ESP8266 and STM32 port.
I have no clue why it is missing in the ESP32 port. Maybe a simple omission.

jmi2
Posts: 21
Joined: Mon Oct 01, 2018 9:31 pm

Re: disable_irq not effective

Post by jmi2 » Fri Oct 05, 2018 11:26 am

just looking here
https://github.com/micropython/micropyt ... 2878/files
mp_handle_pending(); is actually interesting one.

and interesting call of that one is from ets_event_poll() of
https://github.com/micropython/micropyt ... sp_mphal.c

which is called from all delay functions - https://github.com/micropython/micropyt ... sp_mphal.c)
and when waiting for UART https://github.com/micropython/micropyt ... 266/uart.c

I still would like to test, how it would behave, if i would disconenct UART, remove time.sleep_ms call and use soft interrupts. I can imagine, there will be no callback call at all in this case.

btw. during these tests i realized probably, why i got once changesCountLocked=2 while using hard=True.
Reason seems to be, that i didn't perform reset of board, hence my previous script was still running. And when i pasted new script, it gets executed in same context, so it cleared counters first, but before it redefined callback and irq, these two interrupts happend.
Now i'm satisfied, that i understand it :-) Thanks a lot.

jedie
Posts: 252
Joined: Fri Jan 29, 2016 12:32 pm
Contact:

Re: disable_irq not effective

Post by jedie » Fri Oct 05, 2018 11:42 am

Roberthh wrote:
Fri Oct 05, 2018 11:17 am
Is hard a extension on ESP8266 ?
Yes and no. It is not supported in the ESP32 port, but in the ESP8266 and STM32 port.
I have no clue why it is missing in the ESP32 port. Maybe a simple omission.
I have created https://github.com/micropython/micropython/issues/4214 for this.

Post Reply