Callback fuzziness???

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
srogers
Posts: 11
Joined: Sun Feb 06, 2022 12:25 am

Callback fuzziness???

Post by srogers » Fri Feb 11, 2022 6:56 pm

I am trying to understand the meaning of the following 'tip' for the building of interrupt handling code. The following tip can be found at:

https://docs.micropython.org/en/latest/ ... rules.html

  • Where an ISR returns multiple bytes use a pre-allocated bytearray. If multiple integers are to be shared between an ISR and the main program consider an array (array.array).
When I looked at how to set up an interrupt handler (for a Timer class),I've seen examples like this:

Code: Select all

# -----------------------------------------
def mycallback(t):
    pass.

tim = machine.Timer()
tim.init(mode = Timer.PERIODIC, period = 1000, callback = mycallback)
# -----------------------------------------------
What I do not understand is how does a callback (interrupt handler) like mycallback(t) above return anything, much less a pre-allocated buffer?

Did the hint mean to say something other than return'? Did the hint mean to say that the ISR should update a pre-allocated memory buffer like a pre-allocated bytearray or a pre-allocated array.array? If this is not the case, how does one construct an ISR that 'returns' a pre-allocated buffer with the 'return' reserved word, and how does it get passed back via the callback function return?

fivdi
Posts: 16
Joined: Thu Feb 03, 2022 10:28 pm
Contact:

Re: Callback fuzziness???

Post by fivdi » Fri Feb 11, 2022 11:01 pm

srogers wrote:
Fri Feb 11, 2022 6:56 pm
Did the hint mean to say something other than return'?
I guess the word return is overloaded. In the context of an ISR the returned data doesn't mean the value sent back to the ISR caller with a return statement. It means the data that the ISR knows about that it needs to share with (or return to) the main program.
srogers wrote:
Fri Feb 11, 2022 6:56 pm
Did the hint mean to say that the ISR should update a pre-allocated memory buffer like a pre-allocated bytearray or a pre-allocated array.array?
Yes, this is what it means.

The "Writing interrupt handlers" documentation has a section titled Critical sections showing how this can be done.

Post Reply