Skip to content

Commit

Permalink
Fix #117, change local array refs to object pointer
Browse files Browse the repository at this point in the history
This changes all "info" table access to go through an object pointer
that is obtained via an accessor method.
  • Loading branch information
jphickey committed Nov 9, 2023
1 parent a0a1380 commit 99467c4
Show file tree
Hide file tree
Showing 14 changed files with 1,641 additions and 1,010 deletions.
22 changes: 14 additions & 8 deletions fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,11 @@ CFE_Status_t SC_AppInit(void)

CFE_Status_t SC_InitTables(void)
{
CFE_Status_t Result;
int32 i;
int32 j;
CFE_Status_t Result;
int32 i;
int32 j;
SC_RtsInfoEntry_t * RtsInfoPtr;
SC_AtsCmdStatusEntry_t *StatusEntryPtr;

/* Must be able to register all tables with cFE Table Services */
Result = SC_RegisterAllTables();
Expand Down Expand Up @@ -272,17 +274,21 @@ CFE_Status_t SC_InitTables(void)
{
for (j = 0; j < SC_MAX_ATS_CMDS; j++)
{
SC_OperData.AtsCmdStatusTblAddr[i][j] = SC_Status_EMPTY;
StatusEntryPtr = SC_GetAtsStatusEntryForCommand(SC_ATS_IDX_C(i), SC_COMMAND_IDX_C(j));

StatusEntryPtr->Status = SC_Status_EMPTY;
}
}

/* RTS information table */
for (i = 0; i < SC_NUMBER_OF_RTS; i++)
{
SC_OperData.RtsInfoTblAddr[i].NextCommandTime = SC_MAX_TIME;
SC_OperData.RtsInfoTblAddr[i].NextCommandPtr = SC_ENTRY_OFFSET_FIRST;
SC_OperData.RtsInfoTblAddr[i].RtsStatus = SC_Status_EMPTY;
SC_OperData.RtsInfoTblAddr[i].DisabledFlag = true;
RtsInfoPtr = SC_GetRtsInfoObject(SC_RTS_IDX_C(i));

RtsInfoPtr->NextCommandTime = SC_MAX_TIME;
RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST;
RtsInfoPtr->RtsStatus = SC_Status_EMPTY;
RtsInfoPtr->DisabledFlag = true;
}

/* Load default RTS tables */
Expand Down
126 changes: 122 additions & 4 deletions fsw/src/sc_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,16 @@ void SC_RegisterManageCmds(void);

#define SC_BYTES_IN_ATS_APPEND_ENTRY 2 /**< \brief Bytes in an ATS append table entry */

/**
* @brief Entry definition for the command status table
*
* This table stores the status of commands executed in an ATS
*/
typedef struct SC_AtsCmdStatusEntry
{
SC_Status_Enum_t Status;
} SC_AtsCmdStatusEntry_t;

/**
* \brief SC Operational Data Structure
*
Expand Down Expand Up @@ -307,8 +317,8 @@ typedef struct
CFE_TBL_Handle_t AtsCtrlBlckHandle; /**< \brief Table handle for the ATP ctrl block */
SC_AtpControlBlock_t *AtsCtrlBlckAddr; /**< \brief Table address for the ATP ctrl block*/

CFE_TBL_Handle_t AtsCmdStatusHandle[SC_NUMBER_OF_ATS]; /**< \brief ATS Cmd Status table handle */
SC_Status_Enum_t *AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS]; /**< \brief ATS Cmd Status table address */
CFE_TBL_Handle_t AtsCmdStatusHandle[SC_NUMBER_OF_ATS]; /**< \brief ATS Cmd Status table handle */
SC_AtsCmdStatusEntry_t *AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS]; /**< \brief ATS Cmd Status table address */

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

Expand All @@ -317,19 +327,39 @@ typedef struct
SC_HkTlm_t HkPacket; /**< \brief SC Housekeeping structure */
} SC_OperData_t;

/**
* @brief Entry definition for the command entry offset table
*
* This table stores the offset of commands within in an ATS
*/
typedef struct SC_AtsCmdEntryOffsetRecord
{
SC_EntryOffset_t Offset;
} SC_AtsCmdEntryOffsetRecord_t;

/**
* @brief Entry definition for the command number table
*
* This table maps the sequence numbers to command numbers in an ATS
*/
typedef struct SC_AtsCmdNumRecord
{
SC_CommandNum_t CmdNum;
} SC_AtsCmdNumRecord_t;

