Skip to content

Commit

Permalink
Fix nasa#84, Removing NextProcNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Tvisha Andharia committed Dec 13, 2024
1 parent 87c9d87 commit 56f3d21
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 286 deletions.
4 changes: 1 addition & 3 deletions fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ CFE_Status_t SC_AppInit(void)
memset(&SC_AppData, 0, sizeof(SC_AppData));

/* Number of ATS and RTS commands already executed this second */
SC_OperData.NumCmdsSec = 0;
SC_OperData.NumCmdsWakeup = 0;

/* Continue ATS execution if ATS command checksum fails */
SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = SC_CONT_ON_FAILURE_START;
Expand All @@ -155,8 +155,6 @@ CFE_Status_t SC_AppInit(void)
/* assign the time ref accessor from the compile-time option */
SC_AppData.TimeRef = SC_LookupTimeAccessor(SC_TIME_TO_USE);

/* Make sure nothing is running */
SC_AppData.NextProcNumber = SC_Process_NONE;
/* SAD: SC_Process_ATP is 0, within the valid index range of NextCmdTime array, which has 2 elements */
SC_AppData.NextCmdTime[SC_Process_ATP] = SC_MAX_TIME;
/* SAD: SC_Process_RTP is 1, within the valid index range of NextCmdTime array, which has 2 elements */
Expand Down
3 changes: 1 addition & 2 deletions fsw/src/sc_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ typedef struct

int32 AtsDupTestArray[SC_MAX_ATS_CMDS]; /**< \brief ATS test for duplicate cmd numbers */

uint16 NumCmdsSec; /**< \brief the num of cmds that have gone out in a one second period */
uint16 NumCmdsWakeup; /**< \brief the num of cmds that have gone out in this wakeup cycle */

SC_HkTlm_t HkPacket; /**< \brief SC Housekeeping structure */
} SC_OperData_t;
Expand Down Expand Up @@ -368,7 +368,6 @@ typedef struct

bool EnableHeaderUpdate; /**< \brief whether to update headers in outgoing messages */

SC_Process_Enum_t NextProcNumber; /**< \brief the next command processor number */
uint32 NextCmdTime[2]; /**< \brief The overall next command time for ATP (0) and command wakeup count for RTP (1) */
SC_AbsTimeTag_t CurrentTime; /**< \brief this is the current time for SC */
uint32 CurrentWakeupCount; /**< \brief this is the current wakeup count for SC */
Expand Down
26 changes: 14 additions & 12 deletions fsw/src/sc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ void SC_ProcessAtpCmd(void)
*/

if ((SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) &&
(SC_AppData.NextProcNumber == SC_Process_ATP) &&
(!SC_CompareAbsTime(SC_AppData.NextCmdTime[SC_Process_ATP], SC_AppData.CurrentTime)))
{
/*
Expand Down Expand Up @@ -113,7 +112,7 @@ void SC_ProcessAtpCmd(void)
/*
** Count the command for the rate limiter
*/
SC_OperData.NumCmdsSec++;
SC_OperData.NumCmdsWakeup++;

/*
** First check to see if the command is a switch command,
Expand Down Expand Up @@ -312,14 +311,13 @@ void SC_ProcessRtpCommand(void)

RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex);

if ((SC_AppData.NextProcNumber == SC_Process_RTP) &&
(SC_AppData.NextCmdTime[SC_Process_RTP] <= SC_AppData.CurrentWakeupCount) && (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING))
if ((SC_AppData.NextCmdTime[SC_Process_RTP] <= SC_AppData.CurrentWakeupCount) && (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING))
{
/*
** Count the command for the rate limiter
** even if the command fails
*/
SC_OperData.NumCmdsSec++;
SC_OperData.NumCmdsWakeup++;

/*
** Get the Command offset within the RTS
Expand Down Expand Up @@ -543,11 +541,11 @@ void SC_WakeupCmd(const SC_WakeupCmd_t *Cmd)
/*
* Time to execute a command in the SC memory
*/
while (SC_OperData.NumCmdsSec < SC_MAX_CMDS_PER_WAKEUP)
while (SC_OperData.NumCmdsWakeup < SC_MAX_CMDS_PER_WAKEUP)
{
SC_UpdateNextTime();
SC_GetNextRtsTime();

CurrentNumCmds = SC_OperData.NumCmdsSec;
CurrentNumCmds = SC_OperData.NumCmdsWakeup;

/*
* Check to see if there is an ATS switch Pending, if so service it.
Expand All @@ -559,17 +557,21 @@ void SC_WakeupCmd(const SC_WakeupCmd_t *Cmd)

SC_ProcessAtpCmd();

SC_ProcessRtpCommand();

if (CurrentNumCmds == SC_OperData.NumCmdsWakeup)
{
SC_ProcessRtpCommand();
}

/*
* No commands could be processed
*/
if (CurrentNumCmds == SC_OperData.NumCmdsSec) {
if (CurrentNumCmds == SC_OperData.NumCmdsWakeup)
{
break;
}
}

SC_OperData.NumCmdsSec = 0;
SC_OperData.NumCmdsWakeup = 0;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
43 changes: 0 additions & 43 deletions fsw/src/sc_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,49 +96,6 @@ void SC_GetNextRtsTime(void)
} /* end if */
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Decides whether an RTS or ATS command gets scheduled next */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_UpdateNextTime(void)
{
/*
** First, find out which RTS needs to run next
*/
SC_GetNextRtsTime();

/*
** Start out with a default, no processors need to run next
*/
SC_AppData.NextProcNumber = SC_Process_NONE;

/*
** Check to see if the ATP needs to schedule commands
*/
if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING)
{
SC_AppData.NextProcNumber = SC_Process_ATP;
}
/*
** Last, check to see if there is an RTS that needs to schedule commands
** This is determined by the RTS number in the RTP control block
** If it is zero, there is no RTS that needs to run
*/
if (SC_RtsNumIsValid(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum))
{
/*
** If the RTP needs to send commands, only send them if
** the ATP doesn't - the ATP has priority
*/

if (SC_AppData.NextProcNumber != SC_Process_ATP)
{
SC_AppData.NextProcNumber = SC_Process_RTP;
}
} /* end if */
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Gets the next RTS Command */
Expand Down
12 changes: 0 additions & 12 deletions fsw/src/sc_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,6 @@
*/
void SC_GetNextRtsTime(void);

/**
* \brief Decides whether the ATS or RTS runs next
*
* \par Description
* This function compares the next command times for the RTS
* and the ATS and decides which one to schedule next.
*
* \par Assumptions, External Events, and Notes:
* None
*/
void SC_UpdateNextTime(void);

/**
* \brief Gets the next RTS command to run
*
Expand Down
3 changes: 1 addition & 2 deletions fsw/tables/sc_rts002.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ SC_RtsTable002_t SC_Rts002 = {

/* 3 */
.rts.hdr3.WakeupCount = 5,
.rts.cmd3.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_NOOP_CC, SC_NOOP_CKSUM)
};
.rts.cmd3.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_NOOP_CC, SC_NOOP_CKSUM)};

