Page 1 of 1

Raspberry Pico Statemachine Restart

Posted: Thu Apr 22, 2021 11:53 am
by GerryKeely
Hi

What is the purpose of the new statemachine restart function in MP 1.15.
A small sample of its use would be appreciated.
Regards & Thank you

Gerry

Re: Raspberry Pico Statemachine Restart

Posted: Thu Apr 22, 2021 12:44 pm
by hippy
Looking at the source code it appears to offer the ability to set the execution address of a StateMachine. It effectively allows 'sm.exec("jmp(...)")' though I haven't examined its exact implementation. It seems it may only allow restart from an initial address rather than an arbitrary address as there is no parameter allowed. Thus an example would probably be ...

Code: Select all

sm = StateMachine( ... )

# Do things

sm.restart()
Related discussion : https://www.raspberrypi.org/forums/view ... 6&t=308077

Re: Raspberry Pico Statemachine Restart

Posted: Thu Apr 22, 2021 1:00 pm
by Roberthh
The intention is to restart the state machine again from the initial address in it#s initial state. That is useful for state machines that stuck in a certain state, e.g. because the input data was incomplete. Then, timeout checking can be done outside the state machine.

A good example is the simplified DHT22 driver in this document; https://github.com/robert-hh/RP2040-Exa ... r/rp2_util, which does no timeout-checking in the state machine code.
The sample code uses the viper version of sm.restart(), but besides that it demonstrates the application.

For jumps to other addresses you can indeed use the sm.exec() method. But since this jump requires a hardcoded address, and that is usually not known in the Python code, it is hardly ever useful.

Re: Raspberry Pico Statemachine Restart

Posted: Thu Apr 22, 2021 1:34 pm
by GerryKeely
Hippy/Roberthh
Thank you both for your prompt replies.

regards

Gerry