Skip to content

Commit

Permalink
Fix #2473, document and use topicid numbers for cfe
Browse files Browse the repository at this point in the history
A topic ID is the same concept as was previously referred to as a
portable message number.  This just formalizes it, gives it a name,
and adds some macros for easier customization of the behavior.
  • Loading branch information
jphickey committed Dec 6, 2023
1 parent ee18742 commit 9e53504
Show file tree
Hide file tree
Showing 19 changed files with 313 additions and 88 deletions.
79 changes: 78 additions & 1 deletion cmake/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,81 @@ function(cfs_app_check_intf MODULE_NAME)
endfunction(cfs_app_check_intf)


##################################################################
#
# FUNCTION: setup_platform_msgids
#
# This is intended to support cases where MsgIDs for all apps
# and modules are assigned in a single/unified header file
#
function(setup_platform_msgids)

set(PLATFORM_MSGID_HEADERFILE)

# In an EDS build, the msg IDs always come from EDS, there should not be a local msgids.h file
if (NOT CFE_EDS_ENABLED_BUILD)

# Check for the presence of a platform-specific msgid file
# This uses cfe_locate_implementation_file() as this returns whether or not it found one
cfe_locate_implementation_file(PLATFORM_MSGID_HEADERFILE "msgids.h"
PREFIX ${BUILD_CONFIG} cfs
SUBDIR config
)

# If a top level file was found, then create a wrapper around it called "cfs_msgids.h"
# Note that at this point it could be a list
if (PLATFORM_MSGID_HEADERFILE)

set(TEMP_WRAPPER_FILE_CONTENT)
foreach(SELECTED_FILE ${PLATFORM_MSGID_HEADERFILE})
file(TO_NATIVE_PATH "${SELECTED_FILE}" SRC_NATIVE_PATH)
list(APPEND TEMP_WRAPPER_FILE_CONTENT "#include \"${SRC_NATIVE_PATH}\"\n")
endforeach()

# Generate a header file
generate_c_headerfile("${CMAKE_BINARY_DIR}/inc/cfs_msgids.h" ${TEMP_WRAPPER_FILE_CONTENT})
unset(TEMP_WRAPPER_FILE_CONTENT)

# From here on use the wrapper file
set(PLATFORM_MSGID_HEADERFILE "cfs_msgids.h")

endif(PLATFORM_MSGID_HEADERFILE)

endif(NOT CFE_EDS_ENABLED_BUILD)

# Finally, export a CFGFILE_SRC variable for each of the deps
# This should make each respective "mission_build" create a wrapper
# that points directly at this global file, ignoring the default
if (PLATFORM_MSGID_HEADERFILE)

# Historically there has been a cfe_msgids.h defined at the core api level
# be sure to include this in the export list
set (OUTPUT_VAR_LIST
CORE_API_CFGFILE_SRC_cfe_msgids
)

# Slight inconsistency: for CFE core components, the cfe_ prefix is omitted in DEP_NAME
# To make this work without major impact, add it back in here
foreach(DEP_NAME ${MISSION_CORE_MODULES})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_cfe_${DEP_NAME}_msgids)
endforeach(DEP_NAME ${MISSION_CORE_MODULES})

foreach(DEP_NAME ${TGTSYS_${SYSVAR}_APPS} ${TGTSYS_${SYSVAR}_STATICAPPS})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_${DEP_NAME}_msgids)
endforeach(DEP_NAME ${MISSION_APPS})

# This is the actual export to parent scope
foreach(VAR_NAME ${OUTPUT_VAR_LIST})
message("${VAR_NAME}=${PLATFORM_MSGID_HEADERFILE}")
set(${VAR_NAME} ${PLATFORM_MSGID_HEADERFILE} PARENT_SCOPE)
endforeach(VAR_NAME ${OUTPUT_VAR_LIST})

endif (PLATFORM_MSGID_HEADERFILE)

endfunction(setup_platform_msgids)



##################################################################
Expand Down Expand Up @@ -658,6 +733,9 @@ function(prepare)
list(REMOVE_AT BUILD_CONFIG 0)
set(BUILD_CONFIG ${BUILD_CONFIG} PARENT_SCOPE)

# Check if the user has provided a platform-specific "msgids.h" file and set up a wrapper to it
setup_platform_msgids()

# Pull in any application-specific platform-scope configuration
# This may include user configuration files such as cfe_platform_cfg.h,
# or any other configuration/preparation that needs to happen at
Expand Down Expand Up @@ -746,7 +824,6 @@ function(process_arch SYSVAR)
endif()
endforeach()


# Add all core modules
# The osal is handled explicitly (above) since this has special extra config
foreach(DEP ${MISSION_CORE_INTERFACES} ${MISSION_CORE_MODULES})
Expand Down
75 changes: 75 additions & 0 deletions cmake/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,78 @@ function(generate_build_version_templates)

