Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2507, add EDS cmake hooks #2511

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ project(CFE C)
# Allow unit tests to be added by any recipe
enable_testing()

# This switch determines whether to use EDS framework
# By default it is set OFF/false as this is a new/experimental feature.
option(CFE_EDS_ENABLED_BUILD "Use EDS framework" OFF)

# Always create directories to hold generated files/wrappers
# EDS makes signficant use of generated files. In non-EDS builds
# some headers and wrapper files are also generated. Directories
# may simply remain empty if not used/needed in the current config.
file(MAKE_DIRECTORY
"${CMAKE_BINARY_DIR}/eds"
"${CMAKE_BINARY_DIR}/obj"
"${CMAKE_BINARY_DIR}/inc"
"${CMAKE_BINARY_DIR}/src"
)

# Include the global routines
include("cmake/global_functions.cmake")

Expand Down Expand Up @@ -123,4 +138,3 @@ prepare()
foreach(SYSVAR ${TGTSYS_LIST})
process_arch(${SYSVAR})
endforeach(SYSVAR ${TGTSYS_LIST})

11 changes: 11 additions & 0 deletions cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ function(add_cfe_app APP_NAME APP_SRC_FILES)
add_library(${APP_NAME} ${APPTYPE} ${APP_SRC_FILES} ${ARGN})
target_link_libraries(${APP_NAME} core_api)

# If using "local" EDS linkage, then link the app with the EDS library here.
# Note that the linker will only pull in the compilation unit that actually
# resolves an undefined symbol, which in this case would be the app-specific
# DATATYPE_DB object if one is referenced at all.
#
# By linking with the respective application like this, the net result is that
# only the _referenced_ EDS DBs (i.e. those for loaded apps) are held in memory.
if (CFE_EDS_ENABLED_BUILD AND CFE_EDS_LINK_MODE STREQUAL LOCAL)
target_link_libraries($(APP_NAME) cfe_edsdb_static)
endif()

# An "install" step is only needed for dynamic/runtime loaded apps
if (APP_DYNAMIC_TARGET_LIST)
cfs_app_do_install(${APP_NAME} ${APP_DYNAMIC_TARGET_LIST})
Expand Down
16 changes: 15 additions & 1 deletion cmake/global_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@

include(CMakeParseArguments)

# This is done here at the global level so this definition is used for
# ALL code on ALL targets, including host-side tools. Ideally, this should
# only be necessary on the core_api interface, but it does not fully propagate
# to all unit test targets. If/when that issue is resolved, this can be removed.
if (CFE_EDS_ENABLED_BUILD)

# Propagate the setting to a C preprocessor define of the same name
# The CFE_EDS_ENABLED_BUILD switch indicates that any
# compile-time preprocessor blocks should be enabled in this build
add_definitions(-DCFE_EDS_ENABLED_BUILD)

endif(CFE_EDS_ENABLED_BUILD)


##################################################################
#
# FUNCTION: cfe_locate_implementation_file
Expand Down Expand Up @@ -58,7 +72,7 @@ function(cfe_locate_implementation_file OUTPUT_VAR FILE_NAME)
string(REPLACE ${MISSION_SOURCE_DIR} "" RELATIVEDIR ${BASEDIR})

# A target-specific prefixed filename gets priority over a direct filename match
# But do not include this variant if the prefix is already part of the relative search path
# But do not include this variant if the prefix is already part of the relative search path
foreach (PREFIX ${LOCATEIMPL_ARG_PREFIX})
if (NOT "${RELATIVEDIR}" MATCHES "/${PREFIX}/")
list(APPEND IMPL_SEARCH_PATH "${BASEDIR}${PREFIX}_${FILE_NAME}")
Expand Down
9 changes: 2 additions & 7 deletions cmake/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,6 @@ function(prepare)
add_definitions(-DSIMULATION=${SIMULATION})
endif (SIMULATION)

# Create directories to hold generated files/wrappers
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/eds")
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/obj")
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/inc")
file(MAKE_DIRECTORY "${MISSION_BINARY_DIR}/src")

