From ee3db0e2191652a7c55a5e1bfe9a744a5f62b7c1 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 18 Oct 2023 15:32:15 -0400 Subject: [PATCH 1/4] Fix #116, scrub types used for indexing and identification Introduces header files and dedicated types for the purpose of indexing and identification of SC objects and structures. This include ATS/RTS identification, time sequence numbers, word offsets, and command numbers. Use a separate typedef for each, and document its purpose/intent in the description, then update all FSW to use the typedef rather than a simple uint16. Note - in places where the CMD/TLM interface were _not_ using a uint16, the old type is kept. This maintains backward compatibility of the I/F. --- config/default_sc_extern_typedefs.h | 131 +++++++++ config/default_sc_msgdefs.h | 62 ++--- config/default_sc_tbldefs.h | 3 +- fsw/src/sc_app.c | 16 +- fsw/src/sc_app.h | 54 ++-- fsw/src/sc_atsrq.c | 90 ++++--- fsw/src/sc_atsrq.h | 3 +- fsw/src/sc_cmds.c | 88 +++---- fsw/src/sc_index_types.h | 396 ++++++++++++++++++++++++++++ fsw/src/sc_loads.c | 69 +++-- fsw/src/sc_loads.h | 13 +- fsw/src/sc_rtsrq.c | 196 +++++++------- fsw/src/sc_rtsrq.h | 7 +- fsw/src/sc_state.c | 56 ++-- fsw/src/sc_utils.c | 4 +- fsw/src/sc_utils.h | 2 +- fsw/tables/sc_ats1.c | 12 +- fsw/tables/sc_rts001.c | 4 +- mission_build.cmake | 1 + unit-test/sc_app_tests.c | 4 +- unit-test/sc_atsrq_tests.c | 194 ++++++++------ unit-test/sc_cmds_tests.c | 395 ++++++++++++++------------- unit-test/sc_loads_tests.c | 281 ++++++++++++-------- unit-test/sc_rtsrq_tests.c | 228 ++++++++-------- unit-test/sc_state_tests.c | 255 ++++++++++-------- unit-test/sc_utils_tests.c | 8 +- unit-test/stubs/sc_atsrq_stubs.c | 4 +- unit-test/stubs/sc_loads_stubs.c | 26 +- unit-test/stubs/sc_rtsrq_stubs.c | 8 +- unit-test/stubs/sc_utils_stubs.c | 6 +- unit-test/utilities/sc_test_utils.c | 2 +- unit-test/utilities/sc_test_utils.h | 17 ++ 32 files changed, 1661 insertions(+), 974 deletions(-) create mode 100644 config/default_sc_extern_typedefs.h create mode 100644 fsw/src/sc_index_types.h diff --git a/config/default_sc_extern_typedefs.h b/config/default_sc_extern_typedefs.h new file mode 100644 index 0000000..f54a195 --- /dev/null +++ b/config/default_sc_extern_typedefs.h @@ -0,0 +1,131 @@ +/************************************************************************ + * NASA Docket No. GSC-18,924-1, and identified as “Core Flight + * System (cFS) Stored Command Application version 3.1.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Definition of CFS Stored Command (SC) types that are shared between + * tables, messages, or otherwise need to be known publicly. + */ +#ifndef SC_EXTERN_TYPEDEFS_H +#define SC_EXTERN_TYPEDEFS_H + +#include "common_types.h" + +/** + * @brief An identifier for RTS's + * + * This is a 1-based numeric value that refers to a specific RTS. + * The value of 0 is reserved and is considered invalid/null. + * + * The valid range is [1..SC_NUMBER_OF_RTS] (inclusive) + * + * @note Some code and documentation may also refer to this as an RTS Number. + * This is synonymous with an RTS ID. + */ +typedef uint16 SC_RtsNum_t; + +/** + * @brief An identifier for ATS's + * + * This is a 1-based numeric value that refers to a specific ATS. + * The value of 0 is reserved and is considered invalid/null. + * + * The valid range is [1..SC_NUMBER_OF_ATS] (inclusive) + * + * @note Some code and documentation may also refer to this as an ATS Number. + * This is synonymous with an ATS ID. + * + * Unlike RTS, in many circumstances an alphabetic identifier is also used + * to identify an ATS (e.g. ATS A, ATS B, etc). This is a simple mapping where + * A refers to ATS ID 1, B refers to ATS ID 2, etc. + */ +typedef uint16 SC_AtsNum_t; + +/** + * A command number for ATS's + * + * This is a 1-based numeric value that refers to a specific + * command within an ATS. Each entry within an ATS has one of + * these identifiers on each command in it. + * + * @note RTS sequences do not use this identifier, as these + * commands only have a relative offset from the previous command. + * + * The value of 0 is reserved and is considered invalid/null. + * + * The valid range is [1..SC_MAX_ATS_CMDS] (inclusive) + * + * IMPORTANT: This number only serves to uniquely identify a + * specific command within an ATS. It is _not_ necessarily the + * same as a sequence number within the ATS, as commands may be + * defined in the table any order (that is, they may have absolute + * time stamps that are not in sequence). + */ +typedef uint16 SC_CommandNum_t; + +/** + * @brief Represents an offset into an ATS or RTS buffer + * + * This is a 0-based numeric value that refers to a 32-bit word position + * within the ATS or RTS buffer. This can be used to look up the + * specific command at that position. + * + * The valid range is [0..(SC_ATS_BUFF_SIZE/4)-1] for ATS + * or [0..(SC_RTS_BUFF_SIZE/4)-1] for RTS + * + * @note ATS/RTS Buffers are indexed using 32-bit words. + * To get a byte offset, this value needs to be multiplied by 4. + */ +typedef uint16 SC_EntryOffset_t; + +/** + * Convert from an ID or Number value (e.g. RTS/ATS identifier) to a native unsigned int + * + * This is mainly intended for printf()-style logging, where it should be paired + * with the "%u" conversion specifier. + */ +#define SC_IDNUM_AS_UINT(arg) ((unsigned int)(arg)) + +/** + * Convert from a native integer value (e.g. a literal) to an ID or Number value + * + * This is mainly intended for initializing values from literals or integers + * This is the inverse macro of SC_IDNUM_AS_UINT() + */ +#define SC_IDNUM_FROM_UINT(arg) ((uint16)(arg)) + +/* _INITIALIZER macros to be used in static (e.g. table) definitions that need to resolve at compile time */ +#define SC_RTS_NUM_INITIALIZER(i) SC_IDNUM_FROM_UINT(i) +#define SC_ATS_NUM_INITIALIZER(i) SC_IDNUM_FROM_UINT(i) +#define SC_COMMAND_NUM_INITIALIZER(i) SC_IDNUM_FROM_UINT(i) + +#define SC_IDNUM_EQUAL(arg1, arg2) (SC_IDNUM_AS_UINT(arg1) == SC_IDNUM_AS_UINT(arg2)) +#define SC_IDNUM_IS_NULL(arg) (SC_IDNUM_AS_UINT(arg) == 0) + +/* _C macros to be used in other places that need to resolve at runtime time - these are type safe */ +#define SC_RTS_NUM_C(i) ((SC_RtsNum_t)SC_IDNUM_FROM_UINT(i)) +#define SC_ATS_NUM_C(i) ((SC_AtsNum_t)SC_IDNUM_FROM_UINT(i)) +#define SC_COMMAND_NUM_C(i) ((SC_CommandNum_t)SC_IDNUM_FROM_UINT(i)) + +/* _NULL macros refer to a value that is always reserved */ +#define SC_RTS_NUM_NULL SC_RTS_NUM_C(0) +#define SC_ATS_NUM_NULL SC_ATS_NUM_C(0) +#define SC_COMMAND_NUM_NULL SC_COMMAND_NUM_C(0) + +#endif diff --git a/config/default_sc_msgdefs.h b/config/default_sc_msgdefs.h index fc44770..687bab7 100644 --- a/config/default_sc_msgdefs.h +++ b/config/default_sc_msgdefs.h @@ -28,6 +28,7 @@ #define SC_MSGDEFS_H #include "common_types.h" +#include "sc_extern_typedefs.h" #include "sc_fcncodes.h" /************************************************************************ @@ -160,6 +161,7 @@ enum SC_AtsCont SC_AtsCont_FALSE = false, /**< \brief Do not continue on failure */ SC_AtsCont_TRUE = true /**< \brief Continue on failure */ }; + typedef uint8 SC_AtsCont_Enum_t; #ifndef SC_OMIT_DEPRECATED @@ -194,28 +196,28 @@ typedef struct uint8 CmdCtr; /**< \brief Counts Ground Requests */ uint8 Padding8; /**< \brief Structure padding */ - uint16 SwitchPendFlag; /**< \brief Switch pending flag: 0 = NO, 1 = YES */ - uint16 NumRtsActive; /**< \brief Number of RTSs currently active */ - uint16 RtsNumber; /**< \brief Next RTS number */ - uint16 RtsActiveCtr; /**< \brief Increments when an RTS is started without error */ - uint16 RtsActiveErrCtr; /**< \brief Increments when an attempt to start an RTS fails */ - uint16 AtsCmdCtr; /**< \brief Total ATS cmd cnter counts commands sent by the ATS */ - uint16 AtsCmdErrCtr; /**< \brief Total ATS cmd Error ctr command errors in the ATS */ - uint16 RtsCmdCtr; /**< \brief Counts TOTAL rts cmds that were sent out from ALL active RTSs */ - uint16 RtsCmdErrCtr; /**< \brief Counts TOTAL number of errs from ALL RTSs that are active */ - uint16 LastAtsErrSeq; /**< \brief Last ATS Errant Sequence Num Values: 1 or 2 */ - uint16 LastAtsErrCmd; /**< \brief Last ATS Errant Command Num */ - uint16 LastRtsErrSeq; /**< \brief Last RTS Errant Sequence Num */ - uint16 LastRtsErrCmd; /**< \brief Offset in the RTS buffer for the last command error, in "words" */ - - uint16 AppendCmdArg; /**< \brief ATS selection argument from most recent Append ATS command */ - uint16 AppendEntryCount; /**< \brief Number of cmd entries in current Append ATS table */ - uint16 AppendByteCount; /**< \brief Size of cmd entries in current Append ATS table */ - uint16 AppendLoadCount; /**< \brief Total number of Append ATS table loads */ - uint32 AtpCmdNumber; /**< \brief Current command number */ - uint32 AtpFreeBytes[SC_NUMBER_OF_ATS]; /**< \brief Free Bytes in each ATS */ - uint32 NextRtsTime; /**< \brief Next RTS cmd Absolute Time */ - uint32 NextAtsTime; /**< \brief Next ATS Command Time (seconds) */ + uint16 SwitchPendFlag; /**< \brief Switch pending flag: 0 = NO, 1 = YES */ + uint16 NumRtsActive; /**< \brief Number of RTSs currently active */ + SC_RtsNum_t RtsNum; /**< \brief Next RTS number */ + uint16 RtsActiveCtr; /**< \brief Increments when an RTS is started without error */ + uint16 RtsActiveErrCtr; /**< \brief Increments when an attempt to start an RTS fails */ + uint16 AtsCmdCtr; /**< \brief Total ATS cmd cnter counts commands sent by the ATS */ + uint16 AtsCmdErrCtr; /**< \brief Total ATS cmd Error ctr command errors in the ATS */ + uint16 RtsCmdCtr; /**< \brief Counts TOTAL rts cmds that were sent out from ALL active RTSs */ + uint16 RtsCmdErrCtr; /**< \brief Counts TOTAL number of errs from ALL RTSs that are active */ + SC_AtsNum_t LastAtsErrSeq; /**< \brief Last ATS Errant Sequence Num Values: 1 or 2 */ + SC_CommandNum_t LastAtsErrCmd; /**< \brief Last ATS Errant Command Num */ + SC_RtsNum_t LastRtsErrSeq; /**< \brief Last RTS Errant Sequence Num */ + SC_EntryOffset_t LastRtsErrCmd; /**< \brief Offset in the RTS buffer for the last command error, in "words" */ + + SC_AtsNum_t AppendCmdArg; /**< \brief ATS selection argument from most recent Append ATS command */ + uint16 AppendEntryCount; /**< \brief Number of cmd entries in current Append ATS table */ + uint16 AppendByteCount; /**< \brief Size of cmd entries in current Append ATS table */ + uint16 AppendLoadCount; /**< \brief Total number of Append ATS table loads */ + uint32 AtpCmdNumber; /**< \brief Current command number */ + uint32 AtpFreeBytes[SC_NUMBER_OF_ATS]; /**< \brief Free Bytes in each ATS */ + uint32 NextRtsTime; /**< \brief Next RTS cmd Absolute Time */ + uint32 NextAtsTime; /**< \brief Next ATS Command Time (seconds) */ uint16 RtsExecutingStatus[(SC_NUMBER_OF_RTS + (SC_NUMBER_OF_RTS_IN_UINT16 - 1)) / SC_NUMBER_OF_RTS_IN_UINT16]; /**< \brief RTS executing status bit map where each uint16 represents 16 RTS numbers. Note: array @@ -244,8 +246,8 @@ typedef struct */ typedef struct { - uint16 AtsId; /**< \brief The ID of the ATS to start, 1 = ATS_A, 2 = ATS_B */ - uint16 Padding; /**< \brief Structure padding */ + SC_AtsNum_t AtsNum; /**< \brief The ID of the ATS to start, 1 = ATS_A, 2 = ATS_B */ + uint16 Padding; /**< \brief Structure padding */ } SC_StartAtsCmd_Payload_t; /** @@ -253,8 +255,8 @@ typedef struct */ typedef struct { - uint16 RtsId; /**< \brief The ID of the RTS to start, 1 through #SC_NUMBER_OF_RTS */ - uint16 Padding; /**< \brief Structure padding */ + SC_RtsNum_t RtsNum; /**< \brief The ID of the RTS to start, 1 through #SC_NUMBER_OF_RTS */ + uint16 Padding; /**< \brief Structure padding */ } SC_RtsCmd_Payload_t; /** @@ -279,8 +281,8 @@ typedef struct */ typedef struct { - uint16 AtsId; /**< \brief The ID of the ATS to append to, 1 = ATS_A, 2 = ATS_B */ - uint16 Padding; /**< \brief Structure Padding */ + SC_AtsNum_t AtsNum; /**< \brief The ID of the ATS to append to, 1 = ATS_A, 2 = ATS_B */ + uint16 Padding; /**< \brief Structure Padding */ } SC_AppendAtsCmd_Payload_t; /** @@ -288,8 +290,8 @@ typedef struct */ typedef struct { - uint16 FirstRtsId; /**< \brief ID of the first RTS to act on, 1 through #SC_NUMBER_OF_RTS */ - uint16 LastRtsId; /**< \brief ID of the last RTS to act on, 1 through #SC_NUMBER_OF_RTS */ + SC_RtsNum_t FirstRtsNum; /**< \brief ID of the first RTS to act on, 1 through #SC_NUMBER_OF_RTS */ + SC_RtsNum_t LastRtsNum; /**< \brief ID of the last RTS to act on, 1 through #SC_NUMBER_OF_RTS */ } SC_RtsGrpCmd_Payload_t; /**\}*/ diff --git a/config/default_sc_tbldefs.h b/config/default_sc_tbldefs.h index 7effd14..123c093 100644 --- a/config/default_sc_tbldefs.h +++ b/config/default_sc_tbldefs.h @@ -27,6 +27,7 @@ #define SC_TBLDEFS_H #include "common_types.h" +#include "sc_extern_typedefs.h" #include "cfe_msg_hdr.h" /************************************************************************* @@ -70,7 +71,7 @@ typedef struct { uint16 Pad; /**< \brief Structure padding */ - uint16 CmdNumber; /**< \brief command number, range = 1 to SC_MAX_ATS_CMDS */ + SC_CommandNum_t CmdNumber; /**< \brief command number, range = 1 to SC_MAX_ATS_CMDS */ uint16 TimeTag_MS; /**< \brief Time tag most significant 16 bits */ uint16 TimeTag_LS; /**< \brief Time tag least significant 16 bits */ diff --git a/fsw/src/sc_app.c b/fsw/src/sc_app.c index 972b39a..ae4d648 100644 --- a/fsw/src/sc_app.c +++ b/fsw/src/sc_app.c @@ -167,11 +167,11 @@ CFE_Status_t SC_AppInit(void) /* Select auto-exec RTS to start during first HK request */ if (CFE_ES_GetResetType(NULL) == CFE_PSP_RST_TYPE_POWERON) { - SC_AppData.AutoStartRTS = RTS_ID_AUTO_POWER_ON; + SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_POWER_ON); } else { - SC_AppData.AutoStartRTS = RTS_ID_AUTO_PROCESSOR; + SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_PROCESSOR); } /* Must be able to register for events */ @@ -259,13 +259,13 @@ CFE_Status_t SC_InitTables(void) } /* ATP control block status table */ - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_NO_ATS; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_INVALID_CMD_NUMBER; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_NULL; + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_INVALID_CMD_NUMBER; /* RTP control block status table */ SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 0; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_INVALID_RTS_NUMBER; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_NULL; /* ATS command status table(s) */ for (i = 0; i < SC_NUMBER_OF_ATS; i++) @@ -280,7 +280,7 @@ CFE_Status_t SC_InitTables(void) for (i = 0; i < SC_NUMBER_OF_RTS; i++) { SC_OperData.RtsInfoTblAddr[i].NextCommandTime = SC_MAX_TIME; - SC_OperData.RtsInfoTblAddr[i].NextCommandPtr = 0; + SC_OperData.RtsInfoTblAddr[i].NextCommandPtr = SC_ENTRY_OFFSET_FIRST; SC_OperData.RtsInfoTblAddr[i].RtsStatus = SC_Status_EMPTY; SC_OperData.RtsInfoTblAddr[i].DisabledFlag = true; } @@ -516,7 +516,7 @@ CFE_Status_t SC_GetLoadTablePointers(void) /* Process new RTS table data */ if (Result == CFE_TBL_INFO_UPDATED) { - SC_LoadRts(i); + SC_LoadRts(SC_RTS_IDX_C(i)); } } diff --git a/fsw/src/sc_app.h b/fsw/src/sc_app.h index baf788a..a887edc 100644 --- a/fsw/src/sc_app.h +++ b/fsw/src/sc_app.h @@ -29,6 +29,7 @@ *************************************************************************/ #include "cfe.h" +#include "sc_index_types.h" #include "sc_platform_cfg.h" #include "sc_tbldefs.h" #include "sc_msgdefs.h" @@ -52,12 +53,12 @@ typedef struct SC_TimeAccessor */ typedef struct { - uint8 AtpState; /**< \brief execution state of the ATP */ - uint8 AtsNumber; /**< \brief current ATS running if any */ - uint16 Padding; /**< \brief Structure padding to align to 32-bit boundaries */ - uint32 CmdNumber; /**< \brief current cmd number to run if any */ - uint16 TimeIndexPtr; /**< \brief time index pointer for current cmd */ - uint16 SwitchPendFlag; /**< \brief indicates that a buffer switch is waiting */ + SC_Status_Enum_t AtpState; /**< \brief execution state of the ATP */ + SC_AtsNum_t CurrAtsNum; /**< \brief current ATS running if any */ + uint16 Padding; /**< \brief Structure padding to align to 32-bit boundaries */ + SC_CommandNum_t CmdNumber; /**< \brief current cmd number to run if any */ + SC_SeqIndex_t TimeIndexPtr; /**< \brief time index pointer for current cmd */ + uint16 SwitchPendFlag; /**< \brief indicates that a buffer switch is waiting */ } SC_AtpControlBlock_t; /** @@ -79,8 +80,8 @@ typedef struct */ typedef struct { - uint16 NumRtsActive; /**< \brief number of RTSs currently active */ - uint16 RtsNumber; /**< \brief next RTS number */ + uint16 NumRtsActive; /**< \brief number of RTSs currently active */ + SC_RtsNum_t CurrRtsNum; /**< \brief next RTS number */ } SC_RtpControlBlock_t; /** @@ -88,13 +89,13 @@ typedef struct */ typedef struct { - uint8 RtsStatus; /**< \brief status of the RTS */ - bool DisabledFlag; /**< \brief disabled/enabled flag */ - uint8 CmdCtr; /**< \brief Cmds executed in current rts */ - uint8 CmdErrCtr; /**< \brief errs in current RTS */ - SC_AbsTimeTag_t NextCommandTime; /**< \brief next command time for RTS */ - uint16 NextCommandPtr; /**< \brief where next rts cmd is */ - uint16 UseCtr; /**< \brief how many times RTS is run */ + SC_Status_Enum_t RtsStatus; /**< \brief status of the RTS */ + bool DisabledFlag; /**< \brief disabled/enabled flag */ + uint8 CmdCtr; /**< \brief Cmds executed in current rts */ + uint8 CmdErrCtr; /**< \brief errs in current RTS */ + SC_AbsTimeTag_t NextCommandTime; /**< \brief next command time for RTS */ + SC_EntryOffset_t NextCommandPtr; /**< \brief where next rts cmd is */ + uint16 UseCtr; /**< \brief how many times RTS is run */ } SC_RtsInfoEntry_t; /** @@ -269,22 +270,12 @@ void SC_RegisterManageCmds(void); #define SC_DUP_TEST_UNUSED -1 /**< \brief Unused marking for duplicate test */ -#define SC_INVALID_CMD_NUMBER 0xFFFF /**< \brief Invalid command number */ +#define SC_INVALID_CMD_NUMBER ((SC_CommandNum_t) {0}) /**< \brief Invalid command number */ #define SC_ROUND_UP_BYTES 3 /**< \brief Round up to word length (in bytes) */ #define SC_BYTES_IN_ATS_APPEND_ENTRY 2 /**< \brief Bytes in an ATS append table entry */ -#define SC_ATS_CMD_NUM_TO_INDEX(num) ((num)-1) /**< \brief Convert ATS command number to index */ -#define SC_ATS_CMD_INDEX_TO_NUM(index) ((index) + 1) /**< \brief Convert ATS command index to number */ -#define SC_ATS_NUM_TO_INDEX(num) ((num)-1) /**< \brief Convert ATS table number to index */ -#define SC_ATS_INDEX_TO_NUM(index) ((index) + 1) /**< \brief Convert ATS table index to number */ -#define SC_ATS_ID_TO_INDEX(id) ((id)-1) /**< \brief Convert ATS ID to index */ -#define SC_RTS_NUM_TO_INDEX(num) ((num)-1) /**< \brief Convert RTS table number to index */ -#define SC_RTS_INDEX_TO_NUM(index) ((index) + 1) /**< \brief Convert RTS table index to number */ -#define SC_RTS_ID_TO_INDEX(id) ((id)-1) /**< \brief Convert RTS ID to index */ -#define SC_RTS_INDEX_TO_ID(index) ((index) + 1) /**< \brief Convert RTS table index to ID */ - /** * \brief SC Operational Data Structure * @@ -316,8 +307,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 */ - uint32 * 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_Status_Enum_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 */ @@ -332,18 +323,17 @@ typedef struct */ typedef struct { - uint16 AtsTimeIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; + SC_CommandNum_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.. */ - int32 AtsCmdIndexBuffer[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; + SC_EntryOffset_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 */ - SC_TimeAccessor_t TimeRef; /**< \brief Configured time reference */ bool EnableHeaderUpdate; /**< \brief whether to update headers in outgoing messages */ @@ -351,7 +341,7 @@ typedef struct SC_Process_Enum_t NextProcNumber; /**< \brief the next command processor number */ SC_AbsTimeTag_t NextCmdTime[2]; /**< \brief The overall next command time 0 - ATP, 1- RTP*/ SC_AbsTimeTag_t CurrentTime; /**< \brief this is the current time for SC */ - uint16 AutoStartRTS; /**< \brief Start selected auto-exec RTS after init */ + SC_RtsNum_t AutoStartRTS; /**< \brief Start selected auto-exec RTS after init */ uint16 AppendWordCount; /**< \brief Size of cmd entries in current Append ATS table */ } SC_AppData_t; diff --git a/fsw/src/sc_atsrq.c b/fsw/src/sc_atsrq.c index 13d229c..7b299ce 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -49,16 +49,16 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StartAtsCmd(const SC_StartAtsCmd_t *Cmd) { - uint16 AtsId; /* ATS ID */ - uint16 AtsIndex; /* ATS array index */ + SC_AtsNum_t AtsNum; /* ATS ID */ + SC_AtsIndex_t AtsIndex; /* ATS array index */ - AtsId = Cmd->Payload.AtsId; + AtsNum = Cmd->Payload.AtsNum; /* validate ATS ID */ - if ((AtsId > 0) && (AtsId <= SC_NUMBER_OF_ATS)) + if ((AtsNum > 0) && (AtsNum <= SC_NUMBER_OF_ATS)) { /* convert ATS ID to array index */ - AtsIndex = SC_ATS_ID_TO_INDEX(AtsId); + AtsIndex = SC_AtsNumToIndex(AtsNum); /* make sure that there is no ATS running on the ATP */ if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_IDLE) @@ -112,7 +112,7 @@ void SC_StartAtsCmd(const SC_StartAtsCmd_t *Cmd) { /* the specified ATS id is not valid */ CFE_EVS_SendEvent(SC_STARTATS_CMD_INVLD_ID_ERR_EID, CFE_EVS_EventType_ERROR, - "Start ATS %d Rejected: Invalid ATS ID", AtsId); + "Start ATS %u Rejected: Invalid ATS ID", SC_IDNUM_AS_UINT(AtsNum)); /* increment the command request error counter */ SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -133,14 +133,14 @@ void SC_StopAtsCmd(const SC_StopAtsCmd_t *Cmd) /* ** Set the temp ATS ID if it is valid */ - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_AtsId_ATSA) + if (SC_OperData.AtsCtrlBlckAddr->CurrAtsNum == SC_AtsId_ATSA) { TempAtsChar = 'A'; Result = CFE_SUCCESS; } else { - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_AtsId_ATSB) + if (SC_OperData.AtsCtrlBlckAddr->CurrAtsNum == SC_AtsId_ATSB) { TempAtsChar = 'B'; Result = CFE_SUCCESS; @@ -170,13 +170,13 @@ void SC_StopAtsCmd(const SC_StopAtsCmd_t *Cmd) /* Function for starting an ATS */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset) +bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) { SC_AtsEntryHeader_t *Entry; /* ATS table entry pointer */ - int32 EntryIndex; /* ATS entry location in table */ + SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ SC_AbsTimeTag_t ListCmdTime = 0; /* list entry execution time */ - int32 TimeIndex; /* the current time buffer index */ - int32 CmdIndex; /* ATS command index (cmd num - 1) */ + SC_SeqIndex_t TimeIndex; /* the current time buffer index */ + SC_CommandIndex_t CmdIndex; /* ATS command index */ bool ReturnCode; SC_AbsTimeTag_t TimeToStartAts; /* the REAL time to start the ATS */ uint16 CmdsSkipped = 0; @@ -196,12 +196,13 @@ bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset) ** has a time greater than or equal to the current time OR ** all of the commands have been skipped */ - TimeIndex = 0; /* pointer into the time index table */ + TimeIndex = SC_SEQUENCE_IDX_FIRST; /* pointer into the time index table */ + CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ while (TimeIndex < SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) { /* first get the cmd index at this list entry */ - CmdIndex = SC_ATS_CMD_NUM_TO_INDEX(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); + CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); /* then get the entry index from the cmd index table */ EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; /* then get a pointer to the ATS entry data */ @@ -245,8 +246,8 @@ bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset) ** Initialize the ATP Control Block. */ /* leave the atp state alone, it will be updated by the caller */ - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_ATS_INDEX_TO_NUM(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_ATS_CMD_INDEX_TO_NUM(CmdIndex); + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_CommandIndexToNum(CmdIndex); SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr = TimeIndex; /* send an event for number of commands skipped */ @@ -271,10 +272,16 @@ bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_KillAts(void) { - if (SC_OperData.AtsCtrlBlckAddr->AtpState != SC_Status_IDLE) + SC_AtsIndex_t AtsIndex; + + /* + * Check if the ATS ID is valid + */ + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); + if (SC_AtsIndexIsValid(AtsIndex) && SC_OperData.AtsCtrlBlckAddr->AtpState != SC_Status_IDLE) { /* Increment the ats use counter */ - SC_OperData.AtsInfoTblAddr[SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber)].AtsUseCtr++; + SC_OperData.AtsInfoTblAddr[AtsIndex].AtsUseCtr++; } /* ** Reset the state in the atp control block @@ -292,7 +299,7 @@ void SC_KillAts(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_SwitchAtsCmd(const SC_SwitchAtsCmd_t *Cmd) { - uint16 NewAtsIndex; /* the index of the ats to switch to*/ + SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ /* make sure that an ATS is running on the ATP */ if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) @@ -345,8 +352,8 @@ void SC_SwitchAtsCmd(const SC_SwitchAtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ServiceSwitchPend(void) { - uint16 NewAtsIndex; /* the ats index that we are switching to */ - uint16 OldAtsIndex; /* the ats index we are switching from */ + SC_AtsIndex_t NewAtsIndex; /* the ats index that we are switching to */ + SC_AtsIndex_t OldAtsIndex; /* the ats index we are switching from */ /* ** See if it is time to switch the ATS @@ -357,7 +364,7 @@ void SC_ServiceSwitchPend(void) if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { /* get the ATS number to switch to and from */ - OldAtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); + OldAtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); NewAtsIndex = SC_ToggleAtsIndex(); /* Now check to see if the new ATS has commands in it */ @@ -412,15 +419,15 @@ void SC_ServiceSwitchPend(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool SC_InlineSwitch(void) { - uint16 NewAtsIndex; /* the index of the ats to switch to*/ - uint16 OldAtsIndex; /* the index of the ats to switch from*/ - bool ReturnCode; /* return code for function */ + SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ + SC_AtsIndex_t OldAtsIndex; /* the index of the ats to switch from*/ + bool ReturnCode; /* return code for function */ /* figure out which ATS to switch to */ NewAtsIndex = SC_ToggleAtsIndex(); /* Save the ATS number to switch FROM */ - OldAtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); + OldAtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* Now check to see if the new ATS has commands in it */ if (SC_OperData.AtsInfoTblAddr[NewAtsIndex].NumberOfCommands > 0) @@ -483,12 +490,12 @@ bool SC_InlineSwitch(void) void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) { SC_AtsEntryHeader_t *Entry; /* ATS table entry pointer */ - int32 EntryIndex; /* ATS entry location in table */ + SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ SC_AbsTimeTag_t JumpTime; /* the time to jump to in the ATS */ SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ - uint16 AtsIndex; /* index of the ATS that is running */ - int32 TimeIndex; /* the current time buffer index */ - int32 CmdIndex; /* ATS command index (cmd num - 1) */ + SC_AtsIndex_t AtsIndex; /* index of the ATS that is running */ + SC_SeqIndex_t TimeIndex; /* the current time buffer index */ + SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ char TimeBuffer[CFE_TIME_PRINTED_STRING_SIZE]; CFE_TIME_SysTime_t NewTime; uint16 NumSkipped; @@ -496,20 +503,21 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { JumpTime = Cmd->Payload.NewTime; - AtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* ** Loop through the commands until a time tag is found ** that has a time greater than or equal to the current time OR ** all of the commands have been skipped */ - TimeIndex = 0; + TimeIndex = SC_SEQUENCE_IDX_FIRST; + CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ NumSkipped = 0; while (TimeIndex < SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) { /* first get the cmd index at this list entry */ - CmdIndex = SC_ATS_CMD_NUM_TO_INDEX(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); + CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); /* then get the entry index from the cmd index table */ EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; /* then get a pointer to the ATS entry data */ @@ -564,7 +572,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) /* ** Update the ATP Control Block entries. */ - SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_ATS_CMD_INDEX_TO_NUM(CmdIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_CommandIndexToNum(CmdIndex); SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr = TimeIndex; /* @@ -608,7 +616,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ContinueAtsOnFailureCmd(const SC_ContinueAtsOnFailureCmd_t *Cmd) { - uint16 State; + SC_AtsCont_Enum_t State; State = Cmd->Payload.ContinueState; @@ -637,21 +645,21 @@ void SC_ContinueAtsOnFailureCmd(const SC_ContinueAtsOnFailureCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) { - uint16 AtsIndex; /* index (not ID) of target ATS */ + SC_AtsIndex_t AtsIndex; /* index (not ID) of target ATS */ - if ((Cmd->Payload.AtsId == 0) || (Cmd->Payload.AtsId > SC_NUMBER_OF_ATS)) + if ((Cmd->Payload.AtsNum == 0) || (Cmd->Payload.AtsNum > SC_NUMBER_OF_ATS)) { /* invalid target ATS selection */ SC_OperData.HkPacket.Payload.CmdErrCtr++; - CFE_EVS_SendEvent(SC_APPEND_CMD_ARG_ERR_EID, CFE_EVS_EventType_ERROR, "Append ATS error: invalid ATS ID = %d", - Cmd->Payload.AtsId); + CFE_EVS_SendEvent(SC_APPEND_CMD_ARG_ERR_EID, CFE_EVS_EventType_ERROR, "Append ATS error: invalid ATS ID = %u", + SC_IDNUM_AS_UINT(Cmd->Payload.AtsNum)); return; } /* create base zero array index from base one ID value */ - AtsIndex = SC_ATS_ID_TO_INDEX(Cmd->Payload.AtsId); + AtsIndex = SC_AtsNumToIndex(Cmd->Payload.AtsNum); if (SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0) { @@ -682,7 +690,7 @@ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) else { /* store ATS selection from most recent ATS Append command */ - SC_OperData.HkPacket.Payload.AppendCmdArg = Cmd->Payload.AtsId; + SC_OperData.HkPacket.Payload.AppendCmdArg = Cmd->Payload.AtsNum; /* copy append data and re-calc timing data */ SC_ProcessAppend(AtsIndex); diff --git a/fsw/src/sc_atsrq.h b/fsw/src/sc_atsrq.h index 97a21dc..8d79fac 100644 --- a/fsw/src/sc_atsrq.h +++ b/fsw/src/sc_atsrq.h @@ -27,6 +27,7 @@ #define SC_ATSRQ_H #include "cfe.h" +#include "sc_index_types.h" #include "sc_msg.h" /** @@ -45,7 +46,7 @@ * \retval true ATS was started * \retval false ATS was NOT started */ -bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset); +bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset); /** * \brief Start an ATS Command diff --git a/fsw/src/sc_cmds.c b/fsw/src/sc_cmds.c index 023217e..ffd9246 100644 --- a/fsw/src/sc_cmds.c +++ b/fsw/src/sc_cmds.c @@ -55,9 +55,9 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ProcessAtpCmd(void) { - int32 EntryIndex; /* ATS entry location in table */ - uint8 AtsIndex; /* ATS selection index */ - uint32 CmdIndex; /* ATS command index */ + SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ + SC_AtsIndex_t AtsIndex; /* ATS selection index */ + SC_CommandIndex_t CmdIndex; /* ATS command index */ char TempAtsChar; CFE_Status_t Result; bool AbortATS = false; @@ -81,8 +81,8 @@ void SC_ProcessAtpCmd(void) /* ** Get a pointer to the next ats command */ - AtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); /* remember 0..1 */ - CmdIndex = SC_ATS_CMD_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->CmdNumber); + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* remember 0..1 */ + CmdIndex = SC_CommandNumToIndex(SC_OperData.AtsCtrlBlckAddr->CmdNumber); EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; @@ -95,7 +95,7 @@ void SC_ProcessAtpCmd(void) ** Make sure the command number matches what the command ** number is supposed to be */ - if (EntryPtr->Header.CmdNumber == (SC_ATS_CMD_INDEX_TO_NUM(CmdIndex))) + if (SC_IDNUM_EQUAL(EntryPtr->Header.CmdNumber, SC_CommandIndexToNum(CmdIndex))) { /* * Check the checksum on the command @@ -150,7 +150,7 @@ void SC_ProcessAtpCmd(void) SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_FAILED_DISTRIB; SC_OperData.HkPacket.Payload.AtsCmdErrCtr++; - SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; } /* end if */ @@ -169,7 +169,7 @@ void SC_ProcessAtpCmd(void) { /* the command had Software Bus problems */ SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_FAILED_DISTRIB; SC_OperData.HkPacket.Payload.AtsCmdErrCtr++; - SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; CFE_EVS_SendEvent(SC_ATS_DIST_ERR_EID, CFE_EVS_EventType_ERROR, @@ -196,7 +196,7 @@ void SC_ProcessAtpCmd(void) /* ** Update the last ATS error information structure */ - SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; /* update the command status index table */ @@ -217,7 +217,7 @@ void SC_ProcessAtpCmd(void) CFE_EVS_SendEvent(SC_ATS_MSMTCH_ERR_EID, CFE_EVS_EventType_ERROR, "ATS Command Number Mismatch: Command Skipped, expected: %d received: %d", - (int)SC_ATS_CMD_INDEX_TO_NUM(CmdIndex), EntryPtr->Header.CmdNumber); + (int)SC_CommandIndexToNum(CmdIndex), EntryPtr->Header.CmdNumber); /* ** Increment the ATS error counter */ @@ -226,7 +226,7 @@ void SC_ProcessAtpCmd(void) /* ** Update the last ATS error information structure */ - SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; /* update the command status index table */ @@ -252,7 +252,7 @@ void SC_ProcessAtpCmd(void) /* ** Update the last ATS error information structure */ - SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; /* Do Not Mark this ATS for abortion. The command could be marked as EXECUTED @@ -262,7 +262,7 @@ void SC_ProcessAtpCmd(void) if (AbortATS == true) { - if (SC_OperData.AtsCtrlBlckAddr->AtsNumber == SC_AtsId_ATSA) + if (SC_OperData.AtsCtrlBlckAddr->CurrAtsNum == SC_AtsId_ATSA) { TempAtsChar = 'A'; } @@ -296,11 +296,11 @@ void SC_ProcessAtpCmd(void) void SC_ProcessRtpCommand(void) { - SC_RtsEntry_t *EntryPtr; /* a pointer to an RTS entry header */ - uint16 RtsIndex; /* the RTS index for the cmd */ - uint16 CmdOffset; /* the location of the cmd */ - CFE_Status_t Result; - bool ChecksumValid; + SC_RtsEntry_t * EntryPtr; /* a pointer to an RTS entry header */ + SC_RtsIndex_t RtsIndex; /* the RTS index for the cmd */ + SC_EntryOffset_t CmdOffset; /* the location of the cmd */ + CFE_Status_t Result; + bool ChecksumValid; /* ** The following conditions must be met before a RTS command is executed: @@ -309,12 +309,13 @@ void SC_ProcessRtpCommand(void) ** 3.) The RTS number in the RTP control block must be valid and ** 4.) the RTS must be EXECUTING */ + /* convert the RTS number so that it can be directly indexed into the table*/ + RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); if ((SC_AppData.NextCmdTime[SC_AppData.NextProcNumber] <= SC_AppData.CurrentTime) && - (SC_AppData.NextProcNumber == SC_Process_RTP) && (SC_OperData.RtsCtrlBlckAddr->RtsNumber > 0) && - (SC_OperData.RtsCtrlBlckAddr->RtsNumber <= SC_NUMBER_OF_RTS) && - (SC_OperData.RtsInfoTblAddr[SC_RTS_NUM_TO_INDEX(SC_OperData.RtsCtrlBlckAddr->RtsNumber)].RtsStatus == - SC_Status_EXECUTING)) + (SC_AppData.NextProcNumber == SC_Process_RTP) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && + (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS) && + (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING)) { /* ** Count the command for the rate limiter @@ -322,9 +323,6 @@ void SC_ProcessRtpCommand(void) */ SC_OperData.NumCmdsSec++; - /* convert the RTS number so that it can be directly indexed into the table*/ - RtsIndex = SC_RTS_NUM_TO_INDEX(SC_OperData.RtsCtrlBlckAddr->RtsNumber); - /* ** Get the Command offset within the RTS */ @@ -368,11 +366,11 @@ void SC_ProcessRtpCommand(void) */ CFE_EVS_SendEvent(SC_RTS_DIST_ERR_EID, CFE_EVS_EventType_ERROR, "RTS %03d Command Distribution Failed: RTS Stopped. SB returned 0x%08X", - (int)SC_OperData.RtsCtrlBlckAddr->RtsNumber, (unsigned int)Result); + (int)SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, (unsigned int)Result); SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; - SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->RtsNumber; + SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; /* @@ -390,13 +388,13 @@ void SC_ProcessRtpCommand(void) */ CFE_EVS_SendEvent(SC_RTS_CHKSUM_ERR_EID, CFE_EVS_EventType_ERROR, "RTS %03d Command Failed Checksum: RTS Stopped", - (int)SC_OperData.RtsCtrlBlckAddr->RtsNumber); + (int)SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); /* ** Update the RTS command error counter and last RTS error info */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; - SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->RtsNumber; + SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; /* @@ -419,12 +417,12 @@ void SC_SendHkPacket(void) /* ** fill in the free bytes in each ATS */ - SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_ATS_NUM_TO_INDEX(SC_AtsId_ATSA)] = + SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_AtsNumToIndex(SC_AtsId_ATSA)] = (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[SC_ATS_NUM_TO_INDEX(SC_AtsId_ATSA)].AtsSize * SC_BYTES_IN_WORD); - SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_ATS_NUM_TO_INDEX(SC_AtsId_ATSB)] = + (SC_OperData.AtsInfoTblAddr[SC_AtsNumToIndex(SC_AtsId_ATSA)].AtsSize * SC_BYTES_IN_WORD); + SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_AtsNumToIndex(SC_AtsId_ATSB)] = (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[SC_ATS_NUM_TO_INDEX(SC_AtsId_ATSB)].AtsSize * SC_BYTES_IN_WORD); + (SC_OperData.AtsInfoTblAddr[SC_AtsNumToIndex(SC_AtsId_ATSB)].AtsSize * SC_BYTES_IN_WORD); /* ** @@ -432,10 +430,10 @@ void SC_SendHkPacket(void) ** */ - SC_OperData.HkPacket.Payload.CurrAtsId = SC_OperData.AtsCtrlBlckAddr->AtsNumber; + SC_OperData.HkPacket.Payload.CurrAtsId = SC_IDNUM_AS_UINT(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); SC_OperData.HkPacket.Payload.AtpState = SC_OperData.AtsCtrlBlckAddr->AtpState; - SC_OperData.HkPacket.Payload.AtpCmdNumber = SC_OperData.AtsCtrlBlckAddr->CmdNumber; + SC_OperData.HkPacket.Payload.AtpCmdNumber = SC_IDNUM_AS_UINT(SC_OperData.AtsCtrlBlckAddr->CmdNumber); SC_OperData.HkPacket.Payload.SwitchPendFlag = SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag; SC_OperData.HkPacket.Payload.NextAtsTime = SC_AppData.NextCmdTime[SC_Process_ATP]; @@ -445,7 +443,7 @@ void SC_SendHkPacket(void) */ SC_OperData.HkPacket.Payload.NumRtsActive = SC_OperData.RtsCtrlBlckAddr->NumRtsActive; - SC_OperData.HkPacket.Payload.RtsNumber = SC_OperData.RtsCtrlBlckAddr->RtsNumber; + SC_OperData.HkPacket.Payload.RtsNum = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.NextRtsTime = SC_AppData.NextCmdTime[SC_Process_RTP]; /* @@ -489,16 +487,16 @@ void SC_SendHkCmd(const SC_SendHkCmd_t *Cmd) if (SC_AppData.AutoStartRTS != 0) { /* make sure the selected auto-exec RTS is enabled */ - if (SC_OperData.RtsInfoTblAddr[SC_RTS_NUM_TO_INDEX(SC_AppData.AutoStartRTS)].RtsStatus == SC_Status_LOADED) + if (SC_OperData.RtsInfoTblAddr[SC_RtsNumToIndex(SC_AppData.AutoStartRTS)].RtsStatus == SC_Status_LOADED) { - SC_OperData.RtsInfoTblAddr[SC_RTS_NUM_TO_INDEX(SC_AppData.AutoStartRTS)].DisabledFlag = false; + SC_OperData.RtsInfoTblAddr[SC_RtsNumToIndex(SC_AppData.AutoStartRTS)].DisabledFlag = false; } /* send ground cmd to have SC start the RTS */ SC_AutoStartRts(SC_AppData.AutoStartRTS); /* only start it once */ - SC_AppData.AutoStartRTS = 0; + SC_AppData.AutoStartRTS = SC_RTS_NUM_NULL; } /* request from health and safety for housekeeping status */ @@ -735,11 +733,11 @@ void SC_ManageTable(SC_TableType type, int32 ArrayIndex) /* Process new table data */ if (type == ATS) { - SC_LoadAts(ArrayIndex); + SC_LoadAts(SC_ATS_IDX_C(ArrayIndex)); } else if (type == RTS) { - SC_LoadRts(ArrayIndex); + SC_LoadRts(SC_RTS_IDX_C(ArrayIndex)); } else { @@ -752,14 +750,14 @@ void SC_ManageTable(SC_TableType type, int32 ArrayIndex) if (type == ATS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_ATS_ERR_EID, CFE_EVS_EventType_ERROR, - "ATS table manage process error: ATS = %d, Result = 0x%X", - (int)SC_RTS_INDEX_TO_NUM(ArrayIndex), (unsigned int)Result); + "ATS table manage process error: ATS = %u, Result = 0x%X", + SC_IDNUM_AS_UINT(SC_AtsIndexToNum(SC_ATS_IDX_C(ArrayIndex))), (unsigned int)Result); } else if (type == RTS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_RTS_ERR_EID, CFE_EVS_EventType_ERROR, - "RTS table manage process error: RTS = %d, Result = 0x%X", - (int)SC_RTS_INDEX_TO_NUM(ArrayIndex), (unsigned int)Result); + "RTS table manage process error: RTS = %u, Result = 0x%X", + SC_IDNUM_AS_UINT(SC_RtsIndexToNum(SC_RTS_IDX_C(ArrayIndex))), (unsigned int)Result); } else { diff --git a/fsw/src/sc_index_types.h b/fsw/src/sc_index_types.h new file mode 100644 index 0000000..cfc1e63 --- /dev/null +++ b/fsw/src/sc_index_types.h @@ -0,0 +1,396 @@ +/************************************************************************ + * NASA Docket No. GSC-18,924-1, and identified as “Core Flight + * System (cFS) Stored Command Application version 3.1.1” + * + * Copyright (c) 2021 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Defines data types used for internal structure/table indexing + */ +#ifndef SC_INDEX_TYPES_H +#define SC_INDEX_TYPES_H + +/************************************************************************* + * Includes + *************************************************************************/ + +#include "common_types.h" +#include "sc_extern_typedefs.h" +#include "sc_platform_cfg.h" + +/************************************************************************* + * Types + *************************************************************************/ + +/* + * BACKGROUND INFO: + * + * The SC external interface (tables/commands/telemetry) uses non-zero identifiers + * for all object references. This is beneficial because "0" can be reserved + * as an invalid/undefined value, and interpreted as "null" if it should appear. + * + * However, because all objects are stored in arrays and C arrays start at index 0, + * there needs to be a conversion between the externally-used identifier and the + * internal index used during the actual processing. + */ + +/** + * @brief An index type for RTS's. + * + * This is a 0-based value that refers to an internal + * array index for the RTS tables. + * + * The valid range is [0..SC_NUMBER_OF_RTS-1] + */ +typedef uint16 SC_RtsIndex_t; + +/** + * @brief An index type for ATS's. + * + * This is a 0-based value that refers to an internal + * array index for the ATS tables. + * + * The valid range is [0..SC_NUMBER_OF_ATS-1] + */ +typedef uint16 SC_AtsIndex_t; + +/** + * @brief An index type for ATS commands. + * + * This is a 0-based value that refers to an internal + * array index for the ATS command lookup tables. + * + * The valid range is [0..SC_MAX_ATS_CMDS-1] + */ +typedef uint16 SC_CommandIndex_t; + +/** + * @brief A sequence number for commands. + * + * This value is intended to indicate the order with which commands + * are executed within an ATS + * + * @note The command number in ATS entries is strictly for command + * identification and referencing purposes. Commands do not need to + * appear in the table, nor be do they need to be numbered in order. + * + * For example, the command with SeqIndex == 3 will be the 4th command executed + * within the ATS, after sorting by time. + * + * The valid range is [0..SC_MAX_ATS_CMDS-1] + */ +typedef uint16 SC_SeqIndex_t; + +/* + * ------------------------------------------------ + * CONVERSIONS between IDs, indices, and integers + * ------------------------------------------------ + * + * Although these are all integers underneath, they + * refer to different domains and thus transitioning + * or converting between the domains should be clear. + */ + +/* + * Macros and special values associated with IDX values + * These should work with any variant of an index type + */ + +/** + * Convert an index value to a native unsigned int + * + * This is mainly intended for printf()-style logging, where it should be paired + * with the "%u" conversion specifier. + */ +#define SC_IDX_AS_UINT(arg) ((unsigned int)(arg)) + +/** + * Convert a native integer to an index value + * + * This is mainly intended for initializing values from literals or integers + * This is the inverse macro of SC_IDX_AS_UINT() + */ +#define SC_IDX_FROM_UINT(arg) ((uint16)(arg)) +/** + * Increment an index value + * This works with any index type that follows the pattern + */ +#define SC_IDX_INCREMENT(arg) (++(arg)) + +/** + * Decrements an index value + * This works with any index type that follows the pattern + */ +#define SC_IDX_DECREMENT(arg) (--(arg)) + +/** + * Convert an index value to a alphabetic character + * + * This is intended for displaying ATS identifiers as letters (A/B, etc) + * Historically in SC there were only two ATS's (A and B) but this should + * support up to 26. + */ +#define SC_IDX_AS_CHAR(arg) ((char)('A' + SC_IDX_AS_UINT(arg))) + +/** + * Compare two index values for equality + */ +#define SC_IDX_EQUAL(arg1, arg2) (SC_IDX_AS_UINT(arg1) == SC_IDX_AS_UINT(arg2)) + +/** + * Compare if an index is less than or equal to another + * + * This is necessary for circumstances such as RTS group processing, + * which requires looping through a segment/subset of indices. + */ +#define SC_IDX_LESS_OR_EQ(arg1, arg2) (SC_IDX_AS_UINT(arg1) <= SC_IDX_AS_UINT(arg2)) + +/** + * Compare if an index is less than a fixed limit + * + * This is necessary for validating the index, that is within the + * permissible range. The "lim" is expected to be a fixed constant. + */ +#define SC_IDX_WITHIN_LIMIT(arg, lim) (SC_IDX_AS_UINT(arg) < (lim)) + +/** + * Type-safe conversion from an ATS Number/ID to an index + * + * @param AtsNum ATS Number/ID index to convert + * @returns ATS index associated with number + */ +static inline SC_AtsIndex_t SC_AtsNumToIndex(SC_AtsNum_t AtsNum) +{ + return (SC_AtsIndex_t)SC_IDX_FROM_UINT(SC_IDNUM_AS_UINT(AtsNum) - 1); +} + +/** + * Type-safe conversion from an ATS Index to a Number/ID + * + * @param AtsIndex ATS index to convert + * @returns ATS Number associated with index + */ +static inline SC_AtsNum_t SC_AtsIndexToNum(SC_AtsIndex_t AtsIndex) +{ + return (SC_AtsNum_t)SC_IDNUM_FROM_UINT(SC_IDX_AS_UINT(AtsIndex) + 1); +} + +/** + * Type-safe conversion from an RTS Number/ID to an index + * + * @param RtsNum RTS Number/ID index to convert + * @returns RTS index associated with number + */ +static inline SC_RtsIndex_t SC_RtsNumToIndex(SC_RtsNum_t RtsNum) +{ + return (SC_RtsIndex_t)SC_IDX_FROM_UINT(SC_IDNUM_AS_UINT(RtsNum) - 1); +} + +/** + * Type-safe conversion from an RTS Index to a Number/ID + * + * @param RtsIndex RTS index to convert + * @returns RTS Number associated with index + */ +static inline SC_RtsNum_t SC_RtsIndexToNum(SC_RtsIndex_t RtsIndex) +{ + return (SC_RtsNum_t)SC_IDNUM_FROM_UINT(SC_IDX_AS_UINT(RtsIndex) + 1); +} + +/** + * Type-safe conversion from an ATS Command Number to a Command Index + * + * @param CommandNum ATS Command Number/ID index to convert + * @returns Command index associated with number + */ +static inline SC_CommandIndex_t SC_CommandNumToIndex(SC_CommandNum_t CommandNum) +{ + return (SC_CommandIndex_t)SC_IDX_FROM_UINT(SC_IDNUM_AS_UINT(CommandNum) - 1); +} + +/** + * Type-safe conversion from an ATS Command Index to a Command Number + * + * @param CommandIndex ATS Command index to convert + * @returns Command Number associated with index + * + */ +static inline SC_CommandNum_t SC_CommandIndexToNum(SC_CommandIndex_t CommandIndex) +{ + return (SC_CommandNum_t)SC_IDNUM_FROM_UINT(SC_IDX_AS_UINT(CommandIndex) + 1); +} + +/* + * Type-specific integer conversion for each of the defined index types + */ +#define SC_COMMAND_IDX_C(i) ((SC_CommandIndex_t)SC_IDX_FROM_UINT(i)) +#define SC_RTS_IDX_C(i) ((SC_RtsIndex_t)SC_IDX_FROM_UINT(i)) +#define SC_ATS_IDX_C(i) ((SC_AtsIndex_t)SC_IDX_FROM_UINT(i)) +#define SC_SEQUENCE_IDX_C(i) ((SC_SeqIndex_t)SC_IDX_FROM_UINT(i)) +#define SC_ENTRY_OFFSET_C(i) ((SC_EntryOffset_t)SC_IDX_FROM_UINT(i)) + +#define SC_SEQUENCE_IDX_FIRST SC_SEQUENCE_IDX_C(0) +#define SC_SEQUENCE_IDX_INVALID SC_SEQUENCE_IDX_C(-1) +#define SC_ENTRY_OFFSET_FIRST SC_ENTRY_OFFSET_C(0) +#define SC_ENTRY_OFFSET_INVALID SC_ENTRY_OFFSET_C(-1) + +/* + * ------------------------------------------------ + * VALIDATION of IDs and indices + * ------------------------------------------------ + * + * The intent of these inline functions is to encapsulate + * validity and range-checking on IDs and index values so + * they can be applied uniformly across SC. + */ + +/** + * @brief Check if an ATS Index is valid + * + * @param AtsIndex ATS index to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_AtsIndexIsValid(SC_AtsIndex_t AtsIndex) +{ + return SC_IDX_WITHIN_LIMIT(AtsIndex, SC_NUMBER_OF_ATS); +} + +/** + * @brief Check if an ATS Number/ID is valid + * + * @param AtsNum ATS Number/ID to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_AtsNumIsValid(SC_AtsNum_t AtsNum) +{ + return SC_AtsIndexIsValid(SC_AtsNumToIndex(AtsNum)); +} + +/** + * @brief Check if an RTS Index is valid + * + * @param RtsIndex RTS index to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_RtsIndexIsValid(SC_RtsIndex_t RtsIndex) +{ + return SC_IDX_WITHIN_LIMIT(RtsIndex, SC_NUMBER_OF_RTS); +} + +/** + * @brief Check if an RTS Number/ID is valid + * + * @param RtsNum RTS Number/ID to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_RtsNumIsValid(SC_RtsNum_t RtsNum) +{ + return SC_RtsIndexIsValid(SC_RtsNumToIndex(RtsNum)); +} + +/** + * @brief Check if an ATS Command Index is valid + * + * @param CommandIndex Command index to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_AtsCommandIndexIsValid(SC_CommandIndex_t CommandIndex) +{ + return SC_IDX_WITHIN_LIMIT(CommandIndex, SC_MAX_ATS_CMDS); +} + +/** + * @brief Check if an ATS Command Number/ID is valid + * + * @param CommandNum Command Number/ID to check + * @retval true if valid + * @retval false if invalid / out of range + */ +static inline bool SC_AtsCommandNumIsValid(SC_CommandNum_t CommandNum) +{ + return SC_AtsCommandIndexIsValid(SC_CommandNumToIndex(CommandNum)); +} + +/** + * @brief Check if the given RTS Index should use the event reporting subsystem + * + * A subset of RTS values may send events, and this is configurable + * separately from the overall RTS limit + * + * @param RtsIndex RTS index to check + * @retval true if RTS uses events + * @retval false if RTS does not use events + */ +static inline bool SC_RtsIndexHasEvent(SC_RtsIndex_t RtsIndex) +{ + return (SC_IDX_WITHIN_LIMIT(RtsIndex, SC_LAST_RTS_WITH_EVENTS)); +} + +/** + * @brief Check if the given RTS Number/ID should use the event reporting subsystem + * + * A subset of RTS values may send events, and this is configurable + * separately from the overall RTS limit + * + * @param RtsNum RTS Number/ID to check + * @retval true if RTS uses events + * @retval false if RTS does not use events + */ +static inline bool SC_RtsNumHasEvent(SC_RtsNum_t RtsNum) +{ + return SC_RtsIndexHasEvent(SC_RtsNumToIndex(RtsNum)); +} + +/** + * @brief Check if the given RTS Number/ID is less than or equal to the limit + * + * This is used when looping over multiple IDs, to check when the end + * of the range is reached. This concept exists for RTS group commands. + * + * @param RtsNum RTS Number/ID to check + * @param IdLimit RTS Number/ID that refers to upper end of limit + * @retval true if within range + * @retval false if out of range + */ +static inline bool SC_RtsNumWithinRange(SC_RtsNum_t RtsNum, SC_RtsNum_t IdLimit) +{ + return (SC_IDNUM_AS_UINT(RtsNum) <= SC_IDNUM_AS_UINT(IdLimit)); +} + +/** + * @brief Check if the given RTS Number/ID range is valid + * + * This concept exists for RTS group commands, to confirm that the "first" + * and "last" IDs specified in the range are acceptable. + * + * @param FirstRtsNum First RTS Id of range (inclusive) + * @param LastRtsNum Last RTS Id of range (inclusive) + * @retval true if range is valid + * @retval false if range is not valid + */ +static inline bool SC_RtsNumValidateRange(SC_RtsNum_t FirstRtsNum, SC_RtsNum_t LastRtsNum) +{ + return SC_RtsNumIsValid(FirstRtsNum) && SC_RtsNumIsValid(LastRtsNum) && + SC_RtsNumWithinRange(FirstRtsNum, LastRtsNum); +} + +#endif diff --git a/fsw/src/sc_loads.c b/fsw/src/sc_loads.c index 6ca6711..eb1441c 100644 --- a/fsw/src/sc_loads.c +++ b/fsw/src/sc_loads.c @@ -49,16 +49,16 @@ /* Load the ATS from its table to memory */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_LoadAts(uint16 AtsIndex) +void SC_LoadAts(SC_AtsIndex_t AtsIndex) { - uint16 AtsEntryWords; /* current ats entry length in words */ - uint16 AtsCmdNum; /* current ats entry command number */ - uint16 AtsEntryIndex; /* index into the load for current ats entry */ - SC_AtsEntry_t *EntryPtr; /* a pointer to an ats entry */ - uint32 * AtsTablePtr; /* pointer to the start of the Ats table */ - CFE_MSG_Size_t MessageSize = 0; - int32 Result = CFE_SUCCESS; - bool StillProcessing = true; + uint16 AtsEntryWords; /* current ats entry length in words */ + SC_CommandNum_t AtsCmdNum; /* current ats entry command number */ + SC_EntryOffset_t AtsEntryIndex; /* index into the load for current ats entry */ + SC_AtsEntry_t * EntryPtr; /* a pointer to an ats entry */ + uint32 * AtsTablePtr; /* pointer to the start of the Ats table */ + CFE_MSG_Size_t MessageSize = 0; + int32 Result = CFE_SUCCESS; + bool StillProcessing = true; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -107,7 +107,7 @@ void SC_LoadAts(uint16 AtsIndex) } /* else if the cmd number is valid and the command */ /* has not already been loaded */ else if (AtsCmdNum <= SC_MAX_ATS_CMDS && - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_ATS_CMD_NUM_TO_INDEX(AtsCmdNum)] == SC_Status_EMPTY) + SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] == SC_Status_EMPTY) { /* get message size */ CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &MessageSize); @@ -124,11 +124,10 @@ void SC_LoadAts(uint16 AtsIndex) /* set the command pointer in the command index table */ /* CmdNum starts at one.... */ - SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_ATS_CMD_NUM_TO_INDEX(AtsCmdNum)] = AtsEntryIndex; + SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] = AtsEntryIndex; /* set the command status to loaded in the command status table */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_ATS_CMD_NUM_TO_INDEX(AtsCmdNum)] = - SC_Status_LOADED; + SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] = SC_Status_LOADED; /* increment the number of commands loaded */ SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands++; @@ -194,7 +193,7 @@ void SC_LoadAts(uint16 AtsIndex) /* Builds the time table for the ATS buffer */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_BuildTimeIndexTable(uint16 AtsIndex) +void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) { int32 i; int32 ListLength; @@ -229,14 +228,14 @@ void SC_BuildTimeIndexTable(uint16 AtsIndex) /* Inserts and element into a sorted list */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) +void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 ListLength) { SC_AtsEntryHeader_t *EntryHeader; /* ATS table entry pointer */ SC_AbsTimeTag_t NewCmdTime = 0; /* new command execution time */ SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ - uint32 CmdIndex; /* ATS command index (cmd num - 1) */ - uint32 EntryIndex; /* ATS entry location in table */ - int32 TimeBufIndex; /* this must be signed */ + SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ + SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ + SC_SeqIndex_t TimeBufIndex; /* this must be signed */ /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -263,7 +262,7 @@ void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) while (TimeBufIndex >= 0) { /* first get the cmd index for this list entry */ - CmdIndex = SC_ATS_CMD_NUM_TO_INDEX(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex]); + CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex]); /* then get the entry index from the ATS table */ EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; /* then get a pointer to the ATS entry data */ @@ -297,7 +296,7 @@ void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) ** else only entries with later times have been moved ** In either case, there is an empty slot next to TimeBufIndex */ - SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex + 1] = SC_ATS_CMD_INDEX_TO_NUM(NewCmdIndex); + SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex + 1] = SC_CommandIndexToNum(NewCmdIndex); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -305,7 +304,7 @@ void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) /* Clears out Ats Tables before a load */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_InitAtsTables(uint16 AtsIndex) +void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) { int32 i; @@ -335,7 +334,7 @@ void SC_InitAtsTables(uint16 AtsIndex) /* Initializes the info table entry for an RTS */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_LoadRts(uint16 RtsIndex) +void SC_LoadRts(SC_RtsIndex_t RtsIndex) { /* validate RTS array index */ if (RtsIndex < SC_NUMBER_OF_RTS) @@ -597,14 +596,14 @@ void SC_UpdateAppend(void) /* Append contents of Append ATS table to indicated ATS table */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_ProcessAppend(uint16 AtsIndex) +void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) { - SC_AtsEntry_t *EntryPtr; - CFE_MSG_Size_t CommandBytes = 0; - int32 CommandWords; - int32 EntryIndex; - int32 i; - uint16 CmdIndex; + SC_AtsEntry_t * EntryPtr; + CFE_MSG_Size_t CommandBytes = 0; + int32 CommandWords; + SC_EntryOffset_t EntryIndex; + int32 i; + SC_CommandIndex_t CmdIndex; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -631,7 +630,7 @@ void SC_ProcessAppend(uint16 AtsIndex) EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; /* convert base one cmd number to base zero index */ - CmdIndex = SC_ATS_CMD_NUM_TO_INDEX(EntryPtr->Header.CmdNumber); + CmdIndex = SC_CommandNumToIndex(EntryPtr->Header.CmdNumber); /* count only new commands, not replaced commands */ if (SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] == SC_Status_EMPTY) @@ -654,7 +653,7 @@ void SC_ProcessAppend(uint16 AtsIndex) /* did we just append to an ats that was executing? */ if ((SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) && - (SC_OperData.AtsCtrlBlckAddr->AtsNumber == (SC_ATS_INDEX_TO_NUM(AtsIndex)))) + (SC_IDNUM_EQUAL(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum, SC_AtsIndexToNum(AtsIndex)))) { /* ** re-start the ats -- this will go thru the process of skipping @@ -764,7 +763,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) /* All done -- end of ATS buffer */ Result = CFE_SUCCESS; } - else if (EntryPtr->Header.CmdNumber == 0) + else if (SC_IDNUM_IS_NULL(EntryPtr->Header.CmdNumber)) { /* ** If there is at least one word remaining in the buffer then it @@ -820,7 +819,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) "Verify ATS Table error: buffer overflow: buf index = %d, cmd num = %d, pkt len = %d", (int)EntryIndex, EntryPtr->Header.CmdNumber, (int)CommandBytes); } - else if (SC_OperData.AtsDupTestArray[SC_ATS_CMD_NUM_TO_INDEX(EntryPtr->Header.CmdNumber)] != SC_DUP_TEST_UNUSED) + else if (SC_OperData.AtsDupTestArray[SC_CommandNumToIndex(EntryPtr->Header.CmdNumber)] != SC_DUP_TEST_UNUSED) { /* Entry with duplicate command number is invalid */ Result = SC_ERROR; @@ -828,7 +827,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) CFE_EVS_SendEvent(SC_VERIFY_ATS_DUP_ERR_EID, CFE_EVS_EventType_ERROR, "Verify ATS Table error: dup cmd number: buf index = %d, cmd num = %d, dup index = %d", (int)EntryIndex, EntryPtr->Header.CmdNumber, - (int)SC_OperData.AtsDupTestArray[SC_ATS_CMD_NUM_TO_INDEX(EntryPtr->Header.CmdNumber)]); + (int)SC_OperData.AtsDupTestArray[SC_CommandNumToIndex(EntryPtr->Header.CmdNumber)]); } else { @@ -836,7 +835,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) Result = SC_ATS_HDR_NOPKT_WORDS + CommandWords; /* Mark this ATS command ID as in use at this table index */ - SC_OperData.AtsDupTestArray[SC_ATS_CMD_NUM_TO_INDEX(EntryPtr->Header.CmdNumber)] = EntryIndex; + SC_OperData.AtsDupTestArray[SC_CommandNumToIndex(EntryPtr->Header.CmdNumber)] = EntryIndex; } } diff --git a/fsw/src/sc_loads.h b/fsw/src/sc_loads.h index fc7db56..903f220 100644 --- a/fsw/src/sc_loads.h +++ b/fsw/src/sc_loads.h @@ -27,6 +27,7 @@ #define SC_LOADS_H #include "cfe.h" +#include "sc_index_types.h" /** * \brief Parses an RTS to see if it is valid @@ -61,7 +62,7 @@ bool SC_ParseRts(uint32 Buffer32[]); * * \param [in] AtsIndex ATS array index */ -void SC_BuildTimeIndexTable(uint16 AtsIndex); +void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex); /** * \brief Inserts an item in a sorted list @@ -77,7 +78,7 @@ void SC_BuildTimeIndexTable(uint16 AtsIndex); * \param [in] NewCmdIndex ATS command index for new list element * \param [in] ListLength Number of elements currently in list */ -void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength); +void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 ListLength); /** * \brief Initializes ATS tables before a load starts @@ -91,7 +92,7 @@ void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength); * * \param [in] AtsIndex ATS array index */ -void SC_InitAtsTables(uint16 AtsIndex); +void SC_InitAtsTables(SC_AtsIndex_t AtsIndex); /** * \brief Validation function for ATS or Append ATS table data @@ -136,7 +137,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords); * * \param [in] AtsIndex ATS table array index (base zero) */ -void SC_LoadAts(uint16 AtsIndex); +void SC_LoadAts(SC_AtsIndex_t AtsIndex); /** * \brief Validation function for an ATS @@ -197,7 +198,7 @@ void SC_UpdateAppend(void); * * \param [in] AtsIndex ATS table array index (base zero) */ -void SC_ProcessAppend(uint16 AtsIndex); +void SC_ProcessAppend(SC_AtsIndex_t AtsIndex); /** * \brief Loads an RTS into the data structures in SC @@ -210,7 +211,7 @@ void SC_ProcessAppend(uint16 AtsIndex); * * \param [in] RtsIndex RTS table array index (base zero) */ -void SC_LoadRts(uint16 RtsIndex); +void SC_LoadRts(SC_RtsIndex_t RtsIndex); /** * \brief Validation function for an RTS diff --git a/fsw/src/sc_rtsrq.c b/fsw/src/sc_rtsrq.c index f9a3106..34a5273 100644 --- a/fsw/src/sc_rtsrq.c +++ b/fsw/src/sc_rtsrq.c @@ -50,8 +50,8 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) { - uint16 RtsId; /* rts ID */ - uint16 RtsIndex; /* rts array index */ + SC_RtsNum_t RtsNum; /* rts number */ + SC_RtsIndex_t RtsIndex; /* rts array index */ SC_RtsEntryHeader_t *RtsEntryPtr; /* pointer to an rts entry */ CFE_MSG_Message_t * RtsEntryCmd; /* pointer to an rts command */ CFE_MSG_Size_t CmdLength = 0; /* the length of the 1st cmd */ @@ -59,12 +59,12 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) /* ** Check start RTS parameters */ - RtsId = Cmd->Payload.RtsId; + RtsNum = Cmd->Payload.RtsNum; - if ((RtsId > 0) && (RtsId <= SC_NUMBER_OF_RTS)) + if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RTS_ID_TO_INDEX(RtsId); + RtsIndex = SC_RtsNumToIndex(RtsNum); /* make sure that RTS is not disabled */ if (SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false) @@ -107,15 +107,15 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) SC_OperData.HkPacket.Payload.RtsActiveCtr++; SC_OperData.HkPacket.Payload.CmdCtr++; - if (Cmd->Payload.RtsId <= SC_LAST_RTS_WITH_EVENTS) + if (Cmd->Payload.RtsNum <= SC_LAST_RTS_WITH_EVENTS) { CFE_EVS_SendEvent(SC_RTS_START_INF_EID, CFE_EVS_EventType_INFORMATION, - "RTS Number %03d Started", RtsId); + "RTS Number %03d Started", RtsNum); } else { CFE_EVS_SendEvent(SC_STARTRTS_CMD_DBG_EID, CFE_EVS_EventType_DEBUG, "Start RTS #%d command", - RtsId); + RtsNum); } } else @@ -123,7 +123,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) CFE_EVS_SendEvent( SC_STARTRTS_CMD_INVLD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, "Start RTS %03d Rejected: Invld Len Field for 1st Cmd in Sequence. Invld Cmd Length = %d", - RtsId, (int)CmdLength); + RtsNum, (int)CmdLength); SC_OperData.HkPacket.Payload.CmdErrCtr++; SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -134,7 +134,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) { /* Cannot use the RTS now */ CFE_EVS_SendEvent(SC_STARTRTS_CMD_NOT_LDED_ERR_EID, CFE_EVS_EventType_ERROR, - "Start RTS %03d Rejected: RTS Not Loaded or In Use, Status: %d", Cmd->Payload.RtsId, + "Start RTS %03d Rejected: RTS Not Loaded or In Use, Status: %d", Cmd->Payload.RtsNum, SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus); SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -145,7 +145,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) else { /* the RTS is disabled */ CFE_EVS_SendEvent(SC_STARTRTS_CMD_DISABLED_ERR_EID, CFE_EVS_EventType_ERROR, - "Start RTS %03d Rejected: RTS Disabled", RtsId); + "Start RTS %03d Rejected: RTS Disabled", RtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -154,7 +154,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) else { /* the rts id is invalid */ CFE_EVS_SendEvent(SC_STARTRTS_CMD_INVALID_ERR_EID, CFE_EVS_EventType_ERROR, - "Start RTS %03d Rejected: Invalid RTS ID", RtsId); + "Start RTS %03d Rejected: Invalid RTS ID", RtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -168,23 +168,23 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) { - uint16 FirstId; - uint16 LastId; - uint16 FirstIndex; /* RTS array index */ - uint16 LastIndex; - uint16 RtsIndex; - int32 StartCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 StartCount = 0; - FirstId = Cmd->Payload.FirstRtsId; - LastId = Cmd->Payload.LastRtsId; + FirstRtsNum = Cmd->Payload.FirstRtsNum; + LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstId > 0) && (LastId > 0) && (FirstId <= SC_NUMBER_OF_RTS) && (LastId <= SC_NUMBER_OF_RTS) && - (FirstId <= LastId)) + if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && + (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) { /* convert RTS ID to RTS array index */ - FirstIndex = SC_RTS_ID_TO_INDEX(FirstId); - LastIndex = SC_RTS_ID_TO_INDEX(LastId); + FirstIndex = SC_RtsNumToIndex(FirstRtsNum); + LastIndex = SC_RtsNumToIndex(LastRtsNum); for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { @@ -216,7 +216,7 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) CFE_EVS_SendEvent( SC_STARTRTSGRP_CMD_NOT_LDED_ERR_EID, CFE_EVS_EventType_ERROR, "Start RTS group error: rejected RTS ID %03d, RTS Not Loaded or In Use, Status: %d", - SC_RTS_INDEX_TO_ID(RtsIndex), SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus); + SC_RtsIndexToNum(RtsIndex), SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus); SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -226,7 +226,7 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) { /* the RTS is disabled */ CFE_EVS_SendEvent(SC_STARTRTSGRP_CMD_DISABLED_ERR_EID, CFE_EVS_EventType_ERROR, "Start RTS group error: rejected RTS ID %03d, RTS Disabled", - SC_RTS_INDEX_TO_ID(RtsIndex)); + SC_RtsIndexToNum(RtsIndex)); SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -235,13 +235,14 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) /* success */ CFE_EVS_SendEvent(SC_STARTRTSGRP_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, - "Start RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstId, LastId, (int)StartCount); + "Start RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstRtsNum, LastRtsNum, + (int)StartCount); SC_OperData.HkPacket.Payload.CmdCtr++; } else { /* error */ CFE_EVS_SendEvent(SC_STARTRTSGRP_CMD_ERR_EID, CFE_EVS_EventType_ERROR, - "Start RTS group error: FirstID=%d, LastID=%d", FirstId, LastId); + "Start RTS group error: FirstID=%d, LastID=%d", FirstRtsNum, LastRtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; } } @@ -253,30 +254,30 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StopRtsCmd(const SC_StopRtsCmd_t *Cmd) { - uint16 RtsId; /* RTS ID */ - uint16 RtsIndex; /* RTS array index */ + SC_RtsNum_t RtsNum; /* RTS number */ + SC_RtsIndex_t RtsIndex; /* RTS array index */ - RtsId = Cmd->Payload.RtsId; + RtsNum = Cmd->Payload.RtsNum; /* check the command parameter */ - if (RtsId <= SC_NUMBER_OF_RTS) + if (RtsNum <= SC_NUMBER_OF_RTS) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RTS_ID_TO_INDEX(RtsId); + RtsIndex = SC_RtsNumToIndex(RtsNum); /* stop the rts by calling a generic routine */ SC_KillRts(RtsIndex); SC_OperData.HkPacket.Payload.CmdCtr++; - CFE_EVS_SendEvent(SC_STOPRTS_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, "RTS %03d Aborted", RtsId); + CFE_EVS_SendEvent(SC_STOPRTS_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, "RTS %03d Aborted", RtsNum); } else { /* the specified RTS is invalid */ /* the rts id is invalid */ CFE_EVS_SendEvent(SC_STOPRTS_CMD_ERR_EID, CFE_EVS_EventType_ERROR, "Stop RTS %03d rejected: Invalid RTS ID", - RtsId); + RtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -290,23 +291,23 @@ void SC_StopRtsCmd(const SC_StopRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) { - uint16 FirstId; - uint16 LastId; - uint16 FirstIndex; /* RTS array index */ - uint16 LastIndex; - uint16 RtsIndex; - int32 StopCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 StopCount = 0; - FirstId = Cmd->Payload.FirstRtsId; - LastId = Cmd->Payload.LastRtsId; + FirstRtsNum = Cmd->Payload.FirstRtsNum; + LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstId > 0) && (LastId > 0) && (FirstId <= SC_NUMBER_OF_RTS) && (LastId <= SC_NUMBER_OF_RTS) && - (FirstId <= LastId)) + if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && + (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) { /* convert RTS ID to RTS array index */ - FirstIndex = SC_RTS_ID_TO_INDEX(FirstId); - LastIndex = SC_RTS_ID_TO_INDEX(LastId); + FirstIndex = SC_RtsNumToIndex(FirstRtsNum); + LastIndex = SC_RtsNumToIndex(LastRtsNum); for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { @@ -320,13 +321,14 @@ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) /* success */ CFE_EVS_SendEvent(SC_STOPRTSGRP_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, - "Stop RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstId, LastId, (int)StopCount); + "Stop RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstRtsNum, LastRtsNum, + (int)StopCount); SC_OperData.HkPacket.Payload.CmdCtr++; } else { /* error */ CFE_EVS_SendEvent(SC_STOPRTSGRP_CMD_ERR_EID, CFE_EVS_EventType_ERROR, - "Stop RTS group error: FirstID=%d, LastID=%d", FirstId, LastId); + "Stop RTS group error: FirstID=%d, LastID=%d", FirstRtsNum, LastRtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; } } @@ -338,16 +340,16 @@ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) { - uint16 RtsId; /* RTS ID */ - uint16 RtsIndex; /* RTS array index */ + SC_RtsNum_t RtsNum; /* RTS number */ + SC_RtsIndex_t RtsIndex; /* RTS array index */ - RtsId = Cmd->Payload.RtsId; + RtsNum = Cmd->Payload.RtsNum; /* make sure tha specified rts is valid */ - if (RtsId <= SC_NUMBER_OF_RTS) + if (RtsNum <= SC_NUMBER_OF_RTS) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RTS_ID_TO_INDEX(RtsId); + RtsIndex = SC_RtsNumToIndex(RtsNum); /* disable the RTS */ SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; @@ -355,12 +357,12 @@ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) /* update the command status */ SC_OperData.HkPacket.Payload.CmdCtr++; - CFE_EVS_SendEvent(SC_DISABLE_RTS_DEB_EID, CFE_EVS_EventType_DEBUG, "Disabled RTS %03d", RtsId); + CFE_EVS_SendEvent(SC_DISABLE_RTS_DEB_EID, CFE_EVS_EventType_DEBUG, "Disabled RTS %03d", RtsNum); } else { /* it is not a valid RTS id */ CFE_EVS_SendEvent(SC_DISRTS_CMD_ERR_EID, CFE_EVS_EventType_ERROR, "Disable RTS %03d Rejected: Invalid RTS ID", - RtsId); + RtsNum); /* update the command error status */ SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -374,23 +376,23 @@ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) { - uint16 FirstId; - uint16 LastId; - uint16 FirstIndex; /* RTS array index */ - uint16 LastIndex; - uint16 RtsIndex; - int32 DisableCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 DisableCount = 0; - FirstId = Cmd->Payload.FirstRtsId; - LastId = Cmd->Payload.LastRtsId; + FirstRtsNum = Cmd->Payload.FirstRtsNum; + LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstId > 0) && (LastId > 0) && (FirstId <= SC_NUMBER_OF_RTS) && (LastId <= SC_NUMBER_OF_RTS) && - (FirstId <= LastId)) + if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && + (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) { /* convert RTS ID to RTS array index */ - FirstIndex = SC_RTS_ID_TO_INDEX(FirstId); - LastIndex = SC_RTS_ID_TO_INDEX(LastId); + FirstIndex = SC_RtsNumToIndex(FirstRtsNum); + LastIndex = SC_RtsNumToIndex(LastRtsNum); for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { @@ -404,13 +406,14 @@ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) /* success */ CFE_EVS_SendEvent(SC_DISRTSGRP_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, - "Disable RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstId, LastId, (int)DisableCount); + "Disable RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstRtsNum, LastRtsNum, + (int)DisableCount); SC_OperData.HkPacket.Payload.CmdCtr++; } else { /* error */ CFE_EVS_SendEvent(SC_DISRTSGRP_CMD_ERR_EID, CFE_EVS_EventType_ERROR, - "Disable RTS group error: FirstID=%d, LastID=%d", FirstId, LastId); + "Disable RTS group error: FirstID=%d, LastID=%d", FirstRtsNum, LastRtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; } } @@ -422,16 +425,16 @@ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) { - uint16 RtsId; /* RTS ID */ - uint16 RtsIndex; /* RTS array index */ + SC_RtsNum_t RtsNum; /* RTS number */ + SC_RtsIndex_t RtsIndex; /* RTS array index */ - RtsId = Cmd->Payload.RtsId; + RtsNum = Cmd->Payload.RtsNum; /* make sure the specified rts is valid */ - if ((RtsId > 0) && (RtsId <= SC_NUMBER_OF_RTS)) + if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RTS_ID_TO_INDEX(RtsId); + RtsIndex = SC_RtsNumToIndex(RtsNum); /* re-enable the RTS */ SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; @@ -439,12 +442,12 @@ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) /* update the command status */ SC_OperData.HkPacket.Payload.CmdCtr++; - CFE_EVS_SendEvent(SC_ENABLE_RTS_DEB_EID, CFE_EVS_EventType_DEBUG, "Enabled RTS %03d", RtsId); + CFE_EVS_SendEvent(SC_ENABLE_RTS_DEB_EID, CFE_EVS_EventType_DEBUG, "Enabled RTS %03d", RtsNum); } else { /* it is not a valid RTS id */ CFE_EVS_SendEvent(SC_ENARTS_CMD_ERR_EID, CFE_EVS_EventType_ERROR, "Enable RTS %03d Rejected: Invalid RTS ID", - RtsId); + RtsNum); /* update the command error status */ SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -459,23 +462,23 @@ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) { - uint16 FirstId; - uint16 LastId; - uint16 FirstIndex; /* RTS array index */ - uint16 LastIndex; - uint16 RtsIndex; - int32 EnableCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 EnableCount = 0; - FirstId = Cmd->Payload.FirstRtsId; - LastId = Cmd->Payload.LastRtsId; + FirstRtsNum = Cmd->Payload.FirstRtsNum; + LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstId > 0) && (LastId > 0) && (FirstId <= SC_NUMBER_OF_RTS) && (LastId <= SC_NUMBER_OF_RTS) && - (FirstId <= LastId)) + if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && + (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) { /* convert RTS ID to RTS array index */ - FirstIndex = SC_RTS_ID_TO_INDEX(FirstId); - LastIndex = SC_RTS_ID_TO_INDEX(LastId); + FirstIndex = SC_RtsNumToIndex(FirstRtsNum); + LastIndex = SC_RtsNumToIndex(LastRtsNum); for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { @@ -489,13 +492,14 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) /* success */ CFE_EVS_SendEvent(SC_ENARTSGRP_CMD_INF_EID, CFE_EVS_EventType_INFORMATION, - "Enable RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstId, LastId, (int)EnableCount); + "Enable RTS group: FirstID=%d, LastID=%d, Modified=%d", FirstRtsNum, LastRtsNum, + (int)EnableCount); SC_OperData.HkPacket.Payload.CmdCtr++; } else { /* error */ CFE_EVS_SendEvent(SC_ENARTSGRP_CMD_ERR_EID, CFE_EVS_EventType_ERROR, - "Enable RTS group error: FirstID=%d, LastID=%d", FirstId, LastId); + "Enable RTS group error: FirstID=%d, LastID=%d", FirstRtsNum, LastRtsNum); SC_OperData.HkPacket.Payload.CmdErrCtr++; } } @@ -505,7 +509,7 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) /* Kill an RTS and clear out its data */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_KillRts(uint16 RtsIndex) +void SC_KillRts(SC_RtsIndex_t RtsIndex) { /* validate RTS array index */ if (RtsIndex >= SC_NUMBER_OF_RTS) @@ -539,14 +543,14 @@ void SC_KillRts(uint16 RtsIndex) /* Start an RTS on initilization */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_AutoStartRts(uint16 RtsNumber) +void SC_AutoStartRts(SC_RtsNum_t RtsNum) { SC_StartRtsCmd_t CmdPkt; /* the command packet to start an RTS */ memset(&CmdPkt, 0, sizeof(CmdPkt)); /* validate RTS ID */ - if ((RtsNumber > 0) && (RtsNumber <= SC_NUMBER_OF_RTS)) + if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) { /* ** Format the command packet to start the first RTS @@ -558,7 +562,7 @@ void SC_AutoStartRts(uint16 RtsNumber) /* ** Get the RTS ID to start. */ - CmdPkt.Payload.RtsId = RtsNumber; + CmdPkt.Payload.RtsNum = RtsNum; /* ** Now send the command back to SC @@ -568,6 +572,6 @@ void SC_AutoStartRts(uint16 RtsNumber) else { CFE_EVS_SendEvent(SC_AUTOSTART_RTS_INV_ID_ERR_EID, CFE_EVS_EventType_ERROR, - "RTS autostart error: invalid RTS ID %d", RtsNumber); + "RTS autostart error: invalid RTS ID %d", RtsNum); } } diff --git a/fsw/src/sc_rtsrq.h b/fsw/src/sc_rtsrq.h index 7076c60..648d813 100644 --- a/fsw/src/sc_rtsrq.h +++ b/fsw/src/sc_rtsrq.h @@ -27,6 +27,7 @@ #define SC_RTSRQ_H #include "common_types.h" +#include "sc_index_types.h" #include "sc_msg.h" /** @@ -160,7 +161,7 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd); * * \param [in] RtsIndex RTS index to kill (base zero) */ -void SC_KillRts(uint16 RtsIndex); +void SC_KillRts(SC_RtsIndex_t RtsIndex); /** * \brief Automatically starts an RTS @@ -172,8 +173,8 @@ void SC_KillRts(uint16 RtsIndex); * \par Assumptions, External Events, and Notes: * None * - * \param [in] RtsNumber RTS number to start (base one) + * \param [in] RtsNum RTS number to start (base one) */ -void SC_AutoStartRts(uint16 RtsNumber); +void SC_AutoStartRts(SC_RtsNum_t RtsNum); #endif diff --git a/fsw/src/sc_state.c b/fsw/src/sc_state.c index 50b1576..5db0cab 100644 --- a/fsw/src/sc_state.c +++ b/fsw/src/sc_state.c @@ -48,7 +48,7 @@ **************************************************************************/ /* used for RTS table iteration */ -#define SC_INVALID_RTS_INDEX 0xFFFF +#define SC_INVALID_RTS_INDEX ((SC_RtsIndex_t) {-1}) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -58,7 +58,7 @@ void SC_GetNextRtsTime(void) { int16 i; /* loop counter MUST be SIGNED !*/ - uint16 NextRts; /* the next rts to schedule */ + SC_RtsIndex_t NextRts; /* the next rts to schedule */ SC_AbsTimeTag_t NextTime; /* the next time for the RTS */ NextRts = SC_INVALID_RTS_INDEX; @@ -77,20 +77,20 @@ void SC_GetNextRtsTime(void) if (SC_OperData.RtsInfoTblAddr[i].NextCommandTime <= NextTime) { NextTime = SC_OperData.RtsInfoTblAddr[i].NextCommandTime; - NextRts = i; + NextRts = SC_RTS_IDX_C(i); } /* end if */ } /* end if */ } /* end for */ if (NextRts == SC_INVALID_RTS_INDEX) { - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_INVALID_RTS_NUMBER; - SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_TIME; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_NULL; + SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_TIME; } else { - SC_OperData.RtsCtrlBlckAddr->RtsNumber = NextRts + 1; - SC_AppData.NextCmdTime[SC_Process_RTP] = NextTime; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = NextRts + 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = NextTime; } /* end if */ } @@ -123,7 +123,7 @@ void SC_UpdateNextTime(void) ** 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_OperData.RtsCtrlBlckAddr->RtsNumber > 0) + if (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) { /* ** If the RTP needs to send commands, only send them if @@ -144,19 +144,19 @@ void SC_UpdateNextTime(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_GetNextRtsCommand(void) { - uint16 RtsIndex; - uint16 CmdOffset; - SC_RtsEntry_t *EntryPtr; - CFE_MSG_Size_t CmdLength = 0; + SC_RtsIndex_t RtsIndex; + SC_EntryOffset_t CmdOffset; + SC_RtsEntry_t * EntryPtr; + CFE_MSG_Size_t CmdLength = 0; /* ** Make sure that the RTP is executing some RTS */ - if ((SC_OperData.RtsCtrlBlckAddr->RtsNumber > 0) && (SC_OperData.RtsCtrlBlckAddr->RtsNumber <= SC_NUMBER_OF_RTS)) + if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS)) { /* Get the index of the rts that is running */ - RtsIndex = SC_RTS_NUM_TO_INDEX(SC_OperData.RtsCtrlBlckAddr->RtsNumber); + RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); /* ** Find out if the RTS is EXECUTING or just STARTED */ @@ -240,7 +240,7 @@ void SC_GetNextRtsCommand(void) */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; - SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->RtsNumber; + SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; /* @@ -249,7 +249,7 @@ void SC_GetNextRtsCommand(void) SC_KillRts(RtsIndex); CFE_EVS_SendEvent(SC_RTS_LNGTH_ERR_EID, CFE_EVS_EventType_ERROR, "Cmd Runs passed end of table, RTS %03d Aborted", - SC_OperData.RtsCtrlBlckAddr->RtsNumber); + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); } /* end if the command runs off the end of the buffer */ } @@ -259,14 +259,14 @@ void SC_GetNextRtsCommand(void) /* update the error information */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; - SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->RtsNumber; + SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; /* Stop the RTS from executing */ SC_KillRts(RtsIndex); CFE_EVS_SendEvent(SC_RTS_CMD_LNGTH_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Length Field in RTS Command, RTS %03d Aborted. Length: %u, Max: %d", - SC_OperData.RtsCtrlBlckAddr->RtsNumber, + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, (unsigned int)(CmdLength - (uint16)SC_RTS_HEADER_SIZE), SC_PACKET_MAX_SIZE); } /* end if the command length is invalid */ @@ -279,10 +279,10 @@ void SC_GetNextRtsCommand(void) /* Stop the RTS from executing */ SC_KillRts(RtsIndex); - if ((SC_OperData.RtsCtrlBlckAddr->RtsNumber) <= SC_LAST_RTS_WITH_EVENTS) + if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum) <= SC_LAST_RTS_WITH_EVENTS) { CFE_EVS_SendEvent(SC_RTS_COMPL_INF_EID, CFE_EVS_EventType_INFORMATION, - "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->RtsNumber); + "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); } } } @@ -290,10 +290,10 @@ void SC_GetNextRtsCommand(void) { /* The end of the RTS buffer has been reached... */ /* Stop the RTS from executing */ SC_KillRts(RtsIndex); - if ((SC_OperData.RtsCtrlBlckAddr->RtsNumber) <= SC_LAST_RTS_WITH_EVENTS) + if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum) <= SC_LAST_RTS_WITH_EVENTS) { CFE_EVS_SendEvent(SC_RTS_COMPL_INF_EID, CFE_EVS_EventType_INFORMATION, - "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->RtsNumber); + "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); } } /* end if */ @@ -310,17 +310,17 @@ void SC_GetNextRtsCommand(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_GetNextAtsCommand(void) { - uint16 AtsIndex; /* ats array index */ - uint16 TimeIndex; /* a time index pointer */ - uint16 CmdIndex; /* ats command array index */ - SC_AtsEntry_t *EntryPtr; + SC_AtsIndex_t AtsIndex; /* ats array index */ + SC_SeqIndex_t TimeIndex; /* a time index pointer */ + SC_EntryOffset_t CmdIndex; /* ats command array index */ + SC_AtsEntry_t * EntryPtr; if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { /* ** Get the information that is needed to find the next command */ - AtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); TimeIndex = SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr + 1; /* @@ -334,7 +334,7 @@ void SC_GetNextAtsCommand(void) /* update the next command time */ CmdIndex = - SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_ATS_CMD_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->CmdNumber)]; + SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_CommandNumToIndex(SC_OperData.AtsCtrlBlckAddr->CmdNumber)]; EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][CmdIndex]; SC_AppData.NextCmdTime[SC_Process_ATP] = SC_GetAtsEntryTime(&EntryPtr->Header); } diff --git a/fsw/src/sc_utils.c b/fsw/src/sc_utils.c index ebc315f..0895590 100644 --- a/fsw/src/sc_utils.c +++ b/fsw/src/sc_utils.c @@ -154,9 +154,9 @@ bool SC_CompareAbsTime(SC_AbsTimeTag_t AbsTime1, SC_AbsTimeTag_t AbsTime2) return Status; } -uint16 SC_ToggleAtsIndex(void) +SC_AtsIndex_t SC_ToggleAtsIndex(void) { - uint16 CurrAtsIndex = SC_ATS_NUM_TO_INDEX(SC_OperData.AtsCtrlBlckAddr->AtsNumber); + SC_AtsIndex_t CurrAtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); return (1 - CurrAtsIndex); } diff --git a/fsw/src/sc_utils.h b/fsw/src/sc_utils.h index ddf05a2..3f87d0f 100644 --- a/fsw/src/sc_utils.h +++ b/fsw/src/sc_utils.h @@ -107,7 +107,7 @@ bool SC_CompareAbsTime(SC_AbsTimeTag_t AbsTime1, SC_AbsTimeTag_t AbsTime2); * * \sa #SC_LEN_ERR_EID */ -uint16 SC_ToggleAtsIndex(void); +SC_AtsIndex_t SC_ToggleAtsIndex(void); /** * \brief Finds the time accessor object associated with the given time ref diff --git a/fsw/tables/sc_ats1.c b/fsw/tables/sc_ats1.c index afed0e1..9fd3380 100644 --- a/fsw/tables/sc_ats1.c +++ b/fsw/tables/sc_ats1.c @@ -95,29 +95,29 @@ typedef union /* Used designated intializers to be verbose, modify as needed/desired */ SC_AtsTable1_t SC_Ats1 = { /* 1 */ - .ats.hdr1.CmdNumber = 1, + .ats.hdr1.CmdNumber = SC_COMMAND_NUM_INITIALIZER(1), .ats.hdr1.TimeTag_MS = SC_CMD1_TIME >> 16, .ats.hdr1.TimeTag_LS = SC_CMD1_TIME & 0xFFFF, .ats.cmd1.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd1), SC_NOOP_CC, SC_NOOP_CKSUM), /* 2 */ - .ats.hdr2.CmdNumber = 2, + .ats.hdr2.CmdNumber = SC_COMMAND_NUM_INITIALIZER(2), .ats.hdr2.TimeTag_MS = SC_CMD2_TIME >> 16, .ats.hdr2.TimeTag_LS = SC_CMD2_TIME & 0xFFFF, .ats.cmd2.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd2), SC_ENABLE_RTS_CC, SC_ENABLE_RTS1_CKSUM), - .ats.cmd2.Payload.RtsId = 1, + .ats.cmd2.Payload.RtsNum = SC_RTS_NUM_INITIALIZER(1), /* 3 */ - .ats.hdr3.CmdNumber = 3, + .ats.hdr3.CmdNumber = SC_COMMAND_NUM_INITIALIZER(3), .ats.hdr3.TimeTag_MS = SC_CMD3_TIME >> 16, .ats.hdr3.TimeTag_LS = SC_CMD3_TIME & 0xFFFF, .ats.cmd3.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_START_RTS_CC, SC_START_RTS1_CKSUM), - .ats.cmd3.Payload.RtsId = 1, + .ats.cmd3.Payload.RtsNum = SC_RTS_NUM_INITIALIZER(1), /* 4 */ - .ats.hdr4.CmdNumber = 4, + .ats.hdr4.CmdNumber = SC_COMMAND_NUM_INITIALIZER(4), .ats.hdr4.TimeTag_MS = SC_CMD4_TIME >> 16, .ats.hdr4.TimeTag_LS = SC_CMD4_TIME & 0xFFFF, .ats.cmd4.CommandHeader = diff --git a/fsw/tables/sc_rts001.c b/fsw/tables/sc_rts001.c index bd2f5d1..94f8017 100644 --- a/fsw/tables/sc_rts001.c +++ b/fsw/tables/sc_rts001.c @@ -85,13 +85,13 @@ SC_RtsTable001_t SC_Rts001 = { .rts.hdr2.TimeTag = 5, .rts.cmd2.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd2), SC_ENABLE_RTS_CC, SC_ENABLE_RTS2_CKSUM), - .rts.cmd2.Payload.RtsId = 2, + .rts.cmd2.Payload.RtsNum = SC_RTS_NUM_INITIALIZER(2), /* 3 */ .rts.hdr3.TimeTag = 5, .rts.cmd3.CommandHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_START_RTS_CC, SC_START_RTS2_CKSUM), - .rts.cmd3.Payload.RtsId = 2}; + .rts.cmd3.Payload.RtsNum = SC_RTS_NUM_INITIALIZER(2)}; /* Macro for table structure */ CFE_TBL_FILEDEF(SC_Rts001, SC.RTS_TBL001, SC Example RTS_TBL001, sc_rts001.tbl) diff --git a/mission_build.cmake b/mission_build.cmake index d3b9abf..9f2eb26 100644 --- a/mission_build.cmake +++ b/mission_build.cmake @@ -13,6 +13,7 @@ add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/docs/dox_src ${MISSION_BINARY_DIR}/do # The list of header files that control the SC configuration set(SC_MISSION_CONFIG_FILE_LIST + sc_extern_typedefs.h sc_fcncodes.h sc_interface_cfg.h sc_mission_cfg.h diff --git a/unit-test/sc_app_tests.c b/unit-test/sc_app_tests.c index 2549d3f..1a4d03a 100644 --- a/unit-test/sc_app_tests.c +++ b/unit-test/sc_app_tests.c @@ -149,7 +149,7 @@ void SC_AppInit_Test_NominalPowerOnReset(void) 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_TIME; - Expected_SC_AppData.AutoStartRTS = RTS_ID_AUTO_POWER_ON; + Expected_SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_POWER_ON); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); @@ -213,7 +213,7 @@ void SC_AppInit_Test_Nominal(void) 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_TIME; - Expected_SC_AppData.AutoStartRTS = RTS_ID_AUTO_PROCESSOR; + Expected_SC_AppData.AutoStartRTS = SC_RTS_NUM_C(RTS_ID_AUTO_PROCESSOR); Expected_SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = SC_AtsCont_TRUE; diff --git a/unit-test/sc_atsrq_tests.c b/unit-test/sc_atsrq_tests.c index d1d6e56..8a9f3b3 100644 --- a/unit-test/sc_atsrq_tests.c +++ b/unit-test/sc_atsrq_tests.c @@ -67,10 +67,11 @@ CFE_TIME_Compare_t UT_SC_StartAtsRq_CompareHook3(void *UserObj, int32 StubRetcod void SC_StartAtsCmd_Test_NominalA(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; @@ -89,10 +90,11 @@ void SC_StartAtsCmd_Test_NominalA(void) void SC_StartAtsCmd_Test_NominalB(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 2; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; @@ -112,13 +114,14 @@ void SC_StartAtsCmd_Test_CouldNotStart(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; @@ -139,11 +142,12 @@ void SC_StartAtsCmd_Test_NoCommandsA(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 0; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; @@ -161,11 +165,12 @@ void SC_StartAtsCmd_Test_NoCommandsB(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 2; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; @@ -187,7 +192,7 @@ void SC_StartAtsCmd_Test_InUse(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(1); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; /* Execute the function being tested */ @@ -208,7 +213,7 @@ void SC_StartAtsCmd_Test_InvalidAtsId(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 99; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(99); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; /* Execute the function being tested */ @@ -229,7 +234,7 @@ void SC_StartAtsCmd_Test_InvalidAtsIdZero(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 0; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(0); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; /* Execute the function being tested */ @@ -250,7 +255,7 @@ void SC_StopAtsCmd_Test_NominalA(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopAtsCmd(&UT_CmdBuf.StopAtsCmd)); @@ -270,7 +275,7 @@ void SC_StopAtsCmd_Test_NominalB(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSB; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopAtsCmd(&UT_CmdBuf.StopAtsCmd)); @@ -290,7 +295,7 @@ void SC_StopAtsCmd_Test_NoRunningAts(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 99; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(99); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopAtsCmd(&UT_CmdBuf.StopAtsCmd)); @@ -304,8 +309,8 @@ void SC_StopAtsCmd_Test_NoRunningAts(void) void SC_BeginAts_Test_Nominal(void) { - uint16 AtsIndex = 0; - uint16 TimeOffset = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint16 TimeOffset = 0; SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; @@ -313,10 +318,10 @@ void SC_BeginAts_Test_Nominal(void) UtAssert_BOOL_TRUE(SC_BeginAts(AtsIndex, TimeOffset)); /* Verify results */ - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtsNumber == 1, "SC_OperData.AtsCtrlBlckAddr->AtsNumber == 1"); + SC_Assert_ID_VALUE(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum, 1); UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 0, "SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 0"); + SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 0); UtAssert_True(SC_AppData.NextCmdTime[SC_Process_ATP] == 0, "SC_AppData.NextCmdTime[SC_Process_ATP] == 0"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_ERR_SKP_DBG_EID); @@ -325,8 +330,8 @@ void SC_BeginAts_Test_Nominal(void) void SC_BeginAts_Test_AllCommandsSkipped(void) { - uint16 AtsIndex = 0; - uint16 TimeOffset = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint16 TimeOffset = 0; UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); @@ -349,16 +354,8 @@ void SC_BeginAts_Test_AllCommandsSkipped(void) void SC_BeginAts_Test_InvalidAtsIndex(void) { - uint16 AtsIndex = SC_NUMBER_OF_ATS; - uint16 TimeOffset = 0; - - UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - - SC_AppData.AtsTimeIndexBuffer[0][0] = 1; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - - /* Set to cause all commnds to be skipped, to generate error message SC_ATS_SKP_ALL_ERR_EID */ - UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); + uint16 TimeOffset = 0; /* Execute the function being tested */ UtAssert_BOOL_FALSE(SC_BeginAts(AtsIndex, TimeOffset)); @@ -370,8 +367,10 @@ void SC_BeginAts_Test_InvalidAtsIndex(void) void SC_KillAts_Test(void) { - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = 99; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)99; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_KillAts()); @@ -388,11 +387,12 @@ void SC_KillAts_Test(void) void SC_SwitchAtsCmd_Test_Nominal(void) { + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; @@ -412,11 +412,12 @@ void SC_SwitchAtsCmd_Test_Nominal(void) void SC_SwitchAtsCmd_Test_DestinationAtsNotLoaded(void) { + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; @@ -438,8 +439,8 @@ void SC_SwitchAtsCmd_Test_AtpIdle(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = 99; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)99; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_SwitchAtsCmd(&UT_CmdBuf.SwitchAtsCmd)); @@ -455,16 +456,20 @@ void SC_SwitchAtsCmd_Test_AtpIdle(void) void SC_ServiceSwitchPend_Test_NominalA(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_AppData.AtsTimeIndexBuffer[AtsIndex1][0] = 1; UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -483,16 +488,20 @@ void SC_ServiceSwitchPend_Test_NominalA(void) void SC_ServiceSwitchPend_Test_NominalB(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 2; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_AppData.AtsTimeIndexBuffer[AtsIndex0][0] = 1; UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 0); @@ -517,7 +526,7 @@ void SC_ServiceSwitchPend_Test_AtsEmpty(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 0; SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; @@ -541,7 +550,7 @@ void SC_ServiceSwitchPend_Test_AtpIdle(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtpState = 99; + SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)99; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ServiceSwitchPend()); @@ -571,6 +580,9 @@ void SC_ServiceSwitchPend_Test_NoSwitch(void) void SC_ServiceSwitchPend_Test_AtsNotStarted(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + /* Set to cause SC_BeginAts to return false, in order to reach block starting with "could not start the ats" */ UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); @@ -581,10 +593,10 @@ void SC_ServiceSwitchPend_Test_AtsNotStarted(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ServiceSwitchPend()); @@ -601,13 +613,17 @@ void SC_ServiceSwitchPend_Test_AtsNotStarted(void) void SC_InlineSwitch_Test_NominalA(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_AppData.AtsTimeIndexBuffer[AtsIndex1][0] = 1; UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -628,13 +644,17 @@ void SC_InlineSwitch_Test_NominalA(void) void SC_InlineSwitch_Test_NominalB(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 2; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_AppData.AtsTimeIndexBuffer[AtsIndex0][0] = 1; UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 0); @@ -655,15 +675,18 @@ void SC_InlineSwitch_Test_NominalB(void) void SC_InlineSwitch_Test_AllCommandsSkipped(void) { + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); /* Set to cause all commnds to be skipped, to reach block starting with comment "all of the commands in the new ats * were skipped" */ UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_BOOL_FALSE(SC_InlineSwitch()); @@ -678,9 +701,7 @@ void SC_InlineSwitch_Test_AllCommandsSkipped(void) void SC_InlineSwitch_Test_DestinationAtsNotLoaded(void) { - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 0; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 0); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -699,7 +720,7 @@ void SC_InlineSwitch_Test_DestinationAtsNotLoaded(void) void SC_JumpAtsCmd_Test_SkipOneCmd(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; @@ -716,9 +737,9 @@ void SC_JumpAtsCmd_Test_SkipOneCmd(void) SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] = SC_Status_LOADED; SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] = 2; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 2; + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(2); SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 2; /* Execute the function being tested */ @@ -731,7 +752,7 @@ void SC_JumpAtsCmd_Test_SkipOneCmd(void) "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_LOADED"); UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 1, "SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 1"); + SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); UtAssert_True(SC_AppData.NextCmdTime[0] == 0, "SC_AppData.NextCmdTime[0] == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); @@ -742,7 +763,7 @@ void SC_JumpAtsCmd_Test_SkipOneCmd(void) void SC_JumpAtsCmd_Test_AllCommandsSkipped(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; @@ -756,7 +777,7 @@ void SC_JumpAtsCmd_Test_AllCommandsSkipped(void) UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; @@ -792,7 +813,7 @@ void SC_JumpAtsCmd_Test_NoRunningAts(void) void SC_JumpAtsCmd_Test_AtsNotLoaded(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; @@ -807,7 +828,7 @@ void SC_JumpAtsCmd_Test_AtsNotLoaded(void) SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_SKIPPED; SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] = SC_Status_SKIPPED; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 2; @@ -821,7 +842,7 @@ void SC_JumpAtsCmd_Test_AtsNotLoaded(void) "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_SKIPPED"); UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 1, "SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr == 1"); + SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); UtAssert_True(SC_AppData.NextCmdTime[0] == 0, "SC_AppData.NextCmdTime[0] == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); @@ -880,7 +901,7 @@ void ContinueAtsOnFailureCmd_Test_InvalidState(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_ContinueAtsOnFailureCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.ContinueAtsOnFailureCmd.Payload.ContinueState = 99; + UT_CmdBuf.ContinueAtsOnFailureCmd.Payload.ContinueState = (SC_AtsCont_Enum_t)99; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ContinueAtsOnFailureCmd(&UT_CmdBuf.ContinueAtsOnFailureCmd)); @@ -895,7 +916,7 @@ void ContinueAtsOnFailureCmd_Test_InvalidState(void) void SC_AppendAtsCmd_Test_Nominal(void) { SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; @@ -903,9 +924,9 @@ void SC_AppendAtsCmd_Test_Nominal(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = 1; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.HkPacket.Payload.AppendEntryCount = 1; @@ -913,14 +934,14 @@ void SC_AppendAtsCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_AppendAtsCmd(&UT_CmdBuf.AppendAtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.HkPacket.Payload.AppendCmdArg == 1, "SC_OperData.HkPacket.Payload.AppendCmdArg == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.AppendCmdArg, 1); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_APPEND_CMD_INF_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_AppendAtsCmd_Test_InvalidAtsId(void) +void SC_AppendAtsCmd_Test_InvalidAtsNum(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; @@ -928,7 +949,7 @@ void SC_AppendAtsCmd_Test_InvalidAtsId(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 99; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(99); SC_OperData.HkPacket.Payload.AppendEntryCount = 1; /* Execute the function being tested */ @@ -941,7 +962,7 @@ void SC_AppendAtsCmd_Test_InvalidAtsId(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_AppendAtsCmd_Test_InvalidAtsIdZero(void) +void SC_AppendAtsCmd_Test_InvalidAtsNumZero(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; @@ -949,7 +970,7 @@ void SC_AppendAtsCmd_Test_InvalidAtsIdZero(void) UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 0; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(0); SC_OperData.HkPacket.Payload.AppendEntryCount = 1; /* Execute the function being tested */ @@ -964,14 +985,14 @@ void SC_AppendAtsCmd_Test_InvalidAtsIdZero(void) void SC_AppendAtsCmd_Test_AtsTableEmpty(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.HkPacket.Payload.AppendEntryCount = 1; SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 0; @@ -987,14 +1008,14 @@ void SC_AppendAtsCmd_Test_AtsTableEmpty(void) void SC_AppendAtsCmd_Test_AppendTableEmpty(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.HkPacket.Payload.AppendEntryCount = 0; SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; @@ -1010,14 +1031,14 @@ void SC_AppendAtsCmd_Test_AppendTableEmpty(void) void SC_AppendAtsCmd_Test_NoRoomForAppendInAts(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.HkPacket.Payload.AppendEntryCount = 1; SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize = SC_ATS_BUFF_SIZE; @@ -1085,9 +1106,10 @@ void UtTest_Setup(void) UtTest_Add(ContinueAtsOnFailureCmd_Test_InvalidState, SC_Test_Setup, SC_Test_TearDown, "ContinueAtsOnFailureCmd_Test_InvalidState"); UtTest_Add(SC_AppendAtsCmd_Test_Nominal, SC_Test_Setup, SC_Test_TearDown, "SC_AppendAtsCmd_Test_Nominal"); - UtTest_Add(SC_AppendAtsCmd_Test_InvalidAtsId, SC_Test_Setup, SC_Test_TearDown, "SC_AppendAtsCmd_Test_InvalidAtsId"); - UtTest_Add(SC_AppendAtsCmd_Test_InvalidAtsIdZero, SC_Test_Setup, SC_Test_TearDown, - "SC_AppendAtsCmd_Test_InvalidAtsIdZero"); + UtTest_Add(SC_AppendAtsCmd_Test_InvalidAtsNum, SC_Test_Setup, SC_Test_TearDown, + "SC_AppendAtsCmd_Test_InvalidAtsNum"); + UtTest_Add(SC_AppendAtsCmd_Test_InvalidAtsNumZero, SC_Test_Setup, SC_Test_TearDown, + "SC_AppendAtsCmd_Test_InvalidAtsNumZero"); UtTest_Add(SC_AppendAtsCmd_Test_AtsTableEmpty, SC_Test_Setup, SC_Test_TearDown, "SC_AppendAtsCmd_Test_AtsTableEmpty"); UtTest_Add(SC_AppendAtsCmd_Test_AppendTableEmpty, SC_Test_Setup, SC_Test_TearDown, diff --git a/unit-test/sc_cmds_tests.c b/unit-test/sc_cmds_tests.c index 3280d59..e7751e1 100644 --- a/unit-test/sc_cmds_tests.c +++ b/unit-test/sc_cmds_tests.c @@ -64,15 +64,16 @@ void SC_ProcessAtpCmd_Test_SwitchCmd(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -108,15 +109,16 @@ void SC_ProcessAtpCmd_Test_NonSwitchCmd(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -152,15 +154,16 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -188,8 +191,8 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void) UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB, "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == 1, "SC_OperData.HkPacket.Payload.LastAtsErrSeq == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, 1); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } @@ -199,17 +202,18 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -233,9 +237,8 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB, "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_DIST_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); @@ -247,17 +250,18 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[1][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSB; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[1][0] = 0; @@ -281,9 +285,8 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_DISTRIB, "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_DIST_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); @@ -296,17 +299,18 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -332,9 +336,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_CHECKSUM, "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); @@ -349,17 +352,18 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[1][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSB; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[1][0] = 0; @@ -385,9 +389,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM, "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); @@ -402,22 +405,23 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = true; + SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = SC_AtsCont_TRUE; SC_AppData.EnableHeaderUpdate = false; @@ -438,9 +442,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_CHECKSUM, "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); @@ -451,17 +454,18 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 3; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(3); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -472,9 +476,8 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED, "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED"); @@ -486,17 +489,18 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[1][0]; - Entry->CmdNumber = 3; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(3); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSB; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[1][0] = 0; @@ -507,9 +511,8 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSB"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_SKIPPED, "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_SKIPPED"); @@ -521,17 +524,18 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -541,10 +545,8 @@ void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA, - "SC_OperData.HkPacket.Payload.LastAtsErrSeq == SC_AtsId_ATSA"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 1"); - + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_SKP_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } @@ -552,17 +554,18 @@ void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) void SC_ProcessAtpCmd_Test_CompareAbsTime(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -580,17 +583,18 @@ void SC_ProcessAtpCmd_Test_CompareAbsTime(void) void SC_ProcessAtpCmd_Test_NextProcNumber(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_NONE; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -606,17 +610,18 @@ void SC_ProcessAtpCmd_Test_NextProcNumber(void) void SC_ProcessAtpCmd_Test_AtpState(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EMPTY; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = SC_AtsId_ATSA; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -634,15 +639,16 @@ void SC_ProcessAtpCmd_Test_CmdMid(void) SC_AtsEntryHeader_t *Entry; CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -674,11 +680,13 @@ void SC_ProcessAtpCmd_Test_CmdMid(void) void SC_ProcessRtpCommand_Test_Nominal(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = true; @@ -697,11 +705,13 @@ void SC_ProcessRtpCommand_Test_Nominal(void) void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = true; @@ -717,8 +727,8 @@ void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrSeq == 1, "SC_OperData.HkPacket.Payload.LastRtsErrSeq == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == 0, "SC_OperData.HkPacket.Payload.LastRtsErrCmd == 0"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrSeq, 1); + SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, 0); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_DIST_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -726,13 +736,14 @@ void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) void SC_ProcessRtpCommand_Test_BadChecksum(void) { - bool ChecksumValid; + bool ChecksumValid; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = false; @@ -749,8 +760,8 @@ void SC_ProcessRtpCommand_Test_BadChecksum(void) UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrSeq == 1, "SC_OperData.HkPacket.Payload.LastRtsErrSeq == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == 0, "SC_OperData.HkPacket.Payload.LastRtsErrCmd == 0"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrSeq, 1); + SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, 0); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_CHKSUM_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -758,11 +769,13 @@ void SC_ProcessRtpCommand_Test_BadChecksum(void) void SC_ProcessRtpCommand_Test_NextCmdTime(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 1; - SC_AppData.CurrentTime = 0; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 1; + SC_AppData.CurrentTime = 0; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -773,11 +786,13 @@ void SC_ProcessRtpCommand_Test_NextCmdTime(void) void SC_ProcessRtpCommand_Test_ProcNumber(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_NONE; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_NONE; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -786,27 +801,26 @@ void SC_ProcessRtpCommand_Test_ProcNumber(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_ProcessRtpCommand_Test_RtsNumberZero(void) +void SC_ProcessRtpCommand_Test_RtsNumZero(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 0; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(0); - /* RtsNumber > 0 will be false so nothing should happen, branch coverage */ + /* CurrRtsNum > 0 will be false so nothing should happen, branch coverage */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_ProcessRtpCommand_Test_RtsNumberHigh(void) +void SC_ProcessRtpCommand_Test_RtsNumHigh(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS + 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -817,11 +831,13 @@ void SC_ProcessRtpCommand_Test_RtsNumberHigh(void) void SC_ProcessRtpCommand_Test_RtsStatus(void) { - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EMPTY; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EMPTY; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -832,8 +848,9 @@ void SC_ProcessRtpCommand_Test_RtsStatus(void) void SC_SendHkPacket_Test(void) { - uint8 i; - int32 LastRtsHkIndex = 0; + uint8 i; + int32 LastRtsHkIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); SC_OperData.HkPacket.Payload.CmdErrCtr = 1; SC_OperData.HkPacket.Payload.CmdCtr = 2; @@ -843,24 +860,24 @@ void SC_SendHkPacket_Test(void) SC_OperData.HkPacket.Payload.AtsCmdErrCtr = 6; SC_OperData.HkPacket.Payload.RtsCmdCtr = 7; SC_OperData.HkPacket.Payload.RtsCmdErrCtr = 8; - SC_OperData.HkPacket.Payload.LastAtsErrSeq = 9; - SC_OperData.HkPacket.Payload.LastAtsErrCmd = 10; - SC_OperData.HkPacket.Payload.LastRtsErrSeq = 11; - SC_OperData.HkPacket.Payload.LastRtsErrCmd = 12; - SC_OperData.HkPacket.Payload.AppendCmdArg = 13; + SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_ATS_NUM_C(9); + SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_COMMAND_NUM_C(10); + SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_RTS_NUM_C(11); + SC_OperData.HkPacket.Payload.LastRtsErrCmd = SC_ENTRY_OFFSET_C(12); + SC_OperData.HkPacket.Payload.AppendCmdArg = SC_ATS_NUM_C(13); SC_OperData.HkPacket.Payload.AppendEntryCount = 14; SC_AppData.AppendWordCount = 15; SC_OperData.HkPacket.Payload.AppendLoadCount = 16; SC_OperData.AtsInfoTblAddr[0].AtsSize = 0; SC_OperData.AtsInfoTblAddr[1].AtsSize = 0; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 17; - SC_OperData.AtsCtrlBlckAddr->AtpState = 18; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 19; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(17); + SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)18; + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(19); SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag = 0; SC_AppData.NextCmdTime[0] = 0; SC_AppData.NextCmdTime[1] = 0; SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 20; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 21; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(21); SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = 1; for (i = 0; i < SC_NUMBER_OF_RTS - 1; i++) @@ -869,8 +886,8 @@ void SC_SendHkPacket_Test(void) SC_OperData.RtsInfoTblAddr[i].RtsStatus = SC_Status_EXECUTING; } - SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].DisabledFlag = 0; - SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].RtsStatus = 0; + SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = 0; + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = 0; LastRtsHkIndex = sizeof(SC_OperData.HkPacket.Payload.RtsExecutingStatus) / sizeof(SC_OperData.HkPacket.Payload.RtsExecutingStatus[0]) - @@ -889,11 +906,11 @@ void SC_SendHkPacket_Test(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 6, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 6"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdCtr == 7, "SC_OperData.HkPacket.Payload.RtsCmdCtr == 7"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 8, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 8"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrSeq == 9, "SC_OperData.HkPacket.Payload.LastAtsErrSeq == 9"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastAtsErrCmd == 10, "SC_OperData.HkPacket.Payload.LastAtsErrCmd == 10"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrSeq == 11, "SC_OperData.HkPacket.Payload.LastRtsErrSeq == 11"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == 12, "SC_OperData.HkPacket.Payload.LastRtsErrCmd == 12"); - UtAssert_True(SC_OperData.HkPacket.Payload.AppendCmdArg == 13, "SC_OperData.HkPacket.Payload.AppendCmdArg == 13"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, 9); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 10); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrSeq, 11); + SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, 12); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.AppendCmdArg, 13); UtAssert_True(SC_OperData.HkPacket.Payload.AppendEntryCount == 14, "SC_OperData.HkPacket.Payload.AppendEntryCount == 14"); UtAssert_True(SC_OperData.HkPacket.Payload.AppendLoadCount == 16, @@ -906,16 +923,15 @@ void SC_SendHkPacket_Test(void) (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - (SC_OperData.AtsInfoTblAddr[1].AtsSize * SC_BYTES_IN_WORD), "SC_OperData.HkPacket.Payload.AtpFreeBytes[1] == (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD)"); - UtAssert_True(SC_OperData.HkPacket.Payload.CurrAtsId == 17, "SC_OperData.HkPacket.Payload.CurrAtsId == 17"); + UtAssert_UINT8_EQ(SC_OperData.HkPacket.Payload.CurrAtsId, 17); UtAssert_True(SC_OperData.HkPacket.Payload.AtpState == 18, "SC_OperData.HkPacket.Payload.AtpState == 18"); - UtAssert_True(SC_OperData.HkPacket.Payload.AtpCmdNumber == 19, "SC_OperData.HkPacket.Payload.AtpCmdNumber == 19"); + UtAssert_UINT32_EQ(SC_OperData.HkPacket.Payload.AtpCmdNumber, 19); UtAssert_True(SC_OperData.HkPacket.Payload.SwitchPendFlag == 0, "SC_OperData.HkPacket.Payload.SwitchPendFlag == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.NextAtsTime == 0, "SC_OperData.HkPacket.Payload.NextAtsTime == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.NumRtsActive == 20, "SC_OperData.HkPacket.Payload.NumRtsActive == 20"); - UtAssert_True(SC_OperData.HkPacket.Payload.RtsNumber == 21, "SC_OperData.HkPacket.Payload.RtsNumber == 21"); + SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.RtsNum, 21); UtAssert_True(SC_OperData.HkPacket.Payload.NextRtsTime == 0, "SC_OperData.HkPacket.Payload.NextRtsTime == 0"); - UtAssert_True(SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag == 1, - "SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag == 1"); + UtAssert_BOOL_TRUE(SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag); /* Check first element */ UtAssert_True(SC_OperData.HkPacket.Payload.RtsExecutingStatus[0] == 65535, @@ -947,28 +963,33 @@ void SC_ProcessRequest_Test_HkMID(void) void SC_ProcessRequest_Test_HkMIDAutoStartRts(void) { - SC_AppData.AutoStartRTS = 1; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.AutoStartRTS = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_SendHkCmd(&UT_CmdBuf.SendHkCmd)); /* Verify results */ - UtAssert_UINT32_EQ(SC_AppData.AutoStartRTS, 0); - UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[SC_AppData.AutoStartRTS].DisabledFlag); + SC_Assert_ID_VALUE(SC_AppData.AutoStartRTS, 0); + UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessRequest_Test_HkMIDAutoStartRtsLoaded(void) { - SC_AppData.AutoStartRTS = 1; - SC_OperData.RtsInfoTblAddr[SC_AppData.AutoStartRTS - 1].RtsStatus = SC_Status_LOADED; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_AppData.AutoStartRTS = SC_RtsIndexToNum(RtsIndex); + + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_SendHkCmd(&UT_CmdBuf.SendHkCmd)); /* Verify results */ - UtAssert_UINT32_EQ(SC_AppData.AutoStartRTS, 0); + SC_Assert_ID_VALUE(SC_AppData.AutoStartRTS, 0); UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[SC_AppData.AutoStartRTS].DisabledFlag); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -1024,6 +1045,7 @@ void SC_ProcessRequest_Test_OneHzWakeupAtpNotExecutionTime(void) void SC_ProcessRequest_Test_OneHzWakeupRtpExecutionTime(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* required to exit processing loop after 2 iterations */ /* second iteration tests "IsThereAnotherCommandToExecute" */ @@ -1031,16 +1053,16 @@ void SC_ProcessRequest_Test_OneHzWakeupRtpExecutionTime(void) SC_CMDS_TEST_SC_UpdateNextTimeHook_RunCount = 0; UT_SetHookFunction(UT_KEY(SC_UpdateNextTime), Ut_SC_UpdateNextTimeHook, NULL); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_RTP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; /* Causes switch to ATP */ SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_OperData.NumCmdsSec = 3; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -1105,7 +1127,7 @@ void SC_ProcessCommand_Test_ResetCounters(void) void SC_ProcessCommand_Test_StartAts(void) { - UT_CmdBuf.StartAtsCmd.Payload.AtsId = 1; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_ATS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartAtsCmd(&UT_CmdBuf.StartAtsCmd)); @@ -1188,9 +1210,10 @@ void SC_ProcessCommand_Test_AppendAts(void) void SC_ProcessCommand_Test_TableManageAtsTableNominal(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 0; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; @@ -1221,9 +1244,10 @@ void SC_ProcessCommand_Test_TableManageAtsTableGetAddressError(void) void SC_ProcessCommand_Test_TableManageAtsTableID(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 0; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); /* test TableID >= SC_TBL_ID_ATS_0 */ UT_CmdBuf.ManageTableCmd.Payload.Parameter = 0; @@ -1252,9 +1276,10 @@ void SC_ProcessCommand_Test_TableManageAtsTable_InvalidIndex(void) void SC_ProcessCommand_Test_TableManageAtsTableGetAddressNeverLoaded(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 0; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; @@ -1275,11 +1300,11 @@ void SC_ProcessCommand_Test_TableManageAtsTableGetAddressSuccess(void) *to ** combine the tests for each command with the tests for reaching the command from SC_ProcessCommand. **/ - SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 0; + Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; @@ -1304,7 +1329,7 @@ void SC_ProcessCommand_Test_TableManageAppendTableNominal(void) SC_AtsEntryHeader_t *Entry; Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr; - Entry->CmdNumber = 0; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_APPEND; @@ -1345,7 +1370,7 @@ void SC_ProcessCommand_Test_TableManageAppendTableGetAddressNeverLoaded(void) SC_AtsEntryHeader_t *Entry; Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr; - Entry->CmdNumber = 0; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_APPEND; @@ -1370,7 +1395,7 @@ void SC_ProcessCommand_Test_TableManageAppendTableGetAddressSuccess(void) SC_AtsEntryHeader_t *Entry; Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AppendTblAddr; - Entry->CmdNumber = 0; + Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_APPEND; @@ -1593,10 +1618,10 @@ void UtTest_Setup(void) "SC_ProcessRtpCommand_Test_NextCmdTime"); UtTest_Add(SC_ProcessRtpCommand_Test_ProcNumber, SC_Test_Setup, SC_Test_TearDown, "SC_ProcessRtpCommand_Test_ProcNumber"); - UtTest_Add(SC_ProcessRtpCommand_Test_RtsNumberZero, SC_Test_Setup, SC_Test_TearDown, - "SC_ProcessRtpCommand_Test_RtsNumberZero"); - UtTest_Add(SC_ProcessRtpCommand_Test_RtsNumberHigh, SC_Test_Setup, SC_Test_TearDown, - "SC_ProcessRtpCommand_Test_RtsNumberHigh"); + UtTest_Add(SC_ProcessRtpCommand_Test_RtsNumZero, SC_Test_Setup, SC_Test_TearDown, + "SC_ProcessRtpCommand_Test_RtsNumZero"); + UtTest_Add(SC_ProcessRtpCommand_Test_RtsNumHigh, SC_Test_Setup, SC_Test_TearDown, + "SC_ProcessRtpCommand_Test_RtsNumHigh"); UtTest_Add(SC_ProcessRtpCommand_Test_RtsStatus, SC_Test_Setup, SC_Test_TearDown, "SC_ProcessRtpCommand_Test_RtsStatus"); UtTest_Add(SC_SendHkPacket_Test, SC_Test_Setup, SC_Test_TearDown, "SC_SendHkPacket_Test"); diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index f232823..39fa973 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -78,14 +78,14 @@ void UT_SC_Loads_Test_Setup(void) UT_SetHandlerFunction(UT_KEY(CFE_MSG_GetSize), UT_SC_CmdTableSizeHandler, NULL); } -void *UT_SC_GetAtsTable(uint8 AtsIndex) +void *UT_SC_GetAtsTable(SC_AtsIndex_t AtsIndex) { - return SC_OperData.AtsTblAddr[AtsIndex]; + return SC_OperData.AtsTblAddr[SC_IDX_AS_UINT(AtsIndex)]; } -void *UT_SC_GetRtsTable(uint8 RtsIndex) +void *UT_SC_GetRtsTable(SC_RtsIndex_t RtsIndex) { - return SC_OperData.RtsTblAddr[RtsIndex]; + return SC_OperData.RtsTblAddr[SC_IDX_AS_UINT(RtsIndex)]; } void *UT_SC_GetAppendTable(void) @@ -122,7 +122,7 @@ SC_AtsEntryHeader_t *UT_SC_AppendSingleAtsEntry(void **TailPtr, uint16 CmdNumber UT_SC_AdvanceTailPtr(TailPtr, SC_ATS_HEADER_SIZE, MsgSize); - Entry->CmdNumber = CmdNumber; + Entry->CmdNumber = SC_COMMAND_NUM_C(CmdNumber); return Entry; } @@ -138,7 +138,7 @@ SC_RtsEntryHeader_t *UT_SC_AppendSingleRtsEntry(void **TailPtr, SC_RelTimeTag_t return Entry; } -SC_AtsEntryHeader_t *UT_SC_SetupSingleAtsEntry(uint8 AtsIndex, uint16 CmdNumber, size_t MsgSize) +SC_AtsEntryHeader_t *UT_SC_SetupSingleAtsEntry(SC_AtsIndex_t AtsIndex, uint16 CmdNumber, size_t MsgSize) { void *TailPtr; @@ -147,7 +147,7 @@ SC_AtsEntryHeader_t *UT_SC_SetupSingleAtsEntry(uint8 AtsIndex, uint16 CmdNumber, return UT_SC_AppendSingleAtsEntry(&TailPtr, CmdNumber, MsgSize); } -SC_RtsEntryHeader_t *UT_SC_SetupSingleRtsEntry(uint8 RtsIndex, CFE_SB_MsgId_t MsgId, SC_RelTimeTag_t TimeTag, +SC_RtsEntryHeader_t *UT_SC_SetupSingleRtsEntry(SC_RtsIndex_t RtsIndex, CFE_SB_MsgId_t MsgId, SC_RelTimeTag_t TimeTag, size_t MsgSize) { void *TailPtr; @@ -215,7 +215,7 @@ void *UT_SC_SetupFullTable(void **TailPtr, size_t HdrSize, size_t MsgSize, size_ UT_SC_AdvanceTailPtr(TailPtr, HdrSize, MsgSize); EntryInit_Callback(CurrPtr, Idx, MsgSize); - // EntryInit(CurrPtr, SC_ATS_CMD_INDEX_TO_NUM(Idx), MsgSize); + // EntryInit(CurrPtr, SC_CommandIndexToNum(Idx), MsgSize); } /* Capture the last entry that was complete - @@ -227,10 +227,11 @@ void UT_SC_AtsEntryInit(void *EntryPtr, size_t Idx, size_t MsgSize) { SC_AtsEntryHeader_t *Entry = EntryPtr; - Entry->CmdNumber = SC_ATS_CMD_INDEX_TO_NUM(Idx); + Entry->CmdNumber = SC_CommandIndexToNum(SC_COMMAND_IDX_C(Idx)); } -SC_AtsEntryHeader_t *UT_SC_SetupAtsTable(uint8 AtsIndex, size_t MsgSize, size_t TargetEndingWord, void **TailPtrOut) +SC_AtsEntryHeader_t *UT_SC_SetupAtsTable(SC_AtsIndex_t AtsIndex, size_t MsgSize, size_t TargetEndingWord, + void **TailPtrOut) { void * TailPtr; SC_AtsEntryHeader_t *FinalEntry; @@ -258,8 +259,8 @@ void UT_SC_RtsEntryInit(void *EntryPtr, size_t Idx, size_t MsgSize) Entry->TimeTag = 1; } -SC_RtsEntryHeader_t *UT_SC_SetupRtsTable(uint8 RtsIndex, CFE_SB_MsgId_t MsgId, size_t MsgSize, size_t TargetEndingWord, - void **TailPtrOut) +SC_RtsEntryHeader_t *UT_SC_SetupRtsTable(SC_RtsIndex_t RtsIndex, CFE_SB_MsgId_t MsgId, size_t MsgSize, + size_t TargetEndingWord, void **TailPtrOut) { void * TailPtr; SC_RtsEntryHeader_t *FinalEntry; @@ -283,7 +284,7 @@ SC_RtsEntryHeader_t *UT_SC_SetupRtsTable(uint8 RtsIndex, CFE_SB_MsgId_t MsgId, s void SC_LoadAts_Test_Nominal(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, sizeof(SC_NoopCmd_t)); @@ -299,7 +300,7 @@ void SC_LoadAts_Test_Nominal(void) void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* Set up -- Modify the final entry so it would go off the end of the table */ UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32 + 1, NULL); @@ -316,7 +317,7 @@ void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) void SC_LoadAts_Test_CmdLengthInvalid(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE + 1); @@ -332,7 +333,7 @@ void SC_LoadAts_Test_CmdLengthInvalid(void) void SC_LoadAts_Test_CmdLengthZero(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MIN_SIZE - 1); @@ -348,7 +349,7 @@ void SC_LoadAts_Test_CmdLengthZero(void) void SC_LoadAts_Test_CmdNumberInvalid(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS * 2, UT_SC_NOMINAL_CMD_SIZE); @@ -367,7 +368,7 @@ void SC_LoadAts_Test_AtsBufferTooSmall(void) SC_AtsEntryHeader_t *LastValidEntry; void * TailPtr; SC_AtsEntryHeader_t *InvalidEntry; - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* Set up -- Modify the final entry so it would go off the end of the table */ LastValidEntry = @@ -379,7 +380,7 @@ void SC_LoadAts_Test_AtsBufferTooSmall(void) * This is an ATS header at the very end of the ATS buffer, where there is no room * for a cmd message to follow it, but it has a nonzero command number */ - InvalidEntry->CmdNumber = LastValidEntry->CmdNumber + 1; + InvalidEntry->CmdNumber = SC_COMMAND_NUM_C(SC_IDNUM_AS_UINT(LastValidEntry->CmdNumber) + 1); /* Execute the function being tested */ SC_LoadAts(AtsIndex); @@ -394,7 +395,7 @@ void SC_LoadAts_Test_AtsBufferTooSmall(void) void SC_LoadAts_Test_AtsEmpty(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* Execute the function being tested */ SC_LoadAts(AtsIndex); @@ -410,7 +411,7 @@ void SC_LoadAts_Test_AtsEmpty(void) void SC_LoadAts_Test_LoadExactlyBufferLength(void) { SC_AtsEntryHeader_t *Entry; - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* Set up -- Modify the final entry so it exactly takes up the remainder of the buffer */ Entry = UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32, NULL); @@ -428,8 +429,8 @@ void SC_LoadAts_Test_LoadExactlyBufferLength(void) void SC_LoadAts_Test_CmdNotEmpty(void) { - void *TailPtr; - uint8 AtsIndex = 0; + void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); /* Set up a buffer that has a duplicate command number entry */ TailPtr = UT_SC_GetAtsTable(AtsIndex); @@ -450,7 +451,7 @@ void SC_LoadAts_Test_CmdNotEmpty(void) void SC_LoadAts_Test_InvalidIndex(void) { - uint8 AtsIndex = SC_NUMBER_OF_ATS; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); /* Pass in invalid index */ SC_LoadAts(AtsIndex); @@ -463,7 +464,7 @@ void SC_LoadAts_Test_InvalidIndex(void) void SC_BuildTimeIndexTable_Test_InvalidIndex(void) { - uint8 AtsIndex = SC_NUMBER_OF_ATS; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); /* Execute the function being tested */ SC_BuildTimeIndexTable(AtsIndex); @@ -476,9 +477,9 @@ void SC_BuildTimeIndexTable_Test_InvalidIndex(void) void SC_Insert_Test(void) { - uint8 AtsIndex = 0; - uint8 ListLength = 1; - uint8 NewCmdIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; @@ -494,9 +495,9 @@ void SC_Insert_Test(void) void SC_Insert_Test_MiddleOfList(void) { - uint8 AtsIndex = 0; - uint8 ListLength = 1; - uint8 NewCmdIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); /* Set to cause SC_CompareAbsTime to return false, in order to reach block starting with "new cmd will execute at same time or after this list entry" */ @@ -516,9 +517,9 @@ void SC_Insert_Test_MiddleOfList(void) void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) { - uint8 AtsIndex = 0; - uint8 ListLength = 1; - uint8 NewCmdIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); /* Set to cause SC_CompareAbsTime to return false, in order to reach block starting with "new cmd will execute at same time or after this list entry" */ @@ -538,9 +539,9 @@ void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) void SC_Insert_Test_InvalidIndex(void) { - uint8 AtsIndex = SC_NUMBER_OF_ATS; - uint8 ListLength = 1; - uint8 NewCmdIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); /* Execute the function being tested */ SC_Insert(AtsIndex, NewCmdIndex, ListLength); @@ -553,7 +554,7 @@ void SC_Insert_Test_InvalidIndex(void) void SC_InitAtsTables_Test_InvalidIndex(void) { - uint8 AtsIndex = SC_NUMBER_OF_ATS; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); /* Execute the function being tested */ SC_InitAtsTables(AtsIndex); @@ -566,10 +567,13 @@ void SC_InitAtsTables_Test_InvalidIndex(void) void SC_ValidateAts_Test(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_ValidateAts(SC_OperData.AtsTblAddr[AtsIndex]), SC_ERROR); + UtAssert_INT32_EQ(SC_ValidateAts(TablePtr), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -579,10 +583,13 @@ void SC_ValidateAts_Test(void) void SC_ValidateAppend_Test(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_ValidateAppend(SC_OperData.AtsTblAddr[AtsIndex]), SC_ERROR); + UtAssert_INT32_EQ(SC_ValidateAppend(TablePtr), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -592,12 +599,15 @@ void SC_ValidateAppend_Test(void) void SC_ValidateRts_Test(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 1, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_ValidateRts(SC_OperData.RtsTblAddr[RtsIndex]), SC_ERROR); + UtAssert_INT32_EQ(SC_ValidateRts(TablePtr), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -607,12 +617,15 @@ void SC_ValidateRts_Test(void) void SC_ValidateRts_Test_ParseRts(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 0, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_ValidateRts(SC_OperData.RtsTblAddr[RtsIndex]), CFE_SUCCESS); + UtAssert_INT32_EQ(SC_ValidateRts(TablePtr), CFE_SUCCESS); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -620,7 +633,7 @@ void SC_ValidateRts_Test_ParseRts(void) void SC_LoadRts_Test_Nominal(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); UT_SC_SetMsgId(CFE_SB_INVALID_MSG_ID); UT_SC_GetRtsTable(RtsIndex); @@ -634,7 +647,7 @@ void SC_LoadRts_Test_Nominal(void) void SC_LoadRts_Test_InvalidIndex(void) { - uint8 RtsIndex = SC_NUMBER_OF_RTS; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS); /* Execute the function being tested */ SC_LoadRts(RtsIndex); @@ -647,12 +660,15 @@ void SC_LoadRts_Test_InvalidIndex(void) void SC_ParseRts_Test_EndOfFile(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 0, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_TRUE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -660,12 +676,15 @@ void SC_ParseRts_Test_EndOfFile(void) void SC_ParseRts_Test_InvalidMsgId(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, CFE_SB_INVALID_MSG_ID, 1, SC_PACKET_MIN_SIZE); /* Execute the function being tested */ - UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_FALSE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -675,12 +694,15 @@ void SC_ParseRts_Test_InvalidMsgId(void) void SC_ParseRts_Test_LengthErrorTooShort(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, SC_UT_MID_1, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ - UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_FALSE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -690,12 +712,15 @@ void SC_ParseRts_Test_LengthErrorTooShort(void) void SC_ParseRts_Test_LengthErrorTooLong(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupSingleRtsEntry(RtsIndex, SC_UT_MID_1, 1, SC_PACKET_MAX_SIZE + 1); /* Execute the function being tested */ - UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_FALSE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -705,13 +730,16 @@ void SC_ParseRts_Test_LengthErrorTooLong(void) void SC_ParseRts_Test_CmdRunsOffEndOfBuffer(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); /* Set up -- Modify the final entry so it would go off the end of the table */ UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 + 1, NULL); /* Execute the function being tested */ - UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_FALSE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -721,12 +749,15 @@ void SC_ParseRts_Test_CmdRunsOffEndOfBuffer(void) void SC_ParseRts_Test_CmdLengthEqualsBufferLength(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32, NULL); /* Execute the function being tested */ - UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_TRUE(SC_ParseRts(TablePtr)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -734,20 +765,26 @@ void SC_ParseRts_Test_CmdLengthEqualsBufferLength(void) void SC_ParseRts_Test_CmdDoesNotFitBufferEmpty(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 - 1, NULL); /* Execute the function being tested */ - UtAssert_BOOL_TRUE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_TRUE(SC_ParseRts(TablePtr)); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ParseRts_Test_CmdDoesNotFitBufferNotEmpty(void) { - uint8 RtsIndex = 0; - void *TailPtr; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + void * TailPtr; + void * TablePtr; + + TablePtr = UT_SC_GetRtsTable(RtsIndex); UT_SC_SetupRtsTable(RtsIndex, SC_UT_MID_1, UT_SC_NOMINAL_CMD_SIZE, SC_RTS_BUFF_SIZE32 - 1, &TailPtr); @@ -755,7 +792,7 @@ void SC_ParseRts_Test_CmdDoesNotFitBufferNotEmpty(void) *((uint32 *)TailPtr) = 0xFFFFFFFF; /* Execute the function being tested */ - UtAssert_BOOL_FALSE(SC_ParseRts(SC_OperData.RtsTblAddr[RtsIndex])); + UtAssert_BOOL_FALSE(SC_ParseRts(TablePtr)); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LEN_TOO_LONG_ERR_EID); @@ -913,8 +950,8 @@ void SC_UpdateAppend_Test_CmdNumberTooHigh(void) void SC_ProcessAppend_Test(void) { - uint8 AtsIndex = 0; - void *TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -924,8 +961,8 @@ void SC_ProcessAppend_Test(void) SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); /* restart ATS */ UT_SetDeferredRetcode(UT_KEY(SC_BeginAts), 1, true); @@ -945,8 +982,8 @@ void SC_ProcessAppend_Test(void) void SC_ProcessAppend_Test_CmdLoaded(void) { - uint8 AtsIndex = 0; - void *TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -958,7 +995,7 @@ void SC_ProcessAppend_Test_CmdLoaded(void) SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); /* Execute the function being tested */ SC_ProcessAppend(AtsIndex); @@ -975,8 +1012,8 @@ void SC_ProcessAppend_Test_CmdLoaded(void) void SC_ProcessAppend_Test_NotExecuting(void) { - uint8 AtsIndex = 0; - void *TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -986,8 +1023,8 @@ void SC_ProcessAppend_Test_NotExecuting(void) SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); /* Execute the function being tested */ SC_ProcessAppend(AtsIndex); @@ -1002,10 +1039,10 @@ void SC_ProcessAppend_Test_NotExecuting(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_ProcessAppend_Test_AtsNumber(void) +void SC_ProcessAppend_Test_AtsNum(void) { - uint8 AtsIndex = 0; - void *TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -1015,8 +1052,8 @@ void SC_ProcessAppend_Test_AtsNumber(void) SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 0; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAppend(AtsIndex)); @@ -1033,7 +1070,7 @@ void SC_ProcessAppend_Test_AtsNumber(void) void SC_ProcessAppend_Test_InvalidIndex(void) { - uint8 AtsIndex = SC_NUMBER_OF_ATS; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(SC_NUMBER_OF_ATS); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAppend(AtsIndex)); @@ -1047,12 +1084,15 @@ void SC_ProcessAppend_Test_InvalidIndex(void) void SC_VerifyAtsTable_Test_Nominal(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), CFE_SUCCESS); + UtAssert_INT32_EQ(SC_VerifyAtsTable(TablePtr, SC_ATS_BUFF_SIZE), CFE_SUCCESS); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1072,12 +1112,15 @@ void SC_VerifyAtsTable_Test_Nominal(void) void SC_VerifyAtsTable_Test_InvalidEntry(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS + 10, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsTable(TablePtr, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1087,10 +1130,13 @@ void SC_VerifyAtsTable_Test_InvalidEntry(void) void SC_VerifyAtsTable_Test_EmptyTable(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsTable((SC_OperData.AtsTblAddr[AtsIndex]), SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsTable(TablePtr, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1100,14 +1146,17 @@ void SC_VerifyAtsTable_Test_EmptyTable(void) void SC_VerifyAtsEntry_Test_Nominal(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); SC_OperData.AtsDupTestArray[0] = SC_DUP_TEST_UNUSED; /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry(SC_OperData.AtsTblAddr[AtsIndex], 0, SC_ATS_BUFF_SIZE), + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, SC_ATS_BUFF_SIZE), SC_ATS_HDR_NOPKT_WORDS + ((SC_PACKET_MAX_SIZE + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD)); /* Verify results */ @@ -1117,12 +1166,15 @@ void SC_VerifyAtsEntry_Test_Nominal(void) void SC_VerifyAtsEntry_Test_EndOfBuffer(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 10000, SC_ATS_BUFF_SIZE), CFE_SUCCESS); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 10000, SC_ATS_BUFF_SIZE), CFE_SUCCESS); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -1130,12 +1182,15 @@ void SC_VerifyAtsEntry_Test_EndOfBuffer(void) void SC_VerifyAtsEntry_Test_InvalidCmdNumber(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS + 20, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1145,12 +1200,15 @@ void SC_VerifyAtsEntry_Test_InvalidCmdNumber(void) void SC_VerifyAtsEntry_Test_BufferFull(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, 2), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, 2), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1160,12 +1218,15 @@ void SC_VerifyAtsEntry_Test_BufferFull(void) void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooLow(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1175,12 +1236,15 @@ void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooLow(void) void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooHigh(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE * 2); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1190,12 +1254,15 @@ void SC_VerifyAtsEntry_Test_InvalidCmdLengthTooHigh(void) void SC_VerifyAtsEntry_Test_BufferOverflow(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), 0, 20), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, 20), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1205,7 +1272,10 @@ void SC_VerifyAtsEntry_Test_BufferOverflow(void) void SC_VerifyAtsEntry_Test_DuplicateCmdNumber(void) { - uint8 AtsIndex = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TablePtr; + + TablePtr = UT_SC_GetAtsTable(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE); @@ -1213,7 +1283,7 @@ void SC_VerifyAtsEntry_Test_DuplicateCmdNumber(void) SC_OperData.AtsDupTestArray[0] = 99; /* Execute the function being tested */ - UtAssert_INT32_EQ(SC_VerifyAtsEntry((SC_OperData.AtsTblAddr[AtsIndex]), AtsIndex, SC_ATS_BUFF_SIZE), SC_ERROR); + UtAssert_INT32_EQ(SC_VerifyAtsEntry(TablePtr, 0, SC_ATS_BUFF_SIZE), SC_ERROR); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -1288,8 +1358,7 @@ void UtTest_Setup(void) "SC_ProcessAppend_Test_CmdLoaded"); UtTest_Add(SC_ProcessAppend_Test_NotExecuting, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_NotExecuting"); - UtTest_Add(SC_ProcessAppend_Test_AtsNumber, UT_SC_Loads_Test_Setup, SC_Test_TearDown, - "SC_ProcessAppend_Test_AtsNumber"); + UtTest_Add(SC_ProcessAppend_Test_AtsNum, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_AtsNum"); UtTest_Add(SC_ProcessAppend_Test_InvalidIndex, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_InvalidIndex"); UtTest_Add(SC_VerifyAtsTable_Test_Nominal, UT_SC_Loads_Test_Setup, SC_Test_TearDown, diff --git a/unit-test/sc_rtsrq_tests.c b/unit-test/sc_rtsrq_tests.c index cf101ca..3050fbf 100644 --- a/unit-test/sc_rtsrq_tests.c +++ b/unit-test/sc_rtsrq_tests.c @@ -46,13 +46,13 @@ void SC_StartRtsCmd_Test_Nominal(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; @@ -87,12 +87,12 @@ void SC_StartRtsCmd_Test_Nominal(void) void SC_StartRtsCmd_Test_StartRtsNoEvents(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex; + SC_RtsIndex_t RtsIndex; size_t MsgSize; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = SC_NUMBER_OF_RTS; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS); - RtsIndex = UT_CmdBuf.StartRtsCmd.Payload.RtsId - 1; + RtsIndex = SC_RtsNumToIndex(UT_CmdBuf.StartRtsCmd.Payload.RtsNum); Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; @@ -125,7 +125,7 @@ void SC_StartRtsCmd_Test_StartRtsNoEvents(void) UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); /* Handle if SC_LAST_RTS_WITH_EVENTS is the same as SC_NUM_OF_RTS */ - if (UT_CmdBuf.DisableRtsCmd.Payload.RtsId > SC_LAST_RTS_WITH_EVENTS) + if (UT_CmdBuf.DisableRtsCmd.Payload.RtsNum > SC_LAST_RTS_WITH_EVENTS) { UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_STARTRTS_CMD_DBG_EID); } @@ -140,13 +140,13 @@ void SC_StartRtsCmd_Test_StartRtsNoEvents(void) void SC_StartRtsCmd_Test_InvalidCommandLength1(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; @@ -168,13 +168,13 @@ void SC_StartRtsCmd_Test_InvalidCommandLength1(void) void SC_StartRtsCmd_Test_InvalidCommandLength2(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; @@ -196,12 +196,12 @@ void SC_StartRtsCmd_Test_InvalidCommandLength2(void) void SC_StartRtsCmd_Test_RtsNotLoadedOrInUse(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_IDLE; @@ -217,12 +217,12 @@ void SC_StartRtsCmd_Test_RtsNotLoadedOrInUse(void) void SC_StartRtsCmd_Test_RtsDisabled(void) { SC_RtsEntryHeader_t *Entry; - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; Entry->TimeTag = 0; - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; @@ -237,7 +237,7 @@ void SC_StartRtsCmd_Test_RtsDisabled(void) void SC_StartRtsCmd_Test_InvalidRtsId(void) { - UT_CmdBuf.StartRtsCmd.Payload.RtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); @@ -249,7 +249,7 @@ void SC_StartRtsCmd_Test_InvalidRtsId(void) void SC_StartRtsCmd_Test_InvalidRtsIdZero(void) { - UT_CmdBuf.StartRtsCmd.Payload.RtsId = 0; + UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); @@ -261,13 +261,13 @@ void SC_StartRtsCmd_Test_InvalidRtsIdZero(void) void SC_StartRtsGrpCmd_Test_Nominal(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -292,8 +292,8 @@ void SC_StartRtsGrpCmd_Test_Nominal(void) void SC_StartRtsGrpCmd_Test_StartRtsGroupError(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS * 2; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -307,8 +307,8 @@ void SC_StartRtsGrpCmd_Test_StartRtsGroupError(void) void SC_StartRtsGrpCmd_Test_FirstRtsIndex(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS + 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -322,8 +322,8 @@ void SC_StartRtsGrpCmd_Test_FirstRtsIndex(void) void SC_StartRtsGrpCmd_Test_FirstRtsIndexZero(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 0; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(0); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -337,8 +337,8 @@ void SC_StartRtsGrpCmd_Test_FirstRtsIndexZero(void) void SC_StartRtsGrpCmd_Test_LastRtsIndex(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS + 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -352,8 +352,8 @@ void SC_StartRtsGrpCmd_Test_LastRtsIndex(void) void SC_StartRtsGrpCmd_Test_LastRtsIndexZero(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 0; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -367,8 +367,8 @@ void SC_StartRtsGrpCmd_Test_LastRtsIndexZero(void) void SC_StartRtsGrpCmd_Test_FirstLastRtsIndex(void) { - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 2; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(2); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -382,16 +382,16 @@ void SC_StartRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_StartRtsGrpCmd_Test_DisabledFlag(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = 0; + SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = SC_ENTRY_OFFSET_FIRST; - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -417,15 +417,15 @@ void SC_StartRtsGrpCmd_Test_DisabledFlag(void) void SC_StartRtsGrpCmd_Test_RtsStatus(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = 0; + SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = SC_ENTRY_OFFSET_FIRST; - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); @@ -453,7 +453,7 @@ void SC_StartRtsGrpCmd_Test_RtsStatus(void) void SC_StopRtsCmd_Test_Nominal(void) { - UT_CmdBuf.StopRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.StopRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsCmd(&UT_CmdBuf.StopRtsCmd)); @@ -467,7 +467,7 @@ void SC_StopRtsCmd_Test_Nominal(void) void SC_StopRtsCmd_Test_InvalidRts(void) { - UT_CmdBuf.StopRtsCmd.Payload.RtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.StopRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsCmd(&UT_CmdBuf.StopRtsCmd)); @@ -481,8 +481,8 @@ void SC_StopRtsCmd_Test_InvalidRts(void) void SC_StopRtsGrpCmd_Test_Nominal(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -496,8 +496,8 @@ void SC_StopRtsGrpCmd_Test_Nominal(void) void SC_StopRtsGrpCmd_Test_Error(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS * 2; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -511,12 +511,12 @@ void SC_StopRtsGrpCmd_Test_Error(void) void SC_StopRtsGrpCmd_Test_NotExecuting(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -530,8 +530,8 @@ void SC_StopRtsGrpCmd_Test_NotExecuting(void) void SC_StopRtsGrpCmd_Test_FirstRtsIndex(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS + 1; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -545,8 +545,8 @@ void SC_StopRtsGrpCmd_Test_FirstRtsIndex(void) void SC_StopRtsGrpCmd_Test_FirstRtsIndexZero(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 0; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(0); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -560,8 +560,8 @@ void SC_StopRtsGrpCmd_Test_FirstRtsIndexZero(void) void SC_StopRtsGrpCmd_Test_LastRtsIndex(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS + 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -575,8 +575,8 @@ void SC_StopRtsGrpCmd_Test_LastRtsIndex(void) void SC_StopRtsGrpCmd_Test_LastRtsIndexZero(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 0; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -590,8 +590,8 @@ void SC_StopRtsGrpCmd_Test_LastRtsIndexZero(void) void SC_StopRtsGrpCmd_Test_FirstLastRtsIndex(void) { - UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsId = 2; - UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(2); + UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StopRtsGrpCmd(&UT_CmdBuf.StopRtsGrpCmd)); @@ -605,9 +605,9 @@ void SC_StopRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_DisableRtsCmd_Test_Nominal(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - UT_CmdBuf.DisableRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.DisableRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsCmd(&UT_CmdBuf.DisableRtsCmd)); @@ -623,7 +623,7 @@ void SC_DisableRtsCmd_Test_Nominal(void) void SC_DisableRtsCmd_Test_InvalidRtsID(void) { - UT_CmdBuf.DisableRtsCmd.Payload.RtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.DisableRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsCmd(&UT_CmdBuf.DisableRtsCmd)); @@ -637,10 +637,10 @@ void SC_DisableRtsCmd_Test_InvalidRtsID(void) void SC_DisableRtsGrpCmd_Test_Nominal(void) { - uint8 RtsIndex = 0; /* RtsId - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -656,8 +656,8 @@ void SC_DisableRtsGrpCmd_Test_Nominal(void) void SC_DisableRtsGrpCmd_Test_Error(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS * 2; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -671,8 +671,8 @@ void SC_DisableRtsGrpCmd_Test_Error(void) void SC_DisableRtsGrpCmd_Test_FirstRtsIndex(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS + 1; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -686,8 +686,8 @@ void SC_DisableRtsGrpCmd_Test_FirstRtsIndex(void) void SC_DisableRtsGrpCmd_Test_FirstRtsIndexZero(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 0; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(0); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -701,8 +701,8 @@ void SC_DisableRtsGrpCmd_Test_FirstRtsIndexZero(void) void SC_DisableRtsGrpCmd_Test_LastRtsIndex(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS + 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -716,8 +716,8 @@ void SC_DisableRtsGrpCmd_Test_LastRtsIndex(void) void SC_DisableRtsGrpCmd_Test_LastRtsIndexZero(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 0; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -731,8 +731,8 @@ void SC_DisableRtsGrpCmd_Test_LastRtsIndexZero(void) void SC_DisableRtsGrpCmd_Test_FirstLastRtsIndex(void) { - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 2; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(2); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -746,12 +746,12 @@ void SC_DisableRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_DisableRtsGrpCmd_Test_DisabledFlag(void) { - uint8 RtsIndex = 0; /* RtsId - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; - UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); + UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); @@ -767,9 +767,9 @@ void SC_DisableRtsGrpCmd_Test_DisabledFlag(void) void SC_EnableRtsCmd_Test_Nominal(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - UT_CmdBuf.EnableRtsCmd.Payload.RtsId = 1; + UT_CmdBuf.EnableRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsCmd(&UT_CmdBuf.EnableRtsCmd)); @@ -785,7 +785,7 @@ void SC_EnableRtsCmd_Test_Nominal(void) void SC_EnableRtsCmd_Test_InvalidRtsID(void) { - UT_CmdBuf.EnableRtsCmd.Payload.RtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.EnableRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsCmd(&UT_CmdBuf.EnableRtsCmd)); @@ -799,7 +799,7 @@ void SC_EnableRtsCmd_Test_InvalidRtsID(void) void SC_EnableRtsCmd_Test_InvalidRtsIDZero(void) { - UT_CmdBuf.EnableRtsCmd.Payload.RtsId = 0; + UT_CmdBuf.EnableRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsCmd(&UT_CmdBuf.EnableRtsCmd)); @@ -813,10 +813,10 @@ void SC_EnableRtsCmd_Test_InvalidRtsIDZero(void) void SC_EnableRtsGrpCmd_Test_Nominal(void) { - uint8 RtsIndex = 0; /* RtsId - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -832,8 +832,8 @@ void SC_EnableRtsGrpCmd_Test_Nominal(void) void SC_EnableRtsGrpCmd_Test_Error(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS * 2; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS * 2; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -847,8 +847,8 @@ void SC_EnableRtsGrpCmd_Test_Error(void) void SC_EnableRtsGrpCmd_Test_FirstRtsIndex(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = SC_NUMBER_OF_RTS + 1; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -862,8 +862,8 @@ void SC_EnableRtsGrpCmd_Test_FirstRtsIndex(void) void SC_EnableRtsGrpCmd_Test_FirstRtsIndexZero(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 0; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(0); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -877,8 +877,8 @@ void SC_EnableRtsGrpCmd_Test_FirstRtsIndexZero(void) void SC_EnableRtsGrpCmd_Test_LastRtsIndex(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = SC_NUMBER_OF_RTS + 1; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -892,8 +892,8 @@ void SC_EnableRtsGrpCmd_Test_LastRtsIndex(void) void SC_EnableRtsGrpCmd_Test_LastRtsIndexZero(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 0; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -907,8 +907,8 @@ void SC_EnableRtsGrpCmd_Test_LastRtsIndexZero(void) void SC_EnableRtsGrpCmd_Test_FirstLastRtsIndex(void) { - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 2; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 1; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(2); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); @@ -922,19 +922,19 @@ void SC_EnableRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_EnableRtsGrpCmd_Test_DisabledFlag(void) { - uint8 RtsIndex = 0; /* RtsId - 1 */ + SC_RtsIndex_t RtsIndex0 = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex1 = SC_RTS_IDX_C(1); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[1].DisabledFlag = true; - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsId = 1; - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsId = 2; + SC_OperData.RtsInfoTblAddr[RtsIndex0].DisabledFlag = false; + SC_OperData.RtsInfoTblAddr[RtsIndex1].DisabledFlag = true; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex0); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false"); + UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[RtsIndex0].DisabledFlag); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ENARTSGRP_CMD_INF_EID); @@ -943,7 +943,7 @@ void SC_EnableRtsGrpCmd_Test_DisabledFlag(void) void SC_KillRts_Test(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 1; @@ -963,7 +963,7 @@ void SC_KillRts_Test(void) void SC_KillRts_Test_NoActiveRts(void) { - uint8 RtsIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 0; @@ -983,7 +983,7 @@ void SC_KillRts_Test_NoActiveRts(void) void SC_KillRts_Test_InvalidIndex(void) { - uint8 RtsIndex = SC_NUMBER_OF_RTS; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_KillRts(RtsIndex)); @@ -995,10 +995,10 @@ void SC_KillRts_Test_InvalidIndex(void) void SC_AutoStartRts_Test_Nominal(void) { - uint8 RtsId = 1; + SC_RtsNum_t RtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ - UtAssert_VOIDCALL(SC_AutoStartRts(RtsId)); + UtAssert_VOIDCALL(SC_AutoStartRts(RtsNum)); /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -1006,10 +1006,10 @@ void SC_AutoStartRts_Test_Nominal(void) void SC_AutoStartRts_Test_InvalidId(void) { - uint8 RtsId = SC_NUMBER_OF_RTS + 1; + SC_RtsNum_t RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); /* Execute the function being tested */ - UtAssert_VOIDCALL(SC_AutoStartRts(RtsId)); + UtAssert_VOIDCALL(SC_AutoStartRts(RtsNum)); /* Verify results */ UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_AUTOSTART_RTS_INV_ID_ERR_EID); @@ -1018,10 +1018,10 @@ void SC_AutoStartRts_Test_InvalidId(void) void SC_AutoStartRts_Test_InvalidIdZero(void) { - uint8 RtsId = 0; + SC_RtsNum_t RtsNum = SC_RTS_NUM_C(0); /* Execute the function being tested */ - UtAssert_VOIDCALL(SC_AutoStartRts(RtsId)); + UtAssert_VOIDCALL(SC_AutoStartRts(RtsNum)); /* Verify results */ UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_AUTOSTART_RTS_INV_ID_ERR_EID); diff --git a/unit-test/sc_state_tests.c b/unit-test/sc_state_tests.c index ec7c8de..b32ebd6 100644 --- a/unit-test/sc_state_tests.c +++ b/unit-test/sc_state_tests.c @@ -56,34 +56,35 @@ int32 SC_STATE_TEST_CFE_SB_GetTotalMsgLengthHook(void *UserObj, int32 StubRetcod void SC_GetNextRtsTime_Test_Nominal(void) { - SC_OperData.RtsInfoTblAddr[0].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[0].NextCommandTime = SC_MAX_TIME; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = SC_MAX_TIME; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsTime()); /* Verify results */ - UtAssert_True(SC_OperData.RtsCtrlBlckAddr->RtsNumber == 1, "SC_OperData.RtsCtrlBlckAddr->RtsNumber == 1"); + SC_Assert_ID_VALUE(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, 1); UtAssert_True(SC_AppData.NextCmdTime[1] == SC_MAX_TIME, "SC_AppData.NextCmdTime[1] == SC_MAX_TIME"); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_GetNextRtsTime_Test_InvalidRtsNumber(void) +void SC_GetNextRtsTime_Test_InvalidRtsNum(void) { uint8 i; for (i = 0; i < SC_NUMBER_OF_RTS; i++) { - SC_OperData.RtsInfoTblAddr[i].RtsStatus = -1; + SC_OperData.RtsInfoTblAddr[i].RtsStatus = (SC_Status_Enum_t)(-1); } /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsTime()); /* Verify results */ - UtAssert_True(SC_OperData.RtsCtrlBlckAddr->RtsNumber == SC_INVALID_RTS_NUMBER, - "SC_OperData.RtsCtrlBlckAddr->RtsNumber == SC_INVALID_RTS_NUMBER"); + SC_Assert_ID_EQ(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, SC_RTS_NUM_NULL); UtAssert_True(SC_AppData.NextCmdTime[SC_Process_RTP] == SC_MAX_TIME, "SC_AppData.NextCmdTime[SC_Process_RTP] == SC_MAX_TIME"); @@ -102,7 +103,7 @@ void SC_GetNextRtsTime_Test_RtsPriority(void) UtAssert_VOIDCALL(SC_GetNextRtsTime()); /* Verify results */ - UtAssert_True(SC_OperData.RtsCtrlBlckAddr->RtsNumber == 2, "SC_OperData.RtsCtrlBlckAddr->RtsNumber == 2 "); + SC_Assert_ID_VALUE(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, 2); UtAssert_True(SC_AppData.NextCmdTime[1] == SC_MAX_TIME - 1, "SC_AppData.NextCmdTime[1] == SC_MAX_TIME - 1"); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -123,10 +124,10 @@ void SC_UpdateNextTime_Test_Atp(void) void SC_UpdateNextTime_Test_Atp2(void) { - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS + 1; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.NextCmdTime[SC_Process_ATP] = 10; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.NextCmdTime[SC_Process_ATP] = 10; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_UpdateNextTime()); @@ -139,12 +140,14 @@ void SC_UpdateNextTime_Test_Atp2(void) void SC_UpdateNextTime_Test_Rtp(void) { - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 10; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.NextCmdTime[SC_Process_ATP] = 10; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_OperData.RtsInfoTblAddr[0].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[0].NextCommandTime = 1; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(10); + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.NextCmdTime[SC_Process_ATP] = 10; + + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_UpdateNextTime()); @@ -157,9 +160,11 @@ void SC_UpdateNextTime_Test_Rtp(void) void SC_UpdateNextTime_Test_RtpAtpPriority(void) { - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 0; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.NextCmdTime[SC_Process_ATP] = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].RtsStatus = SC_Status_EXECUTING; SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].NextCommandTime = 1; @@ -173,14 +178,16 @@ void SC_UpdateNextTime_Test_RtpAtpPriority(void) void SC_GetNextRtsCommand_Test_GetNextCommand(void) { - size_t MsgSize; + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(1); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -203,7 +210,7 @@ void SC_GetNextRtsCommand_Test_GetNextCommand(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_GetNextRtsCommand_Test_RtsNumberZero(void) +void SC_GetNextRtsCommand_Test_RtsNumZero(void) { /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); @@ -212,16 +219,18 @@ void SC_GetNextRtsCommand_Test_RtsNumberZero(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_GetNextRtsCommand_Test_RtsNumberMax(void) +void SC_GetNextRtsCommand_Test_RtsNumMax(void) { - size_t MsgSize; + size_t MsgSize; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -239,15 +248,16 @@ void SC_GetNextRtsCommand_Test_RtsNumberMax(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } -void SC_GetNextRtsCommand_Test_RtsNumberOverMax(void) +void SC_GetNextRtsCommand_Test_RtsNumOverMax(void) { - size_t MsgSize; + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS + 1; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -267,14 +277,16 @@ void SC_GetNextRtsCommand_Test_RtsNumberOverMax(void) void SC_GetNextRtsCommand_Test_RtsNotExecuting(void) { - size_t MsgSize; + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_NUMBER_OF_RTS; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_IDLE; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_IDLE; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -297,12 +309,14 @@ void SC_GetNextRtsCommand_Test_RtsLengthError(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; @@ -317,7 +331,7 @@ void SC_GetNextRtsCommand_Test_RtsLengthError(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE32 - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); @@ -328,8 +342,7 @@ void SC_GetNextRtsCommand_Test_RtsLengthError(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrSeq == SC_OperData.RtsCtrlBlckAddr->RtsNumber, - "SC_OperData.HkPacket.Payload.LastRtsErrSeq == SC_OperData.RtsCtrlBlckAddr->RtsNumber"); + SC_Assert_ID_EQ(SC_OperData.HkPacket.Payload.LastRtsErrSeq, SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + @@ -346,12 +359,14 @@ void SC_GetNextRtsCommand_Test_CommandLengthError(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; @@ -366,7 +381,7 @@ void SC_GetNextRtsCommand_Test_CommandLengthError(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE32 - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); @@ -377,8 +392,7 @@ void SC_GetNextRtsCommand_Test_CommandLengthError(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrSeq == SC_OperData.RtsCtrlBlckAddr->RtsNumber, - "SC_OperData.HkPacket.Payload.LastRtsErrSeq == SC_OperData.RtsCtrlBlckAddr->RtsNumber"); + SC_Assert_ID_EQ(SC_OperData.HkPacket.Payload.LastRtsErrSeq, SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + @@ -395,12 +409,14 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLength(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS - 1); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_LAST_RTS_WITH_EVENTS; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS - 1][0]; @@ -415,7 +431,7 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLength(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - @@ -434,12 +450,14 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLengthLastRts(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_LAST_RTS_WITH_EVENTS + 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS][0]; @@ -454,7 +472,7 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLengthLastRts(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - @@ -471,12 +489,14 @@ void SC_GetNextRtsCommand_Test_EndOfBuffer(void) { SC_RtsEntryHeader_t *Entry; size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; @@ -489,7 +509,7 @@ void SC_GetNextRtsCommand_Test_EndOfBuffer(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - @@ -507,12 +527,14 @@ void SC_GetNextRtsCommand_Test_EndOfBufferLastRts(void) { SC_RtsEntryHeader_t *Entry; size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->RtsNumber = SC_LAST_RTS_WITH_EVENTS + 1; - SC_OperData.RtsInfoTblAddr[SC_OperData.RtsCtrlBlckAddr->RtsNumber - 1].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS][0]; @@ -525,7 +547,7 @@ void SC_GetNextRtsCommand_Test_EndOfBufferLastRts(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - @@ -573,18 +595,19 @@ void SC_GetNextAtsCommand_Test_Idle(void) void SC_GetNextAtsCommand_Test_GetNextCommand(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_AppData.AtsTimeIndexBuffer[0][0] = 1; - SC_AppData.AtsTimeIndexBuffer[0][1] = 2; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_AppData.AtsTimeIndexBuffer[0][0] = 1; + SC_AppData.AtsTimeIndexBuffer[0][1] = 2; SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; SC_AppData.AtsCmdIndexBuffer[0][0] = 0; @@ -595,7 +618,7 @@ void SC_GetNextAtsCommand_Test_GetNextCommand(void) UtAssert_VOIDCALL(SC_GetNextAtsCommand()); /* Verify results */ - UtAssert_INT32_EQ(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); + SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); UtAssert_INT32_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, SC_AppData.AtsTimeIndexBuffer[0][1]); UtAssert_INT32_EQ(SC_AppData.NextCmdTime[SC_Process_ATP], 0); @@ -605,22 +628,21 @@ void SC_GetNextAtsCommand_Test_GetNextCommand(void) void SC_GetNextAtsCommand_Test_ExecutionACompleted(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 2; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 0; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(0); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; - - SC_OperData.AtsInfoTblAddr[SC_Process_ATP].NumberOfCommands = 0; + SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; + SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] = 0; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextAtsCommand()); @@ -633,22 +655,21 @@ void SC_GetNextAtsCommand_Test_ExecutionACompleted(void) void SC_GetNextAtsCommand_Test_ExecutionBCompleted(void) { SC_AtsEntryHeader_t *Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = 1; + Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; SC_AppData.CurrentTime = 1; SC_AppData.NextProcNumber = SC_Process_ATP; SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = 0; - - SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[1][0] = 0; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(0); - SC_OperData.AtsInfoTblAddr[SC_Process_ATP].NumberOfCommands = 0; + SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; + SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] = 0; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextAtsCommand()); @@ -661,8 +682,8 @@ void SC_GetNextAtsCommand_Test_ExecutionBCompleted(void) void UtTest_Setup(void) { UtTest_Add(SC_GetNextRtsTime_Test_Nominal, SC_Test_Setup, SC_Test_TearDown, "SC_GetNextRtsTime_Test_Nominal"); - UtTest_Add(SC_GetNextRtsTime_Test_InvalidRtsNumber, SC_Test_Setup, SC_Test_TearDown, - "SC_GetNextRtsTime_Test_InvalidRtsNumber"); + UtTest_Add(SC_GetNextRtsTime_Test_InvalidRtsNum, SC_Test_Setup, SC_Test_TearDown, + "SC_GetNextRtsTime_Test_InvalidRtsNum"); UtTest_Add(SC_GetNextRtsTime_Test_RtsPriority, SC_Test_Setup, SC_Test_TearDown, "SC_GetNextRtsTime_Test_RtsPriority"); UtTest_Add(SC_UpdateNextTime_Test_Atp, SC_Test_Setup, SC_Test_TearDown, "SC_UpdateNextTime_Test_Atp"); @@ -672,12 +693,12 @@ void UtTest_Setup(void) "SC_UpdateNextTime_Test_RtpAtpPriority"); UtTest_Add(SC_GetNextRtsCommand_Test_GetNextCommand, SC_Test_Setup, SC_Test_TearDown, "SC_GetNextRtsCommand_Test_GetNextCommand"); - UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumberZero, SC_Test_Setup, SC_Test_TearDown, - "SC_GetNextRtsCommand_Test_RtsNumberZero"); - UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumberMax, SC_Test_Setup, SC_Test_TearDown, - "SC_GetNextRtsCommand_Test_RtsNumberMax"); - UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumberOverMax, SC_Test_Setup, SC_Test_TearDown, - "SC_GetNextRtsCommand_Test_RtsNumberOverMax"); + UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumZero, SC_Test_Setup, SC_Test_TearDown, + "SC_GetNextRtsCommand_Test_RtsNumZero"); + UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumMax, SC_Test_Setup, SC_Test_TearDown, + "SC_GetNextRtsCommand_Test_RtsNumMax"); + UtTest_Add(SC_GetNextRtsCommand_Test_RtsNumOverMax, SC_Test_Setup, SC_Test_TearDown, + "SC_GetNextRtsCommand_Test_RtsNumOverMax"); UtTest_Add(SC_GetNextRtsCommand_Test_RtsNotExecuting, SC_Test_Setup, SC_Test_TearDown, "SC_GetNextRtsCommand_Test_RtsNotExecuting"); UtTest_Add(SC_GetNextRtsCommand_Test_RtsLengthError, SC_Test_Setup, SC_Test_TearDown, diff --git a/unit-test/sc_utils_tests.c b/unit-test/sc_utils_tests.c index ea45850..bc3d296 100644 --- a/unit-test/sc_utils_tests.c +++ b/unit-test/sc_utils_tests.c @@ -107,13 +107,13 @@ void SC_CompareAbsTime_Test_False(void) void SC_ToggleAtsIndex_Test(void) { - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - UtAssert_UINT16_EQ(SC_ToggleAtsIndex(), 1); + UtAssert_UINT32_EQ(SC_IDX_AS_UINT(SC_ToggleAtsIndex()), 1); - SC_OperData.AtsCtrlBlckAddr->AtsNumber = 2; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); - UtAssert_UINT16_EQ(SC_ToggleAtsIndex(), 0); + UtAssert_UINT32_EQ(SC_IDX_AS_UINT(SC_ToggleAtsIndex()), 0); } void UtTest_Setup(void) diff --git a/unit-test/stubs/sc_atsrq_stubs.c b/unit-test/stubs/sc_atsrq_stubs.c index 28b6072..f687d03 100644 --- a/unit-test/stubs/sc_atsrq_stubs.c +++ b/unit-test/stubs/sc_atsrq_stubs.c @@ -43,11 +43,11 @@ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) * Generated stub function for SC_BeginAts() * ---------------------------------------------------- */ -bool SC_BeginAts(uint16 AtsIndex, uint16 TimeOffset) +bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) { UT_GenStub_SetupReturnBuffer(SC_BeginAts, bool); - UT_GenStub_AddParam(SC_BeginAts, uint16, AtsIndex); + UT_GenStub_AddParam(SC_BeginAts, SC_AtsIndex_t, AtsIndex); UT_GenStub_AddParam(SC_BeginAts, uint16, TimeOffset); UT_GenStub_Execute(SC_BeginAts, Basic, NULL); diff --git a/unit-test/stubs/sc_loads_stubs.c b/unit-test/stubs/sc_loads_stubs.c index 99c543a..1b99b7b 100644 --- a/unit-test/stubs/sc_loads_stubs.c +++ b/unit-test/stubs/sc_loads_stubs.c @@ -31,9 +31,9 @@ * Generated stub function for SC_BuildTimeIndexTable() * ---------------------------------------------------- */ -void SC_BuildTimeIndexTable(uint16 AtsIndex) +void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) { - UT_GenStub_AddParam(SC_BuildTimeIndexTable, uint16, AtsIndex); + UT_GenStub_AddParam(SC_BuildTimeIndexTable, SC_AtsIndex_t, AtsIndex); UT_GenStub_Execute(SC_BuildTimeIndexTable, Basic, NULL); } @@ -43,9 +43,9 @@ void SC_BuildTimeIndexTable(uint16 AtsIndex) * Generated stub function for SC_InitAtsTables() * ---------------------------------------------------- */ -void SC_InitAtsTables(uint16 AtsIndex) +void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) { - UT_GenStub_AddParam(SC_InitAtsTables, uint16, AtsIndex); + UT_GenStub_AddParam(SC_InitAtsTables, SC_AtsIndex_t, AtsIndex); UT_GenStub_Execute(SC_InitAtsTables, Basic, NULL); } @@ -55,10 +55,10 @@ void SC_InitAtsTables(uint16 AtsIndex) * Generated stub function for SC_Insert() * ---------------------------------------------------- */ -void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) +void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 ListLength) { - UT_GenStub_AddParam(SC_Insert, uint16, AtsIndex); - UT_GenStub_AddParam(SC_Insert, uint32, NewCmdIndex); + UT_GenStub_AddParam(SC_Insert, SC_AtsIndex_t, AtsIndex); + UT_GenStub_AddParam(SC_Insert, SC_CommandIndex_t, NewCmdIndex); UT_GenStub_AddParam(SC_Insert, uint32, ListLength); UT_GenStub_Execute(SC_Insert, Basic, NULL); @@ -69,9 +69,9 @@ void SC_Insert(uint16 AtsIndex, uint32 NewCmdIndex, uint32 ListLength) * Generated stub function for SC_LoadAts() * ---------------------------------------------------- */ -void SC_LoadAts(uint16 AtsIndex) +void SC_LoadAts(SC_AtsIndex_t AtsIndex) { - UT_GenStub_AddParam(SC_LoadAts, uint16, AtsIndex); + UT_GenStub_AddParam(SC_LoadAts, SC_AtsIndex_t, AtsIndex); UT_GenStub_Execute(SC_LoadAts, Basic, NULL); } @@ -81,9 +81,9 @@ void SC_LoadAts(uint16 AtsIndex) * Generated stub function for SC_LoadRts() * ---------------------------------------------------- */ -void SC_LoadRts(uint16 RtsIndex) +void SC_LoadRts(SC_RtsIndex_t RtsIndex) { - UT_GenStub_AddParam(SC_LoadRts, uint16, RtsIndex); + UT_GenStub_AddParam(SC_LoadRts, SC_RtsIndex_t, RtsIndex); UT_GenStub_Execute(SC_LoadRts, Basic, NULL); } @@ -107,9 +107,9 @@ bool SC_ParseRts(uint32 Buffer32[]) * Generated stub function for SC_ProcessAppend() * ---------------------------------------------------- */ -void SC_ProcessAppend(uint16 AtsIndex) +void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) { - UT_GenStub_AddParam(SC_ProcessAppend, uint16, AtsIndex); + UT_GenStub_AddParam(SC_ProcessAppend, SC_AtsIndex_t, AtsIndex); UT_GenStub_Execute(SC_ProcessAppend, Basic, NULL); } diff --git a/unit-test/stubs/sc_rtsrq_stubs.c b/unit-test/stubs/sc_rtsrq_stubs.c index 1116efb..3d0cae7 100644 --- a/unit-test/stubs/sc_rtsrq_stubs.c +++ b/unit-test/stubs/sc_rtsrq_stubs.c @@ -31,9 +31,9 @@ * Generated stub function for SC_AutoStartRts() * ---------------------------------------------------- */ -void SC_AutoStartRts(uint16 RtsNumber) +void SC_AutoStartRts(SC_RtsNum_t RtsNum) { - UT_GenStub_AddParam(SC_AutoStartRts, uint16, RtsNumber); + UT_GenStub_AddParam(SC_AutoStartRts, SC_RtsNum_t, RtsNum); UT_GenStub_Execute(SC_AutoStartRts, Basic, NULL); } @@ -91,9 +91,9 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) * Generated stub function for SC_KillRts() * ---------------------------------------------------- */ -void SC_KillRts(uint16 RtsIndex) +void SC_KillRts(SC_RtsIndex_t RtsIndex) { - UT_GenStub_AddParam(SC_KillRts, uint16, RtsIndex); + UT_GenStub_AddParam(SC_KillRts, SC_RtsIndex_t, RtsIndex); UT_GenStub_Execute(SC_KillRts, Basic, NULL); } diff --git a/unit-test/stubs/sc_utils_stubs.c b/unit-test/stubs/sc_utils_stubs.c index cbfa538..caf0ef2 100644 --- a/unit-test/stubs/sc_utils_stubs.c +++ b/unit-test/stubs/sc_utils_stubs.c @@ -107,11 +107,11 @@ SC_TimeAccessor_t SC_LookupTimeAccessor(SC_TimeRef_Enum_t TimeRef) * Generated stub function for SC_ToggleAtsIndex() * ---------------------------------------------------- */ -uint16 SC_ToggleAtsIndex(void) +SC_AtsIndex_t SC_ToggleAtsIndex(void) { - UT_GenStub_SetupReturnBuffer(SC_ToggleAtsIndex, uint16); + UT_GenStub_SetupReturnBuffer(SC_ToggleAtsIndex, SC_AtsIndex_t); UT_GenStub_Execute(SC_ToggleAtsIndex, Basic, NULL); - return UT_GenStub_GetReturnValue(SC_ToggleAtsIndex, uint16); + return UT_GenStub_GetReturnValue(SC_ToggleAtsIndex, SC_AtsIndex_t); } diff --git a/unit-test/utilities/sc_test_utils.c b/unit-test/utilities/sc_test_utils.c index 9b81e13..6f3bb25 100644 --- a/unit-test/utilities/sc_test_utils.c +++ b/unit-test/utilities/sc_test_utils.c @@ -48,7 +48,7 @@ SC_AtsInfoTable_t AtsInfoTblAddr[SC_NUMBER_OF_ATS]; SC_RtsInfoEntry_t RtsInfoTblAddr[SC_NUMBER_OF_RTS]; SC_RtpControlBlock_t RtsCtrlBlckAddr; SC_AtpControlBlock_t AtsCtrlBlckAddr; -uint32 AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; +SC_Status_Enum_t AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; /* * Function Definitions diff --git a/unit-test/utilities/sc_test_utils.h b/unit-test/utilities/sc_test_utils.h index 668467d..c84aa9b 100644 --- a/unit-test/utilities/sc_test_utils.h +++ b/unit-test/utilities/sc_test_utils.h @@ -85,6 +85,23 @@ extern UT_CmdBuf_t UT_CmdBuf; /* Unit test ids */ #define SC_UT_MID_1 CFE_SB_ValueToMsgId(CFE_PLATFORM_TLM_MID_BASE + 1) +/* SC-specific assert macros */ +#define SC_Assert_ID_EQ(actual, ref) \ + UtAssert_GenericUnsignedCompare(SC_IDNUM_AS_UINT(actual), UtAssert_Compare_EQ, SC_IDNUM_AS_UINT(ref), \ + UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "ID", #actual, #ref) + +#define SC_Assert_ID_VALUE(actual, ref) \ + UtAssert_GenericUnsignedCompare(SC_IDNUM_AS_UINT(actual), UtAssert_Compare_EQ, (unsigned int)(ref), \ + UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "IDV", #actual, #ref) + +#define SC_Assert_IDX_EQ(actual, ref) \ + UtAssert_GenericUnsignedCompare(SC_IDX_AS_UINT(actual), UtAssert_Compare_EQ, SC_IDX_AS_UINT(ref), \ + UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "IDX", #actual, #ref) + +#define SC_Assert_IDX_VALUE(actual, ref) \ + UtAssert_GenericUnsignedCompare(SC_IDX_AS_UINT(actual), UtAssert_Compare_EQ, (unsigned int)(ref), \ + UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "IDXV", #actual, #ref) + /* * Function Definitions */ From a017a7bca456dc044d300cce5fa85ed0dc7f2e1f Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 12 Oct 2023 09:48:37 -0400 Subject: [PATCH 2/4] Fix #117, change local array refs to object pointer This changes all "info" table access to go through an object pointer that is obtained via an accessor method. --- fsw/src/sc_app.c | 22 +- fsw/src/sc_app.h | 126 +++++++- fsw/src/sc_atsrq.c | 128 ++++---- fsw/src/sc_cmds.c | 106 +++--- fsw/src/sc_loads.c | 189 ++++++----- fsw/src/sc_rtsrq.c | 157 +++++---- fsw/src/sc_state.c | 75 +++-- unit-test/sc_atsrq_tests.c | 386 +++++++++++++--------- unit-test/sc_cmds_tests.c | 483 ++++++++++++++++------------ unit-test/sc_loads_tests.c | 317 ++++++++++++------ unit-test/sc_rtsrq_tests.c | 258 ++++++++------- unit-test/sc_state_tests.c | 384 +++++++++++++--------- unit-test/utilities/sc_test_utils.c | 16 +- unit-test/utilities/sc_test_utils.h | 4 + 14 files changed, 1641 insertions(+), 1010 deletions(-) diff --git a/fsw/src/sc_app.c b/fsw/src/sc_app.c index ae4d648..0fc2567 100644 --- a/fsw/src/sc_app.c +++ b/fsw/src/sc_app.c @@ -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(); @@ -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 */ diff --git a/fsw/src/sc_app.h b/fsw/src/sc_app.h index a887edc..3e54bf3 100644 --- a/fsw/src/sc_app.h +++ b/fsw/src/sc_app.h @@ -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 * @@ -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 */ @@ -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 */ @@ -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 diff --git a/fsw/src/sc_atsrq.c b/fsw/src/sc_atsrq.c index 7b299ce..5a6f09c 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -49,8 +49,9 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StartAtsCmd(const SC_StartAtsCmd_t *Cmd) { - SC_AtsNum_t AtsNum; /* ATS ID */ - SC_AtsIndex_t AtsIndex; /* ATS array index */ + SC_AtsNum_t AtsNum; /* ATS ID */ + SC_AtsIndex_t AtsIndex; /* ATS array index */ + SC_AtsInfoTable_t *AtsInfoPtr; AtsNum = Cmd->Payload.AtsNum; @@ -58,13 +59,14 @@ void SC_StartAtsCmd(const SC_StartAtsCmd_t *Cmd) if ((AtsNum > 0) && (AtsNum <= SC_NUMBER_OF_ATS)) { /* convert ATS ID to array index */ - AtsIndex = SC_AtsNumToIndex(AtsNum); + AtsIndex = SC_AtsNumToIndex(AtsNum); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* make sure that there is no ATS running on the ATP */ if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_IDLE) { /* make sure the specified ATS is ready */ - if (SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands > 0) + if (AtsInfoPtr->NumberOfCommands > 0) { /* start the ats */ if (SC_BeginAts(AtsIndex, 0)) @@ -172,14 +174,16 @@ void SC_StopAtsCmd(const SC_StopAtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) { - SC_AtsEntryHeader_t *Entry; /* ATS table entry pointer */ - SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ - SC_AbsTimeTag_t ListCmdTime = 0; /* list entry execution time */ - SC_SeqIndex_t TimeIndex; /* the current time buffer index */ - SC_CommandIndex_t CmdIndex; /* ATS command index */ - bool ReturnCode; - SC_AbsTimeTag_t TimeToStartAts; /* the REAL time to start the ATS */ - uint16 CmdsSkipped = 0; + SC_AtsEntryHeader_t * Entry; /* ATS table entry pointer */ + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ + SC_AbsTimeTag_t ListCmdTime = 0; /* list entry execution time */ + SC_SeqIndex_t TimeIndex; /* the current time buffer index */ + SC_CommandIndex_t CmdIndex; /* ATS command index */ + bool ReturnCode; + SC_AbsTimeTag_t TimeToStartAts; /* the REAL time to start the ATS */ + uint16 CmdsSkipped = 0; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -189,6 +193,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) return false; } + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); TimeToStartAts = SC_ComputeAbsTime(TimeOffset); /* @@ -199,14 +204,14 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) TimeIndex = SC_SEQUENCE_IDX_FIRST; /* pointer into the time index table */ CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ - while (TimeIndex < SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) + while (TimeIndex < AtsInfoPtr->NumberOfCommands) { /* first get the cmd index at this list entry */ - CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); + CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); /* then get the entry index from the cmd index table */ - EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */ - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; + Entry = &SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset)->Header; /* then get cmd execution time from the ATS entry */ ListCmdTime = SC_GetAtsEntryTime(Entry); @@ -214,8 +219,9 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) if (SC_CompareAbsTime(TimeToStartAts, ListCmdTime)) { /* start time is greater than this list entry time */ + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, CmdIndex); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_SKIPPED; + StatusEntryPtr->Status = SC_Status_SKIPPED; CmdsSkipped++; TimeIndex++; } @@ -229,7 +235,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) /* ** Check to see if the whole ATS was skipped */ - if (TimeIndex == SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) + if (TimeIndex == AtsInfoPtr->NumberOfCommands) { CFE_EVS_SendEvent(SC_ATS_SKP_ALL_ERR_EID, CFE_EVS_EventType_ERROR, "All ATS commands were skipped, ATS stopped"); @@ -272,7 +278,8 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_KillAts(void) { - SC_AtsIndex_t AtsIndex; + SC_AtsIndex_t AtsIndex; + SC_AtsInfoTable_t *AtsInfoPtr; /* * Check if the ATS ID is valid @@ -281,7 +288,9 @@ void SC_KillAts(void) if (SC_AtsIndexIsValid(AtsIndex) && SC_OperData.AtsCtrlBlckAddr->AtpState != SC_Status_IDLE) { /* Increment the ats use counter */ - SC_OperData.AtsInfoTblAddr[AtsIndex].AtsUseCtr++; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + + AtsInfoPtr->AtsUseCtr++; } /* ** Reset the state in the atp control block @@ -299,16 +308,18 @@ void SC_KillAts(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_SwitchAtsCmd(const SC_SwitchAtsCmd_t *Cmd) { - SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ + SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ + SC_AtsInfoTable_t *AtsInfoPtr; /* make sure that an ATS is running on the ATP */ if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { /* get the ATS to switch to */ NewAtsIndex = SC_ToggleAtsIndex(); + AtsInfoPtr = SC_GetAtsInfoObject(NewAtsIndex); /* Now check to see if the new ATS has commands in it */ - if (SC_OperData.AtsInfoTblAddr[NewAtsIndex].NumberOfCommands > 0) + if (AtsInfoPtr->NumberOfCommands > 0) { /* set the global switch pend flag */ SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag = true; @@ -352,8 +363,9 @@ void SC_SwitchAtsCmd(const SC_SwitchAtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ServiceSwitchPend(void) { - SC_AtsIndex_t NewAtsIndex; /* the ats index that we are switching to */ - SC_AtsIndex_t OldAtsIndex; /* the ats index we are switching from */ + SC_AtsIndex_t NewAtsIndex; /* the ats index that we are switching to */ + SC_AtsIndex_t OldAtsIndex; /* the ats index we are switching from */ + SC_AtsInfoTable_t *AtsInfoPtr; /* ** See if it is time to switch the ATS @@ -366,9 +378,10 @@ void SC_ServiceSwitchPend(void) /* get the ATS number to switch to and from */ OldAtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); NewAtsIndex = SC_ToggleAtsIndex(); + AtsInfoPtr = SC_GetAtsInfoObject(NewAtsIndex); /* Now check to see if the new ATS has commands in it */ - if (SC_OperData.AtsInfoTblAddr[NewAtsIndex].NumberOfCommands > 0) + if (AtsInfoPtr->NumberOfCommands > 0) { /* stop the current ATS */ SC_KillAts(); @@ -419,9 +432,10 @@ void SC_ServiceSwitchPend(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ bool SC_InlineSwitch(void) { - SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ - SC_AtsIndex_t OldAtsIndex; /* the index of the ats to switch from*/ - bool ReturnCode; /* return code for function */ + SC_AtsIndex_t NewAtsIndex; /* the index of the ats to switch to*/ + SC_AtsIndex_t OldAtsIndex; /* the index of the ats to switch from*/ + bool ReturnCode; /* return code for function */ + SC_AtsInfoTable_t *AtsInfoPtr; /* figure out which ATS to switch to */ NewAtsIndex = SC_ToggleAtsIndex(); @@ -430,7 +444,8 @@ bool SC_InlineSwitch(void) OldAtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* Now check to see if the new ATS has commands in it */ - if (SC_OperData.AtsInfoTblAddr[NewAtsIndex].NumberOfCommands > 0) + AtsInfoPtr = SC_GetAtsInfoObject(NewAtsIndex); + if (AtsInfoPtr->NumberOfCommands > 0) { /* ** Stop the current ATS @@ -489,21 +504,24 @@ bool SC_InlineSwitch(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) { - SC_AtsEntryHeader_t *Entry; /* ATS table entry pointer */ - SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ - SC_AbsTimeTag_t JumpTime; /* the time to jump to in the ATS */ - SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ - SC_AtsIndex_t AtsIndex; /* index of the ATS that is running */ - SC_SeqIndex_t TimeIndex; /* the current time buffer index */ - SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ - char TimeBuffer[CFE_TIME_PRINTED_STRING_SIZE]; - CFE_TIME_SysTime_t NewTime; - uint16 NumSkipped; + SC_AtsEntryHeader_t * Entry; /* ATS table entry pointer */ + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ + SC_AbsTimeTag_t JumpTime; /* the time to jump to in the ATS */ + SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ + SC_AtsIndex_t AtsIndex; /* index of the ATS that is running */ + SC_SeqIndex_t TimeIndex; /* the current time buffer index */ + SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ + char TimeBuffer[CFE_TIME_PRINTED_STRING_SIZE]; + CFE_TIME_SysTime_t NewTime; + uint16 NumSkipped; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { - JumpTime = Cmd->Payload.NewTime; - AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); + JumpTime = Cmd->Payload.NewTime; + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* ** Loop through the commands until a time tag is found @@ -514,14 +532,14 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ NumSkipped = 0; - while (TimeIndex < SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) + while (TimeIndex < AtsInfoPtr->NumberOfCommands) { /* first get the cmd index at this list entry */ - CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]); + CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); /* then get the entry index from the cmd index table */ - EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */ - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; + Entry = &SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset)->Header; /* then get cmd execution time from the ATS entry */ ListCmdTime = SC_GetAtsEntryTime(Entry); @@ -536,9 +554,10 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) ** if the command has any other status, SC_Status_SKIPPED, SC_Status_EXECUTED, ** etc, then leave the status alone. */ - if (SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] == SC_Status_LOADED) + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, CmdIndex); + if (StatusEntryPtr->Status == SC_Status_LOADED) { - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_SKIPPED; + StatusEntryPtr->Status = SC_Status_SKIPPED; NumSkipped++; } @@ -556,7 +575,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) /* ** Check to see if the whole ATS was skipped */ - if (TimeIndex == SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) + if (TimeIndex == AtsInfoPtr->NumberOfCommands) { CFE_EVS_SendEvent(SC_JUMPATS_CMD_STOPPED_ERR_EID, CFE_EVS_EventType_ERROR, "Jump Cmd: All ATS commands were skipped, ATS stopped"); @@ -645,7 +664,8 @@ void SC_ContinueAtsOnFailureCmd(const SC_ContinueAtsOnFailureCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) { - SC_AtsIndex_t AtsIndex; /* index (not ID) of target ATS */ + SC_AtsIndex_t AtsIndex; /* index (not ID) of target ATS */ + SC_AtsInfoTable_t *AtsInfoPtr; if ((Cmd->Payload.AtsNum == 0) || (Cmd->Payload.AtsNum > SC_NUMBER_OF_ATS)) { @@ -659,9 +679,10 @@ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) } /* create base zero array index from base one ID value */ - AtsIndex = SC_AtsNumToIndex(Cmd->Payload.AtsNum); + AtsIndex = SC_AtsNumToIndex(Cmd->Payload.AtsNum); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); - if (SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands == 0) + if (AtsInfoPtr->NumberOfCommands == 0) { /* target ATS table is empty */ SC_OperData.HkPacket.Payload.CmdErrCtr++; @@ -677,15 +698,14 @@ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) CFE_EVS_SendEvent(SC_APPEND_CMD_SRC_ERR_EID, CFE_EVS_EventType_ERROR, "Append ATS %c error: Append table is empty", 'A' + AtsIndex); } - else if ((SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize + SC_AppData.AppendWordCount) > SC_ATS_BUFF_SIZE32) + else if ((AtsInfoPtr->AtsSize + SC_AppData.AppendWordCount) > SC_ATS_BUFF_SIZE32) { /* not enough room in ATS buffer for Append table data */ SC_OperData.HkPacket.Payload.CmdErrCtr++; CFE_EVS_SendEvent(SC_APPEND_CMD_FIT_ERR_EID, CFE_EVS_EventType_ERROR, "Append ATS %c error: ATS size = %d, Append size = %d, ATS buffer = %d", 'A' + AtsIndex, - (int)SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, SC_AppData.AppendWordCount, - SC_ATS_BUFF_SIZE32); + (int)AtsInfoPtr->AtsSize, SC_AppData.AppendWordCount, SC_ATS_BUFF_SIZE32); } else { diff --git a/fsw/src/sc_cmds.c b/fsw/src/sc_cmds.c index ffd9246..0f24d9a 100644 --- a/fsw/src/sc_cmds.c +++ b/fsw/src/sc_cmds.c @@ -55,16 +55,17 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ProcessAtpCmd(void) { - SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ - SC_AtsIndex_t AtsIndex; /* ATS selection index */ - SC_CommandIndex_t CmdIndex; /* ATS command index */ - char TempAtsChar; - CFE_Status_t Result; - bool AbortATS = false; - SC_AtsEntry_t * EntryPtr; - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t CommandCode = 0; - bool ChecksumValid; + SC_AtsIndex_t AtsIndex; /* ATS selection index */ + SC_CommandIndex_t CmdIndex; /* ATS command index */ + CFE_Status_t Result; + char TempAtsChar; + bool AbortATS = false; + SC_AtsEntry_t * EntryPtr; + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t CommandCode = 0; + bool ChecksumValid; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ + SC_AtsCmdStatusEntry_t * StatusEntryPtr; /* ** The following conditions must be met before the ATS command will be @@ -81,15 +82,15 @@ void SC_ProcessAtpCmd(void) /* ** Get a pointer to the next ats command */ - AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* remember 0..1 */ - CmdIndex = SC_CommandNumToIndex(SC_OperData.AtsCtrlBlckAddr->CmdNumber); - EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; - EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; - + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); /* remember 0..1 */ + CmdIndex = SC_CommandNumToIndex(SC_OperData.AtsCtrlBlckAddr->CmdNumber); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); + EntryPtr = SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, CmdIndex); /* ** Make sure the command has not been executed, skipped or has any other bad status */ - if (SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] == SC_Status_LOADED) + if (StatusEntryPtr->Status == SC_Status_LOADED) { /* ** Make sure the command number matches what the command @@ -142,13 +143,13 @@ void SC_ProcessAtpCmd(void) ** Increment the counter and update the status for ** this command */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_EXECUTED; + StatusEntryPtr->Status = SC_Status_EXECUTED; SC_OperData.HkPacket.Payload.AtsCmdCtr++; } else { /* the switch failed for some reason */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_FAILED_DISTRIB; + StatusEntryPtr->Status = SC_Status_FAILED_DISTRIB; SC_OperData.HkPacket.Payload.AtsCmdErrCtr++; SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; @@ -162,12 +163,12 @@ void SC_ProcessAtpCmd(void) if (Result == CFE_SUCCESS) { /* The command sent OK */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_EXECUTED; + StatusEntryPtr->Status = SC_Status_EXECUTED; SC_OperData.HkPacket.Payload.AtsCmdCtr++; } else { /* the command had Software Bus problems */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_FAILED_DISTRIB; + StatusEntryPtr->Status = SC_Status_FAILED_DISTRIB; SC_OperData.HkPacket.Payload.AtsCmdErrCtr++; SC_OperData.HkPacket.Payload.LastAtsErrSeq = SC_OperData.AtsCtrlBlckAddr->CurrAtsNum; SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; @@ -200,7 +201,7 @@ void SC_ProcessAtpCmd(void) SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; /* update the command status index table */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_FAILED_CHECKSUM; + StatusEntryPtr->Status = SC_Status_FAILED_CHECKSUM; if (SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag == false) { @@ -230,7 +231,7 @@ void SC_ProcessAtpCmd(void) SC_OperData.HkPacket.Payload.LastAtsErrCmd = SC_OperData.AtsCtrlBlckAddr->CmdNumber; /* update the command status index table */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_SKIPPED; + StatusEntryPtr->Status = SC_Status_SKIPPED; /* Mark this ATS for abortion */ AbortATS = true; @@ -242,8 +243,8 @@ void SC_ProcessAtpCmd(void) ** Send an event message to report the invalid command status */ CFE_EVS_SendEvent(SC_ATS_SKP_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid ATS Command Status: Command Skipped, Status: %d", - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex]); + "Invalid ATS Command Status: Command Skipped, Status: %lu", + (unsigned long)StatusEntryPtr->Status); /* ** Increment the ATS error counter */ @@ -296,11 +297,12 @@ void SC_ProcessAtpCmd(void) void SC_ProcessRtpCommand(void) { - SC_RtsEntry_t * EntryPtr; /* a pointer to an RTS entry header */ - SC_RtsIndex_t RtsIndex; /* the RTS index for the cmd */ - SC_EntryOffset_t CmdOffset; /* the location of the cmd */ - CFE_Status_t Result; - bool ChecksumValid; + SC_RtsEntry_t * EntryPtr; /* a pointer to an RTS entry header */ + SC_RtsIndex_t RtsIndex; /* the RTS index for the cmd */ + SC_EntryOffset_t CmdOffset; /* the location of the cmd */ + CFE_Status_t Result; + bool ChecksumValid; + SC_RtsInfoEntry_t *RtsInfoPtr; /* ** The following conditions must be met before a RTS command is executed: @@ -312,10 +314,11 @@ void SC_ProcessRtpCommand(void) /* convert the RTS number so that it can be directly indexed into the table*/ RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + if ((SC_AppData.NextCmdTime[SC_AppData.NextProcNumber] <= SC_AppData.CurrentTime) && (SC_AppData.NextProcNumber == SC_Process_RTP) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && - (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS) && - (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING)) + (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS) && (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING)) { /* ** Count the command for the rate limiter @@ -326,12 +329,12 @@ void SC_ProcessRtpCommand(void) /* ** Get the Command offset within the RTS */ - CmdOffset = SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr; + CmdOffset = RtsInfoPtr->NextCommandPtr; /* ** Get a pointer to the RTS entry using the RTS number and the offset */ - EntryPtr = (SC_RtsEntry_t *)&SC_OperData.RtsTblAddr[RtsIndex][CmdOffset]; + EntryPtr = SC_GetRtsEntryAtOffset(RtsIndex, CmdOffset); ChecksumValid = SC_AppData.EnableHeaderUpdate; if (!SC_AppData.EnableHeaderUpdate) @@ -351,7 +354,7 @@ void SC_ProcessRtpCommand(void) { /* the command was sent OK */ SC_OperData.HkPacket.Payload.RtsCmdCtr++; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr++; + RtsInfoPtr->CmdCtr++; /* ** Get the next command. @@ -369,7 +372,7 @@ void SC_ProcessRtpCommand(void) (int)SC_OperData.RtsCtrlBlckAddr->CurrRtsNum, (unsigned int)Result); SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; + RtsInfoPtr->CmdErrCtr++; SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; @@ -393,7 +396,7 @@ void SC_ProcessRtpCommand(void) ** Update the RTS command error counter and last RTS error info */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; + RtsInfoPtr->CmdErrCtr++; SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; @@ -412,17 +415,20 @@ void SC_ProcessRtpCommand(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_SendHkPacket(void) { - uint16 i; + uint16 i; + SC_AtsInfoTable_t *AtsInfoPtr; + SC_RtsInfoEntry_t *RtsInfoPtr; /* ** fill in the free bytes in each ATS */ - SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_AtsNumToIndex(SC_AtsId_ATSA)] = - (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[SC_AtsNumToIndex(SC_AtsId_ATSA)].AtsSize * SC_BYTES_IN_WORD); - SC_OperData.HkPacket.Payload.AtpFreeBytes[SC_AtsNumToIndex(SC_AtsId_ATSB)] = - (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[SC_AtsNumToIndex(SC_AtsId_ATSB)].AtsSize * SC_BYTES_IN_WORD); + for (i = 0; i < SC_NUMBER_OF_ATS; ++i) + { + AtsInfoPtr = SC_GetAtsInfoObject(SC_ATS_IDX_C(i)); + + SC_OperData.HkPacket.Payload.AtpFreeBytes[i] = + (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - (AtsInfoPtr->AtsSize * SC_BYTES_IN_WORD); + } /* ** @@ -459,12 +465,14 @@ void SC_SendHkPacket(void) for (i = 0; i < SC_NUMBER_OF_RTS; i++) { - if (SC_OperData.RtsInfoTblAddr[i].DisabledFlag == true) + RtsInfoPtr = SC_GetRtsInfoObject(SC_RTS_IDX_C(i)); + + if (RtsInfoPtr->DisabledFlag == true) { SC_OperData.HkPacket.Payload.RtsDisabledStatus[i / SC_NUMBER_OF_RTS_IN_UINT16] |= (1 << (i % SC_NUMBER_OF_RTS_IN_UINT16)); } - if (SC_OperData.RtsInfoTblAddr[i].RtsStatus == SC_Status_EXECUTING) + if (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING) { SC_OperData.HkPacket.Payload.RtsExecutingStatus[i / SC_NUMBER_OF_RTS_IN_UINT16] |= (1 << (i % SC_NUMBER_OF_RTS_IN_UINT16)); @@ -483,13 +491,17 @@ void SC_SendHkPacket(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_SendHkCmd(const SC_SendHkCmd_t *Cmd) { + SC_RtsInfoEntry_t *RtsInfoPtr; + /* set during init to power on or processor reset auto-exec RTS */ if (SC_AppData.AutoStartRTS != 0) { + RtsInfoPtr = SC_GetRtsInfoObject(SC_RtsNumToIndex(SC_AppData.AutoStartRTS)); + /* make sure the selected auto-exec RTS is enabled */ - if (SC_OperData.RtsInfoTblAddr[SC_RtsNumToIndex(SC_AppData.AutoStartRTS)].RtsStatus == SC_Status_LOADED) + if (RtsInfoPtr->RtsStatus == SC_Status_LOADED) { - SC_OperData.RtsInfoTblAddr[SC_RtsNumToIndex(SC_AppData.AutoStartRTS)].DisabledFlag = false; + RtsInfoPtr->DisabledFlag = false; } /* send ground cmd to have SC start the RTS */ diff --git a/fsw/src/sc_loads.c b/fsw/src/sc_loads.c index eb1441c..c77d0de 100644 --- a/fsw/src/sc_loads.c +++ b/fsw/src/sc_loads.c @@ -51,14 +51,16 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_LoadAts(SC_AtsIndex_t AtsIndex) { - uint16 AtsEntryWords; /* current ats entry length in words */ - SC_CommandNum_t AtsCmdNum; /* current ats entry command number */ - SC_EntryOffset_t AtsEntryIndex; /* index into the load for current ats entry */ - SC_AtsEntry_t * EntryPtr; /* a pointer to an ats entry */ - uint32 * AtsTablePtr; /* pointer to the start of the Ats table */ - CFE_MSG_Size_t MessageSize = 0; - int32 Result = CFE_SUCCESS; - bool StillProcessing = true; + uint16 AtsEntryWords; /* current ats entry length in words */ + SC_CommandNum_t AtsCmdNum; /* current ats entry command number */ + SC_EntryOffset_t AtsEntryIndex; /* index into the load for current ats entry */ + SC_AtsEntry_t * EntryPtr; /* a pointer to an ats entry */ + CFE_MSG_Size_t MessageSize = 0; + int32 Result = CFE_SUCCESS; + bool StillProcessing = true; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -74,8 +76,8 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) SC_InitAtsTables(AtsIndex); /* initialize pointers and counters */ - AtsTablePtr = SC_OperData.AtsTblAddr[AtsIndex]; - AtsEntryIndex = 0; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + AtsEntryIndex = SC_ENTRY_OFFSET_FIRST; while (StillProcessing) { @@ -86,7 +88,7 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) if (AtsEntryIndex < SC_ATS_BUFF_SIZE32) { /* get a pointer to the ats command in the table */ - EntryPtr = (SC_AtsEntry_t *)&AtsTablePtr[AtsEntryIndex]; + EntryPtr = SC_GetAtsEntryAtOffset(AtsIndex, AtsEntryIndex); /* get the next command number from the buffer */ AtsCmdNum = EntryPtr->Header.CmdNumber; @@ -94,20 +96,29 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) if (AtsCmdNum == 0) { /* end of the load reached */ - Result = CFE_SUCCESS; - StillProcessing = false; + Result = CFE_SUCCESS; + break; + } + + if (!SC_AtsCommandNumIsValid(AtsCmdNum)) + { + /* the cmd number is invalid */ + Result = SC_ERROR; + break; } /* make sure the CmdPtr can fit in a whole Ats Cmd Header at the very least */ - else if (AtsEntryIndex > (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS)) + if (AtsEntryIndex > (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS)) { /* even the smallest command will not fit in the buffer */ - Result = SC_ERROR; - StillProcessing = false; - } /* else if the cmd number is valid and the command */ - /* has not already been loaded */ - else if (AtsCmdNum <= SC_MAX_ATS_CMDS && - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] == SC_Status_EMPTY) + Result = SC_ERROR; + break; + } + + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_CommandNumToIndex(AtsCmdNum)); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_CommandNumToIndex(AtsCmdNum)); + + if (StatusEntryPtr->Status == SC_Status_EMPTY) { /* get message size */ CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &MessageSize); @@ -124,13 +135,13 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) /* set the command pointer in the command index table */ /* CmdNum starts at one.... */ - SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] = AtsEntryIndex; + CmdOffsetRec->Offset = AtsEntryIndex; /* set the command status to loaded in the command status table */ - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_CommandNumToIndex(AtsCmdNum)] = SC_Status_LOADED; + StatusEntryPtr->Status = SC_Status_LOADED; /* increment the number of commands loaded */ - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands++; + AtsInfoPtr->NumberOfCommands++; /* increment the ats_entry index to the next ats entry */ AtsEntryIndex = AtsEntryIndex + AtsEntryWords; @@ -174,10 +185,10 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) ** if the load was a success, need to build the tables */ /* if the load finished without errors and there was at least one command */ - if ((Result == CFE_SUCCESS) && (SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands > 0)) + if ((Result == CFE_SUCCESS) && (AtsInfoPtr->NumberOfCommands > 0)) { /* record the size of the load in the ATS info table */ - SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize = AtsEntryIndex; /* size in 32-bit WORDS */ + AtsInfoPtr->AtsSize = AtsEntryIndex; /* size in 32-bit WORDS */ /* build the time index table */ SC_BuildTimeIndexTable(AtsIndex); @@ -195,8 +206,10 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) { - int32 i; - int32 ListLength; + int32 i; + int32 ListLength; + SC_CommandIndex_t CmdIdx; + SC_AtsCmdNumRecord_t *AtsCmdNumRec; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -212,12 +225,14 @@ void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) /* initialize sorted list contents */ for (i = 0; i < SC_MAX_ATS_CMDS; i++) { - SC_AppData.AtsTimeIndexBuffer[AtsIndex][i] = SC_INVALID_CMD_NUMBER; + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(i)); + AtsCmdNumRec->CmdNum = SC_INVALID_CMD_NUMBER; /* add in-use command entries to time sorted list */ - if (SC_AppData.AtsCmdIndexBuffer[AtsIndex][i] != SC_ERROR) + CmdIdx = SC_COMMAND_IDX_C(i); + if (!SC_IDX_EQUAL(SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIdx)->Offset, SC_ENTRY_OFFSET_INVALID)) { - SC_Insert(AtsIndex, i, ListLength); + SC_Insert(AtsIndex, CmdIdx, ListLength); ListLength++; } } @@ -230,12 +245,14 @@ void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 ListLength) { - SC_AtsEntryHeader_t *EntryHeader; /* ATS table entry pointer */ - SC_AbsTimeTag_t NewCmdTime = 0; /* new command execution time */ - SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ - SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ - SC_EntryOffset_t EntryIndex; /* ATS entry location in table */ - SC_SeqIndex_t TimeBufIndex; /* this must be signed */ + SC_AtsEntryHeader_t * EntryHeader; /* ATS table entry pointer */ + SC_AbsTimeTag_t NewCmdTime = 0; /* new command execution time */ + SC_AbsTimeTag_t ListCmdTime; /* list entry execution time */ + SC_CommandIndex_t CmdIndex; /* ATS command index (cmd num - 1) */ + SC_SeqIndex_t TimeBufIndex; + SC_SeqIndex_t NextIndex; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ + SC_AtsCmdNumRecord_t * AtsCmdNumRec; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -249,9 +266,9 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis if (ListLength > 0) { /* first get the entry index in the selected ATS table for the new command */ - EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][NewCmdIndex]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, NewCmdIndex); /* then get a pointer to the ATS entry */ - EntryHeader = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; + EntryHeader = &SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset)->Header; /* then get the execution time from the ATS entry for the new command */ NewCmdTime = SC_GetAtsEntryTime(EntryHeader); } @@ -262,11 +279,11 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis while (TimeBufIndex >= 0) { /* first get the cmd index for this list entry */ - CmdIndex = SC_CommandNumToIndex(SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex]); + CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeBufIndex)->CmdNum); /* then get the entry index from the ATS table */ - EntryIndex = SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */ - EntryHeader = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; + EntryHeader = &SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset)->Header; /* then get cmd execution time from the ATS entry */ ListCmdTime = SC_GetAtsEntryTime(EntryHeader); @@ -276,8 +293,11 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis /* new cmd will execute before this list entry */ /* move this list entry to make room for new cmd */ - SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex + 1] = - SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex]; + NextIndex = TimeBufIndex; + SC_IDX_INCREMENT(NextIndex); + + SC_GetAtsCommandNumAtSeq(AtsIndex, NextIndex)->CmdNum = + SC_GetAtsCommandNumAtSeq(AtsIndex, TimeBufIndex)->CmdNum; /* back up to previous list entry (ok if -1) */ TimeBufIndex--; @@ -296,7 +316,10 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis ** else only entries with later times have been moved ** In either case, there is an empty slot next to TimeBufIndex */ - SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeBufIndex + 1] = SC_CommandIndexToNum(NewCmdIndex); + SC_IDX_INCREMENT(TimeBufIndex); + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, TimeBufIndex); + AtsCmdNumRec->CmdNum = SC_CommandIndexToNum(NewCmdIndex); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -306,7 +329,11 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) { - int32 i; + int32 i; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + SC_AtsCmdNumRecord_t * AtsCmdNumRec; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -319,14 +346,19 @@ void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) /* loop through and set the ATS tables to zero */ for (i = 0; i < SC_MAX_ATS_CMDS; i++) { - SC_AppData.AtsCmdIndexBuffer[AtsIndex][i] = SC_ERROR; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][i] = SC_Status_EMPTY; - SC_AppData.AtsTimeIndexBuffer[AtsIndex][i] = SC_INVALID_CMD_NUMBER; + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(i)); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(i)); + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(i)); + + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_INVALID; + StatusEntryPtr->Status = SC_Status_EMPTY; + AtsCmdNumRec->CmdNum = SC_INVALID_CMD_NUMBER; } /* initialize the pointers and counters */ - SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize = 0; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 0; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + AtsInfoPtr->AtsSize = 0; + AtsInfoPtr->NumberOfCommands = 0; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -336,19 +368,23 @@ void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_LoadRts(SC_RtsIndex_t RtsIndex) { + SC_RtsInfoEntry_t *RtsInfoPtr; + /* validate RTS array index */ if (RtsIndex < SC_NUMBER_OF_RTS) { /* Clear out the RTS info table */ - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = 0; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + RtsInfoPtr->RtsStatus = SC_Status_LOADED; + RtsInfoPtr->UseCtr = 0; + RtsInfoPtr->CmdCtr = 0; + RtsInfoPtr->CmdErrCtr = 0; + RtsInfoPtr->NextCommandTime = 0; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST; /* Make sure the RTS is disabled */ - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; + RtsInfoPtr->DisabledFlag = true; } else { @@ -598,12 +634,15 @@ void SC_UpdateAppend(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) { - SC_AtsEntry_t * EntryPtr; - CFE_MSG_Size_t CommandBytes = 0; - int32 CommandWords; - SC_EntryOffset_t EntryIndex; - int32 i; - SC_CommandIndex_t CmdIndex; + SC_AtsEntry_t * EntryPtr; + CFE_MSG_Size_t CommandBytes = 0; + int32 CommandWords; + SC_EntryOffset_t EntryIndex; + int32 i; + SC_CommandIndex_t CmdIndex; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* validate ATS array index */ if (AtsIndex >= SC_NUMBER_OF_ATS) @@ -614,33 +653,37 @@ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) } /* save index of free area at end of ATS table data */ - EntryIndex = SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + EntryIndex = SC_ENTRY_OFFSET_C(AtsInfoPtr->AtsSize); /* copy Append table data to end of ATS table data */ - memcpy(&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex], SC_OperData.AppendTblAddr, + memcpy(SC_GetAtsEntryAtOffset(AtsIndex, EntryIndex), SC_OperData.AppendTblAddr, SC_AppData.AppendWordCount * SC_BYTES_IN_WORD); /* update size of ATS table data */ - SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize += SC_AppData.AppendWordCount; + AtsInfoPtr->AtsSize += SC_AppData.AppendWordCount; /* add appended entries to ats process tables */ for (i = 0; i < SC_OperData.HkPacket.Payload.AppendEntryCount; i++) { /* get pointer to next appended entry */ - EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][EntryIndex]; + EntryPtr = SC_GetAtsEntryAtOffset(AtsIndex, EntryIndex); /* convert base one cmd number to base zero index */ CmdIndex = SC_CommandNumToIndex(EntryPtr->Header.CmdNumber); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, CmdIndex); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); + /* count only new commands, not replaced commands */ - if (SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] == SC_Status_EMPTY) + if (StatusEntryPtr->Status == SC_Status_EMPTY) { - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands++; + AtsInfoPtr->NumberOfCommands++; } /* update array of pointers to ats entries */ - SC_AppData.AtsCmdIndexBuffer[AtsIndex][CmdIndex] = EntryIndex; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_LOADED; + CmdOffsetRec->Offset = EntryIndex; + StatusEntryPtr->Status = SC_Status_LOADED; /* update entry index to point to the next entry */ CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CommandBytes); @@ -825,8 +868,8 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) Result = SC_ERROR; CFE_EVS_SendEvent(SC_VERIFY_ATS_DUP_ERR_EID, CFE_EVS_EventType_ERROR, - "Verify ATS Table error: dup cmd number: buf index = %d, cmd num = %d, dup index = %d", - (int)EntryIndex, EntryPtr->Header.CmdNumber, + "Verify ATS Table error: dup cmd number: buf index = %d, cmd num = %u, dup index = %d", + (int)EntryIndex, SC_IDNUM_AS_UINT(EntryPtr->Header.CmdNumber), (int)SC_OperData.AtsDupTestArray[SC_CommandNumToIndex(EntryPtr->Header.CmdNumber)]); } else diff --git a/fsw/src/sc_rtsrq.c b/fsw/src/sc_rtsrq.c index 34a5273..c12dc37 100644 --- a/fsw/src/sc_rtsrq.c +++ b/fsw/src/sc_rtsrq.c @@ -55,6 +55,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) SC_RtsEntryHeader_t *RtsEntryPtr; /* pointer to an rts entry */ CFE_MSG_Message_t * RtsEntryCmd; /* pointer to an rts command */ CFE_MSG_Size_t CmdLength = 0; /* the length of the 1st cmd */ + SC_RtsInfoEntry_t * RtsInfoPtr; /* ** Check start RTS parameters @@ -64,18 +65,19 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); /* make sure that RTS is not disabled */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false) + if (RtsInfoPtr->DisabledFlag == false) { /* the requested RTS is not being used and is not empty */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED) + if (RtsInfoPtr->RtsStatus == SC_Status_LOADED) { /* ** Check the command length */ - RtsEntryPtr = (SC_RtsEntryHeader_t *)SC_OperData.RtsTblAddr[RtsIndex]; + RtsEntryPtr = &SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST)->Header; RtsEntryCmd = (CFE_MSG_Message_t *)((uint8_t *)RtsEntryPtr + SC_RTS_HEADER_SIZE); CFE_MSG_GetSize(RtsEntryCmd, &CmdLength); @@ -86,18 +88,17 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) /* ** Initialize the RTS info table entry */ - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr++; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->CmdCtr = 0; + RtsInfoPtr->CmdErrCtr = 0; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST; + RtsInfoPtr->UseCtr++; /* ** Get the absolute time for the RTSs next_cmd_time ** using the current time and the relative time tag. */ - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = - SC_ComputeAbsTime(((SC_RtsEntryHeader_t *)SC_OperData.RtsTblAddr[RtsIndex])->TimeTag); + RtsInfoPtr->NextCommandTime = SC_ComputeAbsTime(RtsEntryPtr->TimeTag); /* ** Last, Increment some global counters associated with the @@ -135,7 +136,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) CFE_EVS_SendEvent(SC_STARTRTS_CMD_NOT_LDED_ERR_EID, CFE_EVS_EventType_ERROR, "Start RTS %03d Rejected: RTS Not Loaded or In Use, Status: %d", Cmd->Payload.RtsNum, - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus); + RtsInfoPtr->RtsStatus); SC_OperData.HkPacket.Payload.CmdErrCtr++; SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -168,12 +169,13 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) { - SC_RtsNum_t FirstRtsNum; - SC_RtsNum_t LastRtsNum; - SC_RtsIndex_t FirstIndex; /* RTS array index */ - SC_RtsIndex_t LastIndex; - SC_RtsIndex_t RtsIndex; - int32 StartCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 StartCount = 0; + SC_RtsInfoEntry_t *RtsInfoPtr; FirstRtsNum = Cmd->Payload.FirstRtsNum; LastRtsNum = Cmd->Payload.LastRtsNum; @@ -188,21 +190,23 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* make sure that RTS is not disabled, empty or executing */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false) + if (RtsInfoPtr->DisabledFlag == false) { - if (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED) + if (RtsInfoPtr->RtsStatus == SC_Status_LOADED) { /* initialize the RTS info table entry */ - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr++; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->CmdCtr = 0; + RtsInfoPtr->CmdErrCtr = 0; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST; + RtsInfoPtr->UseCtr++; /* get absolute time for 1st cmd in the RTS */ - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = - SC_ComputeAbsTime(((SC_RtsEntryHeader_t *)SC_OperData.RtsTblAddr[RtsIndex])->TimeTag); + RtsInfoPtr->NextCommandTime = + SC_ComputeAbsTime(SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST)->Header.TimeTag); /* maintain counters associated with starting RTS */ SC_OperData.RtsCtrlBlckAddr->NumRtsActive++; @@ -216,7 +220,7 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) CFE_EVS_SendEvent( SC_STARTRTSGRP_CMD_NOT_LDED_ERR_EID, CFE_EVS_EventType_ERROR, "Start RTS group error: rejected RTS ID %03d, RTS Not Loaded or In Use, Status: %d", - SC_RtsIndexToNum(RtsIndex), SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus); + SC_RtsIndexToNum(RtsIndex), RtsInfoPtr->RtsStatus); SC_OperData.HkPacket.Payload.RtsActiveErrCtr++; @@ -291,12 +295,13 @@ void SC_StopRtsCmd(const SC_StopRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) { - SC_RtsNum_t FirstRtsNum; - SC_RtsNum_t LastRtsNum; - SC_RtsIndex_t FirstIndex; /* RTS array index */ - SC_RtsIndex_t LastIndex; - SC_RtsIndex_t RtsIndex; - int32 StopCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 StopCount = 0; + SC_RtsInfoEntry_t *RtsInfoPtr; FirstRtsNum = Cmd->Payload.FirstRtsNum; LastRtsNum = Cmd->Payload.LastRtsNum; @@ -311,8 +316,10 @@ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* count the entries that were actually stopped */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING) + if (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING) { SC_KillRts(RtsIndex); StopCount++; @@ -340,8 +347,9 @@ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) { - SC_RtsNum_t RtsNum; /* RTS number */ - SC_RtsIndex_t RtsIndex; /* RTS array index */ + SC_RtsNum_t RtsNum; /* RTS number */ + SC_RtsIndex_t RtsIndex; /* RTS array index */ + SC_RtsInfoEntry_t *RtsInfoPtr; RtsNum = Cmd->Payload.RtsNum; @@ -349,10 +357,11 @@ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) if (RtsNum <= SC_NUMBER_OF_RTS) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); /* disable the RTS */ - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; + RtsInfoPtr->DisabledFlag = true; /* update the command status */ SC_OperData.HkPacket.Payload.CmdCtr++; @@ -376,12 +385,13 @@ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) { - SC_RtsNum_t FirstRtsNum; - SC_RtsNum_t LastRtsNum; - SC_RtsIndex_t FirstIndex; /* RTS array index */ - SC_RtsIndex_t LastIndex; - SC_RtsIndex_t RtsIndex; - int32 DisableCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 DisableCount = 0; + SC_RtsInfoEntry_t *RtsInfoPtr; FirstRtsNum = Cmd->Payload.FirstRtsNum; LastRtsNum = Cmd->Payload.LastRtsNum; @@ -396,11 +406,13 @@ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* count the entries that were actually disabled */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false) + if (RtsInfoPtr->DisabledFlag == false) { DisableCount++; - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; + RtsInfoPtr->DisabledFlag = true; } } @@ -425,8 +437,9 @@ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) { - SC_RtsNum_t RtsNum; /* RTS number */ - SC_RtsIndex_t RtsIndex; /* RTS array index */ + SC_RtsNum_t RtsNum; /* RTS number */ + SC_RtsIndex_t RtsIndex; /* RTS array index */ + SC_RtsInfoEntry_t *RtsInfoPtr; RtsNum = Cmd->Payload.RtsNum; @@ -434,10 +447,11 @@ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) { /* convert RTS ID to RTS array index */ - RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsIndex = SC_RtsNumToIndex(RtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); /* re-enable the RTS */ - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; + RtsInfoPtr->DisabledFlag = false; /* update the command status */ SC_OperData.HkPacket.Payload.CmdCtr++; @@ -462,12 +476,13 @@ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) { - SC_RtsNum_t FirstRtsNum; - SC_RtsNum_t LastRtsNum; - SC_RtsIndex_t FirstIndex; /* RTS array index */ - SC_RtsIndex_t LastIndex; - SC_RtsIndex_t RtsIndex; - int32 EnableCount = 0; + SC_RtsNum_t FirstRtsNum; + SC_RtsNum_t LastRtsNum; + SC_RtsIndex_t FirstIndex; /* RTS array index */ + SC_RtsIndex_t LastIndex; + SC_RtsIndex_t RtsIndex; + int32 EnableCount = 0; + SC_RtsInfoEntry_t *RtsInfoPtr; FirstRtsNum = Cmd->Payload.FirstRtsNum; LastRtsNum = Cmd->Payload.LastRtsNum; @@ -482,11 +497,13 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) { + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* count the entries that were actually enabled */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true) + if (RtsInfoPtr->DisabledFlag == true) { EnableCount++; - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; + RtsInfoPtr->DisabledFlag = false; } } @@ -511,25 +528,29 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_KillRts(SC_RtsIndex_t RtsIndex) { + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* validate RTS array index */ if (RtsIndex >= SC_NUMBER_OF_RTS) { CFE_EVS_SendEvent(SC_KILLRTS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "RTS kill error: invalid RTS index %d", RtsIndex); } - else if (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING) + else if (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING) { /* - ** Stop the RTS from executing - */ - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = SC_MAX_TIME; + ** Stop the RTS from executing + */ + RtsInfoPtr->RtsStatus = SC_Status_LOADED; + RtsInfoPtr->NextCommandTime = SC_MAX_TIME; /* - ** Note: the rest of the fields are left alone - ** to provide information on where the - ** rts stopped. They are cleared out when it is restarted. - */ + ** Note: the rest of the fields are left alone + ** to provide information on where the + ** rts stopped. They are cleared out when it is restarted. + */ if (SC_OperData.RtsCtrlBlckAddr->NumRtsActive > 0) { diff --git a/fsw/src/sc_state.c b/fsw/src/sc_state.c index 5db0cab..02fd216 100644 --- a/fsw/src/sc_state.c +++ b/fsw/src/sc_state.c @@ -57,9 +57,10 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_GetNextRtsTime(void) { - int16 i; /* loop counter MUST be SIGNED !*/ - SC_RtsIndex_t NextRts; /* the next rts to schedule */ - SC_AbsTimeTag_t NextTime; /* the next time for the RTS */ + int16 i; /* loop counter MUST be SIGNED !*/ + SC_RtsIndex_t NextRts; /* the next rts to schedule */ + SC_AbsTimeTag_t NextTime; /* the next time for the RTS */ + SC_RtsInfoEntry_t *RtsInfoPtr; NextRts = SC_INVALID_RTS_INDEX; NextTime = SC_MAX_TIME; @@ -72,11 +73,12 @@ void SC_GetNextRtsTime(void) */ for (i = SC_NUMBER_OF_RTS - 1; i >= 0; i--) { - if (SC_OperData.RtsInfoTblAddr[i].RtsStatus == SC_Status_EXECUTING) + RtsInfoPtr = SC_GetRtsInfoObject(SC_RTS_IDX_C(i)); + if (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING) { - if (SC_OperData.RtsInfoTblAddr[i].NextCommandTime <= NextTime) + if (RtsInfoPtr->NextCommandTime <= NextTime) { - NextTime = SC_OperData.RtsInfoTblAddr[i].NextCommandTime; + NextTime = RtsInfoPtr->NextCommandTime; NextRts = SC_RTS_IDX_C(i); } /* end if */ } /* end if */ @@ -89,7 +91,7 @@ void SC_GetNextRtsTime(void) } else { - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = NextRts + 1; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(NextRts); SC_AppData.NextCmdTime[SC_Process_RTP] = NextTime; } /* end if */ } @@ -144,10 +146,11 @@ void SC_UpdateNextTime(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_GetNextRtsCommand(void) { - SC_RtsIndex_t RtsIndex; - SC_EntryOffset_t CmdOffset; - SC_RtsEntry_t * EntryPtr; - CFE_MSG_Size_t CmdLength = 0; + SC_RtsIndex_t RtsIndex; + SC_EntryOffset_t CmdOffset; + SC_RtsEntry_t * EntryPtr; + CFE_MSG_Size_t CmdLength = 0; + SC_RtsInfoEntry_t *RtsInfoPtr; /* ** Make sure that the RTP is executing some RTS @@ -156,17 +159,18 @@ void SC_GetNextRtsCommand(void) if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS)) { /* Get the index of the rts that is running */ - RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); + RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); /* ** Find out if the RTS is EXECUTING or just STARTED */ - if (SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING) + if (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING) { /* ** Get the information needed to find the next command */ - CmdOffset = SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr; - EntryPtr = (SC_RtsEntry_t *)&SC_OperData.RtsTblAddr[RtsIndex][CmdOffset]; + CmdOffset = RtsInfoPtr->NextCommandPtr; + EntryPtr = SC_GetRtsEntryAtOffset(RtsIndex, CmdOffset); CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CmdLength); CmdLength += SC_RTS_HEADER_SIZE; @@ -191,7 +195,7 @@ void SC_GetNextRtsCommand(void) /* ** Get the next RTS command */ - EntryPtr = (SC_RtsEntry_t *)&SC_OperData.RtsTblAddr[RtsIndex][CmdOffset]; + EntryPtr = SC_GetRtsEntryAtOffset(RtsIndex, CmdOffset); /* ** get the length of the new command @@ -223,13 +227,12 @@ void SC_GetNextRtsCommand(void) ** Everything passed! ** Update the proper next command time for that RTS */ - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = - SC_ComputeAbsTime(EntryPtr->Header.TimeTag); + RtsInfoPtr->NextCommandTime = SC_ComputeAbsTime(EntryPtr->Header.TimeTag); /* ** Update the appropriate RTS info table current command pointer */ - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = CmdOffset; + RtsInfoPtr->NextCommandPtr = CmdOffset; } else { /* the command runs past the end of the buffer */ @@ -239,7 +242,7 @@ void SC_GetNextRtsCommand(void) ** is an error condition, so record it */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; + RtsInfoPtr->CmdErrCtr++; SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; @@ -258,7 +261,7 @@ void SC_GetNextRtsCommand(void) /* update the error information */ SC_OperData.HkPacket.Payload.RtsCmdErrCtr++; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr++; + RtsInfoPtr->CmdErrCtr++; SC_OperData.HkPacket.Payload.LastRtsErrSeq = SC_OperData.RtsCtrlBlckAddr->CurrRtsNum; SC_OperData.HkPacket.Payload.LastRtsErrCmd = CmdOffset; @@ -310,32 +313,40 @@ void SC_GetNextRtsCommand(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_GetNextAtsCommand(void) { - SC_AtsIndex_t AtsIndex; /* ats array index */ - SC_SeqIndex_t TimeIndex; /* a time index pointer */ - SC_EntryOffset_t CmdIndex; /* ats command array index */ - SC_AtsEntry_t * EntryPtr; + SC_AtsIndex_t AtsIndex; /* ats array index */ + SC_SeqIndex_t TimeIndex; /* a time index pointer */ + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + SC_AtsEntry_t * EntryPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdNumRecord_t * AtsCmdNumRec; + SC_CommandIndex_t CurrCmdIndex; if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { /* ** Get the information that is needed to find the next command */ - AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); - TimeIndex = SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr + 1; + AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); + TimeIndex = SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr + 1; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* ** Check to see if there are more ATS commands */ - if (TimeIndex < SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands) + if (TimeIndex < AtsInfoPtr->NumberOfCommands) { /* get the information for the next command in the ATP control block */ + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex); + CurrCmdIndex = SC_CommandNumToIndex(AtsCmdNumRec->CmdNum); + SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr = TimeIndex; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_AppData.AtsTimeIndexBuffer[AtsIndex][TimeIndex]; + SC_OperData.AtsCtrlBlckAddr->CmdNumber = AtsCmdNumRec->CmdNum; /* update the next command time */ - CmdIndex = - SC_AppData.AtsCmdIndexBuffer[AtsIndex][SC_CommandNumToIndex(SC_OperData.AtsCtrlBlckAddr->CmdNumber)]; - EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AtsTblAddr[AtsIndex][CmdIndex]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CurrCmdIndex); + + EntryPtr = SC_GetAtsEntryAtOffset(AtsIndex, CmdOffsetRec->Offset); + SC_AppData.NextCmdTime[SC_Process_ATP] = SC_GetAtsEntryTime(&EntryPtr->Header); } else diff --git a/unit-test/sc_atsrq_tests.c b/unit-test/sc_atsrq_tests.c index 8a9f3b3..31c35ad 100644 --- a/unit-test/sc_atsrq_tests.c +++ b/unit-test/sc_atsrq_tests.c @@ -66,14 +66,20 @@ CFE_TIME_Compare_t UT_SC_StartAtsRq_CompareHook3(void *UserObj, int32 StubRetcod void SC_StartAtsCmd_Test_NominalA(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_FIRST); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartAtsCmd(&UT_CmdBuf.StartAtsCmd)); @@ -89,14 +95,20 @@ void SC_StartAtsCmd_Test_NominalA(void) void SC_StartAtsCmd_Test_NominalB(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_FIRST); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartAtsCmd(&UT_CmdBuf.StartAtsCmd)); @@ -112,18 +124,21 @@ void SC_StartAtsCmd_Test_NominalB(void) void SC_StartAtsCmd_Test_CouldNotStart(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; /* Set to cause SC_BeginAts to return false, in order to reach block starting with "could not start the ats" */ UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); @@ -140,16 +155,19 @@ void SC_StartAtsCmd_Test_CouldNotStart(void) void SC_StartAtsCmd_Test_NoCommandsA(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 0; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 0; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartAtsCmd(&UT_CmdBuf.StartAtsCmd)); @@ -163,16 +181,19 @@ void SC_StartAtsCmd_Test_NoCommandsA(void) void SC_StartAtsCmd_Test_NoCommandsB(void) { - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; + UT_CmdBuf.StartAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 0; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_IDLE; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartAtsCmd(&UT_CmdBuf.StartAtsCmd)); @@ -309,18 +330,23 @@ void SC_StopAtsCmd_Test_NoRunningAts(void) void SC_BeginAts_Test_Nominal(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - uint16 TimeOffset = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint16 TimeOffset = 0; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_FIRST); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; + AtsInfoPtr->NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); /* Execute the function being tested */ UtAssert_BOOL_TRUE(SC_BeginAts(AtsIndex, TimeOffset)); /* Verify results */ SC_Assert_ID_VALUE(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum, 1); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], - "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); + SC_Assert_ID_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, AtsCmdNumRec->CmdNum); SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 0); UtAssert_True(SC_AppData.NextCmdTime[SC_Process_ATP] == 0, "SC_AppData.NextCmdTime[SC_Process_ATP] == 0"); @@ -330,13 +356,21 @@ void SC_BeginAts_Test_Nominal(void) void SC_BeginAts_Test_AllCommandsSkipped(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - uint16 TimeOffset = 0; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint16 TimeOffset = 0; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t *StatusEntryPtr; + SC_AtsCmdNumRecord_t * AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_FIRST); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - SC_AppData.AtsTimeIndexBuffer[0][0] = 1; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); + AtsInfoPtr->NumberOfCommands = 1; /* Set to cause all commnds to be skipped, to generate error message SC_ATS_SKP_ALL_ERR_EID */ UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); @@ -345,9 +379,7 @@ void SC_BeginAts_Test_AllCommandsSkipped(void) UtAssert_BOOL_FALSE(SC_BeginAts(AtsIndex, TimeOffset)); /* Verify results */ - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_SKIPPED); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_SKP_ALL_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } @@ -367,7 +399,10 @@ void SC_BeginAts_Test_InvalidAtsIndex(void) void SC_KillAts_Test(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)99; @@ -376,7 +411,7 @@ void SC_KillAts_Test(void) UtAssert_VOIDCALL(SC_KillAts()); /* Verify results */ - UtAssert_True(SC_OperData.AtsInfoTblAddr[0].AtsUseCtr == 1, "SC_OperData.AtsInfoTblAddr[0].AtsUseCtr == 1"); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsUseCtr, 1); UtAssert_True(SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_IDLE, "SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_IDLE"); UtAssert_True(SC_AppData.NextCmdTime[SC_Process_ATP] == SC_MAX_TIME, @@ -387,14 +422,17 @@ void SC_KillAts_Test(void) void SC_SwitchAtsCmd_Test_Nominal(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 1; UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -412,14 +450,17 @@ void SC_SwitchAtsCmd_Test_Nominal(void) void SC_SwitchAtsCmd_Test_DestinationAtsNotLoaded(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_ONEHZ_WAKEUP_MID); + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(TestMsgId), false); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 0; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_SwitchAtsCmd(&UT_CmdBuf.SwitchAtsCmd)); @@ -456,8 +497,11 @@ void SC_SwitchAtsCmd_Test_AtpIdle(void) void SC_ServiceSwitchPend_Test_NominalA(void) { - SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); - SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex1, SC_SEQUENCE_IDX_FIRST); UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); @@ -465,11 +509,11 @@ void SC_ServiceSwitchPend_Test_NominalA(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; - SC_AppData.AtsTimeIndexBuffer[AtsIndex1][0] = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -488,8 +532,11 @@ void SC_ServiceSwitchPend_Test_NominalA(void) void SC_ServiceSwitchPend_Test_NominalB(void) { - SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); - SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex0, SC_SEQUENCE_IDX_FIRST); UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); @@ -497,11 +544,11 @@ void SC_ServiceSwitchPend_Test_NominalB(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; - SC_AppData.AtsTimeIndexBuffer[AtsIndex0][0] = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 0); @@ -526,10 +573,8 @@ void SC_ServiceSwitchPend_Test_AtsEmpty(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 0; - SC_OperData.AtsInfoTblAddr[1].NumberOfCommands = 0; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ServiceSwitchPend()); @@ -593,10 +638,10 @@ void SC_ServiceSwitchPend_Test_AtsNotStarted(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ServiceSwitchPend()); @@ -613,17 +658,20 @@ void SC_ServiceSwitchPend_Test_AtsNotStarted(void) void SC_InlineSwitch_Test_NominalA(void) { - SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); - SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex1, SC_SEQUENCE_IDX_FIRST); /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; - SC_AppData.AtsTimeIndexBuffer[AtsIndex1][0] = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 1); @@ -644,17 +692,20 @@ void SC_InlineSwitch_Test_NominalA(void) void SC_InlineSwitch_Test_NominalB(void) { - SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); - SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsIndex_t AtsIndex0 = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex1 = SC_ATS_IDX_C(1); + SC_AtsCmdNumRecord_t *AtsCmdNumRec; + + AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex0, SC_SEQUENCE_IDX_FIRST); /* Set to satisfy first if-statement, while not affecting later calls to CFE_TIME_Compare */ UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; - SC_AppData.AtsTimeIndexBuffer[AtsIndex0][0] = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; + AtsCmdNumRec->CmdNum = SC_COMMAND_NUM_C(1); UT_SetDeferredRetcode(UT_KEY(SC_ToggleAtsIndex), 1, 0); @@ -684,9 +735,9 @@ void SC_InlineSwitch_Test_AllCommandsSkipped(void) * were skipped" */ UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHookAgreaterthanB, NULL); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); - SC_OperData.AtsInfoTblAddr[AtsIndex0].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex1].NumberOfCommands = 1; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); + SC_GetAtsInfoObject(AtsIndex0)->NumberOfCommands = 1; + SC_GetAtsInfoObject(AtsIndex1)->NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_BOOL_FALSE(SC_InlineSwitch()); @@ -720,9 +771,17 @@ void SC_InlineSwitch_Test_DestinationAtsNotLoaded(void) void SC_JumpAtsCmd_Test_SkipOneCmd(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t *StatusPtr0; + SC_AtsCmdStatusEntry_t *StatusPtr1; + + StatusPtr0 = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusPtr1 = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(1)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_JumpAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); @@ -733,25 +792,24 @@ void SC_JumpAtsCmd_Test_SkipOneCmd(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] = SC_Status_LOADED; - SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; - SC_AppData.AtsTimeIndexBuffer[AtsIndex][1] = 2; - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(2); - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 2; + StatusPtr0->Status = SC_Status_LOADED; + StatusPtr1->Status = SC_Status_LOADED; + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(0))->CmdNum = SC_COMMAND_NUM_C(1); + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum = SC_COMMAND_NUM_C(2); + + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(2); + AtsInfoPtr->NumberOfCommands = 2; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_JumpAtsCmd(&UT_CmdBuf.JumpAtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_Status_SKIPPED"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_LOADED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_LOADED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], - "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); + SC_Assert_CmdStatus(StatusPtr0->Status, SC_Status_SKIPPED); + SC_Assert_CmdStatus(StatusPtr1->Status, SC_Status_LOADED); + SC_Assert_ID_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum); SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); UtAssert_True(SC_AppData.NextCmdTime[0] == 0, "SC_AppData.NextCmdTime[0] == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); @@ -763,9 +821,14 @@ void SC_JumpAtsCmd_Test_SkipOneCmd(void) void SC_JumpAtsCmd_Test_AllCommandsSkipped(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t *StatusEntryPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_JumpAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); @@ -776,10 +839,10 @@ void SC_JumpAtsCmd_Test_AllCommandsSkipped(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 1; + StatusEntryPtr->Status = SC_Status_LOADED; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_JumpAtsCmd(&UT_CmdBuf.JumpAtsCmd)); @@ -813,9 +876,16 @@ void SC_JumpAtsCmd_Test_NoRunningAts(void) void SC_JumpAtsCmd_Test_AtsNotLoaded(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_JUMP_ATS_CC; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t *StatusPtr0; + SC_AtsCmdStatusEntry_t *StatusPtr1; + + StatusPtr0 = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusPtr1 = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(1)); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_JumpAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); @@ -826,22 +896,24 @@ void SC_JumpAtsCmd_Test_AtsNotLoaded(void) UT_SC_StartAtsRq_CompareHookRunCount = 0; UT_SetHookFunction(UT_KEY(CFE_TIME_Compare), UT_SC_StartAtsRq_CompareHook3, NULL); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_SKIPPED; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] = SC_Status_SKIPPED; - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[0].NumberOfCommands = 2; + StatusPtr0->Status = SC_Status_SKIPPED; + StatusPtr1->Status = SC_Status_SKIPPED; + + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 2; + + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(0))->CmdNum = SC_COMMAND_NUM_C(1); + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum = SC_COMMAND_NUM_C(2); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_JumpAtsCmd(&UT_CmdBuf.JumpAtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] == SC_Status_SKIPPED"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[AtsIndex][1] == SC_Status_SKIPPED"); - UtAssert_True(SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0], - "SC_OperData.AtsCtrlBlckAddr->CmdNumber == SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]"); + SC_Assert_CmdStatus(StatusPtr0->Status, SC_Status_SKIPPED); + SC_Assert_CmdStatus(StatusPtr1->Status, SC_Status_SKIPPED); + SC_Assert_ID_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum); SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); UtAssert_True(SC_AppData.NextCmdTime[0] == 0, "SC_AppData.NextCmdTime[0] == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); @@ -919,16 +991,19 @@ void SC_AppendAtsCmd_Test_Nominal(void) SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsInfoTable_t * AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); - UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - SC_OperData.HkPacket.Payload.AppendEntryCount = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + AtsInfoPtr->NumberOfCommands = 1; + SC_OperData.HkPacket.Payload.AppendEntryCount = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_AppendAtsCmd(&UT_CmdBuf.AppendAtsCmd)); @@ -985,16 +1060,19 @@ void SC_AppendAtsCmd_Test_InvalidAtsNumZero(void) void SC_AppendAtsCmd_Test_AtsTableEmpty(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 0; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.HkPacket.Payload.AppendEntryCount = 1; + AtsInfoPtr->NumberOfCommands = 0; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_AppendAtsCmd(&UT_CmdBuf.AppendAtsCmd)); @@ -1008,16 +1086,19 @@ void SC_AppendAtsCmd_Test_AtsTableEmpty(void) void SC_AppendAtsCmd_Test_AppendTableEmpty(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.HkPacket.Payload.AppendEntryCount = 0; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.HkPacket.Payload.AppendEntryCount = 0; + AtsInfoPtr->NumberOfCommands = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_AppendAtsCmd(&UT_CmdBuf.AppendAtsCmd)); @@ -1031,18 +1112,21 @@ void SC_AppendAtsCmd_Test_AppendTableEmpty(void) void SC_AppendAtsCmd_Test_NoRoomForAppendInAts(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_APPEND_ATS_CC; + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &TestMsgId, sizeof(SC_AppendAtsCmd_t), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); - SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize = SC_ATS_BUFF_SIZE; - SC_AppData.AppendWordCount = SC_ATS_BUFF_SIZE; + UT_CmdBuf.AppendAtsCmd.Payload.AtsNum = SC_AtsIndexToNum(AtsIndex); + SC_OperData.HkPacket.Payload.AppendEntryCount = 1; + AtsInfoPtr->NumberOfCommands = 1; + AtsInfoPtr->AtsSize = SC_ATS_BUFF_SIZE; + SC_AppData.AppendWordCount = SC_ATS_BUFF_SIZE; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_AppendAtsCmd(&UT_CmdBuf.AppendAtsCmd)); diff --git a/unit-test/sc_cmds_tests.c b/unit-test/sc_cmds_tests.c index e7751e1..3a8d196 100644 --- a/unit-test/sc_cmds_tests.c +++ b/unit-test/sc_cmds_tests.c @@ -61,12 +61,17 @@ int32 Ut_SC_UpdateNextTimeHook(void *UserObj, int32 StubRetcode, uint32 CallCoun void SC_ProcessAtpCmd_Test_SwitchCmd(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; @@ -75,8 +80,8 @@ void SC_ProcessAtpCmd_Test_SwitchCmd(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_AppData.EnableHeaderUpdate = true; @@ -98,20 +103,23 @@ void SC_ProcessAtpCmd_Test_SwitchCmd(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 0"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EXECUTED); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessAtpCmd_Test_NonSwitchCmd(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; @@ -120,8 +128,8 @@ void SC_ProcessAtpCmd_Test_NonSwitchCmd(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_AppData.EnableHeaderUpdate = true; @@ -143,20 +151,23 @@ void SC_ProcessAtpCmd_Test_NonSwitchCmd(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 0"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EXECUTED); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessAtpCmd_Test_InlineSwitchError(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; @@ -165,8 +176,8 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Set return value for CFE_TIME_Compare to make SC_CompareAbsTime return false, to satisfy first if-statement of * SC_ProcessAtpCmd, and for all other calls to CFE_TIME_Compare called from subfunctions reached by this test */ @@ -189,8 +200,7 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_DISTRIB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, 1); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); @@ -199,12 +209,17 @@ void SC_ProcessAtpCmd_Test_InlineSwitchError(void) void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -215,8 +230,8 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_AppData.EnableHeaderUpdate = true; @@ -235,8 +250,7 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_DISTRIB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); @@ -247,12 +261,17 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsA(void) void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_NOOP_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -263,8 +282,8 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[1][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_AppData.EnableHeaderUpdate = true; @@ -283,8 +302,7 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_DISTRIB, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_DISTRIB"); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_DISTRIB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); @@ -295,13 +313,18 @@ void SC_ProcessAtpCmd_Test_SBErrorAtsB(void) void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - bool ChecksumValid; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -312,8 +335,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = false; @@ -338,9 +361,7 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_CHECKSUM, - "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_CHECKSUM); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_CHKSUM_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); @@ -348,13 +369,18 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsA(void) void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - bool ChecksumValid; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -365,8 +391,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[1][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = false; @@ -391,9 +417,7 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM, - "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_CHECKSUM); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_CHKSUM_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); @@ -401,13 +425,18 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsB(void) void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - bool ChecksumValid; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + bool ChecksumValid; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -418,8 +447,8 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = SC_AtsCont_TRUE; @@ -444,31 +473,34 @@ void SC_ProcessAtpCmd_Test_ChecksumFailedAtsAContinue(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_FAILED_CHECKSUM, - "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_FAILED_CHECKSUM"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_FAILED_CHECKSUM); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_CHKSUM_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; - Entry->CmdNumber = SC_COMMAND_NUM_C(3); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); - SC_AppData.NextCmdTime[SC_Process_ATP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_ATP; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); + Entry->CmdNumber = SC_COMMAND_NUM_C(3); + SC_AppData.NextCmdTime[SC_Process_ATP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_ATP; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAtpCmd()); @@ -478,9 +510,7 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSA); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_SKIPPED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_SKIPPED); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_MSMTCH_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); @@ -488,10 +518,15 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsA(void) void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(3); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -502,8 +537,8 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSB); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[1][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[1][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAtpCmd()); @@ -513,9 +548,7 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdErrCtr == 1"); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrSeq, SC_AtsId_ATSB); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastAtsErrCmd, 1); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_SKIPPED, - "SC_OperData.AtsCmdStatusTblAddr[1][0] == SC_Status_SKIPPED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_SKIPPED); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ATS_MSMTCH_ERR_EID); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[1].EventID, SC_ATS_ABT_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 2); @@ -523,10 +556,12 @@ void SC_ProcessAtpCmd_Test_CmdNumberMismatchAtsB(void) void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -537,7 +572,7 @@ void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAtpCmd()); @@ -553,10 +588,13 @@ void SC_ProcessAtpCmd_Test_CmdNotLoaded(void) void SC_ProcessAtpCmd_Test_CompareAbsTime(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -567,7 +605,7 @@ void SC_ProcessAtpCmd_Test_CompareAbsTime(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); @@ -582,10 +620,12 @@ void SC_ProcessAtpCmd_Test_CompareAbsTime(void) void SC_ProcessAtpCmd_Test_NextProcNumber(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -595,8 +635,7 @@ void SC_ProcessAtpCmd_Test_NextProcNumber(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAtpCmd()); @@ -609,10 +648,12 @@ void SC_ProcessAtpCmd_Test_NextProcNumber(void) void SC_ProcessAtpCmd_Test_AtpState(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -623,7 +664,7 @@ void SC_ProcessAtpCmd_Test_AtpState(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(SC_AtsId_ATSA); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessAtpCmd()); @@ -636,12 +677,17 @@ void SC_ProcessAtpCmd_Test_AtpState(void) void SC_ProcessAtpCmd_Test_CmdMid(void) { - SC_AtsEntryHeader_t *Entry; - CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + CFE_SB_MsgId_t TestMsgId = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t FcnCode = SC_SWITCH_ATS_CC; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_ATP; @@ -650,8 +696,8 @@ void SC_ProcessAtpCmd_Test_CmdMid(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; SC_AppData.EnableHeaderUpdate = true; @@ -672,21 +718,22 @@ void SC_ProcessAtpCmd_Test_CmdMid(void) /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.AtsCmdCtr == 1, "SC_OperData.HkPacket.Payload.AtsCmdCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED, - "SC_OperData.AtsCmdStatusTblAddr[0][0] == SC_Status_EXECUTED"); - + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EXECUTED); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessRtpCommand_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = true; @@ -697,21 +744,24 @@ void SC_ProcessRtpCommand_Test_Nominal(void) UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdCtr == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 0, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 0"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdCtr == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 0, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 0"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 1); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdErrCtr, 0); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = true; @@ -725,8 +775,8 @@ void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.RtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdErrCtr, 1); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrSeq, 1); SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, 0); @@ -736,14 +786,17 @@ void SC_ProcessRtpCommand_Test_BadSoftwareBusReturn(void) void SC_ProcessRtpCommand_Test_BadChecksum(void) { - bool ChecksumValid; - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + bool ChecksumValid; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; SC_AppData.EnableHeaderUpdate = false; @@ -758,8 +811,8 @@ void SC_ProcessRtpCommand_Test_BadChecksum(void) UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdCtr == 0, "SC_OperData.HkPacket.Payload.RtsCmdCtr == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); UtAssert_True(SC_OperData.NumCmdsSec == 1, "SC_OperData.NumCmdsSec == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[0].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdErrCtr, 1); SC_Assert_ID_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrSeq, 1); SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, 0); @@ -769,13 +822,16 @@ void SC_ProcessRtpCommand_Test_BadChecksum(void) void SC_ProcessRtpCommand_Test_NextCmdTime(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 1; - SC_AppData.CurrentTime = 0; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 1; + SC_AppData.CurrentTime = 0; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -786,13 +842,16 @@ void SC_ProcessRtpCommand_Test_NextCmdTime(void) void SC_ProcessRtpCommand_Test_ProcNumber(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_NONE; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_NONE; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -831,13 +890,16 @@ void SC_ProcessRtpCommand_Test_RtsNumHigh(void) void SC_ProcessRtpCommand_Test_RtsStatus(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EMPTY; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EMPTY; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_ProcessRtpCommand()); @@ -848,9 +910,11 @@ void SC_ProcessRtpCommand_Test_RtsStatus(void) void SC_SendHkPacket_Test(void) { - uint8 i; - int32 LastRtsHkIndex = 0; - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + uint8 i; + int32 LastRtsHkIndex = 0; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_RtsInfoEntry_t *RtsInfoPtr; + SC_AtsInfoTable_t *AtsInfoPtr; SC_OperData.HkPacket.Payload.CmdErrCtr = 1; SC_OperData.HkPacket.Payload.CmdCtr = 2; @@ -868,8 +932,6 @@ void SC_SendHkPacket_Test(void) SC_OperData.HkPacket.Payload.AppendEntryCount = 14; SC_AppData.AppendWordCount = 15; SC_OperData.HkPacket.Payload.AppendLoadCount = 16; - SC_OperData.AtsInfoTblAddr[0].AtsSize = 0; - SC_OperData.AtsInfoTblAddr[1].AtsSize = 0; SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(17); SC_OperData.AtsCtrlBlckAddr->AtpState = (SC_Status_Enum_t)18; SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(19); @@ -878,16 +940,27 @@ void SC_SendHkPacket_Test(void) SC_AppData.NextCmdTime[1] = 0; SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 20; SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(21); - SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = 1; + SC_OperData.HkPacket.Payload.ContinueAtsOnFailureFlag = SC_AtsCont_TRUE; + + for (i = 0; i < SC_NUMBER_OF_ATS - 1; i++) + { + AtsInfoPtr = SC_GetAtsInfoObject(SC_ATS_IDX_C(i)); + + AtsInfoPtr->AtsSize = 0; + } for (i = 0; i < SC_NUMBER_OF_RTS - 1; i++) { - SC_OperData.RtsInfoTblAddr[i].DisabledFlag = true; - SC_OperData.RtsInfoTblAddr[i].RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr = SC_GetRtsInfoObject(SC_RTS_IDX_C(i)); + + RtsInfoPtr->DisabledFlag = true; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; } - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = 0; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_EMPTY; LastRtsHkIndex = sizeof(SC_OperData.HkPacket.Payload.RtsExecutingStatus) / sizeof(SC_OperData.HkPacket.Payload.RtsExecutingStatus[0]) - @@ -916,15 +989,13 @@ void SC_SendHkPacket_Test(void) UtAssert_True(SC_OperData.HkPacket.Payload.AppendLoadCount == 16, "SC_OperData.HkPacket.Payload.AppendLoadCount == 16"); UtAssert_True(SC_OperData.HkPacket.Payload.AtpFreeBytes[0] == - (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[0].AtsSize * SC_BYTES_IN_WORD), + (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - (SC_GetAtsInfoObject(0)->AtsSize * SC_BYTES_IN_WORD), "SC_OperData.HkPacket.Payload.AtpFreeBytes[0] == (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD)"); UtAssert_True(SC_OperData.HkPacket.Payload.AtpFreeBytes[1] == - (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - - (SC_OperData.AtsInfoTblAddr[1].AtsSize * SC_BYTES_IN_WORD), + (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD) - (SC_GetAtsInfoObject(1)->AtsSize * SC_BYTES_IN_WORD), "SC_OperData.HkPacket.Payload.AtpFreeBytes[1] == (SC_ATS_BUFF_SIZE32 * SC_BYTES_IN_WORD)"); UtAssert_UINT8_EQ(SC_OperData.HkPacket.Payload.CurrAtsId, 17); - UtAssert_True(SC_OperData.HkPacket.Payload.AtpState == 18, "SC_OperData.HkPacket.Payload.AtpState == 18"); + SC_Assert_CmdStatus(SC_OperData.HkPacket.Payload.AtpState, 18); UtAssert_UINT32_EQ(SC_OperData.HkPacket.Payload.AtpCmdNumber, 19); UtAssert_True(SC_OperData.HkPacket.Payload.SwitchPendFlag == 0, "SC_OperData.HkPacket.Payload.SwitchPendFlag == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.NextAtsTime == 0, "SC_OperData.HkPacket.Payload.NextAtsTime == 0"); @@ -963,7 +1034,10 @@ void SC_ProcessRequest_Test_HkMID(void) void SC_ProcessRequest_Test_HkMIDAutoStartRts(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); SC_AppData.AutoStartRTS = SC_RtsIndexToNum(RtsIndex); @@ -972,25 +1046,28 @@ void SC_ProcessRequest_Test_HkMIDAutoStartRts(void) /* Verify results */ SC_Assert_ID_VALUE(SC_AppData.AutoStartRTS, 0); - UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag); + UtAssert_BOOL_FALSE(RtsInfoPtr->DisabledFlag); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessRequest_Test_HkMIDAutoStartRtsLoaded(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); SC_AppData.AutoStartRTS = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_SendHkCmd(&UT_CmdBuf.SendHkCmd)); /* Verify results */ SC_Assert_ID_VALUE(SC_AppData.AutoStartRTS, 0); - UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[SC_AppData.AutoStartRTS].DisabledFlag); + UtAssert_BOOL_FALSE(RtsInfoPtr->DisabledFlag); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } @@ -1044,8 +1121,14 @@ void SC_ProcessRequest_Test_OneHzWakeupAtpNotExecutionTime(void) void SC_ProcessRequest_Test_OneHzWakeupRtpExecutionTime(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); /* required to exit processing loop after 2 iterations */ /* second iteration tests "IsThereAnotherCommandToExecute" */ @@ -1053,7 +1136,7 @@ void SC_ProcessRequest_Test_OneHzWakeupRtpExecutionTime(void) SC_CMDS_TEST_SC_UpdateNextTimeHook_RunCount = 0; UT_SetHookFunction(UT_KEY(SC_UpdateNextTime), Ut_SC_UpdateNextTimeHook, NULL); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextProcNumber = SC_Process_RTP; @@ -1064,8 +1147,8 @@ void SC_ProcessRequest_Test_OneHzWakeupRtpExecutionTime(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_OneHzWakeupCmd(&UT_CmdBuf.OneHzWakeupCmd)); @@ -1212,7 +1295,7 @@ void SC_ProcessCommand_Test_TableManageAtsTableNominal(void) SC_AtsEntryHeader_t *Entry; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; @@ -1246,7 +1329,7 @@ void SC_ProcessCommand_Test_TableManageAtsTableID(void) SC_AtsEntryHeader_t *Entry; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(0); /* test TableID >= SC_TBL_ID_ATS_0 */ @@ -1278,7 +1361,7 @@ void SC_ProcessCommand_Test_TableManageAtsTableGetAddressNeverLoaded(void) SC_AtsEntryHeader_t *Entry; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; @@ -1303,7 +1386,7 @@ void SC_ProcessCommand_Test_TableManageAtsTableGetAddressSuccess(void) SC_AtsEntryHeader_t *Entry; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[AtsIndex][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(0); UT_CmdBuf.ManageTableCmd.Payload.Parameter = SC_TBL_ID_ATS_0; diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index 39fa973..34a5b82 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -41,6 +41,9 @@ #define UT_SC_NOMINAL_CMD_SIZE (SC_PACKET_MAX_SIZE / 2) +static const SC_SeqIndex_t UT_SEQ_INDEX_0 = SC_IDX_FROM_UINT(0); +static const SC_SeqIndex_t UT_SEQ_INDEX_1 = SC_IDX_FROM_UINT(1); + /* * Function Definitions */ @@ -284,7 +287,15 @@ SC_RtsEntryHeader_t *UT_SC_SetupRtsTable(SC_RtsIndex_t RtsIndex, CFE_SB_MsgId_t void SC_LoadAts_Test_Nominal(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, sizeof(SC_NoopCmd_t)); @@ -292,15 +303,23 @@ void SC_LoadAts_Test_Nominal(void) SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], 0); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 1); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* Set up -- Modify the final entry so it would go off the end of the table */ UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32 + 1, NULL); @@ -308,67 +327,99 @@ void SC_LoadAts_Test_CmdRunOffEndOfBuffer(void) /* Execute the function being tested */ SC_LoadAts(AtsIndex); - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_CmdLengthInvalid(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MAX_SIZE + 1); /* Execute the function being tested */ SC_LoadAts(AtsIndex); - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_CmdLengthZero(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, SC_PACKET_MIN_SIZE - 1); /* Execute the function being tested */ SC_LoadAts(AtsIndex); - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_CmdNumberInvalid(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, SC_MAX_ATS_CMDS * 2, UT_SC_NOMINAL_CMD_SIZE); /* Execute the function being tested */ SC_LoadAts(AtsIndex); - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_AtsBufferTooSmall(void) { - SC_AtsEntryHeader_t *LastValidEntry; - void * TailPtr; - SC_AtsEntryHeader_t *InvalidEntry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * LastValidEntry; + void * TailPtr; + SC_AtsEntryHeader_t * InvalidEntry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* Set up -- Modify the final entry so it would go off the end of the table */ LastValidEntry = @@ -386,32 +437,48 @@ void SC_LoadAts_Test_AtsBufferTooSmall(void) SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_AtsEmpty(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* Execute the function being tested */ SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands); - UtAssert_ZERO(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_ZERO(AtsInfoPtr->NumberOfCommands); + UtAssert_ZERO(AtsInfoPtr->AtsSize); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_LoadExactlyBufferLength(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* Set up -- Modify the final entry so it exactly takes up the remainder of the buffer */ Entry = UT_SC_SetupAtsTable(AtsIndex, UT_SC_NOMINAL_CMD_SIZE, SC_ATS_BUFF_SIZE32, NULL); @@ -420,17 +487,25 @@ void SC_LoadAts_Test_LoadExactlyBufferLength(void) SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_INT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], 0); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, Entry->CmdNumber); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, SC_ATS_BUFF_SIZE32); + SC_Assert_IDX_VALUE(CmdOffsetRec->Offset, 0); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_ID_VALUE(Entry->CmdNumber, AtsInfoPtr->NumberOfCommands); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, SC_ATS_BUFF_SIZE32); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_LoadAts_Test_CmdNotEmpty(void) { - void * TailPtr; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); /* Set up a buffer that has a duplicate command number entry */ TailPtr = UT_SC_GetAtsTable(AtsIndex); @@ -441,10 +516,10 @@ void SC_LoadAts_Test_CmdNotEmpty(void) SC_LoadAts(AtsIndex); /* Verify results */ - UtAssert_UINT32_EQ(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0], SC_ERROR); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_EMPTY); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 0); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 0); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_INVALID); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_EMPTY); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 0); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 0); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } @@ -477,11 +552,16 @@ void SC_BuildTimeIndexTable_Test_InvalidIndex(void) void SC_Insert_Test(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - uint8 ListLength = 1; - SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsCmdNumRecord_t *AtsCmdNumRec0; + SC_AtsCmdNumRecord_t *AtsCmdNumRec1; + + AtsCmdNumRec0 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_0); + AtsCmdNumRec1 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_1); - SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; + AtsCmdNumRec0->CmdNum = SC_CommandIndexToNum(NewCmdIndex); /* Execute the function being tested */ SC_Insert(AtsIndex, NewCmdIndex, ListLength); @@ -489,21 +569,26 @@ void SC_Insert_Test(void) /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, AtsCmdNumRec0->CmdNum); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, SC_CommandIndexToNum(NewCmdIndex)); } void SC_Insert_Test_MiddleOfList(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - uint8 ListLength = 1; - SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsCmdNumRecord_t *AtsCmdNumRec0; + SC_AtsCmdNumRecord_t *AtsCmdNumRec1; + + AtsCmdNumRec0 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_0); + AtsCmdNumRec1 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_1); /* Set to cause SC_CompareAbsTime to return false, in order to reach block starting with "new cmd will execute at same time or after this list entry" */ UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, false); - SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; + AtsCmdNumRec0->CmdNum = SC_CommandIndexToNum(NewCmdIndex); /* Execute the function being tested */ SC_Insert(AtsIndex, NewCmdIndex, ListLength); @@ -511,21 +596,26 @@ void SC_Insert_Test_MiddleOfList(void) /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, AtsCmdNumRec0->CmdNum); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, SC_CommandIndexToNum(NewCmdIndex)); } void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - uint8 ListLength = 1; - SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + uint8 ListLength = 1; + SC_CommandIndex_t NewCmdIndex = SC_COMMAND_IDX_C(0); + SC_AtsCmdNumRecord_t *AtsCmdNumRec0; + SC_AtsCmdNumRecord_t *AtsCmdNumRec1; + + AtsCmdNumRec0 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_0); + AtsCmdNumRec1 = SC_GetAtsCommandNumAtSeq(AtsIndex, UT_SEQ_INDEX_1); /* Set to cause SC_CompareAbsTime to return false, in order to reach block starting with "new cmd will execute at same time or after this list entry" */ UT_SetDeferredRetcode(UT_KEY(SC_CompareAbsTime), 1, true); - SC_AppData.AtsTimeIndexBuffer[AtsIndex][0] = 1; + AtsCmdNumRec0->CmdNum = SC_CommandIndexToNum(NewCmdIndex); /* Execute the function being tested */ SC_Insert(AtsIndex, NewCmdIndex, ListLength); @@ -533,8 +623,8 @@ void SC_Insert_Test_MiddleOfListCompareAbsTimeTrue(void) /* Verify results */ UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], SC_AppData.AtsTimeIndexBuffer[AtsIndex][0]); - UtAssert_UINT16_EQ(SC_AppData.AtsTimeIndexBuffer[AtsIndex][1], NewCmdIndex + 1); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, AtsCmdNumRec0->CmdNum); + SC_Assert_ID_EQ(AtsCmdNumRec1->CmdNum, SC_CommandIndexToNum(NewCmdIndex)); } void SC_Insert_Test_InvalidIndex(void) @@ -950,8 +1040,16 @@ void SC_UpdateAppend_Test_CmdNumberTooHigh(void) void SC_ProcessAppend_Test(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -971,19 +1069,26 @@ void SC_ProcessAppend_Test(void) SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); - UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 1); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 1); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_CmdStatus(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessAppend_Test_CmdLoaded(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -993,27 +1098,35 @@ void SC_ProcessAppend_Test_CmdLoaded(void) SC_AppData.AppendWordCount = 1; SC_OperData.HkPacket.Payload.AppendEntryCount = 1; - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + StatusEntryPtr->Status = SC_Status_LOADED; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); /* Execute the function being tested */ SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 0); - UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 1); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 0); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_CmdStatus(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessAppend_Test_NotExecuting(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -1030,19 +1143,27 @@ void SC_ProcessAppend_Test_NotExecuting(void) SC_ProcessAppend(AtsIndex); /* Verify results */ - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); - UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_IDLE); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 1); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 1); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_CmdStatus(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_IDLE); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } void SC_ProcessAppend_Test_AtsNum(void) { - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); - void * TailPtr; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); @@ -1059,11 +1180,11 @@ void SC_ProcessAppend_Test_AtsNum(void) UtAssert_VOIDCALL(SC_ProcessAppend(AtsIndex)); /* Verify results */ - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].AtsSize, 1); - UtAssert_UINT32_EQ(SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands, 1); - UtAssert_ZERO(SC_AppData.AtsCmdIndexBuffer[AtsIndex][0]); - UtAssert_UINT32_EQ(SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0], SC_Status_LOADED); - UtAssert_UINT32_EQ(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 1); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 1); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_CmdStatus(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } diff --git a/unit-test/sc_rtsrq_tests.c b/unit-test/sc_rtsrq_tests.c index 3050fbf..5d30161 100644 --- a/unit-test/sc_rtsrq_tests.c +++ b/unit-test/sc_rtsrq_tests.c @@ -48,14 +48,17 @@ void SC_StartRtsCmd_Test_Nominal(void) SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; + SC_RtsInfoEntry_t * RtsInfoPtr; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; /* Set message size in order to satisfy if-statement after comment "Make sure the command is big enough, but not too * big" */ @@ -67,14 +70,11 @@ void SC_StartRtsCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1, "SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_EXECUTING, "RtsInfoPtr->RtsStatus == SC_Status_EXECUTING"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_True(RtsInfoPtr->CmdErrCtr == 0, "RtsInfoPtr->CmdErrCtr == 0"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->UseCtr, 1); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsActiveCtr == 1, "SC_OperData.HkPacket.Payload.RtsActiveCtr == 1"); @@ -89,17 +89,19 @@ void SC_StartRtsCmd_Test_StartRtsNoEvents(void) SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex; size_t MsgSize; + SC_RtsInfoEntry_t * RtsInfoPtr; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS); - RtsIndex = SC_RtsNumToIndex(UT_CmdBuf.StartRtsCmd.Payload.RtsNum); + RtsIndex = SC_RtsNumToIndex(UT_CmdBuf.StartRtsCmd.Payload.RtsNum); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; + RtsInfoPtr->UseCtr = 0; /* Set message size in order to satisfy if-statement after comment "Make sure the command is big enough, but not too * big" */ @@ -111,14 +113,11 @@ void SC_StartRtsCmd_Test_StartRtsNoEvents(void) UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1, "SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_EXECUTING, "RtsInfoPtr->RtsStatus == SC_Status_EXECUTING"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_True(RtsInfoPtr->CmdErrCtr == 0, "RtsInfoPtr->CmdErrCtr == 0"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->UseCtr, 1); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsActiveCtr == 1, "SC_OperData.HkPacket.Payload.RtsActiveCtr == 1"); @@ -142,14 +141,17 @@ void SC_StartRtsCmd_Test_InvalidCommandLength1(void) SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; + SC_RtsInfoEntry_t * RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; /* Set message size in order to satisfy if-statement after comment "Make sure the command is big enough, but not too * big" */ @@ -170,14 +172,17 @@ void SC_StartRtsCmd_Test_InvalidCommandLength2(void) SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); size_t MsgSize; + SC_RtsInfoEntry_t * RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; /* Set message size in order to satisfy if-statement after comment "Make sure the command is big enough, but not too * big" */ @@ -197,14 +202,17 @@ void SC_StartRtsCmd_Test_RtsNotLoadedOrInUse(void) { SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t * RtsInfoPtr; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_IDLE; + RtsInfoPtr->DisabledFlag = false; + RtsInfoPtr->RtsStatus = SC_Status_IDLE; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); @@ -218,14 +226,17 @@ void SC_StartRtsCmd_Test_RtsDisabled(void) { SC_RtsEntryHeader_t *Entry; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t * RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[RtsIndex][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->TimeTag = 0; UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; + RtsInfoPtr->DisabledFlag = true; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsCmd(&UT_CmdBuf.StartRtsCmd)); @@ -261,10 +272,13 @@ void SC_StartRtsCmd_Test_InvalidRtsIdZero(void) void SC_StartRtsGrpCmd_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_LOADED; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; + RtsInfoPtr->RtsStatus = SC_Status_LOADED; + RtsInfoPtr->UseCtr = 0; UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); @@ -273,14 +287,11 @@ void SC_StartRtsGrpCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1, "SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 1"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_EXECUTING, "RtsInfoPtr->RtsStatus == SC_Status_EXECUTING"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_True(RtsInfoPtr->CmdErrCtr == 0, "RtsInfoPtr->CmdErrCtr == 0"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->UseCtr, 1); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 1"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsActiveCtr == 1, "SC_OperData.HkPacket.Payload.RtsActiveCtr == 1"); @@ -382,27 +393,28 @@ void SC_StartRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_StartRtsGrpCmd_Test_DisabledFlag(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = SC_ENTRY_OFFSET_FIRST; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); - UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->DisabledFlag = true; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->UseCtr = 0; + RtsInfoPtr->CmdCtr = 0; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST; + + UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); + UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 0"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_True(RtsInfoPtr->CmdErrCtr == 0, "RtsInfoPtr->CmdErrCtr == 0"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->UseCtr, 0); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsActiveCtr == 0, "SC_OperData.HkPacket.Payload.RtsActiveCtr == 0"); @@ -417,12 +429,15 @@ void SC_StartRtsGrpCmd_Test_DisabledFlag(void) void SC_StartRtsGrpCmd_Test_RtsStatus(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr = 0; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr = SC_ENTRY_OFFSET_FIRST; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->UseCtr = 0; + RtsInfoPtr->CmdCtr = 0; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_FIRST; UT_CmdBuf.StartRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); UT_CmdBuf.StartRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); @@ -431,14 +446,11 @@ void SC_StartRtsGrpCmd_Test_RtsStatus(void) UtAssert_VOIDCALL(SC_StartRtsGrpCmd(&UT_CmdBuf.StartRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_EXECUTING"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].CmdErrCtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr == 0"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 0, "SC_OperData.RtsInfoTblAddr[RtsIndex].UseCtr == 0"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_EXECUTING, "RtsInfoPtr->RtsStatus == SC_Status_EXECUTING"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdCtr, 0); + UtAssert_True(RtsInfoPtr->CmdErrCtr == 0, "RtsInfoPtr->CmdErrCtr == 0"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, 0); + UtAssert_UINT32_EQ(RtsInfoPtr->UseCtr, 0); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0"); UtAssert_True(SC_OperData.HkPacket.Payload.RtsActiveCtr == 0, "SC_OperData.HkPacket.Payload.RtsActiveCtr == 0"); @@ -511,9 +523,12 @@ void SC_StopRtsGrpCmd_Test_Error(void) void SC_StopRtsGrpCmd_Test_NotExecuting(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; UT_CmdBuf.StopRtsGrpCmd.Payload.FirstRtsNum = SC_RTS_NUM_C(1); UT_CmdBuf.StopRtsGrpCmd.Payload.LastRtsNum = SC_RTS_NUM_C(1); @@ -605,7 +620,10 @@ void SC_StopRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_DisableRtsCmd_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); UT_CmdBuf.DisableRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); @@ -613,8 +631,7 @@ void SC_DisableRtsCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_DisableRtsCmd(&UT_CmdBuf.DisableRtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true"); + UtAssert_True(RtsInfoPtr->DisabledFlag == true, "RtsInfoPtr->DisabledFlag == true"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_DISABLE_RTS_DEB_EID); @@ -637,7 +654,10 @@ void SC_DisableRtsCmd_Test_InvalidRtsID(void) void SC_DisableRtsGrpCmd_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); @@ -646,8 +666,7 @@ void SC_DisableRtsGrpCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true"); + UtAssert_True(RtsInfoPtr->DisabledFlag == true, "RtsInfoPtr->DisabledFlag == true"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_DISRTSGRP_CMD_INF_EID); @@ -746,9 +765,12 @@ void SC_DisableRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_DisableRtsGrpCmd_Test_DisabledFlag(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag = true; + RtsInfoPtr->DisabledFlag = true; UT_CmdBuf.DisableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); UT_CmdBuf.DisableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); @@ -757,8 +779,7 @@ void SC_DisableRtsGrpCmd_Test_DisabledFlag(void) UtAssert_VOIDCALL(SC_DisableRtsGrpCmd(&UT_CmdBuf.DisableRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == true"); + UtAssert_True(RtsInfoPtr->DisabledFlag == true, "RtsInfoPtr->DisabledFlag == true"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_DISRTSGRP_CMD_INF_EID); @@ -767,7 +788,10 @@ void SC_DisableRtsGrpCmd_Test_DisabledFlag(void) void SC_EnableRtsCmd_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); UT_CmdBuf.EnableRtsCmd.Payload.RtsNum = SC_RtsIndexToNum(RtsIndex); @@ -775,8 +799,7 @@ void SC_EnableRtsCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_EnableRtsCmd(&UT_CmdBuf.EnableRtsCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false"); + UtAssert_True(RtsInfoPtr->DisabledFlag == false, "RtsInfoPtr->DisabledFlag == false"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ENABLE_RTS_DEB_EID); @@ -813,7 +836,10 @@ void SC_EnableRtsCmd_Test_InvalidRtsIDZero(void) void SC_EnableRtsGrpCmd_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); /* RtsNum - 1 */ + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex); UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex); @@ -822,8 +848,7 @@ void SC_EnableRtsGrpCmd_Test_Nominal(void) UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false, - "SC_OperData.RtsInfoTblAddr[RtsIndex].DisabledFlag == false"); + UtAssert_True(RtsInfoPtr->DisabledFlag == false, "RtsInfoPtr->DisabledFlag == false"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ENARTSGRP_CMD_INF_EID); @@ -922,19 +947,24 @@ void SC_EnableRtsGrpCmd_Test_FirstLastRtsIndex(void) void SC_EnableRtsGrpCmd_Test_DisabledFlag(void) { - SC_RtsIndex_t RtsIndex0 = SC_RTS_IDX_C(0); - SC_RtsIndex_t RtsIndex1 = SC_RTS_IDX_C(1); + SC_RtsIndex_t RtsIndex0 = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex1 = SC_RTS_IDX_C(1); + SC_RtsInfoEntry_t *RtsInfoPtr0; + SC_RtsInfoEntry_t *RtsInfoPtr1; + + RtsInfoPtr0 = SC_GetRtsInfoObject(RtsIndex0); + RtsInfoPtr1 = SC_GetRtsInfoObject(RtsIndex1); - SC_OperData.RtsInfoTblAddr[RtsIndex0].DisabledFlag = false; - SC_OperData.RtsInfoTblAddr[RtsIndex1].DisabledFlag = true; - UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex0); - UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex1); + RtsInfoPtr0->DisabledFlag = false; + RtsInfoPtr1->DisabledFlag = true; + UT_CmdBuf.EnableRtsGrpCmd.Payload.FirstRtsNum = SC_RtsIndexToNum(RtsIndex0); + UT_CmdBuf.EnableRtsGrpCmd.Payload.LastRtsNum = SC_RtsIndexToNum(RtsIndex1); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_EnableRtsGrpCmd(&UT_CmdBuf.EnableRtsGrpCmd)); /* Verify results */ - UtAssert_BOOL_FALSE(SC_OperData.RtsInfoTblAddr[RtsIndex0].DisabledFlag); + UtAssert_True(RtsInfoPtr0->DisabledFlag == false, "RtsInfoPtr->DisabledFlag == false"); UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_ENARTSGRP_CMD_INF_EID); @@ -943,19 +973,20 @@ void SC_EnableRtsGrpCmd_Test_DisabledFlag(void) void SC_KillRts_Test(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 1; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_KillRts(RtsIndex)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime == SC_MAX_TIME, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime == SC_MAX_TIME"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_LOADED, "RtsInfoPtr->RtsStatus == SC_Status_LOADED"); + UtAssert_True(RtsInfoPtr->NextCommandTime == SC_MAX_TIME, "RtsInfoPtr->NextCommandTime == SC_MAX_TIME"); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0"); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -963,19 +994,20 @@ void SC_KillRts_Test(void) void SC_KillRts_Test_NoActiveRts(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 0; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + SC_OperData.RtsCtrlBlckAddr->NumRtsActive = 0; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_KillRts(RtsIndex)); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED, - "SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus == SC_Status_LOADED"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime == SC_MAX_TIME, - "SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime == SC_MAX_TIME"); + UtAssert_True(RtsInfoPtr->RtsStatus == SC_Status_LOADED, "RtsInfoPtr->RtsStatus == SC_Status_LOADED"); + UtAssert_True(RtsInfoPtr->NextCommandTime == SC_MAX_TIME, "RtsInfoPtr->NextCommandTime == SC_MAX_TIME"); UtAssert_True(SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0, "SC_OperData.RtsCtrlBlckAddr->NumRtsActive == 0"); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); diff --git a/unit-test/sc_state_tests.c b/unit-test/sc_state_tests.c index b32ebd6..962fcde 100644 --- a/unit-test/sc_state_tests.c +++ b/unit-test/sc_state_tests.c @@ -56,10 +56,13 @@ int32 SC_STATE_TEST_CFE_SB_GetTotalMsgLengthHook(void *UserObj, int32 StubRetcod void SC_GetNextRtsTime_Test_Nominal(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = SC_MAX_TIME; + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->NextCommandTime = SC_MAX_TIME; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsTime()); @@ -73,11 +76,14 @@ void SC_GetNextRtsTime_Test_Nominal(void) void SC_GetNextRtsTime_Test_InvalidRtsNum(void) { - uint8 i; + uint8 i; + SC_RtsInfoEntry_t *RtsInfoPtr; for (i = 0; i < SC_NUMBER_OF_RTS; i++) { - SC_OperData.RtsInfoTblAddr[i].RtsStatus = (SC_Status_Enum_t)(-1); + RtsInfoPtr = SC_GetRtsInfoObject(SC_RTS_IDX_C(i)); + + RtsInfoPtr->RtsStatus = (SC_Status_Enum_t)(-1); } /* Execute the function being tested */ @@ -93,11 +99,17 @@ void SC_GetNextRtsTime_Test_InvalidRtsNum(void) void SC_GetNextRtsTime_Test_RtsPriority(void) { - SC_OperData.RtsInfoTblAddr[0].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[0].NextCommandTime = SC_MAX_TIME; + SC_RtsInfoEntry_t *RtsInfoPtr0; + SC_RtsInfoEntry_t *RtsInfoPtr1; + + RtsInfoPtr0 = SC_GetRtsInfoObject(SC_RTS_IDX_C(0)); + RtsInfoPtr1 = SC_GetRtsInfoObject(SC_RTS_IDX_C(1)); + + RtsInfoPtr0->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr0->NextCommandTime = SC_MAX_TIME; - SC_OperData.RtsInfoTblAddr[1].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[1].NextCommandTime = SC_MAX_TIME - 1; + RtsInfoPtr1->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr1->NextCommandTime = SC_MAX_TIME - 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsTime()); @@ -140,14 +152,17 @@ void SC_UpdateNextTime_Test_Atp2(void) void SC_UpdateNextTime_Test_Rtp(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(10); SC_AppData.NextCmdTime[SC_Process_RTP] = 0; SC_AppData.NextCmdTime[SC_Process_ATP] = 10; - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandTime = 1; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->NextCommandTime = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_UpdateNextTime()); @@ -160,14 +175,17 @@ void SC_UpdateNextTime_Test_Rtp(void) void SC_UpdateNextTime_Test_RtpAtpPriority(void) { - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_RtsInfoEntry_t *RtsInfoPtr; + + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); SC_AppData.NextCmdTime[SC_Process_RTP] = 0; SC_AppData.NextCmdTime[SC_Process_ATP] = 0; - SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].RtsStatus = SC_Status_EXECUTING; - SC_OperData.RtsInfoTblAddr[SC_NUMBER_OF_RTS - 1].NextCommandTime = 1; + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + RtsInfoPtr->NextCommandTime = 1; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_UpdateNextTime()); @@ -178,16 +196,21 @@ void SC_UpdateNextTime_Test_RtpAtpPriority(void) void SC_GetNextRtsCommand_Test_GetNextCommand(void) { - size_t MsgSize; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t *RtsInfoPtr; + SC_AtsInfoTable_t *AtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(1); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(1); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -202,10 +225,7 @@ void SC_GetNextRtsCommand_Test_GetNextCommand(void) UtAssert_VOIDCALL(SC_GetNextRtsCommand()); /* Verify results */ - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].NextCommandPtr == - (SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD, - "SC_OperData.RtsInfoTblAddr[0].NextCommandPtr == (SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 1) / " - "SC_BYTES_IN_WORD"); + SC_Assert_IDX_VALUE(RtsInfoPtr->NextCommandPtr, (SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } @@ -221,16 +241,21 @@ void SC_GetNextRtsCommand_Test_RtsNumZero(void) void SC_GetNextRtsCommand_Test_RtsNumMax(void) { - size_t MsgSize; - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + size_t MsgSize; + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsInfoEntry_t *RtsInfoPtr; + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + AtsInfoPtr->NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -250,14 +275,17 @@ void SC_GetNextRtsCommand_Test_RtsNumMax(void) void SC_GetNextRtsCommand_Test_RtsNumOverMax(void) { - size_t MsgSize; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsInfoTable_t *AtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS + 1); + AtsInfoPtr->NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -277,16 +305,21 @@ void SC_GetNextRtsCommand_Test_RtsNumOverMax(void) void SC_GetNextRtsCommand_Test_RtsNotExecuting(void) { - size_t MsgSize; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); - SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + size_t MsgSize; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_NUMBER_OF_RTS - 1); + SC_RtsInfoEntry_t *RtsInfoPtr; + SC_AtsInfoTable_t *AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_IDLE; - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_IDLE; + AtsInfoPtr->NumberOfCommands = 1; /* Give the packet the minimum possible size, to ensure that (CmdOffset < SC_RTS_HDR_WORDS) is met */ MsgSize = SC_PACKET_MIN_SIZE; @@ -309,16 +342,24 @@ void SC_GetNextRtsCommand_Test_RtsLengthError(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + uint32 EntryOffsetVal; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), SC_PACKET_MAX_SIZE); @@ -331,24 +372,19 @@ void SC_GetNextRtsCommand_Test_RtsLengthError(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = - (SC_RTS_BUFF_SIZE32 - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdErrCtr, 1); SC_Assert_ID_EQ(SC_OperData.HkPacket.Payload.LastRtsErrSeq, SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD), - "SC_OperData.HkPacket.Payload.LastRtsErrCmd == SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + " - "((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD)"); + EntryOffsetVal += (SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD; + SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, EntryOffsetVal); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_LNGTH_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -359,16 +395,24 @@ void SC_GetNextRtsCommand_Test_CommandLengthError(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + uint32 EntryOffsetVal; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), SC_PACKET_MAX_SIZE); @@ -381,24 +425,19 @@ void SC_GetNextRtsCommand_Test_CommandLengthError(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = - (SC_RTS_BUFF_SIZE32 - (SC_RTS_HDR_WORDS)) - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD); + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); /* Verify results */ UtAssert_True(SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1, "SC_OperData.HkPacket.Payload.RtsCmdErrCtr == 1"); - UtAssert_True(SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1, "SC_OperData.RtsInfoTblAddr[0].CmdErrCtr == 1"); + UtAssert_UINT32_EQ(RtsInfoPtr->CmdErrCtr, 1); SC_Assert_ID_EQ(SC_OperData.HkPacket.Payload.LastRtsErrSeq, SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); - UtAssert_True(SC_OperData.HkPacket.Payload.LastRtsErrCmd == - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD), - "SC_OperData.HkPacket.Payload.LastRtsErrCmd == SC_OperData.RtsInfoTblAddr[0].NextCommandPtr + " - "((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD)"); + EntryOffsetVal += (SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD; + SC_Assert_IDX_VALUE(SC_OperData.HkPacket.Payload.LastRtsErrCmd, EntryOffsetVal); UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_RTS_CMD_LNGTH_ERR_EID); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); @@ -409,16 +448,24 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLength(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + uint32 EntryOffsetVal; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS - 1); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS - 1][0]; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD) - 1; /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), SC_LAST_RTS_WITH_EVENTS - 1); @@ -431,11 +478,8 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLength(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - - 1; + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); @@ -450,16 +494,24 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLengthLastRts(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize1; size_t MsgSize2; + uint32 EntryOffsetVal; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD) - 1; /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), SC_PACKET_MIN_SIZE - 1); @@ -472,11 +524,8 @@ void SC_GetNextRtsCommand_Test_ZeroCommandLengthLastRts(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - - 1; + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); @@ -489,16 +538,24 @@ void SC_GetNextRtsCommand_Test_EndOfBuffer(void) { SC_RtsEntryHeader_t *Entry; size_t MsgSize; + uint32 EntryOffsetVal; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(0); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[0][0]; + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD) - 1; /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), 2 * SC_RTS_BUFF_SIZE); @@ -509,11 +566,8 @@ void SC_GetNextRtsCommand_Test_EndOfBuffer(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - - 1; + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); @@ -528,15 +582,23 @@ void SC_GetNextRtsCommand_Test_EndOfBufferLastRts(void) SC_RtsEntryHeader_t *Entry; size_t MsgSize; SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + uint32 EntryOffsetVal; SC_RtsIndex_t RtsIndex = SC_RTS_IDX_C(SC_LAST_RTS_WITH_EVENTS); + SC_RtsInfoEntry_t * RtsInfoPtr; + SC_AtsInfoTable_t * AtsInfoPtr; - SC_AppData.NextCmdTime[SC_Process_RTP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_RTP; - SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); - SC_OperData.RtsInfoTblAddr[RtsIndex].RtsStatus = SC_Status_EXECUTING; + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); - Entry = (SC_RtsEntryHeader_t *)&SC_OperData.RtsTblAddr[SC_LAST_RTS_WITH_EVENTS][0]; + SC_AppData.NextCmdTime[SC_Process_RTP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_RTP; + SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RtsIndexToNum(RtsIndex); + RtsInfoPtr->RtsStatus = SC_Status_EXECUTING; + + Entry = (SC_RtsEntryHeader_t *)SC_GetRtsEntryAtOffset(RtsIndex, SC_ENTRY_OFFSET_FIRST); + EntryOffsetVal = + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS - ((SC_PACKET_MIN_SIZE + SC_RTS_HEADER_SIZE + 3) / SC_BYTES_IN_WORD) - 1; /* Set to generate error message SC_RTS_LNGTH_ERR_EID */ CFE_MSG_Init((CFE_MSG_Message_t *)Entry, CFE_SB_ValueToMsgId(SC_CMD_MID), 2 * SC_RTS_BUFF_SIZE); @@ -547,11 +609,8 @@ void SC_GetNextRtsCommand_Test_EndOfBufferLastRts(void) /* Set so checksum will pass in SC_ProcessRtpCommand */ UT_SetDeferredRetcode(UT_KEY(CFE_MSG_ValidateChecksum), 1, true); - SC_OperData.AtsInfoTblAddr[AtsIndex].NumberOfCommands = 1; - - SC_OperData.RtsInfoTblAddr[0].NextCommandPtr = (SC_RTS_BUFF_SIZE - (SC_RTS_HDR_WORDS)) - - ((SC_PACKET_MAX_SIZE + SC_RTS_HEADER_SIZE + 1) / SC_BYTES_IN_WORD) - - 1; + AtsInfoPtr->NumberOfCommands = 1; + RtsInfoPtr->NextCommandPtr = SC_ENTRY_OFFSET_C(EntryOffsetVal); /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextRtsCommand()); @@ -594,32 +653,39 @@ void SC_GetNextAtsCommand_Test_Idle(void) void SC_GetNextAtsCommand_Test_GetNextCommand(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; - Entry->CmdNumber = SC_COMMAND_NUM_C(1); + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); - SC_AppData.NextCmdTime[SC_Process_ATP] = 0; - SC_AppData.CurrentTime = 1; - SC_AppData.NextProcNumber = SC_Process_ATP; - SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); + Entry->CmdNumber = SC_COMMAND_NUM_C(1); - SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); - SC_AppData.AtsTimeIndexBuffer[0][0] = 1; - SC_AppData.AtsTimeIndexBuffer[0][1] = 2; + SC_AppData.NextCmdTime[SC_Process_ATP] = 0; + SC_AppData.CurrentTime = 1; + SC_AppData.NextProcNumber = SC_Process_ATP; + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(AtsIndex); + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(0))->CmdNum = SC_COMMAND_NUM_C(1); + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum = SC_COMMAND_NUM_C(2); - SC_OperData.AtsCmdStatusTblAddr[0][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[0][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; - SC_OperData.AtsInfoTblAddr[SC_Process_ATP].NumberOfCommands = 100; + AtsInfoPtr->NumberOfCommands = 100; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextAtsCommand()); /* Verify results */ SC_Assert_IDX_VALUE(SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr, 1); - UtAssert_INT32_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, SC_AppData.AtsTimeIndexBuffer[0][1]); + SC_Assert_ID_EQ(SC_OperData.AtsCtrlBlckAddr->CmdNumber, + SC_GetAtsCommandNumAtSeq(AtsIndex, SC_SEQUENCE_IDX_C(1))->CmdNum); UtAssert_INT32_EQ(SC_AppData.NextCmdTime[SC_Process_ATP], 0); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); @@ -627,10 +693,15 @@ void SC_GetNextAtsCommand_Test_GetNextCommand(void) void SC_GetNextAtsCommand_Test_ExecutionACompleted(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -641,8 +712,8 @@ void SC_GetNextAtsCommand_Test_ExecutionACompleted(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(2); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(0); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextAtsCommand()); @@ -654,10 +725,15 @@ void SC_GetNextAtsCommand_Test_ExecutionACompleted(void) void SC_GetNextAtsCommand_Test_ExecutionBCompleted(void) { - SC_AtsEntryHeader_t *Entry; - SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsEntryHeader_t * Entry; + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); - Entry = (SC_AtsEntryHeader_t *)&SC_OperData.AtsTblAddr[0][0]; + Entry = (SC_AtsEntryHeader_t *)SC_GetAtsEntryAtOffset(AtsIndex, SC_ENTRY_OFFSET_FIRST); Entry->CmdNumber = SC_COMMAND_NUM_C(1); SC_AppData.NextCmdTime[SC_Process_ATP] = 0; @@ -668,8 +744,8 @@ void SC_GetNextAtsCommand_Test_ExecutionBCompleted(void) SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_ATS_NUM_C(1); SC_OperData.AtsCtrlBlckAddr->CmdNumber = SC_COMMAND_NUM_C(0); - SC_OperData.AtsCmdStatusTblAddr[AtsIndex][0] = SC_Status_LOADED; - SC_AppData.AtsCmdIndexBuffer[AtsIndex][0] = 0; + StatusEntryPtr->Status = SC_Status_LOADED; + CmdOffsetRec->Offset = SC_ENTRY_OFFSET_FIRST; /* Execute the function being tested */ UtAssert_VOIDCALL(SC_GetNextAtsCommand()); diff --git a/unit-test/utilities/sc_test_utils.c b/unit-test/utilities/sc_test_utils.c index 6f3bb25..19fb503 100644 --- a/unit-test/utilities/sc_test_utils.c +++ b/unit-test/utilities/sc_test_utils.c @@ -41,14 +41,14 @@ CFE_ES_WriteToSysLog_context_t context_CFE_ES_WriteToSysLog; UT_CmdBuf_t UT_CmdBuf; /* Table buffers */ -uint32 AtsTblAddr[SC_NUMBER_OF_ATS][SC_ATS_BUFF_SIZE32]; -uint32 AppendTblAddr[SC_APPEND_BUFF_SIZE32]; -uint32 RtsTblAddr[SC_NUMBER_OF_RTS][SC_RTS_BUFF_SIZE32]; -SC_AtsInfoTable_t AtsInfoTblAddr[SC_NUMBER_OF_ATS]; -SC_RtsInfoEntry_t RtsInfoTblAddr[SC_NUMBER_OF_RTS]; -SC_RtpControlBlock_t RtsCtrlBlckAddr; -SC_AtpControlBlock_t AtsCtrlBlckAddr; -SC_Status_Enum_t AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; +uint32 AtsTblAddr[SC_NUMBER_OF_ATS][SC_ATS_BUFF_SIZE32]; +uint32 AppendTblAddr[SC_APPEND_BUFF_SIZE32]; +uint32 RtsTblAddr[SC_NUMBER_OF_RTS][SC_RTS_BUFF_SIZE32]; +SC_AtsInfoTable_t AtsInfoTblAddr[SC_NUMBER_OF_ATS]; +SC_RtsInfoEntry_t RtsInfoTblAddr[SC_NUMBER_OF_RTS]; +SC_RtpControlBlock_t RtsCtrlBlckAddr; +SC_AtpControlBlock_t AtsCtrlBlckAddr; +SC_AtsCmdStatusEntry_t AtsCmdStatusTblAddr[SC_NUMBER_OF_ATS][SC_MAX_ATS_CMDS]; /* * Function Definitions diff --git a/unit-test/utilities/sc_test_utils.h b/unit-test/utilities/sc_test_utils.h index c84aa9b..f181472 100644 --- a/unit-test/utilities/sc_test_utils.h +++ b/unit-test/utilities/sc_test_utils.h @@ -102,6 +102,10 @@ extern UT_CmdBuf_t UT_CmdBuf; UtAssert_GenericUnsignedCompare(SC_IDX_AS_UINT(actual), UtAssert_Compare_EQ, (unsigned int)(ref), \ UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "IDXV", #actual, #ref) +#define SC_Assert_CmdStatus(actual, ref) \ + UtAssert_GenericUnsignedCompare((unsigned long)(actual), UtAssert_Compare_EQ, (unsigned long)(ref), \ + UtAssert_Radix_DECIMAL, __FILE__, __LINE__, "Status", #actual, #ref) + /* * Function Definitions */ From 3fd6345e02163df48c4b8235832e963a038fc0ed Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Thu, 12 Oct 2023 16:27:57 -0400 Subject: [PATCH 3/4] Fix #118, implement range checking functions Adds inline functions to do range checking, and uses them in all places where the same logic had been copied around. This reduces repetition of logic. Introduces proper data types and wrapper functions to deal with the different types of IDs and indices. --- fsw/src/sc_atsrq.c | 30 +++++++++++++---------- fsw/src/sc_cmds.c | 9 ++++--- fsw/src/sc_index_types.h | 16 +++++++++++++ fsw/src/sc_loads.c | 49 +++++++++++++++++++------------------- fsw/src/sc_rtsrq.c | 32 +++++++++++-------------- fsw/src/sc_state.c | 28 ++++++++++++---------- unit-test/sc_atsrq_tests.c | 25 +++++++++++++++---- unit-test/sc_loads_tests.c | 39 ++++++++++++++++++++++++++++++ unit-test/sc_rtsrq_tests.c | 12 +++++----- 9 files changed, 157 insertions(+), 83 deletions(-) diff --git a/fsw/src/sc_atsrq.c b/fsw/src/sc_atsrq.c index 5a6f09c..16ee96f 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -56,7 +56,7 @@ void SC_StartAtsCmd(const SC_StartAtsCmd_t *Cmd) AtsNum = Cmd->Payload.AtsNum; /* validate ATS ID */ - if ((AtsNum > 0) && (AtsNum <= SC_NUMBER_OF_ATS)) + if (SC_AtsNumIsValid(AtsNum)) { /* convert ATS ID to array index */ AtsIndex = SC_AtsNumToIndex(AtsNum); @@ -133,19 +133,22 @@ void SC_StopAtsCmd(const SC_StopAtsCmd_t *Cmd) int32 Result = SC_ERROR; /* - ** Set the temp ATS ID if it is valid + ** Check if the ATS ID is valid */ + if (SC_AtsNumIsValid(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum)) + { + Result = CFE_SUCCESS; + } + if (SC_OperData.AtsCtrlBlckAddr->CurrAtsNum == SC_AtsId_ATSA) { TempAtsChar = 'A'; - Result = CFE_SUCCESS; } else { if (SC_OperData.AtsCtrlBlckAddr->CurrAtsNum == SC_AtsId_ATSB) { TempAtsChar = 'B'; - Result = CFE_SUCCESS; } } @@ -186,7 +189,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) SC_AtsCmdStatusEntry_t * StatusEntryPtr; /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_BEGINATS_INVLD_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "Begin ATS error: invalid ATS index %d", AtsIndex); @@ -204,7 +207,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) TimeIndex = SC_SEQUENCE_IDX_FIRST; /* pointer into the time index table */ CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ - while (TimeIndex < AtsInfoPtr->NumberOfCommands) + while (SC_IDX_WITHIN_LIMIT(TimeIndex, AtsInfoPtr->NumberOfCommands)) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); @@ -223,7 +226,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) StatusEntryPtr->Status = SC_Status_SKIPPED; CmdsSkipped++; - TimeIndex++; + SC_IDX_INCREMENT(TimeIndex); } else { @@ -235,7 +238,7 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) /* ** Check to see if the whole ATS was skipped */ - if (TimeIndex == AtsInfoPtr->NumberOfCommands) + if (!SC_IDX_WITHIN_LIMIT(TimeIndex, AtsInfoPtr->NumberOfCommands)) { CFE_EVS_SendEvent(SC_ATS_SKP_ALL_ERR_EID, CFE_EVS_EventType_ERROR, "All ATS commands were skipped, ATS stopped"); @@ -312,7 +315,8 @@ void SC_SwitchAtsCmd(const SC_SwitchAtsCmd_t *Cmd) SC_AtsInfoTable_t *AtsInfoPtr; /* make sure that an ATS is running on the ATP */ - if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) + if (SC_AtsNumIsValid(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum) && + SC_OperData.AtsCtrlBlckAddr->AtpState == SC_Status_EXECUTING) { /* get the ATS to switch to */ NewAtsIndex = SC_ToggleAtsIndex(); @@ -532,7 +536,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) CmdIndex = SC_COMMAND_IDX_C(0); /* updated in loop */ NumSkipped = 0; - while (TimeIndex < AtsInfoPtr->NumberOfCommands) + while (SC_IDX_WITHIN_LIMIT(TimeIndex, AtsInfoPtr->NumberOfCommands)) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); @@ -561,7 +565,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) NumSkipped++; } - TimeIndex++; + SC_IDX_INCREMENT(TimeIndex); } else { @@ -575,7 +579,7 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) /* ** Check to see if the whole ATS was skipped */ - if (TimeIndex == AtsInfoPtr->NumberOfCommands) + if (!SC_IDX_WITHIN_LIMIT(TimeIndex, AtsInfoPtr->NumberOfCommands)) { CFE_EVS_SendEvent(SC_JUMPATS_CMD_STOPPED_ERR_EID, CFE_EVS_EventType_ERROR, "Jump Cmd: All ATS commands were skipped, ATS stopped"); @@ -667,7 +671,7 @@ void SC_AppendAtsCmd(const SC_AppendAtsCmd_t *Cmd) SC_AtsIndex_t AtsIndex; /* index (not ID) of target ATS */ SC_AtsInfoTable_t *AtsInfoPtr; - if ((Cmd->Payload.AtsNum == 0) || (Cmd->Payload.AtsNum > SC_NUMBER_OF_ATS)) + if (!SC_AtsNumIsValid(Cmd->Payload.AtsNum)) { /* invalid target ATS selection */ SC_OperData.HkPacket.Payload.CmdErrCtr++; diff --git a/fsw/src/sc_cmds.c b/fsw/src/sc_cmds.c index 0f24d9a..61e9506 100644 --- a/fsw/src/sc_cmds.c +++ b/fsw/src/sc_cmds.c @@ -313,12 +313,15 @@ void SC_ProcessRtpCommand(void) */ /* convert the RTS number so that it can be directly indexed into the table*/ RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); + if (!SC_RtsIndexIsValid(RtsIndex)) + { + return; + } RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); if ((SC_AppData.NextCmdTime[SC_AppData.NextProcNumber] <= SC_AppData.CurrentTime) && - (SC_AppData.NextProcNumber == SC_Process_RTP) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && - (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS) && (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING)) + (SC_AppData.NextProcNumber == SC_Process_RTP) && (RtsInfoPtr->RtsStatus == SC_Status_EXECUTING)) { /* ** Count the command for the rate limiter @@ -494,7 +497,7 @@ void SC_SendHkCmd(const SC_SendHkCmd_t *Cmd) SC_RtsInfoEntry_t *RtsInfoPtr; /* set during init to power on or processor reset auto-exec RTS */ - if (SC_AppData.AutoStartRTS != 0) + if (SC_RtsNumIsValid(SC_AppData.AutoStartRTS)) { RtsInfoPtr = SC_GetRtsInfoObject(SC_RtsNumToIndex(SC_AppData.AutoStartRTS)); diff --git a/fsw/src/sc_index_types.h b/fsw/src/sc_index_types.h index cfc1e63..9ddf461 100644 --- a/fsw/src/sc_index_types.h +++ b/fsw/src/sc_index_types.h @@ -393,4 +393,20 @@ static inline bool SC_RtsNumValidateRange(SC_RtsNum_t FirstRtsNum, SC_RtsNum_t L SC_RtsNumWithinRange(FirstRtsNum, LastRtsNum); } +/** + * @brief Advance the entry offset by the given amount + * + * Entries in ATS/RTS buffers are always aligned to 32-bit words. This advances the + * offset by the specified number of bytes. The given number of bytes will be converted + * to words, rounding up as needed to get to the next word boundary. + * + * @param Pos Starting entry offset + * @param Bytes Amount to advance, in bytes + * @returns Updated entry offset + */ +static inline SC_EntryOffset_t SC_EntryOffsetAdvance(SC_EntryOffset_t Pos, size_t Bytes) +{ + return (SC_EntryOffset_t) {SC_IDX_AS_UINT(Pos) + ((Bytes + sizeof(uint32) - 1) / sizeof(uint32))}; +} + #endif diff --git a/fsw/src/sc_loads.c b/fsw/src/sc_loads.c index c77d0de..fce45a3 100644 --- a/fsw/src/sc_loads.c +++ b/fsw/src/sc_loads.c @@ -51,10 +51,10 @@ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SC_LoadAts(SC_AtsIndex_t AtsIndex) { - uint16 AtsEntryWords; /* current ats entry length in words */ - SC_CommandNum_t AtsCmdNum; /* current ats entry command number */ - SC_EntryOffset_t AtsEntryIndex; /* index into the load for current ats entry */ - SC_AtsEntry_t * EntryPtr; /* a pointer to an ats entry */ + SC_CommandNum_t AtsCmdNum; /* current ats entry command number */ + SC_EntryOffset_t AtsEntryIndex; /* index into the load for current ats entry */ + SC_EntryOffset_t PendingEntryIndex; /* index into the load for current ats entry */ + SC_AtsEntry_t * EntryPtr; /* a pointer to an ats entry */ CFE_MSG_Size_t MessageSize = 0; int32 Result = CFE_SUCCESS; bool StillProcessing = true; @@ -63,7 +63,7 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_LOADATS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "ATS load error: invalid ATS index %d", AtsIndex); @@ -85,7 +85,7 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) ** Make sure that the pointer as well as the primary packet ** header fit in the buffer, so a G.P fault is not caused. */ - if (AtsEntryIndex < SC_ATS_BUFF_SIZE32) + if (SC_IDX_WITHIN_LIMIT(AtsEntryIndex, SC_ATS_BUFF_SIZE32)) { /* get a pointer to the ats command in the table */ EntryPtr = SC_GetAtsEntryAtOffset(AtsIndex, AtsEntryIndex); @@ -93,7 +93,7 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) /* get the next command number from the buffer */ AtsCmdNum = EntryPtr->Header.CmdNumber; - if (AtsCmdNum == 0) + if (SC_IDNUM_IS_NULL(AtsCmdNum)) { /* end of the load reached */ Result = CFE_SUCCESS; @@ -108,7 +108,8 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) } /* make sure the CmdPtr can fit in a whole Ats Cmd Header at the very least */ - if (AtsEntryIndex > (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS)) + if (!SC_IDX_WITHIN_LIMIT(AtsEntryIndex, + 1 + (SC_ATS_BUFF_SIZE32 - SC_ATS_HDR_WORDS))) /* jphfix - revisit? */ { /* even the smallest command will not fit in the buffer */ Result = SC_ERROR; @@ -127,10 +128,10 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) if (MessageSize >= SC_PACKET_MIN_SIZE && MessageSize <= SC_PACKET_MAX_SIZE) { /* get the length of the entry in WORDS (plus 1 to round byte len up to word len) */ - AtsEntryWords = ((MessageSize + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) + SC_ATS_HDR_NOPKT_WORDS; + PendingEntryIndex = SC_EntryOffsetAdvance(AtsEntryIndex, MessageSize + SC_ATS_HEADER_SIZE); /* if the command does not run off of the end of the buffer */ - if (AtsEntryIndex + AtsEntryWords <= SC_ATS_BUFF_SIZE32) + if (SC_IDX_WITHIN_LIMIT(PendingEntryIndex, 1 + SC_ATS_BUFF_SIZE32)) { /* set the command pointer in the command index table */ /* CmdNum starts at one.... */ @@ -144,7 +145,7 @@ void SC_LoadAts(SC_AtsIndex_t AtsIndex) AtsInfoPtr->NumberOfCommands++; /* increment the ats_entry index to the next ats entry */ - AtsEntryIndex = AtsEntryIndex + AtsEntryWords; + AtsEntryIndex = PendingEntryIndex; } else { /* the command runs off the end of the buffer */ @@ -212,7 +213,7 @@ void SC_BuildTimeIndexTable(SC_AtsIndex_t AtsIndex) SC_AtsCmdNumRecord_t *AtsCmdNumRec; /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_BUILD_TIME_IDXTBL_ERR_EID, CFE_EVS_EventType_ERROR, "Build time index table error: invalid ATS index %d", AtsIndex); @@ -255,7 +256,7 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis SC_AtsCmdNumRecord_t * AtsCmdNumRec; /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_INSERTATS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "ATS insert error: invalid ATS index %d", AtsIndex); @@ -274,9 +275,9 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis } /* start at last element in the sorted by time list */ - TimeBufIndex = ListLength - 1; + TimeBufIndex = SC_SEQUENCE_IDX_C(ListLength - 1); - while (TimeBufIndex >= 0) + while (SC_IDX_WITHIN_LIMIT(TimeBufIndex, ListLength)) { /* first get the cmd index for this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeBufIndex)->CmdNum); @@ -300,7 +301,7 @@ void SC_Insert(SC_AtsIndex_t AtsIndex, SC_CommandIndex_t NewCmdIndex, uint32 Lis SC_GetAtsCommandNumAtSeq(AtsIndex, TimeBufIndex)->CmdNum; /* back up to previous list entry (ok if -1) */ - TimeBufIndex--; + SC_IDX_DECREMENT(TimeBufIndex); } else { @@ -336,7 +337,7 @@ void SC_InitAtsTables(SC_AtsIndex_t AtsIndex) SC_AtsCmdNumRecord_t * AtsCmdNumRec; /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_INIT_ATSTBL_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "ATS table init error: invalid ATS index %d", AtsIndex); @@ -371,7 +372,7 @@ void SC_LoadRts(SC_RtsIndex_t RtsIndex) SC_RtsInfoEntry_t *RtsInfoPtr; /* validate RTS array index */ - if (RtsIndex < SC_NUMBER_OF_RTS) + if (SC_RtsIndexIsValid(RtsIndex)) { /* Clear out the RTS info table */ RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); @@ -585,7 +586,7 @@ void SC_UpdateAppend(void) { EntryPtr = (SC_AtsEntry_t *)&SC_OperData.AppendTblAddr[EntryIndex]; - if ((EntryPtr->Header.CmdNumber == 0) || (EntryPtr->Header.CmdNumber > SC_MAX_ATS_CMDS)) + if (!SC_AtsCommandNumIsValid(EntryPtr->Header.CmdNumber)) { /* End of valid command numbers */ StillProcessing = false; @@ -636,7 +637,6 @@ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) { SC_AtsEntry_t * EntryPtr; CFE_MSG_Size_t CommandBytes = 0; - int32 CommandWords; SC_EntryOffset_t EntryIndex; int32 i; SC_CommandIndex_t CmdIndex; @@ -645,7 +645,7 @@ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* validate ATS array index */ - if (AtsIndex >= SC_NUMBER_OF_ATS) + if (!SC_AtsIndexIsValid(AtsIndex)) { CFE_EVS_SendEvent(SC_PROCESS_APPEND_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "ATS process append error: invalid ATS index %d", AtsIndex); @@ -687,8 +687,7 @@ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) /* update entry index to point to the next entry */ CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CommandBytes); - CommandWords = (CommandBytes + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD; - EntryIndex += (SC_ATS_HDR_NOPKT_WORDS + CommandWords); + EntryIndex = SC_EntryOffsetAdvance(EntryIndex, CommandBytes + SC_ATS_HEADER_SIZE); } /* rebuild time sorted list of commands */ @@ -710,7 +709,7 @@ void SC_ProcessAppend(SC_AtsIndex_t AtsIndex) } /* notify cFE that we have modified the ats table */ - CFE_TBL_Modified(SC_OperData.AtsTblHandle[AtsIndex]); + CFE_TBL_Modified(SC_OperData.AtsTblHandle[SC_IDX_AS_UINT(AtsIndex)]); } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -818,7 +817,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords) /* All done -- end of in-use portion of buffer */ Result = CFE_SUCCESS; } - else if (EntryPtr->Header.CmdNumber > SC_MAX_ATS_CMDS) + else if (!SC_AtsCommandNumIsValid(EntryPtr->Header.CmdNumber)) { /* Error -- invalid command number */ Result = SC_ERROR; diff --git a/fsw/src/sc_rtsrq.c b/fsw/src/sc_rtsrq.c index c12dc37..b5d4de0 100644 --- a/fsw/src/sc_rtsrq.c +++ b/fsw/src/sc_rtsrq.c @@ -62,7 +62,7 @@ void SC_StartRtsCmd(const SC_StartRtsCmd_t *Cmd) */ RtsNum = Cmd->Payload.RtsNum; - if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) + if (SC_RtsNumIsValid(RtsNum)) { /* convert RTS ID to RTS array index */ RtsIndex = SC_RtsNumToIndex(RtsNum); @@ -181,14 +181,13 @@ void SC_StartRtsGrpCmd(const SC_StartRtsGrpCmd_t *Cmd) LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && - (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) + if (SC_RtsNumValidateRange(FirstRtsNum, LastRtsNum)) { /* convert RTS ID to RTS array index */ FirstIndex = SC_RtsNumToIndex(FirstRtsNum); LastIndex = SC_RtsNumToIndex(LastRtsNum); - for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) + for (RtsIndex = FirstIndex; SC_IDX_LESS_OR_EQ(RtsIndex, LastIndex); SC_IDX_INCREMENT(RtsIndex)) { RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); @@ -264,7 +263,7 @@ void SC_StopRtsCmd(const SC_StopRtsCmd_t *Cmd) RtsNum = Cmd->Payload.RtsNum; /* check the command parameter */ - if (RtsNum <= SC_NUMBER_OF_RTS) + if (SC_RtsNumIsValid(RtsNum)) { /* convert RTS ID to RTS array index */ RtsIndex = SC_RtsNumToIndex(RtsNum); @@ -307,14 +306,13 @@ void SC_StopRtsGrpCmd(const SC_StopRtsGrpCmd_t *Cmd) LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && - (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) + if (SC_RtsNumValidateRange(FirstRtsNum, LastRtsNum)) { /* convert RTS ID to RTS array index */ FirstIndex = SC_RtsNumToIndex(FirstRtsNum); LastIndex = SC_RtsNumToIndex(LastRtsNum); - for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) + for (RtsIndex = FirstIndex; SC_IDX_LESS_OR_EQ(RtsIndex, LastIndex); SC_IDX_INCREMENT(RtsIndex)) { RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); @@ -354,7 +352,7 @@ void SC_DisableRtsCmd(const SC_DisableRtsCmd_t *Cmd) RtsNum = Cmd->Payload.RtsNum; /* make sure tha specified rts is valid */ - if (RtsNum <= SC_NUMBER_OF_RTS) + if (SC_RtsNumIsValid(RtsNum)) { /* convert RTS ID to RTS array index */ RtsIndex = SC_RtsNumToIndex(RtsNum); @@ -397,14 +395,13 @@ void SC_DisableRtsGrpCmd(const SC_DisableRtsGrpCmd_t *Cmd) LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && - (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) + if (SC_RtsNumValidateRange(FirstRtsNum, LastRtsNum)) { /* convert RTS ID to RTS array index */ FirstIndex = SC_RtsNumToIndex(FirstRtsNum); LastIndex = SC_RtsNumToIndex(LastRtsNum); - for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) + for (RtsIndex = FirstIndex; SC_IDX_LESS_OR_EQ(RtsIndex, LastIndex); SC_IDX_INCREMENT(RtsIndex)) { RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); @@ -444,7 +441,7 @@ void SC_EnableRtsCmd(const SC_EnableRtsCmd_t *Cmd) RtsNum = Cmd->Payload.RtsNum; /* make sure the specified rts is valid */ - if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) + if (SC_RtsNumIsValid(RtsNum)) { /* convert RTS ID to RTS array index */ RtsIndex = SC_RtsNumToIndex(RtsNum); @@ -488,14 +485,13 @@ void SC_EnableRtsGrpCmd(const SC_EnableRtsGrpCmd_t *Cmd) LastRtsNum = Cmd->Payload.LastRtsNum; /* make sure the specified group is valid */ - if ((FirstRtsNum > 0) && (LastRtsNum > 0) && (FirstRtsNum <= SC_NUMBER_OF_RTS) && - (LastRtsNum <= SC_NUMBER_OF_RTS) && (FirstRtsNum <= LastRtsNum)) + if (SC_RtsNumValidateRange(FirstRtsNum, LastRtsNum)) { /* convert RTS ID to RTS array index */ FirstIndex = SC_RtsNumToIndex(FirstRtsNum); LastIndex = SC_RtsNumToIndex(LastRtsNum); - for (RtsIndex = FirstIndex; RtsIndex <= LastIndex; RtsIndex++) + for (RtsIndex = FirstIndex; SC_IDX_LESS_OR_EQ(RtsIndex, LastIndex); SC_IDX_INCREMENT(RtsIndex)) { RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); @@ -533,7 +529,7 @@ void SC_KillRts(SC_RtsIndex_t RtsIndex) RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); /* validate RTS array index */ - if (RtsIndex >= SC_NUMBER_OF_RTS) + if (!SC_RtsIndexIsValid(RtsIndex)) { CFE_EVS_SendEvent(SC_KILLRTS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "RTS kill error: invalid RTS index %d", RtsIndex); @@ -571,7 +567,7 @@ void SC_AutoStartRts(SC_RtsNum_t RtsNum) memset(&CmdPkt, 0, sizeof(CmdPkt)); /* validate RTS ID */ - if ((RtsNum > 0) && (RtsNum <= SC_NUMBER_OF_RTS)) + if (SC_RtsNumIsValid(RtsNum)) { /* ** Format the command packet to start the first RTS diff --git a/fsw/src/sc_state.c b/fsw/src/sc_state.c index 02fd216..5aba46f 100644 --- a/fsw/src/sc_state.c +++ b/fsw/src/sc_state.c @@ -84,7 +84,7 @@ void SC_GetNextRtsTime(void) } /* end if */ } /* end for */ - if (NextRts == SC_INVALID_RTS_INDEX) + if (!SC_RtsIndexIsValid(NextRts)) { SC_OperData.RtsCtrlBlckAddr->CurrRtsNum = SC_RTS_NUM_NULL; SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_TIME; @@ -125,7 +125,7 @@ void SC_UpdateNextTime(void) ** 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_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) + if (SC_RtsNumIsValid(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum)) { /* ** If the RTP needs to send commands, only send them if @@ -148,6 +148,7 @@ void SC_GetNextRtsCommand(void) { SC_RtsIndex_t RtsIndex; SC_EntryOffset_t CmdOffset; + SC_EntryOffset_t PendingOffset; SC_RtsEntry_t * EntryPtr; CFE_MSG_Size_t CmdLength = 0; SC_RtsInfoEntry_t *RtsInfoPtr; @@ -155,12 +156,11 @@ void SC_GetNextRtsCommand(void) /* ** Make sure that the RTP is executing some RTS */ - - if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum > 0) && (SC_OperData.RtsCtrlBlckAddr->CurrRtsNum <= SC_NUMBER_OF_RTS)) + RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); + if (SC_RtsIndexIsValid(RtsIndex)) { - /* Get the index of the rts that is running */ - RtsIndex = SC_RtsNumToIndex(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); RtsInfoPtr = SC_GetRtsInfoObject(RtsIndex); + /* ** Find out if the RTS is EXECUTING or just STARTED */ @@ -181,7 +181,7 @@ void SC_GetNextRtsCommand(void) ** (plus 1 to round byte len up to word len) */ - CmdOffset = CmdOffset + ((CmdLength + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD); + CmdOffset = SC_EntryOffsetAdvance(CmdOffset, CmdLength); /* ** if the end of the buffer is not reached. ** This check is made to make sure that at least the minimum @@ -190,7 +190,7 @@ void SC_GetNextRtsCommand(void) */ /* If at least the header for a command plus the RTS header can fit in the buffer */ - if (CmdOffset <= (SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS)) + if (SC_IDX_WITHIN_LIMIT(CmdOffset, 1 + SC_RTS_BUFF_SIZE32 - SC_RTS_HDR_WORDS)) { /* ** Get the next RTS command @@ -221,7 +221,8 @@ void SC_GetNextRtsCommand(void) ** runs off of the end of the buffer ** (plus 1 to round byte len up to word len) */ - if (CmdOffset + ((CmdLength + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD) <= SC_RTS_BUFF_SIZE32) + PendingOffset = SC_EntryOffsetAdvance(CmdOffset, CmdLength); + if (SC_IDX_WITHIN_LIMIT(PendingOffset, 1 + SC_RTS_BUFF_SIZE32)) { /* ** Everything passed! @@ -282,7 +283,7 @@ void SC_GetNextRtsCommand(void) /* Stop the RTS from executing */ SC_KillRts(RtsIndex); - if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum) <= SC_LAST_RTS_WITH_EVENTS) + if (SC_RtsNumHasEvent(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum)) { CFE_EVS_SendEvent(SC_RTS_COMPL_INF_EID, CFE_EVS_EventType_INFORMATION, "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); @@ -293,7 +294,7 @@ void SC_GetNextRtsCommand(void) { /* The end of the RTS buffer has been reached... */ /* Stop the RTS from executing */ SC_KillRts(RtsIndex); - if ((SC_OperData.RtsCtrlBlckAddr->CurrRtsNum) <= SC_LAST_RTS_WITH_EVENTS) + if (SC_RtsNumHasEvent(SC_OperData.RtsCtrlBlckAddr->CurrRtsNum)) { CFE_EVS_SendEvent(SC_RTS_COMPL_INF_EID, CFE_EVS_EventType_INFORMATION, "RTS %03d Execution Completed", SC_OperData.RtsCtrlBlckAddr->CurrRtsNum); @@ -327,13 +328,14 @@ void SC_GetNextAtsCommand(void) ** Get the information that is needed to find the next command */ AtsIndex = SC_AtsNumToIndex(SC_OperData.AtsCtrlBlckAddr->CurrAtsNum); - TimeIndex = SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr + 1; + TimeIndex = SC_OperData.AtsCtrlBlckAddr->TimeIndexPtr; AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + SC_IDX_INCREMENT(TimeIndex); /* ** Check to see if there are more ATS commands */ - if (TimeIndex < AtsInfoPtr->NumberOfCommands) + if (SC_IDX_WITHIN_LIMIT(TimeIndex, AtsInfoPtr->NumberOfCommands)) { /* get the information for the next command in the ATP control block */ AtsCmdNumRec = SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex); diff --git a/unit-test/sc_atsrq_tests.c b/unit-test/sc_atsrq_tests.c index 31c35ad..0b60319 100644 --- a/unit-test/sc_atsrq_tests.c +++ b/unit-test/sc_atsrq_tests.c @@ -226,7 +226,7 @@ void SC_StartAtsCmd_Test_InUse(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_StartAtsCmd_Test_InvalidAtsId(void) +void SC_StartAtsCmd_Test_InvalidAtsNum(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; @@ -247,7 +247,7 @@ void SC_StartAtsCmd_Test_InvalidAtsId(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_StartAtsCmd_Test_InvalidAtsIdZero(void) +void SC_StartAtsCmd_Test_InvalidAtsNumZero(void) { CFE_SB_MsgId_t TestMsgId = CFE_SB_ValueToMsgId(SC_CMD_MID); CFE_MSG_FcnCode_t FcnCode = SC_START_ATS_CC; @@ -448,6 +448,20 @@ void SC_SwitchAtsCmd_Test_Nominal(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } +void SC_SwitchAtsCmd_Test_BadId(void) +{ + /* Execute the function being tested */ + UtAssert_VOIDCALL(SC_SwitchAtsCmd(&UT_CmdBuf.SwitchAtsCmd)); + + /* Verify results */ + UtAssert_True(SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag == false, + "SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag == false"); + UtAssert_True(SC_OperData.HkPacket.Payload.CmdErrCtr == 1, "SC_OperData.HkPacket.Payload.CmdErrCtr == 1"); + + UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_SWITCH_ATS_CMD_IDLE_ERR_EID); + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); +} + void SC_SwitchAtsCmd_Test_DestinationAtsNotLoaded(void) { SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(1); @@ -1146,9 +1160,9 @@ void UtTest_Setup(void) UtTest_Add(SC_StartAtsCmd_Test_NoCommandsA, SC_Test_Setup, SC_Test_TearDown, "SC_StartAtsCmd_Test_NoCommandsA"); UtTest_Add(SC_StartAtsCmd_Test_NoCommandsB, SC_Test_Setup, SC_Test_TearDown, "SC_StartAtsCmd_Test_NoCommandsB"); UtTest_Add(SC_StartAtsCmd_Test_InUse, SC_Test_Setup, SC_Test_TearDown, "SC_StartAtsCmd_Test_InUse"); - UtTest_Add(SC_StartAtsCmd_Test_InvalidAtsId, SC_Test_Setup, SC_Test_TearDown, "SC_StartAtsCmd_Test_InvalidAtsId"); - UtTest_Add(SC_StartAtsCmd_Test_InvalidAtsIdZero, SC_Test_Setup, SC_Test_TearDown, - "SC_StartAtsCmd_Test_InvalidAtsIdZero"); + UtTest_Add(SC_StartAtsCmd_Test_InvalidAtsNum, SC_Test_Setup, SC_Test_TearDown, "SC_StartAtsCmd_Test_InvalidAtsNum"); + UtTest_Add(SC_StartAtsCmd_Test_InvalidAtsNumZero, SC_Test_Setup, SC_Test_TearDown, + "SC_StartAtsCmd_Test_InvalidAtsNumZero"); UtTest_Add(SC_StopAtsCmd_Test_NominalA, SC_Test_Setup, SC_Test_TearDown, "SC_StopAtsCmd_Test_NominalA"); UtTest_Add(SC_StopAtsCmd_Test_NominalB, SC_Test_Setup, SC_Test_TearDown, "SC_StopAtsCmd_Test_NominalB"); UtTest_Add(SC_StopAtsCmd_Test_NoRunningAts, SC_Test_Setup, SC_Test_TearDown, "SC_StopAtsCmd_Test_NoRunningAts"); @@ -1158,6 +1172,7 @@ void UtTest_Setup(void) UtTest_Add(SC_BeginAts_Test_InvalidAtsIndex, SC_Test_Setup, SC_Test_TearDown, "SC_BeginAts_Test_InvalidAtsIndex"); UtTest_Add(SC_KillAts_Test, SC_Test_Setup, SC_Test_TearDown, "SC_KillAts_Test"); UtTest_Add(SC_SwitchAtsCmd_Test_Nominal, SC_Test_Setup, SC_Test_TearDown, "SC_SwitchAtsCmd_Test_Nominal"); + UtTest_Add(SC_SwitchAtsCmd_Test_BadId, SC_Test_Setup, SC_Test_TearDown, "SC_SwitchAtsCmd_Test_BadId"); UtTest_Add(SC_SwitchAtsCmd_Test_DestinationAtsNotLoaded, SC_Test_Setup, SC_Test_TearDown, "SC_SwitchAtsCmd_Test_DestinationAtsNotLoaded"); UtTest_Add(SC_SwitchAtsCmd_Test_AtpIdle, SC_Test_Setup, SC_Test_TearDown, "SC_SwitchAtsCmd_Test_AtpIdle"); diff --git a/unit-test/sc_loads_tests.c b/unit-test/sc_loads_tests.c index 34a5b82..c6c75f6 100644 --- a/unit-test/sc_loads_tests.c +++ b/unit-test/sc_loads_tests.c @@ -1152,6 +1152,43 @@ void SC_ProcessAppend_Test_NotExecuting(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); } +void SC_ProcessAppend_Test_IdMismatch(void) +{ + SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); + void * TailPtr; + SC_AtsInfoTable_t * AtsInfoPtr; + SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; + + CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, SC_COMMAND_IDX_C(0)); + StatusEntryPtr = SC_GetAtsStatusEntryForCommand(AtsIndex, SC_COMMAND_IDX_C(0)); + + AtsInfoPtr = SC_GetAtsInfoObject(AtsIndex); + + UT_SC_SetupSingleAtsEntry(AtsIndex, 1, UT_SC_NOMINAL_CMD_SIZE); + + TailPtr = UT_SC_GetAppendTable(); + UT_SC_AppendSingleAtsEntry(&TailPtr, 1, UT_SC_NOMINAL_CMD_SIZE); + + SC_AppData.AppendWordCount = 1; + SC_OperData.HkPacket.Payload.AppendEntryCount = 1; + + SC_OperData.AtsCtrlBlckAddr->AtpState = SC_Status_EXECUTING; + SC_OperData.AtsCtrlBlckAddr->CurrAtsNum = SC_AtsIndexToNum(SC_ATS_IDX_C(1)); + + /* Execute the function being tested */ + SC_ProcessAppend(AtsIndex); + + /* Verify results */ + UtAssert_UINT32_EQ(AtsInfoPtr->AtsSize, 1); + UtAssert_UINT32_EQ(AtsInfoPtr->NumberOfCommands, 1); + SC_Assert_IDX_EQ(CmdOffsetRec->Offset, SC_ENTRY_OFFSET_FIRST); + SC_Assert_CmdStatus(StatusEntryPtr->Status, SC_Status_LOADED); + SC_Assert_CmdStatus(SC_OperData.AtsCtrlBlckAddr->AtpState, SC_Status_EXECUTING); + + UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0); +} + void SC_ProcessAppend_Test_AtsNum(void) { SC_AtsIndex_t AtsIndex = SC_ATS_IDX_C(0); @@ -1479,6 +1516,8 @@ void UtTest_Setup(void) "SC_ProcessAppend_Test_CmdLoaded"); UtTest_Add(SC_ProcessAppend_Test_NotExecuting, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_NotExecuting"); + UtTest_Add(SC_ProcessAppend_Test_IdMismatch, UT_SC_Loads_Test_Setup, SC_Test_TearDown, + "SC_ProcessAppend_Test_IdMismatch"); UtTest_Add(SC_ProcessAppend_Test_AtsNum, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_AtsNum"); UtTest_Add(SC_ProcessAppend_Test_InvalidIndex, UT_SC_Loads_Test_Setup, SC_Test_TearDown, "SC_ProcessAppend_Test_InvalidIndex"); diff --git a/unit-test/sc_rtsrq_tests.c b/unit-test/sc_rtsrq_tests.c index 5d30161..c4f4a0b 100644 --- a/unit-test/sc_rtsrq_tests.c +++ b/unit-test/sc_rtsrq_tests.c @@ -124,7 +124,7 @@ void SC_StartRtsCmd_Test_StartRtsNoEvents(void) UtAssert_True(SC_OperData.HkPacket.Payload.CmdCtr == 1, "SC_OperData.HkPacket.Payload.CmdCtr == 1"); /* Handle if SC_LAST_RTS_WITH_EVENTS is the same as SC_NUM_OF_RTS */ - if (UT_CmdBuf.DisableRtsCmd.Payload.RtsNum > SC_LAST_RTS_WITH_EVENTS) + if (!SC_RtsNumHasEvent(UT_CmdBuf.DisableRtsCmd.Payload.RtsNum)) { UtAssert_INT32_EQ(context_CFE_EVS_SendEvent[0].EventID, SC_STARTRTS_CMD_DBG_EID); } @@ -246,7 +246,7 @@ void SC_StartRtsCmd_Test_RtsDisabled(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_StartRtsCmd_Test_InvalidRtsId(void) +void SC_StartRtsCmd_Test_InvalidRtsNum(void) { UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(SC_NUMBER_OF_RTS * 2); @@ -258,7 +258,7 @@ void SC_StartRtsCmd_Test_InvalidRtsId(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); } -void SC_StartRtsCmd_Test_InvalidRtsIdZero(void) +void SC_StartRtsCmd_Test_InvalidRtsNumZero(void) { UT_CmdBuf.StartRtsCmd.Payload.RtsNum = SC_RTS_NUM_C(0); @@ -1072,10 +1072,10 @@ void UtTest_Setup(void) UtTest_Add(SC_StartRtsCmd_Test_RtsNotLoadedOrInUse, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsCmd_Test_RtsNotLoadedOrInUse"); UtTest_Add(SC_StartRtsCmd_Test_RtsDisabled, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsCmd_Test_RtsDisabled"); - UtTest_Add(SC_StartRtsCmd_Test_InvalidRtsId, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsCmd_Test_InvalidRtsId"); + UtTest_Add(SC_StartRtsCmd_Test_InvalidRtsNum, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsCmd_Test_InvalidRtsNum"); - UtTest_Add(SC_StartRtsCmd_Test_InvalidRtsIdZero, SC_Test_Setup, SC_Test_TearDown, - "SC_StartRtsCmd_Test_InvalidRtsIdZero"); + UtTest_Add(SC_StartRtsCmd_Test_InvalidRtsNumZero, SC_Test_Setup, SC_Test_TearDown, + "SC_StartRtsCmd_Test_InvalidRtsNumZero"); UtTest_Add(SC_StartRtsGrpCmd_Test_Nominal, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsGrpCmd_Test_Nominal"); UtTest_Add(SC_StartRtsGrpCmd_Test_StartRtsGroupError, SC_Test_Setup, SC_Test_TearDown, "SC_StartRtsGrpCmd_Test_StartRtsGroupError"); From ee21c305f3f00e33d9bd82f7a56db45660178877 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 18 Oct 2023 16:18:35 -0400 Subject: [PATCH 4/4] Fix #121, add extra range checking Adds additional range checks to avoid out-of-bounds array access --- fsw/src/sc_atsrq.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fsw/src/sc_atsrq.c b/fsw/src/sc_atsrq.c index 16ee96f..a826639 100644 --- a/fsw/src/sc_atsrq.c +++ b/fsw/src/sc_atsrq.c @@ -211,6 +211,12 @@ bool SC_BeginAts(SC_AtsIndex_t AtsIndex, uint16 TimeOffset) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); + if (!SC_AtsCommandIndexIsValid(CmdIndex)) + { + SC_IDX_INCREMENT(TimeIndex); + continue; + } + /* then get the entry index from the cmd index table */ CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */ @@ -540,6 +546,12 @@ void SC_JumpAtsCmd(const SC_JumpAtsCmd_t *Cmd) { /* first get the cmd index at this list entry */ CmdIndex = SC_CommandNumToIndex(SC_GetAtsCommandNumAtSeq(AtsIndex, TimeIndex)->CmdNum); + if (!SC_AtsCommandIndexIsValid(CmdIndex)) + { + SC_IDX_INCREMENT(TimeIndex); + continue; + } + /* then get the entry index from the cmd index table */ CmdOffsetRec = SC_GetAtsEntryOffsetForCmd(AtsIndex, CmdIndex); /* then get a pointer to the ATS entry data */