.. include:: Firmware: Dedicated Thread For CAN Transmission =============================================== .. topic:: Teacher's note * Talk about priorities (we'll be creating a medium priority thread) * After transformation: shorten the critical section by relieving it out message queue operation .. image:: fsm-can-thread.svg :scale: 80% Plan ---- **"Physical" Separation** * In ``main()``, create a message queue * In ``main()`` create a medium priority thread, and pass it * The queue's read end * A CAN controller from :doc:`../can-jf0815-blocking/index` * Pass the write end to the FSM * Remove CAN ISR from FSM * In ``FSM::_state_change()``, write into the message queue **Decouple FSM From CAN** * All we want is *state change notifications* * From FSM point of view, CAN is irrelevant * |longrightarrow| Message queue carries plain FSM state * Frame created in CAN-thread ``main()``: CAN Thread ---------------------- .. literalinclude:: code/main.cpp :caption: :download:`code/main.cpp` :language: c++ FSM: Send State On Message Queue -------------------------------- .. literalinclude:: code/fsm.h :caption: :download:`code/fsm.h` :language: c++ .. literalinclude:: code/fsm.cpp :caption: :download:`code/fsm.cpp` :language: c++