# Certain runtime variables need to be "exported" to the subordinate build, such as
# the specific arch settings and the location of all the apps. This list is collected
# during this function execution and exported at the end.
Expand Down Expand Up @@ -548,7 +542,7 @@ function(process_arch TARGETSYSTEM)
# 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}")
file(MAKE_DIRECTORY "${ARCH_BINARY_DIR}" "${ARCH_BINARY_DIR}/inc")
file(MAKE_DIRECTORY "${ARCH_BINARY_DIR}")

message(STATUS "Configuring for system arch: ${ARCH_TOOLCHAIN_NAME}/${ARCH_CONFIG_NAME}")

Expand Down Expand Up @@ -578,6 +572,7 @@ function(process_arch TARGETSYSTEM)
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=${CMAKE_EXPORT_COMPILE_COMMANDS}
-DCFE_EDS_ENABLED_BUILD:BOOL=${CFE_EDS_ENABLED_BUILD}
${SELECTED_TOOLCHAIN_FILE}
${CFE_SOURCE_DIR}
WORKING_DIRECTORY
Expand Down
35 changes: 35 additions & 0 deletions cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,41 @@ set(MISSION_MODULE_SEARCH_PATH
set(osal_SEARCH_PATH ".")
set(psp_SEARCH_PATH ".")

# Account for differences when EDS is enabled
if(CFE_EDS_ENABLED_BUILD)

# The EDS database is an object (or set of objects) generated by the tools from the EDS files.
# This can be linked into CFE either as a whole (GLOBAL) or as part of each app (LOCAL).
#
# LOCAL mode may use less memory by only only including DB objects for the apps that are
# originating or terminating CFS message traffic, but GLOBAL mode is simpler as it ensures
# that the entire DB is accessible by any app, even for data definitions that are not its own.
#
# NOTE: If running CI/TO, SBN, or other "generic" apps that relay SB traffic (or otherwise
# handle data that may not have originated on the same CFE instance) then it is recommended
# to stay with GLOBAL mode.
if (NOT DEFINED CFE_EDS_LINK_MODE)
set(CFE_EDS_LINK_MODE GLOBAL)
endif()

# The standard msg module is not used in EDS build, edslib provides an alternate
list(REMOVE_ITEM MISSION_CORE_MODULES msg)

list(APPEND MISSION_CORE_MODULES
"edslib"
"missionlib"
"edsmsg"
)

list(APPEND MISSION_MODULE_SEARCH_PATH
"tools/eds/cfecfs" # CFE/CFS modules and extensions from EdsLib
)

# edslib exists directly under tools/eds (EDS runtime libraries)
set(edslib_SEARCH_PATH "tools/eds")

endif(CFE_EDS_ENABLED_BUILD)

# Include "cfe_assert" library in all builds, because it is included
# in the default startup script. It should not have any effect if not
# used.
Expand Down
32 changes: 31 additions & 1 deletion cmake/target/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,37 @@ set(CFE_LINK_NORMAL_LIBS
${${TGTNAME}_STATIC_APPLIST}
)

# If EDS is enabled, then the generated dictionary objects are linked with CFE.
# This can be done statically or dynamically, depending on user preferences.
if (CFE_EDS_ENABLED_BUILD)

# Determine EDS object linking mode for final executable.
# This should be configured via the toolchain file,
# with the default being FALSE (static link)
if (CFE_EDS_LINK_MODE STREQUAL GLOBAL)

# In this mode the full EDS object is statically linked
# In addition, also pull in the runtime lib, which
# supports script language bindings and UI display
list(APPEND CFE_LINK_WHOLE_LIBS
cfe_edsdb_static
edslib_runtime_static
)

endif()

list(APPEND CFE_LINK_WHOLE_LIBS
cfe_missionlib_runtime_static
cfe_missionlib_interfacedb_static
)

# Set a preprocessor define so the source will reference the right thing
target_compile_definitions(core-${TGTNAME} PRIVATE
CFE_EDS_LINK_MODE_${CFE_EDS_LINK_MODE}
)

endif(CFE_EDS_ENABLED_BUILD)

# Handle the list of "embedded files" that should be linked into CFE.
# These are arbitrary files in the mission config that are converted
# into C data structures and linked with the executable. This is
Expand Down Expand Up @@ -276,4 +307,3 @@ target_link_libraries(core-${TGTNAME}
# This is implemented in a separate function so
# it may be overridden in an OS-specific manner if necessary.
cfe_exec_do_install(${TGTNAME})

34 changes: 34 additions & 0 deletions cmake/target/inc/target_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ typedef const struct
const void *Value;
} CFE_ConfigKeyValue_t;

/**
* The "EdsLib_DatabaseObject" is an abstract structure here.
*/
typedef struct EdsLib_DatabaseObject CFE_EdsDbObject_t;
typedef struct CFE_MissionLib_SoftwareBus_Interface CFE_SbIntfDbObject_t;

/**
* Core Flight Executive configuration information.
*/
Expand Down Expand Up @@ -196,6 +202,34 @@ typedef const struct
CFE_ConfigName_t * CoreModuleList; /**< List of CFE core support module names that are statically linked */
CFE_ConfigName_t
*StaticAppList; /**< List of additional CFS Applications that are statically linked into this binary */

/**
* Normal read-only EDS Database object
*
* This EDS DB object pointer is always initialized to be non-null.
* It is qualified as "const" and used for all EDS query requests.
*/
const CFE_EdsDbObject_t *EdsDb;

/**
* Dynamic EDS Database object
*
* This provides a writable (non-const) pointer to the same EDS object as above,
* but only when when dynamic EDS link mode is selected. It will be set NULL
* when static EDS link mode is selected.
*
* This can checked by runtime code to determine the EDS link mode. If it is
* NULL this means the EDS DB is fixed/static and no runtime registration is needed.
* If this pointer is non-null then the EDS DB is dynamic and runtime registration
* is needed.
*/
CFE_EdsDbObject_t *DynamicEdsDb;

/**
* Software bus interface EDS object (MsgId mappings)
*/
const CFE_SbIntfDbObject_t *SbIntfDb;

} Target_ConfigData;

