Skip to content

Commit

Permalink
[amnb] Remove dependency on isResumableRunning()
Browse files Browse the repository at this point in the history
This was blocking the ability to use resumable function in fiber mode
  • Loading branch information
salkinium committed Oct 27, 2024
1 parent 4ecdcfb commit 4ac7efb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
9 changes: 6 additions & 3 deletions examples/nucleo_g071rb/amnb/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
57 changes: 25 additions & 32 deletions src/modm/communication/amnb/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,8 @@ class Node : public modm::Resumable<6>
}

public:
void
update()
{
transmit();
receive();
}

protected:
modm::ResumableResult<void>
transmit()
update_transmit()
{
RF_BEGIN(2);
while(1)
Expand All @@ -150,6 +142,30 @@ class Node : public modm::Resumable<6>
RF_END();
}

modm::ResumableResult<void>
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<void>
send(Message &msg)
{
Expand Down Expand Up @@ -200,29 +216,6 @@ class Node : public modm::Resumable<6>
RF_END();
}

modm::ResumableResult<void>
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)
Expand Down

0 comments on commit 4ac7efb

Please sign in to comment.