Skip to content

Commit

Permalink
[sblib] Consider acknowledge frames in now renamed sendingTelegram
Browse files Browse the repository at this point in the history
Formerly, `Bus::sendingTelegram()` returned `true` iff there was a data
frame ("telegram") to send. However, several call sites actually need
to know whether there is any frame to send, i.e. both data and
acknowledge frames are relevant.

To address this requirement, rename `sendingTelegram` to `sendingFrame`
and make it consider acknowledge frames as well.

Also provide some reasoning for the condition in `BcuBase::loop()`, so
hopefully we do not need to wonder about it again.
  • Loading branch information
dallmair committed Mar 29, 2024
1 parent cb573ea commit 39a3992
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/example-txstresstest/src/app_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ BcuBase* setup()
*/
void loop(void)
{
if (!bcu.bus->sendingTelegram() && ((TEST_DELAY_MS <= 0) || (sendTimeout.expired())))
if (!bcu.bus->sendingFrame() && ((TEST_DELAY_MS <= 0) || (sendTimeout.expired())))
{
sendTestTelegram();
}
Expand Down
10 changes: 5 additions & 5 deletions sblib/inc/sblib/eib/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ class Bus
void timerInterruptHandler();

/**
* Test if there is a telegram being sent.
* Test if there is a frame being sent (data frame or acknowledge frame).
*
* @return True if there is a telegram to be sent, false if not.
* @return True if there is a frame to be sent, false if not.
*/
bool sendingTelegram() const;
bool sendingFrame() const;

/**
* Test if there is a received telegram in bus.telegram[].
Expand Down Expand Up @@ -289,9 +289,9 @@ inline void Bus::maxSendBusyRetries(int retries)
sendBusyRetriesMax = retries;
}

inline bool Bus::sendingTelegram() const
inline bool Bus::sendingFrame() const
{
return sendCurTelegram != nullptr;
return sendCurTelegram != nullptr || sendAck != 0;
}

inline bool Bus::telegramReceived() const
Expand Down
15 changes: 13 additions & 2 deletions sblib/src/eib/bcu_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,18 @@ void BcuBase::loop()
bus->loop();
TLayer4::loop();

if (bus->telegramReceived() && !bus->sendingTelegram() && (userRam->status() & BCU_STATUS_TRANSPORT_LAYER))
// We want to process a received telegram only if there is nothing to send because:
//
// 1) Processing the telegram can cause a response telegram, e.g. a T_ACK in
// connection-oriented Transport Layer messages, and we need to have an empty
// buffer to be able to store and send such responses.
//
// 2) When debugging, it's crucial to only stop in safe states, i.e. only when
// there is nothing to send, not even an acknowledge frame. Otherwise, the
// Bus timer is configured to pull the bus low (send a 0 bit) for some time
// and the MCU continues timer operation, even when a breakpoint is active.
//
if (bus->telegramReceived() && !bus->sendingFrame() && (userRam->status() & BCU_STATUS_TRANSPORT_LAYER))
{
processTelegram(bus->telegram, (uint8_t)bus->telegramLen); // if processed successfully, received telegram will be discarded by processTelegram()
}
Expand All @@ -66,7 +77,7 @@ void BcuBase::loop()
}

// Rest of this function is only relevant if currently able to send another telegram.
if (bus->sendingTelegram())
if (bus->sendingFrame())
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion sblib/src/eib/bcu_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void BcuDefault::loop()
BcuBase::loop(); // check processTelegram and programming button state

// Rest of this function is only relevant if currently able to send another telegram.
if (bus->sendingTelegram())
if (bus->sendingFrame())
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions sblib/src/eib/bus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool Bus::canPause(bool waitForTelegramSent)
// cannot pause as we must retry within a certain time frame.
// * have not sent the telegram yet, it depends on @ref waitForTelegramSent whether the user
// wants us to pause or not.
if (sendingTelegram())
if (sendCurTelegram != nullptr)
{
if (repeatTelegram)
return false;
Expand Down Expand Up @@ -219,7 +219,7 @@ void Bus::prepareTelegram(unsigned char* telegram, unsigned short length) const
*
* Is called from within the BCU-loop method. Is blocking if there is no space
* in the Telegram buffer (as we have only one buffer at BCU level, the check for buffer free is
* in the BCU-loop on bus.sendingTelegram())
* in the BCU-loop on bus.sendingFrame())
*
* Send a telegram. The checksum byte will be added at the end of telegram[].
* Ensure that there is at least one byte space at the end of telegram[].
Expand Down

0 comments on commit 39a3992

Please sign in to comment.