Skip to content

Commit

Permalink
Fix nasa#285, Refactor OSAL to avoid inclusion of C files
Browse files Browse the repository at this point in the history
Use separate source files and CMake-based source selection
based on feature configuration, rather than using the C
preprocessor for including/excluding different OSAL function
groups.

Refactor all implementation units to provide a separate header
file for each functional group/subsystem.  Remove "static"
declaration on internal helper functions so they can be invoked
from unit test.
  • Loading branch information
jphickey committed Apr 20, 2020
1 parent eeab727 commit 839444b
Show file tree
Hide file tree
Showing 432 changed files with 22,073 additions and 12,932 deletions.
80 changes: 56 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,34 @@ if (NOT DEFINED OSAL_SYSTEM_BSPTYPE OR
message(FATAL_ERROR "OSAL_SYSTEM_BSPTYPE must be set to the appropriate BSP")
endif ()

# Read the default compile-time configuration, and update with
# any mission/project specific options in the OSAL_CONFIGURATION_FILE
include("${OSAL_SOURCE_DIR}/default_config.cmake")

# The user-specified file is optional, but in case the value is defined but the
# file does not exist, this should be treated as an error.
if (DEFINED OSAL_CONFIGURATION_FILE)
include("${OSAL_CONFIGURATION_FILE}")
endif (DEFINED OSAL_CONFIGURATION_FILE)

# Use the supplied configuration to generate the osconfig.h file
# which can be referenced by the code. This will be stored in the top level
# "inc" directory of the binary output directory
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/inc")
configure_file(
"${OSAL_SOURCE_DIR}/osconfig.h.in"
"${OSAL_BINARY_DIR}/osconfig.gen"
@ONLY
)

# Only copy the osconfig.h into place if different from the existing file
# This avoids unnecessarily rebuilding all code in case cmake was re-run
# and but generated the same file.
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${OSAL_BINARY_DIR}/osconfig.gen"
"${CMAKE_BINARY_DIR}/inc/osconfig.h"
)

message(STATUS "OSAL Selection: ${OSAL_SYSTEM_OSTYPE}")
message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")

Expand All @@ -74,7 +102,6 @@ message(STATUS "BSP Selection: ${OSAL_SYSTEM_BSPTYPE}")
set(OSAL_API_INCLUDE_DIRECTORIES
"${OSAL_SOURCE_DIR}/src/os/inc"
"${CMAKE_BINARY_DIR}/inc"
${OSAL_INCLUDEDIR}
)
include_directories(${OSAL_API_INCLUDE_DIRECTORIES})

Expand Down Expand Up @@ -153,43 +180,48 @@ add_subdirectory(src/os/${OSAL_SYSTEM_OSTYPE} ${OSAL_SYSTEM_OSTYPE}_impl)
# are referenced in implementation OSAL modules, but should _NOT_
# be referenced outside the OSAL code
target_include_directories(osal_${OSAL_SYSTEM_OSTYPE}_impl PRIVATE
${OSAL_SOURCE_DIR}/src/os/shared
${OSAL_SOURCE_DIR}/src/os/shared/inc
${OSAL_SOURCE_DIR}/src/bsp/shared
)