endfunction(generate_build_version_templates)

##################################################################
#
# FUNCTION: setup_global_topicids
#
# This is intended to support cases where topic IDs for all apps
# and modules are assigned in a single/unified header file
#
function(setup_global_topicids)

if (CFE_EDS_ENABLED_BUILD)

# In an EDS build, the topic IDs always come from EDS
set(MISSION_GLOBAL_TOPICID_HEADERFILE "mission_eds_designparameters.h")

else(CFE_EDS_ENABLED_BUILD)

# Check for the presence of a mission-wide/global topic ID file
# This uses cfe_locate_implementation_file() as this returns whether or not it found one
cfe_locate_implementation_file(MISSION_GLOBAL_TOPICID_HEADERFILE "global_topicids.h"
PREFIX ${MISSIONCONFIG} cfs
SUBDIR config
)

# If a top level file was found, then create a wrapper around it called "cfs_global_topicids.h"
# Note that at this point it could be a list
if (MISSION_GLOBAL_TOPICID_HEADERFILE)

set(TEMP_WRAPPER_FILE_CONTENT)
foreach(SELECTED_FILE ${MISSION_GLOBAL_TOPICID_HEADERFILE})
file(TO_NATIVE_PATH "${SELECTED_FILE}" SRC_NATIVE_PATH)
list(APPEND TEMP_WRAPPER_FILE_CONTENT "#include \"${SRC_NATIVE_PATH}\"\n")
endforeach()

# Generate a header file
generate_c_headerfile("${CMAKE_BINARY_DIR}/inc/cfs_global_topicids.h" ${TEMP_WRAPPER_FILE_CONTENT})
unset(TEMP_WRAPPER_FILE_CONTENT)

# From here on use the wrapper file
set(MISSION_GLOBAL_TOPICID_HEADERFILE "cfs_global_topicids.h")

endif(MISSION_GLOBAL_TOPICID_HEADERFILE)

endif(CFE_EDS_ENABLED_BUILD)

# Finally, export a CFGFILE_SRC variable for each of the deps
# This should make each respective "mission_build" create a wrapper
# that points directly at this global file, ignoring the default
if (MISSION_GLOBAL_TOPICID_HEADERFILE)

set (OUTPUT_VAR_LIST)

# Slight inconsistency: for CFE core components, the cfe_ prefix is omitted in DEP_NAME
# To make this work without major impact, add it back in here
foreach(DEP_NAME ${MISSION_CORE_MODULES})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_cfe_${DEP_NAME}_topicids)
endforeach(DEP_NAME ${MISSION_CORE_MODULES})

foreach(DEP_NAME ${MISSION_APPS})
string(TOUPPER "${DEP_NAME}_CFGFILE_SRC" CFGSRC)
list(APPEND OUTPUT_VAR_LIST ${CFGSRC}_${DEP_NAME}_topicids)
endforeach(DEP_NAME ${MISSION_APPS})

# This is the actual export to parent scope
foreach(VAR_NAME ${OUTPUT_VAR_LIST})
set(${VAR_NAME} ${MISSION_GLOBAL_TOPICID_HEADERFILE} PARENT_SCOPE)
endforeach(VAR_NAME ${OUTPUT_VAR_LIST})

endif (MISSION_GLOBAL_TOPICID_HEADERFILE)

endfunction(setup_global_topicids)

##################################################################
#
# FUNCTION: prepare
Expand Down Expand Up @@ -348,6 +420,9 @@ function(prepare)
add_dependencies(cfe-usersguide doc-prebuild)
add_dependencies(mission-doc doc-prebuild)

# Set up the global topicid header file, if present
setup_global_topicids()

# Pull in any application-specific mission-scope configuration
# This may include user configuration files such as cfe_mission_cfg.h,
# msgid definitions, or any other configuration/preparation that needs to
Expand Down
34 changes: 23 additions & 11 deletions modules/core_api/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,29 @@
###########################################################

# Generate the "cfe_platform_cfg.h" and "cfe_msgids.h" header files
# these must come from mission config
# these usually come from user config, but CFE provides defaults

