Skip to content

Commit

Permalink
Fix nasa#928, Added software bus routing module
Browse files Browse the repository at this point in the history
- Implementation for direct map and unsorted routing table
- Includes full coverage tests
- Removed msg key and route stack concepts from direct map
  • Loading branch information
skliper committed Oct 21, 2020
1 parent 33364e8 commit 0aac36a
Show file tree
Hide file tree
Showing 8 changed files with 791 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ set(MISSION_CORE_MODULES
"osal"
"psp"
"msg"
"sbr"
)

# The "MISSION_GLOBAL_APPLIST" is a set of apps/libs that will be built
Expand Down
43 changes: 43 additions & 0 deletions modules/sbr/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##################################################################
#
# cFE software bus routing module CMake build recipe
#
# This CMakeLists.txt adds source files for the
# SBR module included in the cFE distribution. Selected
# files are built into a static library that in turn
# is linked into the final executable.
#
# Note this is different than applications which are dynamically
# linked to support runtime loading. The core applications all
# use static linkage.
#
##################################################################

if (NOT MISSION_MSGMAP_IMPLEMENTATION)
set(MISSION_MSGMAP_IMPLEMENTATION "DIRECT")
endif (NOT MISSION_MSGMAP_IMPLEMENTATION)

if (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "DIRECT")
message(STATUS "Using direct map software bus routing implementation")
set(${DEP}_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_sbr_map_direct.c
${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_sbr_route_unsorted.c)
elseif (MISSION_MSGMAP_IMPLEMENTATION STREQUAL "HASH")
message(STATUS "Using hashed map software bus routing implementation")
set(${DEP}_SRC
${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_sbr_map_hash.c
${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_sbr_route_unsorted.c)
else()
message(ERROR "Invalid software bush routing implementation selected:" MISSION_MSGMAP_IMPLEMENTATION)
endif()

# Module library
add_library(${DEP} STATIC ${${DEP}_SRC})

# Add private include
target_include_directories(${DEP} PRIVATE private_inc)

# Add unit test coverage subdirectory
if(ENABLE_UNIT_TESTS)
add_subdirectory(unit-test-coverage)
endif(ENABLE_UNIT_TESTS)
66 changes: 66 additions & 0 deletions modules/sbr/private_inc/cfe_sbr_priv.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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.
*/

/******************************************************************************
* Prototypes for private functions and type definitions for SB
* routing internal use.
*****************************************************************************/

#ifndef CFE_SBR_PRIV_H_
#define CFE_SBR_PRIV_H_

/*
* Includes
*/
#include "private/cfe_sbr.h"

/*
* Macro Definitions
*/

/** \brief Invalid route id */
#define CFE_SBR_INVALID_ROUTE_ID ((CFE_SBR_RouteId_t) {.RouteId = 0})

/******************************************************************************
* Function prototypes
*/

/**
* \brief Routing map initialization
*/
void CFE_SBR_Init_Map(void);

/**
* \brief Associates the given route ID with the given message ID
*
* Used for implementations that use a mapping table (typically hash or direct)
* and need this information to later get the route id from the message id.
*
* \note Typically not needed for a search implementation. Assumes
* message ID is valid
*
* \param[in] MsgId Message id to associate with route id
* \param[in] RouteId Route id to associate with message id
*
* \returns Number of collisions
*/
uint32 CFE_SBR_SetRouteId(CFE_SB_MsgId_t MsgId, CFE_SBR_RouteId_t RouteId);

#endif /* CFE_SBR_PRIV_H_ */
93 changes: 93 additions & 0 deletions modules/sbr/src/cfe_sbr_map_direct.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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.
*/

/******************************************************************************
* Direct routing map implementation
*
* Notes:
* These functions manipulate/access global variables and need
* to be protected by the SB Shared data lock.
*
*/

/*
* Include Files
*/

#include "common_types.h"
#include "private/cfe_sbr.h"
#include "cfe_sbr_priv.h"
#include <string.h>

/*
* Macro Definitions
*/

/**
* \brief Message map size
*
* For direct mapping, map size is maximum valid MsgId value + 1 (since MsgId 0 is valid)
*/
#define CFE_SBR_MSG_MAP_SIZE (CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1)

/******************************************************************************
* Shared data
*/

/** \brief Message map shared data */
CFE_SBR_RouteId_t CFE_SBR_MSGMAP[CFE_SBR_MSG_MAP_SIZE];

/******************************************************************************
* Interface function - see header for description
*/
void CFE_SBR_Init_Map(void)
{
/* Clear the shared data */
memset(&CFE_SBR_MSGMAP, 0, sizeof(CFE_SBR_MSGMAP));
}

/******************************************************************************
* Interface function - see header for description
*/
uint32 CFE_SBR_SetRouteId(CFE_SB_MsgId_t MsgId, CFE_SBR_RouteId_t RouteId)
{
if (CFE_SB_IsValidMsgId(MsgId))
{
CFE_SBR_MSGMAP[CFE_SB_MsgIdToValue(MsgId)] = RouteId;
}

/* Direct lookup never collides, always return 0 */
return 0;
}

/******************************************************************************
* Interface function - see API for description
*/
CFE_SBR_RouteId_t CFE_SBR_GetRouteId(CFE_SB_MsgId_t MsgId)
{
CFE_SBR_RouteId_t routeid = CFE_SBR_INVALID_ROUTE_ID;

if (CFE_SB_IsValidMsgId(MsgId))
{
routeid = CFE_SBR_MSGMAP[CFE_SB_MsgIdToValue(MsgId)];
}

return routeid;
}
Loading

0 comments on commit 0aac36a

Please sign in to comment.