/**
* \brief SC Application Data Structure
* This structure is used by the application to process time ordered commands.
*/
typedef struct
{
SC_CommandNum_t AtsTimeIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS];
SC_AtsCmdNumRecord_t AtsTimeIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS];
/**< \brief This table is used to keep a time ordered listing
of ATS command indexes (0 based). The first entry
in this table holds the command index of the command that will execute
first, the second entry has the index of the 2nd cmd, etc.. */

SC_EntryOffset_t AtsCmdIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS];
SC_AtsCmdEntryOffsetRecord_t AtsCmdIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS];
/**< \brief This table is used to keep a list of ATS table command offsets.
These offsets correspond to the addresses of ATS commands located in the ATS table.
The index used is the ATS command index with values from 0 to SC_MAX_ATS_CMDS-1 */
Expand All @@ -351,4 +381,92 @@ typedef struct
extern SC_AppData_t SC_AppData;
extern SC_OperData_t SC_OperData;

/**
* @brief Locates the Info object associated with the given RTS index
*
* @param RtsIndex The RTS index
* @returns The info object for the given RTS
*/
static inline SC_RtsInfoEntry_t *SC_GetRtsInfoObject(SC_RtsIndex_t RtsIndex)
{
return &SC_OperData.RtsInfoTblAddr[SC_IDX_AS_UINT(RtsIndex)];
}

/**
* @brief Locates the Info object associated with the given ATS index
*
* @param AtsIndex The ATS index
* @returns The info object for the given ATS
*/
static inline SC_AtsInfoTable_t *SC_GetAtsInfoObject(SC_AtsIndex_t AtsIndex)
{
return &SC_OperData.AtsInfoTblAddr[SC_IDX_AS_UINT(AtsIndex)];
}

/**
* @brief Locates a specific entry within an RTS
*
* The entry is specified via its offset (in words) from the start of the RTS
*
* @param RtsIndex The RTS index
* @param EntryOffset The offset from the start of the RTS, in words
* @returns Pointer to the entry within the RTS
*/
static inline SC_RtsEntry_t *SC_GetRtsEntryAtOffset(SC_RtsIndex_t RtsIndex, SC_EntryOffset_t EntryOffset)
{
return (SC_RtsEntry_t *)&SC_OperData.RtsTblAddr[SC_IDX_AS_UINT(RtsIndex)][SC_IDX_AS_UINT(EntryOffset)];
}

/**
* @brief Locates a specific entry within an ATS
*
* The entry is specified via its offset (in words) from the start of the ATS
*
* @param AtsIndex The ATS index
* @param EntryOffset The offset from the start of the ATS, in words
* @returns Pointer to the entry within the ATS
*/
static inline SC_AtsEntry_t *SC_GetAtsEntryAtOffset(SC_AtsIndex_t AtsIndex, SC_EntryOffset_t EntryOffset)
{
return (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[SC_IDX_AS_UINT(AtsIndex)][SC_IDX_AS_UINT(EntryOffset)];
}

/**
* @brief Locates the record that maps the command index to an ATS entry offset
*
* @param AtsIndex The ATS index
* @param CommandIndex The command index
* @returns Pointer to the SC_AtsCmdEntryOffsetRecord_t object
*/
static inline SC_AtsCmdEntryOffsetRecord_t *SC_GetAtsEntryOffsetForCmd(SC_AtsIndex_t AtsIndex,
SC_CommandIndex_t CommandIndex)
{
return &SC_AppData.AtsCmdIndexBuffer[SC_IDX_AS_UINT(AtsIndex)][SC_IDX_AS_UINT(CommandIndex)];
}

/**
* @brief Locates the record that maps the sequence index to an ATS command number
*
* @param AtsIndex The ATS index
* @param SeqIndex The sequence index
* @returns Pointer to the SC_AtsCmdNumRecord_t object
*/
static inline SC_AtsCmdNumRecord_t *SC_GetAtsCommandNumAtSeq(SC_AtsIndex_t AtsIndex, SC_SeqIndex_t SeqIndex)
{
return &SC_AppData.AtsTimeIndexBuffer[SC_IDX_AS_UINT(AtsIndex)][SC_IDX_AS_UINT(SeqIndex)];
}

/**
* @brief Locates the record that holds the status of an ATS command
*
* @param AtsIndex The ATS index
* @param CommandIndex The command index
* @returns Pointer to the SC_AtsCmdStatusEntry_t object
*/
static inline SC_AtsCmdStatusEntry_t *SC_GetAtsStatusEntryForCommand(SC_AtsIndex_t AtsIndex,
SC_CommandIndex_t CommandIndex)
{
return &SC_OperData.AtsCmdStatusTblAddr[SC_IDX_AS_UINT(AtsIndex)][SC_IDX_AS_UINT(CommandIndex)];
}

#endif
Loading

0 comments on commit 99467c4

Please sign in to comment.