# Define the external "osal" static library target
# This is a combination of the generic parts with the low level
# system-specific parts
add_library(osal STATIC
src/os/shared/osapi-binsem.c
src/os/shared/osapi-clock.c
src/os/shared/osapi-common.c
src/os/shared/osapi-countsem.c
src/os/shared/osapi-dir.c
src/os/shared/osapi-errors.c
src/os/shared/osapi-file.c
src/os/shared/osapi-filesys.c
src/os/shared/osapi-fpu.c
src/os/shared/osapi-heap.c
src/os/shared/osapi-idmap.c
src/os/shared/osapi-interrupts.c
src/os/shared/osapi-module.c
src/os/shared/osapi-mutex.c
src/os/shared/osapi-network.c
src/os/shared/osapi-printf.c
src/os/shared/osapi-queue.c
src/os/shared/osapi-select.c
src/os/shared/osapi-sockets.c
src/os/shared/osapi-task.c
src/os/shared/osapi-timebase.c
src/os/shared/osapi-time.c
src/os/shared/src/osapi-binsem.c
src/os/shared/src/osapi-clock.c
src/os/shared/src/osapi-common.c
src/os/shared/src/osapi-countsem.c
src/os/shared/src/osapi-dir.c
src/os/shared/src/osapi-errors.c
src/os/shared/src/osapi-file.c
src/os/shared/src/osapi-filesys.c
src/os/shared/src/osapi-fpu.c
src/os/shared/src/osapi-heap.c
src/os/shared/src/osapi-idmap.c
src/os/shared/src/osapi-interrupts.c
src/os/shared/src/osapi-module.c
src/os/shared/src/osapi-mutex.c
src/os/shared/src/osapi-network.c
src/os/shared/src/osapi-printf.c
src/os/shared/src/osapi-queue.c
src/os/shared/src/osapi-select.c
src/os/shared/src/osapi-sockets.c
src/os/shared/src/osapi-task.c
src/os/shared/src/osapi-timebase.c
src/os/shared/src/osapi-time.c
$<TARGET_OBJECTS:osal_${OSAL_SYSTEM_OSTYPE}_impl>
)

target_include_directories(osal INTERFACE
${OSAL_API_INCLUDE_DIRECTORIES}
)

target_include_directories(osal PRIVATE
${OSAL_SOURCE_DIR}/src/os/shared/inc
${OSAL_SOURCE_DIR}/src/bsp/shared
)

# Link the OSAL with the BSP
target_link_libraries(osal osal_bsp)

Expand Down
197 changes: 197 additions & 0 deletions default_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
##########################################################################
#
# Default configuration options for OSAL
#
# This file specifies the default values for various compile-time options
# supported by OSAL. These options can be further tuned by the specific
# OSAL and BSP selection, as well as the user application.
#
# NOTE:
# The defaults in this file should _not_ be directly modified for tuning.
#
# Instead, use the "OSAL_CONFIGURATION_FILE" CMake variable to define
# a custom file which can override/modify the configuration for the items
# which require tuning.
#
##########################################################################


##############################################################
# Code/Feature Selection Options for the OSAL implementation
##############################################################


# OSAL_CONFIG_INCLUDE_NETWORK
# ----------------------------------
#
# Whether to include the Network API
#
# If set TRUE, the the socket abstraction (if applicable on the platform)
# will be included. If set FALSE, then all calls to the network API will
# return OS_ERR_NOT_IMPLEMENTED.
#
# This can be set FALSE for platforms which do not have a network or
# IP stack available, or to save code space if the application does
# not use network resources.
#
set(OSAL_CONFIG_INCLUDE_NETWORK FALSE)


#
# OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER
# ----------------------------------
#
# Whether to include the capability of loading dynamic code objects
#
# This is normally set TRUE to support modularized applications on
# platforms which have this capability.
#
# For deployments which are always statically linked, this may be set
# FALSE for a smaller library size and reduced linking requirements.
#
set(OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER FALSE)


#
# OSAL_CONFIG_INCLUDE_STATIC_LOADER
# ----------------------------------
#
# Whether to include a compatibility "loader" for statically-linked objects
#
# This feature allows applications normally written for dynamic module loading
# operate transparently in a static link environment. If this is set TRUE,
# then the application must supply an object named "OS_STATIC_SYMBOL_TABLE" that
# contains the names and addresses of statically-linked symbols that should
# be known to the lookup/load functions.
#
# Note that modules "loaded" using this abstraction are still assigned a
# module ID and still require a slot in the module table even though
# no actual runtime loading is performed (see OSAL_CONFIG_MAX_MODULES).
#
set(OSAL_CONFIG_INCLUDE_STATIC_LOADER TRUE)

#
# OSAL_CONFIG_DEBUG_PERMISSIVE_MODE
# ----------------------------------
#
# The OSAL_CONFIG_DEBUG_PERMISSIVE_MODE option controls how privileged operations
# are handled by the OSAL in the event that the user does not have sufficient permission.
# In particular this applies to task priorities and message queues.
#
# If set FALSE, then all permissions are enforced, and a failure due to lack of permission
# will cause a failure of the overall operation, which is passed back to the application.
#
# If set to TRUE, this will treat some errors non-fatal and enable a graceful fallback,
# allowing the overall operation to complete in a reduced form. This makes the
# OSAL library compatible with a non-root (normal user mode) environment.
#
# In the PC-Linux/Posix build, this means:
# - A message queue deeper than the maximum system limit will be silently truncated
# to the maximum system limit (no error).
# - If the user does not have permission to create elevated priority tasks, then the tasks will
# be created at the default priority (no error).
#
set(OSAL_CONFIG_DEBUG_PERMISSIVE_MODE FALSE)

