From 968d99c11cc3f3cb7f9b1450fb968e9d121ca9ca Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Sun, 27 Oct 2024 10:27:19 +0100 Subject: [PATCH] [amnb] Remove dependency on isResumableRunning() This was blocking the ability to use resumable function in fiber mode --- examples/nucleo_g071rb/amnb/main.cpp | 9 +++-- src/modm/communication/amnb/node.hpp | 57 ++++++++++++---------------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/examples/nucleo_g071rb/amnb/main.cpp b/examples/nucleo_g071rb/amnb/main.cpp index 4eab5b35a8..588db066e5 100644 --- a/examples/nucleo_g071rb/amnb/main.cpp +++ b/examples/nucleo_g071rb/amnb/main.cpp @@ -137,9 +137,12 @@ main() while (true) { - node1.update(); - node2.update(); - node3.update(); + node1.update_transmit(); + node1.update_receive(); + node2.update_transmit(); + node2.update_receive(); + node3.update_transmit(); + node3.update_receive(); thread.update(); } diff --git a/src/modm/communication/amnb/node.hpp b/src/modm/communication/amnb/node.hpp index e88928bb08..893348b4db 100644 --- a/src/modm/communication/amnb/node.hpp +++ b/src/modm/communication/amnb/node.hpp @@ -125,16 +125,8 @@ class Node : public modm::Resumable<6> } public: - void - update() - { - transmit(); - receive(); - } - -protected: modm::ResumableResult - transmit() + update_transmit() { RF_BEGIN(2); while(1) @@ -150,6 +142,30 @@ class Node : public modm::Resumable<6> RF_END(); } + modm::ResumableResult + update_receive() + { + RF_BEGIN(5); + while(1) + { + rx_msg.deallocate(); // deallocates previous message + if (RF_CALL(interface.receiveHeader(&rx_msg)) == InterfaceStatus::Ok) + { + // Check lists if we are interested in this message + is_rx_msg_for_us = handleRxMessage(false); + // Receive the message data, only allocate if it's for us + if (RF_CALL(interface.receiveData(&rx_msg, is_rx_msg_for_us)) == InterfaceStatus::Ok) + { + // Only handle message *with* data if it's for us + if (is_rx_msg_for_us) handleRxMessage(true); + } + } + RF_YIELD(); + } + RF_END(); + } + +protected: modm::ResumableResult send(Message &msg) { @@ -200,29 +216,6 @@ class Node : public modm::Resumable<6> RF_END(); } - modm::ResumableResult - receive() - { - RF_BEGIN(5); - while(1) - { - rx_msg.deallocate(); // deallocates previous message - if (RF_CALL(interface.receiveHeader(&rx_msg)) == InterfaceStatus::Ok) - { - // Check lists if we are interested in this message - is_rx_msg_for_us = handleRxMessage(false); - // Receive the message data, only allocate if it's for us - if (RF_CALL(interface.receiveData(&rx_msg, is_rx_msg_for_us)) == InterfaceStatus::Ok) - { - // Only handle message *with* data if it's for us - if (is_rx_msg_for_us) handleRxMessage(true); - } - } - RF_YIELD(); - } - RF_END(); - } - protected: bool handleRxMessage(bool complete)