/**
Expand Down
80 changes: 79 additions & 1 deletion cmake/target/src/target_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,78 @@
*/
extern CFE_StaticModuleLoadEntry_t CFE_PSP_MODULE_LIST[];

#ifdef CFE_EDS_ENABLED_BUILD

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.

#include "cfe_mission_eds_parameters.h"
#include "cfe_mission_eds_interface_parameters.h"

#define CFE_SB_INTF_DB_PTR &CFE_SOFTWAREBUS_INTERFACE

#endif /* CFE_EDS_ENABLED_BUILD */

/*
* Determine the proper values for populating the EDS-related
* fields of the configuration structure. This depends on the
* selected linkage mode (static or dynamic).
*/

/*
* Static (const) EDS object link mode:
* Only the const pointer gets assigned to the EDS object, and the
* non-const pointer gets set NULL. There are no "write" operations
* in this mode -- registration and de-registration is not necessary.
*/
#ifdef CFE_EDS_LINK_MODE_GLOBAL

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.

/* This mode is simple, just point directly at the object defined in the external DB */
#define CFE_CONST_EDS_DB_PTR &EDS_DATABASE

#endif /* CFE_EDS_LINK_MODE_GLOBAL */

/*
* Dynamic (non-const) runtime EDS database object
* This is filled in as additional EDS datasheet objects are registered
*/
#ifdef CFE_EDS_LINK_MODE_LOCAL

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.

static EdsLib_DataTypeDB_t CFE_DYNAMIC_EDS_TABLE[EDS_MAX_DATASHEETS] = {NULL};

static EdsLib_DatabaseObject_t CFE_DYNAMIC_EDSDB_OBJECT = {.AppTableSize = EDS_MAX_DATASHEETS,
.DataTypeDB_Table = CFE_DYNAMIC_EDS_TABLE};

/* The object registered in config points at the local (empty) object */
#define CFE_NONCONST_EDS_DB_PTR &CFE_DYNAMIC_EDSDB_OBJECT

#endif /* CFE_EDS_LINK_MODE_LOCAL */

/*
* For all of these DB objects, use NULL if not defined.
* This covers the case where EDS is not being used.
*/
#ifndef CFE_NONCONST_EDS_DB_PTR

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
#define CFE_NONCONST_EDS_DB_PTR NULL
#endif

/*
* Note that the non-const object can be used as a const object,
* but not the other way around. This can also be NULL.
*/
#ifndef CFE_CONST_EDS_DB_PTR

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
#define CFE_CONST_EDS_DB_PTR CFE_NONCONST_EDS_DB_PTR
#endif