/* Macro for table structure */
CFE_TBL_FILEDEF(SC_Rts002, SC.RTS_TBL002, SC Example RTS_TBL002, sc_rts002.tbl)
6 changes: 2 additions & 4 deletions unit-test/sc_app_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ void SC_AppInit_Test_NominalPowerOnReset(void)
memset(&Expected_SC_OperData, 0, sizeof(Expected_SC_OperData));
memset(&Expected_SC_AppData, 0, sizeof(Expected_SC_AppData));

Expected_SC_AppData.NextProcNumber = SC_Process_NONE;
Expected_SC_AppData.NextCmdTime[SC_Process_ATP] = SC_MAX_TIME;
Expected_SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_WAKEUP_CNT;
Expected_SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_POWER_ON);
Expand Down Expand Up @@ -183,7 +182,7 @@ void SC_AppInit_Test_NominalPowerOnReset(void)
sizeof(Expected_SC_OperData.AtsCmdStatusHandle), "AtsCmdStatusHandle");
UtAssert_MemCmp(&SC_OperData.AtsDupTestArray, &Expected_SC_OperData.AtsDupTestArray,
sizeof(Expected_SC_OperData.AtsDupTestArray), "21");
UtAssert_MemCmp(&SC_OperData.NumCmdsSec, &Expected_SC_OperData.NumCmdsSec, sizeof(Expected_SC_OperData.NumCmdsSec),
UtAssert_MemCmp(&SC_OperData.NumCmdsWakeup, &Expected_SC_OperData.NumCmdsWakeup, sizeof(Expected_SC_OperData.NumCmdsWakeup),
"22");
UtAssert_MemCmp(&SC_OperData.HkPacket, &Expected_SC_OperData.HkPacket, sizeof(Expected_SC_OperData.HkPacket), "23");

Expand All @@ -210,7 +209,6 @@ void SC_AppInit_Test_Nominal(void)
memset(&Expected_SC_OperData, 0, sizeof(Expected_SC_OperData));
memset(&Expected_SC_AppData, 0, sizeof(Expected_SC_AppData));

Expected_SC_AppData.NextProcNumber = SC_Process_NONE;
Expected_SC_AppData.NextCmdTime[SC_Process_ATP] = SC_MAX_TIME;
Expected_SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_WAKEUP_CNT;
Expected_SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_PROCESSOR);
Expand Down Expand Up @@ -247,7 +245,7 @@ void SC_AppInit_Test_Nominal(void)
sizeof(Expected_SC_OperData.AtsCmdStatusHandle), "AtsCmdStatusHandle");
UtAssert_MemCmp(&SC_OperData.AtsDupTestArray, &Expected_SC_OperData.AtsDupTestArray,
sizeof(Expected_SC_OperData.AtsDupTestArray), "21");
UtAssert_MemCmp(&SC_OperData.NumCmdsSec, &Expected_SC_OperData.NumCmdsSec, sizeof(Expected_SC_OperData.NumCmdsSec),
UtAssert_MemCmp(&SC_OperData.NumCmdsWakeup, &Expected_SC_OperData.NumCmdsWakeup, sizeof(Expected_SC_OperData.NumCmdsWakeup),
"22");
UtAssert_MemCmp(&SC_OperData.HkPacket, &Expected_SC_OperData.HkPacket, sizeof(Expected_SC_OperData.HkPacket), "23");

Expand Down
Loading

0 comments on commit 56f3d21

Please sign in to comment.