generate_config_includefile(
FILE_NAME "cfe_msgids.h"
MATCH_SUFFIX "msgids.h"
FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_cfe_msgids.h"
PREFIXES ${BUILD_CONFIG} cfe
set(CORE_API_PLATFORM_CONFIG_FILE_LIST
cfe_core_api_base_msgids.h
cfe_msgids.h
)

generate_config_includefile(
FILE_NAME "cfe_core_api_base_msgids.h"
FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_cfe_core_api_base_msgids.h"
PREFIXES ${BUILD_CONFIG}
)
message("CORE_API_CFGFILE_SRC_cfe_msgids = ${CORE_API_CFGFILE_SRC_cfe_msgids}")

# Create wrappers around the all the config header files
# This makes them individually overridable by the missions, without modifying
# the distribution default copies
foreach(CORE_API_CFGFILE ${CORE_API_PLATFORM_CONFIG_FILE_LIST})
get_filename_component(CFGKEY "${CORE_API_CFGFILE}" NAME_WE)
if (DEFINED CORE_API_CFGFILE_SRC_${CFGKEY})
set(DEFAULT_SOURCE GENERATED_FILE "${CORE_API_CFGFILE_SRC_${CFGKEY}}")
else()
set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${CORE_API_CFGFILE}")
endif()

generate_config_includefile(
FILE_NAME "${CORE_API_CFGFILE}"
PREFIXES ${BUILD_CONFIG} cfe
${DEFAULT_SOURCE}
)
endforeach()
62 changes: 59 additions & 3 deletions modules/core_api/config/default_cfe_core_api_base_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
/**
* @file
*
* Purpose:
* This header file contains the Message Id's for messages used by the
* cFE core.
* This header file contains the platform-specific base msg ID values and
* logic to convert a topic ID to a message ID value.
*
*/

Expand Down Expand Up @@ -69,4 +68,61 @@
*/
#define CFE_PLATFORM_CMD_MID_BASE_GLOB 0x1860

/**
* \brief "Global" telemetry message ID base offset
*
* 0x0860 - Nominal value for message ID V1
* 0x0060 - Potential value for MISSION_MSGID_V2, note command bit is 0x0080.
* Works in limited cases only, alternative method of deconfliction
* is recommended.
* See #CFE_PLATFORM_CMD_MID_BASE for more information
*/
#define CFE_PLATFORM_TLM_MID_BASE_GLOB 0x0860

/**
* \brief Convert a command topic ID to a MsgID value
*
* This defines the logic to convert a topic ID value into a message ID value.
* This operates on integer values and should resolve at compile time such
* that it can be used in e.g. switch/case statements.
*
* \note The result of this conversion is a simple integer, thus also needs to
* go through CFE_SB_ValueToMsgId() to obtain a properly-typed CFE_SB_MsgId_t
* for interacting with SB APIs.
*/
#define CFE_PLATFORM_CMD_TOPICID_TO_MIDV(topic) (CFE_PLATFORM_CMD_MID_BASE | (topic))

/**
* \brief Convert a telemetry topic ID to a MsgID value
*
* This defines the logic to convert a topic ID value into a message ID value.
* This operates on integer values and should resolve at compile time such
* that it can be used in e.g. switch/case statements.
*
* \note The result of this conversion is a simple integer, thus also needs to
* go through CFE_SB_ValueToMsgId() to obtain a properly-typed CFE_SB_MsgId_t
* for interacting with SB APIs.
*/
#define CFE_PLATFORM_TLM_TOPICID_TO_MIDV(topic) (CFE_PLATFORM_TLM_MID_BASE | (topic))

/**
* \brief Convert a "global" command topic ID to a MsgID value
*
* A global command is one that is not specific to an individual instance of CFE,
* but rather intended to be broadcast to all CFE instances at the same time.
*
* This is otherwise identical to #CFE_PLATFORM_CMD_TOPICID_TO_MIDV
*/
#define CFE_GLOBAL_CMD_TOPICID_TO_MIDV(topic) (CFE_PLATFORM_CMD_MID_BASE_GLOB | (topic))

/**
* \brief Convert a "global" telemetry topic ID to a MsgID value
*
* A global telemetry is one that is not specific to an individual instance of CFE,
* but rather intended to be broadcast to all CFE instances at the same time.
*
* This is otherwise identical to #CFE_PLATFORM_TLM_TOPICID_TO_MIDV
*/
#define CFE_GLOBAL_TLM_TOPICID_TO_MIDV(topic) (CFE_PLATFORM_TLM_MID_BASE_GLOB | (topic))

#endif /* CFE_CORE_BASE_MSGIDS_H */
9 changes: 6 additions & 3 deletions modules/es/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ set(ES_PLATFORM_CONFIG_FILE_LIST
cfe_es_platform_cfg.h
)

message("ES_CFGFILE_SRC_cfe_es_msgids = ${ES_CFGFILE_SRC_cfe_es_msgids}")


# Create wrappers around the all the config header files
# This makes them individually overridable by the missions, without modifying
# the distribution default copies
foreach(ES_CFGFILE ${ES_PLATFORM_CONFIG_FILE_LIST})
get_filename_component(CFGKEY "${ES_CFGFILE}" NAME_WE)
if (DEFINED ES_CFGFILE_SRC_${CFGKEY})
set(DEFAULT_SOURCE "${ES_CFGFILE_SRC_${CFGKEY}}")
set(DEFAULT_SOURCE GENERATED_FILE "${ES_CFGFILE_SRC_${CFGKEY}}")
else()
set(DEFAULT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/config/default_${ES_CFGFILE}")
set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${ES_CFGFILE}")
endif()
generate_config_includefile(
FILE_NAME "${ES_CFGFILE}"
FALLBACK_FILE ${DEFAULT_SOURCE}
${DEFAULT_SOURCE}
)
endforeach()
10 changes: 5 additions & 5 deletions modules/es/config/default_cfe_es_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
/*
** cFE ES Command Message Id's
*/
#define CFE_ES_CMD_MID CFE_PLATFORM_CMD_MID_BASE + CFE_MISSION_ES_CMD_MSG /* 0x1806 */
#define CFE_ES_SEND_HK_MID CFE_PLATFORM_CMD_MID_BASE + CFE_MISSION_ES_SEND_HK_MSG /* 0x1808 */
#define CFE_ES_CMD_MID CFE_PLATFORM_CMD_TOPICID_TO_MIDV(CFE_MISSION_ES_CMD_TOPICID) /* 0x1806 */
#define CFE_ES_SEND_HK_MID CFE_PLATFORM_CMD_TOPICID_TO_MIDV(CFE_MISSION_ES_SEND_HK_TOPICID) /* 0x1808 */

/*
** CFE ES Telemetry Message Id's
*/
#define CFE_ES_HK_TLM_MID CFE_PLATFORM_TLM_MID_BASE + CFE_MISSION_ES_HK_TLM_MSG /* 0x0800 */
#define CFE_ES_APP_TLM_MID CFE_PLATFORM_TLM_MID_BASE + CFE_MISSION_ES_APP_TLM_MSG /* 0x080B */
#define CFE_ES_MEMSTATS_TLM_MID CFE_PLATFORM_TLM_MID_BASE + CFE_MISSION_ES_MEMSTATS_TLM_MSG /* 0x0810 */
#define CFE_ES_HK_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MIDV(CFE_MISSION_ES_HK_TLM_TOPICID) /* 0x0800 */
#define CFE_ES_APP_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MIDV(CFE_MISSION_ES_APP_TLM_TOPICID) /* 0x080B */
#define CFE_ES_MEMSTATS_TLM_MID CFE_PLATFORM_TLM_TOPICID_TO_MIDV(CFE_MISSION_ES_MEMSTATS_TLM_TOPICID) /* 0x0810 */

#endif
10 changes: 5 additions & 5 deletions modules/es/config/default_cfe_es_topicids.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
** \par Limits
** Not Applicable
*/
#define CFE_MISSION_ES_CMD_MSG 6
#define CFE_MISSION_ES_SEND_HK_MSG 8
#define CFE_MISSION_ES_CMD_TOPICID 6
#define CFE_MISSION_ES_SEND_HK_TOPICID 8

/**
** \cfemissioncfg cFE Portable Message Numbers for Telemetry
Expand All @@ -44,8 +44,8 @@
** \par Limits
** Not Applicable
*/
#define CFE_MISSION_ES_HK_TLM_MSG 0
#define CFE_MISSION_ES_APP_TLM_MSG 11
#define CFE_MISSION_ES_MEMSTATS_TLM_MSG 16
#define CFE_MISSION_ES_HK_TLM_TOPICID 0
#define CFE_MISSION_ES_APP_TLM_TOPICID 11
#define CFE_MISSION_ES_MEMSTATS_TLM_TOPICID 16

#endif
6 changes: 3 additions & 3 deletions modules/evs/arch_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ set(EVS_PLATFORM_CONFIG_FILE_LIST
foreach(EVS_CFGFILE ${EVS_PLATFORM_CONFIG_FILE_LIST})
get_filename_component(CFGKEY "${EVS_CFGFILE}" NAME_WE)
if (DEFINED EVS_CFGFILE_SRC_${CFGKEY})
set(DEFAULT_SOURCE "${EVS_CFGFILE_SRC_${CFGKEY}}")
set(DEFAULT_SOURCE GENERATED_FILE "${EVS_CFGFILE_SRC_${CFGKEY}}")
else()
set(DEFAULT_SOURCE "${CMAKE_CURRENT_LIST_DIR}/config/default_${EVS_CFGFILE}")
set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${EVS_CFGFILE}")
endif()
generate_config_includefile(
FILE_NAME "${EVS_CFGFILE}"
FALLBACK_FILE ${DEFAULT_SOURCE}
${DEFAULT_SOURCE}
)
endforeach()
Loading

0 comments on commit 9e53504

Please sign in to comment.