Skip to content

Commit

Permalink
Fix nasa#55, add timeout to SB receive
Browse files Browse the repository at this point in the history
Apps should not pend forever on software bus receive, because
they should also periodically check CFE_ES_RunLoop even if no
commands were received.
  • Loading branch information
jphickey committed Mar 29, 2021
1 parent dac28c0 commit 531a47f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
13 changes: 10 additions & 3 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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");

Expand Down
11 changes: 11 additions & 0 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*************************************************************************/
Expand Down

0 comments on commit 531a47f

Please sign in to comment.