-
Notifications
You must be signed in to change notification settings - Fork 21
Description
The suggestions by @jpcornil-git are:
- To change
main.cpp
to something like:
void setup() {
// Objects running in async context
GlobalCom::init();
GlobalKnitter::init();
GlobalLedGreen::init();
GlobalLedYellow::init();
GlobalBeeper::init();
// Objects running in interrupt context
GlobalEncoders::init();
}
void loop() {
// Non-blocking methods/cooperative RR scheduling
GlobalCom::update();
GlobalKnitter::update();
GlobalLedGreen::update();
GlobalLedYellow::update();
GlobalBeeper::update();
}
-
fsm
should really be part of theknitter
object whileisr
code should move fromknitter
toencoders
-
care should be taken to synchronize handover of machine state data between interrupt and main contexts
An example of a bug is the following:
At the moment this is done in the interrupt context (https://github.com/AllYarnsAreBeautiful/ayab-firmware/blob/v1.0-dev/src/ayab/knitter.cpp#L107) but it is not safe because if an interrupt fires between L402 and L403 of the same file, m_direction
may change in-between.
To fix this, Knitter::update()
should call, before running the fsm::update()
, an encoder update()
method that enter a critical section/disable interrupts, update machine state data, exit the critical section and return.
This bug is mostly hidden today as most of the code is executed after and interrupt/before the next one but if something takes more time than expected and delay fsm code such that it hits the next interrupt it may expose it (and a webserver will add more tasks moving forward).