/*
* The SB intf DB serves as the lookup table for identification
* of the software bus messages. This can also be NULL if
* EDS is not being used.
*/
#ifndef CFE_SB_INTF_DB_PTR

Check notice

Code scanning / CodeQL

Conditional compilation Note

Use of conditional compilation must be kept to a minimum.
#define CFE_SB_INTF_DB_PTR NULL
#endif

/* Disable clang-format for the rest of this file, to preserve columns in the struct defs */
/* clang-format off */

/**
* A structure that encapsulates all the CFE static configuration
*/
Expand All @@ -152,7 +224,9 @@
.UserReservedSize = CFE_PLATFORM_ES_USER_RESERVED_SIZE,

.RamDiskSectorSize = CFE_PLATFORM_ES_RAM_DISK_SECTOR_SIZE,
.RamDiskTotalSectors = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS};
.RamDiskTotalSectors = CFE_PLATFORM_ES_RAM_DISK_NUM_SECTORS
};


/**
* Instantiation of global system-wide configuration struct
Expand All @@ -176,4 +250,8 @@
.ModuleVersionList = CFE_MODULE_VERSION_TABLE,
.CoreModuleList = CFE_CORE_MODULE_LIST,
.StaticAppList = CFE_STATIC_APP_LIST,
.EdsDb = CFE_CONST_EDS_DB_PTR,
.DynamicEdsDb = CFE_NONCONST_EDS_DB_PTR,
.SbIntfDb = CFE_SB_INTF_DB_PTR
};

4 changes: 4 additions & 0 deletions modules/config/fsw/src/cfe_config_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ void CFE_Config_SetupBasicBuildInfo(void)
KeyVal = CFE_Config_FindTargetKeyValue(GLOBAL_CONFIGDATA.ModuleVersionList, "MISSION");
CFE_Config_SetString(CFE_CONFIGID_MISSION_SRCVER, KeyVal);

/* Global mission EDS runtime DB */
CFE_Config_SetObjPointer(CFE_CONFIGID_MISSION_EDS_DB, GLOBAL_CONFIGDATA.EdsDb);
CFE_Config_SetObjPointer(CFE_CONFIGID_MISSION_SBINTF_DB, GLOBAL_CONFIGDATA.SbIntfDb);

/* propagate the version numbers from version.h */
CFE_Config_SetValue(CFE_CONFIGID_CORE_VERSION_MAJOR, CFE_MAJOR_VERSION);
CFE_Config_SetValue(CFE_CONFIGID_CORE_VERSION_MINOR, CFE_MINOR_VERSION);
Expand Down
2 changes: 2 additions & 0 deletions modules/config/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set(GENERATED_IDNAME_MAP_LIST)
list(APPEND CFE_CONFIG_IDS
MISSION_NAME
MISSION_SRCVER
MISSION_EDS_DB
MISSION_SBINTF_DB

CORE_VERSION_MAJOR
CORE_VERSION_MINOR
Expand Down
8 changes: 7 additions & 1 deletion modules/core_api/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ add_library(core_api INTERFACE)
# The fsw/inc here defines global/shared structures and interfaces
target_include_directories(core_api INTERFACE fsw/inc)

# Propagate the setting to a C preprocessor define of the same name
# The CFE_EDS_ENABLED_BUILD switch indicates that any
# compile-time preprocessor blocks should be enabled in this build
if (CFE_EDS_ENABLED_BUILD)
target_compile_definitions(core_api INTERFACE CFE_EDS_ENABLED_BUILD)
endif()

# Propagate any INTERFACE-level include dirs and compile definitions from
# the modules into this abstract interface target
foreach(MOD ${MISSION_CORE_MODULES})
Expand Down Expand Up @@ -46,4 +53,3 @@ cfs_app_check_intf(core_api

cfe_tbl_filedef.h
)

6 changes: 0 additions & 6 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ CFE_EVS_Global_t CFE_EVS_Global;
/* Defines */
#define CFE_EVS_PANIC_DELAY 500 /**< \brief Task delay before PSP panic */

/*
** Local function prototypes.
*/
void CFE_EVS_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId);
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);

/* Function Definitions */

/*----------------------------------------------------------------
Expand Down
Loading
Loading