#
# OSAL_CONFIG_DEBUG_PRINTF
# ----------------------------------
#
# Controls inclusion of OS_DEBUG statements in the code
#
# If set FALSE, all OS_DEBUG statements are compiled out.
#
# If set TRUE, all the "OS_DEBUG" statements will be compiled in and displayed
# on the debug console. The statements may still be suppressed at runtime.
#
set(OSAL_CONFIG_DEBUG_PRINTF TRUE)


#############################################
# Resource Limits for the OS API
#############################################

# The maximum number of concurrently-running tasks to support
set(OSAL_CONFIG_MAX_TASKS 64)

# The maximum number of queues to support
set(OSAL_CONFIG_MAX_QUEUES 64)

# The maximum number of counting semaphores to support
set(OSAL_CONFIG_MAX_COUNT_SEMAPHORES 20)

# The maximum number of binary semaphores to support
set(OSAL_CONFIG_MAX_BIN_SEMAPHORES 20)

# The maximum number of mutexes to support
set(OSAL_CONFIG_MAX_MUTEXES 20)

# The maximum number of loadable modules to support
# Note that emulating module loading for statically-linked objects also
# requires a slot in this table, as it still assigns an OSAL ID.
set(OSAL_CONFIG_MAX_MODULES 20)

# The maximum number of time base objects (reference for timers)
set(OSAL_CONFIG_MAX_TIMEBASES 5)

# The maximum number of user timers / app callbacks that can be registered
set(OSAL_CONFIG_MAX_TIMERS 10)

# The maximum number of concurrently open file descriptors to support
set(OSAL_CONFIG_MAX_NUM_OPEN_FILES 50)

# The maximum number of concurrently open directory descriptors to support
set(OSAL_CONFIG_MAX_NUM_OPEN_DIRS 4)

# The maximum number of file systems that can be managed by OSAL
set(OSAL_CONFIG_MAX_FILE_SYSTEMS 14)

# The maximum length for a file name, including any extension
# (This does not include the directory part)
set(OSAL_CONFIG_MAX_FILE_NAME 20)

# Maximum length for an virtual path name (virtual directory + file)
set(OSAL_CONFIG_MAX_PATH_LEN 64)

# Maximum length allowed for a object (task,queue....) name
set(OSAL_CONFIG_MAX_API_NAME 20)

# Maximum length of a symbol name for OS_SymbolLookup()
set(OSAL_CONFIG_MAX_SYM_LEN 64)

# Maximum length of a network socket address
# This is only relevant if network support is included, and the
# required length depends on the address families in use
set(OSAL_CONFIG_SOCKADDR_MAX_LEN 28)

# Maximum length of a single message produced by OS_printf()
set(OSAL_CONFIG_PRINTF_BUFFER_SIZE 172)

# Maximum number of OS_printf() messages that will be buffered
set(OSAL_CONFIG_PRINTF_BUFFER_DEPTH 100)

# Priority level of a console output helper task
#
# Set logically low (high number) to maximize performance.
# - Messages from OS_printf() may show on the console with some delay
# but should have minimal impact to real time tasks.
#
# Set logically high (low number) for debugging
# - Messages from OS_printf() will have more timely output, but may
# adversely impact real time tasks.
set(OSAL_CONFIG_UTILITYTASK_PRIORITY 245)

# Stack size of console output task.
#
# This applies to RTOS layers with precise stack control,
# normally not necessary to change this unless the task implementation
# changes.
set(OSAL_CONFIG_UTILITYTASK_STACK_SIZE 2048)

# The size of a command that can be passed to the underlying OS
set(OSAL_CONFIG_MAX_CMD_LEN 1000)

