From 531a47f3a486a4be4615e25947c1031edb499cd0 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 27 Apr 2020 16:29:01 -0400 Subject: [PATCH] Fix #55, add timeout to SB receive Apps should not pend forever on software bus receive, because they should also periodically check CFE_ES_RunLoop even if no commands were received. --- fsw/src/sample_app.c | 13 ++++++++++--- fsw/src/sample_app.h | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 9c47dbb..2e8f15a 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -82,8 +82,14 @@ void SAMPLE_APP_Main(void) */ CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID); - /* Pend on receipt of command packet */ - status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER); + /* + * Pend on receipt of command packet + * + * Note that apps should not wait forever here, to ensure + * that the status of CFE_ES_RunLoop() is also checked periodically, + * even if no software bus messages arrive. + */ + status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_SB_WAIT_PERIOD); /* ** Performance Log Entry Stamp @@ -94,8 +100,9 @@ void SAMPLE_APP_Main(void) { SAMPLE_APP_ProcessCommandPacket(SBBufPtr); } - else + else if (status != CFE_SB_TIME_OUT) { + /* Timeout is normal if no activity, but anything else constitutes a real error */ CFE_EVS_SendEvent(SAMPLE_APP_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "SAMPLE APP: SB Pipe Read Error, App Will Exit"); diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index a7fb92c..3167864 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -53,6 +53,17 @@ #define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 #define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 + +/** + * \brief Amount of time to wait in CFE_SB_RecieveBuffer + * + * Applications need to wait for messages to arrive on the Software Bus, + * but this wait should be time limited to ensure that the app also + * periodically checks the status of CFE_ES_RunLoop(), in case an + * administrative command comes in. + */ +#define SAMPLE_APP_SB_WAIT_PERIOD 1000 + /************************************************************************ ** Type Definitions *************************************************************************/