does scheduling a callback preclude disabling interrupts?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

does scheduling a callback preclude disabling interrupts?

Post by smhodge » Thu Mar 19, 2020 6:11 pm

I am using the <schedule> method to make an interrupt append an "event number" to a list. Works fine, no problem. My question is when I later on in the top-level code pop an event number off this "stack" do I need to globally disable/re-enable interrupts while I do this? I am suspecting that I don't have to. Is that correct?

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: does scheduling a callback preclude disabling interrupts?

Post by jimmo » Fri Mar 20, 2020 2:28 am

I think we'd need more information about the rest of your program. i.e. is your stack a high-level thing that can handle being pushed while it's in the middle of being popped?

schedule will cause the scheduled code to be executed synchronously between two VM instructions at some point in the future.

So it's not so much the interrupt handler that needs to be disabled but that your scheduled push code might be happening right in the middle of a pop. Disabling interrupts might not help because the scheduler can still run a previously scheduled event.

Instead you might want to do something like have a flag to "protect" the stack. If the push function (called by the scheduler) sees this flag set, then it can re-schedule itself. The pop function can set this flag while it's doing the pop.

smhodge
Posts: 86
Joined: Tue Jan 22, 2019 2:16 am
Location: Kirkland, WA, USA

Re: does scheduling a callback preclude disabling interrupts?

Post by smhodge » Fri Mar 20, 2020 4:00 pm

Thanks, I'll use your flag suggestion.

Post Reply