# The maximum depth of an OSAL message queue.
# On some implementations this may affect the overall OSAL memory footprint
# so it may be beneficial to set this limit accordingly.
set(OSAL_CONFIG_QUEUE_MAX_DEPTH 50)
64 changes: 64 additions & 0 deletions osconfig.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Configuration file Operating System Abstraction Layer
*
* NOTE: this file was automatically generated by CMake from
* @CMAKE_CURRENT_SOURCE_DIR@/osconfig.h.in
*
* Any direct modifications to the generated copy will
* be overwritten each time CMake executes.
*/

#ifndef INCLUDE_OSCONFIG_H_
#define INCLUDE_OSCONFIG_H_

/*
* OSAL feature selection options from build config
*/
#cmakedefine OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER
#cmakedefine OSAL_CONFIG_INCLUDE_NETWORK
#cmakedefine OSAL_CONFIG_INCLUDE_STATIC_LOADER
#cmakedefine OSAL_CONFIG_DEBUG_PRINTF
#cmakedefine OSAL_CONFIG_DEBUG_PERMISSIVE_MODE

/*
* OSAL resource limits from build config
*
* (These are prefixed with OS_ for compatibility
* with existing code referencing these symbols)
*/
#define OS_MAX_TASKS @OSAL_CONFIG_MAX_TASKS@
#define OS_MAX_QUEUES @OSAL_CONFIG_MAX_QUEUES@
#define OS_MAX_COUNT_SEMAPHORES @OSAL_CONFIG_MAX_COUNT_SEMAPHORES@
#define OS_MAX_BIN_SEMAPHORES @OSAL_CONFIG_MAX_BIN_SEMAPHORES@
#define OS_MAX_MUTEXES @OSAL_CONFIG_MAX_MUTEXES@
#define OS_MAX_MODULES @OSAL_CONFIG_MAX_MODULES@
#define OS_MAX_TIMEBASES @OSAL_CONFIG_MAX_TIMEBASES@
#define OS_MAX_TIMERS @OSAL_CONFIG_MAX_TIMERS@
#define OS_MAX_NUM_OPEN_FILES @OSAL_CONFIG_MAX_NUM_OPEN_FILES@
#define OS_MAX_NUM_OPEN_DIRS @OSAL_CONFIG_MAX_NUM_OPEN_DIRS@
#define OS_MAX_FILE_SYSTEMS @OSAL_CONFIG_MAX_FILE_SYSTEMS@
#define OS_MAX_SYM_LEN @OSAL_CONFIG_MAX_SYM_LEN@
#define OS_MAX_FILE_NAME @OSAL_CONFIG_MAX_FILE_NAME@
#define OS_MAX_PATH_LEN @OSAL_CONFIG_MAX_PATH_LEN@
#define OS_MAX_API_NAME @OSAL_CONFIG_MAX_API_NAME@
#define OS_SOCKADDR_MAX_LEN @OSAL_CONFIG_SOCKADDR_MAX_LEN@
#define OS_BUFFER_SIZE @OSAL_CONFIG_PRINTF_BUFFER_SIZE@
#define OS_BUFFER_MSG_DEPTH @OSAL_CONFIG_PRINTF_BUFFER_DEPTH@
#define OS_UTILITYTASK_PRIORITY @OSAL_CONFIG_UTILITYTASK_PRIORITY@
#define OS_UTILITYTASK_STACK_SIZE @OSAL_CONFIG_UTILITYTASK_STACK_SIZE@
#define OS_MAX_CMD_LEN @OSAL_CONFIG_MAX_CMD_LEN@
#define OS_QUEUE_MAX_DEPTH @OSAL_CONFIG_QUEUE_MAX_DEPTH@
#define OS_SHELL_CMD_INPUT_FILE_NAME "@OSAL_CONFIG_SHELL_CMD_INPUT_FILE_NAME@"
#define OS_PRINTF_CONSOLE_NAME "@OSAL_CONFIG_PRINTF_CONSOLE_NAME@"

/*
* OSAL fixed resource limits
*
* The resource limits here are not user-configurable, but
* may be changed in a future revision of OSAL, so it is
* still present in osconfig.h along with the others.
*/
#define OS_MAX_CONSOLES 1


#endif /* INCLUDE_OSCONFIG_H_ */
Loading

0 comments on commit 839444b

Please sign in to comment.