diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index 975734f6c..80ee121f6 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -62,6 +62,7 @@ jobs: cp ./cfe/cmake/Makefile.sample Makefile cp -r ./cfe/cmake/sample_defs sample_defs make prep + make -C build mission-prebuild # Build the code - name: Build diff --git a/cmake/mission_build.cmake b/cmake/mission_build.cmake index 26285e56d..fad015d03 100644 --- a/cmake/mission_build.cmake +++ b/cmake/mission_build.cmake @@ -280,6 +280,38 @@ function(export_variable_cache USER_VARLIST) endfunction(export_variable_cache) +################################################################## +# +# FUNCTION: decode_targetsystem +# +# +function(decode_targetsystem TARGETSYSTEM) + # The "BUILD_CONFIG" is a list of items to uniquely identify this build + # The first element in the list is the toolchain name, followed by config name(s) + + set(ONE_VAL_ARGS OUTPUT_ARCH_BINARY_DIR OUTPUT_ARCH_TOOLCHAIN_NAME OUTPUT_ARCH_CONFIG_NAME) + cmake_parse_arguments(DT "" "${ONE_VAL_ARGS}" "" ${ARGN}) + + set(BUILD_CONFIG ${BUILD_CONFIG_${TARGETSYSTEM}}) + list(GET BUILD_CONFIG 0 ARCH_TOOLCHAIN_NAME) + list(REMOVE_AT BUILD_CONFIG 0) + # convert to a string which is safe for a directory name + string(REGEX REPLACE "[^A-Za-z0-9]" "_" ARCH_CONFIG_NAME "${BUILD_CONFIG}") + + # Export values to parent + if (DT_OUTPUT_ARCH_BINARY_DIR) + set(${DT_OUTPUT_ARCH_BINARY_DIR} "${CMAKE_BINARY_DIR}/${ARCH_TOOLCHAIN_NAME}/${ARCH_CONFIG_NAME}" PARENT_SCOPE) + endif() + if (DT_OUTPUT_ARCH_TOOLCHAIN_NAME) + set(${DT_OUTPUT_ARCH_TOOLCHAIN_NAME} "${ARCH_TOOLCHAIN_NAME}" PARENT_SCOPE) + endif() + if (DT_OUTPUT_ARCH_CONFIG_NAME) + set(${DT_OUTPUT_ARCH_CONFIG_NAME} "${ARCH_CONFIG_NAME}" PARENT_SCOPE) + endif() + +endfunction(decode_targetsystem) + + ################################################################## # # FUNCTION: prepare @@ -536,12 +568,12 @@ function(process_arch TARGETSYSTEM) # The "BUILD_CONFIG" is a list of items to uniquely identify this build # The first element in the list is the toolchain name, followed by config name(s) - set(BUILD_CONFIG ${BUILD_CONFIG_${TARGETSYSTEM}}) - list(GET BUILD_CONFIG 0 ARCH_TOOLCHAIN_NAME) - list(REMOVE_AT BUILD_CONFIG 0) - # convert to a string which is safe for a directory name - string(REGEX REPLACE "[^A-Za-z0-9]" "_" ARCH_CONFIG_NAME "${BUILD_CONFIG}") - set(ARCH_BINARY_DIR "${CMAKE_BINARY_DIR}/${ARCH_TOOLCHAIN_NAME}/${ARCH_CONFIG_NAME}") + decode_targetsystem(${TARGETSYSTEM} + OUTPUT_ARCH_BINARY_DIR ARCH_BINARY_DIR + OUTPUT_ARCH_TOOLCHAIN_NAME ARCH_TOOLCHAIN_NAME + OUTPUT_ARCH_CONFIG_NAME ARCH_CONFIG_NAME + ) + file(MAKE_DIRECTORY "${ARCH_BINARY_DIR}") message(STATUS "Configuring for system arch: ${ARCH_TOOLCHAIN_NAME}/${ARCH_CONFIG_NAME}") diff --git a/modules/config/CMakeLists.txt b/modules/config/CMakeLists.txt index 6c8ddf1f0..3bb114702 100644 --- a/modules/config/CMakeLists.txt +++ b/modules/config/CMakeLists.txt @@ -15,12 +15,27 @@ set(config_SOURCES ) add_library(config STATIC ${config_SOURCES} - ${MISSION_BINARY_DIR}/src/cfe_config_map.c + ${MISSION_BINARY_DIR}/src/cfe_configid_nametable.c + ${CMAKE_BINARY_DIR}/src/cfe_platformcfg_tables.c ) -# need to include the "src" dir explicitly here, in order to compile -# the generated tables under ${MISSION_BINARY_DIR} -target_include_directories(config PRIVATE fsw/src) +add_custom_command( + OUTPUT ${CMAKE_BINARY_DIR}/src/cfe_platformcfg_tables.c + COMMAND ${CMAKE_COMMAND} + -D LIST_FILE=${MISSION_BINARY_DIR}/src/cfeconfig_platformdata_${TARGETSYSTEM}.list + -D CONTENT_FILE=${MISSION_BINARY_DIR}/src/cfeconfig_platformdata_${TARGETSYSTEM}.c + -D OUTPUT_FILE=${CMAKE_BINARY_DIR}/src/cfe_platformcfg_tables.c + -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/create_cfe_platform_cfg.cmake + WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR}/cmake + DEPENDS + ${MISSION_BINARY_DIR}/src/cfeconfig_platformdata_${TARGETSYSTEM}.c + ${MISSION_BINARY_DIR}/src/cfeconfig_platformdata_${TARGETSYSTEM}.list + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/create_cfe_platform_cfg.cmake + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cfe_platform_cfg.c.in +) + +target_include_directories(config PUBLIC fsw/inc) target_link_libraries(config PRIVATE core_private) # Add unit test coverage subdirectory diff --git a/modules/config/cmake/cfe_config_ids.h.in b/modules/config/cmake/cfe_config_ids.h.in index ab7f2d2bc..3d48bb9d1 100644 --- a/modules/config/cmake/cfe_config_ids.h.in +++ b/modules/config/cmake/cfe_config_ids.h.in @@ -5,13 +5,15 @@ #include "cfe_config_api_typedefs.h" #include "cfe_resourceid.h" #include "cfe_core_resourceid_basevalues.h" +#include "cfe_configid_offset.h" -/* Value offsets from base (needed for macros; do not use directly) */ -enum CFE_ConfigIdOffset -{ -@GENERATED_ENUM_OFFSET_LIST@ - CFE_ConfigIdOffset_MAX -}; +/* + * Macro to convert to a properly-typed config ID + * The symbol used in this macro must correlate to an offset in the enum + */ + +#define CFE_CONFIGID_OFFSET_TO_RESID(x) CFE_ResourceId_FromInteger(CFE_CONFIGID_BASE + CFE_CONFIGID_OFFSETNAME(x)) +#define CFE_CONFIGID_FROM_OFFSET(x) CFE_CONFIGID_C(CFE_CONFIGID_OFFSET_TO_RESID(x)) /* * Set of actual CONFIGID constants - diff --git a/modules/config/cmake/cfe_config_map.c.in b/modules/config/cmake/cfe_config_map.c.in deleted file mode 100644 index b15ea89ba..000000000 --- a/modules/config/cmake/cfe_config_map.c.in +++ /dev/null @@ -1,8 +0,0 @@ -/* This file is auto-generated from CMake build system. Do not manually edit! */ -#include "cfe_config_map.h" - -/* Map of configuration key IDs to printable names */ -const CFE_Config_IdNameEntry_t CFE_CONFIG_IDNAME_MAP[CFE_ConfigIdOffset_MAX] = -{ -@GENERATED_IDNAME_MAP_LIST@ -}; diff --git a/modules/config/cmake/cfe_configid_nametable.c.in b/modules/config/cmake/cfe_configid_nametable.c.in new file mode 100644 index 000000000..daa3dbe9f --- /dev/null +++ b/modules/config/cmake/cfe_configid_nametable.c.in @@ -0,0 +1,11 @@ +/* This file is auto-generated from CMake build system. Do not manually edit! */ +#include "cfe_configid_offset.h" +#include "cfe_config_nametable.h" + +#define CFE_CONFIGID_DEFINE(x) [CFE_CONFIGID_OFFSETNAME(x)] = { #x }, + +/* Map of configuration key IDs to printable names */ +const CFE_Config_IdNameEntry_t CFE_CONFIGID_NAMETABLE[CFE_ConfigIdOffset_MAX] = +{ +@GENERATED_ID_MACRO_LIST@ +}; diff --git a/modules/config/cmake/cfe_configid_offset.h.in b/modules/config/cmake/cfe_configid_offset.h.in new file mode 100644 index 000000000..daa047a2c --- /dev/null +++ b/modules/config/cmake/cfe_configid_offset.h.in @@ -0,0 +1,19 @@ +/* This file is auto-generated from CMake build system. Do not manually edit! */ +#ifndef CFE_CONFIGID_OFFSET_H +#define CFE_CONFIGID_OFFSET_H + +#define CFE_CONFIGID_OFFSETNAME(x) CFE_ConfigIdOffset_ ## x + +#undef CFE_CONFIGID_DEFINE +#define CFE_CONFIGID_DEFINE(x) CFE_CONFIGID_OFFSETNAME(x), + +/* Value offsets from base (needed for macros; do not use directly) */ +typedef enum CFE_ConfigIdOffset_Enum +{ +@GENERATED_ID_MACRO_LIST@ + CFE_ConfigIdOffset_MAX +} CFE_ConfigIdOffset_Enum_t; + +#undef CFE_CONFIGID_DEFINE + +#endif /* CFE_CONFIGID_OFFSET_H */ diff --git a/modules/config/cmake/cfe_platform_cfg.c.in b/modules/config/cmake/cfe_platform_cfg.c.in new file mode 100644 index 000000000..0c8afcf9c --- /dev/null +++ b/modules/config/cmake/cfe_platform_cfg.c.in @@ -0,0 +1,21 @@ +#include +#include + +#include "cfe_config_core_internal.h" +#include "cfe_config_ids.h" +#include "cfe_config_set.h" + +#define ARRAY_NAME(a) CFE_CONFIG_ ## a ## _CONTENT +#define ARRAY_LEN(a) (sizeof(ARRAY_NAME(a)) / sizeof(ARRAY_NAME(a)[0])) + +#define CFE_PLATFORMCFG_ENTRY(x) {\ + static const CFE_Config_ArrayValue_t ARR_ ## x = { ARRAY_LEN(x), ARRAY_NAME(x) };\ + CFE_Config_SetArrayValue(CFE_CONFIGID_FROM_OFFSET(x), &ARR_ ## x);\ +} + +@PLATCFG_CONTENT@ + +void CFE_Config_SetupPlatformConfigInfo(void) +{ +@PLATCFG_LIST@ +} diff --git a/modules/config/cmake/create_cfe_platform_cfg.cmake b/modules/config/cmake/create_cfe_platform_cfg.cmake new file mode 100644 index 000000000..871c4cd21 --- /dev/null +++ b/modules/config/cmake/create_cfe_platform_cfg.cmake @@ -0,0 +1,5 @@ + +file(READ ${LIST_FILE} PLATCFG_LIST) +file(READ ${CONTENT_FILE} PLATCFG_CONTENT) + +configure_file(cfe_platform_cfg.c.in ${OUTPUT_FILE} @ONLY) diff --git a/modules/config/config_ids_base.cmake b/modules/config/config_ids_base.cmake new file mode 100644 index 000000000..ade046548 --- /dev/null +++ b/modules/config/config_ids_base.cmake @@ -0,0 +1,37 @@ +########################################################## +# +# CFE Configuration key names - base set +# +# These configuration keys are set via the FSW code +# as part of the basic init routine. They will be set +# to the same values on all CPUs. +# +########################################################## + +# Append the set of version description config keys +list(APPEND CFE_CONFIG_IDS + MISSION_NAME + MISSION_SRCVER + MISSION_EDS_DB + MISSION_SBINTF_DB + + CORE_VERSION_MAJOR + CORE_VERSION_MINOR + CORE_VERSION_REVISION + CORE_VERSION_MISSION_REV + CORE_VERSION_BUILDNUM + CORE_VERSION_BASELINE + CORE_VERSION_DESCRIPTION + + CORE_BUILDINFO_DATE + CORE_BUILDINFO_USER + CORE_BUILDINFO_HOST +) + +# Generate config ID for source version of modules that are included in the build +# NOTE: the presence in this list does not necesarily mean it will have a value at runtime, +# which may be the case for dynamic apps which are not loaded, for instance. +foreach(DEP ${MISSION_CORE_INTERFACES} ${MISSION_APPS} ${MISSION_CORE_MODULES} ${MISSION_PSPMODULES}) + string(TOUPPER "${DEP}" DEPNAME) + list(APPEND CFE_CONFIG_IDS MOD_SRCVER_${DEPNAME}) +endforeach() diff --git a/modules/config/fsw/inc/cfe_config_external.h b/modules/config/fsw/inc/cfe_config_external.h new file mode 100644 index 000000000..659aadba7 --- /dev/null +++ b/modules/config/fsw/inc/cfe_config_external.h @@ -0,0 +1,34 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Initialization for CFE configuration registry, external items + * + * These are generated from the build system, they are not directly set + */ + +#ifndef CFE_CONFIG_EXTERNAL_H +#define CFE_CONFIG_EXTERNAL_H + +#include "cfe_config_api_typedefs.h" + +void CFE_Config_SetupPlatformConfigInfo(void); + +#endif /* CFE_CONFIG_EXTERNAL_H */ diff --git a/modules/config/fsw/inc/cfe_config_init.h b/modules/config/fsw/inc/cfe_config_init.h new file mode 100644 index 000000000..0b262813d --- /dev/null +++ b/modules/config/fsw/inc/cfe_config_init.h @@ -0,0 +1,35 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Function declarations for items implemented in init.c + */ + +#ifndef CFE_CONFIG_INIT_H +#define CFE_CONFIG_INIT_H + +#include "cfe_config_api_typedefs.h" + +#include "cfe_config_ids.h" + +void CFE_Config_SetupBasicBuildInfo(void); +int32 CFE_Config_Init(void); + +#endif /* CFE_CONFIG_INIT_H */ diff --git a/modules/config/fsw/inc/cfe_config_lookup.h b/modules/config/fsw/inc/cfe_config_lookup.h new file mode 100644 index 000000000..ed62fb591 --- /dev/null +++ b/modules/config/fsw/inc/cfe_config_lookup.h @@ -0,0 +1,39 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Function declarations for items implemented in lookup.c + */ + +#ifndef CFE_CONFIG_LOOKUP_H +#define CFE_CONFIG_LOOKUP_H + +/* +** Includes +*/ +#include "cfe_config_api_typedefs.h" +#include "cfe_config_table.h" + +/** + * @brief Gets the value record associated with a config ID + */ +CFE_Config_ValueEntry_t *CFE_Config_LocateConfigRecordByID(CFE_ConfigId_t ConfigId); + +#endif /* CFE_CONFIG_LOOKUP_H */ diff --git a/modules/config/fsw/src/cfe_config_map.h b/modules/config/fsw/inc/cfe_config_nametable.h similarity index 87% rename from modules/config/fsw/src/cfe_config_map.h rename to modules/config/fsw/inc/cfe_config_nametable.h index 9f9f5ece3..ce55d65d5 100644 --- a/modules/config/fsw/src/cfe_config_map.h +++ b/modules/config/fsw/inc/cfe_config_nametable.h @@ -22,20 +22,19 @@ * This file contains the CFE configuration registry global data definitions. */ -#ifndef CFE_CONFIG_MAP_H -#define CFE_CONFIG_MAP_H +#ifndef CFE_CONFIG_NAMETABLE_H +#define CFE_CONFIG_NAMETABLE_H /* ** Includes */ -#include "common_types.h" -#include "cfe_config_ids.h" +#include "cfe_configid_offset.h" typedef struct CFE_Config_IdNameEntry { const char *Name; } CFE_Config_IdNameEntry_t; -extern const CFE_Config_IdNameEntry_t CFE_CONFIG_IDNAME_MAP[]; +extern const CFE_Config_IdNameEntry_t CFE_CONFIGID_NAMETABLE[]; #endif /* CFE_CONFIG_MAP_H */ diff --git a/modules/config/fsw/inc/cfe_config_set.h b/modules/config/fsw/inc/cfe_config_set.h new file mode 100644 index 000000000..061bf472e --- /dev/null +++ b/modules/config/fsw/inc/cfe_config_set.h @@ -0,0 +1,38 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Function declarations for items implemented in set.c + */ + +#ifndef CFE_CONFIG_SET_H +#define CFE_CONFIG_SET_H + +/* +** Includes +*/ +#include "cfe_config_api_typedefs.h" + +void CFE_Config_SetValue(CFE_ConfigId_t ConfigId, uint32 Value); +void CFE_Config_SetObjPointer(CFE_ConfigId_t ConfigId, const void *Ptr); +void CFE_Config_SetString(CFE_ConfigId_t ConfigId, const char *Ptr); +void CFE_Config_SetArrayValue(CFE_ConfigId_t ConfigId, const CFE_Config_ArrayValue_t *ArrayPtr); + +#endif /* CFE_CONFIG_SET_H */ diff --git a/modules/config/fsw/src/cfe_config_table.h b/modules/config/fsw/inc/cfe_config_table.h similarity index 95% rename from modules/config/fsw/src/cfe_config_table.h rename to modules/config/fsw/inc/cfe_config_table.h index 931319cb6..39269947c 100644 --- a/modules/config/fsw/src/cfe_config_table.h +++ b/modules/config/fsw/inc/cfe_config_table.h @@ -37,6 +37,7 @@ typedef enum CFE_ConfigType CFE_ConfigType_VALUE, /**< Value is an unsigned int */ CFE_ConfigType_STRING, /**< Value is a string pointer */ CFE_ConfigType_POINTER, /**< Value is a non-string object pointer */ + CFE_ConfigType_ARRAY, /**< Value is a combination of length and pointer */ } CFE_ConfigType_t; typedef union CFE_Config_ValueBuffer diff --git a/modules/config/fsw/src/cfe_config_get.c b/modules/config/fsw/src/cfe_config_get.c index ff98ec0e0..09595ca42 100644 --- a/modules/config/fsw/src/cfe_config_get.c +++ b/modules/config/fsw/src/cfe_config_get.c @@ -22,13 +22,16 @@ * API definition for configuration registry * * This defines the "getter" functions, which are publicly available + * + * @note The declaration for all functions in this file is in the "core_api" module, not here + * This file constitutes the entire externally-callable API for the config module. */ /* ** Required header files. */ #include "cfe_config_priv.h" -#include "cfe_config_map.h" +#include "cfe_config_nametable.h" #include "cfe_version.h" #include @@ -72,6 +75,26 @@ const void *CFE_Config_GetObjPointer(CFE_ConfigId_t ConfigId) return Entry->Datum.AsPointer; } +/*---------------------------------------------------------------- + * + * Defined per public API + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +CFE_Config_ArrayValue_t CFE_Config_GetArrayValue(CFE_ConfigId_t ConfigId) +{ + const CFE_Config_ValueEntry_t *Entry; + static CFE_Config_ArrayValue_t NULL_ARRAY = {0, NULL}; + + Entry = CFE_Config_LocateConfigRecordByID(ConfigId); + if (Entry == NULL || Entry->ActualType != CFE_ConfigType_ARRAY) + { + return NULL_ARRAY; + } + + return *((const CFE_Config_ArrayValue_t *)Entry->Datum.AsPointer); +} + /*---------------------------------------------------------------- * * Defined per public API @@ -108,7 +131,7 @@ const char *CFE_Config_GetName(CFE_ConfigId_t ConfigId) return CFE_Config_Global.UnknownString; } - return CFE_CONFIG_IDNAME_MAP[OffsetVal].Name; + return CFE_CONFIGID_NAMETABLE[OffsetVal].Name; } /*---------------------------------------------------------------- @@ -122,7 +145,7 @@ CFE_ConfigId_t CFE_Config_GetIdByName(const char *Name) const CFE_Config_IdNameEntry_t *NamePtr; uint32 OffsetVal; - NamePtr = CFE_CONFIG_IDNAME_MAP; + NamePtr = CFE_CONFIGID_NAMETABLE; for (OffsetVal = 0; OffsetVal < CFE_ConfigIdOffset_MAX; ++OffsetVal) { if (NamePtr->Name != NULL && strcmp(NamePtr->Name, Name) == 0) @@ -151,7 +174,7 @@ void CFE_Config_IterateAll(void *Arg, CFE_Config_Callback_t Callback) const CFE_Config_IdNameEntry_t *NamePtr; uint32 OffsetVal; - NamePtr = CFE_CONFIG_IDNAME_MAP; + NamePtr = CFE_CONFIGID_NAMETABLE; for (OffsetVal = 0; OffsetVal < CFE_ConfigIdOffset_MAX; ++OffsetVal) { if (CFE_Config_Global.Table[OffsetVal].ActualType != CFE_ConfigType_UNDEFINED) @@ -168,10 +191,9 @@ void CFE_Config_IterateAll(void *Arg, CFE_Config_Callback_t Callback) * See description in header file for argument/return detail * *-----------------------------------------------------------------*/ -void CFE_Config_GetVersionString(char *Buf, size_t Size, const char *Component, - const char *SrcVersion, const char *CodeName, const char *LastOffcRel) +void CFE_Config_GetVersionString(char *Buf, size_t Size, const char *Component, const char *SrcVersion, + const char *CodeName, const char *LastOffcRel) { - snprintf(Buf, Size, "%s %s %s (Codename %s), Last Official Release: %s %s)", - Component, CFE_REVISION == 0 ? "Development Build" : "Release", SrcVersion, - CodeName, Component, LastOffcRel); + snprintf(Buf, Size, "%s %s %s (Codename %s), Last Official Release: %s %s)", Component, + CFE_REVISION == 0 ? "Development Build" : "Release", SrcVersion, CodeName, Component, LastOffcRel); } diff --git a/modules/config/fsw/src/cfe_config_init.c b/modules/config/fsw/src/cfe_config_init.c index e8cee9cc4..bcb9aca71 100644 --- a/modules/config/fsw/src/cfe_config_init.c +++ b/modules/config/fsw/src/cfe_config_init.c @@ -27,9 +27,11 @@ #include "cfe_version.h" #include "target_config.h" -#include "cfe_config_map.h" +#include "cfe_config_nametable.h" #include "cfe_config_ids.h" +#include "cfe_config_external.h" + #include #include #include @@ -145,7 +147,7 @@ void CFE_Config_SetupModuleVersions(CFE_ConfigName_t *ModuleListSet[], size_t Se static const char IDNAME_PREFIX[] = "MOD_SRCVER_"; - NamePtr = CFE_CONFIG_IDNAME_MAP; + NamePtr = CFE_CONFIGID_NAMETABLE; for (OffsetVal = 0; OffsetVal < CFE_ConfigIdOffset_MAX; ++OffsetVal) { if (NamePtr->Name != NULL && strncmp(NamePtr->Name, IDNAME_PREFIX, sizeof(IDNAME_PREFIX) - 1) == 0) @@ -170,7 +172,7 @@ void CFE_Config_SetupModuleVersions(CFE_ConfigName_t *ModuleListSet[], size_t Se void CFE_Config_SetupBasicBuildInfo(void) { const char *KeyVal; - char VersionString[CFE_CFG_MAX_VERSION_STR_LEN]; + char VersionString[CFE_CFG_MAX_VERSION_STR_LEN]; /* Global mission name */ CFE_Config_SetString(CFE_CONFIGID_MISSION_NAME, GLOBAL_CONFIGDATA.MissionName); @@ -189,8 +191,8 @@ void CFE_Config_SetupBasicBuildInfo(void) CFE_Config_SetValue(CFE_CONFIGID_CORE_VERSION_BUILDNUM, CFE_BUILD_NUMBER); CFE_Config_SetString(CFE_CONFIGID_CORE_VERSION_BASELINE, CFE_BUILD_BASELINE); - CFE_Config_GetVersionString(VersionString, CFE_CFG_MAX_VERSION_STR_LEN, "cFE", - CFE_SRC_VERSION, CFE_BUILD_CODENAME, CFE_LAST_OFFICIAL); + CFE_Config_GetVersionString(VersionString, CFE_CFG_MAX_VERSION_STR_LEN, "cFE", CFE_SRC_VERSION, CFE_BUILD_CODENAME, + CFE_LAST_OFFICIAL); CFE_Config_SetString(CFE_CONFIGID_CORE_VERSION_DESCRIPTION, VersionString); /* @@ -225,6 +227,7 @@ int32 CFE_Config_Init(void) CFE_Config_SetupBasicBuildInfo(); CFE_Config_SetupModuleVersions(ModuleListSet, 2, GLOBAL_CONFIGDATA.ModuleVersionList); + CFE_Config_SetupPlatformConfigInfo(); return CFE_SUCCESS; } diff --git a/modules/config/fsw/src/cfe_config_priv.h b/modules/config/fsw/src/cfe_config_priv.h index dadd8ab4f..efa032fba 100644 --- a/modules/config/fsw/src/cfe_config_priv.h +++ b/modules/config/fsw/src/cfe_config_priv.h @@ -33,6 +33,10 @@ #include "cfe_config.h" #include "target_config.h" +#include "cfe_config_init.h" +#include "cfe_config_lookup.h" +#include "cfe_config_set.h" + /* * Actual definition of the config registry table * @@ -53,6 +57,14 @@ extern CFE_Config_Global_t CFE_Config_Global; ****************************** */ +bool CFE_Config_StrCaseEq(const char *c1, const char *c2); +const char *CFE_Config_FindTargetKeyValue(CFE_ConfigKeyValue_t *ConfigList, const char *KeyName); +const char *CFE_Config_IsModuleInList(CFE_ConfigName_t *ModuleListPtr, const char *ModuleName); +const char *CFE_Config_IsPspModule(CFE_StaticModuleLoadEntry_t *PspModuleList, const char *ModuleName); +const char *CFE_Config_FindStaticModName(CFE_ConfigName_t *ModuleListSet[], size_t SetLength, const char *ModuleName); +void CFE_Config_SetupModuleVersions(CFE_ConfigName_t *ModuleListSet[], size_t SetLength, + CFE_ConfigKeyValue_t *ActiveList); + /** * @brief Converts a configuration ID to a table index * @@ -80,19 +92,4 @@ static inline CFE_ConfigId_t CFE_Config_OffsetToId(uint32 OffsetVal) return CFE_CONFIGID_C(CFE_ResourceId_FromInteger(CFE_CONFIGID_BASE + OffsetVal)); } -bool CFE_Config_StrCaseEq(const char *c1, const char *c2); -const char *CFE_Config_FindTargetKeyValue(CFE_ConfigKeyValue_t *ConfigList, const char *KeyName); -const char *CFE_Config_IsModuleInList(CFE_ConfigName_t *ModuleListPtr, const char *ModuleName); -const char *CFE_Config_IsPspModule(CFE_StaticModuleLoadEntry_t *PspModuleList, const char *ModuleName); -const char *CFE_Config_FindStaticModName(CFE_ConfigName_t *ModuleListSet[], size_t SetLength, const char *ModuleName); - -void CFE_Config_SetupModuleVersions(CFE_ConfigName_t *ModuleListSet[], size_t SetLength, - CFE_ConfigKeyValue_t *ActiveList); -void CFE_Config_SetupBasicBuildInfo(void); - -/** - * @brief Gets the value record associated with a config ID - */ -CFE_Config_ValueEntry_t *CFE_Config_LocateConfigRecordByID(CFE_ConfigId_t ConfigId); - #endif /* CFE_CONFIG_PRIV_H */ diff --git a/modules/config/fsw/src/cfe_config_set.c b/modules/config/fsw/src/cfe_config_set.c index 579452d06..0d8b16d28 100644 --- a/modules/config/fsw/src/cfe_config_set.c +++ b/modules/config/fsw/src/cfe_config_set.c @@ -65,6 +65,24 @@ void CFE_Config_SetObjPointer(CFE_ConfigId_t ConfigId, const void *Ptr) } } +/*---------------------------------------------------------------- + * + * CFE core internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_Config_SetArrayValue(CFE_ConfigId_t ConfigId, const CFE_Config_ArrayValue_t *ArrayPtr) +{ + CFE_Config_ValueEntry_t *Entry; + + Entry = CFE_Config_LocateConfigRecordByID(ConfigId); + if (Entry != NULL) + { + Entry->ActualType = CFE_ConfigType_ARRAY; + Entry->Datum.AsPointer = ArrayPtr; + } +} + /*---------------------------------------------------------------- * * CFE core internal function diff --git a/modules/config/mission_build.cmake b/modules/config/mission_build.cmake index c79774c46..6027fa736 100644 --- a/modules/config/mission_build.cmake +++ b/modules/config/mission_build.cmake @@ -9,55 +9,49 @@ ########################################################### # Generate the complete list of configuration ids +# Start with an empty list - will be appended by various files set(CFE_CONFIG_IDS) -set(GENERATED_ENUM_OFFSET_LIST) -set(GENERATED_CONSTANT_DEFINE_LIST) -set(GENERATED_IDNAME_MAP_LIST) - -# Append the set of version description config keys -list(APPEND CFE_CONFIG_IDS - MISSION_NAME - MISSION_SRCVER - MISSION_EDS_DB - MISSION_SBINTF_DB - - CORE_VERSION_MAJOR - CORE_VERSION_MINOR - CORE_VERSION_REVISION - CORE_VERSION_MISSION_REV - CORE_VERSION_BUILDNUM - CORE_VERSION_BASELINE - CORE_VERSION_DESCRIPTION - - CORE_BUILDINFO_DATE - CORE_BUILDINFO_USER - CORE_BUILDINFO_HOST -) - -# Generate config ID for source version of modules that are included in the build -# NOTE: the presence in this list does not necesarily mean it will have a value at runtime, -# which may be the case for dynamic apps which are not loaded, for instance. -foreach(DEP ${MISSION_CORE_INTERFACES} ${MISSION_APPS} ${MISSION_CORE_MODULES} ${MISSION_PSPMODULES}) - string(TOUPPER "${DEP}" DEPNAME) - list(APPEND CFE_CONFIG_IDS MOD_SRCVER_${DEPNAME}) -endforeach() -# Append any mission-defined config keys -# this may further extend the list of IDs +# Get the base set of config IDs from a separate file +# This baseline set is based on build time config and will be the same +# on all CFE instances produced by this build. +include(${CMAKE_CURRENT_LIST_DIR}/config_ids_base.cmake) + +# Get the set of config IDs that are generated via the platform config tool. +# These are set to values based on platform config and may be different on +# the different CFE instances. To accomplish this, an intermediate translation +# tool must be used - this resides in the "tool" directory. +include(${CMAKE_CURRENT_LIST_DIR}/tool/config_ids_dynamic.cmake) + +# Append any mission-specific config IDs. This is done last so it does +# not change the order of items in the first two lists. include(${MISSIONCONFIG}/config_ids_custom.cmake OPTIONAL) +# Now generate header and source files containing the ID tables +# This includes an enum, and enum to string name table, and a set +# of constants to use in runtime FSW code. +set(GENERATED_ID_MACRO_LIST) +set(GENERATED_CONSTANT_DEFINE_LIST) + foreach(CFGID ${CFE_CONFIG_IDS}) - list(APPEND GENERATED_ENUM_OFFSET_LIST " CFE_ConfigIdOffset_${CFGID},\n") - list(APPEND GENERATED_IDNAME_MAP_LIST " [CFE_ConfigIdOffset_${CFGID}] = { \"${CFGID}\" },\n") - list(APPEND GENERATED_CONSTANT_DEFINE_LIST "#define CFE_CONFIGID_${CFGID} CFE_CONFIGID_C(CFE_ResourceId_FromInteger(CFE_CONFIGID_BASE + CFE_ConfigIdOffset_${CFGID}))\n") + list(APPEND GENERATED_ID_MACRO_LIST "CFE_CONFIGID_DEFINE(${CFGID})\n") + list(APPEND GENERATED_CONSTANT_DEFINE_LIST "#define CFE_CONFIGID_${CFGID} CFE_CONFIGID_FROM_OFFSET(${CFGID})\n") endforeach() -string(CONCAT GENERATED_ENUM_OFFSET_LIST ${GENERATED_ENUM_OFFSET_LIST}) +string(CONCAT GENERATED_ID_MACRO_LIST ${GENERATED_ID_MACRO_LIST}) string(CONCAT GENERATED_CONSTANT_DEFINE_LIST ${GENERATED_CONSTANT_DEFINE_LIST}) -string(CONCAT GENERATED_IDNAME_MAP_LIST ${GENERATED_IDNAME_MAP_LIST}) -# Write header file for config IDs -configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cfe_config_ids.h.in ${CMAKE_BINARY_DIR}/inc/cfe_config_ids.h) +# Write header file for config offsets - this is the basic enumeration (symbols mapped to 0-based integers) +# This is a simple list and does not need any other headers, and can be used by the platform config tool +configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cfe_configid_offset.h.in ${CMAKE_BINARY_DIR}/inc/cfe_configid_offset.h @ONLY) + +# Write source file for enum to string mapping - this allows the software to print the config item by name +# this is a simple lookup table based on the enum, so it can also be used by FSW and the platform config tool +configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cfe_configid_nametable.c.in ${CMAKE_BINARY_DIR}/src/cfe_configid_nametable.c @ONLY) + +# Write header file for config IDs - this is the FSW runtime identifier (resourceID) based on the enum above +# however - it requires the full set of FSW headers, so it cannot be used by the platform config tool +configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cfe_config_ids.h.in ${CMAKE_BINARY_DIR}/inc/cfe_config_ids.h @ONLY) -# Write constant map list for config IDs -configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/cfe_config_map.c.in ${CMAKE_BINARY_DIR}/src/cfe_config_map.c) +# Add the subdirectory for the intermediate tool that allows platform-speicific data to included with the config +add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tool cfeconfig_platformdata_tool) diff --git a/modules/config/tool/CMakeLists.txt b/modules/config/tool/CMakeLists.txt new file mode 100644 index 000000000..491b2bd77 --- /dev/null +++ b/modules/config/tool/CMakeLists.txt @@ -0,0 +1,82 @@ +########################################################## +# +# CFE Platform Configuration tool +# +# The purpose of this tool is to act as an intermediate step +# to generate platform-specific config item definitions. This +# is built for the dev host (not cross compiled) and executed +# on the build host during the build to generate objects that +# are then used later during the target (cross) builds. +# +########################################################## + +include_directories(${CMAKE_BINARY_DIR}/inc) +include_directories(../fsw/inc) + +set(SYM_PREFIX CFECONFIG_PLATFORMDATA) + +set(PLATFORM_CONFIG_LIST) +set(PLATFORM_OBJ_NAMES) + +foreach(SYSVAR ${TGTSYS_LIST}) + + # Decode the SYSVAR value to get the arch-specific build dir + # (note this gets compiled at mission scope, so CMAKE_BUILD_DIR + # refers to the top level build, not the cross build) + decode_targetsystem(${SYSVAR} + OUTPUT_ARCH_BINARY_DIR TEMP_ARCH_BINARY_DIR + ) + + set(OBJECT_NAME ${SYM_PREFIX}_${SYSVAR}) + + # add an OBJECT library for the platform-specific config data + # This always uses the same .c file for every platform, but the + # include path is changed for each one so it gets the appropriate + # cfe_platform_cfg.h file. + string(TOLOWER ${OBJECT_NAME} OBJLIB_NAME) + add_library(${OBJLIB_NAME} OBJECT + cfeconfig_platformdata_table.c + ) + target_compile_definitions(${OBJLIB_NAME} PRIVATE + MAP_ENTRY_LIST=${OBJECT_NAME} + ) + target_include_directories(${OBJLIB_NAME} PRIVATE + ${TEMP_ARCH_BINARY_DIR}/inc + ) + + set(PLATFORM_DEFINE_FILE ${MISSION_BINARY_DIR}/src/${OBJLIB_NAME}.c) + set(PLATFORM_LIST_FILE ${MISSION_BINARY_DIR}/src/${OBJLIB_NAME}.list) + list(APPEND PLATFORM_CONFIG_LIST $) + list(APPEND PLATFORM_OBJ_NAMES "CFE_PLATFORM(${SYSVAR})") + + add_custom_command( + OUTPUT ${PLATFORM_DEFINE_FILE} + COMMAND cfeconfig_platformdata_tool initcode ${SYSVAR} > ${PLATFORM_DEFINE_FILE} + DEPENDS cfeconfig_platformdata_tool + ) + + add_custom_command( + OUTPUT ${PLATFORM_LIST_FILE} + COMMAND cfeconfig_platformdata_tool entrylist ${SYSVAR} > ${PLATFORM_LIST_FILE} + DEPENDS cfeconfig_platformdata_tool + ) + + add_custom_target(cfgtool-execute-${SYSVAR} DEPENDS ${PLATFORM_DEFINE_FILE} ${PLATFORM_LIST_FILE}) + add_dependencies(mission-prebuild cfgtool-execute-${SYSVAR}) + +endforeach(SYSVAR ${TGTSYS_LIST}) + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cfe_platform_list.c.in ${CMAKE_BINARY_DIR}/src/cfe_platform_list.c) + +add_executable(cfeconfig_platformdata_tool + cfeconfig_platformdata_tool.c + ${CMAKE_BINARY_DIR}/src/cfe_configid_nametable.c + ${CMAKE_BINARY_DIR}/src/cfe_platform_list.c + ${PLATFORM_CONFIG_LIST} +) + +target_include_directories(cfeconfig_platformdata_tool PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_dependencies(mission-prebuild cfeconfig_platformdata_tool) \ No newline at end of file diff --git a/modules/config/tool/cfeconfig_platformdata_table.c b/modules/config/tool/cfeconfig_platformdata_table.c new file mode 100644 index 000000000..b148a87de --- /dev/null +++ b/modules/config/tool/cfeconfig_platformdata_table.c @@ -0,0 +1,93 @@ + +#include "cfeconfig_platformdata_tool.h" + +#include + +/* + * To prevent name collisions, this table should be named using a platform-specific name. + * This can be done by setting a custom macro definition for this symbol. If this fails, + * it points to a bug in the cmake script which is supposed to set that up. + */ +#ifndef MAP_ENTRY_LIST +#error MAP_ENTRY_LIST should be defined to a platform-specific symbol in this file +#endif + +/* Historical backward compatibility items, do not use if OMIT_DEPRECATED is set */ +#ifndef CFE_OMIT_DEPRECATED + +/* Originally SB did not have its own number of buckets, it simply used the ES value */ +#ifndef CFE_PLATFORM_SB_POOL_MAX_BUCKETS +#define CFE_PLATFORM_SB_POOL_MAX_BUCKETS CFE_PLATFORM_ES_POOL_MAX_BUCKETS +#endif + +/* + * These table items were allowed to be undefined, + * which had the same effect as defining it as 0 + */ +#if !defined(CFE_PLATFORM_TBL_VALID_SCID_COUNT) +#define CFE_PLATFORM_TBL_VALID_SCID_COUNT 0 +#endif + +#if !defined(CFE_PLATFORM_TBL_VALID_PRID_COUNT) +#define CFE_PLATFORM_TBL_VALID_PRID_COUNT 0 +#endif + +#endif + +/* + * NOTE: The CONFIG_ID type/constants cannot be used here, as that is a CFE-defined type (resourceid) + * and thus would necessitate the full set of CFE core API headers. But as this is the global/mission + * scope and not platform scope, the latter is not available. + */ + +CFE_ConfigTool_DetailEntry_t MAP_ENTRY_LIST[] = { + { + .render_style = CFE_ConfigTool_RenderStyle_ARRAY, + .ido = CFE_ConfigIdOffset_PLATFORM_TBL_VALID_SCID, + .u.list = + { + .prefix = "CFE_PLATFORM_TBL_VALID_SCID", + .type_name = "uint32_t", + .num_entries = CFE_PLATFORM_TBL_VALID_SCID_COUNT, + }, + }, + { + .render_style = CFE_ConfigTool_RenderStyle_ARRAY, + .ido = CFE_ConfigIdOffset_PLATFORM_TBL_VALID_PRID, + .u.list = + { + .prefix = "CFE_PLATFORM_TBL_VALID_PRID", + .type_name = "uint32_t", + .num_entries = CFE_PLATFORM_TBL_VALID_PRID_COUNT, + }, + }, + { + .render_style = CFE_ConfigTool_RenderStyle_ARRAY, + .ido = CFE_ConfigIdOffset_PLATFORM_ES_MEM_BLOCK_SIZE, + .u.list = {.prefix = "CFE_PLATFORM_ES_MEM_BLOCK_SIZE", + .type_name = "size_t", + .num_entries = CFE_PLATFORM_ES_POOL_MAX_BUCKETS, + .custom_max = "CFE_PLATFORM_ES_MAX_BLOCK_SIZE", + .options = CFE_CONFIGTOOL_LIST_DESCENDING | CFE_CONFIGTOOL_USE_LEADING_ZERO}, + }, + { + .render_style = CFE_ConfigTool_RenderStyle_ARRAY, + .ido = CFE_ConfigIdOffset_PLATFORM_ES_CDS_MEM_BLOCK_SIZE, + .u.list = {.prefix = "CFE_PLATFORM_ES_CDS_MEM_BLOCK_SIZE", + .type_name = "size_t", + .num_entries = CFE_PLATFORM_ES_POOL_MAX_BUCKETS, + .custom_max = "CFE_PLATFORM_ES_CDS_MAX_BLOCK_SIZE", + .options = CFE_CONFIGTOOL_LIST_DESCENDING | CFE_CONFIGTOOL_USE_LEADING_ZERO}, + }, + { + .render_style = CFE_ConfigTool_RenderStyle_ARRAY, + .ido = CFE_ConfigIdOffset_PLATFORM_SB_MEM_BLOCK_SIZE, + .u.list = {.prefix = "CFE_PLATFORM_SB_MEM_BLOCK_SIZE", + .type_name = "size_t", + .num_entries = CFE_PLATFORM_SB_POOL_MAX_BUCKETS, + .custom_max = "CFE_PLATFORM_SB_MAX_BLOCK_SIZE", + .options = CFE_CONFIGTOOL_LIST_DESCENDING | CFE_CONFIGTOOL_USE_LEADING_ZERO}, + }, + + {0} /* Keep this last */ +}; diff --git a/modules/config/tool/cfeconfig_platformdata_tool.c b/modules/config/tool/cfeconfig_platformdata_tool.c new file mode 100644 index 000000000..162b21b09 --- /dev/null +++ b/modules/config/tool/cfeconfig_platformdata_tool.c @@ -0,0 +1,292 @@ +#include "cfeconfig_platformdata_tool.h" + +#include "cfe_config_nametable.h" + +#include +#include +#include +#include +#include +#include + +#define MAX_INSTANCE_NAME_LEN 64 + +typedef void (*CFE_ConfigTool_RenderFunc_t)(const char *, const CFE_ConfigTool_DetailBuffer_t *); + +/*---------------------------------------------------------------- + * + * Prints command line usage information + * + *-----------------------------------------------------------------*/ +void CFE_ConfigTool_PrintUsage(const char *cmd) +{ + fprintf(stderr, "Usage: %s [(entrylist|initcode) platform_name]\n\n", cmd); + fprintf(stderr, "If executed without any arguments, generate a list of platform names\n"); + fprintf(stderr, "If a platform name is given on command line,\n"); + fprintf(stderr, " initcode: generates a \"C\" source chunk for that platform\n"); + fprintf(stderr, " entrylist: generate \"C\" macros for valid entries on that platform\n\n"); +} + +/*---------------------------------------------------------------- + * + * Renders content structure for a List/Array style platform config entry + * + *-----------------------------------------------------------------*/ +void CFE_ConfigTool_RenderListContent(const char *prefix, const CFE_ConfigTool_ListDetail_t *detail_ptr) +{ + char entry_string[MAX_INSTANCE_NAME_LEN]; + int i; + int idv; + int width; + + bool is_reverse = detail_ptr->options & CFE_CONFIGTOOL_LIST_DESCENDING; + bool use_leading_zero = detail_ptr->options & CFE_CONFIGTOOL_USE_LEADING_ZERO; + + width = 1; + if (use_leading_zero) + { + i = detail_ptr->num_entries; + while (i >= 10) + { + i /= 10; + ++width; + } + } + + snprintf(entry_string, sizeof(entry_string), "CFE_CONFIG_%s_CONTENT", prefix); + + printf("static const %s %s[%zu] = {\n", detail_ptr->type_name, entry_string, detail_ptr->num_entries); + + i = detail_ptr->num_entries; + idv = 0; + while (i > 0) + { + if (is_reverse) + { + idv = i; + } + + --i; + + if (!is_reverse) + { + idv = detail_ptr->num_entries - i; + } + + if (idv == detail_ptr->num_entries && detail_ptr->custom_max != NULL) + { + /* it is the "max" */ + snprintf(entry_string, sizeof(entry_string), "%s", detail_ptr->custom_max); + } + else + { + snprintf(entry_string, sizeof(entry_string), "CFE_%s_%0*d", prefix, width, idv); + } + + printf(" %s%c\n", entry_string, (i == 0) ? ' ' : ','); + } + + printf("};\n\n"); +} + +/*---------------------------------------------------------------- + * + * Gets the rendering function for a given detail entry + * If output should not be rendered at all, returns NULL. + * + *-----------------------------------------------------------------*/ +CFE_ConfigTool_RenderFunc_t CFE_ConfigTool_GetRenderFunc(const CFE_ConfigTool_DetailEntry_t *cfgid_p) +{ + CFE_ConfigTool_RenderFunc_t result; + + result = NULL; + if (cfgid_p->render_style == CFE_ConfigTool_RenderStyle_ARRAY) + { + /* An array with size of 0 is allowed config-wise but should not be rendered, + * as it will be a compile error. Just skip it entirely. */ + if (cfgid_p->u.list.num_entries > 0) + { + result = (CFE_ConfigTool_RenderFunc_t)CFE_ConfigTool_RenderListContent; + } + } + + return result; +} + +/*---------------------------------------------------------------- + * + * Gets the printable name from a config ID offset + * If the offset is not valid, returns NULL. + * + *-----------------------------------------------------------------*/ +const char *CFE_ConfigTool_GetNameFromOffset(CFE_ConfigIdOffset_Enum_t offset) +{ + const char *result; + + if (offset > 0 && offset < CFE_ConfigIdOffset_MAX) + { + result = CFE_CONFIGID_NAMETABLE[offset].Name; + } + else + { + result = NULL; + } + + return result; +} + +/*---------------------------------------------------------------- + * + * Finds the detail list for the given platform name. + * If the plaform name is not valid, returns NULL. + * + *-----------------------------------------------------------------*/ +const CFE_ConfigTool_DetailEntry_t *CFE_ConfigTool_FindDetailByName(const char *name) +{ + const CFE_ConfigTool_PlatformMapEntry_t *platform_ptr; + const CFE_ConfigTool_DetailEntry_t * result_ptr; + + platform_ptr = CFECONFIG_PLATFORMDATA_TABLE; + result_ptr = NULL; + while (platform_ptr->plat_name != NULL) + { + if (strcasecmp(platform_ptr->plat_name, name) == 0) + { + result_ptr = platform_ptr->detail_ptr; + break; + } + + ++platform_ptr; + } + + return result_ptr; +} + +/*---------------------------------------------------------------- + * + * Renders the full content structure for a given platform name + * Returns true if successful, or false if it is not able to be rendered + * + *-----------------------------------------------------------------*/ +bool CFE_ConfigTool_WritePlatformCfg(const char *plat_name) +{ + const CFE_ConfigTool_DetailEntry_t *detail_ptr; + CFE_ConfigTool_RenderFunc_t render_func; + + detail_ptr = CFE_ConfigTool_FindDetailByName(plat_name); + if (detail_ptr == NULL) + { + fprintf(stderr, "%s: platform undefined\n", plat_name); + return false; + } + + printf("/* THIS IS GENERATED CONTENT, DO NOT EDIT */\n\n"); + + while (detail_ptr->render_style != CFE_ConfigTool_RenderStyle_NONE) + { + render_func = CFE_ConfigTool_GetRenderFunc(detail_ptr); + + if (render_func != NULL) + { + render_func(CFE_ConfigTool_GetNameFromOffset(detail_ptr->ido), &detail_ptr->u); + } + ++detail_ptr; + } + + return true; +} + +/*---------------------------------------------------------------- + * + * Prints a list of config ID entries that are valid for the given platform + * + *-----------------------------------------------------------------*/ +bool CFE_ConfigTool_WriteValidEntries(const char *plat_name) +{ + const CFE_ConfigTool_DetailEntry_t *detail_ptr; + const char * cfgname; + + detail_ptr = CFE_ConfigTool_FindDetailByName(plat_name); + if (detail_ptr == NULL) + { + fprintf(stderr, "%s: platform undefined\n", plat_name); + return false; + } + + printf("/* THIS IS GENERATED CONTENT, DO NOT EDIT */\n\n"); + + /* For the purpose of writing names, just use the first platform entry - + * they will all be the same in this context, as this only uses names, not values */ + while (detail_ptr->render_style != CFE_ConfigTool_RenderStyle_NONE) + { + /* + * Checking the render function - in that if the content wasn't rendered, the + * reference to it should not be rendered, either (for example an array with 0 entries). + */ + if (CFE_ConfigTool_GetRenderFunc(detail_ptr) != NULL) + { + cfgname = CFE_ConfigTool_GetNameFromOffset(detail_ptr->ido); + if (cfgname != NULL) + { + printf("CFE_PLATFORMCFG_ENTRY(%s)\n", cfgname); + } + } + ++detail_ptr; + } + + return true; +} + +/*---------------------------------------------------------------- + * + * Writes the names of all platforms known to the tool + * + *-----------------------------------------------------------------*/ +void CFE_ConfigTool_WritePlatformNames(void) +{ + const CFE_ConfigTool_PlatformMapEntry_t *platform_ptr; + + platform_ptr = CFECONFIG_PLATFORMDATA_TABLE; + while (platform_ptr->plat_name != NULL) + { + printf("CFE_PLATFORM_NAME(%s)\n", platform_ptr->plat_name); + ++platform_ptr; + } +} + +/*---------------------------------------------------------------- + * + * Main routine + * + *-----------------------------------------------------------------*/ +int main(int argc, char *argv[]) +{ + bool success; + + success = false; + + if (argc == 1) + { + CFE_ConfigTool_WritePlatformNames(); + success = true; + } + else if (argc == 3) + { + if (strcasecmp(argv[1], "entrylist") == 0) + { + success = CFE_ConfigTool_WriteValidEntries(argv[2]); + } + else if (strcasecmp(argv[1], "initcode") == 0) + { + success = CFE_ConfigTool_WritePlatformCfg(argv[2]); + } + } + + if (!success) + { + CFE_ConfigTool_PrintUsage(argv[0]); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} \ No newline at end of file diff --git a/modules/config/tool/cfeconfig_platformdata_tool.h b/modules/config/tool/cfeconfig_platformdata_tool.h new file mode 100644 index 000000000..011835b0f --- /dev/null +++ b/modules/config/tool/cfeconfig_platformdata_tool.h @@ -0,0 +1,52 @@ +/* This file needs to reference the platform-specific configuration */ + +#ifndef CFECONFIG_PLATFORMDATA_TOOL_H +#define CFECONFIG_PLATFORMDATA_TOOL_H + +/* NOTE: this header is generated by the build scripts, from the list of config IDs */ +#include "cfe_configid_offset.h" + +#include + +#define CFE_CONFIGTOOL_LIST_ASCENDING 0x00 +#define CFE_CONFIGTOOL_LIST_DESCENDING 0x01 +#define CFE_CONFIGTOOL_USE_LEADING_ZERO 0x02 + +typedef enum CFE_ConfigTool_RenderStyle_Enum +{ + CFE_ConfigTool_RenderStyle_NONE, + CFE_ConfigTool_RenderStyle_ARRAY +} CFE_ConfigTool_RenderStyle_Enum_t; + +typedef struct CFE_ConfigTool_ListDetail +{ + const char * prefix; + const char * type_name; + size_t num_entries; + const char * custom_max; + unsigned long options; +} CFE_ConfigTool_ListDetail_t; + +typedef union CFE_ConfigTool_DetailBuffer +{ + CFE_ConfigTool_ListDetail_t list; +} CFE_ConfigTool_DetailBuffer_t; + +typedef struct CFE_ConfigTool_DetailEntry +{ + CFE_ConfigTool_RenderStyle_Enum_t render_style; + CFE_ConfigIdOffset_Enum_t ido; + + CFE_ConfigTool_DetailBuffer_t u; +} CFE_ConfigTool_DetailEntry_t; + +typedef struct CFE_ConfigTool_PlatformMapEntry +{ + const char *plat_name; + + const CFE_ConfigTool_DetailEntry_t *detail_ptr; +} CFE_ConfigTool_PlatformMapEntry_t; + +extern const CFE_ConfigTool_PlatformMapEntry_t CFECONFIG_PLATFORMDATA_TABLE[]; + +#endif /* CFECONFIG_PLATFORMDATA_TOOL_H */ diff --git a/modules/config/tool/cmake/cfe_platform_list.c.in b/modules/config/tool/cmake/cfe_platform_list.c.in new file mode 100644 index 000000000..75e9d78ee --- /dev/null +++ b/modules/config/tool/cmake/cfe_platform_list.c.in @@ -0,0 +1,14 @@ +/* This file is auto-generated from CMake build system. Do not manually edit! */ +#include "cfeconfig_platformdata_tool.h" + +#undef CFE_PLATFORM +#define CFE_PLATFORM(x) extern const CFE_ConfigTool_DetailEntry_t @SYM_PREFIX@_ ## x[]; +@PLATFORM_OBJ_NAMES@ + +#undef CFE_PLATFORM +#define CFE_PLATFORM(x) { #x, @SYM_PREFIX@_ ## x }, +const CFE_ConfigTool_PlatformMapEntry_t CFECONFIG_PLATFORMDATA_TABLE[] = +{ +@PLATFORM_OBJ_NAMES@ + { NULL } +}; diff --git a/modules/config/tool/config_ids_dynamic.cmake b/modules/config/tool/config_ids_dynamic.cmake new file mode 100644 index 000000000..8c0964582 --- /dev/null +++ b/modules/config/tool/config_ids_dynamic.cmake @@ -0,0 +1,22 @@ +########################################################## +# +# CFE Configuration key names - dynamic set +# +# These configuration keys are set via the FSW code +# with the aid of the platform configuration tool, and +# are set according to the platform config parameters. +# They may be set differently on each CPU. +# +########################################################## + +# These "List" items are generated from platform config +# These need to be set dynamically from the tool based on +# the configurable list size. The list size and the initializers +# have to match, so they cannot be hardcoded. +list(APPEND CFE_CONFIG_IDS + PLATFORM_TBL_VALID_SCID + PLATFORM_TBL_VALID_PRID + PLATFORM_ES_MEM_BLOCK_SIZE + PLATFORM_ES_CDS_MEM_BLOCK_SIZE + PLATFORM_SB_MEM_BLOCK_SIZE +) diff --git a/modules/config/ut-coverage/CMakeLists.txt b/modules/config/ut-coverage/CMakeLists.txt index bb4ba20b4..6e9b16677 100644 --- a/modules/config/ut-coverage/CMakeLists.txt +++ b/modules/config/ut-coverage/CMakeLists.txt @@ -9,14 +9,19 @@ foreach(SRC ${config_SOURCES}) list(APPEND UT_SOURCES "${CFE_CONFIG_SOURCE_DIR}/${SRC}") endforeach() +add_cfe_coverage_stubs(cfe_config_internal + ut-stubs/cfe_config_init_stubs.c + ut-stubs/cfe_config_external_stubs.c + ut-stubs/cfe_config_lookup_stubs.c + ut-stubs/cfe_config_set_stubs.c +) + +target_include_directories(coverage-cfe_config_internal-stubs PUBLIC ../fsw/inc ../fsw/src) +target_link_libraries(coverage-cfe_config_internal-stubs ut_core_api_stubs ut_core_private_stubs) + add_cfe_coverage_test(config ALL "test_cfe_config.c" "${UT_SOURCES}" ) -# This permits UT test cases to directly access private headers in the fsw/src dir -target_include_directories(coverage-config-ALL-testrunner PRIVATE - ${CFE_CONFIG_SOURCE_DIR}/fsw/src -) - -target_link_libraries(coverage-config-ALL-testrunner ut_core_private_stubs) +add_cfe_coverage_dependency(config ALL cfe_config_internal) diff --git a/modules/config/ut-coverage/test_cfe_config.c b/modules/config/ut-coverage/test_cfe_config.c index 4c83f02cd..4ae47fdf7 100644 --- a/modules/config/ut-coverage/test_cfe_config.c +++ b/modules/config/ut-coverage/test_cfe_config.c @@ -21,7 +21,7 @@ */ #include "cfe_config.h" #include "cfe_config_priv.h" -#include "cfe_config_map.h" +#include "cfe_config_nametable.h" #include "utassert.h" #include "utstubs.h" @@ -29,20 +29,30 @@ #include "ut_support.h" -const CFE_Config_IdNameEntry_t CFE_CONFIG_IDNAME_MAP[CFE_ConfigIdOffset_MAX] = {{"UT_CHECK_1"}, - {"UT_CHECK_2"}, - {"UT_CHECK_3"}, - {"UT_CHECK_4"}, - {"MOD_SRCVER_COREMODULE1"}, - {"MOD_SRCVER_COREMODULE2"}}; +/* clang-format off */ +const CFE_Config_IdNameEntry_t CFE_CONFIGID_NAMETABLE[CFE_ConfigIdOffset_MAX] = +{ + {"UT_CHECK_1"}, + {"UT_CHECK_2"}, + {"UT_CHECK_3"}, + {"UT_CHECK_4"}, + {"MOD_SRCVER_COREMODULE1"}, + {"MOD_SRCVER_COREMODULE2"} +}; +/* clang-format on */ #define CFE_CONFIGID_UT_CHECK_1 CFE_CONFIGID_C(CFE_RESOURCEID_WRAP(CFE_CONFIGID_BASE + 0)) #define CFE_CONFIGID_UT_CHECK_2 CFE_CONFIGID_C(CFE_RESOURCEID_WRAP(CFE_CONFIGID_BASE + 1)) #define CFE_CONFIGID_UT_CHECK_3 CFE_CONFIGID_C(CFE_RESOURCEID_WRAP(CFE_CONFIGID_BASE + 2)) #define CFE_CONFIGID_UT_CHECK_4 CFE_CONFIGID_C(CFE_RESOURCEID_WRAP(CFE_CONFIGID_BASE + 3)) +#define CFE_CONFIGID_UT_CHECK_5 CFE_CONFIGID_C(CFE_RESOURCEID_WRAP(CFE_CONFIGID_BASE + 4)) const char UT_UNKNOWN_STR[] = "UT-Unknown"; const char UT_VALUE_STR[] = "UT-Value"; + +const uint32 UT_ARR_ELEMENTS[4] = {1, 2, 3, 4}; +const CFE_Config_ArrayValue_t UT_ARRAY = {4, UT_ARR_ELEMENTS}; + const struct { uint16 val; @@ -80,6 +90,40 @@ void Test_CFE_Config_GetObjPointer(void) UtAssert_NULL(CFE_Config_GetObjPointer(CFE_CONFIGID_UT_CHECK_4)); } +void Test_CFE_Config_GetArrayValue(void) +{ + /* + * Test case for: + * CFE_Config_ArrayValue_t CFE_Config_GetArrayValue(CFE_ConfigId_t ConfigId) + */ + + CFE_Config_ArrayValue_t ArrVal; + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UNDEFINED); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_1); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_2); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_3); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_4); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_5); + UtAssert_EQ(size_t, ArrVal.NumElements, UT_ARRAY.NumElements); + UtAssert_ADDRESS_EQ(ArrVal.ElementPtr, UT_ARRAY.ElementPtr); +} + void Test_CFE_Config_GetString(void) { /* @@ -119,6 +163,28 @@ void Test_CFE_Config_SetObjPointer(void) UtAssert_ADDRESS_EQ(CFE_Config_GetObjPointer(CFE_CONFIGID_UT_CHECK_4), TESTOBJ); } +void Test_CFE_Config_SetArrayValue(void) +{ + /* + * Test case for: + * void CFE_Config_SetArrayValue(CFE_ConfigId_t ConfigId, const CFE_Config_ArrayValue_t *ArrayPtr) + */ + static uint16 TESTARR[] = {5, 6, 7, 8, 9, 10}; + static CFE_Config_ArrayValue_t TESTOBJ = {6, TESTARR}; + CFE_Config_ArrayValue_t ArrVal; + + UtAssert_VOIDCALL(CFE_Config_SetArrayValue(CFE_CONFIGID_UNDEFINED, &TESTOBJ)); + UtAssert_VOIDCALL(CFE_Config_SetArrayValue(CFE_CONFIGID_UT_CHECK_2, &TESTOBJ)); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UNDEFINED); + UtAssert_ZERO(ArrVal.NumElements); + UtAssert_NULL(ArrVal.ElementPtr); + + ArrVal = CFE_Config_GetArrayValue(CFE_CONFIGID_UT_CHECK_2); + UtAssert_EQ(size_t, ArrVal.NumElements, TESTOBJ.NumElements); + UtAssert_ADDRESS_EQ(ArrVal.ElementPtr, TESTOBJ.ElementPtr); +} + void Test_CFE_Config_SetString(void) { /* @@ -174,7 +240,7 @@ void Test_CFE_Config_IterateAll(void) CFE_Config_IterateAll(&Count, UT_Callback); /* Callback should only be given for configured/set entities */ - UtAssert_UINT32_EQ(Count, 3); + UtAssert_UINT32_EQ(Count, 4); } void Test_CFE_Config_StrCaseEq(void) @@ -258,6 +324,10 @@ void Test_CFE_Config_Setup(void) CFE_Config_Global.Table[1].Datum.AsPointer = &UT_TEST_OBJ; CFE_Config_Global.Table[2].ActualType = CFE_ConfigType_STRING; CFE_Config_Global.Table[2].Datum.AsPointer = UT_VALUE_STR; + CFE_Config_Global.Table[3].ActualType = CFE_ConfigType_UNDEFINED; + CFE_Config_Global.Table[3].Datum.AsPointer = NULL; + CFE_Config_Global.Table[4].ActualType = CFE_ConfigType_ARRAY; + CFE_Config_Global.Table[4].Datum.AsPointer = &UT_ARRAY; /* NOTE: Leaves last entry unset */ } @@ -266,10 +336,13 @@ void UtTest_Setup(void) { UtTest_Add(Test_CFE_Config_GetValue, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetValue()"); UtTest_Add(Test_CFE_Config_GetObjPointer, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetObjPointer()"); + UtTest_Add(Test_CFE_Config_GetArrayValue, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetArrayValue()"); UtTest_Add(Test_CFE_Config_GetString, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetString()"); UtTest_Add(Test_CFE_Config_SetValue, Test_CFE_Config_Setup, NULL, "Test CFE_Config_SetValue()"); UtTest_Add(Test_CFE_Config_SetObjPointer, Test_CFE_Config_Setup, NULL, "Test CFE_Config_SetObjPointer()"); UtTest_Add(Test_CFE_Config_SetString, Test_CFE_Config_Setup, NULL, "Test CFE_Config_SetString()"); + UtTest_Add(Test_CFE_Config_SetArrayValue, Test_CFE_Config_Setup, NULL, "Test CFE_Config_SetArrayValue()"); + UtTest_Add(Test_CFE_Config_GetName, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetName()"); UtTest_Add(Test_CFE_Config_GetIdByName, Test_CFE_Config_Setup, NULL, "Test CFE_Config_GetIdByName()"); UtTest_Add(Test_CFE_Config_IterateAll, Test_CFE_Config_Setup, NULL, "Test CFE_Config_IterateAll()"); diff --git a/modules/config/ut-coverage/ut-stubs/cfe_config_external_stubs.c b/modules/config/ut-coverage/ut-stubs/cfe_config_external_stubs.c new file mode 100644 index 000000000..ee4a198af --- /dev/null +++ b/modules/config/ut-coverage/ut-stubs/cfe_config_external_stubs.c @@ -0,0 +1,37 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Auto-Generated stub implementations for functions defined in cfe_config_external header + */ + +#include "cfe_config_external.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetupPlatformConfigInfo() + * ---------------------------------------------------- + */ +void CFE_Config_SetupPlatformConfigInfo(void) +{ + + UT_GenStub_Execute(CFE_Config_SetupPlatformConfigInfo, Basic, NULL); +} diff --git a/modules/config/ut-coverage/ut-stubs/cfe_config_init_stubs.c b/modules/config/ut-coverage/ut-stubs/cfe_config_init_stubs.c new file mode 100644 index 000000000..678a04a2a --- /dev/null +++ b/modules/config/ut-coverage/ut-stubs/cfe_config_init_stubs.c @@ -0,0 +1,51 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Auto-Generated stub implementations for functions defined in cfe_config_init header + */ + +#include "cfe_config_init.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_Init() + * ---------------------------------------------------- + */ +int32 CFE_Config_Init(void) +{ + UT_GenStub_SetupReturnBuffer(CFE_Config_Init, int32); + + UT_GenStub_Execute(CFE_Config_Init, Basic, NULL); + + return UT_GenStub_GetReturnValue(CFE_Config_Init, int32); +} + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetupBasicBuildInfo() + * ---------------------------------------------------- + */ +void CFE_Config_SetupBasicBuildInfo(void) +{ + + UT_GenStub_Execute(CFE_Config_SetupBasicBuildInfo, Basic, NULL); +} diff --git a/modules/config/ut-coverage/ut-stubs/cfe_config_lookup_stubs.c b/modules/config/ut-coverage/ut-stubs/cfe_config_lookup_stubs.c new file mode 100644 index 000000000..20a5745df --- /dev/null +++ b/modules/config/ut-coverage/ut-stubs/cfe_config_lookup_stubs.c @@ -0,0 +1,42 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Auto-Generated stub implementations for functions defined in cfe_config_lookup header + */ + +#include "cfe_config_lookup.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_LocateConfigRecordByID() + * ---------------------------------------------------- + */ +CFE_Config_ValueEntry_t *CFE_Config_LocateConfigRecordByID(CFE_ConfigId_t ConfigId) +{ + UT_GenStub_SetupReturnBuffer(CFE_Config_LocateConfigRecordByID, CFE_Config_ValueEntry_t *); + + UT_GenStub_AddParam(CFE_Config_LocateConfigRecordByID, CFE_ConfigId_t, ConfigId); + + UT_GenStub_Execute(CFE_Config_LocateConfigRecordByID, Basic, NULL); + + return UT_GenStub_GetReturnValue(CFE_Config_LocateConfigRecordByID, CFE_Config_ValueEntry_t *); +} diff --git a/modules/config/ut-coverage/ut-stubs/cfe_config_set_stubs.c b/modules/config/ut-coverage/ut-stubs/cfe_config_set_stubs.c new file mode 100644 index 000000000..7ae656e78 --- /dev/null +++ b/modules/config/ut-coverage/ut-stubs/cfe_config_set_stubs.c @@ -0,0 +1,78 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 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 + * + * Auto-Generated stub implementations for functions defined in cfe_config_set header + */ + +#include "cfe_config_set.h" +#include "utgenstub.h" + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetArrayValue() + * ---------------------------------------------------- + */ +void CFE_Config_SetArrayValue(CFE_ConfigId_t ConfigId, const CFE_Config_ArrayValue_t *ArrayPtr) +{ + UT_GenStub_AddParam(CFE_Config_SetArrayValue, CFE_ConfigId_t, ConfigId); + UT_GenStub_AddParam(CFE_Config_SetArrayValue, const CFE_Config_ArrayValue_t *, ArrayPtr); + + UT_GenStub_Execute(CFE_Config_SetArrayValue, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetObjPointer() + * ---------------------------------------------------- + */ +void CFE_Config_SetObjPointer(CFE_ConfigId_t ConfigId, const void *Ptr) +{ + UT_GenStub_AddParam(CFE_Config_SetObjPointer, CFE_ConfigId_t, ConfigId); + UT_GenStub_AddParam(CFE_Config_SetObjPointer, const void *, Ptr); + + UT_GenStub_Execute(CFE_Config_SetObjPointer, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetString() + * ---------------------------------------------------- + */ +void CFE_Config_SetString(CFE_ConfigId_t ConfigId, const char *Ptr) +{ + UT_GenStub_AddParam(CFE_Config_SetString, CFE_ConfigId_t, ConfigId); + UT_GenStub_AddParam(CFE_Config_SetString, const char *, Ptr); + + UT_GenStub_Execute(CFE_Config_SetString, Basic, NULL); +} + +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_SetValue() + * ---------------------------------------------------- + */ +void CFE_Config_SetValue(CFE_ConfigId_t ConfigId, uint32 Value) +{ + UT_GenStub_AddParam(CFE_Config_SetValue, CFE_ConfigId_t, ConfigId); + UT_GenStub_AddParam(CFE_Config_SetValue, uint32, Value); + + UT_GenStub_Execute(CFE_Config_SetValue, Basic, NULL); +} diff --git a/modules/core_api/fsw/inc/cfe_config.h b/modules/core_api/fsw/inc/cfe_config.h index 4fc3478f2..da6869590 100644 --- a/modules/core_api/fsw/inc/cfe_config.h +++ b/modules/core_api/fsw/inc/cfe_config.h @@ -67,6 +67,21 @@ uint32 CFE_Config_GetValue(CFE_ConfigId_t ConfigId); */ const void *CFE_Config_GetObjPointer(CFE_ConfigId_t ConfigId); +/** + * @brief Obtain an array correlating to an CFE configuration ID + * + * Retreives the CFE_Config_ArrayValue_t value associated with the specified key. + * This combines an array length (number of elements) and a pointer to the first element. + * + * If no value has been set, or the key is not valid, this returns 0 / NULL. + * + * @param[in] ConfigId Configuration ID/Key to look up + * + * @return Value associated with key + * @retval NULL if key is not defined or not set + */ +CFE_Config_ArrayValue_t CFE_Config_GetArrayValue(CFE_ConfigId_t ConfigId); + /** * @brief Obtain a string value correlating to an CFE configuration ID * @@ -137,8 +152,7 @@ void CFE_Config_IterateAll(void *Arg, CFE_Config_Callback_t Callback); * @param[in] CodeName Code name for the build (i.e. "equuleus") * @param[in] LastOffcRel Last official release (i.e. "6.7.0") */ -void CFE_Config_GetVersionString(char *Buf, size_t Size, - const char *Component, const char *SrcVersion, - const char *CodeName, const char *LastOffcRel); +void CFE_Config_GetVersionString(char *Buf, size_t Size, const char *Component, const char *SrcVersion, + const char *CodeName, const char *LastOffcRel); #endif /* CFE_CONFIG_H */ diff --git a/modules/core_api/fsw/inc/cfe_config_api_typedefs.h b/modules/core_api/fsw/inc/cfe_config_api_typedefs.h index 662d76fa2..452aa87e0 100644 --- a/modules/core_api/fsw/inc/cfe_config_api_typedefs.h +++ b/modules/core_api/fsw/inc/cfe_config_api_typedefs.h @@ -50,4 +50,16 @@ typedef CFE_RESOURCEID_BASE_TYPE CFE_ConfigId_t; typedef void (*CFE_Config_Callback_t)(void *Arg, CFE_ConfigId_t Id, const char *Name); +/** + * @brief Wrapper type for array configuration + * + * This is a pair containing a size and pointer that is get/set + * via a single config table entry + */ +typedef struct CFE_Config_ArrayValue +{ + size_t NumElements; + const void *ElementPtr; +} CFE_Config_ArrayValue_t; + #endif /* CFE_CONFIG_API_TYPEDEFS_H */ diff --git a/modules/core_api/ut-stubs/src/cfe_config_stubs.c b/modules/core_api/ut-stubs/src/cfe_config_stubs.c index f0d9b50c1..5136f6bca 100644 --- a/modules/core_api/ut-stubs/src/cfe_config_stubs.c +++ b/modules/core_api/ut-stubs/src/cfe_config_stubs.c @@ -28,6 +28,22 @@ void UT_DefaultHandler_CFE_Config_GetObjPointer(void *, UT_EntryKey_t, const UT_StubContext_t *); void UT_DefaultHandler_CFE_Config_GetString(void *, UT_EntryKey_t, const UT_StubContext_t *); +/* + * ---------------------------------------------------- + * Generated stub function for CFE_Config_GetArrayValue() + * ---------------------------------------------------- + */ +CFE_Config_ArrayValue_t CFE_Config_GetArrayValue(CFE_ConfigId_t ConfigId) +{ + UT_GenStub_SetupReturnBuffer(CFE_Config_GetArrayValue, CFE_Config_ArrayValue_t); + + UT_GenStub_AddParam(CFE_Config_GetArrayValue, CFE_ConfigId_t, ConfigId); + + UT_GenStub_Execute(CFE_Config_GetArrayValue, Basic, NULL); + + return UT_GenStub_GetReturnValue(CFE_Config_GetArrayValue, CFE_Config_ArrayValue_t); +} + /* * ---------------------------------------------------- * Generated stub function for CFE_Config_GetIdByName()