diff --git a/CMakeLists.txt b/CMakeLists.txt index e0852e5dc..4a1487b62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}") @@ -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}) @@ -153,36 +180,47 @@ 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 ) +set(OSAL_SRCLIST + 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 +) + +if (OSAL_CONFIG_DEBUG_PRINTF) + list(APPEND OSAL_SRCLIST + src/os/shared/src/osapi-debug.c + ) +endif (OSAL_CONFIG_DEBUG_PRINTF) + + # 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 + ${OSAL_SRCLIST} $ ) @@ -190,6 +228,11 @@ 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) diff --git a/default_config.cmake b/default_config.cmake new file mode 100644 index 000000000..1ab851eda --- /dev/null +++ b/default_config.cmake @@ -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 TRUE) + + +# +# 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 TRUE) + +# +# 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) diff --git a/osconfig.h.in b/osconfig.h.in new file mode 100644 index 000000000..a8535fa47 --- /dev/null +++ b/osconfig.h.in @@ -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_ */ diff --git a/src/bsp/mcp750-vxworks/config/osconfig.h b/src/bsp/mcp750-vxworks/config/osconfig.h deleted file mode 100644 index a0e09dbab..000000000 --- a/src/bsp/mcp750-vxworks/config/osconfig.h +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** -** File: osconfig.h -** -** Purpose: -** This header file contains the OS API configuration parameters. -** -** Author: A. Cudmore -** -** Notes: -** -******************************************************************************/ - -#ifndef _osconfig_ -#define _osconfig_ - -/* -** Platform Configuration Parameters for the OS API -*/ - -#define OS_MAX_TASKS 64 -#define OS_MAX_QUEUES 64 -#define OS_MAX_COUNT_SEMAPHORES 20 -#define OS_MAX_BIN_SEMAPHORES 20 -#define OS_MAX_MUTEXES 20 - -/* -** Maximum length for an absolute path name -*/ -#define OS_MAX_PATH_LEN 64 - -/* -** Maximum length for a local or host path/filename. -** This parameter can consist of the OSAL filename/path + -** the host OS physical volume name or path. -*/ -#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) - - -/* -** The maxium length allowed for a object (task,queue....) name -*/ -#define OS_MAX_API_NAME 20 - -/* -** The maximum length for a file name -*/ -#define OS_MAX_FILE_NAME 20 - -/* -** These defines are for OS_printf -*/ -#define OS_BUFFER_SIZE 172 -#define OS_BUFFER_MSG_DEPTH 100 - -/* This #define turns on a utility task that - * will read the statements to print from - * the OS_printf function. If you want OS_printf - * to print the text out itself, comment this out - * - * NOTE: The Utility Task #defines only have meaning - * on the VxWorks operating systems - */ - -#define OS_UTILITY_TASK_ON - - -#ifdef OS_UTILITY_TASK_ON - #define OS_UTILITYTASK_STACK_SIZE 2048 - /* some room is left for other lower priority tasks */ - #define OS_UTILITYTASK_PRIORITY 245 -#endif - - -/* -** the size of a command that can be passed to the underlying OS -*/ -#define OS_MAX_CMD_LEN 1000 - -/* -** This define will include the OS network API. -** It should be turned off for targtets that do not have a network stack or -** device ( like the basic RAD750 vxWorks BSP ) -*/ -#define OS_INCLUDE_NETWORK - -/* -** This is the maximum number of open file descriptors allowed at a time -*/ -#define OS_MAX_NUM_OPEN_FILES 50 - -/* -** This defines the filethe input command of OS_ShellOutputToFile -** is written to in the VxWorks6 port -*/ -#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" - -/* -** This define sets the queue implentation of the Linux port to use sockets -** commenting this out makes the Linux port use the POSIX message queues. -*/ -/* #define OSAL_SOCKET_QUEUE */ - -/* -** Module loader/symbol table is optional -*/ -#define OS_INCLUDE_MODULE_LOADER - -#ifdef OS_INCLUDE_MODULE_LOADER - /* - ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in - ** the running system. This define must be set high enough to support the maximum number of - ** loadable modules in the system. If the the table is filled up at runtime, a new module load - ** would fail. - */ - #define OS_MAX_MODULES 20 - - /* - ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. - */ - /* #define OS_STATIC_LOADER */ - -#endif - - -/* -** This define sets the maximum symbol name string length. It is used in implementations that -** support the symbols and symbol lookup. -*/ -#define OS_MAX_SYM_LEN 64 - - -/* -** This define sets the maximum number of timers available -*/ -#define OS_MAX_TIMERS 5 - -#endif diff --git a/src/bsp/pc-linux/config/osconfig.h b/src/bsp/pc-linux/config/osconfig.h deleted file mode 100644 index ec0a26d9d..000000000 --- a/src/bsp/pc-linux/config/osconfig.h +++ /dev/null @@ -1,199 +0,0 @@ -/****************************************************************************** -** File: osconfig.h -** -** Purpose: -** This header file contains the OS API configuration parameters. -** -** Author: A. Cudmore -** -** Notes: -** -******************************************************************************/ - -#ifndef _osconfig_ -#define _osconfig_ - -/* -** Platform Configuration Parameters for the OS API -*/ - -#define OS_MAX_TASKS 64 -#define OS_MAX_QUEUES 64 -#define OS_MAX_COUNT_SEMAPHORES 20 -#define OS_MAX_BIN_SEMAPHORES 20 -#define OS_MAX_MUTEXES 20 - -/* -** Maximum length for an absolute path name -*/ -#define OS_MAX_PATH_LEN 64 - -/* -** Maximum length for a local or host path/filename. -** This parameter can consist of the OSAL filename/path + -** the host OS physical volume name or path. -*/ -#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) - -/* -** The maxium length allowed for a object (task,queue....) name -*/ -#define OS_MAX_API_NAME 20 - -/* -** The maximum length for a file name -*/ -#define OS_MAX_FILE_NAME 20 - -/* -** These defines are for OS_printf -*/ -#define OS_BUFFER_SIZE 172 -#define OS_BUFFER_MSG_DEPTH 100 - -/* - * Definitions regarding the "utility task" - * - * The utility task is a special background task started - * by OSAL to move data from calls to OS_printf() to the - * actual console output device. In former versions of - * OSAL (4.2.x and below), this was a VxWorks-only option. - * In the current OSAL, the task is always enabled, but - * the performance can still be tuned to achieve the - * desired behavior. - * - * Where realtime performance is a concern, the task - * may be set to a low priority (high number) such that - * threads calling OS_printf() are not blocked significantly. - * However, this may delay the actual output from a call to - * OS_printf() from reaching the console. - * - * During debugging, if it is desired to see output from - * OS_printf() immediately as it occurs, this task can be set - * to a high priority (low number). This will effectively - * preempt the task that called OS_printf() until the output - * is completed. - * - * By default this is set to 245 for low priority/delayed - * output. This still leaves some room for lower priority - * tasks, if desired. - * - * It should not be necessary to change the stack size from - * the default. - */ -#define OS_UTILITYTASK_PRIORITY 245 -#define OS_UTILITYTASK_STACK_SIZE 2048 - - -/* -** the size of a command that can be passed to the underlying OS -*/ -#define OS_MAX_CMD_LEN 1000 - -/* -** This define will include the OS network API. -** It should be turned off for targtets that do not have a network stack or -** device ( like the basic RAD750 vxWorks BSP ) -*/ -#define OS_INCLUDE_NETWORK - -/* -** This is the maximum number of open file descriptors allowed at a time -*/ -#define OS_MAX_NUM_OPEN_FILES 50 - -/* -** This defines the filethe input command of OS_ShellOutputToFile -** is written to in the VxWorks6 port -*/ -#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" - -/* -** This define sets the queue implentation of the Linux port to use sockets -** commenting this out makes the Linux port use the POSIX message queues. -*/ -/* #define OSAL_SOCKET_QUEUE */ - -/* -** Module loader/symbol table is optional -*/ -#define OS_INCLUDE_MODULE_LOADER - -#ifdef OS_INCLUDE_MODULE_LOADER - /* - ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in - ** the running system. This define must be set high enough to support the maximum number of - ** loadable modules in the system. If the the table is filled up at runtime, a new module load - ** would fail. - */ - #define OS_MAX_MODULES 20 - - /* - ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. - */ - /* #define OS_STATIC_LOADER */ - -#endif - - -/* -** This define sets the maximum symbol name string length. It is used in implementations that -** support the symbols and symbol lookup. -*/ -#define OS_MAX_SYM_LEN 64 - -/* -** This define sets the maximum number of time base objects -** The limit depends on the underlying OS and the resources it offers, but in general -** these are a limited resource and only a handful can be created. -** -** This is included as an example, for OSAL implementations that do not [yet] support -** separate timebase objects, this directive will be ignored. However, the OSAL unit -** test stub code does require that this is defined. -*/ -#define OS_MAX_TIMEBASES 5 - -/* -** This define sets the maximum number of user timers available -** The limit here depends on whether the OSAL implementation uses limited resources -** for a timer object; in the case of the newer "posix-ng" and "rtems-ng" variants, -** the "timebase" allocates the OS resources and the timer does not use any additional -** OS resources. Therefore this limit can be higher. -*/ -#define OS_MAX_TIMERS 5 - -/* -** This define sets the maximum number of open directories -*/ -#define OS_MAX_NUM_OPEN_DIRS 4 - -/* -** This define sets 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 according to -** what the application actually needs. -*/ -#define OS_QUEUE_MAX_DEPTH 50 - -/* - * If OS_DEBUG_PRINTF is defined, this will enable the "OS_DEBUG" statements in the code - * This should be left disabled in a normal build as it may affect real time performance as - * well as producing extra console output. - */ -#undef OS_DEBUG_PRINTF - -/* - * If OSAL_DEBUG_PERMISSIVE_MODE is defined, this will enable features to make 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). Note this behavior can also be forced by the - * OSAL_DEBUG_DISABLE_TASK_PRIORITIES macro below. - * - * Leaving this undefined will produce the default behavior, which is to return errors to the caller - * for these conditions. - */ -#define OSAL_DEBUG_PERMISSIVE_MODE - -#endif diff --git a/src/bsp/pc-rtems/config/osconfig.h b/src/bsp/pc-rtems/config/osconfig.h deleted file mode 100644 index 6d90a2663..000000000 --- a/src/bsp/pc-rtems/config/osconfig.h +++ /dev/null @@ -1,184 +0,0 @@ -/****************************************************************************** -** File: osconfig.h -** -** Purpose: -** This header file contains the OS API configuration parameters. -** -** Author: A. Cudmore -** -** Notes: -** -******************************************************************************/ - -#ifndef _osconfig_ -#define _osconfig_ - -/* -** Platform Configuration Parameters for the OS API -*/ - -#define OS_MAX_TASKS 64 -#define OS_MAX_QUEUES 64 -#define OS_MAX_COUNT_SEMAPHORES 20 -#define OS_MAX_BIN_SEMAPHORES 20 -#define OS_MAX_MUTEXES 20 - -/* -** Maximum length for an absolute path name -*/ -#define OS_MAX_PATH_LEN 64 - -/* -** Maximum length for a local or host path/filename. -** This parameter can consist of the OSAL filename/path + -** the host OS physical volume name or path. -*/ -#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) - -/* -** The maxium length allowed for a object (task,queue....) name -*/ -#define OS_MAX_API_NAME 20 - -/* -** The maximum length for a file name -*/ -#define OS_MAX_FILE_NAME 20 - -/* -** These defines are for OS_printf -*/ -#define OS_BUFFER_SIZE 172 -#define OS_BUFFER_MSG_DEPTH 100 - -/* - * Definitions regarding the "utility task" - * - * The utility task is a special background task started - * by OSAL to move data from calls to OS_printf() to the - * actual console output device. In former versions of - * OSAL (4.2.x and below), this was a VxWorks-only option. - * In the current OSAL, the task is always enabled, but - * the performance can still be tuned to achieve the - * desired behavior. - * - * Where realtime performance is a concern, the task - * may be set to a low priority (high number) such that - * threads calling OS_printf() are not blocked significantly. - * However, this may delay the actual output from a call to - * OS_printf() from reaching the console. - * - * During debugging, if it is desired to see output from - * OS_printf() immediately as it occurs, this task can be set - * to a high priority (low number). This will effectively - * preempt the task that called OS_printf() until the output - * is completed. - * - * By default this is set to 245 for low priority/delayed - * output. This still leaves some room for lower priority - * tasks, if desired. - * - * It should not be necessary to change the stack size from - * the default. - */ -#define OS_UTILITYTASK_PRIORITY 245 -#define OS_UTILITYTASK_STACK_SIZE 2048 - - -/* -** the size of a command that can be passed to the underlying OS -*/ -#define OS_MAX_CMD_LEN 1000 - -/* -** This define will include the OS network API. -** It should be turned off for targtets that do not have a network stack or -** device ( like the basic RAD750 vxWorks BSP ) -*/ -#undef OS_INCLUDE_NETWORK - -/* -** This is the maximum number of open file descriptors allowed at a time -*/ -#define OS_MAX_NUM_OPEN_FILES 50 - -/* -** This defines the filethe input command of OS_ShellOutputToFile -** is written to in the VxWorks6 port -*/ -#define OS_SHELL_CMD_INPUT_FILE_NAME "/ram/OS_ShellCmd.in" - -/* -** This define sets the queue implentation of the Linux port to use sockets -** commenting this out makes the Linux port use the POSIX message queues. -*/ -/* #define OSAL_SOCKET_QUEUE */ - -/* -** Module loader/symbol table is optional -*/ -#define OS_INCLUDE_MODULE_LOADER - -#ifdef OS_INCLUDE_MODULE_LOADER - /* - ** This define sets the size of the OS Module Table, which keeps track of the loaded modules in - ** the running system. This define must be set high enough to support the maximum number of - ** loadable modules in the system. If the the table is filled up at runtime, a new module load - ** would fail. - */ - #define OS_MAX_MODULES 20 - - /* - ** The Static Loader define is used for switching between the Dynamic and Static loader implementations. - */ - /* #define OS_STATIC_LOADER */ - -#endif - - -/* -** This define sets the maximum symbol name string length. It is used in implementations that -** support the symbols and symbol lookup. -*/ -#define OS_MAX_SYM_LEN 64 - -/* -** This define sets the maximum number of time base objects -** The limit depends on the underlying OS and the resources it offers, but in general -** these are a limited resource and only a handful can be created. -** -** This is included as an example, for OSAL implementations that do not [yet] support -** separate timebase objects, this directive will be ignored. However, the OSAL unit -** test stub code does require that this is defined. -*/ -#define OS_MAX_TIMEBASES 5 - -/* -** This define sets the maximum number of user timers available -** The limit here depends on whether the OSAL implementation uses limited resources -** for a timer object; in the case of the newer "posix-ng" and "rtems-ng" variants, -** the "timebase" allocates the OS resources and the timer does not use any additional -** OS resources. Therefore this limit can be higher. -*/ -#define OS_MAX_TIMERS 5 - -/* -** This define sets the maximum number of open directories -*/ -#define OS_MAX_NUM_OPEN_DIRS 4 - -/* -** This define sets 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 according to -** what the application actually needs. -*/ -#define OS_QUEUE_MAX_DEPTH 50 - -/* - * If OS_DEBUG_PRINTF is defined, this will enable the "OS_DEBUG" statements in the code - * This should be left disabled in a normal build as it may affect real time performance as - * well as producing extra console output. - */ -#undef OS_DEBUG_PRINTF - -#endif diff --git a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h index de2ae50f7..89656d2c7 100644 --- a/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h +++ b/src/bsp/pc-rtems/src/pcrtems_bsp_internal.h @@ -32,15 +32,10 @@ #define RTEMS_MAX_CMDLINE 256 /* - * For debugging, it is helpful to keep the shell - * priority relatively high. But this may cause the - * shell activity to preempt the actual realtime tasks. + * By default put the shell at the same priority + * as the utility task which handles OS_printf() */ -#ifdef NDEBUG -#define RTEMS_SHELL_PRIORITY 100 -#else -#define RTEMS_SHELL_PRIORITY 5 -#endif +#define RTEMS_SHELL_PRIORITY OS_UTILITYTASK_PRIORITY /* ** BSP types diff --git a/src/os/inc/osapi-os-core.h b/src/os/inc/osapi-os-core.h index 728508424..a8da34b0a 100644 --- a/src/os/inc/osapi-os-core.h +++ b/src/os/inc/osapi-os-core.h @@ -64,6 +64,16 @@ */ #define OS_ERROR_NAME_LENGTH 35 + +typedef enum +{ + OS_STREAM_STATE_BOUND = 0x01, + OS_STREAM_STATE_CONNECTED = 0x02, + OS_STREAM_STATE_READABLE = 0x04, + OS_STREAM_STATE_WRITABLE = 0x08, +} OS_StreamState_t; + + /* Object property structures */ /** @brief OSAL task properties */ @@ -104,7 +114,7 @@ typedef struct { char name [OS_MAX_API_NAME]; uint32 creator; -}OS_mut_sem_prop_t; +}OS_mutex_prop_t; /** @brief OSAL time */ @@ -993,7 +1003,7 @@ int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name); * @retval #OS_ERR_INVALID_ID if the id passed in is not a valid semaphore * @retval #OS_INVALID_POINTER if the mut_prop pointer is null */ -int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop); +int32 OS_MutSemGetInfo (uint32 sem_id, OS_mutex_prop_t *mut_prop); /**@}*/ /** @defgroup OSAPITime OSAL Time/Tick APIs diff --git a/src/os/inc/osapi-os-filesys.h b/src/os/inc/osapi-os-filesys.h index 9a408b309..a25786b43 100644 --- a/src/os/inc/osapi-os-filesys.h +++ b/src/os/inc/osapi-os-filesys.h @@ -59,6 +59,15 @@ #define OS_FS_PHYS_NAME_LEN 64 /**< Physical drive name length */ #define OS_FS_VOL_NAME_LEN 32 /**< Volume name length */ +/** + * @brief Maximum length of a local/native path name string + * + * This is a concatenation of the OSAL virtual path with the system + * mount point or device name + */ +#define OS_MAX_LOCAL_PATH_LEN (OS_MAX_PATH_LEN + OS_FS_PHYS_NAME_LEN) + + /** @addtogroup OSReturnCodes * @{ */ diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index b15507794..823d8fe1f 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -13,17 +13,28 @@ * \author joseph.p.hickey@nasa.gov * * Purpose: This file contains wrappers around the select() system call - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* Handled by includer */ +/* + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * FD_SET/FD_CLR/FD_ISSET macros and fd_set typedef + * select() + * clock_gettime() - for computing select timeouts + */ +#include +#include +#include + +#include +#include "os-impl-select.h" +#include "osapi-select-impl.h" /**************************************************************************************** DEFINES diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index e24ffe970..bad3f9249 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -14,10 +14,6 @@ * * Purpose: This file contains the network functionality for for * systems which implement the BSD-style socket API. - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** @@ -25,9 +21,30 @@ ***************************************************************************************/ /* - * NOTE - This is a code fragment and all the include files should have - * been handled by the includer (because those vary from OS to OS). + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * socket() + * getsockopt() + * setsockopt() + * fcntl() + * bind() + * listen() + * accept() + * connect() + * recvfrom() + * sendto() + * inet_pton() + * ntohl()/ntohs() + * + * As well as any headers for the struct sockaddr type and any address families in use */ +#include +#include +#include "os-impl.h" +#include "os-impl-sockets.h" + /**************************************************************************************** DEFINES @@ -45,50 +62,9 @@ typedef union /**************************************************************************************** - GLOBAL DATA - ***************************************************************************************/ - - -/**************************************************************************************** - INITIALIZATION FUNCTION + Sockets API ***************************************************************************************/ - -/**************************************************************************************** - Network API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_NetworkGetHostName_Impl - * - * Purpose: Implemented per internal OSAL API - * See description in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) -{ - int32 return_code; - - if ( gethostname(host_name, name_len) < 0 ) - { - return_code = OS_ERROR; - } - else - { - /* - * posix does not say that the name is always - * null terminated, so its worthwhile to ensure it - */ - host_name[name_len - 1] = 0; - return_code = OS_SUCCESS; - } - - return(return_code); -} /* end OS_NetworkGetHostName_Impl */ - - /*---------------------------------------------------------------- * diff --git a/src/os/portable/os-impl-console-directwrite.c b/src/os/portable/os-impl-console-bsp.c similarity index 70% rename from src/os/portable/os-impl-console-directwrite.c rename to src/os/portable/os-impl-console-bsp.c index e9b6efa79..9e0013df5 100644 --- a/src/os/portable/os-impl-console-directwrite.c +++ b/src/os/portable/os-impl-console-bsp.c @@ -9,24 +9,26 @@ */ /** - * \file os-impl-console-directwrite.c + * \file os-impl-console-bsp.c * \author joseph.p.hickey@nasa.gov * * Purpose: - * For many platforms the "OS_printf" output can be sent to the console - * using a standard file descriptor provided by the C library using - * the write() call. + * Uses the BSP-provided "console write" function + * Note this only supports a single console * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* Handled by includer */ +#include +#include + +#include "bsp-impl.h" + +#include "os-impl-console.h" +#include "osapi-printf-impl.h" /**************************************************************************************** CONSOLE OUTPUT @@ -47,10 +49,8 @@ void OS_ConsoleOutput_Impl(uint32 local_id) uint32 EndPos; long WriteSize; OS_console_internal_record_t *console; - int fd; console = &OS_console_table[local_id]; - fd = OS_impl_console_table[local_id].out_fd; StartPos = console->ReadPos; EndPos = console->WritePos; while (StartPos != EndPos) @@ -65,19 +65,9 @@ void OS_ConsoleOutput_Impl(uint32 local_id) WriteSize = EndPos - StartPos; } - WriteSize = write(fd, - &console->BufBase[StartPos], + OS_BSP_ConsoleOutput_Impl(&console->BufBase[StartPos], WriteSize); - if (WriteSize <= 0) - { - /* write error */ - /* This debug message _might_ go to the same console, - * but might not, so its worth a shot. */ - OS_DEBUG("%s(): write(): %s\n", __func__, strerror(errno)); - break; - } - StartPos += WriteSize; if (StartPos >= console->BufSize) { diff --git a/src/os/portable/os-impl-no-loader.c b/src/os/portable/os-impl-no-loader.c new file mode 100644 index 000000000..79d061ee1 --- /dev/null +++ b/src/os/portable/os-impl-no-loader.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file os-impl-no-module.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: This file contains a module loader implementation for systems + * that do not use dynamic modules. It returns OS_ERR_NOT_IMPLEMENTED + * for all calls. + */ + + +#include +#include "osapi-module-impl.h" + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleLoad_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ) +{ + return OS_ERR_NOT_IMPLEMENTED; + +} /* end OS_ModuleLoad_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleUnload_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleUnload_Impl ( uint32 module_id ) +{ + return OS_ERR_NOT_IMPLEMENTED; + +} /* end OS_ModuleUnload_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) +{ + return OS_ERR_NOT_IMPLEMENTED; + +} /* end OS_ModuleGetInfo_Impl */ + + + + + + diff --git a/src/os/portable/os-impl-no-network.c b/src/os/portable/os-impl-no-network.c index 4122aef1f..70edfbe69 100644 --- a/src/os/portable/os-impl-no-network.c +++ b/src/os/portable/os-impl-no-network.c @@ -13,22 +13,20 @@ * \author joseph.p.hickey@nasa.gov * * - * Purpose: This file contains the network functionality for for - * systems which do not implement any networking (OS_INCLUDE_NETWORK is false). + * Purpose: This file contains the network implementation for + * systems where OSAL_CONFIG_INCLUDE_NETWORK is false or otherwise + * do not provide any network functions. * - * It implements the required calls and returns OS_ERR_NOT_IMPLEMENTED for all of them. - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ +#include +#include "osapi-network-impl.h" + /**************************************************************************************** Network API ***************************************************************************************/ - /*---------------------------------------------------------------- * @@ -60,3 +58,4 @@ int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) } /* end OS_NetworkGetHostName_Impl */ + diff --git a/src/os/portable/os-impl-no-sockets.c b/src/os/portable/os-impl-no-sockets.c new file mode 100644 index 000000000..e8cef4572 --- /dev/null +++ b/src/os/portable/os-impl-no-sockets.c @@ -0,0 +1,208 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file os-impl-no-sockets.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: All functions return OS_ERR_NOT_IMPLEMENTED. + * This is used when network functionality is disabled by config. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include "osapi-sockets-impl.h" + + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + + +/**************************************************************************************** + Socket API + ***************************************************************************************/ + + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketOpen_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketOpen_Impl(uint32 sock_id) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketOpen_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketBind_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketBind_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketConnect_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketConnect_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAccept_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAccept_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketRecvFrom_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketRecvFrom_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketSendTo_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketSendTo_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketGetInfo_Impl (uint32 sock_id, OS_socket_prop_t *sock_prop) +{ + return OS_SUCCESS; +} /* end OS_SocketGetInfo_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAddrInit_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAddrInit_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAddrToString_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAddrToString_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAddrFromString_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAddrFromString_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAddrGetPort_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAddrGetPort_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SocketAddrSetPort_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum) +{ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_SocketAddrSetPort_Impl */ + + + + diff --git a/src/os/posix/osloader.c b/src/os/portable/os-impl-no-symtab.c similarity index 50% rename from src/os/posix/osloader.c rename to src/os/portable/os-impl-no-symtab.c index f74e1520f..7cd567384 100644 --- a/src/os/posix/osloader.c +++ b/src/os/portable/os-impl-no-symtab.c @@ -9,50 +9,33 @@ */ /** - * \file osloader.c + * \file os-impl-no-module.c * \author joseph.p.hickey@nasa.gov * - * Purpose: This file contains the module loader and symbol lookup functions for the OSAL. + * Purpose: This file contains a symbol table implementation for systems + * that do not use dynamic symbol lookups. It returns OS_ERR_NOT_IMPLEMENTED + * for all calls. */ -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include -#include -#include -#include "os-impl.h" - -/* - * The posix OSAL (by definition) always uses the posix dlfcn.h loading functions - * Other non-posix OS's (i.e. classic RTEMS) share posix-style dl functions which is - * why it is put into a separate code blob. - */ -#include "../portable/os-impl-posix-dl.c" +#include +#include "osapi-module-impl.h" /*---------------------------------------------------------------- * - * Function: OS_ModuleGetInfo_Impl + * Function: OS_SymbolLookup_Impl * * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail + * See description in os-impl.h for argument/return detail * *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) +int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) { - /* - * Note that the "dlinfo()" function might return some interesting - * information for this API, but this is actually a non-posix GNU extension. - * However this is not done for now, limiting to only posix APIs here - */ - return(OS_SUCCESS); + return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_ModuleGetInfo_Impl */ +} /* end OS_SymbolLookup_Impl */ - /*---------------------------------------------------------------- * * Function: OS_SymbolTableDump_Impl @@ -63,8 +46,11 @@ int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) *-----------------------------------------------------------------*/ int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) { - return(OS_ERR_NOT_IMPLEMENTED); } /* end OS_SymbolTableDump_Impl */ + + + + diff --git a/src/os/portable/os-impl-posix-dirs.c b/src/os/portable/os-impl-posix-dirs.c index 0aa9c112c..ea78d033f 100644 --- a/src/os/portable/os-impl-posix-dirs.c +++ b/src/os/portable/os-impl-posix-dirs.c @@ -15,16 +15,30 @@ * Purpose: This file Contains all of the api calls for manipulating files * in a file system / C library that implements the UNIX-style file API * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* Handled by includer */ +/* + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * stat() + * mkdir() + * rmdir() + * opendir() + * readdir() + * closedir() + * rewinddir() + */ +#include +#include + +#include "os-impl-dirs.h" +#include "osapi-dir-impl.h" /**************************************************************************************** DEFINES @@ -83,11 +97,12 @@ int32 OS_DirCreate_Impl(const char *local_path, uint32 access) *-----------------------------------------------------------------*/ int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) { - OS_impl_dir_table[local_id] = opendir(local_path); - if (OS_impl_dir_table[local_id] == NULL) + DIR *dp = opendir(local_path); + if (dp == NULL) { return OS_FS_ERROR; } + OS_impl_dir_table[local_id].dp = dp; return OS_FS_SUCCESS; } /* end OS_DirOpen_Impl */ @@ -101,8 +116,8 @@ int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) *-----------------------------------------------------------------*/ int32 OS_DirClose_Impl(uint32 local_id) { - closedir(OS_impl_dir_table[local_id]); - OS_impl_dir_table[local_id] = NULL; + closedir(OS_impl_dir_table[local_id].dp); + OS_impl_dir_table[local_id].dp = NULL; return OS_FS_SUCCESS; } /* end OS_DirClose_Impl */ @@ -127,7 +142,7 @@ int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) */ /* cppcheck-suppress readdirCalled */ /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id]); + de = readdir(OS_impl_dir_table[local_id].dp); if (de == NULL) { return OS_FS_ERROR; @@ -149,7 +164,7 @@ int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) *-----------------------------------------------------------------*/ int32 OS_DirRewind_Impl(uint32 local_id) { - rewinddir(OS_impl_dir_table[local_id]); + rewinddir(OS_impl_dir_table[local_id].dp); return OS_FS_SUCCESS; } /* end OS_DirRewind_Impl */ diff --git a/src/os/portable/os-impl-posix-dl-loader.c b/src/os/portable/os-impl-posix-dl-loader.c new file mode 100644 index 000000000..756c162aa --- /dev/null +++ b/src/os/portable/os-impl-posix-dl-loader.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file os-impl-posix-dl-loader.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: This file contains a module loader implementation for systems + * that implement a POSIX-style dynamic module loader. This includes + * RTEMS even if built without its native POSIX API. + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +/* + * Inclusions Defined by OSAL layer. + * + * typically this must include dlfcn.h and whatever else is required + * to get the prototypes of these functions: + * + * dlopen() + * dlclose() + * dlsym() + * dlerror() + */ +#include +#include + +#include "os-impl-loader.h" +#include "osapi-module-impl.h" + + + + +/**************************************************************************************** + Module Loader API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleLoad_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ) +{ + int32 status = OS_ERROR; + + dlerror(); + OS_impl_module_table[module_id].dl_handle = dlopen(translated_path, RTLD_NOW | RTLD_GLOBAL); + if (OS_impl_module_table[module_id].dl_handle != NULL) + { + status = OS_SUCCESS; + } + else + { + OS_DEBUG("Error loading shared library: %s\n", dlerror()); + } + + return status; + +} /* end OS_ModuleLoad_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleUnload_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleUnload_Impl ( uint32 module_id ) +{ + int32 status = OS_ERROR; + + /* + ** Attempt to close/unload the module + */ + dlerror(); + if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) + { + OS_impl_module_table[module_id].dl_handle = NULL; + status = OS_SUCCESS; + } + else + { + OS_DEBUG("Error unloading shared library: %s\n", dlerror()); + } + + return status; + +} /* end OS_ModuleUnload_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) +{ + /* + * Limiting strictly to POSIX-defined API means there is no defined + * method to get information about a module contents. + * + * The "dlinfo()" function might return some interesting information + * but this is actually a non-posix extension / platform-defined API. + * + * This returns success - although there is no information to add here, + * the parent/shared layer information is still valid. + */ + return(OS_SUCCESS); + +} /* end OS_ModuleGetInfo_Impl */ + + diff --git a/src/os/portable/os-impl-posix-dl-symtab.c b/src/os/portable/os-impl-posix-dl-symtab.c new file mode 100644 index 000000000..6c54f2061 --- /dev/null +++ b/src/os/portable/os-impl-posix-dl-symtab.c @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file os-impl-posix-dl-symtab.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: This file contains a module loader implementation for systems + * that implement a POSIX-style dynamic module loader. This includes + * RTEMS even if built without its native POSIX API. + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +/* + * Inclusions Defined by OSAL layer. + * + * typically this must include dlfcn.h and whatever else is required + * to get the prototypes of these functions: + * + * dlsym() + * dlerror() + * + * In POSIX these functions are grouped with the loader (dl) library + */ +#include +#include + +#include "os-impl-loader.h" +#include "osapi-module-impl.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +/* + * Determine what to pass in for the first parameter of dlsym() + * + * If the "os-impl-loader.h" header already defined this, then use that. + * + * Otherwise, check if the C library provides an "RTLD_DEFAULT" symbol - + * This symbol is not POSIX standard but many implementations do provide it. + * + * Lastly, if nothing else works, use NULL. This is technically undefined + * behavior per POSIX, but most implementations do seem to interpret this + * as referring to the complete process (base executable + all loaded modules). + */ +#ifndef OSAL_DLSYM_DEFAULT_HANDLE +#ifdef RTLD_DEFAULT +#define OSAL_DLSYM_DEFAULT_HANDLE RTLD_DEFAULT +#else +#define OSAL_DLSYM_DEFAULT_HANDLE NULL +#endif +#endif + + + +/**************************************************************************************** + Symbol table API + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) +{ + int32 status = OS_ERROR; + const char *dlError; /* Pointer to error string */ + void *Function; + + /* + * call dlerror() to clear any prior error that might have occurred. + */ + dlerror(); + Function = dlsym(OSAL_DLSYM_DEFAULT_HANDLE, SymbolName); + dlError = dlerror(); + + /* + * For the POSIX DL implementation, if the symbol does not exist + * then dlerror() is supposed to return non-null. This is intended + * to differentiate between valid symbols which are actually 0/NULL + * and invalid symbols that do not exist. + * + * Some implementations do _not_ implement this detail, and dlerror() + * still returns NULL after looking up an invalid symbol name. + * + * In practice, this is expected to be used for looking up functions + * and as such all valid symbols should be non-NULL, so NULL is considered + * an error even if the C library doesn't consider this an error. + */ + if( dlError == NULL && Function != NULL ) + { + *SymbolAddress = (cpuaddr)Function; + status = OS_SUCCESS; + } + + return status; + +} /* end OS_SymbolLookup_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolTableDump_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + * POSIX DL does not provide + * + *-----------------------------------------------------------------*/ +int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) +{ + /* + * Limiting strictly to POSIX-defined API means there is no defined + * method to get iterate over the symbol table. + * + * Some C libraries do offer an extension to provide this function, so + * if this becomes a requirement on those platforms, this function + * might need to move. + * + * Currently this is not a widely used/needed feature so it will report + * unimplemented here. + */ + + return(OS_ERR_NOT_IMPLEMENTED); + +} /* end OS_SymbolTableDump_Impl */ + + diff --git a/src/os/portable/os-impl-posix-dl.c b/src/os/portable/os-impl-posix-dl.c deleted file mode 100644 index 3a419a405..000000000 --- a/src/os/portable/os-impl-posix-dl.c +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file os-impl-posix-dl.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains a module loader implementation for systems - * that implement a POSIX-style dynamic module loader. This includes - * RTEMS even if built without its native POSIX API. - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -/* Handled by includer -- typically this must include dlfcn.h and whatever else is required - * to get the prototypes of these functions: - * - * dlopen() - * dlclose() - * dlsym() - */ - -/**************************************************************************************** - DEFINES - ***************************************************************************************/ - -/*************************************************************************************** - FUNCTION PROTOTYPES - **************************************************************************************/ - -/**************************************************************************************** - GLOBAL DATA - ***************************************************************************************/ - -/* - * A local lookup table for posix-specific information. - * This is not directly visible to the outside world. - */ -typedef struct -{ - /* cppcheck-suppress unusedStructMember */ - void *dl_handle; -} OS_impl_module_internal_record_t; - -/* - * The storage table is only instantiated when OS_MAX_MODULES is nonzero. - * It is allowed to be zero to save memory in statically linked apps. - * However even in that case it is still relevant to include the - * OS_SymbolLookup_Impl() function for symbol lookups. - * - * If neither loading nor symbol lookups are desired then this file - * shouldn't be used at all -- a no-op version should be used instead. - */ -#if (OS_MAX_MODULES > 0) -OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; -#endif - -/**************************************************************************************** - DEFINES - ***************************************************************************************/ - -/**************************************************************************************** - FUNCTION PROTOTYPES - ***************************************************************************************/ - -/**************************************************************************************** - GLOBAL DATA - ***************************************************************************************/ - - - -/**************************************************************************************** - INITIALIZATION FUNCTION - ***************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_Posix_ModuleAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Posix_ModuleAPI_Impl_Init(void) -{ -#if (OS_MAX_MODULES > 0) - memset(OS_impl_module_table, 0, sizeof(OS_impl_module_table)); -#endif - return(OS_SUCCESS); -} /* end OS_Posix_ModuleAPI_Impl_Init */ - -/**************************************************************************************** - Symbol table API - ***************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_SymbolLookup_Impl - * - * Purpose: Implemented per internal OSAL API - * See description in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) -{ - int32 status = OS_ERROR; - const char *dlError; /* Pointer to error string */ - void *Function; - - /* - * call dlerror() to clear any prior error that might have occured. - */ - dlerror(); - Function = dlsym((void *)0, SymbolName); - dlError = dlerror(); - if( dlError == NULL ) - { - /* considered successful if no error is present - - * note the address itself is allowed to be NULL */ - *SymbolAddress = (cpuaddr)Function; - status = OS_SUCCESS; - } - - return status; - -} /* end OS_SymbolLookup_Impl */ - - -/**************************************************************************************** - Module Loader API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleLoad_Impl - * - * Purpose: Implemented per internal OSAL API - * See description in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ) -{ - int32 status = OS_ERROR; - -#if (OS_MAX_MODULES > 0) - dlerror(); - OS_impl_module_table[module_id].dl_handle = dlopen(translated_path, RTLD_NOW | RTLD_GLOBAL); - if (OS_impl_module_table[module_id].dl_handle != NULL) - { - status = OS_SUCCESS; - } - else - { - OS_DEBUG("Error loading shared library: %s\n", dlerror()); - } -#endif - - return status; - -} /* end OS_ModuleLoad_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleUnload_Impl - * - * Purpose: Implemented per internal OSAL API - * See description in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl ( uint32 module_id ) -{ - int32 status = OS_ERROR; - -#if (OS_MAX_MODULES > 0) - /* - ** Attempt to close/unload the module - */ - dlerror(); - if (dlclose(OS_impl_module_table[module_id].dl_handle) == 0) - { - OS_impl_module_table[module_id].dl_handle = NULL; - status = OS_SUCCESS; - } - else - { - OS_DEBUG("Error unloading shared library: %s\n", dlerror()); - } -#endif - - return status; - -} /* end OS_ModuleUnload_Impl */ - - - - diff --git a/src/os/portable/os-impl-posix-files.c b/src/os/portable/os-impl-posix-files.c index 0120e9244..f618bdf49 100644 --- a/src/os/portable/os-impl-posix-files.c +++ b/src/os/portable/os-impl-posix-files.c @@ -14,17 +14,29 @@ * * Purpose: This file Contains all of the api calls for manipulating files * in a file system / C library that implements the POSIX-style file API - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* Handled by includer */ +/* + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * open() + * stat() + * chmod() + * remove() + * rename() + */ +#include +#include + +#include "os-impl-files.h" +#include "osapi-file-impl.h" + /**************************************************************************************** DEFINES diff --git a/src/os/portable/os-impl-posix-gettime.c b/src/os/portable/os-impl-posix-gettime.c index 5ba273ef2..ec631c5b3 100644 --- a/src/os/portable/os-impl-posix-gettime.c +++ b/src/os/portable/os-impl-posix-gettime.c @@ -18,16 +18,30 @@ * The OS-specific code must #include the correct headers that define the * prototypes for these functions before including this implementation file. * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* Handled by includer */ +/* + * Inclusions Defined by OSAL layer. + * + * This must provide the prototypes of these functions: + * + * clock_gettime() + * clock_settime() + * + * and the "struct timespec" definition + */ +#include +#include + +#include +#include "os-impl-gettime.h" +#include "osapi-clock-impl.h" + + /**************************************************************************************** @@ -49,7 +63,7 @@ int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) int32 ReturnCode; struct timespec time; - Status = clock_gettime(CLOCK_REALTIME, &time); + Status = clock_gettime(OSAL_GETTIME_SOURCE_CLOCK, &time); if (Status == 0) { @@ -84,7 +98,7 @@ int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) time.tv_sec = time_struct -> seconds; time.tv_nsec = (time_struct -> microsecs * 1000); - Status = clock_settime(CLOCK_REALTIME, &time); + Status = clock_settime(OSAL_GETTIME_SOURCE_CLOCK, &time); if (Status == 0) { diff --git a/src/os/portable/os-impl-posix-io.c b/src/os/portable/os-impl-posix-io.c index 834e553b8..238014061 100644 --- a/src/os/portable/os-impl-posix-io.c +++ b/src/os/portable/os-impl-posix-io.c @@ -17,17 +17,28 @@ * * These generic ops may apply to regular files, sockets, pipes, or * special devices, depending on the OS in use. - * - * NOTE: This is a "template" file and not a directly usable source file. - * It must be adapted/instantiated from within the OS-specific - * implementation on platforms that wish to use this template. */ /**************************************************************************************** INCLUDE FILES ***************************************************************************************/ -/* handled by includer */ +/* + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * read() + * write() + * close() + */ +#include +#include + +#include "os-impl-io.h" +#include "osapi-file-impl.h" +#include "osapi-select-impl.h" + /* some OS libraries (e.g. VxWorks) do not declare the API to be const-correct * It can still use this generic implementation but the call to write() must be diff --git a/src/os/portable/os-impl-posix-network.c b/src/os/portable/os-impl-posix-network.c new file mode 100644 index 000000000..1ac58a5ce --- /dev/null +++ b/src/os/portable/os-impl-posix-network.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file os-impl-bsd-sockets.c + * \author joseph.p.hickey@nasa.gov + * + * Purpose: This file contains the network functionality for + * systems which implement the POSIX-defined network hostname/id functions. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +/* + * Inclusions Defined by OSAL layer. + * + * This must include whatever is required to get the prototypes of these functions: + * + * gethostname() + * gethostid() + * + * Both of these routines should conform to X/Open 5 definition. + */ +#include +#include +#include "os-impl.h" +#include "os-impl-network.h" + + +/**************************************************************************************** + Network API + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetHostName_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) +{ + int32 return_code; + + if ( gethostname(host_name, name_len) < 0 ) + { + return_code = OS_ERROR; + } + else + { + /* + * posix does not say that the name is always + * null terminated, so its worthwhile to ensure it + */ + host_name[name_len - 1] = 0; + return_code = OS_SUCCESS; + } + + return(return_code); +} /* end OS_NetworkGetHostName_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetID_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetID_Impl (int32 *IdBuf) +{ + /* gethostid() has no failure modes */ + *IdBuf = gethostid(); + return OS_SUCCESS; +} /* end OS_NetworkGetID_Impl */ + + diff --git a/src/os/posix/CMakeLists.txt b/src/os/posix/CMakeLists.txt index b628aefe0..e89019d73 100644 --- a/src/os/posix/CMakeLists.txt +++ b/src/os/posix/CMakeLists.txt @@ -5,15 +5,69 @@ ###################################################################### # This CMake script generates targets specific to the POSIX implementation -# It defines an OBJECT target named "osal_posix_impl" +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) -add_library(osal_posix_impl OBJECT - osapi.c - osfileapi.c - osfilesys.c - osloader.c - osnetwork.c - osselect.c - ostimer.c +# The basic set of files which are always built +set(POSIX_BASE_SRCLIST + src/os-impl-binsem.c + src/os-impl-common.c + src/os-impl-console.c + src/os-impl-countsem.c + src/os-impl-dirs.c + src/os-impl-errors.c + src/os-impl-files.c + src/os-impl-filesys.c + src/os-impl-fpu.c + src/os-impl-heap.c + src/os-impl-idmap.c + src/os-impl-interrupts.c + src/os-impl-mutex.c + src/os-impl-queues.c + src/os-impl-shell.c + src/os-impl-tasks.c + src/os-impl-timebase.c ) +# Use portable blocks for basic I/O +set(POSIX_IMPL_SRCLIST + ../portable/os-impl-posix-gettime.c + ../portable/os-impl-console-bsp.c + ../portable/os-impl-bsd-select.c + ../portable/os-impl-posix-io.c + ../portable/os-impl-posix-files.c + ../portable/os-impl-posix-dirs.c +) + +# If some form of module loading is configured, +# then build the module loader +if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER) + list(APPEND POSIX_IMPL_SRCLIST + src/os-impl-loader.c + ../portable/os-impl-posix-dl-loader.c + ../portable/os-impl-posix-dl-symtab.c + ) +else () + list(APPEND POSIX_IMPL_SRCLIST + src/os-impl-no-module.c + ../portable/os-impl-no-loader.c + ../portable/os-impl-no-symtab.c + ) +endif () + +if (OSAL_CONFIG_INCLUDE_NETWORK) + list(APPEND POSIX_IMPL_SRCLIST + ../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation + ../portable/os-impl-posix-network.c # Use POSIX-defined hostname/id implementation + ) +else() + list(APPEND POSIX_IMPL_SRCLIST + ../portable/os-impl-no-network.c # non-implemented versions of all network APIs + ../portable/os-impl-no-sockets.c # non-implemented versions of all socket APIs + ) +endif () + +# Defines an OBJECT target named "osal_posix_impl" with selected source files +add_library(osal_posix_impl OBJECT + ${POSIX_BASE_SRCLIST} + ${POSIX_IMPL_SRCLIST} +) diff --git a/src/os/posix/inc/os-impl-binsem.h b/src/os/posix/inc/os-impl-binsem.h new file mode 100644 index 000000000..20d55df25 --- /dev/null +++ b/src/os/posix/inc/os-impl-binsem.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_BINSEM_H_ +#define INCLUDE_OS_IMPL_BINSEM_H_ + +#include +#include +#include + +/* Binary Semaphores */ +typedef struct +{ + pthread_mutex_t id; + pthread_cond_t cv; + volatile sig_atomic_t flush_request; + volatile sig_atomic_t current_value; +} OS_impl_binsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + + + +#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ + diff --git a/src/os/posix/inc/os-impl-console.h b/src/os/posix/inc/os-impl-console.h new file mode 100644 index 000000000..09eda7d3d --- /dev/null +++ b/src/os/posix/inc/os-impl-console.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ +#define INCLUDE_OS_IMPL_CONSOLE_H_ + +#include +#include +#include +#include + +/* Console device */ +typedef struct +{ + bool is_async; + sem_t data_sem; +}OS_impl_console_internal_record_t; + + +extern OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + + +#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ + diff --git a/src/os/posix/inc/os-impl-countsem.h b/src/os/posix/inc/os-impl-countsem.h new file mode 100644 index 000000000..7393700c2 --- /dev/null +++ b/src/os/posix/inc/os-impl-countsem.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ +#define INCLUDE_OS_IMPL_COUNTSEM_H_ + +#include +#include + +typedef struct +{ + sem_t id; +} OS_impl_countsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + + +#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ + diff --git a/src/os/posix/inc/os-impl-dirs.h b/src/os/posix/inc/os-impl-dirs.h new file mode 100644 index 000000000..a59574c48 --- /dev/null +++ b/src/os/posix/inc/os-impl-dirs.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_DIRS_H_ +#define INCLUDE_OS_IMPL_DIRS_H_ + +#include +#include +#include +#include +#include +#include + +typedef struct +{ + DIR *dp; +} OS_impl_dir_internal_record_t; + + +/* + * The directory handle table. + */ +extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + + +#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ + diff --git a/src/os/posix/inc/os-impl-files.h b/src/os/posix/inc/os-impl-files.h new file mode 100644 index 000000000..a46e69683 --- /dev/null +++ b/src/os/posix/inc/os-impl-files.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_FILES_H_ +#define INCLUDE_OS_IMPL_FILES_H_ + +#include "os-impl-io.h" + +#include +#include +#include + + +/* + * These two constants (EUID and EGID) are local cache of the + * euid and egid of the user running the OSAL application. They + * assist the "stat" implementation in determination of permissions. + * + * For an OS that does not have multiple users, these could be + * defined as 0. Otherwise they should be populated via the system + * geteuid/getegid calls. + */ +extern uid_t OS_IMPL_SELF_EUID; +extern gid_t OS_IMPL_SELF_EGID; + + +extern const int OS_IMPL_REGULAR_FILE_FLAGS; + +#endif /* INCLUDE_OS_IMPL_FILES_H_ */ + diff --git a/src/os/posix/inc/os-impl-gettime.h b/src/os/posix/inc/os-impl-gettime.h new file mode 100644 index 000000000..b8d021d0d --- /dev/null +++ b/src/os/posix/inc/os-impl-gettime.h @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-gettime.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_GETTIME_H_ +#define INCLUDE_OS_IMPL_GETTIME_H_ + +#include +#include + + +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC + + +#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ + diff --git a/src/os/posix/inc/os-impl-io.h b/src/os/posix/inc/os-impl-io.h new file mode 100644 index 000000000..74a733749 --- /dev/null +++ b/src/os/posix/inc/os-impl-io.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-io.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_IO_H_ +#define INCLUDE_OS_IMPL_IO_H_ + +#include +#include +#include +#include +#include +#include + +typedef struct +{ + int fd; + bool selectable; +} OS_Posix_file_internal_record_t; + +/* + * The global file handle table. + * + * This is shared by all OSAL entities that perform low-level I/O. + */ +extern OS_Posix_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + + +#endif /* INCLUDE_OS_IMPL_IO_H_ */ + diff --git a/src/os/posix/inc/os-impl-loader.h b/src/os/posix/inc/os-impl-loader.h new file mode 100644 index 000000000..445031383 --- /dev/null +++ b/src/os/posix/inc/os-impl-loader.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-loader.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_LOADER_H_ +#define INCLUDE_OS_IMPL_LOADER_H_ + +#include +#include + +/* + * A local lookup table for posix-specific information. + * This is not directly visible to the outside world. + */ +typedef struct +{ + /* cppcheck-suppress unusedStructMember */ + void *dl_handle; +} OS_impl_module_internal_record_t; + +/* + * The storage table is only instantiated when OS_MAX_MODULES is nonzero. + * It is allowed to be zero to save memory in statically linked apps. + * However even in that case it is still relevant to include the + * OS_SymbolLookup_Impl() function for symbol lookups. + * + * If neither loading nor symbol lookups are desired then this file + * shouldn't be used at all -- a no-op version should be used instead. + */ +extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; + +#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ + diff --git a/src/os/posix/inc/os-impl-mutex.h b/src/os/posix/inc/os-impl-mutex.h new file mode 100644 index 000000000..4c75f31f2 --- /dev/null +++ b/src/os/posix/inc/os-impl-mutex.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_MUTEX_H_ +#define INCLUDE_OS_IMPL_MUTEX_H_ + +#include +#include + +/* Mutexes */ +typedef struct +{ + pthread_mutex_t id; +} OS_impl_mutex_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_mutex_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + + +#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ + diff --git a/src/os/posix/inc/os-impl-network.h b/src/os/posix/inc/os-impl-network.h new file mode 100644 index 000000000..ed225857a --- /dev/null +++ b/src/os/posix/inc/os-impl-network.h @@ -0,0 +1,28 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-network.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_NETWORK_H_ +#define INCLUDE_OS_IMPL_NETWORK_H_ + +#include + + +#endif /* INCLUDE_OS_IMPL_NETWORK_H_ */ + diff --git a/src/os/posix/inc/os-impl-queues.h b/src/os/posix/inc/os-impl-queues.h new file mode 100644 index 000000000..4510d7785 --- /dev/null +++ b/src/os/posix/inc/os-impl-queues.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_QUEUES_H_ +#define INCLUDE_OS_IMPL_QUEUES_H_ + +#include +#include + +/* queues */ +typedef struct +{ + mqd_t id; +} OS_impl_queue_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + + +#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ + diff --git a/src/os/posix/inc/os-impl-select.h b/src/os/posix/inc/os-impl-select.h new file mode 100644 index 000000000..1d9965480 --- /dev/null +++ b/src/os/posix/inc/os-impl-select.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-select.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SELECT_H_ +#define INCLUDE_OS_IMPL_SELECT_H_ + +#include "os-impl-io.h" + +#include +#include + + +#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ + diff --git a/src/os/posix/inc/os-impl-sockets.h b/src/os/posix/inc/os-impl-sockets.h new file mode 100644 index 000000000..836e2f619 --- /dev/null +++ b/src/os/posix/inc/os-impl-sockets.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-sockets.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ +#define INCLUDE_OS_IMPL_SOCKETS_H_ + +#include "os-impl-io.h" + +#include +#include +#include +#include + + +#define OS_NETWORK_SUPPORTS_IPV6 + +/* + * A full POSIX-compliant I/O layer should support using + * nonblocking I/O calls in combination with select(). + */ +#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK + + + +#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ + diff --git a/src/os/posix/inc/os-impl-tasks.h b/src/os/posix/inc/os-impl-tasks.h new file mode 100644 index 000000000..e7dc24db7 --- /dev/null +++ b/src/os/posix/inc/os-impl-tasks.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TASKS_H_ +#define INCLUDE_OS_IMPL_TASKS_H_ + +#include +#include + +/*tasks */ +typedef struct +{ + pthread_t id; +} OS_impl_task_internal_record_t; + + +/* Tables where the OS object information is stored */ +extern OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + + +#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ + diff --git a/src/os/posix/inc/os-impl-timebase.h b/src/os/posix/inc/os-impl-timebase.h new file mode 100644 index 000000000..855e0390a --- /dev/null +++ b/src/os/posix/inc/os-impl-timebase.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-timebase.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ +#define INCLUDE_OS_IMPL_TIMEBASE_H_ + +#include +#include +#include + + +typedef struct +{ + pthread_t handler_thread; + pthread_mutex_t handler_mutex; + timer_t host_timerid; + int assigned_signal; + sigset_t sigset; + sig_atomic_t reset_flag; + struct timespec softsleep; + +} OS_impl_timebase_internal_record_t; + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; + + +#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ + diff --git a/src/os/posix/os-posix.h b/src/os/posix/inc/os-posix.h similarity index 73% rename from src/os/posix/os-posix.h rename to src/os/posix/inc/os-posix.h index 0fdccf7be..792325cf8 100644 --- a/src/os/posix/os-posix.h +++ b/src/os/posix/inc/os-posix.h @@ -1,28 +1,33 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file os-posix.h - * \author joseph.p.hickey@nasa.gov + * \file os-posix.h + * \ingroup posix + * \author joseph.p.hickey@nasa.gov * * Purpose: This file contains definitions that are shared across the POSIX * OSAL implementation. This file is private to the POSIX port and it * may contain POSIX-specific definitions. - * */ +#ifndef INCLUDE_OS_POSIX_H_ +#define INCLUDE_OS_POSIX_H_ + + /**************************************************************************************** COMMON INCLUDE FILES ***************************************************************************************/ -#ifndef _os_posix_h_ -#define _os_posix_h_ #include #include @@ -39,9 +44,10 @@ #include #include -#include "common_types.h" -#include "osapi.h" -#include "os-impl.h" +/* + * Use the global definitions from the shared layer + */ +#include /**************************************************************************************** DEFINES @@ -71,12 +77,6 @@ typedef struct int SelectedRtScheduler; } POSIX_GlobalVars_t; -typedef struct -{ - int fd; - bool selectable; -} OS_Posix_filehandle_entry_t; - /**************************************************************************************** GLOBAL DATA @@ -84,15 +84,6 @@ typedef struct extern POSIX_GlobalVars_t POSIX_GlobalVars; -/* - * The global file handle table. - * - * This table is shared across multiple units (files, sockets, etc) and they will share - * the same file handle table from the basic file I/O. - */ -extern OS_Posix_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - - /**************************************************************************************** POSIX IMPLEMENTATION FUNCTION PROTOTYPES @@ -109,7 +100,11 @@ int32 OS_Posix_StreamAPI_Impl_Init(void); int32 OS_Posix_DirAPI_Impl_Init(void); int32 OS_Posix_FileSysAPI_Impl_Init(void); +int32 OS_Posix_TableMutex_Init(uint32 idtype); + int32 OS_Posix_InternalTaskCreate_Impl (pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, void *entry_arg); +void OS_Posix_CompAbsDelayTime( uint32 msecs , struct timespec * tm); + +#endif /* INCLUDE_OS_POSIX_H_ */ -#endif /* End of os-posix*/ diff --git a/src/os/posix/osapi.c b/src/os/posix/osapi.c deleted file mode 100644 index 6ad957968..000000000 --- a/src/os/posix/osapi.c +++ /dev/null @@ -1,2490 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osapi.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains some of the OS APIs abstraction layer - * implementation for POSIX, specifically for Linux with the 2.6 kernel ( > 2.6.18 ) - * with the glibc library. uClibc or other embedded C libraries are not yet tested. - * - * This implementation works with the "shared" OSAL to complete the functionality. - * This contains only the POSIX-specific parts. - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-posix.h" -#include "bsp-impl.h" -#include - -/* - * Defines - */ -#ifndef PTHREAD_STACK_MIN -#define PTHREAD_STACK_MIN (8*1024) -#endif - -/* - * Added SEM_VALUE_MAX Define - */ -#ifndef SEM_VALUE_MAX -#define SEM_VALUE_MAX (UINT32_MAX/2) -#endif - -/* - * By default use the stdout stream for the console (OS_printf) - */ -#define OSAL_CONSOLE_FILENO STDOUT_FILENO - -/* - * By default the console output is always asynchronous - * (equivalent to "OS_UTILITY_TASK_ON" being set) - * - * This option was removed from osconfig.h and now is - * assumed to always be on. - */ -#define OS_CONSOLE_ASYNC true -#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY - -/* - * Global data for the API - */ - -/* - * Tables for the properties of objects - */ - -/*tasks */ -typedef struct -{ - pthread_t id; -} OS_impl_task_internal_record_t; - -/* queues */ -typedef struct -{ - mqd_t id; -} OS_impl_queue_internal_record_t; - -/* Counting & Binary Semaphores */ -typedef struct -{ - pthread_mutex_t id; - pthread_cond_t cv; - volatile sig_atomic_t flush_request; - volatile sig_atomic_t current_value; -}OS_impl_binsem_internal_record_t; - -typedef struct -{ - sem_t id; -}OS_impl_countsem_internal_record_t; - -/* Mutexes */ -typedef struct -{ - pthread_mutex_t id; -}OS_impl_mut_sem_internal_record_t; - -/* Console device */ -typedef struct -{ - bool is_async; - sem_t data_sem; - int out_fd; -}OS_impl_console_internal_record_t; - - -/* Tables where the OS object information is stored */ -OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; -OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; -OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; -OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; -OS_impl_mut_sem_internal_record_t OS_impl_mut_sem_table [OS_MAX_MUTEXES]; -OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; - -typedef struct -{ - pthread_mutex_t mutex; - sigset_t sigmask; -} POSIX_GlobalLock_t; - -static POSIX_GlobalLock_t OS_global_task_table_mut; -static POSIX_GlobalLock_t OS_queue_table_mut; -static POSIX_GlobalLock_t OS_bin_sem_table_mut; -static POSIX_GlobalLock_t OS_mut_sem_table_mut; -static POSIX_GlobalLock_t OS_count_sem_table_mut; -static POSIX_GlobalLock_t OS_stream_table_mut; -static POSIX_GlobalLock_t OS_dir_table_mut; -static POSIX_GlobalLock_t OS_timebase_table_mut; -static POSIX_GlobalLock_t OS_module_table_mut; -static POSIX_GlobalLock_t OS_filesys_table_mut; -static POSIX_GlobalLock_t OS_console_mut; - -static POSIX_GlobalLock_t * const MUTEX_TABLE[] = - { - [OS_OBJECT_TYPE_UNDEFINED] = NULL, - [OS_OBJECT_TYPE_OS_TASK] = &OS_global_task_table_mut, - [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_mut, - [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_mut, - [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_mut, - [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mut_sem_table_mut, - [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, - [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, - [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, - [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, - [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, - [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, - }; - - -POSIX_GlobalVars_t POSIX_GlobalVars = { 0 }; - -enum -{ - MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) -}; - -const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; - -/* - * Local Function Prototypes - */ -static void OS_CompAbsDelayTime( uint32 msecs , struct timespec * tm); -static int OS_PriorityRemap(uint32 InputPri); - - -/*---------------------------------------------------------------- - * - * Function: OS_NoopSigHandler - * - * Purpose: Local helper routine, not part of OSAL API. - * A POSIX signal handler that does nothing - * - *-----------------------------------------------------------------*/ -static void OS_NoopSigHandler (int signal) -{ -} /* end OS_NoopSigHandler */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_Lock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) -{ - POSIX_GlobalLock_t *mut; - sigset_t previous; - - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else - { - mut = NULL; - } - - if (mut == NULL) - { - return OS_ERROR; - } - - if (pthread_sigmask(SIG_SETMASK, &POSIX_GlobalVars.MaximumSigMask, &previous) != 0) - { - return OS_ERROR; - } - - if (pthread_mutex_lock(&mut->mutex) != 0) - { - return OS_ERROR; - } - - /* Only set values inside the GlobalLock _after_ it is locked */ - mut->sigmask = previous; - - return OS_SUCCESS; -} /* end OS_Lock_Global_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_Unlock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) -{ - POSIX_GlobalLock_t *mut; - sigset_t previous; - - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else - { - mut = NULL; - } - - if (mut == NULL) - { - return OS_ERROR; - } - - /* Only get values inside the GlobalLock _before_ it is unlocked */ - previous = mut->sigmask; - - if (pthread_mutex_unlock(&mut->mutex) != 0) - { - return OS_ERROR; - } - - pthread_sigmask(SIG_SETMASK, &previous, NULL); - - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ - - -/*--------------------------------------------------------------------------------------- - Name: OS_API_Init - - Purpose: Initialize the tables that the OS API uses to keep track of information - about objects - - returns: OS_SUCCESS or OS_ERROR ----------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) -{ - int ret; - int32 return_code = OS_SUCCESS; - pthread_mutexattr_t mutex_attr; - - do - { - /* Initialize the table mutex for the given idtype */ - if (idtype < MUTEX_TABLE_SIZE && MUTEX_TABLE[idtype] != NULL) - { - /* - ** initialize the pthread mutex attribute structure with default values - */ - ret = pthread_mutexattr_init(&mutex_attr); - if ( ret != 0 ) - { - OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n",strerror(ret)); - return_code = OS_ERROR; - break; - } - - /* - ** Allow the mutex to use priority inheritance - */ - ret = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT) ; - if ( ret != 0 ) - { - OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n",strerror(ret)); - return_code = OS_ERROR; - break; - } - - /* - ** Set the mutex type to RECURSIVE so a thread can do nested locks - ** TBD - not sure if this is really desired, but keep it for now. - */ - ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); - if ( ret != 0 ) - { - OS_DEBUG("Error: pthread_mutexattr_settype failed: %s\n",strerror(ret)); - return_code = OS_ERROR; - break; - } - - ret = pthread_mutex_init(&MUTEX_TABLE[idtype]->mutex, &mutex_attr); - if ( ret != 0 ) - { - OS_DEBUG("Error: pthread_mutex_init failed: %s\n",strerror(ret)); - return_code = OS_ERROR; - break; - } - } - - switch(idtype) - { - case OS_OBJECT_TYPE_OS_TASK: - return_code = OS_Posix_TaskAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_QUEUE: - return_code = OS_Posix_QueueAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_BINSEM: - return_code = OS_Posix_BinSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_COUNTSEM: - return_code = OS_Posix_CountSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MUTEX: - return_code = OS_Posix_MutexAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MODULE: - return_code = OS_Posix_ModuleAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_TIMEBASE: - return_code = OS_Posix_TimeBaseAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_STREAM: - return_code = OS_Posix_StreamAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_DIR: - return_code = OS_Posix_DirAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_FILESYS: - return_code = OS_Posix_FileSysAPI_Impl_Init(); - break; - default: - break; - } - } - while (0); - - - return(return_code); -} /* end OS_API_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IdleLoop_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_IdleLoop_Impl() -{ - /* - * Unblock signals and wait for something to occur - * - * Note - "NormalSigMask" was calculated during task init to be the original signal mask - * of the process PLUS all "RT" signals. The RT signals are used by timers, so we want - * to keep them masked here (this is different than the original POSIX impl). The - * timebase objects have a dedicated thread that will be doing "sigwait" on those. - */ - sigsuspend(&POSIX_GlobalVars.NormalSigMask); -} /* end OS_IdleLoop_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ApplicationShutdown_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ApplicationShutdown_Impl() -{ - /* - * Raise a signal that is unblocked in OS_IdleLoop(), - * which should break it out of the sigsuspend() call. - */ - kill(getpid(), SIGHUP); -} /* end OS_ApplicationShutdown_Impl */ - - -/*--------------------------------------------------------------------------------------- - Name: OS_PthreadEntry - - Purpose: A Simple pthread-compatible entry point that calls the real task function - - returns: NULL - - NOTES: This wrapper function is only used locally by OS_TaskCreate below - ----------------------------------------------------------------------------------------*/ -static void *OS_PthreadTaskEntry(void *arg) -{ - OS_U32ValueWrapper_t local_arg; - - local_arg.opaque_arg = arg; - OS_TaskEntryPoint(local_arg.value); /* Never returns */ - - return NULL; -} - -/*--------------------------------------------------------------------------------------- - Name: OS_Posix_GetSchedulerParams - - Purpose: Helper function to get the details of the given OS scheduling policy. - Determines if the policy is usable by OSAL - namely, that it provides - enough priority levels to be useful. - - returns: true if policy is suitable for use by OSAL - - NOTES: Only used locally by task API initialization - ----------------------------------------------------------------------------------------*/ -static bool OS_Posix_GetSchedulerParams(int sched_policy, POSIX_PriorityLimits_t *PriLim) -{ - int ret; - - /* - * Set up the local Min/Max priority levels (varies by OS and scheduler policy) - * - * Per POSIX: - * - The sched_get_priority_min/max() returns a number >= 0 on success. - * (-1 indicates an error) - * - Numerically higher values are scheduled before numerically lower values - * - A compliant OS will have a spread of at least 32 between min and max - */ - ret = sched_get_priority_max(sched_policy); - if (ret < 0) - { - OS_DEBUG("Policy %d: Unable to obtain maximum scheduling priority: %s\n", sched_policy, strerror(errno)); - return false; - } - - PriLim->PriorityMax = ret; - - ret = sched_get_priority_min(sched_policy); - if (ret < 0) - { - OS_DEBUG("Policy %d: Unable to obtain minimum scheduling priority: %s\n", sched_policy, strerror(errno)); - return false; - } - - PriLim->PriorityMin = ret; - - /* - * For OSAL, the absolute minimum spread between min and max must be 4. - * - * Although POSIX stipulates 32, we don't necessarily need that many, but we - * also want to confirm that there is an acceptable spread. - * - * - Highest is reserved for the root task - * - Next highest is reserved for OSAL priority=0 task(s) - * - Lowest is reserved for OSAL priority=255 tasks(s) - * - Need at least 1 for everything else. - */ - if ((PriLim->PriorityMax - PriLim->PriorityMin) < 4) - { - OS_DEBUG("Policy %d: Insufficient spread between priority min-max: %d-%d\n", - sched_policy, (int)PriLim->PriorityMin, (int)PriLim->PriorityMax); - return false; - } - - /* If we get here, then the sched_policy is potentially valid */ - OS_DEBUG("Policy %d: available, min-max: %d-%d\n", sched_policy, - (int)PriLim->PriorityMin, (int)PriLim->PriorityMax); - return true; -} /* end OS_Posix_GetSchedulerParams */ - -/* - ********************************************************************************* - * TASK API - ********************************************************************************* - */ - -/*--------------------------------------------------------------------------------------- - Name: OS_Posix_TaskAPI_Impl_Init - - Purpose: Initialize the Posix Task data structures - - ----------------------------------------------------------------------------------------*/ -int32 OS_Posix_TaskAPI_Impl_Init(void) -{ - int ret; - int sig; - struct sched_param sched_param; - int sched_policy; - POSIX_PriorityLimits_t sched_fifo_limits; - bool sched_fifo_valid; - POSIX_PriorityLimits_t sched_rr_limits; - bool sched_rr_valid; - - /* Initialize Local Tables */ - memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); - - /* Clear the "limits" structs otherwise the compiler may warn - * about possibly being used uninitialized (false warning) - */ - memset(&sched_fifo_limits, 0, sizeof(sched_fifo_limits)); - memset(&sched_rr_limits, 0, sizeof(sched_rr_limits)); - - /* - * Create the key used to store OSAL task IDs - */ - ret = pthread_key_create(&POSIX_GlobalVars.ThreadKey, NULL ); - if ( ret != 0 ) - { - OS_DEBUG("Error creating thread key: %s (%d)\n",strerror(ret),ret); - return OS_ERROR; - } - - /* - ** Disable Signals to parent thread and therefore all - ** child threads create will block all signals - ** Note: Timers will not work in the application unless - ** threads are spawned in OS_Application_Startup. - */ - sigfillset(&POSIX_GlobalVars.MaximumSigMask); - - /* - * Keep these signals unblocked so the process can be interrupted - */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGINT); /* CTRL+C */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGABRT); /* Abort */ - - /* - * One should not typically block ANY of the synchronous error - * signals, i.e. SIGSEGV, SIGFPE, SIGILL, SIGBUS - * - * The kernel generates these signals in response to hardware events - * and they get routed to the _specific thread_ that was executing when - * the problem occurred. - * - * While it is technically possible to block these signals, the result is - * undefined, and it makes debugging _REALLY_ hard. If the kernel ever does - * send one it means there really is a major problem, best to listen to it, - * and not ignore it. - */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGSEGV); /* Segfault */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGILL); /* Illegal instruction */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGBUS); /* Bus Error */ - sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGFPE); /* Floating Point Exception */ - - /* - * Set the mask and store the original (default) mask in the POSIX_GlobalVars.NormalSigMask - */ - sigprocmask(SIG_SETMASK, &POSIX_GlobalVars.MaximumSigMask, &POSIX_GlobalVars.NormalSigMask); - - /* - * Add all "RT" signals into the POSIX_GlobalVars.NormalSigMask - * This will be used for the signal mask of the main thread - * (This way it will end up as the default/original signal mask plus all RT sigs) - */ - for (sig = SIGRTMIN; sig <= SIGRTMAX; ++sig) - { - sigaddset(&POSIX_GlobalVars.NormalSigMask, sig); - } - - /* - * SIGHUP is used to wake up the main thread when necessary, - * so make sure it is NOT in the set. - */ - sigdelset(&POSIX_GlobalVars.NormalSigMask, SIGHUP); - - /* - ** Install noop as the signal handler for SIGUP. - */ - signal(SIGHUP, OS_NoopSigHandler); - - /* - ** Raise the priority of the current (main) thread so that subsequent - ** application initialization will complete. This had previously been - ** done by the BSP and but it is moved here. - ** - ** This will only work if the user owning this process has permission - ** to create real time threads. Otherwise, the default priority will - ** be retained. Typically this is only the root user, but finer grained - ** permission controls are out there. So if it works, great, but if - ** a permission denied error is generated, that is OK too - this allows - ** easily debugging code as a normal user. - */ - ret = pthread_getschedparam(pthread_self(), &sched_policy, &sched_param); - if (ret == 0) - { - POSIX_GlobalVars.SelectedRtScheduler = sched_policy; /* Fallback/default */ - do - { - sched_fifo_valid = OS_Posix_GetSchedulerParams(SCHED_FIFO, &sched_fifo_limits); - sched_rr_valid = OS_Posix_GetSchedulerParams(SCHED_RR, &sched_rr_limits); - - /* - * If both policies are valid, choose the best. In general, FIFO is preferred - * since it is simpler. - * - * But, RR is preferred if mapping several OSAL priority levels into the - * same local priority level. For instance, if 2 OSAL tasks are created at priorities - * "2" and "1", both may get mapped to local priority 98, and if using FIFO then the - * task at priority "2" could run indefinitely, never letting priority "1" execute. - * - * This violates the original intent, which would be to have priority "1" preempt - * priority "2" tasks. RR is less bad since it at least guarantees both tasks some - * CPU time, - */ - if (sched_fifo_valid && sched_rr_valid) - { - /* - * If the spread from min->max is greater than what OSAL actually needs, - * then FIFO is the preferred scheduler. Must take into account one extra level - * for the root task. - */ - if ((sched_fifo_limits.PriorityMax - sched_fifo_limits.PriorityMin) > OS_MAX_TASK_PRIORITY) - { - sched_policy = SCHED_FIFO; - POSIX_GlobalVars.PriLimits = sched_fifo_limits; - } - else - { - sched_policy = SCHED_RR; - POSIX_GlobalVars.PriLimits = sched_rr_limits; - } - - } - else if (sched_fifo_valid) - { - /* only FIFO is available */ - sched_policy = SCHED_FIFO; - POSIX_GlobalVars.PriLimits = sched_fifo_limits; - } - else if (sched_rr_valid) - { - /* only RR is available */ - sched_policy = SCHED_RR; - POSIX_GlobalVars.PriLimits = sched_rr_limits; - } - else - { - /* Nothing is valid, use default */ - break; - } - - /* - * This OSAL POSIX implementation will reserve the absolute highest priority - * for the root thread, which ultimately will just pend in sigsuspend() so - * it will not actually DO anything, except if sent a signal. This way, - * that thread will still be able to preempt a high-priority user thread that - * has gone awry (i.e. using 100% cpu in FIFO mode). - */ - sched_param.sched_priority = POSIX_GlobalVars.PriLimits.PriorityMax; - --POSIX_GlobalVars.PriLimits.PriorityMax; - - OS_DEBUG("Selected policy %d for RT tasks, root task = %d\n", sched_policy, (int)sched_param.sched_priority); - - /* - * If the spread from min->max is greater than what OSAL actually needs, - * then truncate it at the number of OSAL priorities. This will end up mapping 1:1. - * and leaving the highest priority numbers unused. - */ - if ((POSIX_GlobalVars.PriLimits.PriorityMax - POSIX_GlobalVars.PriLimits.PriorityMin) > OS_MAX_TASK_PRIORITY) - { - POSIX_GlobalVars.PriLimits.PriorityMax = POSIX_GlobalVars.PriLimits.PriorityMin + OS_MAX_TASK_PRIORITY; - } - -#ifndef OSAL_DEBUG_DISABLE_TASK_PRIORITIES - ret = pthread_setschedparam(pthread_self(), sched_policy, &sched_param); - if (ret != 0) - { - OS_DEBUG("Could not setschedparam in main thread: %s (%d)\n",strerror(ret),ret); - break; - } - - /* - * Set the boolean to indicate that "setschedparam" worked -- - * This means that it is also expected to work for future calls. - */ - POSIX_GlobalVars.SelectedRtScheduler = sched_policy; - POSIX_GlobalVars.EnableTaskPriorities = true; -#endif - } - while (0); - } - else - { - OS_DEBUG("Could not getschedparam in main thread: %s (%d)\n",strerror(ret),ret); - } - -#if !defined(OSAL_DEBUG_PERMISSIVE_MODE) && !defined(OSAL_DEBUG_DISABLE_TASK_PRIORITIES) - /* - * In strict (non-permissive) mode, if the task priority setting did not work, fail with an error. - * This would be used on a real target where it needs to be ensured that priorities are active - * and the "silent fallback" of debug mode operation is not desired. - */ - if (!POSIX_GlobalVars.EnableTaskPriorities) - { - return OS_ERROR; - } -#endif - - return OS_SUCCESS; -} /* end OS_Posix_TaskAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_Posix_InternalTaskCreate_Impl - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, void *entry_arg) -{ - int return_code = 0; - pthread_attr_t custom_attr; - struct sched_param priority_holder; - - - /* - ** Initialize the pthread_attr structure. - ** The structure is used to set the stack and priority - */ - memset(&custom_attr, 0, sizeof(custom_attr)); - return_code = pthread_attr_init(&custom_attr); - if(return_code != 0) - { - OS_DEBUG("pthread_attr_init error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - - - /* - ** Test to see if the original main task scheduling priority worked. - ** If so, then also set the attributes for this task. Otherwise attributes - ** are left at default. - */ - if (POSIX_GlobalVars.EnableTaskPriorities) - { - /* - ** Set the scheduling inherit attribute to EXPLICIT - */ - return_code = pthread_attr_setinheritsched(&custom_attr, PTHREAD_EXPLICIT_SCHED); - if ( return_code != 0 ) - { - OS_DEBUG("pthread_attr_setinheritsched error in OS_TaskCreate, errno = %s\n",strerror(return_code)); - return(OS_ERROR); - } - - /* - ** Set the Stack Size - */ - if (stacksz > 0) - { - if (stacksz < PTHREAD_STACK_MIN) - { - stacksz = PTHREAD_STACK_MIN; - } - - return_code = pthread_attr_setstacksize(&custom_attr, stacksz); - if (return_code != 0) - { - OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - } - - /* - ** Set the scheduling policy - ** The best policy is determined during initialization - */ - return_code = pthread_attr_setschedpolicy(&custom_attr, POSIX_GlobalVars.SelectedRtScheduler); - if (return_code != 0) - { - OS_DEBUG("pthread_attr_setschedpolity error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - - /* - ** Set priority - */ - return_code = pthread_attr_getschedparam(&custom_attr, &priority_holder); - if (return_code != 0) - { - OS_DEBUG("pthread_attr_getschedparam error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - - priority_holder.sched_priority = OS_PriorityRemap(priority); - return_code = pthread_attr_setschedparam(&custom_attr,&priority_holder); - if(return_code != 0) - { - OS_DEBUG("pthread_attr_setschedparam error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - - } /* End if user is root */ - - /* - ** Create thread - */ - return_code = pthread_create(pthr, &custom_attr, entry, entry_arg); - if (return_code != 0) - { - OS_DEBUG("pthread_create error in OS_TaskCreate: %s\n",strerror(return_code)); - return(OS_ERROR); - } - - /* - ** Free the resources that are no longer needed - ** Since the task is now running - pthread_create() was successful - - ** Do not treat anything bad that happens after this point as fatal. - ** The task is running, after all - better to leave well enough alone. - */ - return_code = pthread_detach(*pthr); - if (return_code != 0) - { - OS_DEBUG("pthread_detach error in OS_TaskCreate: %s\n",strerror(return_code)); - } - - return_code = pthread_attr_destroy(&custom_attr); - if (return_code != 0) - { - OS_DEBUG("pthread_attr_destroy error in OS_TaskCreate: %s\n",strerror(return_code)); - } - - return OS_SUCCESS; -} /* end OS_Posix_InternalTaskCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) -{ - OS_U32ValueWrapper_t arg; - int32 return_code; - - arg.opaque_arg = NULL; - arg.value = OS_global_task_table[task_id].active_id; - - return_code = OS_Posix_InternalTaskCreate_Impl( - &OS_impl_task_table[task_id].id, - OS_task_table[task_id].priority, - OS_task_table[task_id].stack_size, - OS_PthreadTaskEntry, - arg.opaque_arg); - - return return_code; -} /* end OS_TaskCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskMatch_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) -{ - if (pthread_equal(pthread_self(), OS_impl_task_table[task_id].id) == 0) - { - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_TaskMatch_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl (uint32 task_id) -{ - /* - ** Try to delete the task - ** If this fails, not much recourse - the only potential cause of failure - ** to cancel here is that the thread ID is invalid because it already exited itself, - ** and if that is true there is nothing wrong - everything is OK to continue normally. - */ - pthread_cancel(OS_impl_task_table[task_id].id); - return OS_SUCCESS; - -} /* end OS_TaskDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskExit_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_TaskExit_Impl() -{ - pthread_exit(NULL); - -} /* end OS_TaskExit_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelay_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelay_Impl(uint32 millisecond) -{ - struct timespec sleep_end; - int status; - - clock_gettime(CLOCK_MONOTONIC, &sleep_end); - sleep_end.tv_sec += millisecond / 1000; - sleep_end.tv_nsec += 1000000 * (millisecond % 1000); - - if (sleep_end.tv_nsec >= 1000000000) - { - sleep_end.tv_nsec -= 1000000000; - ++sleep_end.tv_sec; - } - - do - { - status = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &sleep_end, NULL); - } - while (status == EINTR); - - if (status != 0) - { - return OS_ERROR; - } - else - { - return OS_SUCCESS; - } -} /* end OS_TaskDelay_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskSetPriority_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) -{ - int os_priority; - int ret; - - if (POSIX_GlobalVars.EnableTaskPriorities) - { - /* Change OSAL priority into a priority that will work for this OS */ - os_priority = OS_PriorityRemap(new_priority); - - /* - ** Set priority - */ - ret = pthread_setschedprio(OS_impl_task_table[task_id].id, os_priority); - if( ret != 0 ) - { - OS_DEBUG("pthread_setschedprio: Task ID = %u, prio = %d, err = %s\n", - (unsigned int)task_id,os_priority,strerror(ret)); - return(OS_ERROR); - } - } - - return OS_SUCCESS; -} /* end OS_TaskSetPriority_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskRegister_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskRegister_Impl(uint32 global_task_id) -{ - int32 return_code; - OS_U32ValueWrapper_t arg; - - arg.opaque_arg = 0; - arg.value = global_task_id; - - return_code = pthread_setspecific(POSIX_GlobalVars.ThreadKey, arg.opaque_arg); - if (return_code == 0) - { - return_code = OS_SUCCESS; - } - else - { - OS_DEBUG("OS_TaskRegister_Impl failed during pthread_setspecific() error=%s\n",strerror(return_code)); - return_code = OS_ERROR; - } - - return return_code; -} /* end OS_TaskRegister_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetId_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -uint32 OS_TaskGetId_Impl (void) -{ - OS_U32ValueWrapper_t self_record; - - self_record.opaque_arg = pthread_getspecific(POSIX_GlobalVars.ThreadKey); - - return(self_record.value); -} /* end OS_TaskGetId_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) -{ - size_t copy_sz; - - /* - * NOTE - this is not really valid, as you can't officially - * cast a pthread_t to an integer - * (in fact this fails on cygwin where pthread_t is NOT an integral type) - * - * This is just a hack to fill the value with something. - * To be portable, the application should _NOT_ be using OStask_id for anything. - */ - task_prop->OStask_id = 0; - - if (sizeof(pthread_t) < sizeof(task_prop->OStask_id)) - { - copy_sz = sizeof(pthread_t); - } - else - { - copy_sz = sizeof(task_prop->OStask_id); - } - - memcpy(&task_prop->OStask_id, &OS_impl_task_table[task_id].id, copy_sz); - - return OS_SUCCESS; -} /* end OS_TaskGetInfo_Impl */ - -/**************************************************************************************** - MESSAGE QUEUE API - ***************************************************************************************/ - -/*--------------------------------------------------------------------------------------- - Name: OS_Posix_QueueAPI_Impl_Init - - Purpose: Initialize the Queue data structures - - ----------------------------------------------------------------------------------------*/ -int32 OS_Posix_QueueAPI_Impl_Init(void) -{ - memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); - - /* - * Automatic truncation is dependent on the OSAL_DEBUG_PERMISSIVE_MODE compile-time define - so - * creating a too-large message queue on a target without OSAL_DEBUG_PERMISSIVE_MODE will fail - * with an OS error as intended. - */ -#ifdef OSAL_DEBUG_PERMISSIVE_MODE - /* - * Use the BSP-provided limit - */ - POSIX_GlobalVars.TruncateQueueDepth = OS_BSP_Global.MaxQueueDepth; -#else - /* - * Initialize this to zero to indicate no limit - */ - POSIX_GlobalVars.TruncateQueueDepth = 0; -#endif - - return OS_SUCCESS; -} /* end OS_Posix_QueueAPI_Impl_Init */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) -{ - int return_code; - mqd_t queueDesc; - struct mq_attr queueAttr; - char name[OS_MAX_API_NAME * 2]; - - /* set queue attributes */ - memset(&queueAttr, 0, sizeof(queueAttr)); - queueAttr.mq_maxmsg = OS_queue_table[queue_id].max_depth; - queueAttr.mq_msgsize = OS_queue_table[queue_id].max_size; - - /* - * The "TruncateQueueDepth" indicates a soft limit to the size of a queue. - * If nonzero, anything larger than this will be silently truncated - * (Supports running applications as non-root) - */ - if (POSIX_GlobalVars.TruncateQueueDepth > 0 && - POSIX_GlobalVars.TruncateQueueDepth < queueAttr.mq_maxmsg) - { - queueAttr.mq_maxmsg = POSIX_GlobalVars.TruncateQueueDepth; - } - - /* - ** Construct the queue name: - ** The name will consist of "/.queue_name" - */ - snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), OS_global_queue_table[queue_id].name_entry); - - /* - ** create message queue - */ - queueDesc = mq_open(name, O_CREAT | O_RDWR, 0666, &queueAttr); - if ( queueDesc == (mqd_t)(-1) ) - { - OS_DEBUG("OS_QueueCreate Error. errno = %d (%s)\n",errno,strerror(errno)); - if( errno == EINVAL ) - { - OS_DEBUG("Your queue depth may be too large for the\n"); - OS_DEBUG("OS to handle. Please check the msg_max\n"); - OS_DEBUG("parameter located in /proc/sys/fs/mqueue/msg_max\n"); - OS_DEBUG("on your Linux file system and raise it if you\n"); - OS_DEBUG(" need to or run as root\n"); - } - return_code = OS_ERROR; - } - else - { - OS_impl_queue_table[queue_id].id = queueDesc; - return_code = OS_SUCCESS; - - /* - * Unlink the queue right now -- - * queues have kernel persistence and if we do a lot of restarts (i.e. during debugging) - * a lot of stale message queues will collect in the system. It is OK to unlink right now - * as this only affects the ability of another process to open the same queue, but we do - * not need that to happen anyway. - */ - if(mq_unlink(name) != 0) - { - OS_DEBUG("OS_QueueDelete Error during mq_unlink(). errno = %d (%s)\n",errno,strerror(errno)); - /* Note - since the queue is already closed, we cannot really handle this failure gracefully, - * The queue is no longer usable so we can't return an error and go back to the way things were. - * In this case we need to return OS_SUCCESS so the rest of the entry will be cleaned up. - */ - } - } - - return return_code; -} /* end OS_QueueCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl (uint32 queue_id) -{ - int32 return_code; - - /* Try to delete and unlink the queue */ - if (mq_close(OS_impl_queue_table[queue_id].id) != 0) - { - OS_DEBUG("OS_QueueDelete Error during mq_close(). errno = %d (%s)\n",errno,strerror(errno)); - return_code = OS_ERROR; - } - else - { - return_code = OS_SUCCESS; - } - - return return_code; -} /* end OS_QueueDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueGet_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) -{ - int32 return_code; - ssize_t sizeCopied; - struct timespec ts; - - /* - ** Read the message queue for data - */ - sizeCopied = -1; - if (timeout == OS_PEND) - { - /* - ** A signal can interrupt the mq_receive call, so the call has to be done with - ** a loop - */ - do - { - sizeCopied = mq_receive(OS_impl_queue_table[queue_id].id, data, size, NULL); - } - while ( sizeCopied < 0 && errno == EINTR ); - - } - else - { - /* - * NOTE - a prior implementation of OS_CHECK would check the mq_attr for a nonzero depth - * and then call mq_receive(). This is insufficient since another thread might do the same - * thing at the same time in which case one thread will read and the other will block. - * - * Calling mq_timedreceive with a zero timeout effectively does the same thing in the typical - * case, but for the case where two threads do a simultaneous read, one will get the message - * while the other will NOT block (as expected). - */ - if (timeout == OS_CHECK) - { - memset(&ts, 0, sizeof(ts)); - } - else - { - OS_CompAbsDelayTime( timeout, &ts); - } - - /* - ** If the mq_timedreceive call is interrupted by a system call or signal, - ** call it again. - */ - do - { - sizeCopied = mq_timedreceive(OS_impl_queue_table[queue_id].id, data, size, NULL, &ts); - } - while ( timeout != OS_CHECK && sizeCopied < 0 && errno == EINTR ); - - } /* END timeout */ - - /* Figure out the return code */ - if(sizeCopied == -1) - { - *size_copied = 0; - - /* Map the system errno to the most appropriate OSAL return code */ - if (errno == EMSGSIZE) - { - return_code = OS_QUEUE_INVALID_SIZE; - } - else if (timeout == OS_PEND || errno != ETIMEDOUT) - { - /* OS_PEND was supposed to pend forever until a message arrived - * so something else is wrong. Otherwise, at this point the only - * "acceptable" errno is TIMEDOUT for the other cases. - */ - return_code = OS_ERROR; - } - else if (timeout == OS_CHECK) - { - return_code = OS_QUEUE_EMPTY; - } - else - { - return_code = OS_QUEUE_TIMEOUT; - } - } - else - { - *size_copied = sizeCopied; - return_code = OS_SUCCESS; - } - - return return_code; -} /* end OS_QueueGet_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueuePut_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) -{ - int32 return_code; - int result; - struct timespec ts; - - /* - * NOTE - using a zero timeout here for the same reason that QueueGet does --- - * checking the attributes and doing the actual send is non-atomic, and if - * two threads call QueuePut() at the same time on a nearly-full queue, - * one could block. - */ - memset(&ts, 0, sizeof(ts)); - - /* send message */ - do - { - result = mq_timedsend(OS_impl_queue_table[queue_id].id, data, size, 1, &ts); - } - while ( result == -1 && errno == EINTR ); - - if(result == 0) - { - return_code = OS_SUCCESS; - } - else if (errno == ETIMEDOUT) - { - return_code = OS_QUEUE_FULL; - } - else - { - /* Something else went wrong */ - return_code = OS_ERROR; - } - - return return_code; - -} /* end OS_QueuePut_Impl */ - - - -/**************************************************************************************** - BINARY SEMAPHORE API - ***************************************************************************************/ - -/* - * Note that the pthreads world does not provide VxWorks-style binary semaphores that the OSAL API is modeled after. - * Instead, semaphores are simulated using pthreads mutexes, condition variables, and a bit of internal state. - * - * IMPORTANT: the side effect of this is that Binary Semaphores are not usable from signal handlers / ISRs. - * Use Counting Semaphores instead. - */ - -/*--------------------------------------------------------------------------------------- - Name: OS_Posix_BinSemAPI_Impl_Init - - Purpose: Initialize the Binary Semaphore data structures - - ----------------------------------------------------------------------------------------*/ -int32 OS_Posix_BinSemAPI_Impl_Init(void) -{ - memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); - return OS_SUCCESS; -} /* end OS_Posix_BinSemAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) -{ - int ret; - int attr_created; - int mutex_created; - int cond_created; - int32 return_code; - pthread_mutexattr_t mutex_attr; - OS_impl_binsem_internal_record_t *sem; - - /* - * This preserves a bit of pre-existing functionality that was particular to binary sems: - * if the initial value is greater than 1 it just silently used 1 without error. - * (by contrast the counting semaphore will return an error) - */ - if ( initial_value > 1 ) - { - initial_value = 1; - } - - attr_created = 0; - mutex_created = 0; - cond_created = 0; - sem = &OS_impl_bin_sem_table[sem_id]; - memset(sem, 0, sizeof (*sem)); - - do - { - /* - ** Initialize the pthread mutex attribute structure with default values - */ - ret = pthread_mutexattr_init(&mutex_attr); - if (ret != 0) - { - OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n",strerror(ret)); - return_code = OS_SEM_FAILURE; - break; - } - - /* After this point, the attr object should be destroyed before return */ - attr_created = 1; - - /* - ** Use priority inheritance - */ - ret = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT); - if (ret != 0) - { - OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n",strerror(ret)); - return_code = OS_SEM_FAILURE; - break; - } - - /* - ** Initialize the mutex that is used with the condition variable - */ - ret = pthread_mutex_init(&(sem->id), &mutex_attr); - if (ret != 0) - { - OS_DEBUG("Error: pthread_mutex_init failed: %s\n",strerror(ret)); - return_code = OS_SEM_FAILURE; - break; - } - - mutex_created = 1; - - /* - ** Initialize the condition variable - */ - ret = pthread_cond_init(&(sem->cv), NULL); - if (ret != 0) - { - OS_DEBUG("Error: pthread_cond_init failed: %s\n",strerror(ret)); - return_code = OS_SEM_FAILURE; - break; - } - - cond_created = 1; - - /* - ** fill out the proper OSAL table fields - */ - - sem->current_value = initial_value; - - return_code = OS_SUCCESS; - } - while (0); - - /* Clean up resources if the operation failed */ - if (return_code != OS_SUCCESS) - { - if (mutex_created) - { - pthread_mutex_destroy(&(sem->id)); - } - if (cond_created) - { - pthread_cond_destroy(&(sem->cv)); - } - } - - if (attr_created) - { - /* Done with the attribute object - - * this call is a no-op in linux - but for other implementations if - * the create call allocated something this should free it - */ - pthread_mutexattr_destroy(&mutex_attr); - } - - return return_code; - -} /* end OS_BinSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl (uint32 sem_id) -{ - OS_impl_binsem_internal_record_t *sem; - int32 return_code; - - sem = &OS_impl_bin_sem_table[sem_id]; - - if (pthread_cond_destroy(&(sem->cv)) != 0) - { - /* sem could be busy, i.e. some task is pending on it already. - * that means it cannot be deleted at this time. */ - return_code = OS_SEM_FAILURE; - } - else - { - /* Now that the CV is destroyed this sem is unusable, - * so we must do our best to clean everything else. Even if cleanup - * does not fully work, returning anything other than OS_SUCCESS would - * suggest to the caller that the sem is still usable which it is not. - */ - return_code = OS_SUCCESS; - - /* destroy the associated mutex -- - * Note that this might fail if the mutex is locked, - * but there is no sane way to recover from that (see above). */ - pthread_mutex_destroy(&(sem->id)); - } - - return return_code; -} /* end OS_BinSemDelete_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl ( uint32 sem_id ) -{ - OS_impl_binsem_internal_record_t *sem; - - sem = &OS_impl_bin_sem_table[sem_id]; - - /* - * Note there is a possibility that another thread is concurrently taking this sem, - * and has just checked the current_value but not yet inside the cond_wait call. - * - * To address this possibility - the lock must be taken here. This is unfortunate - * as it means there may be a task switch when _giving_ a binary semaphore. But the - * alternative of having a BinSemGive not wake up the other thread is a bigger issue. - * - * Counting sems do not suffer from this, as there is a native POSIX mechanism for those. - */ - - /* Lock the mutex ( not the table! ) */ - if ( pthread_mutex_lock(&(sem->id)) != 0 ) - { - return(OS_SEM_FAILURE); - } - - /* Binary semaphores are always set as "1" when given */ - sem->current_value = 1; - - /* unblock one thread that is waiting on this sem */ - pthread_cond_signal(&(sem->cv)); - - pthread_mutex_unlock(&(sem->id)); - - return OS_SUCCESS; -} /* end OS_BinSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemFlush_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl (uint32 sem_id) -{ - OS_impl_binsem_internal_record_t *sem; - - sem = &OS_impl_bin_sem_table[sem_id]; - - /* Lock the mutex ( not the table! ) */ - if ( pthread_mutex_lock(&(sem->id)) != 0 ) - { - return(OS_SEM_FAILURE); - } - - /* increment the flush counter. Any other threads that are - * currently pending in SemTake() will see the counter change and - * return _without_ modifying the semaphore count. - */ - ++sem->flush_request; - - /* unblock all threads that are be waiting on this sem */ - pthread_cond_broadcast(&(sem->cv)); - - pthread_mutex_unlock(&(sem->id)); - - return OS_SUCCESS; -} /* end OS_BinSemFlush_Impl */ - -/*--------------------------------------------------------------------------------------- - Name: OS_GenericBinSemTake_Impl - - Purpose: Helper function that takes a simulated binary semaphore with a "timespec" timeout - If the value is zero this will block until either the value - becomes nonzero (via SemGive) or the semaphore gets flushed. - ----------------------------------------------------------------------------------------*/ -static int32 OS_GenericBinSemTake_Impl (OS_impl_binsem_internal_record_t *sem, const struct timespec *timeout) -{ - sig_atomic_t flush_count; - int32 return_code; - - /* Lock the mutex ( not the table! ) */ - if ( pthread_mutex_lock(&(sem->id)) != 0 ) - { - return(OS_SEM_FAILURE); - } - - return_code = OS_SUCCESS; - - /* - * Note that for vxWorks compatibility, we need to stop pending on the semaphore - * and return from this function under two possible circumstances: - * - * a) the semaphore count was nonzero (may be pre-existing or due to a give) - * this is the normal case, we should decrement the count by 1 and return. - * b) the semaphore got "flushed" - * in this case ALL tasks are un-blocked and we do NOT decrement the count. - */ - - /* - * first take a local snapshot of the flush request counter, - * if it changes, we know that someone else called SemFlush. - */ - flush_count = sem->flush_request; - - /* Note - the condition must be checked in a while loop because - * even if pthread_cond_wait() returns, it does NOT guarantee that - * the condition we are looking for has been met. - * - * Also if the current_value is already nonzero we will not wait. - */ - while ( sem->current_value == 0 && sem->flush_request == flush_count ) - { - /* Must pend until something changes */ - if (timeout == NULL) - { - /* wait forever */ - pthread_cond_wait(&(sem->cv),&(sem->id)); - } - else if (pthread_cond_timedwait(&(sem->cv),&(sem->id),timeout) == ETIMEDOUT) - { - return_code = OS_SEM_TIMEOUT; - break; - } - } - - /* If the flush counter did not change, set the value to zero */ - if (return_code == OS_SUCCESS && sem->flush_request == flush_count) - { - sem->current_value = 0; - } - - pthread_mutex_unlock(&(sem->id)); - - return return_code; -} /* end OS_GenericBinSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl ( uint32 sem_id ) -{ - return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], NULL)); -} /* end OS_BinSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) -{ - struct timespec ts; - - /* - ** Compute an absolute time for the delay - */ - OS_CompAbsDelayTime(msecs, &ts); - - return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], &ts)); -} /* end OS_BinSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *sem_prop) -{ - /* put the info into the stucture */ - sem_prop -> value = OS_impl_bin_sem_table[sem_id].current_value; - return OS_SUCCESS; -} /* end OS_BinSemGetInfo_Impl */ - - -/**************************************************************************************** - COUNTING SEMAPHORE API - ***************************************************************************************/ - -/* - * Unlike binary semaphores, counting semaphores can use the standard POSIX semaphore facility. - * This has the advantage of more correct behavior on "give" operations: - * - give may be done from a signal / ISR context - * - give should not cause an unexpected task switch nor should it ever block - */ - -/*--------------------------------------------------------------------------------------- - Name: OS_Posix_CountSemAPI_Impl_Init - - Purpose: Initialize the Counting Semaphore data structures - ----------------------------------------------------------------------------------------*/ -int32 OS_Posix_CountSemAPI_Impl_Init(void) -{ - memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); - return OS_SUCCESS; -} /* end OS_Posix_CountSemAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) -{ - if (sem_initial_value > SEM_VALUE_MAX) - { - return OS_INVALID_SEM_VALUE; - } - - if (sem_init(&OS_impl_count_sem_table[sem_id].id, 0, sem_initial_value) < 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl (uint32 sem_id) -{ - if (sem_destroy(&OS_impl_count_sem_table[sem_id].id) < 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl ( uint32 sem_id ) -{ - if (sem_post(&OS_impl_count_sem_table[sem_id].id) < 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl ( uint32 sem_id ) -{ - if (sem_wait(&OS_impl_count_sem_table[sem_id].id) < 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_CountSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) -{ - struct timespec ts; - int result; - - /* - ** Compute an absolute time for the delay - */ - OS_CompAbsDelayTime(msecs, &ts); - - if (sem_timedwait(&OS_impl_count_sem_table[sem_id].id, &ts) == 0) - { - result = OS_SUCCESS; - } - else if (errno == ETIMEDOUT) - { - result = OS_SEM_TIMEOUT; - } - else - { - /* unspecified failure */ - result = OS_SEM_FAILURE; - } - - return result; -} /* end OS_CountSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) -{ - int sval; - - if (sem_getvalue(&OS_impl_count_sem_table[sem_id].id, &sval) < 0) - { - return OS_SEM_FAILURE; - } - - /* put the info into the stucture */ - count_prop -> value = sval; - return OS_SUCCESS; -} /* end OS_CountSemGetInfo_Impl */ - -/**************************************************************************************** - MUTEX API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_Posix_MutexAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Posix_MutexAPI_Impl_Init(void) -{ - memset(OS_impl_mut_sem_table, 0, sizeof(OS_impl_mut_sem_table)); - return OS_SUCCESS; -} /* end OS_Posix_MutexAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) -{ - int return_code; - pthread_mutexattr_t mutex_attr; - - /* - ** initialize the attribute with default values - */ - return_code = pthread_mutexattr_init(&mutex_attr); - if ( return_code != 0 ) - { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %u: %s\n", - (unsigned int)sem_id,strerror(return_code)); - return OS_SEM_FAILURE; - } - - /* - ** Allow the mutex to use priority inheritance - */ - return_code = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT); - if ( return_code != 0 ) - { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %u: %s\n", - (unsigned int)sem_id,strerror(return_code)); - return OS_SEM_FAILURE; - } - - /* - ** Set the mutex type to RECURSIVE so a thread can do nested locks - */ - return_code = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); - if ( return_code != 0 ) - { - OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %u: %s\n", - (unsigned int)sem_id,strerror(return_code)); - return OS_SEM_FAILURE; - } - - /* - ** create the mutex - ** upon successful initialization, the state of the mutex becomes initialized and unlocked - */ - return_code = pthread_mutex_init(&OS_impl_mut_sem_table[sem_id].id,&mutex_attr); - if ( return_code != 0 ) - { - OS_DEBUG("Error: Mutex could not be created. ID = %u: %s\n", - (unsigned int)sem_id,strerror(return_code)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_MutSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl (uint32 sem_id) -{ - int status; - - status = pthread_mutex_destroy( &(OS_impl_mut_sem_table[sem_id].id)); /* 0 = success */ - - if (status != 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_MutSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl ( uint32 sem_id ) -{ - int status; - - /* - ** Unlock the mutex - */ - status = pthread_mutex_unlock(&(OS_impl_mut_sem_table[sem_id].id)); - if(status != 0) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_MutSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl ( uint32 sem_id ) -{ - int status; - - /* - ** Lock the mutex - */ - status = pthread_mutex_lock(&(OS_impl_mut_sem_table[sem_id].id)); - if( status != 0 ) - { - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_MutSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) -{ - return OS_SUCCESS; - -} /* end OS_MutSemGetInfo_Impl */ - -#ifndef OSAL_OMIT_DEPRECATED - -/**************************************************************************************** - INT API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntAttachHandler_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntUnlock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntUnlock_Impl (int32 IntLevel) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntUnlock_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntLock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntLock_Impl ( void ) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntLock_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_IntEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntEnable_Impl(int32 Level) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntEnable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntDisable_Impl(int32 Level) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) -{ - *MaskSettingPtr = 0; - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntGetMask_Impl */ - -#endif /* OSAL_OMIT_DEPRECATED */ - -/*---------------------------------------------------------------- - * - * Function: OS_HeapGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) -{ - /* - ** Not implemented yet - */ - return (OS_ERR_NOT_IMPLEMENTED); -} /* end OS_HeapGetInfo_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_CompAbsDelayTime - * - * Purpose: Local helper function - * - * This function accept time interval, msecs, as an input and - * computes the absolute time at which this time interval will expire. - * The absolute time is programmed into a struct. - * - *-----------------------------------------------------------------*/ -void OS_CompAbsDelayTime( uint32 msecs, struct timespec * tm) -{ - clock_gettime( CLOCK_REALTIME, tm ); - - /* add the delay to the current time */ - tm->tv_sec += (time_t) (msecs / 1000) ; - /* convert residue ( msecs ) to nanoseconds */ - tm->tv_nsec += (msecs % 1000) * 1000000L ; - - if(tm->tv_nsec >= 1000000000L ) - { - tm->tv_nsec -= 1000000000L ; - tm->tv_sec ++ ; - } -} /* end OS_CompAbsDelayTime */ - -/*---------------------------------------------------------------------------- - * Name: OS_PriorityRemap - * - * Purpose: Remaps the OSAL priority into one that is viable for this OS - * - * Note: This implementation assumes that InputPri has already been verified - * to be within the range of [0,OS_MAX_TASK_PRIORITY] - * -----------------------------------------------------------------------------*/ -static int OS_PriorityRemap(uint32 InputPri) -{ - int OutputPri; - - if (InputPri == 0) - { - /* use the "MAX" local priority only for OSAL tasks with priority=0 */ - OutputPri = POSIX_GlobalVars.PriLimits.PriorityMax; - } - else if (InputPri >= OS_MAX_TASK_PRIORITY) - { - /* use the "MIN" local priority only for OSAL tasks with priority=255 */ - OutputPri = POSIX_GlobalVars.PriLimits.PriorityMin; - } - else - { - /* - * Spread the remainder of OSAL priorities over the remainder of local priorities - * - * Note OSAL priorities use the VxWorks style with zero being the - * highest and OS_MAX_TASK_PRIORITY being the lowest, this inverts it - */ - OutputPri = (OS_MAX_TASK_PRIORITY - 1) - (int)InputPri; - - OutputPri *= (POSIX_GlobalVars.PriLimits.PriorityMax - POSIX_GlobalVars.PriLimits.PriorityMin) - 2; - OutputPri += OS_MAX_TASK_PRIORITY / 2; - OutputPri /= (OS_MAX_TASK_PRIORITY - 2); - OutputPri += POSIX_GlobalVars.PriLimits.PriorityMin + 1; - } - - return OutputPri; -} /* end OS_PriorityRemap */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, - int32 parameter) -{ - /* - ** Not implemented in linux. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcAttachHandler_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in linux. - */ - return(OS_SUCCESS); -} /* end OS_FPUExcEnable_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in linux. - */ - return(OS_SUCCESS); -} /* end OS_FPUExcDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcSetMask_Impl(uint32 mask) -{ - /* - ** Not implemented in linux. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcGetMask_Impl(uint32 *mask) -{ - /* - ** Not implemented in linux. - */ - *mask = 0; - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcGetMask_Impl */ - -/********************************************************************/ -/* CONSOLE OUTPUT */ -/********************************************************************/ - -/* use the portable version of OS_ConsoleWrite_Impl() */ -#include "../portable/os-impl-console-directwrite.c" - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleWakeup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - - if (local->is_async) - { - /* post the sem for the utility task to run */ - sem_post(&local->data_sem); - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(local_id); - } -} /* end OS_ConsoleWakeup_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleTask_Entry - * - * Purpose: Local Helper function - * Implements the console output task - * - *-----------------------------------------------------------------*/ -static void* OS_ConsoleTask_Entry(void* arg) -{ - OS_U32ValueWrapper_t local_arg; - OS_impl_console_internal_record_t *local; - - local_arg.opaque_arg = arg; - local = &OS_impl_console_table[local_arg.value]; - while (true) - { - OS_ConsoleOutput_Impl(local_arg.value); - sem_wait(&local->data_sem); - } - return NULL; -} /* end OS_ConsoleTask_Entry */ - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - pthread_t consoletask; - int32 return_code; - OS_U32ValueWrapper_t local_arg = { 0 }; - - if (local_id == 0) - { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; - local->out_fd = OSAL_CONSOLE_FILENO; - - if (local->is_async) - { - if (sem_init(&OS_impl_console_table[local_id].data_sem, 0, 0) < 0) - { - return_code = OS_SEM_FAILURE; - } - else - { - local_arg.value = local_id; - return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, - OS_ConsoleTask_Entry, local_arg.opaque_arg); - - if (return_code != OS_SUCCESS) - { - sem_destroy(&OS_impl_console_table[local_id].data_sem); - } - } - } - } - else - { - /* only one physical console device is implemented */ - return_code = OS_ERR_NOT_IMPLEMENTED; - } - - return return_code; -} /* end OS_ConsoleCreate_Impl */ - diff --git a/src/os/posix/osfileapi.c b/src/os/posix/osfileapi.c deleted file mode 100644 index 140a705a4..000000000 --- a/src/os/posix/osfileapi.c +++ /dev/null @@ -1,204 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osfileapi.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file Contains all of the api calls for manipulating - * files in a file system for posix - * - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-posix.h" - -#include -#include -#include -#include -#include - - -/**************************************************************************************** - GLOBALS - ***************************************************************************************/ - -/* - * The global file handle table. - * - * This is shared by all OSAL entities that perform low-level I/O. - */ -OS_Posix_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - -/* - * The directory handle table. - */ -DIR *OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; - - -/* - * These two constants (EUID and EGID) are local cache of the - * euid and egid of the user running the OSAL application. They - * assist the "stat" implementation in determination of permissions. - * - * For an OS that does not have multiple users, these could be - * defined as 0. Otherwise they should be populated via the system - * geteuid/getegid calls. - */ -uid_t OS_IMPL_SELF_EUID = 0; -gid_t OS_IMPL_SELF_EGID = 0; - -/* - * Flag(s) to set on file handles for regular files - * This sets all regular filehandles to be non-blocking by default. - * - * In turn, the implementation will utilize select() to determine - * a filehandle readiness to read/write. - */ -const int OS_IMPL_REGULAR_FILE_FLAGS = O_NONBLOCK; - - -/**************************************************************************************** - COMMON ROUTINES - After including the OS/C-library specific include files, the basic UNIX file API is used - ****************************************************************************************/ - -/* - * The "I/O" portable block includes the generic - * posix-style read/write/seek/close operations - */ -#include "../portable/os-impl-posix-io.c" - -/* - * The "Files" portable block includes impl - * calls for named files i.e. FileOpen and FileStat - * This is anything that operates on a pathname. - */ -#include "../portable/os-impl-posix-files.c" - -/* - * The "Dirs" portable block includes impl - * calls for reading directory contents using - * posix-style opendir/readdir/closedir etc. - */ -#include "../portable/os-impl-posix-dirs.c" - -/**************************************************************************************** - IMPLEMENTATION-SPECIFIC ROUTINES - These are specific to this particular operating system - ****************************************************************************************/ - -/* -------------------------------------------------------------------------------------- - Name: OS_Posix_StreamAPI_Impl_Init - - Purpose: File/Stream subsystem global initialization - - Returns: OS_SUCCESS if success - ---------------------------------------------------------------------------------------*/ -int32 OS_Posix_StreamAPI_Impl_Init(void) -{ - uint32 local_id; - - /* - * init all filehandles to -1, which is always invalid. - * this isn't strictly necessary but helps when debugging. - */ - for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) - { - OS_impl_filehandle_table[local_id].fd = -1; - } - - OS_IMPL_SELF_EUID = geteuid(); - OS_IMPL_SELF_EGID = getegid(); - - return OS_SUCCESS; -} /* end OS_Posix_StreamAPI_Impl_Init */ - -/* -------------------------------------------------------------------------------------- - Name: OS_Posix_DirAPI_Impl_Init - - Purpose: Directory table initialization - - Returns: OS_SUCCESS if success - ---------------------------------------------------------------------------------------*/ -int32 OS_Posix_DirAPI_Impl_Init(void) -{ - memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); - return OS_SUCCESS; -} /* end OS_Posix_DirAPI_Impl_Init */ - - - - -/*---------------------------------------------------------------- - * - * Function: OS_ShellOutputToFile_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char* Cmd) -{ - pid_t cpid; - uint32 local_id; - int wstat; - const char *shell = getenv("SHELL"); - - if (shell == NULL) - { - shell = "/bin/sh"; - } - - cpid = fork(); - if (cpid < 0) - { - OS_DEBUG("%s(): Error during fork(): %s\n", __func__, strerror(errno)); - return OS_ERROR; - } - - if (cpid == 0) - { - /* child process */ - dup2(OS_impl_filehandle_table[file_id].fd, STDOUT_FILENO); - dup2(OS_impl_filehandle_table[file_id].fd, STDERR_FILENO); - - /* close all _other_ filehandles */ - for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) - { - if (OS_global_stream_table[local_id].active_id != 0) - { - close(OS_impl_filehandle_table[local_id].fd); - } - } - - execl(shell, "sh", "-c", Cmd, NULL); /* does not return if successful */ - exit(EXIT_FAILURE); - } - - if (waitpid(cpid, &wstat, 0) != cpid) - { - OS_DEBUG("%s(): Error during waitpid(): %s\n", __func__, strerror(errno)); - return OS_ERROR; - } - - if (!WIFEXITED(wstat) || WEXITSTATUS(wstat) != 0) - { - OS_DEBUG("%s(): Error from child process: %d\n", __func__, wstat); - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_ShellOutputToFile_Impl */ - diff --git a/src/os/posix/osnetwork.c b/src/os/posix/osnetwork.c deleted file mode 100644 index 4a07b1989..000000000 --- a/src/os/posix/osnetwork.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osnetwork.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains the network functionality for the osapi. - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-posix.h" - -/* - * FIXME: this belongs in the osconfig.h file, really. - */ -#define OS_NETWORK_SUPPORTS_IPV6 - -#include -#include -#include -#include -#include -#include - - - -#ifdef OS_INCLUDE_NETWORK - - -/* - * Leverage the POSIX-style File I/O as this will mostly work on RTEMS, - * with the exception that regular files cannot be passed to select(), - * which means that we should NOT set the O_NONBLOCK flag on filehandles - * like the standard POSIX OSAL does. - */ -const int OS_IMPL_SOCKET_FLAGS = O_NONBLOCK; - -/**************************************************************************************** - COMMON ROUTINES - After including the OS/C-library specific include files, the basic UNIX file API is used - ****************************************************************************************/ - -/* - * The "bsd-socket" portable block includes the generic - * bsd-style network operations - */ -#include "../portable/os-impl-bsd-sockets.c" - - -/**************************************************************************************** - IMPLEMENTATION-SPECIFIC ROUTINES - These are specific to this particular operating system - ****************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_NetworkGetID_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_NetworkGetID_Impl (int32 *IdBuf) -{ - /* BSD-style gethostid() has no failure modes */ - *IdBuf = gethostid(); - return OS_SUCCESS; -} /* end OS_NetworkGetID_Impl */ - -#else /* OS_INCLUDE_NETWORK */ - - -/**************************************************************************************** - NOT IMPLEMENTED OPTION - This block provides stubs in case this module is disabled by config - ****************************************************************************************/ - -/* - * The "no-network" block includes the required API calls - * that all return OS_ERR_NOT_IMPLEMENTED - */ -#include "../portable/os-impl-no-network.c" - -#endif - - diff --git a/src/os/posix/osselect.c b/src/os/posix/osselect.c deleted file mode 100644 index a82fc7366..000000000 --- a/src/os/posix/osselect.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osselect.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains wrappers around the select() system call - * - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-posix.h" - -/* Include the OS-specific header files necessary for select() operations */ -#include - - -/**************************************************************************************** - COMMON ROUTINES - After including the OS/C-library specific include files, the basic UNIX select API is used - ****************************************************************************************/ - -/* Leverage the portable UNIX-style Select API for POSIX */ -#include "../portable/os-impl-bsd-select.c" - diff --git a/src/os/posix/src/os-impl-binsem.c b/src/os/posix/src/os-impl-binsem.c new file mode 100644 index 000000000..26f9e6650 --- /dev/null +++ b/src/os/posix/src/os-impl-binsem.c @@ -0,0 +1,419 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + * Purpose: This file contains some of the OS APIs abstraction layer + * implementation for POSIX + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "os-impl-binsem.h" + +/* Tables where the OS object information is stored */ +OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + +/**************************************************************************************** + BINARY SEMAPHORE API + ***************************************************************************************/ + +/* + * Note that the pthreads world does not provide VxWorks-style binary semaphores that the OSAL API is modeled after. + * Instead, semaphores are simulated using pthreads mutexes, condition variables, and a bit of internal state. + * + * IMPORTANT: the side effect of this is that Binary Semaphores are not usable from signal handlers / ISRs. + * Use Counting Semaphores instead. + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_BinSemAPI_Impl_Init + + Purpose: Initialize the Binary Semaphore data structures + + ----------------------------------------------------------------------------------------*/ +int32 OS_Posix_BinSemAPI_Impl_Init(void) +{ + memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); + return OS_SUCCESS; +} /* end OS_Posix_BinSemAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) +{ + int ret; + int attr_created; + int mutex_created; + int cond_created; + int32 return_code; + pthread_mutexattr_t mutex_attr; + OS_impl_binsem_internal_record_t *sem; + + /* + * This preserves a bit of pre-existing functionality that was particular to binary sems: + * if the initial value is greater than 1 it just silently used 1 without error. + * (by contrast the counting semaphore will return an error) + */ + if ( initial_value > 1 ) + { + initial_value = 1; + } + + attr_created = 0; + mutex_created = 0; + cond_created = 0; + sem = &OS_impl_bin_sem_table[sem_id]; + memset(sem, 0, sizeof (*sem)); + + do + { + /* + ** Initialize the pthread mutex attribute structure with default values + */ + ret = pthread_mutexattr_init(&mutex_attr); + if (ret != 0) + { + OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n",strerror(ret)); + return_code = OS_SEM_FAILURE; + break; + } + + /* After this point, the attr object should be destroyed before return */ + attr_created = 1; + + /* + ** Use priority inheritance + */ + ret = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT); + if (ret != 0) + { + OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n",strerror(ret)); + return_code = OS_SEM_FAILURE; + break; + } + + /* + ** Initialize the mutex that is used with the condition variable + */ + ret = pthread_mutex_init(&(sem->id), &mutex_attr); + if (ret != 0) + { + OS_DEBUG("Error: pthread_mutex_init failed: %s\n",strerror(ret)); + return_code = OS_SEM_FAILURE; + break; + } + + mutex_created = 1; + + /* + ** Initialize the condition variable + */ + ret = pthread_cond_init(&(sem->cv), NULL); + if (ret != 0) + { + OS_DEBUG("Error: pthread_cond_init failed: %s\n",strerror(ret)); + return_code = OS_SEM_FAILURE; + break; + } + + cond_created = 1; + + /* + ** fill out the proper OSAL table fields + */ + + sem->current_value = initial_value; + + return_code = OS_SUCCESS; + } + while (0); + + /* Clean up resources if the operation failed */ + if (return_code != OS_SUCCESS) + { + if (mutex_created) + { + pthread_mutex_destroy(&(sem->id)); + } + if (cond_created) + { + pthread_cond_destroy(&(sem->cv)); + } + } + + if (attr_created) + { + /* Done with the attribute object - + * this call is a no-op in linux - but for other implementations if + * the create call allocated something this should free it + */ + pthread_mutexattr_destroy(&mutex_attr); + } + + return return_code; + +} /* end OS_BinSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemDelete_Impl (uint32 sem_id) +{ + OS_impl_binsem_internal_record_t *sem; + int32 return_code; + + sem = &OS_impl_bin_sem_table[sem_id]; + + if (pthread_cond_destroy(&(sem->cv)) != 0) + { + /* sem could be busy, i.e. some task is pending on it already. + * that means it cannot be deleted at this time. */ + return_code = OS_SEM_FAILURE; + } + else + { + /* Now that the CV is destroyed this sem is unusable, + * so we must do our best to clean everything else. Even if cleanup + * does not fully work, returning anything other than OS_SUCCESS would + * suggest to the caller that the sem is still usable which it is not. + */ + return_code = OS_SUCCESS; + + /* destroy the associated mutex -- + * Note that this might fail if the mutex is locked, + * but there is no sane way to recover from that (see above). */ + pthread_mutex_destroy(&(sem->id)); + } + + return return_code; +} /* end OS_BinSemDelete_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGive_Impl ( uint32 sem_id ) +{ + OS_impl_binsem_internal_record_t *sem; + + sem = &OS_impl_bin_sem_table[sem_id]; + + /* + * Note there is a possibility that another thread is concurrently taking this sem, + * and has just checked the current_value but not yet inside the cond_wait call. + * + * To address this possibility - the lock must be taken here. This is unfortunate + * as it means there may be a task switch when _giving_ a binary semaphore. But the + * alternative of having a BinSemGive not wake up the other thread is a bigger issue. + * + * Counting sems do not suffer from this, as there is a native POSIX mechanism for those. + */ + + /* Lock the mutex ( not the table! ) */ + if ( pthread_mutex_lock(&(sem->id)) != 0 ) + { + return(OS_SEM_FAILURE); + } + + /* Binary semaphores are always set as "1" when given */ + sem->current_value = 1; + + /* unblock one thread that is waiting on this sem */ + pthread_cond_signal(&(sem->cv)); + + pthread_mutex_unlock(&(sem->id)); + + return OS_SUCCESS; +} /* end OS_BinSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemFlush_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemFlush_Impl (uint32 sem_id) +{ + OS_impl_binsem_internal_record_t *sem; + + sem = &OS_impl_bin_sem_table[sem_id]; + + /* Lock the mutex ( not the table! ) */ + if ( pthread_mutex_lock(&(sem->id)) != 0 ) + { + return(OS_SEM_FAILURE); + } + + /* increment the flush counter. Any other threads that are + * currently pending in SemTake() will see the counter change and + * return _without_ modifying the semaphore count. + */ + ++sem->flush_request; + + /* unblock all threads that are be waiting on this sem */ + pthread_cond_broadcast(&(sem->cv)); + + pthread_mutex_unlock(&(sem->id)); + + return OS_SUCCESS; +} /* end OS_BinSemFlush_Impl */ + +/*--------------------------------------------------------------------------------------- + Name: OS_GenericBinSemTake_Impl + + Purpose: Helper function that takes a simulated binary semaphore with a "timespec" timeout + If the value is zero this will block until either the value + becomes nonzero (via SemGive) or the semaphore gets flushed. + +---------------------------------------------------------------------------------------*/ +static int32 OS_GenericBinSemTake_Impl (OS_impl_binsem_internal_record_t *sem, const struct timespec *timeout) +{ + sig_atomic_t flush_count; + int32 return_code; + + /* Lock the mutex ( not the table! ) */ + if ( pthread_mutex_lock(&(sem->id)) != 0 ) + { + return(OS_SEM_FAILURE); + } + + return_code = OS_SUCCESS; + + /* + * Note that for vxWorks compatibility, we need to stop pending on the semaphore + * and return from this function under two possible circumstances: + * + * a) the semaphore count was nonzero (may be pre-existing or due to a give) + * this is the normal case, we should decrement the count by 1 and return. + * b) the semaphore got "flushed" + * in this case ALL tasks are un-blocked and we do NOT decrement the count. + */ + + /* + * first take a local snapshot of the flush request counter, + * if it changes, we know that someone else called SemFlush. + */ + flush_count = sem->flush_request; + + /* Note - the condition must be checked in a while loop because + * even if pthread_cond_wait() returns, it does NOT guarantee that + * the condition we are looking for has been met. + * + * Also if the current_value is already nonzero we will not wait. + */ + while ( sem->current_value == 0 && sem->flush_request == flush_count ) + { + /* Must pend until something changes */ + if (timeout == NULL) + { + /* wait forever */ + pthread_cond_wait(&(sem->cv),&(sem->id)); + } + else if (pthread_cond_timedwait(&(sem->cv),&(sem->id),timeout) == ETIMEDOUT) + { + return_code = OS_SEM_TIMEOUT; + break; + } + } + + /* If the flush counter did not change, set the value to zero */ + if (return_code == OS_SUCCESS && sem->flush_request == flush_count) + { + sem->current_value = 0; + } + + pthread_mutex_unlock(&(sem->id)); + + return return_code; +} /* end OS_GenericBinSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTake_Impl ( uint32 sem_id ) +{ + return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], NULL)); +} /* end OS_BinSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) +{ + struct timespec ts; + + /* + ** Compute an absolute time for the delay + */ + OS_Posix_CompAbsDelayTime(msecs, &ts); + + return (OS_GenericBinSemTake_Impl (&OS_impl_bin_sem_table[sem_id], &ts)); +} /* end OS_BinSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *sem_prop) +{ + /* put the info into the stucture */ + sem_prop -> value = OS_impl_bin_sem_table[sem_id].current_value; + return OS_SUCCESS; +} /* end OS_BinSemGetInfo_Impl */ + diff --git a/src/os/posix/src/os-impl-common.c b/src/os/posix/src/os-impl-common.c new file mode 100644 index 000000000..1494bf887 --- /dev/null +++ b/src/os/posix/src/os-impl-common.c @@ -0,0 +1,168 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-common.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "bsp-impl.h" + +#include "os-impl-tasks.h" +#include "os-impl-queues.h" +#include "os-impl-binsem.h" +#include "os-impl-countsem.h" +#include "os-impl-mutex.h" + +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-errors-impl.h" + + +POSIX_GlobalVars_t POSIX_GlobalVars = { 0 }; + + +/*--------------------------------------------------------------------------------------- + Name: OS_API_Impl_Init + + Purpose: Initialize the tables that the OS API uses to keep track of information + about objects + + returns: OS_SUCCESS or OS_ERROR +---------------------------------------------------------------------------------------*/ +int32 OS_API_Impl_Init(uint32 idtype) +{ + int32 return_code; + + return_code = OS_Posix_TableMutex_Init(idtype); + if (return_code != OS_SUCCESS) + { + return return_code; + } + + + switch(idtype) + { + case OS_OBJECT_TYPE_OS_TASK: + return_code = OS_Posix_TaskAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_QUEUE: + return_code = OS_Posix_QueueAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_BINSEM: + return_code = OS_Posix_BinSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_COUNTSEM: + return_code = OS_Posix_CountSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MUTEX: + return_code = OS_Posix_MutexAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MODULE: + return_code = OS_Posix_ModuleAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_TIMEBASE: + return_code = OS_Posix_TimeBaseAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_STREAM: + return_code = OS_Posix_StreamAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_DIR: + return_code = OS_Posix_DirAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_FILESYS: + return_code = OS_Posix_FileSysAPI_Impl_Init(); + break; + default: + break; + } + + + return(return_code); +} /* end OS_API_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IdleLoop_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_IdleLoop_Impl(void) +{ + /* + * Unblock signals and wait for something to occur + * + * Note - "NormalSigMask" was calculated during task init to be the original signal mask + * of the process PLUS all "RT" signals. The RT signals are used by timers, so we want + * to keep them masked here (this is different than the original POSIX impl). The + * timebase objects have a dedicated thread that will be doing "sigwait" on those. + */ + sigsuspend(&POSIX_GlobalVars.NormalSigMask); +} /* end OS_IdleLoop_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ApplicationShutdown_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ApplicationShutdown_Impl(void) +{ + /* + * Raise a signal that is unblocked in OS_IdleLoop(), + * which should break it out of the sigsuspend() call. + */ + kill(getpid(), SIGHUP); +} /* end OS_ApplicationShutdown_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_CompAbsDelayTime + * + * Purpose: Local helper function + * + * This function accept time interval, msecs, as an input and + * computes the absolute time at which this time interval will expire. + * The absolute time is programmed into a struct. + * + *-----------------------------------------------------------------*/ +void OS_Posix_CompAbsDelayTime( uint32 msecs, struct timespec * tm) +{ + clock_gettime( CLOCK_REALTIME, tm ); + + /* add the delay to the current time */ + tm->tv_sec += (time_t) (msecs / 1000) ; + /* convert residue ( msecs ) to nanoseconds */ + tm->tv_nsec += (msecs % 1000) * 1000000L ; + + if(tm->tv_nsec >= 1000000000L ) + { + tm->tv_nsec -= 1000000000L ; + tm->tv_sec ++ ; + } +} /* end OS_CompAbsDelayTime */ + + diff --git a/src/os/posix/src/os-impl-console.c b/src/os/posix/src/os-impl-console.c new file mode 100644 index 000000000..e4c85ab58 --- /dev/null +++ b/src/os/posix/src/os-impl-console.c @@ -0,0 +1,143 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "os-impl-console.h" + +#include "osapi-printf-impl.h" + +/* + * By default the console output is always asynchronous + * (equivalent to "OS_UTILITY_TASK_ON" being set) + * + * This option was removed from osconfig.h and now is + * assumed to always be on. + */ +#define OS_CONSOLE_ASYNC true +#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY + + +/* Tables where the OS object information is stored */ +OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + + +/********************************************************************/ +/* CONSOLE OUTPUT */ +/********************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleWakeup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ConsoleWakeup_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + + if (local->is_async) + { + /* post the sem for the utility task to run */ + sem_post(&local->data_sem); + } + else + { + /* output directly */ + OS_ConsoleOutput_Impl(local_id); + } +} /* end OS_ConsoleWakeup_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleTask_Entry + * + * Purpose: Local Helper function + * Implements the console output task + * + *-----------------------------------------------------------------*/ +static void* OS_ConsoleTask_Entry(void* arg) +{ + OS_U32ValueWrapper_t local_arg; + OS_impl_console_internal_record_t *local; + + local_arg.opaque_arg = arg; + local = &OS_impl_console_table[local_arg.value]; + while (true) + { + OS_ConsoleOutput_Impl(local_arg.value); + sem_wait(&local->data_sem); + } + return NULL; +} /* end OS_ConsoleTask_Entry */ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ConsoleCreate_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + pthread_t consoletask; + int32 return_code; + OS_U32ValueWrapper_t local_arg = { 0 }; + + if (local_id == 0) + { + return_code = OS_SUCCESS; + local->is_async = OS_CONSOLE_ASYNC; + + if (local->is_async) + { + if (sem_init(&OS_impl_console_table[local_id].data_sem, 0, 0) < 0) + { + return_code = OS_SEM_FAILURE; + } + else + { + local_arg.value = local_id; + return_code = OS_Posix_InternalTaskCreate_Impl(&consoletask, OS_CONSOLE_TASK_PRIORITY, 0, + OS_ConsoleTask_Entry, local_arg.opaque_arg); + + if (return_code != OS_SUCCESS) + { + sem_destroy(&OS_impl_console_table[local_id].data_sem); + } + } + } + } + else + { + /* only one physical console device is implemented */ + return_code = OS_ERR_NOT_IMPLEMENTED; + } + + return return_code; +} /* end OS_ConsoleCreate_Impl */ + diff --git a/src/os/posix/src/os-impl-countsem.c b/src/os/posix/src/os-impl-countsem.c new file mode 100644 index 000000000..2edcfdd29 --- /dev/null +++ b/src/os/posix/src/os-impl-countsem.c @@ -0,0 +1,204 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "os-impl-countsem.h" + +/* + * Added SEM_VALUE_MAX Define + */ +#ifndef SEM_VALUE_MAX +#define SEM_VALUE_MAX (UINT32_MAX/2) +#endif + +/* Tables where the OS object information is stored */ +OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + + +/**************************************************************************************** + COUNTING SEMAPHORE API + ***************************************************************************************/ + +/* + * Unlike binary semaphores, counting semaphores can use the standard POSIX semaphore facility. + * This has the advantage of more correct behavior on "give" operations: + * - give may be done from a signal / ISR context + * - give should not cause an unexpected task switch nor should it ever block + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_CountSemAPI_Impl_Init + + Purpose: Initialize the Counting Semaphore data structures + +---------------------------------------------------------------------------------------*/ +int32 OS_Posix_CountSemAPI_Impl_Init(void) +{ + memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); + return OS_SUCCESS; +} /* end OS_Posix_CountSemAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) +{ + if (sem_initial_value > SEM_VALUE_MAX) + { + return OS_INVALID_SEM_VALUE; + } + + if (sem_init(&OS_impl_count_sem_table[sem_id].id, 0, sem_initial_value) < 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemDelete_Impl (uint32 sem_id) +{ + if (sem_destroy(&OS_impl_count_sem_table[sem_id].id) < 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGive_Impl ( uint32 sem_id ) +{ + if (sem_post(&OS_impl_count_sem_table[sem_id].id) < 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTake_Impl ( uint32 sem_id ) +{ + if (sem_wait(&OS_impl_count_sem_table[sem_id].id) < 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_CountSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) +{ + struct timespec ts; + int result; + + /* + ** Compute an absolute time for the delay + */ + OS_Posix_CompAbsDelayTime(msecs, &ts); + + if (sem_timedwait(&OS_impl_count_sem_table[sem_id].id, &ts) == 0) + { + result = OS_SUCCESS; + } + else if (errno == ETIMEDOUT) + { + result = OS_SEM_TIMEOUT; + } + else + { + /* unspecified failure */ + result = OS_SEM_FAILURE; + } + + return result; +} /* end OS_CountSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) +{ + int sval; + + if (sem_getvalue(&OS_impl_count_sem_table[sem_id].id, &sval) < 0) + { + return OS_SEM_FAILURE; + } + + /* put the info into the stucture */ + count_prop -> value = sval; + return OS_SUCCESS; +} /* end OS_CountSemGetInfo_Impl */ + diff --git a/src/os/posix/src/os-impl-dirs.c b/src/os/posix/src/os-impl-dirs.c new file mode 100644 index 000000000..ed681ffc5 --- /dev/null +++ b/src/os/posix/src/os-impl-dirs.c @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include +#include +#include +#include + +#include "os-posix.h" +#include "os-impl-dirs.h" + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + +/* + * The directory handle table. + */ +OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + +/* -------------------------------------------------------------------------------------- + Name: OS_Posix_DirAPI_Impl_Init + + Purpose: Directory table initialization + + Returns: OS_SUCCESS if success + ---------------------------------------------------------------------------------------*/ +int32 OS_Posix_DirAPI_Impl_Init(void) +{ + memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); + return OS_SUCCESS; +} /* end OS_Posix_DirAPI_Impl_Init */ + diff --git a/src/os/posix/src/os-impl-errors.c b/src/os/posix/src/os-impl-errors.c new file mode 100644 index 000000000..c41f597d0 --- /dev/null +++ b/src/os/posix/src/os-impl-errors.c @@ -0,0 +1,30 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-common.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" + +#include "osapi-errors-impl.h" + +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; + diff --git a/src/os/posix/src/os-impl-files.c b/src/os/posix/src/os-impl-files.c new file mode 100644 index 000000000..f95facee1 --- /dev/null +++ b/src/os/posix/src/os-impl-files.c @@ -0,0 +1,98 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include +#include +#include +#include + +#include "os-posix.h" +#include "os-impl-files.h" + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + +/* + * The global file handle table. + * + * This is shared by all OSAL entities that perform low-level I/O. + */ +OS_Posix_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + +/* + * These two constants (EUID and EGID) are local cache of the + * euid and egid of the user running the OSAL application. They + * assist the "stat" implementation in determination of permissions. + * + * For an OS that does not have multiple users, these could be + * defined as 0. Otherwise they should be populated via the system + * geteuid/getegid calls. + */ +uid_t OS_IMPL_SELF_EUID = 0; +gid_t OS_IMPL_SELF_EGID = 0; + +/* + * Flag(s) to set on file handles for regular files + * This sets all regular filehandles to be non-blocking by default. + * + * In turn, the implementation will utilize select() to determine + * a filehandle readiness to read/write. + */ +const int OS_IMPL_REGULAR_FILE_FLAGS = O_NONBLOCK; + + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + +/* -------------------------------------------------------------------------------------- + Name: OS_Posix_StreamAPI_Impl_Init + + Purpose: File/Stream subsystem global initialization + + Returns: OS_SUCCESS if success + ---------------------------------------------------------------------------------------*/ +int32 OS_Posix_StreamAPI_Impl_Init(void) +{ + uint32 local_id; + + /* + * init all filehandles to -1, which is always invalid. + * this isn't strictly necessary but helps when debugging. + */ + for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) + { + OS_impl_filehandle_table[local_id].fd = -1; + } + + OS_IMPL_SELF_EUID = geteuid(); + OS_IMPL_SELF_EGID = getegid(); + + return OS_SUCCESS; +} /* end OS_Posix_StreamAPI_Impl_Init */ + diff --git a/src/os/posix/osfilesys.c b/src/os/posix/src/os-impl-filesys.c similarity index 93% rename from src/os/posix/osfilesys.c rename to src/os/posix/src/os-impl-filesys.c index 1a02a14dd..fcba70248 100644 --- a/src/os/posix/osfilesys.c +++ b/src/os/posix/src/os-impl-filesys.c @@ -1,19 +1,20 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osfilesys.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file has the api's for all of the making - * and mounting type of calls for file systems + * \file os-impl-filesys.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov * */ @@ -35,10 +36,8 @@ #include #include -#include "common_types.h" -#include "osapi.h" - -#include "os-impl.h" +#include "os-posix.h" +#include "osapi-filesys-impl.h" /**************************************************************************************** @@ -70,7 +69,7 @@ int32 OS_Posix_FileSysAPI_Impl_Init(void) * System Level API */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStartVolume_Impl diff --git a/src/os/posix/src/os-impl-fpu.c b/src/os/posix/src/os-impl-fpu.c new file mode 100644 index 000000000..b8fef6b40 --- /dev/null +++ b/src/os/posix/src/os-impl-fpu.c @@ -0,0 +1,116 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-fpu.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "bsp-impl.h" + +/**************************************************************************************** + FPU API (deprecated) + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, + int32 parameter) +{ + /* + ** Not implemented in linux. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcAttachHandler_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in linux. + */ + return(OS_SUCCESS); +} /* end OS_FPUExcEnable_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in linux. + */ + return(OS_SUCCESS); +} /* end OS_FPUExcDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcSetMask_Impl(uint32 mask) +{ + /* + ** Not implemented in linux. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcGetMask_Impl(uint32 *mask) +{ + /* + ** Not implemented in linux. + */ + *mask = 0; + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcGetMask_Impl */ + diff --git a/src/os/posix/src/os-impl-heap.c b/src/os/posix/src/os-impl-heap.c new file mode 100644 index 000000000..02cea6a26 --- /dev/null +++ b/src/os/posix/src/os-impl-heap.c @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-heap.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" + +/*---------------------------------------------------------------- + * + * Function: OS_HeapGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) +{ + /* + ** Not implemented yet + */ + return (OS_ERR_NOT_IMPLEMENTED); +} /* end OS_HeapGetInfo_Impl */ + diff --git a/src/os/posix/src/os-impl-idmap.c b/src/os/posix/src/os-impl-idmap.c new file mode 100644 index 000000000..61a2c52b3 --- /dev/null +++ b/src/os/posix/src/os-impl-idmap.c @@ -0,0 +1,228 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-idmap.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "bsp-impl.h" +#include + +#include "osapi-idmap-impl.h" + +typedef struct +{ + pthread_mutex_t mutex; + sigset_t sigmask; +} POSIX_GlobalLock_t; + +static POSIX_GlobalLock_t OS_global_task_table_mut; +static POSIX_GlobalLock_t OS_queue_table_mut; +static POSIX_GlobalLock_t OS_bin_sem_table_mut; +static POSIX_GlobalLock_t OS_mutex_table_mut; +static POSIX_GlobalLock_t OS_count_sem_table_mut; +static POSIX_GlobalLock_t OS_stream_table_mut; +static POSIX_GlobalLock_t OS_dir_table_mut; +static POSIX_GlobalLock_t OS_timebase_table_mut; +static POSIX_GlobalLock_t OS_module_table_mut; +static POSIX_GlobalLock_t OS_filesys_table_mut; +static POSIX_GlobalLock_t OS_console_mut; + +static POSIX_GlobalLock_t * const MUTEX_TABLE[] = + { + [OS_OBJECT_TYPE_UNDEFINED] = NULL, + [OS_OBJECT_TYPE_OS_TASK] = &OS_global_task_table_mut, + [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_mut, + [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_mut, + [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_mut, + [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_mut, + [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, + [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, + [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, + [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, + [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, + [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, + }; + +enum +{ + MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) +}; + +/*---------------------------------------------------------------- + * + * Function: OS_Lock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Lock_Global_Impl(uint32 idtype) +{ + POSIX_GlobalLock_t *mut; + sigset_t previous; + + if (idtype < MUTEX_TABLE_SIZE) + { + mut = MUTEX_TABLE[idtype]; + } + else + { + mut = NULL; + } + + if (mut == NULL) + { + return OS_ERROR; + } + + if (pthread_sigmask(SIG_SETMASK, &POSIX_GlobalVars.MaximumSigMask, &previous) != 0) + { + return OS_ERROR; + } + + if (pthread_mutex_lock(&mut->mutex) != 0) + { + return OS_ERROR; + } + + /* Only set values inside the GlobalLock _after_ it is locked */ + mut->sigmask = previous; + + return OS_SUCCESS; +} /* end OS_Lock_Global_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_Unlock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Unlock_Global_Impl(uint32 idtype) +{ + POSIX_GlobalLock_t *mut; + sigset_t previous; + + if (idtype < MUTEX_TABLE_SIZE) + { + mut = MUTEX_TABLE[idtype]; + } + else + { + mut = NULL; + } + + if (mut == NULL) + { + return OS_ERROR; + } + + /* Only get values inside the GlobalLock _before_ it is unlocked */ + previous = mut->sigmask; + + if (pthread_mutex_unlock(&mut->mutex) != 0) + { + return OS_ERROR; + } + + pthread_sigmask(SIG_SETMASK, &previous, NULL); + + return OS_SUCCESS; +} /* end OS_Unlock_Global_Impl */ + + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_TableMutex_Init + + Purpose: Initialize the mutex that the OS API uses for the shared state tables + + returns: OS_SUCCESS or OS_ERROR +---------------------------------------------------------------------------------------*/ +int32 OS_Posix_TableMutex_Init(uint32 idtype) +{ + int ret; + int32 return_code = OS_SUCCESS; + pthread_mutexattr_t mutex_attr; + + do + { + if (idtype >= MUTEX_TABLE_SIZE) + { + break; + } + + /* Initialize the table mutex for the given idtype */ + if (MUTEX_TABLE[idtype] == NULL) + { + break; + } + + /* + ** initialize the pthread mutex attribute structure with default values + */ + ret = pthread_mutexattr_init(&mutex_attr); + if ( ret != 0 ) + { + OS_DEBUG("Error: pthread_mutexattr_init failed: %s\n",strerror(ret)); + return_code = OS_ERROR; + break; + } + + /* + ** Allow the mutex to use priority inheritance + */ + ret = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT) ; + if ( ret != 0 ) + { + OS_DEBUG("Error: pthread_mutexattr_setprotocol failed: %s\n",strerror(ret)); + return_code = OS_ERROR; + break; + } + + /* + ** Set the mutex type to RECURSIVE so a thread can do nested locks + ** TBD - not sure if this is really desired, but keep it for now. + */ + ret = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + if ( ret != 0 ) + { + OS_DEBUG("Error: pthread_mutexattr_settype failed: %s\n",strerror(ret)); + return_code = OS_ERROR; + break; + } + + ret = pthread_mutex_init(&MUTEX_TABLE[idtype]->mutex, &mutex_attr); + if ( ret != 0 ) + { + OS_DEBUG("Error: pthread_mutex_init failed: %s\n",strerror(ret)); + return_code = OS_ERROR; + break; + } + } + while (0); + + + return(return_code); +} /* end OS_Posix_TableMutex_Init */ + diff --git a/src/os/posix/src/os-impl-interrupts.c b/src/os/posix/src/os-impl-interrupts.c new file mode 100644 index 000000000..856abbb5f --- /dev/null +++ b/src/os/posix/src/os-impl-interrupts.c @@ -0,0 +1,129 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-interrupts.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" + + +/**************************************************************************************** + INT API (deprecated) + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntAttachHandler_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntUnlock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntUnlock_Impl (int32 IntLevel) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntUnlock_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntLock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntLock_Impl ( void ) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntLock_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_IntEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntEnable_Impl(int32 Level) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntEnable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntDisable_Impl(int32 Level) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) +{ + *MaskSettingPtr = 0; + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntGetMask_Impl */ + diff --git a/src/os/posix/src/os-impl-loader.c b/src/os/posix/src/os-impl-loader.c new file mode 100644 index 000000000..7e02b1196 --- /dev/null +++ b/src/os/posix/src/os-impl-loader.c @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-loader.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include +#include "os-impl-loader.h" +#include "osapi-module-impl.h" + +OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; + +/*---------------------------------------------------------------- + * + * Function: OS_Posix_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Posix_ModuleAPI_Impl_Init(void) +{ + memset(OS_impl_module_table, 0, sizeof(OS_impl_module_table)); + return(OS_SUCCESS); +} /* end OS_Posix_ModuleAPI_Impl_Init */ + + diff --git a/src/os/posix/src/os-impl-mutex.c b/src/os/posix/src/os-impl-mutex.c new file mode 100644 index 000000000..0eb77ce99 --- /dev/null +++ b/src/os/posix/src/os-impl-mutex.c @@ -0,0 +1,201 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "os-impl-mutex.h" + + +/* Tables where the OS object information is stored */ +OS_impl_mutex_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + + +/**************************************************************************************** + MUTEX API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_Posix_MutexAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Posix_MutexAPI_Impl_Init(void) +{ + memset(OS_impl_mutex_table, 0, sizeof(OS_impl_mutex_table)); + return OS_SUCCESS; +} /* end OS_Posix_MutexAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) +{ + int return_code; + pthread_mutexattr_t mutex_attr; + + /* + ** initialize the attribute with default values + */ + return_code = pthread_mutexattr_init(&mutex_attr); + if ( return_code != 0 ) + { + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_init failed ID = %u: %s\n", + (unsigned int)sem_id,strerror(return_code)); + return OS_SEM_FAILURE; + } + + /* + ** Allow the mutex to use priority inheritance + */ + return_code = pthread_mutexattr_setprotocol(&mutex_attr,PTHREAD_PRIO_INHERIT); + if ( return_code != 0 ) + { + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_setprotocol failed ID = %u: %s\n", + (unsigned int)sem_id,strerror(return_code)); + return OS_SEM_FAILURE; + } + + /* + ** Set the mutex type to RECURSIVE so a thread can do nested locks + */ + return_code = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE); + if ( return_code != 0 ) + { + OS_DEBUG("Error: Mutex could not be created. pthread_mutexattr_settype failed ID = %u: %s\n", + (unsigned int)sem_id,strerror(return_code)); + return OS_SEM_FAILURE; + } + + /* + ** create the mutex + ** upon successful initialization, the state of the mutex becomes initialized and unlocked + */ + return_code = pthread_mutex_init(&OS_impl_mutex_table[sem_id].id,&mutex_attr); + if ( return_code != 0 ) + { + OS_DEBUG("Error: Mutex could not be created. ID = %u: %s\n", + (unsigned int)sem_id,strerror(return_code)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_MutSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemDelete_Impl (uint32 sem_id) +{ + int status; + + status = pthread_mutex_destroy( &(OS_impl_mutex_table[sem_id].id)); /* 0 = success */ + + if (status != 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_MutSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGive_Impl ( uint32 sem_id ) +{ + int status; + + /* + ** Unlock the mutex + */ + status = pthread_mutex_unlock(&(OS_impl_mutex_table[sem_id].id)); + if(status != 0) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_MutSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemTake_Impl ( uint32 sem_id ) +{ + int status; + + /* + ** Lock the mutex + */ + status = pthread_mutex_lock(&(OS_impl_mutex_table[sem_id].id)); + if( status != 0 ) + { + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_MutSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) +{ + return OS_SUCCESS; + +} /* end OS_MutSemGetInfo_Impl */ + diff --git a/src/os/posix/src/os-impl-no-module.c b/src/os/posix/src/os-impl-no-module.c new file mode 100644 index 000000000..a18cf65dc --- /dev/null +++ b/src/os/posix/src/os-impl-no-module.c @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-no-module.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include + +#include +#include "osapi-module-impl.h" + +/*---------------------------------------------------------------- + * + * Function: OS_Posix_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Posix_ModuleAPI_Impl_Init(void) +{ + /* nothing to init in this mode */ + return(OS_SUCCESS); +} /* end OS_Posix_ModuleAPI_Impl_Init */ + + diff --git a/src/os/posix/src/os-impl-queues.c b/src/os/posix/src/os-impl-queues.c new file mode 100644 index 000000000..97d8b3b4b --- /dev/null +++ b/src/os/posix/src/os-impl-queues.c @@ -0,0 +1,325 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "bsp-impl.h" + +#include "os-impl-queues.h" +#include "osapi-queue-impl.h" +#include "osapi-idmap-impl.h" + +/* Tables where the OS object information is stored */ +OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + +/**************************************************************************************** + MESSAGE QUEUE API + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_QueueAPI_Impl_Init + + Purpose: Initialize the Queue data structures + + ----------------------------------------------------------------------------------------*/ +int32 OS_Posix_QueueAPI_Impl_Init(void) +{ + memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); + + /* + * Automatic truncation is dependent on the OSAL_CONFIG_DEBUG_PERMISSIVE_MODE compile-time define - so + * creating a too-large message queue on a target without OSAL_CONFIG_DEBUG_PERMISSIVE_MODE will fail + * with an OS error as intended. + */ +#ifdef OSAL_CONFIG_DEBUG_PERMISSIVE_MODE + /* + * Use the BSP-provided limit + */ + POSIX_GlobalVars.TruncateQueueDepth = OS_BSP_Global.MaxQueueDepth; +#else + /* + * Initialize this to zero to indicate no limit + */ + POSIX_GlobalVars.TruncateQueueDepth = 0; +#endif + + return OS_SUCCESS; +} /* end OS_Posix_QueueAPI_Impl_Init */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) +{ + int return_code; + mqd_t queueDesc; + struct mq_attr queueAttr; + char name[OS_MAX_API_NAME * 2]; + + /* set queue attributes */ + memset(&queueAttr, 0, sizeof(queueAttr)); + queueAttr.mq_maxmsg = OS_queue_table[queue_id].max_depth; + queueAttr.mq_msgsize = OS_queue_table[queue_id].max_size; + + /* + * The "TruncateQueueDepth" indicates a soft limit to the size of a queue. + * If nonzero, anything larger than this will be silently truncated + * (Supports running applications as non-root) + */ + if (POSIX_GlobalVars.TruncateQueueDepth > 0 && + POSIX_GlobalVars.TruncateQueueDepth < queueAttr.mq_maxmsg) + { + queueAttr.mq_maxmsg = POSIX_GlobalVars.TruncateQueueDepth; + } + + /* + ** Construct the queue name: + ** The name will consist of "/.queue_name" + */ + snprintf(name, sizeof(name), "/%d.%s", (int)getpid(), OS_global_queue_table[queue_id].name_entry); + + /* + ** create message queue + */ + queueDesc = mq_open(name, O_CREAT | O_RDWR, 0666, &queueAttr); + if ( queueDesc == (mqd_t)(-1) ) + { + OS_DEBUG("OS_QueueCreate Error. errno = %d (%s)\n",errno,strerror(errno)); + if( errno == EINVAL ) + { + OS_DEBUG("Your queue depth may be too large for the\n"); + OS_DEBUG("OS to handle. Please check the msg_max\n"); + OS_DEBUG("parameter located in /proc/sys/fs/mqueue/msg_max\n"); + OS_DEBUG("on your Linux file system and raise it if you\n"); + OS_DEBUG(" need to or run as root\n"); + } + return_code = OS_ERROR; + } + else + { + OS_impl_queue_table[queue_id].id = queueDesc; + return_code = OS_SUCCESS; + + /* + * Unlink the queue right now -- + * queues have kernel persistence and if we do a lot of restarts (i.e. during debugging) + * a lot of stale message queues will collect in the system. It is OK to unlink right now + * as this only affects the ability of another process to open the same queue, but we do + * not need that to happen anyway. + */ + if(mq_unlink(name) != 0) + { + OS_DEBUG("OS_QueueDelete Error during mq_unlink(). errno = %d (%s)\n",errno,strerror(errno)); + /* Note - since the queue is already closed, we cannot really handle this failure gracefully, + * The queue is no longer usable so we can't return an error and go back to the way things were. + * In this case we need to return OS_SUCCESS so the rest of the entry will be cleaned up. + */ + } + } + + return return_code; +} /* end OS_QueueCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueDelete_Impl (uint32 queue_id) +{ + int32 return_code; + + /* Try to delete and unlink the queue */ + if (mq_close(OS_impl_queue_table[queue_id].id) != 0) + { + OS_DEBUG("OS_QueueDelete Error during mq_close(). errno = %d (%s)\n",errno,strerror(errno)); + return_code = OS_ERROR; + } + else + { + return_code = OS_SUCCESS; + } + + return return_code; +} /* end OS_QueueDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueGet_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) +{ + int32 return_code; + ssize_t sizeCopied; + struct timespec ts; + + /* + ** Read the message queue for data + */ + sizeCopied = -1; + if (timeout == OS_PEND) + { + /* + ** A signal can interrupt the mq_receive call, so the call has to be done with + ** a loop + */ + do + { + sizeCopied = mq_receive(OS_impl_queue_table[queue_id].id, data, size, NULL); + } + while ( sizeCopied < 0 && errno == EINTR ); + + } + else + { + /* + * NOTE - a prior implementation of OS_CHECK would check the mq_attr for a nonzero depth + * and then call mq_receive(). This is insufficient since another thread might do the same + * thing at the same time in which case one thread will read and the other will block. + * + * Calling mq_timedreceive with a zero timeout effectively does the same thing in the typical + * case, but for the case where two threads do a simultaneous read, one will get the message + * while the other will NOT block (as expected). + */ + if (timeout == OS_CHECK) + { + memset(&ts, 0, sizeof(ts)); + } + else + { + OS_Posix_CompAbsDelayTime( timeout, &ts); + } + + /* + ** If the mq_timedreceive call is interrupted by a system call or signal, + ** call it again. + */ + do + { + sizeCopied = mq_timedreceive(OS_impl_queue_table[queue_id].id, data, size, NULL, &ts); + } + while ( timeout != OS_CHECK && sizeCopied < 0 && errno == EINTR ); + + } /* END timeout */ + + /* Figure out the return code */ + if(sizeCopied == -1) + { + *size_copied = 0; + + /* Map the system errno to the most appropriate OSAL return code */ + if (errno == EMSGSIZE) + { + return_code = OS_QUEUE_INVALID_SIZE; + } + else if (timeout == OS_PEND || errno != ETIMEDOUT) + { + /* OS_PEND was supposed to pend forever until a message arrived + * so something else is wrong. Otherwise, at this point the only + * "acceptable" errno is TIMEDOUT for the other cases. + */ + return_code = OS_ERROR; + } + else if (timeout == OS_CHECK) + { + return_code = OS_QUEUE_EMPTY; + } + else + { + return_code = OS_QUEUE_TIMEOUT; + } + } + else + { + *size_copied = sizeCopied; + return_code = OS_SUCCESS; + } + + return return_code; +} /* end OS_QueueGet_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueuePut_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) +{ + int32 return_code; + int result; + struct timespec ts; + + /* + * NOTE - using a zero timeout here for the same reason that QueueGet does --- + * checking the attributes and doing the actual send is non-atomic, and if + * two threads call QueuePut() at the same time on a nearly-full queue, + * one could block. + */ + memset(&ts, 0, sizeof(ts)); + + /* send message */ + do + { + result = mq_timedsend(OS_impl_queue_table[queue_id].id, data, size, 1, &ts); + } + while ( result == -1 && errno == EINTR ); + + if(result == 0) + { + return_code = OS_SUCCESS; + } + else if (errno == ETIMEDOUT) + { + return_code = OS_QUEUE_FULL; + } + else + { + /* Something else went wrong */ + return_code = OS_ERROR; + } + + return return_code; + +} /* end OS_QueuePut_Impl */ + + diff --git a/src/os/posix/src/os-impl-shell.c b/src/os/posix/src/os-impl-shell.c new file mode 100644 index 000000000..30afa7afc --- /dev/null +++ b/src/os/posix/src/os-impl-shell.c @@ -0,0 +1,108 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-shell.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include +#include +#include +#include + +#include "os-posix.h" +#include "os-impl-io.h" + +#include "osapi-file-impl.h" +#include "osapi-idmap-impl.h" + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + + + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_ShellOutputToFile_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char* Cmd) +{ + pid_t cpid; + uint32 local_id; + int wstat; + const char *shell = getenv("SHELL"); + + if (shell == NULL) + { + shell = "/bin/sh"; + } + + cpid = fork(); + if (cpid < 0) + { + OS_DEBUG("%s(): Error during fork(): %s\n", __func__, strerror(errno)); + return OS_ERROR; + } + + if (cpid == 0) + { + /* child process */ + dup2(OS_impl_filehandle_table[file_id].fd, STDOUT_FILENO); + dup2(OS_impl_filehandle_table[file_id].fd, STDERR_FILENO); + + /* close all _other_ filehandles */ + for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) + { + if (OS_global_stream_table[local_id].active_id != 0) + { + close(OS_impl_filehandle_table[local_id].fd); + } + } + + execl(shell, "sh", "-c", Cmd, NULL); /* does not return if successful */ + exit(EXIT_FAILURE); + } + + if (waitpid(cpid, &wstat, 0) != cpid) + { + OS_DEBUG("%s(): Error during waitpid(): %s\n", __func__, strerror(errno)); + return OS_ERROR; + } + + if (!WIFEXITED(wstat) || WEXITSTATUS(wstat) != 0) + { + OS_DEBUG("%s(): Error from child process: %d\n", __func__, wstat); + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_ShellOutputToFile_Impl */ + diff --git a/src/os/posix/src/os-impl-tasks.c b/src/os/posix/src/os-impl-tasks.c new file mode 100644 index 000000000..edc3be861 --- /dev/null +++ b/src/os/posix/src/os-impl-tasks.c @@ -0,0 +1,789 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-posix.h" +#include "bsp-impl.h" +#include + +#include "os-impl-tasks.h" + +#include "osapi-task-impl.h" +#include "osapi-idmap-impl.h" + +/* + * Defines + */ +#ifndef PTHREAD_STACK_MIN +#define PTHREAD_STACK_MIN (8*1024) +#endif + +/* Tables where the OS object information is stored */ +OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + +/* + * Local Function Prototypes + */ + +/*---------------------------------------------------------------------------- + * Name: OS_PriorityRemap + * + * Purpose: Remaps the OSAL priority into one that is viable for this OS + * + * Note: This implementation assumes that InputPri has already been verified + * to be within the range of [0,OS_MAX_TASK_PRIORITY] + * +----------------------------------------------------------------------------*/ +static int OS_PriorityRemap(uint32 InputPri) +{ + int OutputPri; + + if (InputPri == 0) + { + /* use the "MAX" local priority only for OSAL tasks with priority=0 */ + OutputPri = POSIX_GlobalVars.PriLimits.PriorityMax; + } + else if (InputPri >= OS_MAX_TASK_PRIORITY) + { + /* use the "MIN" local priority only for OSAL tasks with priority=255 */ + OutputPri = POSIX_GlobalVars.PriLimits.PriorityMin; + } + else + { + /* + * Spread the remainder of OSAL priorities over the remainder of local priorities + * + * Note OSAL priorities use the VxWorks style with zero being the + * highest and OS_MAX_TASK_PRIORITY being the lowest, this inverts it + */ + OutputPri = (OS_MAX_TASK_PRIORITY - 1) - (int)InputPri; + + OutputPri *= (POSIX_GlobalVars.PriLimits.PriorityMax - POSIX_GlobalVars.PriLimits.PriorityMin) - 2; + OutputPri += OS_MAX_TASK_PRIORITY / 2; + OutputPri /= (OS_MAX_TASK_PRIORITY - 2); + OutputPri += POSIX_GlobalVars.PriLimits.PriorityMin + 1; + } + + return OutputPri; +} /* end OS_PriorityRemap */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_NoopSigHandler + * + * Purpose: Local helper routine, not part of OSAL API. + * A POSIX signal handler that does nothing + * + *-----------------------------------------------------------------*/ +static void OS_NoopSigHandler (int signal) +{ +} /* end OS_NoopSigHandler */ + + + +/*--------------------------------------------------------------------------------------- + Name: OS_PthreadEntry + + Purpose: A Simple pthread-compatible entry point that calls the real task function + + returns: NULL + + NOTES: This wrapper function is only used locally by OS_TaskCreate below + +---------------------------------------------------------------------------------------*/ +static void *OS_PthreadTaskEntry(void *arg) +{ + OS_U32ValueWrapper_t local_arg; + + local_arg.opaque_arg = arg; + OS_TaskEntryPoint(local_arg.value); /* Never returns */ + + return NULL; +} + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_GetSchedulerParams + + Purpose: Helper function to get the details of the given OS scheduling policy. + Determines if the policy is usable by OSAL - namely, that it provides + enough priority levels to be useful. + + returns: true if policy is suitable for use by OSAL + + NOTES: Only used locally by task API initialization + +---------------------------------------------------------------------------------------*/ +static bool OS_Posix_GetSchedulerParams(int sched_policy, POSIX_PriorityLimits_t *PriLim) +{ + int ret; + + /* + * Set up the local Min/Max priority levels (varies by OS and scheduler policy) + * + * Per POSIX: + * - The sched_get_priority_min/max() returns a number >= 0 on success. + * (-1 indicates an error) + * - Numerically higher values are scheduled before numerically lower values + * - A compliant OS will have a spread of at least 32 between min and max + */ + ret = sched_get_priority_max(sched_policy); + if (ret < 0) + { + OS_DEBUG("Policy %d: Unable to obtain maximum scheduling priority: %s\n", sched_policy, strerror(errno)); + return false; + } + + PriLim->PriorityMax = ret; + + ret = sched_get_priority_min(sched_policy); + if (ret < 0) + { + OS_DEBUG("Policy %d: Unable to obtain minimum scheduling priority: %s\n", sched_policy, strerror(errno)); + return false; + } + + PriLim->PriorityMin = ret; + + /* + * For OSAL, the absolute minimum spread between min and max must be 4. + * + * Although POSIX stipulates 32, we don't necessarily need that many, but we + * also want to confirm that there is an acceptable spread. + * + * - Highest is reserved for the root task + * - Next highest is reserved for OSAL priority=0 task(s) + * - Lowest is reserved for OSAL priority=255 tasks(s) + * - Need at least 1 for everything else. + */ + if ((PriLim->PriorityMax - PriLim->PriorityMin) < 4) + { + OS_DEBUG("Policy %d: Insufficient spread between priority min-max: %d-%d\n", + sched_policy, (int)PriLim->PriorityMin, (int)PriLim->PriorityMax); + return false; + } + + /* If we get here, then the sched_policy is potentially valid */ + OS_DEBUG("Policy %d: available, min-max: %d-%d\n", sched_policy, + (int)PriLim->PriorityMin, (int)PriLim->PriorityMax); + return true; +} /* end OS_Posix_GetSchedulerParams */ + +/* + ********************************************************************************* + * TASK API + ********************************************************************************* + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_Posix_TaskAPI_Impl_Init + + Purpose: Initialize the Posix Task data structures + + ----------------------------------------------------------------------------------------*/ +int32 OS_Posix_TaskAPI_Impl_Init(void) +{ + int ret; + int sig; + struct sched_param sched_param; + int sched_policy; + POSIX_PriorityLimits_t sched_fifo_limits; + bool sched_fifo_valid; + POSIX_PriorityLimits_t sched_rr_limits; + bool sched_rr_valid; + + /* Initialize Local Tables */ + memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); + + /* Clear the "limits" structs otherwise the compiler may warn + * about possibly being used uninitialized (false warning) + */ + memset(&sched_fifo_limits, 0, sizeof(sched_fifo_limits)); + memset(&sched_rr_limits, 0, sizeof(sched_rr_limits)); + + /* + * Create the key used to store OSAL task IDs + */ + ret = pthread_key_create(&POSIX_GlobalVars.ThreadKey, NULL ); + if ( ret != 0 ) + { + OS_DEBUG("Error creating thread key: %s (%d)\n",strerror(ret),ret); + return OS_ERROR; + } + + /* + ** Disable Signals to parent thread and therefore all + ** child threads create will block all signals + ** Note: Timers will not work in the application unless + ** threads are spawned in OS_Application_Startup. + */ + sigfillset(&POSIX_GlobalVars.MaximumSigMask); + + /* + * Keep these signals unblocked so the process can be interrupted + */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGINT); /* CTRL+C */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGABRT); /* Abort */ + + /* + * One should not typically block ANY of the synchronous error + * signals, i.e. SIGSEGV, SIGFPE, SIGILL, SIGBUS + * + * The kernel generates these signals in response to hardware events + * and they get routed to the _specific thread_ that was executing when + * the problem occurred. + * + * While it is technically possible to block these signals, the result is + * undefined, and it makes debugging _REALLY_ hard. If the kernel ever does + * send one it means there really is a major problem, best to listen to it, + * and not ignore it. + */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGSEGV); /* Segfault */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGILL); /* Illegal instruction */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGBUS); /* Bus Error */ + sigdelset(&POSIX_GlobalVars.MaximumSigMask, SIGFPE); /* Floating Point Exception */ + + /* + * Set the mask and store the original (default) mask in the POSIX_GlobalVars.NormalSigMask + */ + sigprocmask(SIG_SETMASK, &POSIX_GlobalVars.MaximumSigMask, &POSIX_GlobalVars.NormalSigMask); + + /* + * Add all "RT" signals into the POSIX_GlobalVars.NormalSigMask + * This will be used for the signal mask of the main thread + * (This way it will end up as the default/original signal mask plus all RT sigs) + */ + for (sig = SIGRTMIN; sig <= SIGRTMAX; ++sig) + { + sigaddset(&POSIX_GlobalVars.NormalSigMask, sig); + } + + /* + * SIGHUP is used to wake up the main thread when necessary, + * so make sure it is NOT in the set. + */ + sigdelset(&POSIX_GlobalVars.NormalSigMask, SIGHUP); + + /* + ** Install noop as the signal handler for SIGUP. + */ + signal(SIGHUP, OS_NoopSigHandler); + + /* + ** Raise the priority of the current (main) thread so that subsequent + ** application initialization will complete. This had previously been + ** done by the BSP and but it is moved here. + ** + ** This will only work if the user owning this process has permission + ** to create real time threads. Otherwise, the default priority will + ** be retained. Typically this is only the root user, but finer grained + ** permission controls are out there. So if it works, great, but if + ** a permission denied error is generated, that is OK too - this allows + ** easily debugging code as a normal user. + */ + ret = pthread_getschedparam(pthread_self(), &sched_policy, &sched_param); + if (ret == 0) + { + POSIX_GlobalVars.SelectedRtScheduler = sched_policy; /* Fallback/default */ + do + { + sched_fifo_valid = OS_Posix_GetSchedulerParams(SCHED_FIFO, &sched_fifo_limits); + sched_rr_valid = OS_Posix_GetSchedulerParams(SCHED_RR, &sched_rr_limits); + + /* + * If both policies are valid, choose the best. In general, FIFO is preferred + * since it is simpler. + * + * But, RR is preferred if mapping several OSAL priority levels into the + * same local priority level. For instance, if 2 OSAL tasks are created at priorities + * "2" and "1", both may get mapped to local priority 98, and if using FIFO then the + * task at priority "2" could run indefinitely, never letting priority "1" execute. + * + * This violates the original intent, which would be to have priority "1" preempt + * priority "2" tasks. RR is less bad since it at least guarantees both tasks some + * CPU time, + */ + if (sched_fifo_valid && sched_rr_valid) + { + /* + * If the spread from min->max is greater than what OSAL actually needs, + * then FIFO is the preferred scheduler. Must take into account one extra level + * for the root task. + */ + if ((sched_fifo_limits.PriorityMax - sched_fifo_limits.PriorityMin) > OS_MAX_TASK_PRIORITY) + { + sched_policy = SCHED_FIFO; + POSIX_GlobalVars.PriLimits = sched_fifo_limits; + } + else + { + sched_policy = SCHED_RR; + POSIX_GlobalVars.PriLimits = sched_rr_limits; + } + + } + else if (sched_fifo_valid) + { + /* only FIFO is available */ + sched_policy = SCHED_FIFO; + POSIX_GlobalVars.PriLimits = sched_fifo_limits; + } + else if (sched_rr_valid) + { + /* only RR is available */ + sched_policy = SCHED_RR; + POSIX_GlobalVars.PriLimits = sched_rr_limits; + } + else + { + /* Nothing is valid, use default */ + break; + } + + /* + * This OSAL POSIX implementation will reserve the absolute highest priority + * for the root thread, which ultimately will just pend in sigsuspend() so + * it will not actually DO anything, except if sent a signal. This way, + * that thread will still be able to preempt a high-priority user thread that + * has gone awry (i.e. using 100% cpu in FIFO mode). + */ + sched_param.sched_priority = POSIX_GlobalVars.PriLimits.PriorityMax; + --POSIX_GlobalVars.PriLimits.PriorityMax; + + OS_DEBUG("Selected policy %d for RT tasks, root task = %d\n", sched_policy, (int)sched_param.sched_priority); + + /* + * If the spread from min->max is greater than what OSAL actually needs, + * then truncate it at the number of OSAL priorities. This will end up mapping 1:1. + * and leaving the highest priority numbers unused. + */ + if ((POSIX_GlobalVars.PriLimits.PriorityMax - POSIX_GlobalVars.PriLimits.PriorityMin) > OS_MAX_TASK_PRIORITY) + { + POSIX_GlobalVars.PriLimits.PriorityMax = POSIX_GlobalVars.PriLimits.PriorityMin + OS_MAX_TASK_PRIORITY; + } + + ret = pthread_setschedparam(pthread_self(), sched_policy, &sched_param); + if (ret != 0) + { + OS_DEBUG("Could not setschedparam in main thread: %s (%d)\n",strerror(ret),ret); + break; + } + + /* + * Set the boolean to indicate that "setschedparam" worked -- + * This means that it is also expected to work for future calls. + */ + POSIX_GlobalVars.SelectedRtScheduler = sched_policy; + POSIX_GlobalVars.EnableTaskPriorities = true; + } + while (0); + } + else + { + OS_DEBUG("Could not getschedparam in main thread: %s (%d)\n",strerror(ret),ret); + } + +#if !defined(OSAL_CONFIG_DEBUG_PERMISSIVE_MODE) + /* + * In strict (non-permissive) mode, if the task priority setting did not work, fail with an error. + * This would be used on a real target where it needs to be ensured that priorities are active + * and the "silent fallback" of debug mode operation is not desired. + */ + if (!POSIX_GlobalVars.EnableTaskPriorities) + { + return OS_ERROR; + } +#endif + + return OS_SUCCESS; +} /* end OS_Posix_TaskAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_Posix_InternalTaskCreate_Impl + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Posix_InternalTaskCreate_Impl(pthread_t *pthr, uint32 priority, size_t stacksz, PthreadFuncPtr_t entry, void *entry_arg) +{ + int return_code = 0; + pthread_attr_t custom_attr; + struct sched_param priority_holder; + + + /* + ** Initialize the pthread_attr structure. + ** The structure is used to set the stack and priority + */ + memset(&custom_attr, 0, sizeof(custom_attr)); + return_code = pthread_attr_init(&custom_attr); + if(return_code != 0) + { + OS_DEBUG("pthread_attr_init error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + + + /* + ** Test to see if the original main task scheduling priority worked. + ** If so, then also set the attributes for this task. Otherwise attributes + ** are left at default. + */ + if (POSIX_GlobalVars.EnableTaskPriorities) + { + /* + ** Set the scheduling inherit attribute to EXPLICIT + */ + return_code = pthread_attr_setinheritsched(&custom_attr, PTHREAD_EXPLICIT_SCHED); + if ( return_code != 0 ) + { + OS_DEBUG("pthread_attr_setinheritsched error in OS_TaskCreate, errno = %s\n",strerror(return_code)); + return(OS_ERROR); + } + + /* + ** Set the Stack Size + */ + if (stacksz > 0) + { + if (stacksz < PTHREAD_STACK_MIN) + { + stacksz = PTHREAD_STACK_MIN; + } + + return_code = pthread_attr_setstacksize(&custom_attr, stacksz); + if (return_code != 0) + { + OS_DEBUG("pthread_attr_setstacksize error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + } + + /* + ** Set the scheduling policy + ** The best policy is determined during initialization + */ + return_code = pthread_attr_setschedpolicy(&custom_attr, POSIX_GlobalVars.SelectedRtScheduler); + if (return_code != 0) + { + OS_DEBUG("pthread_attr_setschedpolity error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + + /* + ** Set priority + */ + return_code = pthread_attr_getschedparam(&custom_attr, &priority_holder); + if (return_code != 0) + { + OS_DEBUG("pthread_attr_getschedparam error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + + priority_holder.sched_priority = OS_PriorityRemap(priority); + return_code = pthread_attr_setschedparam(&custom_attr,&priority_holder); + if(return_code != 0) + { + OS_DEBUG("pthread_attr_setschedparam error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + + } /* End if user is root */ + + /* + ** Create thread + */ + return_code = pthread_create(pthr, &custom_attr, entry, entry_arg); + if (return_code != 0) + { + OS_DEBUG("pthread_create error in OS_TaskCreate: %s\n",strerror(return_code)); + return(OS_ERROR); + } + + /* + ** Free the resources that are no longer needed + ** Since the task is now running - pthread_create() was successful - + ** Do not treat anything bad that happens after this point as fatal. + ** The task is running, after all - better to leave well enough alone. + */ + return_code = pthread_detach(*pthr); + if (return_code != 0) + { + OS_DEBUG("pthread_detach error in OS_TaskCreate: %s\n",strerror(return_code)); + } + + return_code = pthread_attr_destroy(&custom_attr); + if (return_code != 0) + { + OS_DEBUG("pthread_attr_destroy error in OS_TaskCreate: %s\n",strerror(return_code)); + } + + return OS_SUCCESS; +} /* end OS_Posix_InternalTaskCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) +{ + OS_U32ValueWrapper_t arg; + int32 return_code; + + arg.opaque_arg = NULL; + arg.value = OS_global_task_table[task_id].active_id; + + return_code = OS_Posix_InternalTaskCreate_Impl( + &OS_impl_task_table[task_id].id, + OS_task_table[task_id].priority, + OS_task_table[task_id].stack_size, + OS_PthreadTaskEntry, + arg.opaque_arg); + + return return_code; +} /* end OS_TaskCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskMatch_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskMatch_Impl(uint32 task_id) +{ + if (pthread_equal(pthread_self(), OS_impl_task_table[task_id].id) == 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_TaskMatch_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelete_Impl (uint32 task_id) +{ + /* + ** Try to delete the task + ** If this fails, not much recourse - the only potential cause of failure + ** to cancel here is that the thread ID is invalid because it already exited itself, + ** and if that is true there is nothing wrong - everything is OK to continue normally. + */ + pthread_cancel(OS_impl_task_table[task_id].id); + return OS_SUCCESS; + +} /* end OS_TaskDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskExit_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_TaskExit_Impl() +{ + pthread_exit(NULL); + +} /* end OS_TaskExit_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelay_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelay_Impl(uint32 millisecond) +{ + struct timespec sleep_end; + int status; + + clock_gettime(CLOCK_MONOTONIC, &sleep_end); + sleep_end.tv_sec += millisecond / 1000; + sleep_end.tv_nsec += 1000000 * (millisecond % 1000); + + if (sleep_end.tv_nsec >= 1000000000) + { + sleep_end.tv_nsec -= 1000000000; + ++sleep_end.tv_sec; + } + + do + { + status = clock_nanosleep(CLOCK_MONOTONIC, TIMER_ABSTIME, &sleep_end, NULL); + } + while (status == EINTR); + + if (status != 0) + { + return OS_ERROR; + } + else + { + return OS_SUCCESS; + } +} /* end OS_TaskDelay_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskSetPriority_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) +{ + int os_priority; + int ret; + + if (POSIX_GlobalVars.EnableTaskPriorities) + { + /* Change OSAL priority into a priority that will work for this OS */ + os_priority = OS_PriorityRemap(new_priority); + + /* + ** Set priority + */ + ret = pthread_setschedprio(OS_impl_task_table[task_id].id, os_priority); + if( ret != 0 ) + { + OS_DEBUG("pthread_setschedprio: Task ID = %u, prio = %d, err = %s\n", + (unsigned int)task_id,os_priority,strerror(ret)); + return(OS_ERROR); + } + } + + return OS_SUCCESS; +} /* end OS_TaskSetPriority_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskRegister_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskRegister_Impl(uint32 global_task_id) +{ + int32 return_code; + OS_U32ValueWrapper_t arg; + + arg.opaque_arg = 0; + arg.value = global_task_id; + + return_code = pthread_setspecific(POSIX_GlobalVars.ThreadKey, arg.opaque_arg); + if (return_code == 0) + { + return_code = OS_SUCCESS; + } + else + { + OS_DEBUG("OS_TaskRegister_Impl failed during pthread_setspecific() error=%s\n",strerror(return_code)); + return_code = OS_ERROR; + } + + return return_code; +} /* end OS_TaskRegister_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetId_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +uint32 OS_TaskGetId_Impl (void) +{ + OS_U32ValueWrapper_t self_record; + + self_record.opaque_arg = pthread_getspecific(POSIX_GlobalVars.ThreadKey); + + return(self_record.value); +} /* end OS_TaskGetId_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) +{ + size_t copy_sz; + + /* + * NOTE - this is not really valid, as you can't officially + * cast a pthread_t to an integer + * (in fact this fails on cygwin where pthread_t is NOT an integral type) + * + * This is just a hack to fill the value with something. + * To be portable, the application should _NOT_ be using OStask_id for anything. + */ + task_prop->OStask_id = 0; + + if (sizeof(pthread_t) < sizeof(task_prop->OStask_id)) + { + copy_sz = sizeof(pthread_t); + } + else + { + copy_sz = sizeof(task_prop->OStask_id); + } + + memcpy(&task_prop->OStask_id, &OS_impl_task_table[task_id].id, copy_sz); + + return OS_SUCCESS; +} /* end OS_TaskGetInfo_Impl */ + diff --git a/src/os/posix/ostimer.c b/src/os/posix/src/os-impl-timebase.c similarity index 92% rename from src/os/posix/ostimer.c rename to src/os/posix/src/os-impl-timebase.c index 54ad418fc..aa4c6c3f2 100644 --- a/src/os/posix/ostimer.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -1,11 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-timer.c + * \ingroup posix + * \author joseph.p.hickey@nasa.gov * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. */ /** @@ -24,6 +34,12 @@ ***************************************************************************************/ #include "os-posix.h" +#include "os-impl-timebase.h" + +#include "osapi-timebase-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-common-impl.h" + /**************************************************************************************** EXTERNAL FUNCTION PROTOTYPES @@ -52,23 +68,7 @@ static void OS_UsecToTimespec(uint32 usecs, struct timespec *time_spec); #endif /**************************************************************************************** - LOCAL TYPEDEFS - ***************************************************************************************/ - -typedef struct -{ - pthread_t handler_thread; - pthread_mutex_t handler_mutex; - timer_t host_timerid; - int assigned_signal; - sigset_t sigset; - uint32 reset_flag; - struct timespec softsleep; - -} OS_impl_timebase_internal_record_t; - -/**************************************************************************************** - GLOBAL DATA + GLOBALS ***************************************************************************************/ OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; @@ -100,7 +100,7 @@ static void OS_UsecToTimespec(uint32 usecs, struct timespec *time_spec) time_spec->tv_nsec = (usecs % 1000000) * 1000; } } /* end OS_UsecToTimespec */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseLock_Impl @@ -113,7 +113,7 @@ void OS_TimeBaseLock_Impl(uint32 local_id) { pthread_mutex_lock(&OS_impl_timebase_table[local_id].handler_mutex); } /* end OS_TimeBaseLock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseUnlock_Impl @@ -127,7 +127,7 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) pthread_mutex_unlock(&OS_impl_timebase_table[local_id].handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBase_SoftWaitImpl @@ -536,7 +536,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } /* end OS_TimeBaseSet_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseDelete_Impl @@ -572,7 +572,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) return OS_SUCCESS; } /* end OS_TimeBaseDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetInfo_Impl @@ -587,10 +587,3 @@ int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) } /* end OS_TimeBaseGetInfo_Impl */ -/**************************************************************************************** - Other Time-Related API Implementation - ***************************************************************************************/ - -/* POSIX implements clock_gettime and clock_settime that can be used */ -#include "../portable/os-impl-posix-gettime.c" - diff --git a/src/os/rtems/CMakeLists.txt b/src/os/rtems/CMakeLists.txt index 32ef42a9c..d21e7d3bc 100644 --- a/src/os/rtems/CMakeLists.txt +++ b/src/os/rtems/CMakeLists.txt @@ -5,13 +5,66 @@ ###################################################################### # This CMake script generates targets specific to the RTEMS implementation -# It defines an OBJECT target named "osal_rtems_impl" +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +# The basic set of files which are always built +set(RTEMS_BASE_SRCLIST + src/os-impl-binsem.c + src/os-impl-common.c + src/os-impl-console.c + src/os-impl-countsem.c + src/os-impl-dirs.c + src/os-impl-files.c + src/os-impl-filesys.c + src/os-impl-fpu.c + src/os-impl-heap.c + src/os-impl-interrupts.c + src/os-impl-mutex.c + src/os-impl-queues.c + src/os-impl-shell.c + src/os-impl-tasks.c + src/os-impl-timebase.c +) + +# Use portable blocks for basic I/O +set(RTEMS_IMPL_SRCLIST + ../portable/os-impl-posix-gettime.c + ../portable/os-impl-console-bsp.c + ../portable/os-impl-bsd-select.c + ../portable/os-impl-posix-io.c + ../portable/os-impl-posix-files.c + ../portable/os-impl-posix-dirs.c +) + +# If some form of module loading is configured, +# then build the module loader +if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER) + list(APPEND RTEMS_IMPL_SRCLIST + src/os-impl-module.c # Use RTEMS-specific versions of the load/unload routines + ../portable/os-impl-posix-dl-symtab.c # Use Standard POSIX implementation for symbol lookups + ) +else () + list(APPEND RTEMS_IMPL_SRCLIST + src/os-impl-no-module.c # No-op init routine + ../portable/os-impl-no-module.c # Non-implemented stubs for all Impl routines + ) +endif () + +# Leverage the "standard" BSD socket code if network is enabled +if (OSAL_CONFIG_INCLUDE_NETWORK) + list(APPEND RTEMS_IMPL_SRCLIST + src/os-impl-network.c + ../portable/os-impl-bsd-sockets.c + ) +else() + list(APPEND RTEMS_IMPL_SRCLIST + ../portable/os-impl-no-network.c + ../portable/os-impl-no-sockets.c + ) +endif () + +# Defines an OBJECT target named "osal_rtems_impl" with selected source files add_library(osal_rtems_impl OBJECT - osapi.c - osfileapi.c - osfilesys.c - osloader.c - osnetwork.c - osselect.c - ostimer.c + ${RTEMS_BASE_SRCLIST} + ${RTEMS_IMPL_SRCLIST} ) diff --git a/src/os/rtems/inc/os-impl-binsem.h b/src/os/rtems/inc/os-impl-binsem.h new file mode 100644 index 000000000..dce481e23 --- /dev/null +++ b/src/os/rtems/inc/os-impl-binsem.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_BINSEM_H_ +#define INCLUDE_OS_IMPL_BINSEM_H_ + +#include +#include + +typedef struct +{ + rtems_id id; +} OS_impl_binsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + + + +#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ + diff --git a/src/os/rtems/inc/os-impl-console.h b/src/os/rtems/inc/os-impl-console.h new file mode 100644 index 000000000..b578490ea --- /dev/null +++ b/src/os/rtems/inc/os-impl-console.h @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ +#define INCLUDE_OS_IMPL_CONSOLE_H_ + +#include +#include +#include +#include + +/* Console device */ +typedef struct +{ + bool is_async; + sem_t data_sem; +}OS_impl_console_internal_record_t; + + +extern OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + +#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ + diff --git a/src/os/rtems/inc/os-impl-countsem.h b/src/os/rtems/inc/os-impl-countsem.h new file mode 100644 index 000000000..3d4f2fc7b --- /dev/null +++ b/src/os/rtems/inc/os-impl-countsem.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ +#define INCLUDE_OS_IMPL_COUNTSEM_H_ + +#include +#include + +typedef struct +{ + rtems_id id; +} OS_impl_countsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + + +#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ + diff --git a/src/os/rtems/inc/os-impl-dirs.h b/src/os/rtems/inc/os-impl-dirs.h new file mode 100644 index 000000000..f9e4e414f --- /dev/null +++ b/src/os/rtems/inc/os-impl-dirs.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_DIRS_H_ +#define INCLUDE_OS_IMPL_DIRS_H_ + +#include +#include +#include +#include +#include +#include + +typedef struct +{ + DIR *dp; +} OS_impl_dir_internal_record_t; + + +/* + * The directory handle table. + */ +extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + +#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ + diff --git a/src/os/rtems/inc/os-impl-files.h b/src/os/rtems/inc/os-impl-files.h new file mode 100644 index 000000000..cf52a0bfe --- /dev/null +++ b/src/os/rtems/inc/os-impl-files.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_FILES_H_ +#define INCLUDE_OS_IMPL_FILES_H_ + +#include "os-impl-io.h" + +#include +#include +#include + +/* + * RTEMS does not have UID/GID so these are defined as 0. + */ +#define OS_IMPL_SELF_EUID 0 +#define OS_IMPL_SELF_EGID 0 + +#define OS_IMPL_REGULAR_FILE_FLAGS 0 + +#endif /* INCLUDE_OS_IMPL_FILES_H_ */ + diff --git a/src/os/rtems/inc/os-impl-gettime.h b/src/os/rtems/inc/os-impl-gettime.h new file mode 100644 index 000000000..befd2212b --- /dev/null +++ b/src/os/rtems/inc/os-impl-gettime.h @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-gettime.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_GETTIME_H_ +#define INCLUDE_OS_IMPL_GETTIME_H_ + +#include +#include + + +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC + + +#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ + diff --git a/src/os/rtems/inc/os-impl-io.h b/src/os/rtems/inc/os-impl-io.h new file mode 100644 index 000000000..b6ec164fd --- /dev/null +++ b/src/os/rtems/inc/os-impl-io.h @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-io.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_IO_H_ +#define INCLUDE_OS_IMPL_IO_H_ + +#include +#include +#include + +typedef struct +{ + int fd; + bool selectable; +} OS_Rtems_filehandle_entry_t; + +/* + * The global file handle table. + * + * This table is shared across multiple units (files, sockets, etc) and they will share + * the same file handle table from the basic file I/O. + */ +extern OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + +#endif /* INCLUDE_OS_IMPL_IO_H_ */ + diff --git a/src/os/rtems/inc/os-impl-loader.h b/src/os/rtems/inc/os-impl-loader.h new file mode 100644 index 000000000..20b813b74 --- /dev/null +++ b/src/os/rtems/inc/os-impl-loader.h @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-loader.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_LOADER_H_ +#define INCLUDE_OS_IMPL_LOADER_H_ + +#include +#include + +#include +#include + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +/* + * A local lookup table for RTEMS-specific information. + * This is not directly visible to the outside world. + */ +typedef struct +{ + /* cppcheck-suppress unusedStructMember */ + void *dl_handle; +} OS_impl_module_internal_record_t; + +extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; + + + +#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ + diff --git a/src/os/rtems/inc/os-impl-mutex.h b/src/os/rtems/inc/os-impl-mutex.h new file mode 100644 index 000000000..ca5f10d64 --- /dev/null +++ b/src/os/rtems/inc/os-impl-mutex.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_MUTEX_H_ +#define INCLUDE_OS_IMPL_MUTEX_H_ + +#include +#include + +typedef struct +{ + rtems_id id; +} OS_impl_mutex_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_mutex_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + + +#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ + diff --git a/src/os/rtems/inc/os-impl-queues.h b/src/os/rtems/inc/os-impl-queues.h new file mode 100644 index 000000000..501ab7f67 --- /dev/null +++ b/src/os/rtems/inc/os-impl-queues.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_QUEUES_H_ +#define INCLUDE_OS_IMPL_QUEUES_H_ + +#include +#include + +typedef struct +{ + rtems_id id; +} OS_impl_queue_internal_record_t; + + + +/* Tables where the OS object information is stored */ +extern OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + + +#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ + diff --git a/src/os/rtems/inc/os-impl-select.h b/src/os/rtems/inc/os-impl-select.h new file mode 100644 index 000000000..25f17dedb --- /dev/null +++ b/src/os/rtems/inc/os-impl-select.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-select.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SELECT_H_ +#define INCLUDE_OS_IMPL_SELECT_H_ + +#include "os-impl-io.h" + +#include +#include + + +#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ + diff --git a/src/os/rtems/inc/os-impl-sockets.h b/src/os/rtems/inc/os-impl-sockets.h new file mode 100644 index 000000000..2cd166156 --- /dev/null +++ b/src/os/rtems/inc/os-impl-sockets.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-sockets.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ +#define INCLUDE_OS_IMPL_SOCKETS_H_ + +#include "os-impl-io.h" + +#include +#include +#include +#include +#include +#include + +/* + * A RTEMS socket I/O layer should support using + * nonblocking I/O calls in combination with select(). + */ +#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK + + + +#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ + diff --git a/src/os/rtems/inc/os-impl-tasks.h b/src/os/rtems/inc/os-impl-tasks.h new file mode 100644 index 000000000..4d02c959b --- /dev/null +++ b/src/os/rtems/inc/os-impl-tasks.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TASKS_H_ +#define INCLUDE_OS_IMPL_TASKS_H_ + +#include +#include + +typedef struct +{ + rtems_id id; +} OS_impl_task_internal_record_t; + + +/* Tables where the OS object information is stored */ +extern OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + + +#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ + diff --git a/src/os/rtems/inc/os-impl-timebase.h b/src/os/rtems/inc/os-impl-timebase.h new file mode 100644 index 000000000..bc3b6a24d --- /dev/null +++ b/src/os/rtems/inc/os-impl-timebase.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-timebase.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ +#define INCLUDE_OS_IMPL_TIMEBASE_H_ + +#include +#include +#include + + +typedef struct +{ + pthread_t handler_thread; + pthread_mutex_t handler_mutex; + timer_t host_timerid; + int assigned_signal; + sigset_t sigset; + sig_atomic_t reset_flag; + struct timespec softsleep; + +} OS_impl_timebase_internal_record_t; + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; + + +#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ + diff --git a/src/os/rtems/os-rtems.h b/src/os/rtems/inc/os-rtems.h similarity index 72% rename from src/os/rtems/os-rtems.h rename to src/os/rtems/inc/os-rtems.h index 0b1db8f29..3e7fa7bc8 100644 --- a/src/os/rtems/os-rtems.h +++ b/src/os/rtems/inc/os-rtems.h @@ -1,23 +1,30 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file os-rtems.h - * \author joseph.p.hickey@nasa.gov + * \file os-rtems.h + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov * * Purpose: This file contains definitions that are shared across the RTEMS * OSAL implementation. This file is private to the RTEMS port and it * may contain RTEMS-specific definitions. - * */ +#ifndef INCLUDE_OS_RTEMS_H_ +#define INCLUDE_OS_RTEMS_H_ + + /**************************************************************************************** COMMON INCLUDE FILES ***************************************************************************************/ @@ -52,12 +59,6 @@ typedef struct rtems_id IdleTaskId; } RTEMS_GlobalVars_t; -typedef struct -{ - int fd; - bool selectable; -} OS_Rtems_filehandle_entry_t; - /**************************************************************************************** GLOBAL DATA @@ -65,14 +66,6 @@ typedef struct extern RTEMS_GlobalVars_t RTEMS_GlobalVars; -/* - * The global file handle table. - * - * This table is shared across multiple units (files, sockets, etc) and they will share - * the same file handle table from the basic file I/O. - */ -extern OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - /**************************************************************************************** RTEMS IMPLEMENTATION FUNCTION PROTOTYPES @@ -91,3 +84,6 @@ int32 OS_Rtems_FileSysAPI_Impl_Init(void); + +#endif /* INCLUDE_OS_RTEMS_H_ */ + diff --git a/src/os/rtems/osapi.c b/src/os/rtems/osapi.c deleted file mode 100644 index 62b672c04..000000000 --- a/src/os/rtems/osapi.c +++ /dev/null @@ -1,1818 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osapi.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: - * This file contains some of the OS APIs abstraction layer for RTEMS - * This has been tested against the current RTEMS 4.11 release branch - * - * NOTE: This uses only the "Classic" RTEMS API. It is intended to - * work on RTEMS targets that do not provide the POSIX API, i.e. - * when "--disable-posix" is given during the configuration stage. - * - * If the RTEMS POSIX API is enabled, then it may be possible to - * use the POSIX OSAL which is more full featured. - */ -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-rtems.h" - -#include - -/**************************************************************************************** - DEFINES - ***************************************************************************************/ - -#define OSAL_CONSOLE_STREAM stdout -#define RTEMS_INT_LEVEL_ENABLE_ALL 0 -#define RTEMS_INT_LEVEL_DISABLE_ALL 7 -#define MAX_SEM_VALUE 0x7FFFFFFF - -/* - * Define all of the RTEMS semaphore attributes - * 1. The TABLE_MUTEX attributes are for the internal OSAL tables. - * In RTEMS, a MUTEX is defined as a binary semaphore - * It allows nested locks, priority wait order, and supports priority inheritance - * - * 2. OSAL Mutex attributes -- same as 1 - * - * 3. OSAL Binary Semaphore attributes - * This is a simple binary semaphore used for synchronization. It does not - * allow nested calls ( nor should it ) It should not be used for mutual exclusion. - * - * 4. OSAL Counting Semaphore attributes - * This is a counting semaphore with priority wait order. - * - */ - -#define OSAL_RTEMS_INHERIT_PRIO RTEMS_INHERIT_PRIORITY - -#define OSAL_TABLE_MUTEX_ATTRIBS (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | OSAL_RTEMS_INHERIT_PRIO) - -#define OSAL_MUTEX_ATTRIBS (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | OSAL_RTEMS_INHERIT_PRIO) - -#define OSAL_BINARY_SEM_ATTRIBS (RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY) - -#define OSAL_COUNT_SEM_ATTRIBS (RTEMS_PRIORITY) - -/* - * By default use the stdout stream for the console (OS_printf) - */ -#define OSAL_CONSOLE_FILENO STDOUT_FILENO - -/* - * By default the console output is always asynchronous - * (equivalent to "OS_UTILITY_TASK_ON" being set) - * - * This option was removed from osconfig.h and now is - * assumed to always be on. - */ -#define OS_CONSOLE_ASYNC true -#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY -#define OS_CONSOLE_TASK_STACKSIZE OS_UTILITYTASK_STACK_SIZE - - -/**************************************************************************************** - GLOBAL DATA - ***************************************************************************************/ -/* tables for the properties of objects */ - -/*tasks */ -typedef struct -{ - rtems_id id; -} OS_impl_internal_record_t; - -/* Console device */ -typedef struct -{ - bool is_async; - rtems_id data_sem; - int out_fd; -} OS_impl_console_internal_record_t; - - -/* Tables where the OS object information is stored */ -OS_impl_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; -OS_impl_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; -OS_impl_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; -OS_impl_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; -OS_impl_internal_record_t OS_impl_mut_sem_table [OS_MAX_MUTEXES]; -OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; - -rtems_id OS_task_table_sem; -rtems_id OS_queue_table_sem; -rtems_id OS_bin_sem_table_sem; -rtems_id OS_mut_sem_table_sem; -rtems_id OS_count_sem_table_sem; -rtems_id OS_stream_table_mut; -rtems_id OS_dir_table_mut; -rtems_id OS_timebase_table_mut; -rtems_id OS_module_table_mut; -rtems_id OS_filesys_table_mut; -rtems_id OS_console_mut; - -static rtems_id * const MUTEX_TABLE[] = - { - [OS_OBJECT_TYPE_UNDEFINED] = NULL, - [OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_sem, - [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_sem, - [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_sem, - [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_sem, - [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mut_sem_table_sem, - [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, - [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, - [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, - [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, - [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, - [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, - }; - -enum -{ - MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) -}; - -const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; - -RTEMS_GlobalVars_t RTEMS_GlobalVars = { 0 }; - -/*---------------------------------------------------------------- - * - * Function: OS_Lock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) -{ - rtems_id *mut; - - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else - { - mut = NULL; - } - - if (mut == NULL) - { - return OS_ERROR; - } - - if (rtems_semaphore_obtain(*mut, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != 0) - { - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_Lock_Global_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_Unlock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) -{ - rtems_id *mut; - - if (idtype < MUTEX_TABLE_SIZE) - { - mut = MUTEX_TABLE[idtype]; - } - else - { - mut = NULL; - } - - if (mut == NULL) - { - return OS_ERROR; - } - - if (rtems_semaphore_release(*mut) != 0) - { - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ - - - -/**************************************************************************************** - INITIALIZATION FUNCTION - ***************************************************************************************/ - -/*--------------------------------------------------------------------------------------- - Name: OS_API_Init - - Purpose: Initialize the tables that the OS API uses to keep track of information - about objects - - returns: OS_SUCCESS or OS_ERROR ----------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) -{ - int32 return_code = OS_SUCCESS; - rtems_status_code rtems_sc; - - do - { - /* Initialize the table mutex for the given idtype */ - if (idtype < MUTEX_TABLE_SIZE && MUTEX_TABLE[idtype] != NULL) - { - rtems_sc = rtems_semaphore_create (idtype, - 1, OSAL_TABLE_MUTEX_ATTRIBS, 0, - MUTEX_TABLE[idtype]); - - if ( rtems_sc != RTEMS_SUCCESSFUL ) - { - OS_DEBUG("Error: rtems_semaphore_create failed: %s\n", rtems_status_text(rtems_sc)); - return_code = OS_ERROR; - break; - } - } - - switch(idtype) - { - case OS_OBJECT_TYPE_OS_TASK: - return_code = OS_Rtems_TaskAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_QUEUE: - return_code = OS_Rtems_QueueAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_BINSEM: - return_code = OS_Rtems_BinSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_COUNTSEM: - return_code = OS_Rtems_CountSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MUTEX: - return_code = OS_Rtems_MutexAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MODULE: - return_code = OS_Rtems_ModuleAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_TIMEBASE: - return_code = OS_Rtems_TimeBaseAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_STREAM: - return_code = OS_Rtems_StreamAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_DIR: - return_code = OS_Rtems_DirAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_FILESYS: - return_code = OS_Rtems_FileSysAPI_Impl_Init(); - break; - default: - break; - } - } - while (0); - - - return(return_code); -} /* end OS_API_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IdleLoop_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_IdleLoop_Impl() -{ - RTEMS_GlobalVars.IdleTaskId = rtems_task_self(); - rtems_task_suspend(RTEMS_SELF); -} /* end OS_IdleLoop_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ApplicationShutdown_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ApplicationShutdown_Impl() -{ - /* Note that setting the IdleTaskId and suspending - * the idle task is not an atomic operation, so there - * is a remote chance that this could attempt to - * resume a task that is not yet suspended. */ - rtems_task_resume(RTEMS_GlobalVars.IdleTaskId); -} /* end OS_ApplicationShutdown_Impl */ - - - -/*--------------------------------------------------------------------------------------- - Name: OS_RtemsEntry - - Purpose: A Simple RTEMS-compatible entry point that calls the common task entry function - - NOTES: This wrapper function is only used locally by OS_TaskCreate below - ----------------------------------------------------------------------------------------*/ -static rtems_task OS_RtemsEntry(rtems_task_argument arg) -{ - OS_TaskEntryPoint((uint32)arg); -} /* end OS_RtemsEntry */ - - - -/**************************************************************************************** - TASK API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_Rtems_TaskAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Rtems_TaskAPI_Impl_Init(void) -{ - memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); - return (OS_SUCCESS); -} /* end OS_Rtems_TaskAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) -{ - rtems_status_code status; - rtems_name r_name; - rtems_mode r_mode; - rtems_attribute r_attributes; - - /* - ** RTEMS task names are 4 byte integers. - ** It is convenient to use the OSAL task ID in here, as we know it is already unique - ** and trying to use the real task name would be less than useful (only 4 chars) - */ - r_name = OS_global_task_table[task_id].active_id; - r_mode = RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0); - - /* - ** see if the user wants floating point enabled. If - ** so, then set the correct option. - */ - r_attributes = RTEMS_LOCAL; - if (flags & OS_FP_ENABLED) - { - r_attributes |= RTEMS_FLOATING_POINT; - } - - status = rtems_task_create( - r_name, - OS_task_table[task_id].priority, - OS_task_table[task_id].stack_size, - r_mode, - r_attributes, - &OS_impl_task_table[task_id].id); - - /* check if task_create failed */ - if (status != RTEMS_SUCCESSFUL ) - { - /* Provide some freedback as to why this failed */ - OS_printf("rtems_task_create failed: %s\n", rtems_status_text(status)); - return OS_ERROR; - } - - /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start (OS_impl_task_table[task_id].id, /*rtems task id*/ - (rtems_task_entry) OS_RtemsEntry, /* task entry point */ - (rtems_task_argument) OS_global_task_table[task_id].active_id ); /* passed argument */ - - if (status != RTEMS_SUCCESSFUL ) - { - OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); - rtems_task_delete(OS_impl_task_table[task_id].id); - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_TaskCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl (uint32 task_id) -{ - /* - ** Try to delete the task - ** If this fails, not much recourse - the only potential cause of failure - ** to cancel here is that the thread ID is invalid because it already exited itself, - ** and if that is true there is nothing wrong - everything is OK to continue normally. - */ - - rtems_task_delete(OS_impl_task_table[task_id].id); - return OS_SUCCESS; -} /* end OS_TaskDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskExit_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_TaskExit_Impl() -{ - rtems_task_delete(RTEMS_SELF); - -} /* end OS_TaskExit_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelay_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelay_Impl (uint32 milli_second) -{ - rtems_interval ticks; - - ticks = OS_Milli2Ticks(milli_second); - - rtems_task_wake_after(ticks); - /* - ** Always successful ( from RTEMS docs ) - */ - return (OS_SUCCESS); - -} /* end OS_TaskDelay_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskSetPriority_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) -{ - rtems_task_priority old_pri; - rtems_status_code status; - - /* Set RTEMS Task Priority */ - status = rtems_task_set_priority(OS_impl_task_table[task_id].id, new_priority, &old_pri); - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled task_set_priority error: %s\n",rtems_status_text(status)); - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_TaskSetPriority_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskMatch_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) -{ - /* - ** Get RTEMS Task Id - */ - if ( rtems_task_self() != OS_impl_task_table[task_id].id ) - { - return(OS_ERROR); - } - - - return OS_SUCCESS; -} /* end OS_TaskMatch_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskRegister_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskRegister_Impl (uint32 global_task_id) -{ - /* - * This is supposed to maintain the "reverse lookup" information used - * to map an RTEMS task ID back into an OSAL ID. - * - * Originally this used "task variables" which got deprecated. - * So this changed to "task notes" which are also now deprecated in 4.11. - * - * So there is now no documented per-task thread local storage facility in RTEMS - * with these two options gone. RTEMS does seem to have TLS, but there is just - * no published (non-deprecated) API to access it. - * - * Right now this does nothing and the OS_TaskGetId() must brute-force it. - * - * An alternative for performance improvements might be to use a locally maintained - * hash table here. - */ - return OS_SUCCESS; - -} /* end OS_TaskRegister_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetId_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -uint32 OS_TaskGetId_Impl (void) -{ - uint32 global_task_id; - rtems_id task_self; - rtems_name self_name; - rtems_status_code status; - - task_self = rtems_task_self(); - /* When the task was created the OSAL ID was used as the "classic name", - * which gives us an easy way to map it back again */ - status = rtems_object_get_classic_name(task_self, &self_name); - if (status == RTEMS_SUCCESSFUL) - { - global_task_id = self_name; - } - else - { - global_task_id = 0; - } - - return global_task_id; - -} /* end OS_TaskGetId_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) -{ - task_prop->OStask_id = (uint32) OS_impl_task_table[task_id].id; - return OS_SUCCESS; - -} /* end OS_TaskGetInfo_Impl */ - - -/**************************************************************************************** - MESSAGE QUEUE API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_Rtems_QueueAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Rtems_QueueAPI_Impl_Init(void) -{ - memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); - return (OS_SUCCESS); -} /* end OS_Rtems_QueueAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) -{ - rtems_status_code status; - rtems_name r_name; - - - /* - ** RTEMS task names are 4 byte integers. - ** It is convenient to use the OSAL queue ID in here, as we know it is already unique - ** and trying to use the real queue name would be less than useful (only 4 chars) - */ - r_name = OS_global_queue_table[queue_id].active_id; - - /* - ** Create the message queue. - ** The queue attributes are set to default values; the waiting order - ** (RTEMS_FIFO or RTEMS_PRIORITY) is irrelevant since only one task waits - ** on each queue. - */ - status = rtems_message_queue_create( - r_name, /* 32-bit RTEMS object name; not used */ - OS_queue_table[queue_id].max_depth, /* maximum number of messages in queue (queue depth) */ - OS_queue_table[queue_id].max_size, /* maximum size in bytes of a message */ - RTEMS_FIFO|RTEMS_LOCAL, /* attributes (default) */ - &(OS_impl_queue_table[queue_id].id) /* object ID returned for queue */ - ); - - /* - ** If the operation failed, report the error - */ - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled queue_create error: %s\n",rtems_status_text(status)); - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_QueueCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl (uint32 queue_id) -{ - rtems_status_code status; - - /* Try to delete the queue */ - status = rtems_message_queue_delete(OS_impl_queue_table[queue_id].id); - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled queue_delete error: %s\n",rtems_status_text(status)); - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_QueueDelete_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueGet_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, - int32 timeout) -{ - int32 return_code; - rtems_status_code status; - rtems_interval ticks; - rtems_option option_set; - size_t rtems_size; - rtems_id rtems_queue_id; - - rtems_queue_id = OS_impl_queue_table[queue_id].id; - - /* Get Message From Message Queue */ - if (timeout == OS_PEND) - { - option_set = RTEMS_WAIT; - ticks = RTEMS_NO_TIMEOUT; - } - else if (timeout == OS_CHECK) - { - option_set = RTEMS_NO_WAIT; - ticks = RTEMS_NO_TIMEOUT; - } - else - { - option_set = RTEMS_WAIT; - /* msecs rounded to the closest system tick count */ - ticks = OS_Milli2Ticks(timeout); - } - - /* - ** Pend until a message arrives. - */ - status = rtems_message_queue_receive( - rtems_queue_id, /* message queue descriptor */ - data, /* pointer to message buffer */ - &rtems_size, /* returned size of message */ - option_set, /* wait option */ - ticks /* timeout */ - ); - - if (status == RTEMS_SUCCESSFUL) - { - return_code = OS_SUCCESS; - } - else if (status == RTEMS_TIMEOUT) - { - return_code = OS_QUEUE_TIMEOUT; - } - else if (status == RTEMS_UNSATISFIED) - { - return_code = OS_QUEUE_EMPTY; - } - else - { - /* Something else went wrong */ - return_code = OS_ERROR; - OS_DEBUG("Unhandled queue_receive error: %s\n",rtems_status_text(status)); - } - - /* - ** Check the size of the message. If a valid message was - ** obtained, indicate success. - */ - if (status == RTEMS_SUCCESSFUL) - { - *size_copied = rtems_size; - if (rtems_size != size) - { - /* Success, but the size was wrong */ - return_code = OS_QUEUE_INVALID_SIZE; - } - } - else - { - *size_copied = 0; - } - - return return_code; -} /* end OS_QueueGet_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueuePut_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) -{ - rtems_status_code status; - rtems_id rtems_queue_id; - - rtems_queue_id = OS_impl_queue_table[queue_id].id; - - /* Write the buffer pointer to the queue. If an error occurred, report it - ** with the corresponding SB status code. - */ - status = rtems_message_queue_send( - rtems_queue_id, /* message queue descriptor */ - data, /* pointer to message */ - size /* length of message */ - ); - - if (status == RTEMS_TOO_MANY) - { - /* - ** Queue is full. - */ - return OS_QUEUE_FULL; - } - - if (status != RTEMS_SUCCESSFUL) - { - /* - ** Unexpected error while writing to queue. - */ - OS_DEBUG("Unhandled queue_send error: %s\n",rtems_status_text(status)); - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_QueuePut_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) -{ - /* No extra info for queues in the OS implementation */ - return OS_SUCCESS; - -} /* end OS_QueueGetInfo_Impl */ - - -/**************************************************************************************** - SEMAPHORE API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_Rtems_BinSemAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Rtems_BinSemAPI_Impl_Init(void) -{ - memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); - return (OS_SUCCESS); -} /* end OS_Rtems_BinSemAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) -{ - rtems_status_code status; - rtems_name r_name; - - /* - ** RTEMS task names are 4 byte integers. - ** It is convenient to use the OSAL ID in here, as we know it is already unique - ** and trying to use the real name would be less than useful (only 4 chars) - */ - r_name = OS_global_bin_sem_table[sem_id].active_id; - - /* Check to make sure the sem value is going to be either 0 or 1 */ - if (sem_initial_value > 1) - { - sem_initial_value = 1; - } - - /* Create RTEMS Semaphore */ - status = rtems_semaphore_create( r_name, sem_initial_value, - OSAL_BINARY_SEM_ATTRIBS, - 0, - &(OS_impl_bin_sem_table[sem_id].id)); - - /* check if Create failed */ - if ( status != RTEMS_SUCCESSFUL ) - { - OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_BinSemCreate_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_delete(OS_impl_bin_sem_table[sem_id].id); - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_BinSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_release(OS_impl_bin_sem_table[sem_id].id); - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_BinSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemFlush_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl (uint32 sem_id) -{ - rtems_status_code status; - - /* Give Semaphore */ - status = rtems_semaphore_flush(OS_impl_bin_sem_table[sem_id].id); - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_flush error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_BinSemFlush_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - /* - ** If the semaphore is flushed, this function will return - ** RTEMS_UNSATISFIED. If this happens, the OSAL does not want to return - ** an error, it would be inconsistent with the other ports - ** - ** I currently do not know of any other reasons this call would return - ** RTEMS_UNSATISFIED, so I think it is OK. - */ - if ( status != RTEMS_SUCCESSFUL && status != RTEMS_UNSATISFIED ) - { - OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_BinSemTake_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) -{ - rtems_status_code status; - uint32 TimeInTicks; - - TimeInTicks = OS_Milli2Ticks(msecs); - - status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks) ; - - if ( status == RTEMS_TIMEOUT ) - { - return OS_SEM_TIMEOUT; - } - - /* See BinSemWait regarding UNSATISFIED */ - if ( status != RTEMS_SUCCESSFUL && status != RTEMS_UNSATISFIED ) - { - OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_BinSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) -{ - /* RTEMS has no API for obtaining the current value of a semaphore */ - return OS_SUCCESS; -} /* end OS_BinSemGetInfo_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_Rtems_CountSemAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Rtems_CountSemAPI_Impl_Init(void) -{ - memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); - return (OS_SUCCESS); -} /* end OS_Rtems_CountSemAPI_Impl_Init */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) -{ - rtems_status_code status; - rtems_name r_name; - - /* - ** Verify that the semaphore maximum value is not too high - */ - if ( sem_initial_value > MAX_SEM_VALUE ) - { - return OS_INVALID_SEM_VALUE; - } - - /* - ** RTEMS task names are 4 byte integers. - ** It is convenient to use the OSAL ID in here, as we know it is already unique - ** and trying to use the real name would be less than useful (only 4 chars) - */ - r_name = OS_global_count_sem_table[sem_id].active_id; - status = rtems_semaphore_create( r_name, sem_initial_value, - OSAL_COUNT_SEM_ATTRIBS, - 0, - &(OS_impl_count_sem_table[sem_id].id)); - - /* check if Create failed */ - if ( status != RTEMS_SUCCESSFUL ) - { - OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_delete( OS_impl_count_sem_table[sem_id].id); - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_release(OS_impl_count_sem_table[sem_id].id); - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return(OS_SUCCESS); - -} /* end OS_CountSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemTake_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs) -{ - rtems_status_code status; - uint32 TimeInTicks; - - TimeInTicks = OS_Milli2Ticks(msecs); - - status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); - if (status == RTEMS_TIMEOUT) - { - return OS_SEM_TIMEOUT; - } - - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_CountSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) -{ - /* RTEMS does not provide an API to get the value */ - return OS_SUCCESS; - -} /* end OS_CountSemGetInfo_Impl */ - -/**************************************************************************************** - MUTEX API - ***************************************************************************************/ - - - -/*---------------------------------------------------------------- - * - * Function: OS_Rtems_MutexAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_Rtems_MutexAPI_Impl_Init(void) -{ - memset(OS_impl_mut_sem_table, 0, sizeof(OS_impl_mut_sem_table)); - return (OS_SUCCESS); -} /* end OS_Rtems_MutexAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) -{ - rtems_status_code status; - rtems_name r_name; - - /* - ** Try to create the mutex - */ - r_name = OS_global_mutex_table[sem_id].active_id; - status = rtems_semaphore_create ( r_name, 1, - OSAL_MUTEX_ATTRIBS , - 0, - &OS_impl_mut_sem_table[sem_id].id ); - - if ( status != RTEMS_SUCCESSFUL ) - { - OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_MutSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_delete( OS_impl_mut_sem_table[sem_id].id); - if (status != RTEMS_SUCCESSFUL) - { - /* clean up? */ - OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_MutSemDelete_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl (uint32 sem_id) -{ - rtems_status_code status; - - /* Give the mutex */ - status = rtems_semaphore_release(OS_impl_mut_sem_table[sem_id].id); - - if(status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_MutSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl (uint32 sem_id) -{ - rtems_status_code status; - - status = rtems_semaphore_obtain(OS_impl_mut_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - - if (status != RTEMS_SUCCESSFUL) - { - OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; - -} /* end OS_MutSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) -{ - /* RTEMS provides no additional info */ - return OS_SUCCESS; - -} /* end OS_MutSemGetInfo_Impl */ - -/**************************************************************************************** - TICK API - ***************************************************************************************/ - -#ifndef OSAL_OMIT_DEPRECATED - -/**************************************************************************************** - INT API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) -{ -#if (CPU_SIMPLE_VECTORED_INTERRUPTS == false) - return OS_ERR_NOT_IMPLEMENTED; -#else - rtems_status_code ret_status; - uint32 status ; - rtems_isr_entry old_handler; - - ret_status = rtems_interrupt_catch( - (rtems_isr_entry)InterruptHandler, - (rtems_vector_number)InterruptNumber, - &old_handler); - - switch (ret_status) - { - case RTEMS_SUCCESSFUL : - status = OS_SUCCESS; - break ; - - case RTEMS_INVALID_NUMBER : - status = OS_INVALID_INT_NUM; - break ; - - case RTEMS_INVALID_ADDRESS : - status = OS_INVALID_POINTER; - break ; - - default : - status = OS_ERROR; - break ; - } - return(status) ; -#endif -} /* end OS_IntAttachHandler_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_IntUnlock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntUnlock_Impl (int32 IntLevel) -{ - rtems_interrupt_level rtems_int_level = IntLevel; - rtems_interrupt_local_enable ( rtems_int_level ); - return (OS_SUCCESS); - -} /* end OS_IntUnlock_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntLock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntLock_Impl (void) -{ - rtems_interrupt_level rtems_int_level; - - /* - * NOTE: rtems_interrupt_local_disable() is a macro - * that sets the rtems_int_level value. - * - * This code assumes that the value is also storable - * in an int32. - * - * This uses the "local" version which operates on - * the current CPU in case of a multi-processor environment. - * - * This should be identical to rtems_interrupt_disable in - * a single-processor config, but that call is not - * implemented in multi-processor configs. - */ - rtems_interrupt_local_disable(rtems_int_level) ; - return ( (int32) rtems_int_level) ; - -} /* end OS_IntLock_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_IntEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntEnable_Impl (int32 Level) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntEnable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntDisable_Impl (int32 Level) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) -{ - *MaskSettingPtr = 0; - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntGetMask_Impl */ - -#endif /* OSAL_OMIT_DEPRECATED */ - -/*---------------------------------------------------------------- - * - * Function: OS_HeapGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_HeapGetInfo_Impl (OS_heap_prop_t *heap_prop) -{ - region_information_block info; - int status; - - status = malloc_info( &info ); - - if ( status != 0 ) - { - return(OS_ERROR); - } - - heap_prop->free_bytes = (uint32) info.Free.total; - heap_prop->free_blocks = (uint32) info.Free.number; - heap_prop->largest_free_block = (uint32) info.Free.largest; - - return (OS_SUCCESS); -} /* end OS_HeapGetInfo_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, - int32 parameter) -{ - /* - ** Not implemented in RTEMS. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcAttachHandler_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in RTEMS. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcEnable_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in RTEMS. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcSetMask_Impl(uint32 mask) -{ - /* - ** Not implemented in RTEMS. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcGetMask_Impl(uint32 *mask) -{ - /* - ** Not implemented in RTEMS. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcGetMask_Impl */ - -/********************************************************************/ -/* CONSOLE OUTPUT */ -/********************************************************************/ - -/* use the portable version of OS_ConsoleWrite_Impl() */ -#include "../portable/os-impl-console-directwrite.c" - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleWakeup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - - if (local->is_async) - { - /* post the sem for the utility task to run */ - rtems_semaphore_release(local->data_sem); - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(local_id); - } -} /* end OS_ConsoleWakeup_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleTask_Entry - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -static void OS_ConsoleTask_Entry(rtems_task_argument arg) -{ - uint32 local_id = arg; - OS_impl_console_internal_record_t *local; - - local = &OS_impl_console_table[local_id]; - while (true) - { - OS_ConsoleOutput_Impl(local_id); - rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); - } -} /* end OS_ConsoleTask_Entry */ - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - int32 return_code; - rtems_name r_name; - rtems_id r_task_id; - rtems_status_code status; - - if (local_id == 0) - { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; - local->out_fd = OSAL_CONSOLE_FILENO; - - if (local->is_async) - { - OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); - /* - ** RTEMS task names are 4 byte integers. - ** It is convenient to use the OSAL ID in here, as we know it is already unique - ** and trying to use the real name would be less than useful (only 4 chars) - */ - r_name = OS_global_console_table[local_id].active_id; - status = rtems_semaphore_create( r_name, 0, - OSAL_COUNT_SEM_ATTRIBS, - 0, - &local->data_sem); - if (status != RTEMS_SUCCESSFUL) - { - return_code = OS_SEM_FAILURE; - } - else - { - status = rtems_task_create( - r_name, - OS_CONSOLE_TASK_PRIORITY, - OS_CONSOLE_TASK_STACKSIZE, - RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0), - RTEMS_LOCAL, - &r_task_id); - - /* check if task_create failed */ - if (status != RTEMS_SUCCESSFUL ) - { - /* Provide some freedback as to why this failed */ - OS_DEBUG("rtems_task_create failed: %s\n", rtems_status_text(status)); - rtems_semaphore_delete(local->data_sem); - return_code = OS_ERROR; - } - else - { - /* will place the task in 'ready for scheduling' state */ - status = rtems_task_start (r_task_id, /*rtems task id*/ - OS_ConsoleTask_Entry, /* task entry point */ - (rtems_task_argument)local_id ); /* passed argument */ - - if (status != RTEMS_SUCCESSFUL ) - { - OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); - rtems_task_delete(r_task_id); - rtems_semaphore_delete(local->data_sem); - return_code = OS_ERROR; - } - } - } - } - } - else - { - /* only one physical console device is implemented */ - return_code = OS_ERR_NOT_IMPLEMENTED; - } - - return return_code; -} /* end OS_ConsoleCreate_Impl */ - - diff --git a/src/os/rtems/osfileapi.c b/src/os/rtems/osfileapi.c deleted file mode 100644 index f7733a31e..000000000 --- a/src/os/rtems/osfileapi.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osfileapi.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file Contains all of the api calls for manipulating - * files in a file system for RTEMS - * - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-rtems.h" - -#include -#include -#include - -/**************************************************************************************** - DEFINES - ***************************************************************************************/ - -#define OS_REDIRECTSTRSIZE 15 - - -/* - * RTEMS does not have UID/GID so these are defined as 0. - */ -#define OS_IMPL_SELF_EUID 0 -#define OS_IMPL_SELF_EGID 0 - - -/**************************************************************************************** - GLOBALS - ***************************************************************************************/ - -/* - * Leverage the POSIX-style File I/O as this will mostly work on RTEMS, - * with the exception that regular files cannot be passed to select(), - * which means that we should NOT set the O_NONBLOCK flag on filehandles - * like the standard POSIX OSAL does. - */ -const int OS_IMPL_REGULAR_FILE_FLAGS = 0; - -/* - * The global file handle table. - * - * This is shared by all OSAL entities that perform low-level I/O. - */ -/* The file/stream table is referenced by multiple entities, i.e. sockets, select, etc */ -OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - -/* - * The directory handle table. - */ -DIR *OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; - - - -/**************************************************************************************** - COMMON ROUTINES - After including the OS/C-library specific include files, the basic UNIX file API is used - ****************************************************************************************/ - -/* - * The "I/O" portable block includes the generic - * posix-style read/write/seek/close operations - */ -#include "../portable/os-impl-posix-io.c" - -/* - * The "Files" portable block includes impl - * calls for named files i.e. FileOpen and FileStat - * This is anything that operates on a pathname. - */ -#include "../portable/os-impl-posix-files.c" - -/* - * The "Dirs" portable block includes impl - * calls for reading directory contents using - * posix-style opendir/readdir/closedir etc. - */ -#include "../portable/os-impl-posix-dirs.c" - - -/**************************************************************************************** - IMPLEMENTATION-SPECIFIC ROUTINES - These are specific to this particular operating system - ****************************************************************************************/ - -/* -------------------------------------------------------------------------------------- - Name: OS_Rtems_StreamAPI_Impl_Init - - Purpose: File/Stream subsystem global initialization - - Returns: OS_SUCCESS if success - ---------------------------------------------------------------------------------------*/ -int32 OS_Rtems_StreamAPI_Impl_Init(void) -{ - uint32 local_id; - - /* - * init all filehandles to -1, which is always invalid. - * this isn't strictly necessary but helps when debugging. - */ - for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) - { - OS_impl_filehandle_table[local_id].fd = -1; - } - - return OS_SUCCESS; -} /* end OS_Rtems_StreamAPI_Impl_Init */ - -/* -------------------------------------------------------------------------------------- - Name: OS_Rtems_DirAPI_Impl_Init - - Purpose: Directory table initialization - - Returns: OS_SUCCESS if success - ---------------------------------------------------------------------------------------*/ -int32 OS_Rtems_DirAPI_Impl_Init(void) -{ - memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); - return OS_SUCCESS; -} /* end OS_Rtems_DirAPI_Impl_Init */ - - -/* FIXME - need to do something better here */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ShellOutputToFile_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) -{ - /* - ** this is a #define to avoid a 'variable length array' warning - ** 15 is for the size of the redirection string that is added - ** to the command - */ - char LocalCmd [OS_MAX_CMD_LEN + OS_REDIRECTSTRSIZE]; - int32 Result; - - strncpy(LocalCmd,Cmd,OS_MAX_CMD_LEN +OS_REDIRECTSTRSIZE); - - /* Make sure that we are able to access this file */ - fchmod(OS_impl_filehandle_table[file_id].fd, 0666); - - /* - ** add in the extra chars necessary to perform the redirection - ** 1 for stdout and 2 for stderr. they are redirected to the - ** file descriptor passed in - */ - snprintf(LocalCmd, sizeof(LocalCmd), "%s 1>&%d 2>&%d", - Cmd, - OS_impl_filehandle_table[file_id].fd, - OS_impl_filehandle_table[file_id].fd); - - Result = system(LocalCmd); - - if (Result != 0) - { - return OS_FS_ERROR; - } - return OS_SUCCESS; -} /* end OS_ShellOutputToFile_Impl */ - diff --git a/src/os/rtems/osnetwork.c b/src/os/rtems/osnetwork.c deleted file mode 100644 index cf64d6e7a..000000000 --- a/src/os/rtems/osnetwork.c +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osnetwork.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains the network functionality for the osapi. - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-rtems.h" - -#ifdef OS_INCLUDE_NETWORK - -#include -#include -#include -#include -#include -#include - - -/* - * Leverage the POSIX-style File I/O as this will mostly work on RTEMS, - * with the exception that regular files cannot be passed to select(), - * which means that we should NOT set the O_NONBLOCK flag on filehandles - * like the standard POSIX OSAL does. - */ -const int OS_IMPL_SOCKET_FLAGS = O_NONBLOCK; - -/* Leverage the portable BSD sockets implementation */ -#include "../portable/os-impl-bsd-sockets.c" - -/*---------------------------------------------------------------- - * - * Function: OS_NetworkGetID_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_NetworkGetID_Impl (int32 *IdBuf) -{ - /* RTEMS does not have the GetHostId call - - * it is deprecated in other OS's anyway and not a good idea to use it - */ - return OS_ERR_NOT_IMPLEMENTED; -} /* end OS_NetworkGetID_Impl */ - -#else /* OS_INCLUDE_NETWORK */ - -/**************************************************************************************** - NOT IMPLEMENTED OPTION - This block provides stubs in case this module is disabled by config - ****************************************************************************************/ - -/* - * The "no-network" block includes the required API calls - * that all return OS_ERR_NOT_IMPLEMENTED - */ -#include "../portable/os-impl-no-network.c" - - -#endif - diff --git a/src/os/rtems/osselect.c b/src/os/rtems/osselect.c deleted file mode 100644 index e9d86241f..000000000 --- a/src/os/rtems/osselect.c +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file osselect.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: This file contains wrappers around the select() system call - * - */ - -/**************************************************************************************** - INCLUDE FILES - ***************************************************************************************/ - -#include "os-rtems.h" - -#include - - -/**************************************************************************************** - COMMON ROUTINES - After including the OS/C-library specific include files, the basic UNIX select API is used - ****************************************************************************************/ - -/* - * NOTE: the RTEMS select() implementation is very limited and only works on - * network sockets (at least for release 4.11.2 this is the case). - */ -#include "../portable/os-impl-bsd-select.c" - diff --git a/src/os/rtems/src/os-impl-binsem.c b/src/os/rtems/src/os-impl-binsem.c new file mode 100644 index 000000000..cc47c0365 --- /dev/null +++ b/src/os/rtems/src/os-impl-binsem.c @@ -0,0 +1,274 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-binsem.h" + + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +/* + * Define all of the RTEMS semaphore attributes + * 3. OSAL Binary Semaphore attributes + * This is a simple binary semaphore used for synchronization. It does not + * allow nested calls ( nor should it ) It should not be used for mutual exclusion. + */ + +#define OSAL_BINARY_SEM_ATTRIBS (RTEMS_SIMPLE_BINARY_SEMAPHORE | RTEMS_PRIORITY) + + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ +/* tables for the properties of objects */ + + +/* Tables where the OS object information is stored */ +OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + + +/**************************************************************************************** + SEMAPHORE API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_BinSemAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_BinSemAPI_Impl_Init(void) +{ + memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); + return (OS_SUCCESS); +} /* end OS_Rtems_BinSemAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) +{ + rtems_status_code status; + rtems_name r_name; + + /* + ** RTEMS task names are 4 byte integers. + ** It is convenient to use the OSAL ID in here, as we know it is already unique + ** and trying to use the real name would be less than useful (only 4 chars) + */ + r_name = OS_global_bin_sem_table[sem_id].active_id; + + /* Check to make sure the sem value is going to be either 0 or 1 */ + if (sem_initial_value > 1) + { + sem_initial_value = 1; + } + + /* Create RTEMS Semaphore */ + status = rtems_semaphore_create( r_name, sem_initial_value, + OSAL_BINARY_SEM_ATTRIBS, + 0, + &(OS_impl_bin_sem_table[sem_id].id)); + + /* check if Create failed */ + if ( status != RTEMS_SUCCESSFUL ) + { + OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_BinSemCreate_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemDelete_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_delete(OS_impl_bin_sem_table[sem_id].id); + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_BinSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGive_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_release(OS_impl_bin_sem_table[sem_id].id); + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_BinSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemFlush_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemFlush_Impl (uint32 sem_id) +{ + rtems_status_code status; + + /* Give Semaphore */ + status = rtems_semaphore_flush(OS_impl_bin_sem_table[sem_id].id); + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_flush error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_BinSemFlush_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTake_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + /* + ** If the semaphore is flushed, this function will return + ** RTEMS_UNSATISFIED. If this happens, the OSAL does not want to return + ** an error, it would be inconsistent with the other ports + ** + ** I currently do not know of any other reasons this call would return + ** RTEMS_UNSATISFIED, so I think it is OK. + */ + if ( status != RTEMS_SUCCESSFUL && status != RTEMS_UNSATISFIED ) + { + OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_BinSemTake_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) +{ + rtems_status_code status; + uint32 TimeInTicks; + + TimeInTicks = OS_Milli2Ticks(msecs); + + status = rtems_semaphore_obtain(OS_impl_bin_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks) ; + + if ( status == RTEMS_TIMEOUT ) + { + return OS_SEM_TIMEOUT; + } + + /* See BinSemWait regarding UNSATISFIED */ + if ( status != RTEMS_SUCCESSFUL && status != RTEMS_UNSATISFIED ) + { + OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_BinSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) +{ + /* RTEMS has no API for obtaining the current value of a semaphore */ + return OS_SUCCESS; +} /* end OS_BinSemGetInfo_Impl */ + diff --git a/src/os/rtems/src/os-impl-common.c b/src/os/rtems/src/os-impl-common.c new file mode 100644 index 000000000..c7d4e411e --- /dev/null +++ b/src/os/rtems/src/os-impl-common.c @@ -0,0 +1,259 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-common.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +#define OSAL_TABLE_MUTEX_ATTRIBS (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY) + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + +rtems_id OS_task_table_sem; +rtems_id OS_queue_table_sem; +rtems_id OS_bin_sem_table_sem; +rtems_id OS_mutex_table_sem; +rtems_id OS_count_sem_table_sem; +rtems_id OS_stream_table_mut; +rtems_id OS_dir_table_mut; +rtems_id OS_timebase_table_mut; +rtems_id OS_module_table_mut; +rtems_id OS_filesys_table_mut; +rtems_id OS_console_mut; + +static rtems_id * const MUTEX_TABLE[] = + { + [OS_OBJECT_TYPE_UNDEFINED] = NULL, + [OS_OBJECT_TYPE_OS_TASK] = &OS_task_table_sem, + [OS_OBJECT_TYPE_OS_QUEUE] = &OS_queue_table_sem, + [OS_OBJECT_TYPE_OS_COUNTSEM] = &OS_count_sem_table_sem, + [OS_OBJECT_TYPE_OS_BINSEM] = &OS_bin_sem_table_sem, + [OS_OBJECT_TYPE_OS_MUTEX] = &OS_mutex_table_sem, + [OS_OBJECT_TYPE_OS_STREAM] = &OS_stream_table_mut, + [OS_OBJECT_TYPE_OS_DIR] = &OS_dir_table_mut, + [OS_OBJECT_TYPE_OS_TIMEBASE] = &OS_timebase_table_mut, + [OS_OBJECT_TYPE_OS_MODULE] = &OS_module_table_mut, + [OS_OBJECT_TYPE_OS_FILESYS] = &OS_filesys_table_mut, + [OS_OBJECT_TYPE_OS_CONSOLE] = &OS_console_mut, + }; + +enum +{ + MUTEX_TABLE_SIZE = (sizeof(MUTEX_TABLE) / sizeof(MUTEX_TABLE[0])) +}; + +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; + +RTEMS_GlobalVars_t RTEMS_GlobalVars = { 0 }; + +/*---------------------------------------------------------------- + * + * Function: OS_Lock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Lock_Global_Impl(uint32 idtype) +{ + rtems_id *mut; + + if (idtype < MUTEX_TABLE_SIZE) + { + mut = MUTEX_TABLE[idtype]; + } + else + { + mut = NULL; + } + + if (mut == NULL) + { + return OS_ERROR; + } + + if (rtems_semaphore_obtain(*mut, RTEMS_WAIT, RTEMS_NO_TIMEOUT) != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_Lock_Global_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_Unlock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Unlock_Global_Impl(uint32 idtype) +{ + rtems_id *mut; + + if (idtype < MUTEX_TABLE_SIZE) + { + mut = MUTEX_TABLE[idtype]; + } + else + { + mut = NULL; + } + + if (mut == NULL) + { + return OS_ERROR; + } + + if (rtems_semaphore_release(*mut) != 0) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_Unlock_Global_Impl */ + + + +/**************************************************************************************** + INITIALIZATION FUNCTION + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_API_Init + + Purpose: Initialize the tables that the OS API uses to keep track of information + about objects + + returns: OS_SUCCESS or OS_ERROR +---------------------------------------------------------------------------------------*/ +int32 OS_API_Impl_Init(uint32 idtype) +{ + int32 return_code = OS_SUCCESS; + rtems_status_code rtems_sc; + + do + { + /* Initialize the table mutex for the given idtype */ + if (idtype < MUTEX_TABLE_SIZE && MUTEX_TABLE[idtype] != NULL) + { + rtems_sc = rtems_semaphore_create (idtype, + 1, OSAL_TABLE_MUTEX_ATTRIBS, 0, + MUTEX_TABLE[idtype]); + + if ( rtems_sc != RTEMS_SUCCESSFUL ) + { + OS_DEBUG("Error: rtems_semaphore_create failed: %s\n", rtems_status_text(rtems_sc)); + return_code = OS_ERROR; + break; + } + } + + switch(idtype) + { + case OS_OBJECT_TYPE_OS_TASK: + return_code = OS_Rtems_TaskAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_QUEUE: + return_code = OS_Rtems_QueueAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_BINSEM: + return_code = OS_Rtems_BinSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_COUNTSEM: + return_code = OS_Rtems_CountSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MUTEX: + return_code = OS_Rtems_MutexAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MODULE: + return_code = OS_Rtems_ModuleAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_TIMEBASE: + return_code = OS_Rtems_TimeBaseAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_STREAM: + return_code = OS_Rtems_StreamAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_DIR: + return_code = OS_Rtems_DirAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_FILESYS: + return_code = OS_Rtems_FileSysAPI_Impl_Init(); + break; + default: + break; + } + } + while (0); + + + return(return_code); +} /* end OS_API_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IdleLoop_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_IdleLoop_Impl() +{ + RTEMS_GlobalVars.IdleTaskId = rtems_task_self(); + rtems_task_suspend(RTEMS_SELF); +} /* end OS_IdleLoop_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ApplicationShutdown_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ApplicationShutdown_Impl() +{ + /* Note that setting the IdleTaskId and suspending + * the idle task is not an atomic operation, so there + * is a remote chance that this could attempt to + * resume a task that is not yet suspended. */ + rtems_task_resume(RTEMS_GlobalVars.IdleTaskId); +} /* end OS_ApplicationShutdown_Impl */ + + diff --git a/src/os/rtems/src/os-impl-console.c b/src/os/rtems/src/os-impl-console.c new file mode 100644 index 000000000..3624e80a1 --- /dev/null +++ b/src/os/rtems/src/os-impl-console.c @@ -0,0 +1,204 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +#define OSAL_CONSOLE_STREAM stdout +/* + * By default use the stdout stream for the console (OS_printf) + */ +#define OSAL_CONSOLE_FILENO STDOUT_FILENO + +/* + * By default the console output is always asynchronous + * (equivalent to "OS_UTILITY_TASK_ON" being set) + * + * This option was removed from osconfig.h and now is + * assumed to always be on. + */ +#define OS_CONSOLE_ASYNC true +#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY +#define OS_CONSOLE_TASK_STACKSIZE OS_UTILITYTASK_STACK_SIZE + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ +/* Console device */ +typedef struct +{ + bool is_async; + rtems_id data_sem; + int out_fd; +} OS_impl_console_internal_record_t; + + +/* Tables where the OS object information is stored */ +OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + + +/********************************************************************/ +/* CONSOLE OUTPUT */ +/********************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleWakeup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ConsoleWakeup_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + + if (local->is_async) + { + /* post the sem for the utility task to run */ + rtems_semaphore_release(local->data_sem); + } + else + { + /* output directly */ + OS_ConsoleOutput_Impl(local_id); + } +} /* end OS_ConsoleWakeup_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleTask_Entry + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +static void OS_ConsoleTask_Entry(rtems_task_argument arg) +{ + uint32 local_id = arg; + OS_impl_console_internal_record_t *local; + + local = &OS_impl_console_table[local_id]; + while (true) + { + OS_ConsoleOutput_Impl(local_id); + rtems_semaphore_obtain(local->data_sem, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + } +} /* end OS_ConsoleTask_Entry */ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ConsoleCreate_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + int32 return_code; + rtems_name r_name; + rtems_id r_task_id; + rtems_status_code status; + + if (local_id == 0) + { + return_code = OS_SUCCESS; + local->is_async = OS_CONSOLE_ASYNC; + local->out_fd = OSAL_CONSOLE_FILENO; + + if (local->is_async) + { + OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); + /* + ** RTEMS task names are 4 byte integers. + ** It is convenient to use the OSAL ID in here, as we know it is already unique + ** and trying to use the real name would be less than useful (only 4 chars) + */ + r_name = OS_global_console_table[local_id].active_id; + status = rtems_semaphore_create( r_name, 0, + RTEMS_PRIORITY, + 0, + &local->data_sem); + if (status != RTEMS_SUCCESSFUL) + { + return_code = OS_SEM_FAILURE; + } + else + { + status = rtems_task_create( + r_name, + OS_CONSOLE_TASK_PRIORITY, + OS_CONSOLE_TASK_STACKSIZE, + RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0), + RTEMS_LOCAL, + &r_task_id); + + /* check if task_create failed */ + if (status != RTEMS_SUCCESSFUL ) + { + /* Provide some freedback as to why this failed */ + OS_DEBUG("rtems_task_create failed: %s\n", rtems_status_text(status)); + rtems_semaphore_delete(local->data_sem); + return_code = OS_ERROR; + } + else + { + /* will place the task in 'ready for scheduling' state */ + status = rtems_task_start (r_task_id, /*rtems task id*/ + OS_ConsoleTask_Entry, /* task entry point */ + (rtems_task_argument)local_id ); /* passed argument */ + + if (status != RTEMS_SUCCESSFUL ) + { + OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); + rtems_task_delete(r_task_id); + rtems_semaphore_delete(local->data_sem); + return_code = OS_ERROR; + } + } + } + } + } + else + { + /* only one physical console device is implemented */ + return_code = OS_ERR_NOT_IMPLEMENTED; + } + + return return_code; +} /* end OS_ConsoleCreate_Impl */ + + diff --git a/src/os/rtems/src/os-impl-countsem.c b/src/os/rtems/src/os-impl-countsem.c new file mode 100644 index 000000000..d56b8db1c --- /dev/null +++ b/src/os/rtems/src/os-impl-countsem.c @@ -0,0 +1,235 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-countsem.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +#define MAX_SEM_VALUE 0x7FFFFFFF + +/* + * Define all of the RTEMS semaphore attributes + * 4. OSAL Counting Semaphore attributes + * This is a counting semaphore with priority wait order. + */ + +#define OSAL_COUNT_SEM_ATTRIBS (RTEMS_PRIORITY) + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +/* tables for the properties of objects */ +OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_CountSemAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_CountSemAPI_Impl_Init(void) +{ + memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); + return (OS_SUCCESS); +} /* end OS_Rtems_CountSemAPI_Impl_Init */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) +{ + rtems_status_code status; + rtems_name r_name; + + /* + ** Verify that the semaphore maximum value is not too high + */ + if ( sem_initial_value > MAX_SEM_VALUE ) + { + return OS_INVALID_SEM_VALUE; + } + + /* + ** RTEMS task names are 4 byte integers. + ** It is convenient to use the OSAL ID in here, as we know it is already unique + ** and trying to use the real name would be less than useful (only 4 chars) + */ + r_name = OS_global_count_sem_table[sem_id].active_id; + status = rtems_semaphore_create( r_name, sem_initial_value, + OSAL_COUNT_SEM_ATTRIBS, + 0, + &(OS_impl_count_sem_table[sem_id].id)); + + /* check if Create failed */ + if ( status != RTEMS_SUCCESSFUL ) + { + OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemDelete_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_delete( OS_impl_count_sem_table[sem_id].id); + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGive_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_release(OS_impl_count_sem_table[sem_id].id); + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return(OS_SUCCESS); + +} /* end OS_CountSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTake_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemTake_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs) +{ + rtems_status_code status; + uint32 TimeInTicks; + + TimeInTicks = OS_Milli2Ticks(msecs); + + status = rtems_semaphore_obtain(OS_impl_count_sem_table[sem_id].id, RTEMS_WAIT, TimeInTicks); + if (status == RTEMS_TIMEOUT) + { + return OS_SEM_TIMEOUT; + } + + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_CountSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) +{ + /* RTEMS does not provide an API to get the value */ + return OS_SUCCESS; + +} /* end OS_CountSemGetInfo_Impl */ + diff --git a/src/os/rtems/src/os-impl-dirs.c b/src/os/rtems/src/os-impl-dirs.c new file mode 100644 index 000000000..41d2e4052 --- /dev/null +++ b/src/os/rtems/src/os-impl-dirs.c @@ -0,0 +1,64 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + +#include +#include +#include + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + +/* + * The directory handle table. + */ +DIR *OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + +/* -------------------------------------------------------------------------------------- + Name: OS_Rtems_DirAPI_Impl_Init + + Purpose: Directory table initialization + + Returns: OS_SUCCESS if success + ---------------------------------------------------------------------------------------*/ +int32 OS_Rtems_DirAPI_Impl_Init(void) +{ + memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); + return OS_SUCCESS; +} /* end OS_Rtems_DirAPI_Impl_Init */ + + diff --git a/src/os/rtems/src/os-impl-files.c b/src/os/rtems/src/os-impl-files.c new file mode 100644 index 000000000..fa080c111 --- /dev/null +++ b/src/os/rtems/src/os-impl-files.c @@ -0,0 +1,74 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-files.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + + +/**************************************************************************************** + GLOBALS + ***************************************************************************************/ + +/* + * The global file handle table. + * + * This is shared by all OSAL entities that perform low-level I/O. + */ +/* The file/stream table is referenced by multiple entities, i.e. sockets, select, etc */ +OS_Rtems_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + +/* -------------------------------------------------------------------------------------- + Name: OS_Rtems_StreamAPI_Impl_Init + + Purpose: File/Stream subsystem global initialization + + Returns: OS_SUCCESS if success + ---------------------------------------------------------------------------------------*/ +int32 OS_Rtems_StreamAPI_Impl_Init(void) +{ + uint32 local_id; + + /* + * init all filehandles to -1, which is always invalid. + * this isn't strictly necessary but helps when debugging. + */ + for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) + { + OS_impl_filehandle_table[local_id].fd = -1; + } + + return OS_SUCCESS; +} /* end OS_Rtems_StreamAPI_Impl_Init */ + diff --git a/src/os/rtems/osfilesys.c b/src/os/rtems/src/os-impl-filesys.c similarity index 94% rename from src/os/rtems/osfilesys.c rename to src/os/rtems/src/os-impl-filesys.c index ce34bd0e7..e561af01f 100644 --- a/src/os/rtems/osfilesys.c +++ b/src/os/rtems/src/os-impl-filesys.c @@ -1,19 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osfilesys.c - * \author joseph.p.hickey@nasa.gov + * \file os-impl-filesys.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov * - * Purpose: This file has the apis for all of the making - * and mounting type of calls for file systems */ /**************************************************************************************** @@ -93,7 +95,7 @@ int32 OS_Rtems_FileSysAPI_Impl_Init(void) } /* end OS_Rtems_FileSysAPI_Impl_Init */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStartVolume_Impl @@ -203,7 +205,7 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) } /* end OS_FileSysStartVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStopVolume_Impl @@ -219,7 +221,7 @@ int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) } /* end OS_FileSysStopVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysFormatVolume_Impl @@ -283,7 +285,7 @@ int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) } /* end OS_FileSysFormatVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysMountVolume_Impl @@ -333,7 +335,7 @@ int32 OS_FileSysMountVolume_Impl (uint32 filesys_id) } /* end OS_FileSysMountVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysUnmountVolume_Impl @@ -359,7 +361,7 @@ int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id) } /* end OS_FileSysUnmountVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStatVolume_Impl @@ -386,7 +388,7 @@ int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) } /* end OS_FileSysStatVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysCheckVolume_Impl diff --git a/src/os/rtems/src/os-impl-fpu.c b/src/os/rtems/src/os-impl-fpu.c new file mode 100644 index 000000000..5990c6c63 --- /dev/null +++ b/src/os/rtems/src/os-impl-fpu.c @@ -0,0 +1,114 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-fpu.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + +/**************************************************************************************** + FPU API (deprecated) + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, + int32 parameter) +{ + /* + ** Not implemented in RTEMS. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcAttachHandler_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in RTEMS. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcEnable_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in RTEMS. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcSetMask_Impl(uint32 mask) +{ + /* + ** Not implemented in RTEMS. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcGetMask_Impl(uint32 *mask) +{ + /* + ** Not implemented in RTEMS. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcGetMask_Impl */ + diff --git a/src/os/rtems/src/os-impl-heap.c b/src/os/rtems/src/os-impl-heap.c new file mode 100644 index 000000000..ac39e4a9d --- /dev/null +++ b/src/os/rtems/src/os-impl-heap.c @@ -0,0 +1,59 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-heap.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + + +/**************************************************************************************** + HEAP API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_HeapGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_HeapGetInfo_Impl (OS_heap_prop_t *heap_prop) +{ + region_information_block info; + int status; + + status = malloc_info( &info ); + + if ( status != 0 ) + { + return(OS_ERROR); + } + + heap_prop->free_bytes = (uint32) info.Free.total; + heap_prop->free_blocks = (uint32) info.Free.number; + heap_prop->largest_free_block = (uint32) info.Free.largest; + + return (OS_SUCCESS); +} /* end OS_HeapGetInfo_Impl */ + diff --git a/src/os/rtems/src/os-impl-interrupts.c b/src/os/rtems/src/os-impl-interrupts.c new file mode 100644 index 000000000..29361a24d --- /dev/null +++ b/src/os/rtems/src/os-impl-interrupts.c @@ -0,0 +1,181 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-interrupts.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" + +/**************************************************************************************** + INT API (deprecated) + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) +{ +#if (CPU_SIMPLE_VECTORED_INTERRUPTS == false) + return OS_ERR_NOT_IMPLEMENTED; +#else + rtems_status_code ret_status; + uint32 status ; + rtems_isr_entry old_handler; + + ret_status = rtems_interrupt_catch( + (rtems_isr_entry)InterruptHandler, + (rtems_vector_number)InterruptNumber, + &old_handler); + + switch (ret_status) + { + case RTEMS_SUCCESSFUL : + status = OS_SUCCESS; + break ; + + case RTEMS_INVALID_NUMBER : + status = OS_INVALID_INT_NUM; + break ; + + case RTEMS_INVALID_ADDRESS : + status = OS_INVALID_POINTER; + break ; + + default : + status = OS_ERROR; + break ; + } + return(status) ; +#endif +} /* end OS_IntAttachHandler_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_IntUnlock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntUnlock_Impl (int32 IntLevel) +{ + rtems_interrupt_level rtems_int_level = IntLevel; + rtems_interrupt_local_enable ( rtems_int_level ); + return (OS_SUCCESS); + +} /* end OS_IntUnlock_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntLock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntLock_Impl (void) +{ + rtems_interrupt_level rtems_int_level; + + /* + * NOTE: rtems_interrupt_local_disable() is a macro + * that sets the rtems_int_level value. + * + * This code assumes that the value is also storable + * in an int32. + * + * This uses the "local" version which operates on + * the current CPU in case of a multi-processor environment. + * + * This should be identical to rtems_interrupt_disable in + * a single-processor config, but that call is not + * implemented in multi-processor configs. + */ + rtems_interrupt_local_disable(rtems_int_level) ; + return ( (int32) rtems_int_level) ; + +} /* end OS_IntLock_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_IntEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntEnable_Impl (int32 Level) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntEnable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntDisable_Impl (int32 Level) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) +{ + *MaskSettingPtr = 0; + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntGetMask_Impl */ + diff --git a/src/os/rtems/osloader.c b/src/os/rtems/src/os-impl-loader.c similarity index 56% rename from src/os/rtems/osloader.c rename to src/os/rtems/src/os-impl-loader.c index 0de68fc48..e4eb5925d 100644 --- a/src/os/rtems/osloader.c +++ b/src/os/rtems/src/os-impl-loader.c @@ -1,20 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osloader.c - * \author joseph.p.hickey@nasa.gov + * \file os-impl-loader.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov * - * Purpose: This file contains the module loader and symbol lookup functions for the OSAL. - * RTEMS uses the POSIX-style "dl" implementation (even if the rest of the POSIX API - * is disabled). */ /**************************************************************************************** @@ -24,44 +25,19 @@ #define _USING_RTEMS_INCLUDES_ #include "os-rtems.h" -#include - -#include -#include - +#include "os-impl-loader.h" /**************************************************************************************** GLOBAL DATA ***************************************************************************************/ -/* - * A local lookup table for posix-specific information. - * This is not directly visible to the outside world. - */ -typedef struct -{ - /* cppcheck-suppress unusedStructMember */ - void *dl_handle; -} OS_impl_module_internal_record_t; - -/* - * The storage table is only instantiated when OS_MAX_MODULES is nonzero. - * It is allowed to be zero to save memory in statically linked apps. - * However even in that case it is still relevant to include the - * OS_SymbolLookup_Impl() function for symbol lookups. - * - * If neither loading nor symbol lookups are desired then this file - * shouldn't be used at all -- a no-op version should be used instead. - */ -#if (OS_MAX_MODULES > 0) OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; -#endif /**************************************************************************************** INITIALIZATION FUNCTION ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_Rtems_ModuleAPI_Impl_Init @@ -71,95 +47,10 @@ OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; *-----------------------------------------------------------------*/ int32 OS_Rtems_ModuleAPI_Impl_Init(void) { -#if (OS_MAX_MODULES > 0) memset(OS_impl_module_table, 0, sizeof(OS_impl_module_table)); -#endif return(OS_SUCCESS); } /* end OS_Rtems_ModuleAPI_Impl_Init */ -/**************************************************************************************** - Symbol table API - ***************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_SymbolLookup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) -{ - int32 status; - const char *dlError; - void *Function; - - /* - * call dlerror() to clear any prior error that might have occured. - */ - dlerror(); - Function = dlsym(RTLD_DEFAULT, SymbolName); - dlError = dlerror(); - - /* - * For the POSIX DL implementation, if the symbol does not exist - * then dlerror() is supposed to return non-null. This is intended - * to differentiate between valid symbols which are actually 0/NULL - * and invalid symbols that do not exist. - * - * RTEMS does _not_ seem to implement this detail, and dlerror() - * still returns NULL after looking up an invalid symbol name. - * - * In practice, all valid symbols should be non-NULL anyway, - * so we check both here. - */ - - if( dlError == NULL && Function != NULL ) - { - /* considered successful if no error is present - - * note the address itself is allowed to be NULL */ - *SymbolAddress = (cpuaddr)Function; - status = OS_SUCCESS; - } - else - { - *SymbolAddress = 0; - status = OS_ERROR; - } - - return status; - -} /* end OS_SymbolLookup_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_SymbolTableDump_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) -{ - - return(OS_ERR_NOT_IMPLEMENTED); - -} /* end OS_SymbolTableDump_Impl */ - - - -/**************************************************************************************** - Module Loader API - ***************************************************************************************/ - -/* - * NOTE: The module loading functions are only compiled of OS_MAX_MODULES is >0 - * Otherwise stubs will be compiled in place of these (see below) - */ - -#if (OS_MAX_MODULES > 0) && defined(OS_INCLUDE_MODULE_LOADER) /**************************************************************************************** HELPER ROUTINES @@ -197,7 +88,11 @@ static bool OS_rtems_rtl_check_unresolved (rtems_rtl_unresolv_rec_t* rec, } /* end OS_rtems_rtl_check_unresolved */ - +/**************************************************************************************** + Module Loader API + ***************************************************************************************/ + + /*---------------------------------------------------------------- * * Function: OS_ModuleLoad_Impl @@ -272,7 +167,7 @@ int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ) } /* end OS_ModuleLoad_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_ModuleUnload_Impl @@ -304,40 +199,6 @@ int32 OS_ModuleUnload_Impl ( uint32 module_id ) } /* end OS_ModuleUnload_Impl */ - - -#else - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleLoad_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ) -{ - return OS_SUCCESS; -} /* end OS_ModuleLoad_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleUnload_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl ( uint32 module_id ) -{ - return OS_SUCCESS; -} /* end OS_ModuleUnload_Impl */ - -#endif - - /*---------------------------------------------------------------- * * Function: OS_ModuleGetInfo_Impl diff --git a/src/os/rtems/src/os-impl-mutex.c b/src/os/rtems/src/os-impl-mutex.c new file mode 100644 index 000000000..e66741404 --- /dev/null +++ b/src/os/rtems/src/os-impl-mutex.c @@ -0,0 +1,200 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-mutex.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + + +/* + * Define all of the RTEMS semaphore attributes + * In RTEMS, a MUTEX is defined as a binary semaphore + * It allows nested locks, priority wait order, and supports priority inheritance + */ + +#define OSAL_MUTEX_ATTRIBS (RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY) + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +/* Tables where the OS object information is stored */ +OS_impl_mutex_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + + +/**************************************************************************************** + MUTEX API + ***************************************************************************************/ + + + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_MutexAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_MutexAPI_Impl_Init(void) +{ + memset(OS_impl_mutex_table, 0, sizeof(OS_impl_mutex_table)); + return (OS_SUCCESS); +} /* end OS_Rtems_MutexAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) +{ + rtems_status_code status; + rtems_name r_name; + + /* + ** Try to create the mutex + */ + r_name = OS_global_mutex_table[sem_id].active_id; + status = rtems_semaphore_create ( r_name, 1, + OSAL_MUTEX_ATTRIBS , + 0, + &OS_impl_mutex_table[sem_id].id ); + + if ( status != RTEMS_SUCCESSFUL ) + { + OS_DEBUG("Unhandled semaphore_create error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_MutSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemDelete_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_delete( OS_impl_mutex_table[sem_id].id); + if (status != RTEMS_SUCCESSFUL) + { + /* clean up? */ + OS_DEBUG("Unhandled semaphore_delete error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_MutSemDelete_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGive_Impl (uint32 sem_id) +{ + rtems_status_code status; + + /* Give the mutex */ + status = rtems_semaphore_release(OS_impl_mutex_table[sem_id].id); + + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_release error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_MutSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemTake_Impl (uint32 sem_id) +{ + rtems_status_code status; + + status = rtems_semaphore_obtain(OS_impl_mutex_table[sem_id].id, RTEMS_WAIT, RTEMS_NO_TIMEOUT); + + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled semaphore_obtain error: %s\n",rtems_status_text(status)); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; + +} /* end OS_MutSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) +{ + /* RTEMS provides no additional info */ + return OS_SUCCESS; + +} /* end OS_MutSemGetInfo_Impl */ + diff --git a/src/os/rtems/src/os-impl-network.c b/src/os/rtems/src/os-impl-network.c new file mode 100644 index 000000000..a288001f4 --- /dev/null +++ b/src/os/rtems/src/os-impl-network.c @@ -0,0 +1,75 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-network.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-sockets.h" + + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetID_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetID_Impl (int32 *IdBuf) +{ + /* RTEMS does not have the GetHostId call - + * it is deprecated in other OS's anyway and not a good idea to use it + */ + return OS_ERR_NOT_IMPLEMENTED; +} /* end OS_NetworkGetID_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetHostName_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) +{ + int32 return_code; + + if ( gethostname(host_name, name_len) < 0 ) + { + return_code = OS_ERROR; + } + else + { + /* + * posix does not say that the name is always + * null terminated, so its worthwhile to ensure it + */ + host_name[name_len - 1] = 0; + return_code = OS_SUCCESS; + } + + return(return_code); +} /* end OS_NetworkGetHostName_Impl */ + + diff --git a/src/os/rtems/src/os-impl-no-module.c b/src/os/rtems/src/os-impl-no-module.c new file mode 100644 index 000000000..5c9314862 --- /dev/null +++ b/src/os/rtems/src/os-impl-no-module.c @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-no-module.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#define _USING_RTEMS_INCLUDES_ + +#include "os-rtems.h" + + +/**************************************************************************************** + INITIALIZATION FUNCTION + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_ModuleAPI_Impl_Init(void) +{ + /* nothing to init, but needs to return SUCCESS to allow the rest of OSAL to work */ + return(OS_SUCCESS); +} /* end OS_Rtems_ModuleAPI_Impl_Init */ + + diff --git a/src/os/rtems/src/os-impl-queues.c b/src/os/rtems/src/os-impl-queues.c new file mode 100644 index 000000000..374909771 --- /dev/null +++ b/src/os/rtems/src/os-impl-queues.c @@ -0,0 +1,291 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-queues.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +/* Tables where the OS object information is stored */ +OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + + +/**************************************************************************************** + MESSAGE QUEUE API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_QueueAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_QueueAPI_Impl_Init(void) +{ + memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); + return (OS_SUCCESS); +} /* end OS_Rtems_QueueAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) +{ + rtems_status_code status; + rtems_name r_name; + + + /* + ** RTEMS task names are 4 byte integers. + ** It is convenient to use the OSAL queue ID in here, as we know it is already unique + ** and trying to use the real queue name would be less than useful (only 4 chars) + */ + r_name = OS_global_queue_table[queue_id].active_id; + + /* + ** Create the message queue. + ** The queue attributes are set to default values; the waiting order + ** (RTEMS_FIFO or RTEMS_PRIORITY) is irrelevant since only one task waits + ** on each queue. + */ + status = rtems_message_queue_create( + r_name, /* 32-bit RTEMS object name; not used */ + OS_queue_table[queue_id].max_depth, /* maximum number of messages in queue (queue depth) */ + OS_queue_table[queue_id].max_size, /* maximum size in bytes of a message */ + RTEMS_FIFO|RTEMS_LOCAL, /* attributes (default) */ + &(OS_impl_queue_table[queue_id].id) /* object ID returned for queue */ + ); + + /* + ** If the operation failed, report the error + */ + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled queue_create error: %s\n",rtems_status_text(status)); + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_QueueCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueDelete_Impl (uint32 queue_id) +{ + rtems_status_code status; + + /* Try to delete the queue */ + status = rtems_message_queue_delete(OS_impl_queue_table[queue_id].id); + if(status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled queue_delete error: %s\n",rtems_status_text(status)); + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_QueueDelete_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueGet_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, + int32 timeout) +{ + int32 return_code; + rtems_status_code status; + rtems_interval ticks; + rtems_option option_set; + size_t rtems_size; + rtems_id rtems_queue_id; + + rtems_queue_id = OS_impl_queue_table[queue_id].id; + + /* Get Message From Message Queue */ + if (timeout == OS_PEND) + { + option_set = RTEMS_WAIT; + ticks = RTEMS_NO_TIMEOUT; + } + else if (timeout == OS_CHECK) + { + option_set = RTEMS_NO_WAIT; + ticks = RTEMS_NO_TIMEOUT; + } + else + { + option_set = RTEMS_WAIT; + /* msecs rounded to the closest system tick count */ + ticks = OS_Milli2Ticks(timeout); + } + + /* + ** Pend until a message arrives. + */ + status = rtems_message_queue_receive( + rtems_queue_id, /* message queue descriptor */ + data, /* pointer to message buffer */ + &rtems_size, /* returned size of message */ + option_set, /* wait option */ + ticks /* timeout */ + ); + + if (status == RTEMS_SUCCESSFUL) + { + return_code = OS_SUCCESS; + } + else if (status == RTEMS_TIMEOUT) + { + return_code = OS_QUEUE_TIMEOUT; + } + else if (status == RTEMS_UNSATISFIED) + { + return_code = OS_QUEUE_EMPTY; + } + else + { + /* Something else went wrong */ + return_code = OS_ERROR; + OS_DEBUG("Unhandled queue_receive error: %s\n",rtems_status_text(status)); + } + + /* + ** Check the size of the message. If a valid message was + ** obtained, indicate success. + */ + if (status == RTEMS_SUCCESSFUL) + { + *size_copied = rtems_size; + if (rtems_size != size) + { + /* Success, but the size was wrong */ + return_code = OS_QUEUE_INVALID_SIZE; + } + } + else + { + *size_copied = 0; + } + + return return_code; +} /* end OS_QueueGet_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueuePut_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) +{ + rtems_status_code status; + rtems_id rtems_queue_id; + + rtems_queue_id = OS_impl_queue_table[queue_id].id; + + /* Write the buffer pointer to the queue. If an error occurred, report it + ** with the corresponding SB status code. + */ + status = rtems_message_queue_send( + rtems_queue_id, /* message queue descriptor */ + data, /* pointer to message */ + size /* length of message */ + ); + + if (status == RTEMS_TOO_MANY) + { + /* + ** Queue is full. + */ + return OS_QUEUE_FULL; + } + + if (status != RTEMS_SUCCESSFUL) + { + /* + ** Unexpected error while writing to queue. + */ + OS_DEBUG("Unhandled queue_send error: %s\n",rtems_status_text(status)); + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_QueuePut_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) +{ + /* No extra info for queues in the OS implementation */ + return OS_SUCCESS; + +} /* end OS_QueueGetInfo_Impl */ + diff --git a/src/os/rtems/src/os-impl-shell.c b/src/os/rtems/src/os-impl-shell.c new file mode 100644 index 000000000..4a9ff6664 --- /dev/null +++ b/src/os/rtems/src/os-impl-shell.c @@ -0,0 +1,85 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-shell.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-files.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +#define OS_REDIRECTSTRSIZE 15 + + + +/**************************************************************************************** + IMPLEMENTATION-SPECIFIC ROUTINES + These are specific to this particular operating system + ****************************************************************************************/ + +/* FIXME - need to do something better here */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ShellOutputToFile_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +{ + /* + ** this is a #define to avoid a 'variable length array' warning + ** 15 is for the size of the redirection string that is added + ** to the command + */ + char LocalCmd [OS_MAX_CMD_LEN + OS_REDIRECTSTRSIZE]; + int32 Result; + + strncpy(LocalCmd,Cmd,OS_MAX_CMD_LEN +OS_REDIRECTSTRSIZE); + + /* Make sure that we are able to access this file */ + fchmod(OS_impl_filehandle_table[file_id].fd, 0666); + + /* + ** add in the extra chars necessary to perform the redirection + ** 1 for stdout and 2 for stderr. they are redirected to the + ** file descriptor passed in + */ + snprintf(LocalCmd, sizeof(LocalCmd), "%s 1>&%d 2>&%d", + Cmd, + OS_impl_filehandle_table[file_id].fd, + OS_impl_filehandle_table[file_id].fd); + + Result = system(LocalCmd); + + if (Result != 0) + { + return OS_FS_ERROR; + } + return OS_SUCCESS; +} /* end OS_ShellOutputToFile_Impl */ + diff --git a/src/os/rtems/src/os-impl-tasks.c b/src/os/rtems/src/os-impl-tasks.c new file mode 100644 index 000000000..cf5d36fa3 --- /dev/null +++ b/src/os/rtems/src/os-impl-tasks.c @@ -0,0 +1,333 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov + * + * This file contains some of the OS APIs abstraction layer for RTEMS + * This has been tested against the current RTEMS 4.11 release branch + * + * NOTE: This uses only the "Classic" RTEMS API. It is intended to + * work on RTEMS targets that do not provide the POSIX API, i.e. + * when "--disable-posix" is given during the configuration stage. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-rtems.h" +#include "os-impl-tasks.h" + +/**************************************************************************************** + DEFINES + ***************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ +/* Tables where the OS object information is stored */ +OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + + +/*--------------------------------------------------------------------------------------- + Name: OS_RtemsEntry + + Purpose: A Simple RTEMS-compatible entry point that calls the common task entry function + + NOTES: This wrapper function is only used locally by OS_TaskCreate below + +---------------------------------------------------------------------------------------*/ +static rtems_task OS_RtemsEntry(rtems_task_argument arg) +{ + OS_TaskEntryPoint((uint32)arg); +} /* end OS_RtemsEntry */ + + + +/**************************************************************************************** + TASK API + ***************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_Rtems_TaskAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_Rtems_TaskAPI_Impl_Init(void) +{ + memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); + return (OS_SUCCESS); +} /* end OS_Rtems_TaskAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) +{ + rtems_status_code status; + rtems_name r_name; + rtems_mode r_mode; + rtems_attribute r_attributes; + + /* + ** RTEMS task names are 4 byte integers. + ** It is convenient to use the OSAL task ID in here, as we know it is already unique + ** and trying to use the real task name would be less than useful (only 4 chars) + */ + r_name = OS_global_task_table[task_id].active_id; + r_mode = RTEMS_PREEMPT | RTEMS_NO_ASR | RTEMS_NO_TIMESLICE | RTEMS_INTERRUPT_LEVEL(0); + + /* + ** see if the user wants floating point enabled. If + ** so, then set the correct option. + */ + r_attributes = RTEMS_LOCAL; + if (flags & OS_FP_ENABLED) + { + r_attributes |= RTEMS_FLOATING_POINT; + } + + status = rtems_task_create( + r_name, + OS_task_table[task_id].priority, + OS_task_table[task_id].stack_size, + r_mode, + r_attributes, + &OS_impl_task_table[task_id].id); + + /* check if task_create failed */ + if (status != RTEMS_SUCCESSFUL ) + { + /* Provide some freedback as to why this failed */ + OS_printf("rtems_task_create failed: %s\n", rtems_status_text(status)); + return OS_ERROR; + } + + /* will place the task in 'ready for scheduling' state */ + status = rtems_task_start (OS_impl_task_table[task_id].id, /*rtems task id*/ + (rtems_task_entry) OS_RtemsEntry, /* task entry point */ + (rtems_task_argument) OS_global_task_table[task_id].active_id ); /* passed argument */ + + if (status != RTEMS_SUCCESSFUL ) + { + OS_printf("rtems_task_start failed: %s\n", rtems_status_text(status)); + rtems_task_delete(OS_impl_task_table[task_id].id); + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_TaskCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelete_Impl (uint32 task_id) +{ + /* + ** Try to delete the task + ** If this fails, not much recourse - the only potential cause of failure + ** to cancel here is that the thread ID is invalid because it already exited itself, + ** and if that is true there is nothing wrong - everything is OK to continue normally. + */ + + rtems_task_delete(OS_impl_task_table[task_id].id); + return OS_SUCCESS; +} /* end OS_TaskDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskExit_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_TaskExit_Impl() +{ + rtems_task_delete(RTEMS_SELF); + +} /* end OS_TaskExit_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelay_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelay_Impl (uint32 milli_second) +{ + rtems_interval ticks; + + ticks = OS_Milli2Ticks(milli_second); + + rtems_task_wake_after(ticks); + /* + ** Always successful ( from RTEMS docs ) + */ + return (OS_SUCCESS); + +} /* end OS_TaskDelay_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskSetPriority_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) +{ + rtems_task_priority old_pri; + rtems_status_code status; + + /* Set RTEMS Task Priority */ + status = rtems_task_set_priority(OS_impl_task_table[task_id].id, new_priority, &old_pri); + if (status != RTEMS_SUCCESSFUL) + { + OS_DEBUG("Unhandled task_set_priority error: %s\n",rtems_status_text(status)); + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_TaskSetPriority_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskMatch_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskMatch_Impl(uint32 task_id) +{ + /* + ** Get RTEMS Task Id + */ + if ( rtems_task_self() != OS_impl_task_table[task_id].id ) + { + return(OS_ERROR); + } + + + return OS_SUCCESS; +} /* end OS_TaskMatch_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskRegister_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskRegister_Impl (uint32 global_task_id) +{ + /* + * This is supposed to maintain the "reverse lookup" information used + * to map an RTEMS task ID back into an OSAL ID. + * + * Originally this used "task variables" which got deprecated. + * So this changed to "task notes" which are also now deprecated in 4.11. + * + * So there is now no documented per-task thread local storage facility in RTEMS + * with these two options gone. RTEMS does seem to have TLS, but there is just + * no published (non-deprecated) API to access it. + * + * Right now this does nothing and the OS_TaskGetId() must brute-force it. + * + * An alternative for performance improvements might be to use a locally maintained + * hash table here. + */ + return OS_SUCCESS; + +} /* end OS_TaskRegister_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetId_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +uint32 OS_TaskGetId_Impl (void) +{ + uint32 global_task_id; + rtems_id task_self; + rtems_name self_name; + rtems_status_code status; + + task_self = rtems_task_self(); + /* When the task was created the OSAL ID was used as the "classic name", + * which gives us an easy way to map it back again */ + status = rtems_object_get_classic_name(task_self, &self_name); + if (status == RTEMS_SUCCESSFUL) + { + global_task_id = self_name; + } + else + { + global_task_id = 0; + } + + return global_task_id; + +} /* end OS_TaskGetId_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) +{ + task_prop->OStask_id = (uint32) OS_impl_task_table[task_id].id; + return OS_SUCCESS; + +} /* end OS_TaskGetInfo_Impl */ + + diff --git a/src/os/rtems/ostimer.c b/src/os/rtems/src/os-impl-timebase.c similarity index 94% rename from src/os/rtems/ostimer.c rename to src/os/rtems/src/os-impl-timebase.c index e966d29f0..78ace4c8d 100644 --- a/src/os/rtems/ostimer.c +++ b/src/os/rtems/src/os-impl-timebase.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file ostimer.c - * \author joseph.p.hickey@nasa.gov + * \file os-impl-timebase.c + * \ingroup rtems + * \author joseph.p.hickey@nasa.gov * - * Purpose: This file contains the OSAL Timer API for RTEMS */ /**************************************************************************************** @@ -72,7 +75,7 @@ typedef struct ***************************************************************************************/ OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseLock_Impl @@ -85,7 +88,7 @@ void OS_TimeBaseLock_Impl(uint32 local_id) { rtems_semaphore_obtain(OS_impl_timebase_table[local_id].handler_mutex, RTEMS_WAIT, RTEMS_NO_TIMEOUT); } /* end OS_TimeBaseLock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseUnlock_Impl @@ -99,7 +102,7 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) rtems_semaphore_release(OS_impl_timebase_table[local_id].handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBase_ISR @@ -140,7 +143,7 @@ static rtems_timer_service_routine OS_TimeBase_ISR(rtems_id rtems_timer_id, void } /* end OS_TimeBase_ISR */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBase_WaitImpl @@ -186,7 +189,7 @@ static uint32 OS_TimeBase_WaitImpl(uint32 local_id) /**************************************************************************************** INITIALIZATION FUNCTION ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_Rtems_TimeBaseAPI_Impl_Init @@ -274,7 +277,7 @@ void OS_UsecsToTicks(uint32 usecs, rtems_interval *ticks) /* The user may specify whether to use priority inheritance on mutexes via osconfig.h */ #define OSAL_TIMEBASE_MUTEX_ATTRIBS RTEMS_PRIORITY | RTEMS_BINARY_SEMAPHORE | RTEMS_INHERIT_PRIORITY - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseCreate_Impl @@ -404,7 +407,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) return return_code; } /* end OS_TimeBaseCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseSet_Impl @@ -511,7 +514,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } /* end OS_TimeBaseSet_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseDelete_Impl @@ -576,7 +579,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) return return_code; } /* end OS_TimeBaseDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetInfo_Impl @@ -591,10 +594,3 @@ int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) } /* end OS_TimeBaseGetInfo_Impl */ -/**************************************************************************************** - Other Time-Related API Implementation - ***************************************************************************************/ - -/* RTEMS implements POSIX-style clock_gettime and clock_settime calls */ -#include "../portable/os-impl-posix-gettime.c" - diff --git a/src/os/shared/inc/osapi-binsem-impl.h b/src/os/shared/inc/osapi-binsem-impl.h new file mode 100644 index 000000000..80f4bf897 --- /dev/null +++ b/src/os/shared/inc/osapi-binsem-impl.h @@ -0,0 +1,123 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-binsem.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_BINSEM_H_ +#define INCLUDE_OSAPI_BINSEM_H_ + +#include + +/* other objects that have only an API name and no other data */ +typedef struct +{ + char obj_name[OS_MAX_API_NAME]; +} OS_bin_sem_internal_record_t; + + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_bin_sem_internal_record_t OS_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; + +/**************************************************************************************** + SEMAPHORE API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_BinSemAPI_Init + + Purpose: Initialize the OS-independent layer for binary semaphores + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_BinSemAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_BinSemCreate_Impl + + Purpose: Prepare/allocate OS resources for a binary semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options); + +/*---------------------------------------------------------------- + Function: OS_BinSemFlush_Impl + + Purpose: Unblock all tasks waiting on the binary semaphore. + Does not change the semaphore value. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemFlush_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_BinSemGive_Impl + + Purpose: Release the semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemGive_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_BinSemTake_Impl + + Purpose: Acquire the semaphore + Block the calling task if the semaphore is 0. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemTake_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_BinSemTimedWait_Impl + + Purpose: Acquire the semaphore, with a time limit + + Returns: OS_SUCCESS on success, or relevant error code + OS_SEM_TIMEOUT must be returned if the time limit was reached + ------------------------------------------------------------------*/ +int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs); + +/*---------------------------------------------------------------- + Function: OS_BinSemDelete_Impl + + Purpose: Free the OS resources associated with the binary semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemDelete_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_BinSemGetInfo_Impl + + Purpose: Obtain OS-specific information about the semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop); + + + +#endif /* INCLUDE_OSAPI_BINSEM_H_ */ + diff --git a/src/os/shared/inc/osapi-clock-impl.h b/src/os/shared/inc/osapi-clock-impl.h new file mode 100644 index 000000000..5dc220815 --- /dev/null +++ b/src/os/shared/inc/osapi-clock-impl.h @@ -0,0 +1,52 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-clock.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_CLOCK_H_ +#define INCLUDE_OSAPI_CLOCK_H_ + +#include + + +/* + * Clock API low-level handlers + * These simply get/set the kernel RTC (if it has one) + */ + +/*---------------------------------------------------------------- + Function: OS_GetLocalTime_Impl + + Purpose: Get the time from the RTC + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_GetLocalTime_Impl(OS_time_t *time_struct); + +/*---------------------------------------------------------------- + Function: OS_SetLocalTime_Impl + + Purpose: Set the time in the RTC + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct); + + +#endif /* INCLUDE_OSAPI_CLOCK_H_ */ + diff --git a/src/os/shared/inc/osapi-common-impl.h b/src/os/shared/inc/osapi-common-impl.h new file mode 100644 index 000000000..a74cce39f --- /dev/null +++ b/src/os/shared/inc/osapi-common-impl.h @@ -0,0 +1,120 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-common.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_COMMON_H_ +#define INCLUDE_OSAPI_COMMON_H_ + +#include + +/* + * A "magic number" that when written to the "ShutdownFlag" member + * of the global state structure indicates an active shutdown request. + */ +#define OS_SHUTDOWN_MAGIC_NUMBER 0xABADC0DE + + + +/* Global variables that are common between implementations */ +struct OS_shared_global_vars +{ + bool Initialized; + + /* + * The console device ID used for OS_printf() calls + */ + uint32 PrintfConsoleId; + + /* + * PrintfEnabled and ShutdownFlag are marked "volatile" + * because they are updated and read by different threads + */ + volatile bool PrintfEnabled; + volatile uint32 ShutdownFlag; + int32 MicroSecPerTick; + int32 TicksPerSecond; + +#ifdef OSAL_CONFIG_DEBUG_PRINTF + uint8 DebugLevel; +#endif + +}; + + +/* + * Shared data structure for global values + */ +extern OS_SharedGlobalVars_t OS_SharedGlobalVars; + +/*--------------------------------------------------------------------------------------- + Name: OS_API_Impl_Init + + Purpose: Initialize the OS-specific layer for the given object type + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_API_Impl_Init (uint32 idtype); + + + +/* + * This functions implement a the OS-specific portion + * of various OSAL functions. They are defined in + * OS-specific source files. + */ + + +/*---------------------------------------------------------------- + + Function: OS_IdleLoop_Impl + + Purpose: Block the "idle" thread until woken up + + The "IdleLoop_Impl" is called by the main thread once + everything is running and there is no more work to do. + + It should suspend the calling thread until a wakeup + event happens. + + ------------------------------------------------------------------*/ +void OS_IdleLoop_Impl (void); + +/*---------------------------------------------------------------- + + Function: OS_ApplicationShutdown_Impl + + Purpose: Wake up the idle task + + The "ApplicationShutdown_Impl" should wake up whatever + task is currently suspended in "IdleLoop_Impl" and cause + that thread to resume and return to its caller. + + NOTE: This should not block but it may cause the current + thread to be preempted by the thread that was woken up, + depending on priority levels. + + ------------------------------------------------------------------*/ +void OS_ApplicationShutdown_Impl (void); + + + + + +#endif /* INCLUDE_OSAPI_COMMON_H_ */ + diff --git a/src/os/shared/inc/osapi-countsem-impl.h b/src/os/shared/inc/osapi-countsem-impl.h new file mode 100644 index 000000000..7035398fd --- /dev/null +++ b/src/os/shared/inc/osapi-countsem-impl.h @@ -0,0 +1,113 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-countsem.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_COUNTSEM_H_ +#define INCLUDE_OSAPI_COUNTSEM_H_ + +#include + + +/* other objects that have only an API name and no other data */ +typedef struct +{ + char obj_name[OS_MAX_API_NAME]; +} OS_count_sem_internal_record_t; + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_count_sem_internal_record_t OS_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; + +/**************************************************************************************** + IMPLEMENTATION FUNCTIONS + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_CountSemAPI_Init + + Purpose: Initialize the OS-independent layer for counting semaphores + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_CountSemAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_CountSemCreate_Impl + + Purpose: Prepare/allocate OS resources for a counting semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options); + +/*---------------------------------------------------------------- + Function: OS_CountSemGive_Impl + + Purpose: Increment the semaphore value + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CountSemGive_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_CountSemTake_Impl + + Purpose: Decrement the semaphore value + Block the calling task if the semaphore is 0. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CountSemTake_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_CountSemTimedWait_Impl + + Purpose: Decrement the semaphore value, with a time limit + + Returns: OS_SUCCESS on success, or relevant error code + OS_SEM_TIMEOUT must be returned if the time limit was reached + ------------------------------------------------------------------*/ +int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs); + +/*---------------------------------------------------------------- + Function: OS_CountSemDelete_Impl + + Purpose: Free the OS resources associated with the counting semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CountSemDelete_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_CountSemGetInfo_Impl + + Purpose: Obtain OS-specific information about the semaphore + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop); + + + +#endif /* INCLUDE_OSAPI_COUNTSEM_H_ */ + diff --git a/src/os/shared/inc/osapi-dir-impl.h b/src/os/shared/inc/osapi-dir-impl.h new file mode 100644 index 000000000..2d5c86217 --- /dev/null +++ b/src/os/shared/inc/osapi-dir-impl.h @@ -0,0 +1,116 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-dir.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_DIR_H_ +#define INCLUDE_OSAPI_DIR_H_ + +#include + +/* directory objects */ +typedef struct +{ + char dir_name[OS_MAX_PATH_LEN]; +#ifndef OSAL_OMIT_DEPRECATED + os_dirent_t dirent_object; +#endif +} OS_dir_internal_record_t; + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_dir_internal_record_t OS_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + +/* + * Directory API abstraction layer + * + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_DirAPI_Init + + Purpose: Initialize the OS-independent layer for directory resources + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_DirAPI_Init (void); + + + +/*---------------------------------------------------------------- + Function: OS_DirCreate_Impl + + Purpose: Create a directory in the local filesystem + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirCreate_Impl(const char *local_path, uint32 access); + +/*---------------------------------------------------------------- + Function: OS_DirOpen_Impl + + Purpose: Open a directory and prepare to read the entries + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path); + +/*---------------------------------------------------------------- + Function: OS_DirClose_Impl + + Purpose: Close a directory + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirClose_Impl(uint32 local_id); + +/*---------------------------------------------------------------- + Function: OS_DirRead_Impl + + Purpose: Read the next entry from a directory handle + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent); + +/*---------------------------------------------------------------- + Function: OS_DirRewind_Impl + + Purpose: Rewind a directory handle back to the start + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirRewind_Impl(uint32 local_id); + +/*---------------------------------------------------------------- + Function: OS_DirRemove_Impl + + Purpose: Remove a directory in the local filesystem + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_DirRemove_Impl(const char *local_path); + + + +#endif /* INCLUDE_OSAPI_DIR_H_ */ + diff --git a/src/os/shared/inc/osapi-errors-impl.h b/src/os/shared/inc/osapi-errors-impl.h new file mode 100644 index 000000000..42c3ea26a --- /dev/null +++ b/src/os/shared/inc/osapi-errors-impl.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-errors.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_ERRORS_H_ +#define INCLUDE_OSAPI_ERRORS_H_ + +#include + + +/* Mapping of integer error number to name */ +typedef struct +{ + int32 Number; + const char *Name; +} OS_ErrorTable_Entry_t; + +extern const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[]; + + +#endif /* INCLUDE_OSAPI_ERRORS_H_ */ + diff --git a/src/os/shared/inc/osapi-file-impl.h b/src/os/shared/inc/osapi-file-impl.h new file mode 100644 index 000000000..194693f96 --- /dev/null +++ b/src/os/shared/inc/osapi-file-impl.h @@ -0,0 +1,200 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-file.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_FILE_H_ +#define INCLUDE_OSAPI_FILE_H_ + +#include + +/* + * Flags that can be used with opening of a file (bitmask) + */ +typedef enum +{ + OS_FILE_FLAG_NONE, + OS_FILE_FLAG_CREATE = 0x01, + OS_FILE_FLAG_TRUNCATE = 0x02, +} OS_file_flag_t; + + + +typedef struct +{ + char stream_name[OS_MAX_PATH_LEN]; + uint8 socket_domain; + uint8 socket_type; + uint16 stream_state; +} OS_stream_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; + + + + +/**************************************************************************************** + FILE / DIRECTORY API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_FileAPI_Init + + Purpose: Initialize the OS-independent layer for file resources + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_FileAPI_Init (void); + + +/* + * Generic stream manipulation implementation + * + * These generic seek/read/write/close calls are usable for regular files and + * anything else that is stream-oriented in nature, including pipes, devices, + * and sockets if supported. Note that "open" is not generic as this usually + * requires a different approach depending on whether it is a socket, file, etc. + * (There is a separate "FileOpen_Impl" later for this purpose). + * + * Note that read/write also include an option for a timeout. This is more + * relevant for fifos or sockets. It should be set to OS_PEND for normal + * behavior on regular files which is to wait forever. + */ + +/*---------------------------------------------------------------- + Function: OS_GenericSeek_Impl + + Purpose: Seek to a given position in a file + + Returns: File position (non-negative) on success, or relevant error code (negative) + ------------------------------------------------------------------*/ +int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence); + +/*---------------------------------------------------------------- + Function: OS_GenericRead_Impl + + Purpose: Read from a file descriptor + This may be a normal file or a socket/pipe + + Returns: Number of bytes read (non-negative) on success, or relevant error code (negative) + ------------------------------------------------------------------*/ +int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 timeout); + +/*---------------------------------------------------------------- + Function: OS_GenericWrite_Impl + + Purpose: Write to a file descriptor + This may be a normal file or a socket/pipe + + Returns: Number of bytes written (non-negative) on success, or relevant error code (negative) + ------------------------------------------------------------------*/ +int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout); + + +/*---------------------------------------------------------------- + Function: OS_GenericClose_Impl + + Purpose: Close a file descriptor + This may be a normal file or a socket/pipe + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_GenericClose_Impl(uint32 local_id); + +/*---------------------------------------------------------------- + Function: OS_FileOpen_Impl + + Purpose: Opens the file indicated by "local_path" with permission + indicated by "access". + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access); + +/*---------------------------------------------------------------- + Function: OS_ShellOutputToFile_Impl + + Purpose: Takes a shell command in and writes the output of that command to the specified file + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ShellOutputToFile_Impl(uint32 stream_id, const char* Cmd); + + + +/**************************************************************************************** + Filename-based Operations + ***************************************************************************************/ + + +/* + * These FileXXX_Impl calls are usable for things that operate on pathnames, + * that is to say they appear in the file system in some way. + * + * Mainly intended for regular files but they should work on named pipes or + * devices too, provided they have a pathname associated with them. + * + * Note that sockets (at least the inet variety) usually do _not_ have a + * filename, so they require a different "open" method, but usually do use + * the generic read/write/close pattern thereafter. + */ + +/*---------------------------------------------------------------- + Function: OS_FileStat_Impl + + Purpose: Output stats on the file indicated by "local_path" + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *filestat); + +/*---------------------------------------------------------------- + Function: OS_FileRemove_Impl + + Purpose: Remove/Unlink the file indicated by "local_path" + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileRemove_Impl(const char *local_path); + +/*---------------------------------------------------------------- + Function: OS_FileRename_Impl + + Purpose: Rename "old_path" to "new_path" in the filesystem + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileRename_Impl(const char *old_path, const char *new_path); + +/*---------------------------------------------------------------- + + Function: OS_FileChmod_Impl + + Purpose: Change permission on an existing file + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileChmod_Impl(const char *local_path, uint32 access); + + +#endif /* INCLUDE_OSAPI_FILE_H_ */ + diff --git a/src/os/shared/inc/osapi-filesys-impl.h b/src/os/shared/inc/osapi-filesys-impl.h new file mode 100644 index 000000000..15d9ebeec --- /dev/null +++ b/src/os/shared/inc/osapi-filesys-impl.h @@ -0,0 +1,209 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-filesys.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_FILESYS_H_ +#define INCLUDE_OSAPI_FILESYS_H_ + +#include + +/** + * This flag will be set on the internal record to indicate + * that the filesystem is "fixed" and therefore not mountable + * or unmountable by OSAL on the system side. + * + * The filesystem should be configured and mounted at the right + * spot prior to starting OSAL. + */ +#define OS_FILESYS_FLAG_IS_FIXED 0x01 + + +/** + * This flag will be set on the internal record to indicate + * that the low level device driver has been started. + * + * On Linux, this might mean that the relevant block device + * module has been loaded and an appropriate /dev entry exists. + * + * On VxWorks, this means that the low-level block device + * is registered in the kernel and XBD layers. + */ +#define OS_FILESYS_FLAG_IS_READY 0x02 + +/** + * This flag will be set on the internal record to indicate + * that the file system is accessible within the underlying + * operating system, i.e. that the system_mountpt is valid. + */ +#define OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM 0x10 + +/** + * This flag will be set on the internal record to indicate + * that the file system is mounted within the virtualized + * file system exposed to applications. + */ +#define OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL 0x20 + +/** + * These definitions apply to the "type" field within + * the file system record. This field may serve as a + * hint or guidance for the implementation layer as to + * what type of file system to use when initializing or + * mounting the file system. + */ +enum +{ + OS_FILESYS_TYPE_DEFAULT = 0, /**< Unspecified or unknown file system type */ + OS_FILESYS_TYPE_NORMAL_DISK, /**< A traditional disk drive or something that emulates one */ + OS_FILESYS_TYPE_VOLATILE_DISK, /**< A temporary/volatile file system or RAM disk */ + OS_FILESYS_TYPE_MTD, /**< A "memory technology device" such as FLASH or EEPROM */ + OS_FILESYS_TYPE_MAX +}; + +/* + * The data type filled in by the "statvfs" call. + * + * This is defined here since there is no public API to get this info, + * only the total bytes free is accessible via the current OSAL API. + * + * However, returning the detailed info at this level means that the + * more detailed information could be made available with a new API call. + */ +typedef struct +{ + uint32 block_size; + uint64 total_blocks; + uint64 blocks_free; +} OS_statvfs_t; + + +typedef struct +{ + char device_name[OS_MAX_API_NAME]; /**< The name of the underlying block device, if applicable */ + char volume_name[OS_MAX_API_NAME]; + char system_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix where the contents are accessible in the host operating system */ + char virtual_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix in the OSAL Virtual File system exposed to applications */ + char *address; + uint32 blocksize; + uint32 numblocks; + uint8 flags; + uint8 fstype; +} OS_filesys_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_filesys_internal_record_t OS_filesys_table[OS_MAX_FILE_SYSTEMS]; + + +/* + * File system abstraction layer + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_FileSysAPI_Init + + Purpose: Initialize the OS-independent layer for file systems + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_FileSysAPI_Init (void); + + + +/*---------------------------------------------------------------- + Function: OS_FileSysStartVolume_Impl + + Purpose: Starts/Registers a file system on the target + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysStartVolume_Impl (uint32 filesys_id); + +/*---------------------------------------------------------------- + Function: OS_FileSysStopVolume_Impl + + Purpose: Stops/Unregisters a file system on the target + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysStopVolume_Impl (uint32 filesys_id); + +/*---------------------------------------------------------------- + Function: OS_FileSysFormatVolume_Impl + + Purpose: Formats a file system on the target to prepare it for use + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id); + +/*---------------------------------------------------------------- + Function: OS_FileSysCheckVolume_Impl + + Purpose: Checks the drives and optionally repairs inconsistencies + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysCheckVolume_Impl (uint32 filesys_id, bool repair); + +/*---------------------------------------------------------------- + Function: OS_FileSysStatVolume_Impl + + Purpose: Returns stats about a volume + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result); + +/*---------------------------------------------------------------- + Function: OS_FileSysMountVolume_Impl + + Purpose: mounts a drive + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysMountVolume_Impl (uint32 filesys_id); + +/*---------------------------------------------------------------- + Function: OS_FileSysUnmountVolume_Impl + + Purpose: unmounts a drive. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id); + + +/* + * Internal helper functions + * + * Not normally invoked outside this unit, except for unit testing + */ + +bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj); +int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, const OS_VolumeInfo_t *Vol); +int32 OS_FileSys_SetupInitialParamsForDevice(const char *devname, OS_filesys_internal_record_t *local); +int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char * fsvolname, uint32 blocksize, + uint32 numblocks, bool should_format); + + +#endif /* INCLUDE_OSAPI_FILESYS_H_ */ + diff --git a/src/os/shared/inc/osapi-fpu-impl.h b/src/os/shared/inc/osapi-fpu-impl.h new file mode 100644 index 000000000..8c92e91be --- /dev/null +++ b/src/os/shared/inc/osapi-fpu-impl.h @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-fpu.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_FPU_H_ +#define INCLUDE_OSAPI_FPU_H_ + +#include + +#ifndef OSAL_OMIT_DEPRECATED + + +/**************************************************************************************** + FLOATING POINT CONFIG/EXCEPTION API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/* + * FPU API low-level handlers + * These may also not be implementable on some platforms + */ +int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, + int32 parameter); +int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber); +int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber); + +/*---------------------------------------------------------------- + Function: OS_FPUExcSetMask_Impl + + Purpose: This function sets the FPU exception mask + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FPUExcSetMask_Impl(uint32 mask); + +/*---------------------------------------------------------------- + Function: OS_FPUExcGetMask_Impl + + Purpose: This function gets the FPU exception mask + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_FPUExcGetMask_Impl(uint32 *mask); + +#endif + +#endif /* INCLUDE_OSAPI_FPU_H_ */ + diff --git a/src/os/shared/inc/osapi-heap-impl.h b/src/os/shared/inc/osapi-heap-impl.h new file mode 100644 index 000000000..387945eb7 --- /dev/null +++ b/src/os/shared/inc/osapi-heap-impl.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-heap.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_HEAP_H_ +#define INCLUDE_OSAPI_HEAP_H_ + +#include + + +/**************************************************************************************** + MEMORY HEAP API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/* + * This may also not be implementable on some platforms + */ + +/*---------------------------------------------------------------- + Function: OS_HeapGetInfo_Impl + + Purpose: Return current info on the heap + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop); + + + +#endif /* INCLUDE_OSAPI_HEAP_H_ */ + diff --git a/src/os/shared/inc/osapi-idmap-impl.h b/src/os/shared/inc/osapi-idmap-impl.h new file mode 100644 index 000000000..37fbccb17 --- /dev/null +++ b/src/os/shared/inc/osapi-idmap-impl.h @@ -0,0 +1,263 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-idmap.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_IDMAP_H_ +#define INCLUDE_OSAPI_IDMAP_H_ + +#include + + +#define OS_OBJECT_EXCL_REQ_FLAG 0x0001 + +/* + * This supplies a non-abstract definition of "OS_common_record_t" + */ +struct OS_common_record +{ + const char *name_entry; + uint32 active_id; + uint32 creator; + uint16 refcount; + uint16 flags; +}; + + +/* + * Type of locking that should occur when checking IDs. + */ +typedef enum +{ + OS_LOCK_MODE_NONE, /**< Do not lock global table at all (use with caution) */ + OS_LOCK_MODE_GLOBAL, /**< Lock during operation, and if successful, leave global table locked */ + OS_LOCK_MODE_EXCLUSIVE, /**< Like OS_LOCK_MODE_GLOBAL but must be exclusive (refcount == zero) */ + OS_LOCK_MODE_REFCOUNT, /**< If operation succeeds, increment refcount and unlock global table */ +} OS_lock_mode_t; + + +/* + * A function to perform arbitrary record matching. + * + * This can be used to find a record based on criteria other than the ID, + * such as the name or any other record within the structure. + * + * Returns true if the id/obj matches the reference, false otherwise. + */ +typedef bool (*OS_ObjectMatchFunc_t)(void *ref, uint32 local_id, const OS_common_record_t *obj); + +/* + * Global instantiations + */ +/* The following are quick-access pointers to the various sections of the common table */ +extern OS_common_record_t * const OS_global_task_table; +extern OS_common_record_t * const OS_global_queue_table; +extern OS_common_record_t * const OS_global_bin_sem_table; +extern OS_common_record_t * const OS_global_count_sem_table; +extern OS_common_record_t * const OS_global_mutex_table; +extern OS_common_record_t * const OS_global_stream_table; +extern OS_common_record_t * const OS_global_dir_table; +extern OS_common_record_t * const OS_global_timebase_table; +extern OS_common_record_t * const OS_global_timecb_table; +extern OS_common_record_t * const OS_global_module_table; +extern OS_common_record_t * const OS_global_filesys_table; +extern OS_common_record_t * const OS_global_console_table; + + + + +/**************************************************************************************** + ID MAPPING FUNCTIONS + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_ObjectIdInit + + Purpose: Initialize the OS-independent layer for object ID management + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_ObjectIdInit (void); + + +/* + * Table locking and unlocking for global objects can be done at the shared code + * layer but the actual implementation is OS-specific + */ + + +/*---------------------------------------------------------------- + Function: OS_Lock_Global_Impl + + Purpose: Locks the global table identified by "idtype" + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_Lock_Global_Impl(uint32 idtype); + +/*---------------------------------------------------------------- + Function: OS_Unlock_Global_Impl + + Purpose: Unlocks the global table identified by "idtype" + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_Unlock_Global_Impl(uint32 idtype); + + + +/* + Function prototypes for routines implemented in common layers but private to OSAL + + These implement the basic OSAL ObjectID patterns - that is a 32-bit number that + is opaque externally, but internally identifies a specific type of object and + corresponding index within the local tables. + */ + +/*---------------------------------------------------------------- + Function: OS_GetMaxForObjectType + + Purpose: Obtains the maximum number of objects for "idtype" in the global table + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +uint32 OS_GetMaxForObjectType(uint32 idtype); + +/*---------------------------------------------------------------- + Function: OS_GetBaseForObjectType + + Purpose: Obtains the base object number for "idtype" in the global table + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +uint32 OS_GetBaseForObjectType(uint32 idtype); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdMap + + Purpose: Convert an object serial number into a 32-bit OSAL ID of the given type + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdMap(uint32 idtype, uint32 idvalue, uint32 *result); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdUnMap + + Purpose: Convert a 32-bit OSAL ID of the expected type into an object serial number + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdUnMap(uint32 id, uint32 idtype, uint32 *idvalue); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdFindByName + + Purpose: Finds an entry in the global resource table matching the given name + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdFindByName (uint32 idtype, const char *name, uint32 *object_id); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdToArrayIndex + + Purpose: Convert a 32-bit OSAL ID into a zero-based array index + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdToArrayIndex(uint32 idtype, uint32 id, uint32 *ArrayIndex); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdGetBySearch + + Purpose: Find and lock an entry in the global resource table + Search is performed using a user-specified match function + (Allows searching for items by arbitrary keys) + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdGetByName + + Purpose: Find and lock an entry in the global resource table + Search is performed using a name match function + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdGetByName (OS_lock_mode_t lock_mode, uint32 idtype, const char *name, OS_common_record_t **record); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdGetById + + Purpose: Find and lock an entry in the global resource table + Lookup is performed by ID value (no searching required) + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, uint32 idtype, uint32 id, uint32 *array_index, OS_common_record_t **record); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdAllocateNew + + Purpose: Issue a new object ID of the given type and associate with the given name + The array index (0-based) and global record pointers are output back to the caller + The table will be left in a "locked" state to allow further initialization + The OS_ObjectIdFinalizeNew() function must be called to complete the operation + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdFinalizeNew + + Purpose: Completes the operation initiated by OS_ObjectIdAllocateNew() + If the operation was successful, the final OSAL ID is returned + If the operation was unsuccessful, the ID is deleted and returned to the pool. + The global table is unlocked for future operations + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, uint32 *outid); + +/*---------------------------------------------------------------- + Function: OS_ObjectIdRefcountDecr + + Purpose: Decrement the reference count + This releases objects obtained with OS_LOCK_MODE_REFCOUNT mode + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record); + +/* + * Internal helper functions + * These are not normally called outside this unit, but need + * to be exposed for unit testing. + */ +bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *obj); +void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype); +int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj); +int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record); +int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); + +#endif /* INCLUDE_OSAPI_IDMAP_H_ */ + diff --git a/src/os/shared/inc/osapi-interrupts-impl.h b/src/os/shared/inc/osapi-interrupts-impl.h new file mode 100644 index 000000000..ab97160aa --- /dev/null +++ b/src/os/shared/inc/osapi-interrupts-impl.h @@ -0,0 +1,112 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-interrupts.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_INTERRUPTS_H_ +#define INCLUDE_OSAPI_INTERRUPTS_H_ + +#include + + +#ifndef OSAL_OMIT_DEPRECATED + +/**************************************************************************************** + INTERRUPT API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/* + * Interrupt API low-level handlers + * + * These are defined for completeness but may not be implementable on + * multi-user platforms where interrupts are handled exclusively at the + * kernel level. They may work on single-user RTOS's like + * VxWorks or RTEMS, but not Linux. As such they should not be + * relied upon. + */ + +/*---------------------------------------------------------------- + Function: OS_IntAttachHandler_Impl + + Purpose: The call associates a specified C routine to a specified interrupt + number.Upon occurring of the InterruptNumber the InerruptHandler + routine will be called and passed the parameter. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter); + +/*---------------------------------------------------------------- + Function: OS_IntUnlock_Impl + + Purpose: Enable previous state of interrupts + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntUnlock_Impl (int32 IntLevel); + +/*---------------------------------------------------------------- + Function: OS_IntLock_Impl + + Purpose: Disable interrupts + + Returns: A key value that can be used to restore interrupts + ------------------------------------------------------------------*/ +int32 OS_IntLock_Impl ( void ); + +/*---------------------------------------------------------------- + Function: OS_IntEnable_Impl + + Purpose: Enable previous state of interrupts + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntEnable_Impl(int32 Level); + +/*---------------------------------------------------------------- + Function: OS_IntDisable_Impl + + Purpose: Disable the corresponding interrupt number. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntDisable_Impl(int32 Level); + +/*---------------------------------------------------------------- + Function: OS_IntSetMask_Impl + + Purpose: Set the cpu mask register for interrupts + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntSetMask_Impl ( uint32 MaskSetting ); + +/*---------------------------------------------------------------- + Function: OS_IntGetMask_Impl + + Purpose: Read and output the setting of the cpu mask register + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ); + +#endif /* OSAL_OMIT_DEPRECATED */ + + +#endif /* INCLUDE_OSAPI_INTERRUPTS_H_ */ + diff --git a/src/os/shared/inc/osapi-module-impl.h b/src/os/shared/inc/osapi-module-impl.h new file mode 100644 index 000000000..c0a4cdb94 --- /dev/null +++ b/src/os/shared/inc/osapi-module-impl.h @@ -0,0 +1,113 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-module.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_MODULE_H_ +#define INCLUDE_OSAPI_MODULE_H_ + +#include + + +typedef struct +{ + char module_name[OS_MAX_API_NAME]; + char file_name[OS_MAX_PATH_LEN]; + uint32 flags; + cpuaddr entry_point; +} OS_module_internal_record_t; + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_module_internal_record_t OS_module_table[OS_MAX_MODULES]; + +/**************************************************************************************** + MODULE LOADER API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_ModuleAPI_Init + + Purpose: Initialize the OS-independent layer for modules + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_ModuleAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_ModuleLoad_Impl + + Purpose: Loads an object file into the running operating system + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ); + +/*---------------------------------------------------------------- + + Function: OS_ModuleUnload_Impl + + Purpose: Unloads the module file from the running operating system + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ModuleUnload_Impl ( uint32 module_id ); + +/*---------------------------------------------------------------- + Function: OS_ModuleGetInfo_Impl + + Purpose: Returns information about the loadable module + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ); + +/*---------------------------------------------------------------- + Function: OS_SymbolLookup_Impl + + Purpose: Find the Address of a Symbol + The address of the symbol will be stored in the pointer that is passed in. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SymbolLookup_Impl ( cpuaddr *SymbolAddress, const char *SymbolName ); + +/*---------------------------------------------------------------- + Function: OS_SymbolTableDump_Impl + + Purpose: Dumps the system symbol table to a file + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 size_limit ); + + +/* + * Helper functions within the shared layer that are not normally invoked outside the local module + * These need to be exposed for unit testing + */ +int32 OS_ModuleLoad_Static(const char *ModuleName); +int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName); + + +#endif /* INCLUDE_OSAPI_MODULE_H_ */ + diff --git a/src/os/shared/inc/osapi-mutex-impl.h b/src/os/shared/inc/osapi-mutex-impl.h new file mode 100644 index 000000000..bb41b8837 --- /dev/null +++ b/src/os/shared/inc/osapi-mutex-impl.h @@ -0,0 +1,97 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-mutex.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_MUTEX_H_ +#define INCLUDE_OSAPI_MUTEX_H_ + +#include + + +typedef struct +{ + char obj_name[OS_MAX_API_NAME]; +} OS_mutex_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_mutex_internal_record_t OS_mutex_table[OS_MAX_MUTEXES]; + +/*--------------------------------------------------------------------------------------- + Name: OS_MutexAPI_Init + + Purpose: Initialize the OS-independent layer for mutex objects + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_MutexAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_MutSemCreate_Impl + + Purpose: Prepare/allocate OS resources for a mutex object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options); + +/*---------------------------------------------------------------- + Function: OS_MutSemGive_Impl + + Purpose: Release the mutex, which must be owned by the caller + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_MutSemGive_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_MutSemTake_Impl + + Purpose: Acquire the mutex, blocking the caller as necessary + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_MutSemTake_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_MutSemDelete_Impl + + Purpose: Free the OS resources associated with a mutex object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_MutSemDelete_Impl (uint32 sem_id); + +/*---------------------------------------------------------------- + Function: OS_MutSemGetInfo_Impl + + Purpose: Obtain OS-specific information about the mutex object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop); + + + + +#endif /* INCLUDE_OSAPI_MUTEX_H_ */ + diff --git a/src/os/shared/inc/osapi-network-impl.h b/src/os/shared/inc/osapi-network-impl.h new file mode 100644 index 000000000..a6100255a --- /dev/null +++ b/src/os/shared/inc/osapi-network-impl.h @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-network.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_NETWORK_H_ +#define INCLUDE_OSAPI_NETWORK_H_ + +#include + + + +/**************************************************************************************** + NETWORK / SOCKET API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_NetworkAPI_Init + + Purpose: Initialize the OS-independent layer for network services + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_NetworkAPI_Init (void); + + +/*---------------------------------------------------------------- + + Function: OS_NetworkGetHostName_Impl + + Purpose: Gets the name of the current host + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len); + +/*---------------------------------------------------------------- + Function: OS_NetworkGetID_Impl + + Purpose: Gets the ID of the host on the network + + Returns: the ID value on success, or -1 on error. + ------------------------------------------------------------------*/ +int32 OS_NetworkGetID_Impl (int32 *IdBuf); + +#endif /* INCLUDE_OSAPI_NETWORK_H_ */ + diff --git a/src/os/shared/inc/osapi-printf-impl.h b/src/os/shared/inc/osapi-printf-impl.h new file mode 100644 index 000000000..dc6207299 --- /dev/null +++ b/src/os/shared/inc/osapi-printf-impl.h @@ -0,0 +1,107 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-printf.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_PRINTF_H_ +#define INCLUDE_OSAPI_PRINTF_H_ + +#include + +/* + * Variables related to the console buffer. + * This is a simple ring buffer that decouples + * the OS_printf() call from actual console output. + * + * The implementation layer may optionally spawn a + * "utility task" or equivalent to forward data, or + * it may process data immediately. + */ + +typedef struct +{ + char device_name[OS_MAX_API_NAME]; + + char *BufBase; /**< Start of the buffer memory */ + uint32 BufSize; /**< Total size of the buffer */ + volatile uint32 ReadPos; /**< Offset of next byte to read */ + volatile uint32 WritePos; /**< Offset of next byte to write */ + uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ + +} OS_console_internal_record_t; + + +extern OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; + + + +/**************************************************************************************** + CONSOLE / DEBUG API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_ConsoleAPI_Init + + Purpose: Initialize the OS-independent layer for console service + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_ConsoleAPI_Init (void); + + + +/*---------------------------------------------------------------- + Function: OS_ConsoleCreate_Impl + + Purpose: Prepare a console device for use + For Async devices, this sets up the background writer task + ------------------------------------------------------------------*/ +int32 OS_ConsoleCreate_Impl(uint32 local_id); + +/*---------------------------------------------------------------- + Function: OS_ConsoleOutput_Impl + + Purpose: Basic Console output implementation + + This function forwards the data from the console + ring buffer into the actual output device/descriptor + + The data is already formatted, this just writes the characters. + ------------------------------------------------------------------*/ +void OS_ConsoleOutput_Impl(uint32 local_id); + +/*---------------------------------------------------------------- + Function: OS_ConsoleOutput_Impl + + Purpose: Console output data notification + + This is a notification API that is invoked whenever there + is new data available in the console output buffer. + + For a synchronous console service, this may call + OS_ConsoleWrite_Impl() directly. For an async console + service, this should wakeup the actual console servicing + thread. + ------------------------------------------------------------------*/ +void OS_ConsoleWakeup_Impl(uint32 local_id); + + + + +#endif /* INCLUDE_OSAPI_PRINTF_H_ */ + diff --git a/src/os/shared/inc/osapi-queue-impl.h b/src/os/shared/inc/osapi-queue-impl.h new file mode 100644 index 000000000..528a3bc6e --- /dev/null +++ b/src/os/shared/inc/osapi-queue-impl.h @@ -0,0 +1,112 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-queue.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_QUEUE_H_ +#define INCLUDE_OSAPI_QUEUE_H_ + +#include + + +typedef struct +{ + char queue_name[OS_MAX_API_NAME]; + uint32 max_size; + uint32 max_depth; +} OS_queue_internal_record_t; + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; + + + +/**************************************************************************************** + MESSAGE QUEUE API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_QueueAPI_Init + + Purpose: Initialize the OS-independent layer for queues + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_QueueAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_QueueCreate_Impl + + Purpose: Prepare/Allocate OS resources for a message queue + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags); + +/*---------------------------------------------------------------- + Function: OS_QueueDelete_Impl + + Purpose: Free the OS resources associated with the message queue + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_QueueDelete_Impl (uint32 queue_id); + +/*---------------------------------------------------------------- + Function: OS_QueueGet_Impl + + Purpose: Receive a message on a message queue. + The calling task will be blocked if no message is immediately available + + Returns: OS_SUCCESS on success, or relevant error code + OS_QUEUE_TIMEOUT must be returned if the timeout expired and no message was received + OS_QUEUE_EMPTY must be returned if the queue is empty when polled (OS_CHECK) + OS_QUEUE_INVALID_SIZE must be returned if the supplied buffer is too small + ------------------------------------------------------------------*/ +int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout); + +/*---------------------------------------------------------------- + Function: OS_QueuePut_Impl + + Purpose: Put a message into a message queue + + Returns: OS_SUCCESS on success, or relevant error code + OS_QUEUE_FULL must be returned if the queue is full. + ------------------------------------------------------------------*/ +int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags); + +/*---------------------------------------------------------------- + Function: OS_QueueGetInfo_Impl + + Purpose: Obtain OS-specific information about a message queue + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop); + + + + + +#endif /* INCLUDE_OSAPI_QUEUE_H_ */ + diff --git a/src/os/shared/inc/osapi-select-impl.h b/src/os/shared/inc/osapi-select-impl.h new file mode 100644 index 000000000..5d61a5644 --- /dev/null +++ b/src/os/shared/inc/osapi-select-impl.h @@ -0,0 +1,74 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-select.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_SELECT_H_ +#define INCLUDE_OSAPI_SELECT_H_ + +#include + + +/* + * Select API + * Blocks until specified readable/writable conditions + * are met on a file id or set of file ids + */ + +/*---------------------------------------------------------------- + Function: OS_SelectSingle_Impl + + Purpose: Waits for activity on a single file descriptor + This wrapper is usable by the File or Socket API + The type of activity to wait for is indicated by "SelectFlags" + msecs indicates the timeout. Positive values will wait up to that many milliseconds. + Zero will not wait (poll) or negative values will wait forever (pend) + + Bits in "SelectFlags" will be unset according to activity + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs); + +/*---------------------------------------------------------------- + + Function: OS_SelectMultiple_Impl + + Purpose: Waits for activity on multiple file descriptors + This wrapper is usable by the File or Socket API + Will wait for any file descriptor in "ReadSet" to be readable OR + any descriptor in "WriteSet" to be writable. + Time-Limited to "msecs" (negative to wait forever, zero to poll) + + Notes: It is not possible for this function to verify that the file descriptors + passed in are actually valid. In order to do so would require a different + approach to the OS_FdSet structure (this is currently just a bitmask so + the actual file descriptor value is lost in translation). + + Using an array of uint32's would solve the problem but make the structures + much bigger. + + File descriptors in sets be modified according to activity + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); + + +#endif /* INCLUDE_OSAPI_SELECT_H_ */ + diff --git a/src/os/shared/inc/osapi-shared-globaldefs.h b/src/os/shared/inc/osapi-shared-globaldefs.h new file mode 100644 index 000000000..a426690ba --- /dev/null +++ b/src/os/shared/inc/osapi-shared-globaldefs.h @@ -0,0 +1,79 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-shared-globaldefs.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + * Internal type/macro definitions used across the "shared" OSAPI layer. + * These definitions are internal to OSAL but shared/referenced across all subsystems + * so they are put into a common header file. + */ + +#ifndef INCLUDE_OSAPI_SHARED_GLOBALDEFS_H_ +#define INCLUDE_OSAPI_SHARED_GLOBALDEFS_H_ + +/* All subsystems reference the public API */ +#include + +/* + * The "common_record" is part of the generic ID mapping - + * Functions in the internal API may use this as an abstract pointer. + */ +struct OS_common_record; +typedef struct OS_common_record OS_common_record_t; + +/* + * The "OS_shared_global_vars" keeps global state - + * Functions in the internal API may use this as an abstract pointer. + */ +struct OS_shared_global_vars; +typedef struct OS_shared_global_vars OS_SharedGlobalVars_t; + +/* + * Wrapper for encoding of other types into a generic void* type required as argument + * to callbacks and pthread entry/return values, etc. + * + * Note this can only encode types with sizes <= sizeof(void*) + */ +typedef union +{ + void *opaque_arg; + OS_ArgCallback_t arg_callback_func; + OS_TimerCallback_t timer_callback_func; + osal_task_entry entry_func; + uint32 value; +} OS_U32ValueWrapper_t; + + + +/* + * The "OS_DEBUG" is a no-op unless OSAL_CONFIG_DEBUG_PRINTF is enabled. + * When enabled, it is a macro that includes function/line number info. + */ +#if defined(OSAL_CONFIG_DEBUG_PRINTF) +extern void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *Format, ...); +/* Debug printfs are compiled in, but also can be disabled by a run-time flag. + * Note that the ##__VA_ARGS__ syntax works on GCC but might need tweaks for other compilers... */ +#define OS_DEBUG_LEV(l,...) OS_DebugPrintf(l, __func__, __LINE__, __VA_ARGS__); +#define OS_DEBUG(...) OS_DEBUG_LEV(1,__VA_ARGS__) +#else +/* Debug printfs are not compiled in at all */ +#define OS_DEBUG(...) +#endif + + + +#endif /* INCLUDE_OSAPI_SHARED_GLOBALDEFS_H_ */ + diff --git a/src/os/shared/inc/osapi-sockets-impl.h b/src/os/shared/inc/osapi-sockets-impl.h new file mode 100644 index 000000000..5a3fe6173 --- /dev/null +++ b/src/os/shared/inc/osapi-sockets-impl.h @@ -0,0 +1,173 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-sockets.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_SOCKETS_H_ +#define INCLUDE_OSAPI_SOCKETS_H_ + +#include + +/* + * Sockets API abstraction layer + */ + +/*--------------------------------------------------------------------------------------- + Name: OS_SocketAPI_Init + + Purpose: Initialize the OS-independent layer for network sockets + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_SocketAPI_Init (void); + +/*---------------------------------------------------------------- + Function: OS_SocketOpen_Impl + + Purpose: Opens the OS socket indicated by the sock_id table entry + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketOpen_Impl(uint32 sock_id); + +/*---------------------------------------------------------------- + Function: OS_SocketBind_Impl + + Purpose: Binds the indicated socket table entry to the passed-in address + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr); + +/*---------------------------------------------------------------- + Function: OS_SocketAccept_Impl + + Purpose: Accept an incoming connection on the indicated socket (must be a STREAM socket) + Will wait up to "timeout" milliseconds for an incoming connection + Will wait forever if timeout is negative + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout); + +/*---------------------------------------------------------------- + Function: OS_SocketConnect_Impl + + Purpose: Connects the socket to a remote address. + Socket must be of the STREAM variety. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout); + +/*---------------------------------------------------------------- + Function: OS_SocketRecvFrom_Impl + + Purpose: Receives a datagram from the specified socket (must be of the DATAGRAM type) + Stores the datagram in "buffer" which has a maximum size of "buflen" + Stores the remote address (sender of the datagram) in "RemoteAddr" + Will wait up to "timeout" milliseconds to receive a packet + (zero to poll, negative to wait forever) + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); + +/*---------------------------------------------------------------- + Function: OS_SocketSendTo_Impl + + Purpose: Sends a datagram from the specified socket (must be of the DATAGRAM type) + to the remote address specified by "RemoteAddr" + The datagram to send must be stored in "buffer" with a size of "buflen" + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr); + +/*---------------------------------------------------------------- + + Function: OS_SocketGetInfo_Impl + + Purpose: Get OS-specific information about a socket + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketGetInfo_Impl (uint32 sock_id, OS_socket_prop_t *sock_prop); + +/*---------------------------------------------------------------- + + Function: OS_SocketAddrInit_Impl + + Purpose: Initializes an OSAL SockAddr structure to the given address domain + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain); + +/*---------------------------------------------------------------- + Function: OS_SocketAddrToString_Impl + + Purpose: Converts a Socket Address structure to a printable string + Useful for including a dotted-decimal IP address in a message or log + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr); + +/*---------------------------------------------------------------- + Function: OS_SocketAddrFromString_Impl + + Purpose: Sets the Address portion of the SockAddr structure according to the string + For IPV4 (SocketDomain_INET) this will parse the dotted decimal IP address. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string); + +/*---------------------------------------------------------------- + Function: OS_SocketAddrGetPort_Impl + + Purpose: Retrieve the TCP/UDP port number from the SockAddr structure + + NOTE: The port number is output to the caller in native byte order + (the value is converted from network order before return) + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr); + +/*---------------------------------------------------------------- + Function: OS_SocketAddrSetPort_Impl + + Purpose: Set the TCP/UDP port number in the SockAddr structure + + NOTE: The port number should be passed in native byte order + (this function will convert to network order) + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum); + +/* + * Internal helper functions + * Not normally called outside the local unit, except during unit test + */ +void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *parent_name); + +#endif /* INCLUDE_OSAPI_SOCKETS_H_ */ + diff --git a/src/os/shared/inc/osapi-task-impl.h b/src/os/shared/inc/osapi-task-impl.h new file mode 100644 index 000000000..0d8efcfeb --- /dev/null +++ b/src/os/shared/inc/osapi-task-impl.h @@ -0,0 +1,164 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-task.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_TASK_H_ +#define INCLUDE_OSAPI_TASK_H_ + +#include + +/*tasks */ +typedef struct +{ + char task_name[OS_MAX_API_NAME]; + uint32 stack_size; + uint32 priority; + osal_task_entry entry_function_pointer; + osal_task_entry delete_hook_pointer; + void *entry_arg; + uint32 *stack_pointer; +}OS_task_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; + + + +/**************************************************************************************** + TASK API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ***************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_TaskAPI_Init + + Purpose: Initialize the OS-independent layer for tasks + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_TaskAPI_Init (void); + + +/*---------------------------------------------------------------- + Function: OS_TaskEntryPoint + + Purpose: Entry point for all newly created tasks + + The "OS_TaskEntryPoint" is a generic method implemented in the + shared layer that performs housekeeping and then calls the user-specified + entry point. It should be the first thing called in any new task. + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +void OS_TaskEntryPoint (uint32 global_task_id); + +/*---------------------------------------------------------------- + Function: OS_TaskMatch_Impl + + Purpose: Determines if the caller matches the given task_id + + Returns: OS_SUCCESS on match, any other code on non-match + ------------------------------------------------------------------*/ +int32 OS_TaskMatch_Impl (uint32 task_id); + +/*---------------------------------------------------------------- + + Function: OS_TaskCreate_Impl + + Purpose: Prepare/Allocate OS resources for a new task and start + running it, based on configuration in the global object + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags); + +/*---------------------------------------------------------------- + Function: OS_TaskDelete_Impl + + Purpose: Free the OS resources associated with the specified task + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskDelete_Impl (uint32 task_id); + +/*---------------------------------------------------------------- + Function: OS_TaskExit_Impl + + Purpose: Exits the calling task + + This function does not return + ------------------------------------------------------------------*/ +void OS_TaskExit_Impl (void); + +/*---------------------------------------------------------------- + Function: OS_TaskDelay_Impl + + Purpose: Blocks the calling task for the specified number of milliseconds + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskDelay_Impl (uint32 millisecond); + +/*---------------------------------------------------------------- + Function: OS_TaskSetPriority_Impl + + Purpose: Set the scheduling priority of the specified task + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority); + +/*---------------------------------------------------------------- + Function: OS_TaskGetId_Impl + + Purpose: Obtain the OSAL task ID of the caller + + Returns: The OSAL ID of the calling task, or zero if not registered + ------------------------------------------------------------------*/ +uint32 OS_TaskGetId_Impl (void); + +/*---------------------------------------------------------------- + Function: OS_TaskGetInfo_Impl + + Purpose: Obtain OS-specific information about a task + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop); + +/*---------------------------------------------------------------- + + Function: OS_TaskRegister_Impl + + Purpose: Perform registration actions after new task creation + + NOTE: This is invoked via the OS_TaskEntryPoint() immediately + after new task creation, not through OS_TaskRegister() API + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TaskRegister_Impl (uint32 global_task_id); + + + + +#endif /* INCLUDE_OSAPI_TASK_H_ */ + diff --git a/src/os/shared/inc/osapi-time-impl.h b/src/os/shared/inc/osapi-time-impl.h new file mode 100644 index 000000000..e4a08bd92 --- /dev/null +++ b/src/os/shared/inc/osapi-time-impl.h @@ -0,0 +1,62 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-time.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_TIME_H_ +#define INCLUDE_OSAPI_TIME_H_ + +#include + + +#define TIMECB_FLAG_DEDICATED_TIMEBASE 0x1 + +typedef struct +{ + char timer_name[OS_MAX_API_NAME]; + uint32 flags; + uint32 timebase_ref; + uint32 prev_ref; + uint32 next_ref; + uint32 backlog_resets; + int32 wait_time; + int32 interval_time; + OS_ArgCallback_t callback_ptr; + void *callback_arg; +} OS_timecb_internal_record_t; + + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; + +/*--------------------------------------------------------------------------------------- + Name: OS_TimerCbAPI_Init + + Purpose: Initialize the OS-independent layer for timer callback objects + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_TimerCbAPI_Init (void); + + + +#endif /* INCLUDE_OSAPI_TIME_H_ */ + diff --git a/src/os/shared/inc/osapi-timebase-impl.h b/src/os/shared/inc/osapi-timebase-impl.h new file mode 100644 index 000000000..b6785727a --- /dev/null +++ b/src/os/shared/inc/osapi-timebase-impl.h @@ -0,0 +1,134 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-timebase.h + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OSAPI_TIMEBASE_H_ +#define INCLUDE_OSAPI_TIMEBASE_H_ + +#include + + +typedef struct +{ + char timebase_name[OS_MAX_API_NAME]; + OS_TimerSync_t external_sync; + uint32 accuracy_usec; + uint32 first_cb; + uint32 freerun_time; + uint32 nominal_start_time; + uint32 nominal_interval_time; +} OS_timebase_internal_record_t; + +/* + * These record types have extra information with each entry. These tables are used + * to share extra data between the common layer and the OS-specific implementation. + */ +extern OS_timebase_internal_record_t OS_timebase_table[OS_MAX_TIMEBASES]; + +/**************************************************************************************** + CLOCK / TIME API LOW-LEVEL IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*--------------------------------------------------------------------------------------- + Name: OS_TimeBaseAPI_Init + + Purpose: Initialize the OS-independent layer for timebase objects + + returns: OS_SUCCESS on success, or relevant error code +---------------------------------------------------------------------------------------*/ +int32 OS_TimeBaseAPI_Init (void); + + +/* + * TimeBase routines implement a low-level timer tick/interrupt; + * no callbacks to user code here. All application callbacks are + * done in the shared layer timer API. + */ + +/*---------------------------------------------------------------- + Function: OS_TimeBaseCreate_Impl + + Purpose: Prepare OS resources for a time base + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TimeBaseCreate_Impl (uint32 timebase_id); + +/*---------------------------------------------------------------- + Function: OS_TimeBaseSet_Impl + + Purpose: Configure the OS resources to provide a timer tick + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TimeBaseSet_Impl (uint32 timebase_id, int32 start_time, int32 interval_time); + +/*---------------------------------------------------------------- + Function: OS_TimeBaseDelete_Impl + + Purpose: Free the OS resources associated with the time base + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TimeBaseDelete_Impl (uint32 timebase_id); + + +/**************************************************************************************** + INTERNAL FUNCTIONS +****************************************************************************************/ + + +/*---------------------------------------------------------------- + Function: OS_TimeBaseLock_Impl + + Purpose: Get exclusive access to the given timebase + Add/remove of application callbacks is prevented + ------------------------------------------------------------------*/ +void OS_TimeBaseLock_Impl (uint32 timebase_id); + +/*---------------------------------------------------------------- + Function: OS_TimeBaseLock_Impl + + Purpose: Release exclusive access to the given timebase + Add/remove of application callbacks is allowed + ------------------------------------------------------------------*/ +void OS_TimeBaseUnlock_Impl (uint32 timebase_id); + +/*---------------------------------------------------------------- + Function: OS_TimeBaseGetInfo_Impl + + Purpose: Obtain the OS-specific time base information, if any + + Returns: OS_SUCCESS on success, or relevant error code + ------------------------------------------------------------------*/ +int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop); + +/*---------------------------------------------------------------- + Function: OS_TimeBase_CallbackThread + + Purpose: Implement the time base helper thread + This is the context for providing application callbacks + ------------------------------------------------------------------*/ +void OS_TimeBase_CallbackThread (uint32 timebase_id); + + + + +#endif /* INCLUDE_OSAPI_TIMEBASE_H_ */ + diff --git a/src/os/shared/os-impl.h b/src/os/shared/os-impl.h deleted file mode 100644 index 02cabb57b..000000000 --- a/src/os/shared/os-impl.h +++ /dev/null @@ -1,1927 +0,0 @@ -/* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/** - * \file os-impl.h - * \author joseph.p.hickey@nasa.gov - * - * Purpose: Contains functions prototype definitions and variables declarations - * for the OS Abstraction Layer, Core OS module - */ - -/* - * NOTE - CONVENTION WITHIN THIS LAYER: - * This file contains function prototypes and type declarations that define the - * interface between the OS-specific and the shared portions of the OSAPI. - * - * Functions that end in "_Impl" are _OS Specific_ and should be implemented - * within the appropriate OS-specific directory (i.e. posix, rtems, vxworks, etc) - * - * NONE of the functions or variables within this file are supposed to be public -- - * i.e. these are private to OSAL and not exposed to the code above this layer. - * - */ - -#ifndef _osapi_os_impl_ -#define _osapi_os_impl_ - -#include "osapi.h" - -/* - * A "magic number" that when written to the "ShutdownFlag" member - * of the global state structure indicates an active shutdown request. - */ -#define OS_SHUTDOWN_MAGIC_NUMBER 0xABADC0DE - -/* - * File system table size: - * Historically this was a PSP/BSP-supplied table with a fixed size - * of "NUM_TABLE_ENTRIES" which is _not_ part of osconfig.h. - * - * To be more consistent with other object types this implementation - * allows the size of the run-time file system table to be configured - * using "OS_MAX_FILE_SYSTEMS". - * - * For backward compatibility, if this is not defined in osconfig.h, - * then this shall simply make the internal table to be the same size - * as NUM_TABLE_ENTRIES. - */ -#ifndef OS_MAX_FILE_SYSTEMS -#define OS_MAX_FILE_SYSTEMS NUM_TABLE_ENTRIES -#endif - -/* - * Number of console devices - * - * Typically this would always be 1, for OS_printf() output. - */ -#ifndef OS_MAX_CONSOLES -#define OS_MAX_CONSOLES 1 -#endif - - -/* - * Types shared between the implementations and shared code - */ - -/* - * Wrapper for encoding of other types into a generic void* type required as argument - * to callbacks and pthread entry/return values, etc. - * - * Note this can only encode types with sizes <= sizeof(void*) - */ -typedef union -{ - void *opaque_arg; - OS_ArgCallback_t arg_callback_func; - OS_TimerCallback_t timer_callback_func; - osal_task_entry entry_func; - uint32 value; -} OS_U32ValueWrapper_t; - -/* - * OS_U32ValueWrapper_t must be equal in size to a "void*" as it is used in places - * where a void* argument is required. This compile-time assert ensures that. - * If this fails, then it means one of the types within the union is too large. - */ -CompileTimeAssert(sizeof(OS_U32ValueWrapper_t) == sizeof(void *), U32ValueWrapperSize); - - -#define OS_OBJECT_EXCL_REQ_FLAG 0x0001 - -typedef struct -{ - const char *name_entry; - uint32 active_id; - uint32 creator; - uint16 refcount; - uint16 flags; -}OS_common_record_t; - -typedef enum -{ - OS_STREAM_STATE_BOUND = 0x01, - OS_STREAM_STATE_CONNECTED = 0x02, - OS_STREAM_STATE_READABLE = 0x04, - OS_STREAM_STATE_WRITABLE = 0x08, -} OS_StreamState_t; - -/*tasks */ -typedef struct -{ - char task_name[OS_MAX_API_NAME]; - uint32 stack_size; - uint32 priority; - osal_task_entry entry_function_pointer; - osal_task_entry delete_hook_pointer; - void *entry_arg; - uint32 *stack_pointer; -}OS_task_internal_record_t; - -/* other objects that have only an API name and no other data */ -typedef struct -{ - char queue_name[OS_MAX_API_NAME]; - uint32 max_size; - uint32 max_depth; -} OS_queue_internal_record_t; - -/* other objects that have only an API name and no other data */ -typedef struct -{ - char obj_name[OS_MAX_API_NAME]; -} OS_apiname_internal_record_t; - -/* directory objects */ -typedef struct -{ - char dir_name[OS_MAX_PATH_LEN]; -#ifndef OSAL_OMIT_DEPRECATED - os_dirent_t dirent_object; -#endif -} OS_dir_internal_record_t; - -typedef struct -{ - char stream_name[OS_MAX_PATH_LEN]; - uint8 socket_domain; - uint8 socket_type; - uint16 stream_state; -} OS_stream_internal_record_t; - -typedef struct -{ - char timebase_name[OS_MAX_API_NAME]; - OS_TimerSync_t external_sync; - uint32 accuracy_usec; - uint32 first_cb; - uint32 freerun_time; - uint32 nominal_start_time; - uint32 nominal_interval_time; -} OS_timebase_internal_record_t; - -#define TIMECB_FLAG_DEDICATED_TIMEBASE 0x1 -typedef struct -{ - char timer_name[OS_MAX_API_NAME]; - uint32 flags; - uint32 timebase_ref; - uint32 prev_ref; - uint32 next_ref; - uint32 backlog_resets; - int32 wait_time; - int32 interval_time; - OS_ArgCallback_t callback_ptr; - void *callback_arg; -} OS_timecb_internal_record_t; - -typedef struct -{ - char module_name[OS_MAX_API_NAME]; - char file_name[OS_MAX_PATH_LEN]; - uint32 flags; - cpuaddr entry_point; -} OS_module_internal_record_t; - -typedef struct -{ - char device_name[OS_MAX_API_NAME]; /**< The name of the underlying block device, if applicable */ - char volume_name[OS_MAX_API_NAME]; - char system_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix where the contents are accessible in the host operating system */ - char virtual_mountpt[OS_MAX_PATH_LEN]; /**< The name/prefix in the OSAL Virtual File system exposed to applications */ - char *address; - uint32 blocksize; - uint32 numblocks; - uint8 flags; - uint8 fstype; -} OS_filesys_internal_record_t; - -/** - * This flag will be set on the internal record to indicate - * that the filesystem is "fixed" and therefore not mountable - * or unmountable by OSAL on the system side. - * - * The filesystem should be configured and mounted at the right - * spot prior to starting OSAL. - */ -#define OS_FILESYS_FLAG_IS_FIXED 0x01 - - -/** - * This flag will be set on the internal record to indicate - * that the low level device driver has been started. - * - * On Linux, this might mean that the relevant block device - * module has been loaded and an appropriate /dev entry exists. - * - * On VxWorks, this means that the low-level block device - * is registered in the kernel and XBD layers. - */ -#define OS_FILESYS_FLAG_IS_READY 0x02 - -/** - * This flag will be set on the internal record to indicate - * that the file system is accessible within the underlying - * operating system, i.e. that the system_mountpt is valid. - */ -#define OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM 0x10 - -/** - * This flag will be set on the internal record to indicate - * that the file system is mounted within the virtualized - * file system exposed to applications. - */ -#define OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL 0x20 - - -/** - * These definitions apply to the "type" field within - * the file system record. This field may serve as a - * hint or guidance for the implementation layer as to - * what type of file system to use when initializing or - * mounting the file system. - */ -enum -{ - OS_FILESYS_TYPE_DEFAULT = 0, /**< Unspecified or unknown file system type */ - OS_FILESYS_TYPE_NORMAL_DISK, /**< A traditional disk drive or something that emulates one */ - OS_FILESYS_TYPE_VOLATILE_DISK, /**< A temporary/volatile file system or RAM disk */ - OS_FILESYS_TYPE_MTD, /**< A "memory technology device" such as FLASH or EEPROM */ - OS_FILESYS_TYPE_MAX -}; - - -/* - * Variables related to the console buffer. - * This is a simple ring buffer that decouples - * the OS_printf() call from actual console output. - * - * The implementation layer may optionally spawn a - * "utility task" or equivalent to forward data, or - * it may process data immediately. - */ - -typedef struct -{ - char device_name[OS_MAX_API_NAME]; - - char *BufBase; /**< Start of the buffer memory */ - uint32 BufSize; /**< Total size of the buffer */ - volatile uint32 ReadPos; /**< Offset of next byte to read */ - volatile uint32 WritePos; /**< Offset of next byte to write */ - uint32 OverflowEvents; /**< Number of lines dropped due to overflow */ - -} OS_console_internal_record_t; - -/* Mapping of integer error number to name */ -typedef struct -{ - int32 Number; - const char *Name; -} OS_ErrorTable_Entry_t; - -/* Global variables that are common between implementations */ -typedef struct -{ - bool Initialized; - - /* - * The console device ID used for OS_printf() calls - */ - uint32 PrintfConsoleId; - - /* - * PrintfEnabled and ShutdownFlag are marked "volatile" - * because they are updated and read by different threads - */ - volatile bool PrintfEnabled; - volatile uint32 ShutdownFlag; - int32 MicroSecPerTick; - int32 TicksPerSecond; - -#ifdef OS_DEBUG_PRINTF - uint8 DebugLevel; -#endif - -} OS_SharedGlobalVars_t; - - - -/* - * Global instantiations - */ - -extern const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[]; - -/* The following are quick-access pointers to the various sections of the common table */ -extern OS_common_record_t * const OS_global_task_table; -extern OS_common_record_t * const OS_global_queue_table; -extern OS_common_record_t * const OS_global_bin_sem_table; -extern OS_common_record_t * const OS_global_count_sem_table; -extern OS_common_record_t * const OS_global_mutex_table; -extern OS_common_record_t * const OS_global_stream_table; -extern OS_common_record_t * const OS_global_dir_table; -extern OS_common_record_t * const OS_global_timebase_table; -extern OS_common_record_t * const OS_global_timecb_table; -extern OS_common_record_t * const OS_global_module_table; -extern OS_common_record_t * const OS_global_filesys_table; -extern OS_common_record_t * const OS_global_console_table; - -/* - * These record types have extra information with each entry. These tables are used - * to share extra data between the common layer and the OS-specific implementation. - */ -extern OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; -extern OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; -extern OS_apiname_internal_record_t OS_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; -extern OS_apiname_internal_record_t OS_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; -extern OS_apiname_internal_record_t OS_mutex_table[OS_MAX_MUTEXES]; -extern OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; -extern OS_dir_internal_record_t OS_dir_table[OS_MAX_NUM_OPEN_DIRS]; -extern OS_timebase_internal_record_t OS_timebase_table[OS_MAX_TIMEBASES]; -extern OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; -#if (OS_MAX_MODULES > 0) -extern OS_module_internal_record_t OS_module_table[OS_MAX_MODULES]; -#endif -extern OS_filesys_internal_record_t OS_filesys_table[OS_MAX_FILE_SYSTEMS]; -extern OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; - - - -/* - * Shared data structure for global values - */ -extern OS_SharedGlobalVars_t OS_SharedGlobalVars; - -/* - * Flags that can be used with opening of a file (bitmask) - */ -typedef enum -{ - OS_FILE_FLAG_NONE, - OS_FILE_FLAG_CREATE = 0x01, - OS_FILE_FLAG_TRUNCATE = 0x02, -} OS_file_flag_t; - - -/* - * Type of locking that should occur when checking IDs. - */ -typedef enum -{ - OS_LOCK_MODE_NONE, /**< Do not lock global table at all (use with caution) */ - OS_LOCK_MODE_GLOBAL, /**< Lock during operation, and if successful, leave global table locked */ - OS_LOCK_MODE_EXCLUSIVE, /**< Like OS_LOCK_MODE_GLOBAL but must be exclusive (refcount == zero) */ - OS_LOCK_MODE_REFCOUNT, /**< If operation succeeds, increment refcount and unlock global table */ -} OS_lock_mode_t; - -/* - * The data type filled in by the "statvfs" call. - * - * This is defined here since there is no public API to get this info, - * only the total bytes free is accessible via the current OSAL API. - * - * However, returning the detailed info at this level means that the - * more detailed information could be made available with a new API call. - */ -typedef struct -{ - uint32 block_size; - uint64 total_blocks; - uint64 blocks_free; -} OS_statvfs_t; - -/* - * A function to perform arbitrary record matching. - * - * This can be used to find a record based on criteria other than the ID, - * such as the name or any other record within the structure. - * - * Returns true if the id/obj matches the reference, false otherwise. - */ -typedef bool (*OS_ObjectMatchFunc_t)(void *ref, uint32 local_id, const OS_common_record_t *obj); - - -/**************************************************************************************** - INITIALIZATION FUNCTIONS - ****************************************************************************************/ - -/* - * Initialization functions for each of the common sub-layers - * These functions may or may not do anything, but the hook is provided nonetheless. - */ - -/*--------------------------------------------------------------------------------------- - Name: OS_API_Impl_Init - - Purpose: Initialize the OS-specific layer for the given object type - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_API_Impl_Init (uint32 idtype); - -/*--------------------------------------------------------------------------------------- - Name: OS_ObjectIdInit - - Purpose: Initialize the OS-independent layer for object ID management - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_ObjectIdInit (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_TaskAPI_Init - - Purpose: Initialize the OS-independent layer for tasks - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_TaskAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_QueueAPI_Init - - Purpose: Initialize the OS-independent layer for queues - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_QueueAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_BinSemAPI_Init - - Purpose: Initialize the OS-independent layer for binary semaphores - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_BinSemAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_CountSemAPI_Init - - Purpose: Initialize the OS-independent layer for counting semaphores - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_CountSemAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_MutexAPI_Init - - Purpose: Initialize the OS-independent layer for mutex objects - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_MutexAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_ModuleAPI_Init - - Purpose: Initialize the OS-independent layer for modules - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_ModuleAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_TimeBaseAPI_Init - - Purpose: Initialize the OS-independent layer for timebase objects - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_TimeBaseAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_TimerCbAPI_Init - - Purpose: Initialize the OS-independent layer for timer callback objects - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_TimerCbAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_FileAPI_Init - - Purpose: Initialize the OS-independent layer for file resources - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_FileAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_DirAPI_Init - - Purpose: Initialize the OS-independent layer for directory resources - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_DirAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_NetworkAPI_Init - - Purpose: Initialize the OS-independent layer for network services - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_NetworkAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_SocketAPI_Init - - Purpose: Initialize the OS-independent layer for network sockets - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_SocketAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_FileSysAPI_Init - - Purpose: Initialize the OS-independent layer for file systems - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_FileSysAPI_Init (void); - -/*--------------------------------------------------------------------------------------- - Name: OS_ConsoleAPI_Init - - Purpose: Initialize the OS-independent layer for console service - - returns: OS_SUCCESS on success, or relevant error code ----------------------------------------------------------------------------------------*/ -int32 OS_ConsoleAPI_Init (void); - - -/**************************************************************************************** - IMPLEMENTATION FUNCTIONS - ***************************************************************************************/ - -/* - * This functions implement a the OS-specific portion - * of various OSAL functions. They are defined in - * OS-specific source files. - */ - - -/*---------------------------------------------------------------- - - Function: OS_IdleLoop_Impl - - Purpose: Block the "idle" thread until woken up - - The "IdleLoop_Impl" is called by the main thread once - everything is running and there is no more work to do. - - It should suspend the calling thread until a wakeup - event happens. - - ------------------------------------------------------------------*/ -void OS_IdleLoop_Impl (void); - -/*---------------------------------------------------------------- - - Function: OS_ApplicationShutdown_Impl - - Purpose: Wake up the idle task - - The "ApplicationShutdown_Impl" should wake up whatever - task is currently suspended in "IdleLoop_Impl" and cause - that thread to resume and return to its caller. - - NOTE: This should not block but it may cause the current - thread to be preempted by the thread that was woken up, - depending on priority levels. - - ------------------------------------------------------------------*/ -void OS_ApplicationShutdown_Impl (void); - - - -/**************************************************************************************** - ID MAPPING FUNCTIONS - ***************************************************************************************/ - -/* - Function prototypes for routines implemented in common layers but private to OSAL - - These implement the basic OSAL ObjectID patterns - that is a 32-bit number that - is opaque externally, but internally identifies a specific type of object and - corresponding index within the local tables. - */ - -/*---------------------------------------------------------------- - Function: OS_GetMaxForObjectType - - Purpose: Obtains the maximum number of objects for "idtype" in the global table - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -uint32 OS_GetMaxForObjectType(uint32 idtype); - -/*---------------------------------------------------------------- - Function: OS_GetBaseForObjectType - - Purpose: Obtains the base object number for "idtype" in the global table - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -uint32 OS_GetBaseForObjectType(uint32 idtype); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdMap - - Purpose: Convert an object serial number into a 32-bit OSAL ID of the given type - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdMap(uint32 idtype, uint32 idvalue, uint32 *result); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdUnMap - - Purpose: Convert a 32-bit OSAL ID of the expected type into an object serial number - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdUnMap(uint32 id, uint32 idtype, uint32 *idvalue); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdFindByName - - Purpose: Finds an entry in the global resource table matching the given name - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdFindByName (uint32 idtype, const char *name, uint32 *object_id); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdToArrayIndex - - Purpose: Convert a 32-bit OSAL ID into a zero-based array index - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdToArrayIndex(uint32 idtype, uint32 id, uint32 *ArrayIndex); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdGetBySearch - - Purpose: Find and lock an entry in the global resource table - Search is performed using a user-specified match function - (Allows searching for items by arbitrary keys) - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetBySearch(OS_lock_mode_t lock_mode, uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdGetByName - - Purpose: Find and lock an entry in the global resource table - Search is performed using a name match function - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetByName (OS_lock_mode_t lock_mode, uint32 idtype, const char *name, OS_common_record_t **record); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdGetById - - Purpose: Find and lock an entry in the global resource table - Lookup is performed by ID value (no searching required) - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdGetById(OS_lock_mode_t lock_mode, uint32 idtype, uint32 id, uint32 *array_index, OS_common_record_t **record); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdAllocateNew - - Purpose: Issue a new object ID of the given type and associate with the given name - The array index (0-based) and global record pointers are output back to the caller - The table will be left in a "locked" state to allow further initialization - The OS_ObjectIdFinalizeNew() function must be called to complete the operation - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdAllocateNew(uint32 idtype, const char *name, uint32 *array_index, OS_common_record_t **record); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdFinalizeNew - - Purpose: Completes the operation initiated by OS_ObjectIdAllocateNew() - If the operation was successful, the final OSAL ID is returned - If the operation was unsuccessful, the ID is deleted and returned to the pool. - The global table is unlocked for future operations - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdFinalizeNew(int32 operation_status, OS_common_record_t *record, uint32 *outid); - -/*---------------------------------------------------------------- - Function: OS_ObjectIdRefcountDecr - - Purpose: Decrement the reference count - This releases objects obtained with OS_LOCK_MODE_REFCOUNT mode - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ObjectIdRefcountDecr(OS_common_record_t *record); - - -/* - * Table locking and unlocking for global objects can be done at the shared code - * layer but the actual implementation is OS-specific - */ - - -/*---------------------------------------------------------------- - Function: OS_Lock_Global_Impl - - Purpose: Locks the global table identified by "idtype" - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype); - -/*---------------------------------------------------------------- - Function: OS_Unlock_Global_Impl - - Purpose: Unlocks the global table identified by "idtype" - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype); - - - -/**************************************************************************************** - TASK API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ***************************************************************************************/ - -/*---------------------------------------------------------------- - Function: OS_TaskEntryPoint - - Purpose: Entry point for all newly created tasks - - The "OS_TaskEntryPoint" is a generic method implemented in the - shared layer that performs housekeeping and then calls the user-specified - entry point. It should be the first thing called in any new task. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -void OS_TaskEntryPoint (uint32 global_task_id); - -/*---------------------------------------------------------------- - Function: OS_TaskMatch_Impl - - Purpose: Determines if the caller matches the given task_id - - Returns: OS_SUCCESS on match, any other code on non-match - ------------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl (uint32 task_id); - -/*---------------------------------------------------------------- - - Function: OS_TaskCreate_Impl - - Purpose: Prepare/Allocate OS resources for a new task and start - running it, based on configuration in the global object - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags); - -/*---------------------------------------------------------------- - Function: OS_TaskDelete_Impl - - Purpose: Free the OS resources associated with the specified task - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl (uint32 task_id); - -/*---------------------------------------------------------------- - Function: OS_TaskExit_Impl - - Purpose: Exits the calling task - - This function does not return - ------------------------------------------------------------------*/ -void OS_TaskExit_Impl (void); - -/*---------------------------------------------------------------- - Function: OS_TaskDelay_Impl - - Purpose: Blocks the calling task for the specified number of milliseconds - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskDelay_Impl (uint32 millisecond); - -/*---------------------------------------------------------------- - Function: OS_TaskSetPriority_Impl - - Purpose: Set the scheduling priority of the specified task - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority); - -/*---------------------------------------------------------------- - Function: OS_TaskGetId_Impl - - Purpose: Obtain the OSAL task ID of the caller - - Returns: The OSAL ID of the calling task, or zero if not registered - ------------------------------------------------------------------*/ -uint32 OS_TaskGetId_Impl (void); - -/*---------------------------------------------------------------- - Function: OS_TaskGetInfo_Impl - - Purpose: Obtain OS-specific information about a task - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop); - -/*---------------------------------------------------------------- - - Function: OS_TaskRegister_Impl - - Purpose: Perform registration actions after new task creation - - NOTE: This is invoked via the OS_TaskEntryPoint() immediately - after new task creation, not through OS_TaskRegister() API - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TaskRegister_Impl (uint32 global_task_id); - - - - -/**************************************************************************************** - MESSAGE QUEUE API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ***************************************************************************************/ - -/*---------------------------------------------------------------- - Function: OS_QueueCreate_Impl - - Purpose: Prepare/Allocate OS resources for a message queue - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags); - -/*---------------------------------------------------------------- - Function: OS_QueueDelete_Impl - - Purpose: Free the OS resources associated with the message queue - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl (uint32 queue_id); - -/*---------------------------------------------------------------- - Function: OS_QueueGet_Impl - - Purpose: Receive a message on a message queue. - The calling task will be blocked if no message is immediately available - - Returns: OS_SUCCESS on success, or relevant error code - OS_QUEUE_TIMEOUT must be returned if the timeout expired and no message was received - OS_QUEUE_EMPTY must be returned if the queue is empty when polled (OS_CHECK) - OS_QUEUE_INVALID_SIZE must be returned if the supplied buffer is too small - ------------------------------------------------------------------*/ -int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout); - -/*---------------------------------------------------------------- - Function: OS_QueuePut_Impl - - Purpose: Put a message into a message queue - - Returns: OS_SUCCESS on success, or relevant error code - OS_QUEUE_FULL must be returned if the queue is full. - ------------------------------------------------------------------*/ -int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags); - -/*---------------------------------------------------------------- - Function: OS_QueueGetInfo_Impl - - Purpose: Obtain OS-specific information about a message queue - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop); - - - -/**************************************************************************************** - SEMAPHORE API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ***************************************************************************************/ - -/* - * Binary semaphores - */ - -/*---------------------------------------------------------------- - Function: OS_BinSemCreate_Impl - - Purpose: Prepare/allocate OS resources for a binary semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options); - -/*---------------------------------------------------------------- - Function: OS_BinSemFlush_Impl - - Purpose: Unblock all tasks waiting on the binary semaphore. - Does not change the semaphore value. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_BinSemGive_Impl - - Purpose: Release the semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_BinSemTake_Impl - - Purpose: Acquire the semaphore - Block the calling task if the semaphore is 0. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_BinSemTimedWait_Impl - - Purpose: Acquire the semaphore, with a time limit - - Returns: OS_SUCCESS on success, or relevant error code - OS_SEM_TIMEOUT must be returned if the time limit was reached - ------------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs); - -/*---------------------------------------------------------------- - Function: OS_BinSemDelete_Impl - - Purpose: Free the OS resources associated with the binary semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_BinSemGetInfo_Impl - - Purpose: Obtain OS-specific information about the semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop); - -/* - * Counting semaphores - */ - -/*---------------------------------------------------------------- - Function: OS_CountSemCreate_Impl - - Purpose: Prepare/allocate OS resources for a counting semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options); - -/*---------------------------------------------------------------- - Function: OS_CountSemGive_Impl - - Purpose: Increment the semaphore value - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_CountSemTake_Impl - - Purpose: Decrement the semaphore value - Block the calling task if the semaphore is 0. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_CountSemTimedWait_Impl - - Purpose: Decrement the semaphore value, with a time limit - - Returns: OS_SUCCESS on success, or relevant error code - OS_SEM_TIMEOUT must be returned if the time limit was reached - ------------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs); - -/*---------------------------------------------------------------- - Function: OS_CountSemDelete_Impl - - Purpose: Free the OS resources associated with the counting semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_CountSemGetInfo_Impl - - Purpose: Obtain OS-specific information about the semaphore - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop); - -/* - * Mutex semaphores - */ - -/*---------------------------------------------------------------- - Function: OS_MutSemCreate_Impl - - Purpose: Prepare/allocate OS resources for a mutex object - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options); - -/*---------------------------------------------------------------- - Function: OS_MutSemGive_Impl - - Purpose: Release the mutex, which must be owned by the caller - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_MutSemTake_Impl - - Purpose: Acquire the mutex, blocking the caller as necessary - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_MutSemDelete_Impl - - Purpose: Free the OS resources associated with a mutex object - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl (uint32 sem_id); - -/*---------------------------------------------------------------- - Function: OS_MutSemGetInfo_Impl - - Purpose: Obtain OS-specific information about the mutex object - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop); - - -/**************************************************************************************** - CLOCK / TIME API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/* - * TimeBase routines implement a low-level timer tick/interrupt; - * no callbacks to user code here. All application callbacks are - * done in the shared layer timer API. - */ - -/*---------------------------------------------------------------- - Function: OS_TimeBaseCreate_Impl - - Purpose: Prepare OS resources for a time base - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TimeBaseCreate_Impl (uint32 timebase_id); - -/*---------------------------------------------------------------- - Function: OS_TimeBaseSet_Impl - - Purpose: Configure the OS resources to provide a timer tick - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TimeBaseSet_Impl (uint32 timebase_id, int32 start_time, int32 interval_time); - -/*---------------------------------------------------------------- - Function: OS_TimeBaseDelete_Impl - - Purpose: Free the OS resources associated with the time base - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TimeBaseDelete_Impl (uint32 timebase_id); - - - -/**************************************************************************************** - INTERNAL FUNCTIONS -****************************************************************************************/ - - -/*---------------------------------------------------------------- - Function: OS_TimeBaseLock_Impl - - Purpose: Get exclusive access to the given timebase - Add/remove of application callbacks is prevented - ------------------------------------------------------------------*/ -void OS_TimeBaseLock_Impl (uint32 timebase_id); - -/*---------------------------------------------------------------- - Function: OS_TimeBaseLock_Impl - - Purpose: Release exclusive access to the given timebase - Add/remove of application callbacks is allowed - ------------------------------------------------------------------*/ -void OS_TimeBaseUnlock_Impl (uint32 timebase_id); - -/*---------------------------------------------------------------- - Function: OS_TimeBaseGetInfo_Impl - - Purpose: Obtain the OS-specific time base information, if any - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop); - -/*---------------------------------------------------------------- - Function: OS_TimeBase_CallbackThread - - Purpose: Implement the time base helper thread - This is the context for providing application callbacks - ------------------------------------------------------------------*/ -void OS_TimeBase_CallbackThread (uint32 timebase_id); - -/* - * Clock API low-level handlers - * These simply get/set the kernel RTC (if it has one) - */ - -/*---------------------------------------------------------------- - Function: OS_GetLocalTime_Impl - - Purpose: Get the time from the RTC - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_GetLocalTime_Impl(OS_time_t *time_struct); - -/*---------------------------------------------------------------- - Function: OS_SetLocalTime_Impl - - Purpose: Set the time in the RTC - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct); - - - - -/**************************************************************************************** - MODULE LOADER API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/*---------------------------------------------------------------- - Function: OS_ModuleLoad_Impl - - Purpose: Loads an object file into the running operating system - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl ( uint32 module_id, const char *translated_path ); - -/*---------------------------------------------------------------- - - Function: OS_ModuleUnload_Impl - - Purpose: Unloads the module file from the running operating system - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl ( uint32 module_id ); - -/*---------------------------------------------------------------- - Function: OS_ModuleGetInfo_Impl - - Purpose: Returns information about the loadable module - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ); - -/*---------------------------------------------------------------- - Function: OS_SymbolLookup_Impl - - Purpose: Find the Address of a Symbol - The address of the symbol will be stored in the pointer that is passed in. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl ( cpuaddr *SymbolAddress, const char *SymbolName ); - -/*---------------------------------------------------------------- - Function: OS_SymbolTableDump_Impl - - Purpose: Dumps the system symbol table to a file - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 size_limit ); - - - -/**************************************************************************************** - CONSOLE / DEBUG API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - - -/*---------------------------------------------------------------- - Function: OS_ConsoleCreate_Impl - - Purpose: Prepare a console device for use - For Async devices, this sets up the background writer task - ------------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id); - -/*---------------------------------------------------------------- - Function: OS_ConsoleOutput_Impl - - Purpose: Basic Console output implementation - - This function forwards the data from the console - ring buffer into the actual output device/descriptor - - The data is already formatted, this just writes the characters. - ------------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(uint32 local_id); - -/*---------------------------------------------------------------- - Function: OS_ConsoleOutput_Impl - - Purpose: Console output data notification - - This is a notification API that is invoked whenever there - is new data available in the console output buffer. - - For a synchronous console service, this may call - OS_ConsoleWrite_Impl() directly. For an async console - service, this should wakeup the actual console servicing - thread. - ------------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id); - - - -/* - * The "OS_DEBUG" is a no-op unless OS_DEBUG_PRINTF is enabled. - * When enabled, it is a macro that includes function/line number info. - */ -#if defined(OS_DEBUG_PRINTF) -/* Debug printfs are compiled in, but also can be disabled by a run-time flag. - * Note that the ##__VA_ARGS__ syntax works on GCC but might need tweaks for other compilers... */ -#define OS_DEBUG_LEV(l,...) do { if (OS_SharedGlobalVars.DebugLevel >= l) printf("%s():%d:", __func__,__LINE__); printf(__VA_ARGS__); } while (0) -#define OS_DEBUG(...) OS_DEBUG_LEV(1,__VA_ARGS__) -#else -/* Debug printfs are not compiled in at all */ -#define OS_DEBUG(...) -#endif - - - - -/**************************************************************************************** - FILE / DIRECTORY API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/* - * Generic stream manipulation implementation - * - * These generic seek/read/write/close calls are usable for regular files and - * anything else that is stream-oriented in nature, including pipes, devices, - * and sockets if supported. Note that "open" is not generic as this usually - * requires a different approach depending on whether it is a socket, file, etc. - * (There is a separate "FileOpen_Impl" later for this purpose). - * - * Note that read/write also include an option for a timeout. This is more - * relevant for fifos or sockets. It should be set to OS_PEND for normal - * behavior on regular files which is to wait forever. - */ - -/*---------------------------------------------------------------- - Function: OS_GenericSeek_Impl - - Purpose: Seek to a given position in a file - - Returns: File position (non-negative) on success, or relevant error code (negative) - ------------------------------------------------------------------*/ -int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence); - -/*---------------------------------------------------------------- - Function: OS_GenericRead_Impl - - Purpose: Read from a file descriptor - This may be a normal file or a socket/pipe - - Returns: Number of bytes read (non-negative) on success, or relevant error code (negative) - ------------------------------------------------------------------*/ -int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 timeout); - -/*---------------------------------------------------------------- - Function: OS_GenericWrite_Impl - - Purpose: Write to a file descriptor - This may be a normal file or a socket/pipe - - Returns: Number of bytes written (non-negative) on success, or relevant error code (negative) - ------------------------------------------------------------------*/ -int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout); - -/**************************************************************************************** - Low Level Input/Output API - ***************************************************************************************/ - - -/*---------------------------------------------------------------- - Function: OS_GenericClose_Impl - - Purpose: Close a file descriptor - This may be a normal file or a socket/pipe - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_GenericClose_Impl(uint32 local_id); - - -/* - * These FileXXX_Impl calls are usable for things that operate on pathnames, - * that is to say they appear in the file system in some way. - * - * Mainly intended for regular files but they should work on named pipes or - * devices too, provided they have a pathname associated with them. - * - * Note that sockets (at least the inet variety) usually do _not_ have a - * filename, so they require a different "open" method, but usually do use - * the generic read/write/close pattern thereafter. - */ - -/*---------------------------------------------------------------- - Function: OS_FileStat_Impl - - Purpose: Output stats on the file indicated by "local_path" - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *filestat); - -/*---------------------------------------------------------------- - Function: OS_FileRemove_Impl - - Purpose: Remove/Unlink the file indicated by "local_path" - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileRemove_Impl(const char *local_path); - -/*---------------------------------------------------------------- - Function: OS_FileRename_Impl - - Purpose: Rename "old_path" to "new_path" in the filesystem - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileRename_Impl(const char *old_path, const char *new_path); - -/*---------------------------------------------------------------- - Function: OS_FileOpen_Impl - - Purpose: Opens the file indicated by "local_path" with permission - indicated by "access". - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access); - -/*---------------------------------------------------------------- - - Function: OS_FileChmod_Impl - - Purpose: Change permission on an existing file - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileChmod_Impl(const char *local_path, uint32 access); - -/*---------------------------------------------------------------- - Function: OS_ShellOutputToFile_Impl - - Purpose: Takes a shell command in and writes the output of that command to the specified file - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 stream_id, const char* Cmd); - -/* - * Directory API abstraction layer - */ - -/*---------------------------------------------------------------- - Function: OS_DirCreate_Impl - - Purpose: Create a directory in the local filesystem - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirCreate_Impl(const char *local_path, uint32 access); - -/*---------------------------------------------------------------- - Function: OS_DirOpen_Impl - - Purpose: Open a directory and prepare to read the entries - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path); - -/*---------------------------------------------------------------- - Function: OS_DirClose_Impl - - Purpose: Close a directory - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirClose_Impl(uint32 local_id); - -/*---------------------------------------------------------------- - Function: OS_DirRead_Impl - - Purpose: Read the next entry from a directory handle - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent); - -/*---------------------------------------------------------------- - Function: OS_DirRewind_Impl - - Purpose: Rewind a directory handle back to the start - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(uint32 local_id); - -/*---------------------------------------------------------------- - Function: OS_DirRemove_Impl - - Purpose: Remove a directory in the local filesystem - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_DirRemove_Impl(const char *local_path); - -/* - * Select API - * Blocks until specified readable/writable conditions - * are met on a file id or set of file ids - */ - -/*---------------------------------------------------------------- - Function: OS_SelectSingle_Impl - - Purpose: Waits for activity on a single file descriptor - This wrapper is usable by the File or Socket API - The type of activity to wait for is indicated by "SelectFlags" - msecs indicates the timeout. Positive values will wait up to that many milliseconds. - Zero will not wait (poll) or negative values will wait forever (pend) - - Bits in "SelectFlags" will be unset according to activity - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs); - -/*---------------------------------------------------------------- - - Function: OS_SelectMultiple_Impl - - Purpose: Waits for activity on multiple file descriptors - This wrapper is usable by the File or Socket API - Will wait for any file descriptor in "ReadSet" to be readable OR - any descriptor in "WriteSet" to be writable. - Time-Limited to "msecs" (negative to wait forever, zero to poll) - - Notes: It is not possible for this function to verify that the file descriptors - passed in are actually valid. In order to do so would require a different - approach to the OS_FdSet structure (this is currently just a bitmask so - the actual file descriptor value is lost in translation). - - Using an array of uint32's would solve the problem but make the structures - much bigger. - - File descriptors in sets be modified according to activity - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs); - - -/* - * File system abstraction layer - */ - -/*---------------------------------------------------------------- - Function: OS_FileSysStartVolume_Impl - - Purpose: Starts/Registers a file system on the target - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysStartVolume_Impl (uint32 filesys_id); - -/*---------------------------------------------------------------- - Function: OS_FileSysStopVolume_Impl - - Purpose: Stops/Unregisters a file system on the target - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysStopVolume_Impl (uint32 filesys_id); - -/*---------------------------------------------------------------- - Function: OS_FileSysFormatVolume_Impl - - Purpose: Formats a file system on the target to prepare it for use - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id); - -/*---------------------------------------------------------------- - Function: OS_FileSysCheckVolume_Impl - - Purpose: Checks the drives and optionally repairs inconsistencies - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysCheckVolume_Impl (uint32 filesys_id, bool repair); - -/*---------------------------------------------------------------- - Function: OS_FileSysStatVolume_Impl - - Purpose: Returns stats about a volume - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result); - -/*---------------------------------------------------------------- - Function: OS_FileSysMountVolume_Impl - - Purpose: mounts a drive - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysMountVolume_Impl (uint32 filesys_id); - -/*---------------------------------------------------------------- - Function: OS_FileSysUnmountVolume_Impl - - Purpose: unmounts a drive. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id); - - -/**************************************************************************************** - NETWORK / SOCKET API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - - -/*---------------------------------------------------------------- - - Function: OS_NetworkGetHostName_Impl - - Purpose: Gets the name of the current host - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len); - -/*---------------------------------------------------------------- - Function: OS_NetworkGetID_Impl - - Purpose: Gets the ID of the host on the network - - Returns: the ID value on success, or -1 on error. - ------------------------------------------------------------------*/ -int32 OS_NetworkGetID_Impl (int32 *IdBuf); - -/* - * Sockets API abstraction layer - */ - -/*---------------------------------------------------------------- - Function: OS_SocketOpen_Impl - - Purpose: Opens the OS socket indicated by the sock_id table entry - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketOpen_Impl(uint32 sock_id); - -/*---------------------------------------------------------------- - Function: OS_SocketBind_Impl - - Purpose: Binds the indicated socket table entry to the passed-in address - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketBind_Impl(uint32 sock_id, const OS_SockAddr_t *Addr); - -/*---------------------------------------------------------------- - Function: OS_SocketAccept_Impl - - Purpose: Accept an incoming connection on the indicated socket (must be a STREAM socket) - Will wait up to "timeout" milliseconds for an incoming connection - Will wait forever if timeout is negative - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAccept_Impl(uint32 sock_id, uint32 connsock_id, OS_SockAddr_t *Addr, int32 timeout); - -/*---------------------------------------------------------------- - Function: OS_SocketConnect_Impl - - Purpose: Connects the socket to a remote address. - Socket must be of the STREAM variety. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketConnect_Impl(uint32 sock_id, const OS_SockAddr_t *Addr, int32 timeout); - -/*---------------------------------------------------------------- - Function: OS_SocketRecvFrom_Impl - - Purpose: Receives a datagram from the specified socket (must be of the DATAGRAM type) - Stores the datagram in "buffer" which has a maximum size of "buflen" - Stores the remote address (sender of the datagram) in "RemoteAddr" - Will wait up to "timeout" milliseconds to receive a packet - (zero to poll, negative to wait forever) - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr_t *RemoteAddr, int32 timeout); - -/*---------------------------------------------------------------- - Function: OS_SocketSendTo_Impl - - Purpose: Sends a datagram from the specified socket (must be of the DATAGRAM type) - to the remote address specified by "RemoteAddr" - The datagram to send must be stored in "buffer" with a size of "buflen" - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, const OS_SockAddr_t *RemoteAddr); - -/*---------------------------------------------------------------- - - Function: OS_SocketGetInfo_Impl - - Purpose: Get OS-specific information about a socket - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketGetInfo_Impl (uint32 sock_id, OS_socket_prop_t *sock_prop); - -/*---------------------------------------------------------------- - - Function: OS_SocketAddrInit_Impl - - Purpose: Initializes an OSAL SockAddr structure to the given address domain - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAddrInit_Impl(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain); - -/*---------------------------------------------------------------- - Function: OS_SocketAddrToString_Impl - - Purpose: Converts a Socket Address structure to a printable string - Useful for including a dotted-decimal IP address in a message or log - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAddrToString_Impl(char *buffer, uint32 buflen, const OS_SockAddr_t *Addr); - -/*---------------------------------------------------------------- - Function: OS_SocketAddrFromString_Impl - - Purpose: Sets the Address portion of the SockAddr structure according to the string - For IPV4 (SocketDomain_INET) this will parse the dotted decimal IP address. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAddrFromString_Impl(OS_SockAddr_t *Addr, const char *string); - -/*---------------------------------------------------------------- - Function: OS_SocketAddrGetPort_Impl - - Purpose: Retrieve the TCP/UDP port number from the SockAddr structure - - NOTE: The port number is output to the caller in native byte order - (the value is converted from network order before return) - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAddrGetPort_Impl(uint16 *PortNum, const OS_SockAddr_t *Addr); - -/*---------------------------------------------------------------- - Function: OS_SocketAddrSetPort_Impl - - Purpose: Set the TCP/UDP port number in the SockAddr structure - - NOTE: The port number should be passed in native byte order - (this function will convert to network order) - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_SocketAddrSetPort_Impl(OS_SockAddr_t *Addr, uint16 PortNum); - -#ifndef OSAL_OMIT_DEPRECATED - -/**************************************************************************************** - INTERRUPT API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/* - * Interrupt API low-level handlers - * - * These are defined for completeness but may not be implementable on - * multi-user platforms where interrupts are handled exclusively at the - * kernel level. They may work on single-user RTOS's like - * VxWorks or RTEMS, but not Linux. As such they should not be - * relied upon. - */ - -/*---------------------------------------------------------------- - Function: OS_IntAttachHandler_Impl - - Purpose: The call associates a specified C routine to a specified interrupt - number.Upon occurring of the InterruptNumber the InerruptHandler - routine will be called and passed the parameter. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter); - -/*---------------------------------------------------------------- - Function: OS_IntUnlock_Impl - - Purpose: Enable previous state of interrupts - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntUnlock_Impl (int32 IntLevel); - -/*---------------------------------------------------------------- - Function: OS_IntLock_Impl - - Purpose: Disable interrupts - - Returns: A key value that can be used to restore interrupts - ------------------------------------------------------------------*/ -int32 OS_IntLock_Impl ( void ); - -/*---------------------------------------------------------------- - Function: OS_IntEnable_Impl - - Purpose: Enable previous state of interrupts - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntEnable_Impl(int32 Level); - -/*---------------------------------------------------------------- - Function: OS_IntDisable_Impl - - Purpose: Disable the corresponding interrupt number. - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntDisable_Impl(int32 Level); - -/*---------------------------------------------------------------- - Function: OS_IntSetMask_Impl - - Purpose: Set the cpu mask register for interrupts - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntSetMask_Impl ( uint32 MaskSetting ); - -/*---------------------------------------------------------------- - Function: OS_IntGetMask_Impl - - Purpose: Read and output the setting of the cpu mask register - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ); - -#endif /* OSAL_OMIT_DEPRECATED */ - -/**************************************************************************************** - FLOATING POINT CONFIG/EXCEPTION API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/* - * FPU API low-level handlers - * These may also not be implementable on some platforms - */ -int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, - int32 parameter); -int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber); -int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber); - -/*---------------------------------------------------------------- - Function: OS_FPUExcSetMask_Impl - - Purpose: This function sets the FPU exception mask - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FPUExcSetMask_Impl(uint32 mask); - -/*---------------------------------------------------------------- - Function: OS_FPUExcGetMask_Impl - - Purpose: This function gets the FPU exception mask - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_FPUExcGetMask_Impl(uint32 *mask); - - - -/**************************************************************************************** - MEMORY HEAP API LOW-LEVEL IMPLEMENTATION FUNCTIONS - ****************************************************************************************/ - -/* - * This may also not be implementable on some platforms - */ - -/*---------------------------------------------------------------- - Function: OS_HeapGetInfo_Impl - - Purpose: Return current info on the heap - - Returns: OS_SUCCESS on success, or relevant error code - ------------------------------------------------------------------*/ -int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop); - - - -/********************* - END os-impl.h - *********************/ -#endif /* _osapi_os_impl_ */ diff --git a/src/os/shared/osapi-binsem.c b/src/os/shared/src/osapi-binsem.c similarity index 91% rename from src/os/shared/osapi-binsem.c rename to src/os/shared/src/osapi-binsem.c index 4e72b5cab..205d7244d 100644 --- a/src/os/shared/osapi-binsem.c +++ b/src/os/shared/src/osapi-binsem.c @@ -1,21 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-binsem.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-binsem.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * */ /**************************************************************************************** @@ -30,8 +32,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-binsem-impl.h" +#include "osapi-idmap-impl.h" /* * Sanity checks on the user-supplied configuration @@ -51,7 +53,7 @@ enum LOCAL_OBJID_TYPE = OS_OBJECT_TYPE_OS_BINSEM }; -OS_apiname_internal_record_t OS_bin_sem_table [LOCAL_NUM_OBJECTS]; +OS_bin_sem_internal_record_t OS_bin_sem_table [LOCAL_NUM_OBJECTS]; /**************************************************************************************** @@ -66,7 +68,7 @@ OS_apiname_internal_record_t OS_bin_sem_table [LOCAL_NUM_OBJECTS]; Returns: OS_SUCCESS ---------------------------------------------------------------------------------------*/ - + /*---------------------------------------------------------------- * * Function: OS_BinSemAPI_Init @@ -81,7 +83,7 @@ int32 OS_BinSemAPI_Init(void) } /* end OS_BinSemAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemCreate @@ -128,7 +130,7 @@ int32 OS_BinSemCreate (uint32 *sem_id, const char *sem_name, uint32 sem_initial_ } /* end OS_BinSemCreate */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemDelete @@ -163,7 +165,7 @@ int32 OS_BinSemDelete (uint32 sem_id) } /* end OS_BinSemDelete */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGive @@ -189,7 +191,7 @@ int32 OS_BinSemGive ( uint32 sem_id ) } /* end OS_BinSemGive */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemFlush @@ -214,7 +216,7 @@ int32 OS_BinSemFlush (uint32 sem_id) return return_code; } /* end OS_BinSemFlush */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTake @@ -239,7 +241,7 @@ int32 OS_BinSemTake ( uint32 sem_id ) return return_code; } /* end OS_BinSemTake */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemTimedWait @@ -263,7 +265,7 @@ int32 OS_BinSemTimedWait ( uint32 sem_id, uint32 msecs ) return return_code; } /* end OS_BinSemTimedWait */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGetIdByName @@ -286,7 +288,7 @@ int32 OS_BinSemGetIdByName (uint32 *sem_id, const char *sem_name) return return_code; } /* end OS_BinSemGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_BinSemGetInfo diff --git a/src/os/shared/osapi-clock.c b/src/os/shared/src/osapi-clock.c similarity index 71% rename from src/os/shared/osapi-clock.c rename to src/os/shared/src/osapi-clock.c index 14fcac60c..e927d362d 100644 --- a/src/os/shared/osapi-clock.c +++ b/src/os/shared/src/osapi-clock.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-clock.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-clock.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * Contains the code related to clock getting / setting. * Implementation of these are mostly in the lower layer; however * a wrapper must exist at this level which allows for unit testing. @@ -29,10 +32,9 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-clock-impl.h" + - /*---------------------------------------------------------------- * * Function: OS_GetLocalTime @@ -52,7 +54,7 @@ int32 OS_GetLocalTime(OS_time_t *time_struct) } /* end OS_GetLocalTime */ - + /*---------------------------------------------------------------- * * Function: OS_SetLocalTime diff --git a/src/os/shared/osapi-common.c b/src/os/shared/src/osapi-common.c similarity index 89% rename from src/os/shared/osapi-common.c rename to src/os/shared/src/osapi-common.c index dde63d3b8..41cf8ffc6 100644 --- a/src/os/shared/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -1,24 +1,26 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-common.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-common.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * * Instantiates the global object tables and the overall OSAL * init/teardown logic such as OS_API_Init() and OS_ApplicationExit(). - * */ /**************************************************************************************** @@ -32,8 +34,22 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-binsem-impl.h" +#include "osapi-common-impl.h" +#include "osapi-countsem-impl.h" +#include "osapi-dir-impl.h" +#include "osapi-file-impl.h" +#include "osapi-filesys-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-module-impl.h" +#include "osapi-mutex-impl.h" +#include "osapi-network-impl.h" +#include "osapi-printf-impl.h" +#include "osapi-queue-impl.h" +#include "osapi-sockets-impl.h" +#include "osapi-task-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-time-impl.h" OS_SharedGlobalVars_t OS_SharedGlobalVars = { @@ -42,6 +58,9 @@ OS_SharedGlobalVars_t OS_SharedGlobalVars = .ShutdownFlag = 0, .MicroSecPerTick = 0, /* invalid, _must_ be set by implementation init */ .TicksPerSecond = 0, /* invalid, _must_ be set by implementation init */ +#if defined(OSAL_CONFIG_DEBUG_PRINTF) + .DebugLevel = 1, +#endif }; /* @@ -51,7 +70,7 @@ OS_SharedGlobalVars_t OS_SharedGlobalVars = */ - + /*---------------------------------------------------------------- * * Function: OS_API_Init @@ -164,7 +183,7 @@ int32 OS_API_Init(void) return(return_code); } /* end OS_API_Init */ - + /*---------------------------------------------------------------- * * Function: OS_ApplicationExit @@ -194,7 +213,7 @@ void OS_ApplicationExit(int32 Status) Returns: None ---------------------------------------------------------------------------------------*/ - + /*---------------------------------------------------------------- * * Function: OS_CleanUpObject @@ -245,7 +264,7 @@ void OS_CleanUpObject(uint32 object_id, void *arg) } } /* end OS_CleanUpObject */ - + /*---------------------------------------------------------------- * * Function: OS_DeleteAllObjects @@ -278,7 +297,7 @@ void OS_DeleteAllObjects(void) while (ObjectCount > 0 && TryCount < 5); } /* end OS_DeleteAllObjects */ - + /*---------------------------------------------------------------- * * Function: OS_IdleLoop @@ -301,7 +320,7 @@ void OS_IdleLoop() } /* end OS_IdleLoop */ - + /*---------------------------------------------------------------- * * Function: OS_ApplicationShutdown diff --git a/src/os/shared/osapi-countsem.c b/src/os/shared/src/osapi-countsem.c similarity index 90% rename from src/os/shared/osapi-countsem.c rename to src/os/shared/src/osapi-countsem.c index b7e08f63c..0862c92da 100644 --- a/src/os/shared/osapi-countsem.c +++ b/src/os/shared/src/osapi-countsem.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-countsem.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-countsem.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -31,8 +32,9 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-countsem-impl.h" +#include "osapi-idmap-impl.h" + /* * Sanity checks on the user-supplied configuration @@ -52,14 +54,14 @@ enum LOCAL_OBJID_TYPE = OS_OBJECT_TYPE_OS_COUNTSEM }; -OS_apiname_internal_record_t OS_count_sem_table [LOCAL_NUM_OBJECTS]; +OS_count_sem_internal_record_t OS_count_sem_table [LOCAL_NUM_OBJECTS]; /**************************************************************************************** SEMAPHORE API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_CountSemAPI_Init @@ -75,7 +77,7 @@ int32 OS_CountSemAPI_Init(void) } /* end OS_CountSemAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemCreate @@ -121,7 +123,7 @@ int32 OS_CountSemCreate (uint32 *sem_id, const char *sem_name, uint32 sem_initia } /* end OS_CountSemCreate */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemDelete @@ -156,7 +158,7 @@ int32 OS_CountSemDelete (uint32 sem_id) } /* end OS_CountSemDelete */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGive @@ -182,7 +184,7 @@ int32 OS_CountSemGive ( uint32 sem_id ) } /* end OS_CountSemGive */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTake @@ -207,7 +209,7 @@ int32 OS_CountSemTake ( uint32 sem_id ) return return_code; } /* end OS_CountSemTake */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemTimedWait @@ -232,7 +234,7 @@ int32 OS_CountSemTimedWait ( uint32 sem_id, uint32 msecs ) return return_code; } /* end OS_CountSemTimedWait */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGetIdByName @@ -255,7 +257,7 @@ int32 OS_CountSemGetIdByName (uint32 *sem_id, const char *sem_name) return return_code; } /* end OS_CountSemGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_CountSemGetInfo diff --git a/src/os/shared/src/osapi-debug.c b/src/os/shared/src/osapi-debug.c new file mode 100644 index 000000000..303d0fbdf --- /dev/null +++ b/src/os/shared/src/osapi-debug.c @@ -0,0 +1,63 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file osapi-debug.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov + * + * Contains the implementation for OS_DEBUG(). + * + * This is only compiled in when OSAL_CONFIG_DEBUG_PRINTF is enabled. + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ +#include +#include +#include +#include + + +/* + * User defined include files + */ +#include "osapi-shared-globaldefs.h" +#include "osapi-common-impl.h" + +#define OS_DEBUG_OUTPUT_STREAM stdout + + + +/*---------------------------------------------------------------- + * + * Function: OS_DebugPrintf + * + * Purpose: Outputs a single debug statement to the console + * + *-----------------------------------------------------------------*/ +void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *Format, ...) +{ + va_list va; + + if (OS_SharedGlobalVars.DebugLevel >= Level) + { + va_start(va, Format); + fprintf(OS_DEBUG_OUTPUT_STREAM, "%s():%d:",Func,Line); + vfprintf(OS_DEBUG_OUTPUT_STREAM, Format, va); + va_end(va); + } + +} /* end OS_DebugPrintf */ + diff --git a/src/os/shared/osapi-dir.c b/src/os/shared/src/osapi-dir.c similarity index 92% rename from src/os/shared/osapi-dir.c rename to src/os/shared/src/osapi-dir.c index 10d554321..f158b9143 100644 --- a/src/os/shared/osapi-dir.c +++ b/src/os/shared/src/osapi-dir.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-dir.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-dir.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -31,8 +32,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-dir-impl.h" +#include "osapi-idmap-impl.h" /* @@ -75,7 +76,7 @@ typedef union DIRECTORY API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_DirAPI_Init @@ -90,7 +91,7 @@ int32 OS_DirAPI_Init(void) return OS_SUCCESS; } /* end OS_DirAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_mkdir @@ -114,7 +115,7 @@ int32 OS_mkdir (const char *path, uint32 access) } /* end OS_mkdir */ - + /*---------------------------------------------------------------- * * Function: OS_DirectoryOpen @@ -158,7 +159,7 @@ int32 OS_DirectoryOpen(uint32 *dir_id, const char *path) } /* end OS_DirectoryOpen */ - + /*---------------------------------------------------------------- * * Function: OS_DirectoryClose @@ -192,7 +193,7 @@ int32 OS_DirectoryClose(uint32 dir_id) return return_code; } /* end OS_DirectoryClose */ - + /*---------------------------------------------------------------- * * Function: OS_DirectoryRead @@ -235,7 +236,7 @@ int32 OS_DirectoryRead(uint32 dir_id, os_dirent_t *dirent) } /* end OS_DirectoryRead */ - + /*---------------------------------------------------------------- * * Function: OS_DirectoryRewind @@ -260,7 +261,7 @@ int32 OS_DirectoryRewind(uint32 dir_id) return return_code; } /* end OS_DirectoryRewind */ - + /*---------------------------------------------------------------- * * Function: OS_rmdir @@ -288,9 +289,9 @@ int32 OS_rmdir (const char *path) * Compatibility layers for old-style API */ #ifndef OSAL_OMIT_DEPRECATED - + /*---------------------------------------------------------------- - + * Function: OS_opendir * * Purpose: Open a directory. Deprecated function. @@ -306,7 +307,7 @@ os_dirp_t OS_opendir (const char *path) return dirdescptr.dirp; } /* end OS_opendir */ - + /*---------------------------------------------------------------- * * Function: OS_closedir diff --git a/src/os/shared/osapi-errors.c b/src/os/shared/src/osapi-errors.c similarity index 87% rename from src/os/shared/osapi-errors.c rename to src/os/shared/src/osapi-errors.c index 7d985b0b8..a82ee01ce 100644 --- a/src/os/shared/osapi-errors.c +++ b/src/os/shared/src/osapi-errors.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-errors.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-errors.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * Contains the code related to error handling. Currently this * entails conversion of OSAL error codes into printable strings. */ @@ -28,8 +31,7 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-errors-impl.h" /** * Global error name table @@ -83,7 +85,7 @@ static const OS_ErrorTable_Entry_t OS_GLOBAL_ERROR_NAME_TABLE[] = */ - + /*---------------------------------------------------------------- * * Function: OS_GetErrorName diff --git a/src/os/shared/osapi-file.c b/src/os/shared/src/osapi-file.c similarity index 95% rename from src/os/shared/osapi-file.c rename to src/os/shared/src/osapi-file.c index ce14cf264..d9e2dca23 100644 --- a/src/os/shared/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-file.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-file.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -30,8 +31,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-file-impl.h" +#include "osapi-idmap-impl.h" /* @@ -54,7 +55,7 @@ enum OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; - + /*---------------------------------------------------------------- * * Function: OS_check_name_length @@ -93,7 +94,7 @@ static int32 OS_check_name_length(const char *path) FILE API ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_FileAPI_Init @@ -159,7 +160,7 @@ static int32 OS_OpenCreate(uint32 *filedes, const char *path, int32 flags, int32 return return_code; } /* end OS_OpenCreate */ - + /*---------------------------------------------------------------- * * Function: OS_creat @@ -197,7 +198,7 @@ int32 OS_creat (const char *path, int32 access) return return_code; } /* end OS_creat */ - + /*---------------------------------------------------------------- * * Function: OS_open @@ -235,7 +236,7 @@ int32 OS_open (const char *path, int32 access, uint32 mode) } /* end OS_open */ - + /*---------------------------------------------------------------- * * Function: OS_close @@ -270,7 +271,7 @@ int32 OS_close (uint32 filedes) } /* end OS_close */ - + /*---------------------------------------------------------------- * * Function: OS_TimedRead @@ -301,7 +302,7 @@ int32 OS_TimedRead(uint32 filedes, void *buffer, uint32 nbytes, int32 timeout) return return_code; } /* end OS_TimedRead */ - + /*---------------------------------------------------------------- * * Function: OS_TimedWrite @@ -332,7 +333,7 @@ int32 OS_TimedWrite(uint32 filedes, const void *buffer, uint32 nbytes, int32 ti return return_code; } /* end OS_TimedWrite */ - + /*---------------------------------------------------------------- * * Function: OS_read @@ -346,7 +347,7 @@ int32 OS_read (uint32 filedes, void *buffer, uint32 nbytes) return OS_TimedRead(filedes, buffer, nbytes, OS_PEND); } /* end OS_read */ - + /*---------------------------------------------------------------- * * Function: OS_write @@ -361,7 +362,7 @@ int32 OS_write (uint32 filedes, const void *buffer, uint32 nbytes) } /* end OS_write */ - + /*---------------------------------------------------------------- * * Function: OS_chmod @@ -385,7 +386,7 @@ int32 OS_chmod (const char *path, uint32 access) } /* end OS_chmod */ - + /*---------------------------------------------------------------- * * Function: OS_stat @@ -415,7 +416,7 @@ int32 OS_stat (const char *path, os_fstat_t *filestats) return return_code; } /* end OS_stat */ - + /*---------------------------------------------------------------- * * Function: OS_lseek @@ -441,7 +442,7 @@ int32 OS_lseek (uint32 filedes, int32 offset, uint32 whence) return return_code; } /* end OS_lseek */ - + /*---------------------------------------------------------------- * * Function: OS_remove @@ -469,7 +470,7 @@ int32 OS_remove (const char *path) } /* end OS_remove */ - + /*---------------------------------------------------------------- * * Function: OS_rename @@ -523,7 +524,7 @@ int32 OS_rename (const char *old, const char *new) } /* end OS_rename */ - + /*---------------------------------------------------------------- * * Function: OS_cp @@ -601,7 +602,7 @@ int32 OS_cp (const char *src, const char *dest) } /* end OS_cp */ - + /*---------------------------------------------------------------- * * Function: OS_mv @@ -631,7 +632,7 @@ int32 OS_mv (const char *src, const char *dest) - + /*---------------------------------------------------------------- * * Function: OS_FDGetInfo @@ -668,7 +669,7 @@ int32 OS_FDGetInfo (uint32 filedes, OS_file_prop_t *fd_prop) } /* end OS_FDGetInfo */ - + /*---------------------------------------------------------------- * * Function: OS_FileOpenCheck @@ -708,7 +709,7 @@ int32 OS_FileOpenCheck(const char *Filename) } /* end OS_FileOpenCheck */ - + /*---------------------------------------------------------------- * * Function: OS_CloseFileByName @@ -756,7 +757,7 @@ int32 OS_CloseFileByName(const char *Filename) } /* end OS_CloseFileByName */ - + /*---------------------------------------------------------------- * * Function: OS_CloseAllFiles @@ -797,7 +798,7 @@ int32 OS_CloseAllFiles(void) } /* end OS_CloseAllFiles */ - + /*---------------------------------------------------------------- * * Function: OS_ShellOutputToFile diff --git a/src/os/shared/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c similarity index 95% rename from src/os/shared/osapi-filesys.c rename to src/os/shared/src/osapi-filesys.c index 21fca38bf..e9339187e 100644 --- a/src/os/shared/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -1,22 +1,24 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-filesys.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-filesys.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * - * */ /**************************************************************************************** @@ -31,8 +33,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-filesys-impl.h" +#include "osapi-idmap-impl.h" enum { @@ -66,7 +68,7 @@ extern const OS_VolumeInfo_t OS_VolumeTable[]; #define OS_COMPAT_VOLTAB_SIZE 0 #endif - + /*---------------------------------------------------------------- * * Function: OS_FileSys_FindVirtMountPoint @@ -78,7 +80,7 @@ extern const OS_VolumeInfo_t OS_VolumeTable[]; * Returns: true if the entry matches, false if it does not match * *-----------------------------------------------------------------*/ -static bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj) { OS_filesys_internal_record_t *rec = &OS_filesys_table[local_id]; const char *target = (const char*)ref; @@ -94,7 +96,7 @@ static bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_c (target[mplen] == '/' || target[mplen] == 0)); } /* end OS_FileSys_FindVirtMountPoint */ - + /*---------------------------------------------------------------- * * Function: OS_FileSys_InitLocalFromVolTable @@ -106,7 +108,7 @@ static bool OS_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_c * Returns: OS_SUCCESS on success or appropriate error code. * *-----------------------------------------------------------------*/ -static int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, const OS_VolumeInfo_t *Vol) +int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, const OS_VolumeInfo_t *Vol) { int32 return_code = OS_SUCCESS; @@ -194,7 +196,7 @@ static int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *loca return return_code; } /* end OS_FileSys_InitLocalFromVolTable */ - + /*---------------------------------------------------------------- * * Function: OS_FileSys_SetupInitialParamsForDevice @@ -206,7 +208,7 @@ static int32 OS_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *loca * Returns: OS_SUCCESS on success or appropriate error code. * *-----------------------------------------------------------------*/ -static int32 OS_FileSys_SetupInitialParamsForDevice(const char *devname, OS_filesys_internal_record_t *local) +int32 OS_FileSys_SetupInitialParamsForDevice(const char *devname, OS_filesys_internal_record_t *local) { const OS_VolumeInfo_t *Vol; int32 return_code; @@ -228,7 +230,7 @@ static int32 OS_FileSys_SetupInitialParamsForDevice(const char *devname, OS_file return return_code; } /* end OS_FileSys_SetupInitialParamsForDevice */ - + /*---------------------------------------------------------------- * * Function: OS_FileSys_Initialize @@ -240,7 +242,7 @@ static int32 OS_FileSys_SetupInitialParamsForDevice(const char *devname, OS_file * Returns: OS_FS_SUCCESS on creating the disk, or appropriate error code. * *-----------------------------------------------------------------*/ -static int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char * fsvolname, uint32 blocksize, +int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const char * fsvolname, uint32 blocksize, uint32 numblocks, bool should_format) { OS_common_record_t *global; @@ -345,7 +347,7 @@ static int32 OS_FileSys_Initialize(char *address, const char *fsdevname, const c INITIALIZATION ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_FileSysAPI_Init @@ -412,7 +414,7 @@ int32 OS_FileSysAPI_Init(void) return return_code; } /* end OS_FileSysAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysAddFixedMap @@ -491,7 +493,7 @@ int32 OS_FileSysAddFixedMap(uint32 *filesys_id, const char *phys_path, const cha return return_code; } /* end OS_FileSysAddFixedMap */ - + /*---------------------------------------------------------------- * * Function: OS_mkfs @@ -524,7 +526,7 @@ int32 OS_mkfs (char *address, const char *devname, const char * volname, uint32 } /* end OS_mkfs */ - + /*---------------------------------------------------------------- * * Function: OS_rmfs @@ -581,7 +583,7 @@ int32 OS_rmfs (const char *devname) return return_code; } /* end OS_rmfs */ - + /*---------------------------------------------------------------- * * Function: OS_initfs @@ -614,7 +616,7 @@ int32 OS_initfs (char *address,const char *devname, const char *volname, } /* end OS_initfs */ - + /*---------------------------------------------------------------- * * Function: OS_mount @@ -693,7 +695,7 @@ int32 OS_mount (const char *devname, const char* mountpoint) } /* end OS_mount */ - + /*---------------------------------------------------------------- * * Function: OS_unmount @@ -771,7 +773,7 @@ int32 OS_unmount (const char *mountpoint) return return_code; } /* end OS_unmount */ - + /*---------------------------------------------------------------- * * Function: OS_fsBlocksFree @@ -823,7 +825,7 @@ int32 OS_fsBlocksFree (const char *name) } /* end OS_fsBlocksFree */ - + /*---------------------------------------------------------------- * * Function: OS_fsBytesFree @@ -876,7 +878,7 @@ int32 OS_fsBytesFree (const char *name, uint64 *bytes_free) } /* end OS_fsBytesFree */ - + /*---------------------------------------------------------------- * * Function: OS_chkfs @@ -924,7 +926,7 @@ int32 OS_chkfs (const char *name, bool repair) } /* end OS_chkfs */ - + /*---------------------------------------------------------------- * * Function: OS_FS_GetPhysDriveName @@ -981,7 +983,7 @@ int32 OS_FS_GetPhysDriveName(char * PhysDriveName, const char * MountPoint) } /* end OS_FS_GetPhysDriveName */ - + /*---------------------------------------------------------------- * * Function: OS_GetFsInfo @@ -1034,7 +1036,7 @@ int32 OS_GetFsInfo(os_fsinfo_t *filesys_info) return(OS_FS_SUCCESS); } /* end OS_GetFsInfo */ - + /*---------------------------------------------------------------- * * Function: OS_TranslatePath diff --git a/src/os/shared/osapi-fpu.c b/src/os/shared/src/osapi-fpu.c similarity index 81% rename from src/os/shared/osapi-fpu.c rename to src/os/shared/src/osapi-fpu.c index 48cbddd28..b8c179928 100644 --- a/src/os/shared/osapi-fpu.c +++ b/src/os/shared/src/osapi-fpu.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-fpu.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-fpu.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * Contains the code related to floating point mode setting. * Implementation of these are mostly in the lower layer; however * a wrapper must exist at this level which allows for unit testing. @@ -29,9 +32,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" - +#include "osapi-fpu-impl.h" + /*---------------------------------------------------------------- * * Function: OS_FPUExcAttachHandler @@ -51,7 +53,7 @@ int32 OS_FPUExcAttachHandler (uint32 ExceptionNumber, osal_task_entry Exceptio return OS_FPUExcAttachHandler_Impl(ExceptionNumber, ExceptionHandler, parameter); } /* end OS_FPUExcAttachHandler */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcSetMask @@ -65,7 +67,7 @@ int32 OS_FPUExcSetMask(uint32 mask) return OS_FPUExcSetMask_Impl(mask); } /* end OS_FPUExcSetMask */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcGetMask @@ -83,7 +85,7 @@ int32 OS_FPUExcGetMask(uint32 *mask) return OS_FPUExcGetMask_Impl(mask); } /* end OS_FPUExcGetMask */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcEnable @@ -96,7 +98,7 @@ int32 OS_FPUExcEnable (int32 ExceptionNumber) { return OS_FPUExcEnable_Impl(ExceptionNumber); } /* end OS_FPUExcEnable */ - + /*---------------------------------------------------------------- * * Function: OS_FPUExcDisable diff --git a/src/os/shared/osapi-heap.c b/src/os/shared/src/osapi-heap.c similarity index 64% rename from src/os/shared/osapi-heap.c rename to src/os/shared/src/osapi-heap.c index 0cbda348f..0e940b983 100644 --- a/src/os/shared/osapi-heap.c +++ b/src/os/shared/src/osapi-heap.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-heap.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-heap.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * Contains the code related to heap. * Implementation of these are mostly in the lower layer; however * a wrapper must exist at this level which allows for unit testing. @@ -29,11 +32,10 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-heap-impl.h" + - /*---------------------------------------------------------------- * * Function: OS_HeapGetInfo diff --git a/src/os/shared/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c similarity index 95% rename from src/os/shared/osapi-idmap.c rename to src/os/shared/src/osapi-idmap.c index 14a23954e..e3984f383 100644 --- a/src/os/shared/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -1,21 +1,24 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-idmap.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-idmap.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: - * This file contains utility functions to interpret OSAL IDs - * in a generic/common manner. They are used internally within - * OSAL by all the various modules. + * This file contains utility functions to interpret OSAL IDs + * in a generic/common manner. They are used internally within + * OSAL by all the various modules. * * In order to add additional verification capabilities, each class of fundamental * objects will use its own ID space within the 32-bit integer ID value. This way @@ -42,8 +45,9 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-task-impl.h" typedef enum { @@ -128,7 +132,7 @@ int32 OS_ObjectIdMap(uint32 idtype, uint32 idvalue, uint32 *result) return OS_SUCCESS; } /* end OS_ObjectIdMap */ - + /*---------------------------------------------------------------- * * Function: OS_ObjectIdUnMap @@ -148,7 +152,7 @@ int32 OS_ObjectIdUnMap(uint32 id, uint32 idtype, uint32 *idvalue) return OS_SUCCESS; } /* end OS_ObjectIdUnMap */ - + /*---------------------------------------------------------------- * * Function: OS_GetMaxForObjectType @@ -176,7 +180,7 @@ uint32 OS_GetMaxForObjectType(uint32 idtype) } } /* end OS_GetMaxForObjectType */ - + /*---------------------------------------------------------------- * * Function: OS_GetBaseForObjectType @@ -209,7 +213,7 @@ uint32 OS_GetBaseForObjectType(uint32 idtype) * (not used outside of this unit) **************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_ObjectNameMatch @@ -224,13 +228,13 @@ uint32 OS_GetBaseForObjectType(uint32 idtype) * returns: true if match, false otherwise * *-----------------------------------------------------------------*/ -static bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *obj) +bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_record_t *obj) { return (obj->name_entry != NULL && strcmp((const char*)ref, obj->name_entry) == 0); } /* end OS_ObjectNameMatch */ - + /*---------------------------------------------------------------- * * Function: OS_ObjectIdInitiateLock @@ -247,7 +251,7 @@ static bool OS_ObjectNameMatch(void *ref, uint32 local_id, const OS_common_recor * lock type requested (lock_mode). * *-----------------------------------------------------------------*/ -static void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) +void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) { if (lock_mode != OS_LOCK_MODE_NONE) { @@ -255,7 +259,7 @@ static void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) } } /* end OS_ObjectIdInitiateLock */ - + /*---------------------------------------------------------------- * * Function: OS_ObjectIdConvertLock @@ -294,7 +298,7 @@ static void OS_ObjectIdInitiateLock(OS_lock_mode_t lock_mode, uint32 idtype) * all lock modes other than OS_LOCK_MODE_NONE. * *-----------------------------------------------------------------*/ -static int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj) +int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj) { int32 return_code = OS_ERROR; uint32 exclusive_bits = 0; @@ -425,7 +429,7 @@ static int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uin * returns: OS_ERR_NAME_NOT_FOUND if not found, OS_SUCCESS if match is found * *-----------------------------------------------------------------*/ -static int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record) +int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, void *arg, OS_common_record_t **record) { int32 return_code; uint32 obj_count; @@ -480,7 +484,7 @@ static int32 OS_ObjectIdSearch(uint32 idtype, OS_ObjectMatchFunc_t MatchFunc, vo * * returns: OS_SUCCESS if an empty location was found. *-----------------------------------------------------------------*/ -static int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record) +int32 OS_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record) { uint32 max_id; uint32 base_id; @@ -975,7 +979,7 @@ int32 OS_ConvertToArrayIndex(uint32 object_id, uint32 *ArrayIndex) return return_code; } /* end OS_ConvertToArrayIndex */ - + /*---------------------------------------------------------------- * * Function: OS_ForEachObject diff --git a/src/os/shared/osapi-interrupts.c b/src/os/shared/src/osapi-interrupts.c similarity index 83% rename from src/os/shared/osapi-interrupts.c rename to src/os/shared/src/osapi-interrupts.c index 86d804580..052dbee20 100644 --- a/src/os/shared/osapi-interrupts.c +++ b/src/os/shared/src/osapi-interrupts.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-interrupts.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-interrupts.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * Contains the code related to interrupt handling. * Implementation of these are mostly in the lower layer; however * a wrapper must exist at this level which allows for unit testing. @@ -29,12 +32,11 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-interrupts-impl.h" #ifndef OSAL_OMIT_DEPRECATED /* Remove file and remove from build when deleted */ /* Optionally remove from sources once source selection is in cmake options */ - + /*---------------------------------------------------------------- * * Function: OS_IntAttachHandler @@ -53,7 +55,7 @@ int32 OS_IntAttachHandler (uint32 InterruptNumber, osal_task_entry InterruptHan return OS_IntAttachHandler_Impl(InterruptNumber, InterruptHandler, parameter); } /* end OS_IntAttachHandler */ - + /*---------------------------------------------------------------- * * Function: OS_IntUnlock @@ -67,7 +69,7 @@ int32 OS_IntUnlock (int32 IntFlags) return OS_IntUnlock_Impl(IntFlags); } /* end OS_IntUnlock */ - + /*---------------------------------------------------------------- * * Function: OS_IntLock @@ -81,7 +83,7 @@ int32 OS_IntLock ( void ) return OS_IntLock_Impl(); } /* end OS_IntLock */ - + /*---------------------------------------------------------------- * * Function: OS_IntEnable @@ -95,7 +97,7 @@ int32 OS_IntEnable(int32 Level) return OS_IntEnable_Impl(Level); } /* end OS_IntEnable */ - + /*---------------------------------------------------------------- * * Function: OS_IntDisable @@ -109,7 +111,7 @@ int32 OS_IntDisable(int32 Level) return OS_IntDisable_Impl(Level); } /* end OS_IntDisable */ - + /*---------------------------------------------------------------- * * Function: OS_IntSetMask @@ -123,7 +125,7 @@ int32 OS_IntSetMask ( uint32 MaskSetting ) return OS_IntSetMask_Impl(MaskSetting); } /* end OS_IntSetMask */ - + /*---------------------------------------------------------------- * * Function: OS_IntGetMask diff --git a/src/os/shared/osapi-module.c b/src/os/shared/src/osapi-module.c similarity index 77% rename from src/os/shared/osapi-module.c rename to src/os/shared/src/osapi-module.c index 4a10f3e21..4632835d1 100644 --- a/src/os/shared/osapi-module.c +++ b/src/os/shared/src/osapi-module.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-module.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-module.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -30,8 +31,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-module-impl.h" +#include "osapi-idmap-impl.h" /* * Sanity checks on the user-supplied configuration @@ -40,8 +41,8 @@ * OS_MAX_MODULES is allowed to be zero in which case the * table is not instantiated. */ -#if !defined(OS_MAX_MODULES) || (OS_MAX_MODULES < 0) -#error "osconfig.h must define OS_MAX_ to a valid value" +#if !defined(OS_MAX_MODULES) || (OS_MAX_MODULES <= 0) +#error "osconfig.h must define OS_MAX_MODULES to a valid value" #endif @@ -51,25 +52,18 @@ enum LOCAL_OBJID_TYPE = OS_OBJECT_TYPE_OS_MODULE }; -/* - * Only instantiate the "OS_module_table" if - * OS_MAX_MODULES configuration is greater than 0. - * It is allowed to be zero on statically linked apps. - */ -#if (OS_MAX_MODULES > 0) OS_module_internal_record_t OS_module_table[OS_MAX_MODULES]; -#endif /* * If the "OS_STATIC_LOADER" directive is enabled, * then the user application/BSP must provide a symbol * called "OS_STATIC_SYMBOL_TABLE" which will provide * user-defined mappings of symbol names to addresses. - * + * * Note - when compiling unit tests, the UT code will * supply a custom definition for OS_STATIC_SYMTABLE_SOURCE */ -#if !defined(OS_STATIC_SYMTABLE_SOURCE) && defined(OS_STATIC_LOADER) +#if !defined(OS_STATIC_SYMTABLE_SOURCE) && defined(OSAL_CONFIG_INCLUDE_STATIC_LOADER) /* use default symbol name for static table */ #define OS_STATIC_SYMTABLE_SOURCE OS_STATIC_SYMBOL_TABLE #endif @@ -90,7 +84,7 @@ extern OS_static_symbol_record_t OS_STATIC_SYMTABLE_SOURCE[]; * Checks for a symbol name in the static symbol table * *-----------------------------------------------------------------*/ -static int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) +int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) { int32 return_code = OS_ERR_NOT_IMPLEMENTED; OS_static_symbol_record_t *StaticSym = OS_STATIC_SYMTABLE_SOURCE; @@ -119,7 +113,7 @@ static int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolNa return return_code; } /* end OS_SymbolLookup_Static */ - + /*---------------------------------------------------------------- * * Function: OS_ModuleLoad_Static @@ -128,7 +122,7 @@ static int32 OS_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolNa * Checks for a module name in the static symbol table * *-----------------------------------------------------------------*/ -static int32 OS_ModuleLoad_Static(const char *ModuleName) +int32 OS_ModuleLoad_Static(const char *ModuleName) { int32 return_code = OS_ERR_NAME_NOT_FOUND; OS_static_symbol_record_t *StaticSym = OS_STATIC_SYMTABLE_SOURCE; @@ -169,9 +163,7 @@ static int32 OS_ModuleLoad_Static(const char *ModuleName) *-----------------------------------------------------------------*/ int32 OS_ModuleAPI_Init(void) { -#if (OS_MAX_MODULES > 0) memset(OS_module_table, 0, sizeof(OS_module_table)); -#endif return OS_SUCCESS; } /* end OS_ModuleAPI_Init */ @@ -188,13 +180,17 @@ int32 OS_ModuleLoad ( uint32 *module_id, const char *module_name, const char *fi { char translated_path[OS_MAX_LOCAL_PATH_LEN]; int32 return_code; + int32 filename_status; uint32 local_id; OS_common_record_t *record; /* ** Check parameters + ** + ** Note "filename" is not checked, because in certain configurations it can be validly + ** null. filename is checked for NULL-ness by the OS_TranslatePath() later. */ - if (( filename == NULL ) || (module_id == NULL ) || (module_name == NULL)) + if ((module_id == NULL ) || (module_name == NULL)) { return(OS_INVALID_POINTER); } @@ -205,44 +201,56 @@ int32 OS_ModuleLoad ( uint32 *module_id, const char *module_name, const char *fi } /* - * Check the statically-linked module list. - * If a matching entry is found, this means its - * already effectively "loaded" through static linkage. - * Return success without any more action. - */ - return_code = OS_ModuleLoad_Static(module_name); - if (return_code == OS_SUCCESS) - { - *module_id = 0; - return OS_SUCCESS; - } - - /* - ** Translate the filename to the Host System + * Preemptively translate the filename, and hold it in a temporary buffer. + * + * This should be done before allocating a new object ID because it also + * locks the global table, and this prevents double-locking. + * + * The status of this operation is stored separately, because it may or + * may not be relevant, depending on whether the static module table is enabled. */ - return_code = OS_TranslatePath(filename, translated_path); - if ( return_code != OS_SUCCESS ) - { - return(return_code); - } + filename_status = OS_TranslatePath(filename, translated_path); /* Note - the common ObjectIdAllocate routine will lock the object type and leave it locked. */ return_code = OS_ObjectIdAllocateNew(LOCAL_OBJID_TYPE, module_name, &local_id, &record); if(return_code == OS_SUCCESS) { - /* - * Save all the data to our own internal module table, but - * only if OS_MAX_MODULES is greater than 0 - */ -#if (OS_MAX_MODULES > 0) memset(&OS_module_table[local_id], 0, sizeof(OS_module_internal_record_t)); strncpy(OS_module_table[local_id].module_name, module_name, OS_MAX_API_NAME); - strncpy(OS_module_table[local_id].file_name, filename, OS_MAX_PATH_LEN); record->name_entry = OS_module_table[local_id].module_name; - /* Now call the OS-specific implementation. This reads info from the module table. */ - return_code = OS_ModuleLoad_Impl(local_id, translated_path); -#endif + /* + * Check the statically-linked module list. + * If a matching entry is found, this means its + * already effectively "loaded" through static linkage. + * Return success without any more action. + * + * If the OSAL_CONFIG_INCLUDE_STATIC_LOADER feature is disabled, + * then the list of static modules is empty and this always + * returns OS_ERR_NAME_NOT_FOUND. + */ + return_code = OS_ModuleLoad_Static(module_name); + if (return_code != OS_SUCCESS) + { + /* + * If this is NOT a static module, then the module file must be loaded by normal + * means using the dynamic loader, if available. This also means the filename + * must be valid, so this is when the "filename_status" is checked/enforced. + */ + if (filename_status != OS_SUCCESS) + { + /* supplied filename was not valid */ + return_code = filename_status; + } + else + { + /* supplied filename was valid, so store a copy for future reference */ + strncpy(OS_module_table[local_id].file_name, filename, OS_MAX_PATH_LEN); + + /* Now call the OS-specific implementation. This reads info from the module table. */ + return_code = OS_ModuleLoad_Impl(local_id, translated_path); + } + } /* Check result, finalize record, and unlock global table. */ return_code = OS_ObjectIdFinalizeNew(return_code, record, module_id); @@ -312,14 +320,10 @@ int32 OS_ModuleInfo ( uint32 module_id, OS_module_prop_t *module_prop ) return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL,LOCAL_OBJID_TYPE, module_id, &local_id, &record); if (return_code == OS_SUCCESS) { - -#if (OS_MAX_MODULES > 0) strncpy(module_prop->name, record->name_entry, OS_MAX_API_NAME - 1); strncpy(module_prop->filename, OS_module_table[local_id].file_name, OS_MAX_API_NAME - 1); - /* module_prop->creator = record->creator; */ return_code = OS_ModuleGetInfo_Impl(local_id, module_prop); -#endif OS_Unlock_Global_Impl(LOCAL_OBJID_TYPE); } diff --git a/src/os/shared/osapi-mutex.c b/src/os/shared/src/osapi-mutex.c similarity index 88% rename from src/os/shared/osapi-mutex.c rename to src/os/shared/src/osapi-mutex.c index f141b9945..4f0ca888a 100644 --- a/src/os/shared/osapi-mutex.c +++ b/src/os/shared/src/osapi-mutex.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-mutex.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-mutex.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -31,8 +32,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-mutex-impl.h" /* @@ -52,7 +53,7 @@ enum LOCAL_OBJID_TYPE = OS_OBJECT_TYPE_OS_MUTEX }; -OS_apiname_internal_record_t OS_mutex_table [LOCAL_NUM_OBJECTS]; +OS_mutex_internal_record_t OS_mutex_table [LOCAL_NUM_OBJECTS]; /**************************************************************************************** @@ -151,7 +152,7 @@ int32 OS_MutSemDelete (uint32 sem_id) } /* end OS_MutSemDelete */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGive @@ -177,7 +178,7 @@ int32 OS_MutSemGive ( uint32 sem_id ) } /* end OS_MutSemGive */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemTake @@ -202,7 +203,7 @@ int32 OS_MutSemTake ( uint32 sem_id ) return return_code; } /* end OS_MutSemTake */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGetIdByName @@ -226,7 +227,7 @@ int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name) } /* end OS_MutSemGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_MutSemGetInfo @@ -235,7 +236,7 @@ int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name) * See description in API and header file for detail * *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo (uint32 sem_id, OS_mutex_prop_t *mut_prop) { OS_common_record_t *record; int32 return_code; @@ -247,7 +248,7 @@ int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) return OS_INVALID_POINTER; } - memset(mut_prop,0,sizeof(OS_mut_sem_prop_t)); + memset(mut_prop,0,sizeof(OS_mutex_prop_t)); return_code = OS_ObjectIdGetById(OS_LOCK_MODE_GLOBAL,LOCAL_OBJID_TYPE, sem_id, &local_id, &record); if (return_code == OS_SUCCESS) diff --git a/src/os/shared/osapi-network.c b/src/os/shared/src/osapi-network.c similarity index 80% rename from src/os/shared/osapi-network.c rename to src/os/shared/src/osapi-network.c index e508de36e..337e775d4 100644 --- a/src/os/shared/osapi-network.c +++ b/src/os/shared/src/osapi-network.c @@ -1,22 +1,23 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-network.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-network.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. - * - * */ /**************************************************************************************** @@ -30,8 +31,7 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-network-impl.h" /**************************************************************************************** @@ -51,7 +51,7 @@ int32 OS_NetworkAPI_Init(void) } /* end OS_NetworkAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_NetworkGetHostName @@ -89,7 +89,7 @@ int32 OS_NetworkGetHostName (char *host_name, uint32 name_len) - + /*---------------------------------------------------------------- * * Function: OS_NetworkGetID diff --git a/src/os/shared/osapi-printf.c b/src/os/shared/src/osapi-printf.c similarity index 84% rename from src/os/shared/osapi-printf.c rename to src/os/shared/src/osapi-printf.c index 6f1c782d0..7c4b04bc3 100644 --- a/src/os/shared/osapi-printf.c +++ b/src/os/shared/src/osapi-printf.c @@ -1,18 +1,20 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-printf.c - * \author joseph.p.hickey@nasa.gov - * - * Purpose: + * \file osapi-printf.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * * Contains the abstraction for the OS_printf() call. * @@ -30,7 +32,6 @@ * to a console device but may alternatively write to any other * implementation-defined output interface, such as a system log or * serial port. - * */ /**************************************************************************************** @@ -44,44 +45,11 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" - -/* - * The OS_BUFFER_SIZE and OS_BUFFER_MSG_DEPTH - * directives pertain to the printf() buffer. - * - * In conjuction with a "utility task" this decouples - * the OS_printf() call from the actual console output, - * intended for systems where the console is a slow - * serial link that can block. - * - * These are both typically defined in osconfig.h, - * but if not, then supply default values here. - */ -#ifndef OS_BUFFER_SIZE -#define OS_BUFFER_SIZE 172 -#endif - -#ifndef OS_BUFFER_MSG_DEPTH -/* When using the utility task, buffer up to 100 messages by default */ -#define OS_BUFFER_MSG_DEPTH 100 -#endif +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-printf-impl.h" -/* - * The OS_PRINTF_CONSOLE_NAME, if defined, will be pre-pended to the content of - * every call to OS_printf(). This can be a useful feature to provide - * some visual differentiation between strings produced from OS_printf() - * versus other debug prints. - * - * If desired, it can be specified in osconfig.h. Otherwise the empty - * string will be used (no added tag). - */ -#ifndef OS_PRINTF_CONSOLE_NAME -#define OS_PRINTF_CONSOLE_NAME "" -#endif - /* reserve buffer memory for the printf console device */ static char OS_printf_buffer_mem[(sizeof(OS_PRINTF_CONSOLE_NAME) + OS_BUFFER_SIZE) * OS_BUFFER_MSG_DEPTH]; @@ -94,7 +62,7 @@ OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; ********************************************************************************* */ - + /*---------------------------------------------------------------- * * Function: OS_ConsoleAPI_Init @@ -121,7 +89,8 @@ int32 OS_ConsoleAPI_Init(void) console = &OS_console_table[local_id]; record->name_entry = console->device_name; - strcpy(console->device_name, OS_PRINTF_CONSOLE_NAME); + strncpy(console->device_name, OS_PRINTF_CONSOLE_NAME, sizeof(console->device_name)-1); + console->device_name[sizeof(console->device_name)-1] = 0; /* * Initialize the ring buffer pointers @@ -209,7 +178,7 @@ static int32 OS_Console_CopyOut(OS_console_internal_record_t *console, const cha ********************************************************************************* */ - + /*---------------------------------------------------------------- * * Function: OS_ConsoleWrite @@ -275,7 +244,7 @@ int32 OS_ConsoleWrite(uint32 console_id, const char *Str) } /* end OS_ConsoleWrite */ - + /*---------------------------------------------------------------- * * Function: OS_printf @@ -339,7 +308,7 @@ void OS_printf( const char *String, ...) } /* end OS_printf */ - + /*---------------------------------------------------------------- * * Function: OS_printf_disable @@ -353,7 +322,7 @@ void OS_printf_disable(void) OS_SharedGlobalVars.PrintfEnabled = false; } /* end OS_printf_disable */ - + /*---------------------------------------------------------------- * * Function: OS_printf_enable diff --git a/src/os/shared/osapi-queue.c b/src/os/shared/src/osapi-queue.c similarity index 91% rename from src/os/shared/osapi-queue.c rename to src/os/shared/src/osapi-queue.c index 010c556b0..3782945dd 100644 --- a/src/os/shared/osapi-queue.c +++ b/src/os/shared/src/osapi-queue.c @@ -1,25 +1,27 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-queue.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-queue.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * * This code only uses very basic C library calls that are expected * to be available on every sane C-language compiler. For everything else, * a platform-specific implementation function is used. - * */ /**************************************************************************************** @@ -34,9 +36,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" - +#include "osapi-queue-impl.h" +#include "osapi-idmap-impl.h" /* * Sanity checks on the user-supplied configuration @@ -76,7 +77,7 @@ int32 OS_QueueAPI_Init(void) } /* end OS_QueueAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_QueueCreate @@ -123,7 +124,7 @@ int32 OS_QueueCreate (uint32 *queue_id, const char *queue_name, uint32 queue_dep } /* end OS_QueueCreate */ - + /*---------------------------------------------------------------- * * Function: OS_QueueDelete @@ -157,7 +158,7 @@ int32 OS_QueueDelete (uint32 queue_id) } /* end OS_QueueDelete */ - + /*---------------------------------------------------------------- * * Function: OS_QueueGet @@ -200,7 +201,7 @@ int32 OS_QueueGet (uint32 queue_id, void *data, uint32 size, uint32 *size_copied return return_code; } /* end OS_QueueGet */ - + /*---------------------------------------------------------------- * * Function: OS_QueuePut @@ -233,7 +234,7 @@ int32 OS_QueuePut (uint32 queue_id, const void *data, uint32 size, uint32 flags) } /* end OS_QueuePut */ - + /*---------------------------------------------------------------- * * Function: OS_QueueGetIdByName @@ -257,7 +258,7 @@ int32 OS_QueueGetIdByName (uint32 *queue_id, const char *queue_name) } /* end OS_QueueGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_QueueGetInfo diff --git a/src/os/shared/osapi-select.c b/src/os/shared/src/osapi-select.c similarity index 85% rename from src/os/shared/osapi-select.c rename to src/os/shared/src/osapi-select.c index 983ff64c5..fae4b52d7 100644 --- a/src/os/shared/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -1,27 +1,27 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-select.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-select.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * * This code only uses very basic C library calls that are expected * to be available on every sane C-language compiler. For everything else, * a platform-specific implementation function is used. - * - * This select API is in a separate compilation unit to aid in unit testing. - * */ /**************************************************************************************** @@ -35,8 +35,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-select-impl.h" /* @@ -44,7 +44,7 @@ * SELECT API ********************************************************************************* */ - + /*---------------------------------------------------------------- * * Function: OS_SelectSingle @@ -68,7 +68,7 @@ int32 OS_SelectSingle(uint32 objid, uint32 *StateFlags, int32 msecs) return return_code; } /* end OS_SelectSingle */ - + /*---------------------------------------------------------------- * * Function: OS_SelectMultiple @@ -91,7 +91,7 @@ int32 OS_SelectMultiple(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) return return_code; } /* end OS_SelectMultiple */ - + /*---------------------------------------------------------------- * * Function: OS_SelectFdZero @@ -105,7 +105,7 @@ int32 OS_SelectFdZero(OS_FdSet *Set) memset(Set,0,sizeof(OS_FdSet)); return OS_SUCCESS; } /* end OS_SelectFdZero */ - + /*---------------------------------------------------------------- * * Function: OS_SelectFdAdd @@ -127,7 +127,7 @@ int32 OS_SelectFdAdd(OS_FdSet *Set, uint32 objid) return return_code; } /* end OS_SelectFdAdd */ - + /*---------------------------------------------------------------- * * Function: OS_SelectFdClear @@ -149,7 +149,7 @@ int32 OS_SelectFdClear(OS_FdSet *Set, uint32 objid) return return_code; } /* end OS_SelectFdClear */ - + /*---------------------------------------------------------------- * * Function: OS_SelectFdIsSet diff --git a/src/os/shared/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c similarity index 93% rename from src/os/shared/osapi-sockets.c rename to src/os/shared/src/osapi-sockets.c index 06a7b8b0e..c590b7cfe 100644 --- a/src/os/shared/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -1,22 +1,24 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-sockets.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-sockets.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * - * */ /**************************************************************************************** @@ -31,8 +33,10 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-file-impl.h" +#include "osapi-sockets-impl.h" + /* * Global data for the API @@ -47,7 +51,7 @@ enum Init Functions ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_SocketAPI_Init @@ -65,13 +69,11 @@ int32 OS_SocketAPI_Init(void) return OS_SUCCESS; } /* end OS_SocketAPI_Init */ -#ifdef OS_INCLUDE_NETWORK - /**************************************************************************************** Local Helper Functions ***************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_CreateSocketName @@ -79,10 +81,11 @@ int32 OS_SocketAPI_Init(void) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static void OS_CreateSocketName(OS_stream_internal_record_t *sock, const OS_SockAddr_t *Addr, const char *parent_name) +void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *parent_name) { int32 len; uint16 port; + OS_stream_internal_record_t *sock = &OS_stream_table[local_id]; if (OS_SocketAddrToString_Impl(sock->stream_name, OS_MAX_API_NAME, Addr) != OS_SUCCESS) { @@ -104,7 +107,7 @@ static void OS_CreateSocketName(OS_stream_internal_record_t *sock, const OS_Sock } } /* end OS_CreateSocketName */ - + /*---------------------------------------------------------------- * * Function: OS_SocketOpen @@ -144,7 +147,7 @@ int32 OS_SocketOpen(uint32 *sock_id, OS_SocketDomain_t Domain, OS_SocketType_t T return return_code; } /* end OS_SocketOpen */ - + /*---------------------------------------------------------------- * * Function: OS_SocketBind @@ -185,7 +188,7 @@ int32 OS_SocketBind(uint32 sock_id, const OS_SockAddr_t *Addr) if (return_code == OS_SUCCESS) { - OS_CreateSocketName(&OS_stream_table[local_id], Addr, NULL); + OS_CreateSocketName(local_id, Addr, NULL); record->name_entry = OS_stream_table[local_id].stream_name; OS_stream_table[local_id].stream_state |= OS_STREAM_STATE_BOUND; } @@ -197,7 +200,7 @@ int32 OS_SocketBind(uint32 sock_id, const OS_SockAddr_t *Addr) return return_code; } /* end OS_SocketBind */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAccept @@ -275,7 +278,7 @@ int32 OS_SocketAccept(uint32 sock_id, uint32 *connsock_id, OS_SockAddr_t *Addr, if (return_code == OS_SUCCESS) { /* Generate an entry name based on the remote address */ - OS_CreateSocketName(&OS_stream_table[conn_id], Addr, record->name_entry); + OS_CreateSocketName(conn_id, Addr, record->name_entry); connrecord->name_entry = OS_stream_table[conn_id].stream_name; OS_stream_table[conn_id].stream_state |= OS_STREAM_STATE_CONNECTED; } @@ -293,7 +296,7 @@ int32 OS_SocketAccept(uint32 sock_id, uint32 *connsock_id, OS_SockAddr_t *Addr, return return_code; } /* end OS_SocketAccept */ - + /*---------------------------------------------------------------- * * Function: OS_SocketConnect @@ -350,7 +353,7 @@ int32 OS_SocketConnect(uint32 sock_id, const OS_SockAddr_t *Addr, int32 Timeout) return return_code; } /* end OS_SocketConnect */ - + /*---------------------------------------------------------------- * * Function: OS_SocketRecvFrom @@ -393,7 +396,7 @@ int32 OS_SocketRecvFrom(uint32 sock_id, void *buffer, uint32 buflen, OS_SockAddr return return_code; } /* end OS_SocketRecvFrom */ - + /*---------------------------------------------------------------- * * Function: OS_SocketSendTo @@ -432,7 +435,7 @@ int32 OS_SocketSendTo(uint32 sock_id, const void *buffer, uint32 buflen, const O return return_code; } /* end OS_SocketSendTo */ - + /*---------------------------------------------------------------- * * Function: OS_SocketGetIdByName @@ -455,7 +458,7 @@ int32 OS_SocketGetIdByName (uint32 *sock_id, const char *sock_name) return return_code; } /* end OS_SocketGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_SocketGetInfo @@ -490,7 +493,7 @@ int32 OS_SocketGetInfo (uint32 sock_id, OS_socket_prop_t *sock_prop) return return_code; } /* end OS_SocketGetInfo */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAddrInit @@ -508,7 +511,7 @@ int32 OS_SocketAddrInit(OS_SockAddr_t *Addr, OS_SocketDomain_t Domain) return OS_SocketAddrInit_Impl(Addr, Domain); } /* end OS_SocketAddrInit */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAddrToString @@ -526,7 +529,7 @@ int32 OS_SocketAddrToString(char *buffer, uint32 buflen, const OS_SockAddr_t *Ad return OS_SocketAddrToString_Impl(buffer, buflen, Addr); } /* end OS_SocketAddrToString */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAddrFromString @@ -544,7 +547,7 @@ int32 OS_SocketAddrFromString(OS_SockAddr_t *Addr, const char *string) return OS_SocketAddrFromString_Impl(Addr, string); } /* end OS_SocketAddrFromString */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAddrGetPort @@ -562,7 +565,7 @@ int32 OS_SocketAddrGetPort(uint16 *PortNum, const OS_SockAddr_t *Addr) return OS_SocketAddrGetPort_Impl(PortNum, Addr); } /* end OS_SocketAddrGetPort */ - + /*---------------------------------------------------------------- * * Function: OS_SocketAddrSetPort @@ -581,5 +584,3 @@ int32 OS_SocketAddrSetPort(OS_SockAddr_t *Addr, uint16 PortNum) return OS_SocketAddrSetPort_Impl(Addr, PortNum); } /* end OS_SocketAddrSetPort */ -#endif - diff --git a/src/os/shared/osapi-task.c b/src/os/shared/src/osapi-task.c similarity index 94% rename from src/os/shared/osapi-task.c rename to src/os/shared/src/osapi-task.c index a0ec7ccc0..c24425193 100644 --- a/src/os/shared/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-task.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-task.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * @@ -34,8 +37,8 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-task-impl.h" +#include "osapi-idmap-impl.h" /* @@ -165,7 +168,7 @@ int32 OS_TaskAPI_Init(void) } /* end OS_TaskAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_TaskCreate @@ -227,7 +230,7 @@ int32 OS_TaskCreate (uint32 *task_id, const char *task_name, osal_task_entry fun } /* end OS_TaskCreate */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelete @@ -277,7 +280,7 @@ int32 OS_TaskDelete (uint32 task_id) return return_code; } /* end OS_TaskDelete */ - + /*---------------------------------------------------------------- * * Function: OS_TaskExit @@ -306,7 +309,7 @@ void OS_TaskExit() /* Impl function never returns */ } /* end OS_TaskExit */ - + /*---------------------------------------------------------------- * * Function: OS_TaskDelay @@ -321,7 +324,7 @@ int32 OS_TaskDelay(uint32 millisecond) return OS_TaskDelay_Impl(millisecond); } /* end OS_TaskDelay */ - + /*---------------------------------------------------------------- * * Function: OS_TaskSetPriority @@ -363,7 +366,7 @@ int32 OS_TaskSetPriority (uint32 task_id, uint32 new_priority) } /* end OS_TaskSetPriority */ - + /*---------------------------------------------------------------- * * Function: OS_TaskRegister @@ -384,7 +387,7 @@ int32 OS_TaskRegister (void) return OS_ObjectIdGetById(OS_LOCK_MODE_NONE, LOCAL_OBJID_TYPE, OS_TaskGetId_Impl(), &local_id, &record); } /* end OS_TaskRegister */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetId @@ -411,7 +414,7 @@ uint32 OS_TaskGetId (void) return(task_id); } /* end OS_TaskGetId */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetIdByName @@ -435,7 +438,7 @@ int32 OS_TaskGetIdByName (uint32 *task_id, const char *task_name) } /* end OS_TaskGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_TaskGetInfo @@ -479,7 +482,7 @@ int32 OS_TaskGetInfo (uint32 task_id, OS_task_prop_t *task_prop) } /* end OS_TaskGetInfo */ - + /*---------------------------------------------------------------- * * Function: OS_TaskInstallDeleteHandler diff --git a/src/os/shared/osapi-time.c b/src/os/shared/src/osapi-time.c similarity index 95% rename from src/os/shared/osapi-time.c rename to src/os/shared/src/osapi-time.c index 38b0c4d6d..91bcddacf 100644 --- a/src/os/shared/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -1,22 +1,24 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-time.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-time.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * - * */ /**************************************************************************************** @@ -32,8 +34,12 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-time-impl.h" +#include "osapi-task-impl.h" + /* * Sanity checks on the user-supplied configuration @@ -186,7 +192,7 @@ static int32 OS_DoTimerAdd(uint32 *timer_id, const char *timer_name, uint32 time return return_code; } /* end OS_DoTimerAdd */ - + /*---------------------------------------------------------------- * * Function: OS_TimerAdd @@ -201,7 +207,7 @@ int32 OS_TimerAdd(uint32 *timer_id, const char *timer_name, uint32 timebase_ref_ } /* end OS_TimerAdd */ - + /*---------------------------------------------------------------- * * Function: OS_Timer_NoArgCallback @@ -221,7 +227,7 @@ static void OS_Timer_NoArgCallback(uint32 objid, void *arg) (*Conv.timer_callback_func)(objid); } /* end OS_Timer_NoArgCallback */ - + /*---------------------------------------------------------------- * * Function: OS_TimerCreate @@ -294,7 +300,7 @@ int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *accuracy, } /* end OS_TimerCreate */ - + /*---------------------------------------------------------------- * * Function: OS_TimerSet @@ -317,7 +323,7 @@ int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time) { return OS_TIMER_ERR_INVALID_ARGS; } - + if (start_time == 0 && interval_time == 0) { return OS_ERROR; @@ -376,7 +382,7 @@ int32 OS_TimerSet(uint32 timer_id, uint32 start_time, uint32 interval_time) } /* end OS_TimerSet */ - + /*---------------------------------------------------------------- * * Function: OS_TimerDelete @@ -473,7 +479,7 @@ int32 OS_TimerDelete(uint32 timer_id) return return_code; } /* end OS_TimerDelete */ - + /*---------------------------------------------------------------- * * Function: OS_TimerGetIdByName @@ -508,7 +514,7 @@ int32 OS_TimerGetIdByName (uint32 *timer_id, const char *timer_name) return return_code; } /* end OS_TimerGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_TimerGetInfo diff --git a/src/os/shared/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c similarity index 96% rename from src/os/shared/osapi-timebase.c rename to src/os/shared/src/osapi-timebase.c index 50384b2aa..5b55de8c5 100644 --- a/src/os/shared/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -1,18 +1,21 @@ /* - * Copyright (c) 2018, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Glenn - * Research Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ + /** - * \file osapi-timebase.c - * \author joseph.p.hickey@nasa.gov + * \file osapi-timebase.c + * \ingroup shared + * \author joseph.p.hickey@nasa.gov * - * Purpose: * This file contains some of the OS APIs abstraction layer code * that is shared/common across all OS-specific implementations. * @@ -32,8 +35,11 @@ /* * User defined include files */ -#include "common_types.h" -#include "os-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-task-impl.h" +#include "osapi-time-impl.h" /* @@ -81,7 +87,7 @@ int32 OS_TimeBaseAPI_Init(void) } /* end OS_TimeBaseAPI_Init */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseCreate @@ -156,7 +162,7 @@ int32 OS_TimeBaseCreate(uint32 *timer_id, const char *timebase_name, OS_TimerSyn return return_code; } /* end OS_TimeBaseCreate */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseSet @@ -217,7 +223,7 @@ int32 OS_TimeBaseSet(uint32 timer_id, uint32 start_time, uint32 interval_time) return return_code; } /* end OS_TimeBaseSet */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseDelete @@ -260,7 +266,7 @@ int32 OS_TimeBaseDelete(uint32 timer_id) return return_code; } /* end OS_TimeBaseDelete */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetIdByName @@ -295,7 +301,7 @@ int32 OS_TimeBaseGetIdByName (uint32 *timer_id, const char *timebase_name) return return_code; } /* end OS_TimeBaseGetIdByName */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetInfo @@ -345,7 +351,7 @@ int32 OS_TimeBaseGetInfo (uint32 timebase_id, OS_timebase_prop_t *timebase_prop) return return_code; } /* end OS_TimeBaseGetInfo */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetFreeRun @@ -548,7 +554,7 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id) * OS ticks directly. */ - + /*---------------------------------------------------------------- * * Function: OS_Tick2Micros @@ -562,7 +568,7 @@ int32 OS_Tick2Micros (void) return (OS_SharedGlobalVars.MicroSecPerTick); } /* end OS_Tick2Micros */ - + /*---------------------------------------------------------------- * * Function: OS_Milli2Ticks diff --git a/src/os/vxworks/CMakeLists.txt b/src/os/vxworks/CMakeLists.txt index 578be6c60..0379ad640 100644 --- a/src/os/vxworks/CMakeLists.txt +++ b/src/os/vxworks/CMakeLists.txt @@ -5,13 +5,66 @@ ###################################################################### # This CMake script generates targets specific to the VxWorks implementation -# It defines an OBJECT target named "osal_vxworks_impl" -add_library(osal_vxworks_impl OBJECT - osapi.c - osfileapi.c - osfilesys.c - osloader.c - osnetwork.c - osselect.c - ostimer.c -) \ No newline at end of file +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) + +# The basic set of files which are always built +set(VXWORKS_BASE_SRCLIST + src/os-impl-binsem.c + src/os-impl-common.c + src/os-impl-console.c + src/os-impl-countsem.c + src/os-impl-errors.c + src/os-impl-dirs.c + src/os-impl-files.c + src/os-impl-filesys.c + src/os-impl-fpu.c + src/os-impl-heap.c + src/os-impl-idmap.c + src/os-impl-interrupts.c + src/os-impl-mutex.c + src/os-impl-queues.c + src/os-impl-shell.c + src/os-impl-tasks.c + src/os-impl-timebase.c +) + +# Use portable blocks for basic I/O +set(VXWORKS_IMPL_SRCLIST + ../portable/os-impl-posix-gettime.c + ../portable/os-impl-console-bsp.c + ../portable/os-impl-bsd-select.c + ../portable/os-impl-posix-io.c + ../portable/os-impl-posix-files.c +) + +# If some form of module loading is configured, +# then build the module loader +if (OSAL_CONFIG_INCLUDE_DYNAMIC_LOADER) + list(APPEND VXWORKS_IMPL_SRCLIST + src/os-impl-module.c + ) +else () + list(APPEND VXWORKS_IMPL_SRCLIST + src/os-impl-no-module.c + ../portable/os-impl-no-loader.c + ../portable/os-impl-no-symtab.c + ) +endif () + +if (OSAL_CONFIG_INCLUDE_NETWORK) + list(APPEND VXWORKS_IMPL_SRCLIST + ../portable/os-impl-bsd-sockets.c # Use BSD socket layer implementation + ../portable/os-impl-posix-network.c # Use POSIX-defined hostname/id implementation + ) +else() + list(APPEND VXWORKS_IMPL_SRCLIST + ../portable/os-impl-no-network.c # non-implemented versions of all network APIs + ../portable/os-impl-no-sockets.c # non-implemented versions of all socket APIs + ) +endif () + +# Defines an OBJECT target named "osal_vxworks_impl" with selected source files +add_library(osal_vxworks_impl OBJECT + ${VXWORKS_BASE_SRCLIST} + ${VXWORKS_IMPL_SRCLIST} +) diff --git a/src/os/vxworks/inc/os-impl-binsem.h b/src/os/vxworks/inc/os-impl-binsem.h new file mode 100644 index 000000000..665de9ca8 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-binsem.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_BINSEM_H_ +#define INCLUDE_OS_IMPL_BINSEM_H_ + +#include +#include + +/* Binary Semaphores */ +typedef struct +{ + VX_BINARY_SEMAPHORE(bmem); + SEM_ID vxid; +} OS_impl_binsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + +#endif /* INCLUDE_OS_IMPL_BINSEM_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-console.h b/src/os/vxworks/inc/os-impl-console.h new file mode 100644 index 000000000..96547be82 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-console.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_CONSOLE_H_ +#define INCLUDE_OS_IMPL_CONSOLE_H_ + +#include +#include +#include +#include + +/* Console device */ +typedef struct +{ + VX_COUNTING_SEMAPHORE(cmem); + bool is_async; + SEM_ID datasem; + TASK_ID taskid; +} OS_impl_console_internal_record_t; + + +extern OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + +#endif /* INCLUDE_OS_IMPL_CONSOLE_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-countsem.h b/src/os/vxworks/inc/os-impl-countsem.h new file mode 100644 index 000000000..c0ae5be12 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-countsem.h @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_COUNTSEM_H_ +#define INCLUDE_OS_IMPL_COUNTSEM_H_ + +#include +#include + +/* Counting & Binary Semaphores */ +typedef struct +{ + VX_COUNTING_SEMAPHORE(cmem); + SEM_ID vxid; +} OS_impl_countsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + + +#endif /* INCLUDE_OS_IMPL_COUNTSEM_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-dirs.h b/src/os/vxworks/inc/os-impl-dirs.h new file mode 100644 index 000000000..ac1ec5c96 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-dirs.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_DIRS_H_ +#define INCLUDE_OS_IMPL_DIRS_H_ + +#include +#include +#include +#include + +typedef struct +{ + DIR *dp; +} OS_impl_dir_internal_record_t; + + +/* + * The directory handle table. + */ +extern OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + +#endif /* INCLUDE_OS_IMPL_DIRS_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-files.h b/src/os/vxworks/inc/os-impl-files.h new file mode 100644 index 000000000..f01121436 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-files.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_FILES_H_ +#define INCLUDE_OS_IMPL_FILES_H_ + +#include "os-impl-io.h" + +#include +#include +#include + +#include + +/* + * VxWorks does not have UID/GID so these are defined as 0. + */ +#define OS_IMPL_SELF_EUID 0 +#define OS_IMPL_SELF_EGID 0 + + +/* + * Do not set any additional flags for regular files + */ +#define OS_IMPL_REGULAR_FILE_FLAGS 0 + + +#endif /* INCLUDE_OS_IMPL_FILES_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-filesys.h b/src/os/vxworks/inc/os-impl-filesys.h new file mode 100644 index 000000000..17d92e147 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-filesys.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-filesys.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_FILESYS_H_ +#define INCLUDE_OS_IMPL_FILESYS_H_ + +#include +#include +#include +#include + +typedef struct +{ + BLK_DEV *blkDev; + device_t xbd; + uint32 xbdMaxPartitions; +} OS_impl_filesys_internal_record_t; + + +extern OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; + + +#endif /* INCLUDE_OS_IMPL_FILESYS_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-gettime.h b/src/os/vxworks/inc/os-impl-gettime.h new file mode 100644 index 000000000..0a9e13d06 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-gettime.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-gettime.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_GETTIME_H_ +#define INCLUDE_OS_IMPL_GETTIME_H_ + +#include +#include + + +#define OSAL_GETTIME_SOURCE_CLOCK CLOCK_MONOTONIC + +#endif /* INCLUDE_OS_IMPL_GETTIME_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-io.h b/src/os/vxworks/inc/os-impl-io.h new file mode 100644 index 000000000..df8c55c5a --- /dev/null +++ b/src/os/vxworks/inc/os-impl-io.h @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-io.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_IO_H_ +#define INCLUDE_OS_IMPL_IO_H_ + +#include +#include +#include +#include +#include + +typedef struct +{ + int fd; + bool selectable; +} OS_VxWorks_filehandle_entry_t; + +/* + * The global file handle table. + * + * This table is shared across multiple units (files, sockets, etc) and they will share + * the same file handle table from the basic file I/O. + */ +extern OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + +/* + * VxWorks needs to cast the argument to "write()" to avoid a warning. + * This can be turned off in a future version if the vendor fixes the + * prototype to be standards-compliant + */ +#define GENERIC_IO_CONST_DATA_CAST (void*) + + +#endif /* INCLUDE_OS_IMPL_IO_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-loader.h b/src/os/vxworks/inc/os-impl-loader.h new file mode 100644 index 000000000..7d136d6a4 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-loader.h @@ -0,0 +1,49 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-loader.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_LOADER_H_ +#define INCLUDE_OS_IMPL_LOADER_H_ + +#include +#include + +/* + * A local lookup table for posix-specific information. + * This is not directly visible to the outside world. + */ +typedef struct +{ + MODULE_ID moduleID; +} OS_impl_module_internal_record_t; + +/* + * The storage table is only instantiated when OS_MAX_MODULES is nonzero. + * It is allowed to be zero to save memory in statically linked apps. + * However even in that case it is still relevant to include the + * OS_SymbolLookup_Impl() function for symbol lookups. + * + * If neither loading nor symbol lookups are desired then this file + * shouldn't be used at all -- a no-op version should be used instead. + */ +extern OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; + + +#endif /* INCLUDE_OS_IMPL_LOADER_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-mutex.h b/src/os/vxworks/inc/os-impl-mutex.h new file mode 100644 index 000000000..b85e384fc --- /dev/null +++ b/src/os/vxworks/inc/os-impl-mutex.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_MUTEX_H_ +#define INCLUDE_OS_IMPL_MUTEX_H_ + +#include +#include + +typedef struct +{ + VX_MUTEX_SEMAPHORE(mmem); + SEM_ID vxid; +} OS_impl_mutsem_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_mutsem_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + + +#endif /* INCLUDE_OS_IMPL_MUTEX_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-network.h b/src/os/vxworks/inc/os-impl-network.h new file mode 100644 index 000000000..e208de1a4 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-network.h @@ -0,0 +1,28 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-network.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_NETWORK_H_ +#define INCLUDE_OS_IMPL_NETWORK_H_ + +#include +#include + +#endif /* INCLUDE_OS_IMPL_NETWORK_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-queues.h b/src/os/vxworks/inc/os-impl-queues.h new file mode 100644 index 000000000..700093a6c --- /dev/null +++ b/src/os/vxworks/inc/os-impl-queues.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_QUEUES_H_ +#define INCLUDE_OS_IMPL_QUEUES_H_ + +#include +#include + +typedef struct +{ + MSG_Q_ID vxid; +} OS_impl_queue_internal_record_t; + +/* Tables where the OS object information is stored */ +extern OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + + +#endif /* INCLUDE_OS_IMPL_QUEUES_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-select.h b/src/os/vxworks/inc/os-impl-select.h new file mode 100644 index 000000000..b6f14ee9c --- /dev/null +++ b/src/os/vxworks/inc/os-impl-select.h @@ -0,0 +1,29 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-select.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SELECT_H_ +#define INCLUDE_OS_IMPL_SELECT_H_ + +#include "os-impl-io.h" +#include + + +#endif /* INCLUDE_OS_IMPL_SELECT_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-sockets.h b/src/os/vxworks/inc/os-impl-sockets.h new file mode 100644 index 000000000..6f9e0bd35 --- /dev/null +++ b/src/os/vxworks/inc/os-impl-sockets.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-sockets.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SOCKETS_H_ +#define INCLUDE_OS_IMPL_SOCKETS_H_ + +#include "os-impl-io.h" + +#include +#include +#include +#include +#include +#include +#include + +/* + * Use the O_NONBLOCK flag on sockets + */ +#define OS_IMPL_SOCKET_FLAGS O_NONBLOCK + + +/* The "in.h" header file supplied in VxWorks 6.9 is missing the "in_port_t" typedef */ +typedef u_short in_port_t; + + +#endif /* INCLUDE_OS_IMPL_SOCKETS_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-symtab.h b/src/os/vxworks/inc/os-impl-symtab.h new file mode 100644 index 000000000..e4b03e55a --- /dev/null +++ b/src/os/vxworks/inc/os-impl-symtab.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-symtab.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_SYMTAB_H_ +#define INCLUDE_OS_IMPL_SYMTAB_H_ + +#include +#include + +typedef struct +{ + uint32 Sizelimit; + uint32 CurrSize; + int32 StatusCode; + int fd; +} SymbolDumpState_t; + + +/* A global for storing the state in a SymbolDump call */ +extern SymbolDumpState_t OS_VxWorks_SymbolDumpState; + +BOOL OS_SymTableIterator_Impl ( char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_arg_t arg, SYM_GROUP group ); + +#endif /* INCLUDE_OS_IMPL_SYMTAB_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-tasks.h b/src/os/vxworks/inc/os-impl-tasks.h new file mode 100644 index 000000000..773f8898e --- /dev/null +++ b/src/os/vxworks/inc/os-impl-tasks.h @@ -0,0 +1,42 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TASKS_H_ +#define INCLUDE_OS_IMPL_TASKS_H_ + +#include +#include + + +/*tasks */ +typedef struct +{ + WIND_TCB tcb; /* Must be first */ + TASK_ID vxid; + void *heap_block; /* set non-null if the stack was obtained with malloc() */ + long heap_block_size; +} OS_impl_task_internal_record_t; + + +/* Tables where the OS object information is stored */ +extern OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + +#endif /* INCLUDE_OS_IMPL_TASKS_H_ */ + diff --git a/src/os/vxworks/inc/os-impl-timebase.h b/src/os/vxworks/inc/os-impl-timebase.h new file mode 100644 index 000000000..5b42a2f7c --- /dev/null +++ b/src/os/vxworks/inc/os-impl-timebase.h @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-timebase.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_IMPL_TIMEBASE_H_ +#define INCLUDE_OS_IMPL_TIMEBASE_H_ + +#include +#include +#include +#include +#include + +enum OS_TimerState +{ + OS_TimerRegState_INIT = 0, + OS_TimerRegState_SUCCESS, + OS_TimerRegState_ERROR +}; + +typedef struct +{ + VX_MUTEX_SEMAPHORE(mmem); + SEM_ID handler_mutex; + int assigned_signal; + sigset_t timer_sigset; + TASK_ID handler_task; + timer_t host_timerid; + enum OS_TimerState timer_state; + uint32 configured_start_time; + uint32 configured_interval_time; + bool reset_flag; +} OS_impl_timebase_internal_record_t; + + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +extern OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; + + +#endif /* INCLUDE_OS_IMPL_TIMEBASE_H_ */ + diff --git a/src/os/vxworks/os-vxworks.h b/src/os/vxworks/inc/os-vxworks.h similarity index 57% rename from src/os/vxworks/os-vxworks.h rename to src/os/vxworks/inc/os-vxworks.h index 8685e722c..91da2de98 100644 --- a/src/os/vxworks/os-vxworks.h +++ b/src/os/vxworks/inc/os-vxworks.h @@ -1,21 +1,26 @@ /* -** File : os-vxworks.h -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey -** -** Purpose: This file contains definitions that are shared across the VxWorks -** OSAL implementation. This file is private to the VxWorks port and it -** may contain VxWorks-specific definitions. -** -*/ + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-vxworks.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef INCLUDE_OS_VXWORKS_H_ +#define INCLUDE_OS_VXWORKS_H_ + /**************************************************************************************** COMMON INCLUDE FILES @@ -27,10 +32,11 @@ #include #include +#include +#include + +#include -#include "common_types.h" -#include "osapi.h" -#include /**************************************************************************************** DEFINES @@ -42,22 +48,15 @@ typedef struct { - int fd; - bool selectable; -} OS_VxWorks_filehandle_entry_t; + void * const mem; + SEM_ID vxid; +} VxWorks_GlobalMutex_t; /**************************************************************************************** GLOBAL DATA ****************************************************************************************/ -/* - * The global file handle table. - * - * This table is shared across multiple units (files, sockets, etc) and they will share - * the same file handle table from the basic file I/O. - */ -extern OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - +extern VxWorks_GlobalMutex_t VX_MUTEX_TABLE[]; /**************************************************************************************** @@ -74,4 +73,19 @@ int32 OS_VxWorks_ModuleAPI_Impl_Init(void); int32 OS_VxWorks_StreamAPI_Impl_Init(void); int32 OS_VxWorks_DirAPI_Impl_Init(void); +int OS_VxWorks_TaskEntry(int arg); +int OS_VxWorks_ConsoleTask_Entry(int arg); + +uint32 OS_VxWorks_SigWait(uint32 local_id); +int OS_VxWorks_TimeBaseTask(int arg); +void OS_VxWorks_RegisterTimer(uint32 local_id); +void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec); + +int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks); +int32 OS_VxWorks_GenericSemGive(SEM_ID vxid); + + +int32 OS_VxWorks_TableMutex_Init(uint32 idtype); + +#endif /* INCLUDE_OS_VXWORKS_H_ */ diff --git a/src/os/vxworks/osapi.c b/src/os/vxworks/osapi.c deleted file mode 100644 index 8bf49d6c2..000000000 --- a/src/os/vxworks/osapi.c +++ /dev/null @@ -1,1782 +0,0 @@ -/* -** File : osapi.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original VxWorks implementation by Ezra Yeheskeli -** -** Purpose: -** This file contains some of the OS APIs abstraction layer for VxWorks -** This has been tested against the current VxWorks 4.11 release branch -** -** NOTE: This uses only the "Classic" VxWorks API. It is intended to -** work on VxWorks targets that do not provide the POSIX API, i.e. -** when "--disable-posix" is given during the configuration stage. -** -** If the VxWorks POSIX API is enabled, then it should be possible to -** use the POSIX OSAL which is more full featured. -*/ -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/**************************************************************************************** - DEFINES -****************************************************************************************/ - -/* - * macros for stack size manipulation. - * These are normally provided by vxWorks.h if relevant for the platform. - * If they are not defined, use a reasonable default/substitute. - */ -#if defined(_STACK_ALIGN_SIZE) -#define VX_IMPL_STACK_ALIGN_SIZE _STACK_ALIGN_SIZE -#else -#define VX_IMPL_STACK_ALIGN_SIZE 16 -#endif - -#if defined(STACK_ROUND_DOWN) -#define VX_IMPL_STACK_ROUND_DOWN(x) STACK_ROUND_DOWN(x) -#else -#define VX_IMPL_STACK_ROUND_DOWN(x) ((x) & ~(VX_IMPL_STACK_ALIGN_SIZE-1)) -#endif - -#if defined(STACK_ROUND_UP) -#define VX_IMPL_STACK_ROUND_UP(x) STACK_ROUND_UP(x) -#else -#define VX_IMPL_STACK_ROUND_UP(x) (((x) + (VX_IMPL_STACK_ALIGN_SIZE-1)) & ~(VX_IMPL_STACK_ALIGN_SIZE-1)) -#endif - -/* - * By default the console output is always asynchronous - * (equivalent to "OS_UTILITY_TASK_ON" being set) - * - * This option was removed from osconfig.h and now is - * assumed to always be on. - */ -#define OS_CONSOLE_ASYNC true -#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY -#define OS_CONSOLE_TASK_STACKSIZE OS_UTILITYTASK_STACK_SIZE - - - -/**************************************************************************************** - GLOBAL DATA -****************************************************************************************/ -/* tables for the properties of objects */ -/*tasks */ -typedef struct -{ - WIND_TCB tcb; /* Must be first */ - TASK_ID vxid; - void *heap_block; /* set non-null if the stack was obtained with malloc() */ - long heap_block_size; -} OS_impl_task_internal_record_t; - -/* queues */ -typedef struct -{ - MSG_Q_ID vxid; -} OS_impl_queue_internal_record_t; - -/* Counting & Binary Semaphores */ -typedef struct -{ - VX_BINARY_SEMAPHORE(bmem); - SEM_ID vxid; -} OS_impl_binsem_internal_record_t; - -/* Counting & Binary Semaphores */ -typedef struct -{ - VX_COUNTING_SEMAPHORE(cmem); - SEM_ID vxid; -} OS_impl_countsem_internal_record_t; - -/* Counting & Binary Semaphores */ -typedef struct -{ - VX_MUTEX_SEMAPHORE(mmem); - SEM_ID vxid; -} OS_impl_mutsem_internal_record_t; - -/* Console device */ -typedef struct -{ - VX_COUNTING_SEMAPHORE(cmem); - bool is_async; - SEM_ID datasem; - TASK_ID taskid; -} OS_impl_console_internal_record_t; - - -/* Tables where the OS object information is stored */ -OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; -OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; -OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; -OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; -OS_impl_mutsem_internal_record_t OS_impl_mut_sem_table [OS_MAX_MUTEXES]; -OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; - -static TASK_ID OS_idle_task_id; - -VX_MUTEX_SEMAPHORE(OS_task_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_queue_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_bin_sem_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_mut_sem_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_count_sem_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_stream_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_dir_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_timebase_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_module_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_filesys_table_mut_mem); -VX_MUTEX_SEMAPHORE(OS_console_mut_mem); - -typedef struct -{ - void * const mem; - SEM_ID vxid; -} VxWorks_GlobalMutex_t; - -static VxWorks_GlobalMutex_t VX_MUTEX_TABLE[] = - { - [OS_OBJECT_TYPE_UNDEFINED] = { NULL }, - [OS_OBJECT_TYPE_OS_TASK] = { .mem = OS_task_table_mut_mem }, - [OS_OBJECT_TYPE_OS_QUEUE] = { .mem = OS_queue_table_mut_mem }, - [OS_OBJECT_TYPE_OS_COUNTSEM] = { .mem = OS_count_sem_table_mut_mem }, - [OS_OBJECT_TYPE_OS_BINSEM] = { .mem = OS_bin_sem_table_mut_mem }, - [OS_OBJECT_TYPE_OS_MUTEX] = { .mem = OS_mut_sem_table_mut_mem }, - [OS_OBJECT_TYPE_OS_STREAM] = { .mem = OS_stream_table_mut_mem }, - [OS_OBJECT_TYPE_OS_DIR] = { .mem = OS_dir_table_mut_mem }, - [OS_OBJECT_TYPE_OS_TIMEBASE] = { .mem = OS_timebase_table_mut_mem }, - [OS_OBJECT_TYPE_OS_MODULE] = { .mem = OS_module_table_mut_mem }, - [OS_OBJECT_TYPE_OS_FILESYS] = { .mem = OS_filesys_table_mut_mem }, - [OS_OBJECT_TYPE_OS_CONSOLE] = { .mem = OS_console_mut_mem }, - }; - -enum -{ - VX_MUTEX_TABLE_SIZE = (sizeof(VX_MUTEX_TABLE) / sizeof(VX_MUTEX_TABLE[0])) -}; - -const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; - -/*---------------------------------------------------------------- - * - * Function: OS_Lock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Lock_Global_Impl(uint32 idtype) -{ - VxWorks_GlobalMutex_t *mut; - - if (idtype >= VX_MUTEX_TABLE_SIZE) - { - return OS_ERROR; - } - - mut = &VX_MUTEX_TABLE[idtype]; - if (mut->vxid == (SEM_ID)0) - { - return OS_ERROR; - } - - if (semTake(mut->vxid, WAIT_FOREVER) != OK) - { - OS_DEBUG("semTake() - vxWorks errno %d\n",errno); - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_Lock_Global_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_Unlock_Global_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_Unlock_Global_Impl(uint32 idtype) -{ - VxWorks_GlobalMutex_t *mut; - - if (idtype >= VX_MUTEX_TABLE_SIZE) - { - return OS_ERROR; - } - - mut = &VX_MUTEX_TABLE[idtype]; - if (mut->vxid == (SEM_ID)0) - { - return OS_ERROR; - } - - if (semGive(mut->vxid) != OK) - { - OS_DEBUG("semGive() - vxWorks errno %d\n",errno); - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_Unlock_Global_Impl */ - - - -/**************************************************************************************** - INITIALIZATION FUNCTION -****************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_API_Impl_Init - * - * Purpose: Initialize the tables that the OS API uses to keep track of information - * about objects - * - *-----------------------------------------------------------------*/ -int32 OS_API_Impl_Init(uint32 idtype) -{ - int32 return_code = OS_SUCCESS; - SEM_ID semid; - - do - { - /* Initialize the table mutex for the given idtype */ - if (idtype < VX_MUTEX_TABLE_SIZE && VX_MUTEX_TABLE[idtype].mem != NULL) - { - semid = semMInitialize (VX_MUTEX_TABLE[idtype].mem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); - - if ( semid == (SEM_ID)0 ) - { - OS_DEBUG("Error: semMInitialize() failed - vxWorks errno %d\n",errno); - return_code = OS_ERROR; - break; - } - - VX_MUTEX_TABLE[idtype].vxid = semid; - } - - switch(idtype) - { - case OS_OBJECT_TYPE_OS_TASK: - return_code = OS_VxWorks_TaskAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_QUEUE: - return_code = OS_VxWorks_QueueAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_BINSEM: - return_code = OS_VxWorks_BinSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_COUNTSEM: - return_code = OS_VxWorks_CountSemAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MUTEX: - return_code = OS_VxWorks_MutexAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_MODULE: - return_code = OS_VxWorks_ModuleAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_TIMEBASE: - return_code = OS_VxWorks_TimeBaseAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_STREAM: - return_code = OS_VxWorks_StreamAPI_Impl_Init(); - break; - case OS_OBJECT_TYPE_OS_DIR: - return_code = OS_VxWorks_DirAPI_Impl_Init(); - break; - default: - break; - } - } - while (0); - - - return(return_code); -} /* end OS_API_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IdleLoop_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_IdleLoop_Impl() -{ - TASK_ID tid = taskIdSelf(); - OS_idle_task_id = tid; - taskSuspend(tid); -} /* end OS_IdleLoop_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ApplicationShutdown_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ApplicationShutdown_Impl() -{ - taskResume(OS_idle_task_id); -} /* end OS_ApplicationShutdown_Impl */ - - - -/*--------------------------------------------------------------------------------------- - Name: OS_VxWorksEntry - - Purpose: A Simple VxWorks-compatible entry point that calls the common task entry function - - NOTES: This wrapper function is only used locally by OS_TaskCreate below - ----------------------------------------------------------------------------------------*/ -static int OS_VxWorksEntry(int arg) -{ - OS_TaskEntryPoint((uint32)arg); - return 0; -} /* end OS_VxWorksEntry */ - - - -/**************************************************************************************** - TASK API -****************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_TaskAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_TaskAPI_Impl_Init(void) -{ - memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); - return (OS_SUCCESS); -} /* end OS_VxWorks_TaskAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) -{ - STATUS status; - int vxflags; - int vxpri; - long actualsz; - long userstackbase; - long actualstackbase; - OS_impl_task_internal_record_t *lrec; - - lrec = &OS_impl_task_table[task_id]; - - /* Create VxWorks Task */ - - /* see if the user wants floating point enabled. If - * so, then se the correct option. - */ - vxflags = 0; - if (flags & OS_FP_ENABLED) - { - vxflags |= VX_FP_TASK; - } - - - /* - * Get priority/stack specs from main struct - * priority should be a direct passthru - */ - vxpri = OS_task_table[task_id].priority; - actualsz = OS_task_table[task_id].stack_size; - userstackbase = (long)OS_task_table[task_id].stack_pointer; - - /* - * NOTE: Using taskInit() here rather than taskSpawn() allows us - * to specify a specific statically-allocated WIND_TCB instance. - * - * This is very important as it allows for efficient reverse-lookup; - * a call to taskTcb() will get the WIND_TCB pointer back, which - * in turn provides an index into OSAL local data structures. With - * this we can have the equivalent of a taskVar that works on both - * UMP and SMP deployments. - * - * The difficulty with taskInit() is that we must also manually - * allocate the stack as well (there is no API that allows - * a specific WIND_TCB but automatically allocates the stack). - * Furthermore, VxWorks uses this pointer directly as the CPU - * stack pointer register, so we need to manually adjust it for - * downward-growing stacks. - * - * NOTE: Allocation of the stack requires a malloc() of some form. - * This is what taskSpawn() effectively does internally to create - * stack. If the system malloc() is unacceptable here then this - * could be replaced with a statically-allocated OSAL stack buffer. - * - * ALSO NOTE: The stack-rounding macros are normally supplied from - * vxWorks.h on relevant platforms. If not provided then it is - * assumed that no specific alignment is needed on this platform. - */ - - if (userstackbase == 0) - { - /* add a little extra in case the base address needs alignment too. - * this helps ensure that the final aligned stack is not less - * than what was originally requested (but might be a bit more) */ - actualsz += VX_IMPL_STACK_ALIGN_SIZE; - actualsz = VX_IMPL_STACK_ROUND_UP(actualsz); - - /* - * VxWorks does not provide a way to deallocate - * a taskInit-provided stack when a task exits. - * - * So in this case we will find the leftover heap - * buffer when OSAL reuses this local record block. - * - * If that leftover heap buffer is big enough it - * can be used directly. Otherwise it needs to be - * re-created. - */ - if (lrec->heap_block_size < actualsz) - { - if (lrec->heap_block != NULL) - { - /* release the old block */ - free(lrec->heap_block); - lrec->heap_block_size = 0; - } - - /* allocate a new heap block to use for a stack */ - lrec->heap_block = malloc(actualsz); - - if (lrec->heap_block != NULL) - { - lrec->heap_block_size = actualsz; - } - - } - - userstackbase = (long)lrec->heap_block; - } - - if (userstackbase == 0) - { - /* no stack - cannot create task */ - return OS_ERROR; - } - - actualstackbase = userstackbase; - - /* also round the base address */ - actualstackbase = VX_IMPL_STACK_ROUND_UP(actualstackbase); - actualsz -= (actualstackbase - userstackbase); - actualsz = VX_IMPL_STACK_ROUND_DOWN(actualsz); - - /* - * On most CPUs the stack grows downward, so assume that to be - * the case in the event that _STACK_DIR is not defined/known - */ -#if !defined(_STACK_DIR) || (_STACK_DIR != _STACK_GROWS_UP) - actualstackbase += actualsz; /* move to last byte of stack block */ -#endif - - status = taskInit( - &lrec->tcb, /* address of new task's TCB */ - (char*)OS_global_task_table[task_id].name_entry, - vxpri, /* priority of new task */ - vxflags, /* task option word */ - (char *)actualstackbase, /* base of new task's stack */ - actualsz, /* size (bytes) of stack needed */ - (FUNCPTR)OS_VxWorksEntry, /* entry point of new task */ - OS_global_task_table[task_id].active_id, /* 1st arg is ID */ - 0,0,0,0,0,0,0,0,0); - - if (status != OK) - { - return OS_ERROR; - } - - lrec->vxid = (TASK_ID)&lrec->tcb; - - taskActivate(lrec->vxid); - - return OS_SUCCESS; - -} /* end OS_TaskCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelete_Impl (uint32 task_id) -{ - /* - ** Try to delete the task - ** If this fails, not much recourse - the only potential cause of failure - ** to cancel here is that the thread ID is invalid because it already exited itself, - ** and if that is true there is nothing wrong - everything is OK to continue normally. - */ - if (taskDelete(OS_impl_task_table[task_id].vxid) != OK) - { - OS_DEBUG("taskDelete() - vxWorks errno %d\n",errno); - return OS_ERROR; - } - - OS_impl_task_table[task_id].vxid = 0; - return OS_SUCCESS; - -} /* end OS_TaskDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskExit_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_TaskExit_Impl() -{ - taskExit(0); -} /* end OS_TaskExit_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskDelay_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskDelay_Impl (uint32 milli_second) -{ - /* msecs rounded to the closest system tick count */ - int sys_ticks; - - sys_ticks = OS_Milli2Ticks(milli_second); - - /* if successful, the execution of task will pend here until delay finishes */ - if(taskDelay(sys_ticks) != OK) - { - return OS_ERROR; - } - return OS_SUCCESS; - -} /* end OS_TaskDelay_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskSetPriority_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) -{ - /* Set VxWorks Task Priority */ - if(taskPrioritySet(OS_impl_task_table[task_id].vxid, new_priority) != OK) - { - return OS_ERROR; - } - - return OS_SUCCESS; - -} /* end OS_TaskSetPriority_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskMatch_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskMatch_Impl(uint32 task_id) -{ - /* - ** Get VxWorks Task Id - */ - if ( taskIdSelf() != OS_impl_task_table[task_id].vxid ) - { - return(OS_ERROR); - } - - - return OS_SUCCESS; -} /* end OS_TaskMatch_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskRegister_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskRegister_Impl (uint32 global_task_id) -{ - return OS_SUCCESS; -} /* end OS_TaskRegister_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetId_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -uint32 OS_TaskGetId_Impl (void) -{ - OS_impl_task_internal_record_t *lrec; - size_t index; - uint32 id; - - id = 0; - lrec = (OS_impl_task_internal_record_t *)taskTcb(taskIdSelf()); - - if (lrec != NULL) - { - index = lrec - &OS_impl_task_table[0]; - if (index < OS_MAX_TASKS) - { - id = OS_global_task_table[index].active_id; - } - } - - return id; - -} /* end OS_TaskGetId_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_TaskGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) -{ - union - { - TASK_ID vxid; - uint32 value; - } u; - - /* - * The "OStask_id" is a broken concept and only included for backward compatibility. - * On 32 bit platforms this should produce a backward-compatible result. - * But on 64 bit platforms this value should never be used..... - * using a union defeats a (valid) warning on 64-bit. - */ - u.vxid = OS_impl_task_table[task_id].vxid; - task_prop->OStask_id = u.value; - - return OS_SUCCESS; - -} /* end OS_TaskGetInfo_Impl */ - - -/**************************************************************************************** - MESSAGE QUEUE API -****************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_QueueAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_QueueAPI_Impl_Init(void) -{ - memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); - return (OS_SUCCESS); -} /* end OS_VxWorks_QueueAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) -{ - MSG_Q_ID tmp_msgq_id; - int queue_depth = OS_queue_table[queue_id].max_depth; /* maximum number of messages in queue (queue depth) */ - int data_size = OS_queue_table[queue_id].max_size; /* maximum size in bytes of a message */ - - /* Create VxWorks Message Queue */ - tmp_msgq_id = msgQCreate(queue_depth, data_size, MSG_Q_FIFO); - - /* check if message Q create failed */ - if(tmp_msgq_id == 0) - { - OS_DEBUG("msgQCreate() - vxWorks errno %d\n",errno); - return OS_ERROR; - } - - OS_impl_queue_table[queue_id].vxid = tmp_msgq_id; - return OS_SUCCESS; - -} /* end OS_QueueCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueDelete_Impl (uint32 queue_id) -{ - /* Try to delete the queue */ - if (msgQDelete(OS_impl_queue_table[queue_id].vxid) != OK) - { - OS_DEBUG("msgQDelete() - vxWorks errno %d\n",errno); - return OS_ERROR; - } - - OS_impl_queue_table[queue_id].vxid = 0; - return OS_SUCCESS; - -} /* end OS_QueueDelete_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueGet_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, - int32 timeout) -{ - int32 return_code; - STATUS status; - int ticks; - - /* Get Message From Message Queue */ - if (timeout == OS_PEND) - { - ticks = WAIT_FOREVER; - } - else if (timeout == OS_CHECK) - { - ticks = NO_WAIT; - } - else - { - /* msecs rounded to the closest system tick count */ - ticks = OS_Milli2Ticks(timeout); - } - - status = msgQReceive(OS_impl_queue_table[queue_id].vxid, data, size, ticks); - - if(status == ERROR) - { - *size_copied = 0; - if (errno == S_objLib_OBJ_TIMEOUT) - { - return_code = OS_QUEUE_TIMEOUT; - } - else if (errno == S_objLib_OBJ_UNAVAILABLE) - { - return_code = OS_QUEUE_EMPTY; - } - else - { - OS_DEBUG("msgQReceive() - vxWorks errno %d\n",errno); - return_code = OS_ERROR; - } - } - else - { - *size_copied = status; - return_code = OS_SUCCESS; - } - - return return_code; -} /* end OS_QueueGet_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueuePut_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) -{ - int32 return_code; - - if(msgQSend(OS_impl_queue_table[queue_id].vxid, (void*)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) - { - return_code = OS_SUCCESS; - } - else if(errno == S_objLib_OBJ_UNAVAILABLE) - { - return_code = OS_QUEUE_FULL; - } - else - { - OS_DEBUG("msgQSend() - vxWorks errno %d\n",errno); - return_code = OS_ERROR; - } - - return return_code; - -} /* end OS_QueuePut_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_QueueGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) -{ - /* No extra info for queues in the OS implementation */ - return OS_SUCCESS; - -} /* end OS_QueueGetInfo_Impl */ - - -/**************************************************************************************** - GENERIC SEMAPHORE API -****************************************************************************************/ - -/* - * ---------------------------------- - * generic semaphore give/take - - * VxWorks uses the sem semTake()/semGive() API for all types of semaphores. - * Only the initialization is different between them. - * Therefore all semaphore actions can just invoke these generic actions - * ----------------------------------- - */ - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_GenericSemGive - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -static int32 OS_VxWorks_GenericSemGive(SEM_ID vxid) -{ - /* Give VxWorks Semaphore */ - if(semGive(vxid) != OK) - { - OS_DEBUG("semGive() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - return OS_SUCCESS; -} /* end OS_VxWorks_GenericSemGive */ - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_GenericSemTake - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -static int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks) -{ - int vx_status; - - /* Take VxWorks Semaphore */ - vx_status = semTake(vxid, sys_ticks); - if (vx_status != OK) - { - /* - * check for the timeout condition, - * which has a different return code and - * not necessarily an error of concern. - */ - if (errno == S_objLib_OBJ_TIMEOUT) - { - return OS_SEM_TIMEOUT; - } - - OS_DEBUG("semTake() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_VxWorks_GenericSemTake */ - -/**************************************************************************************** - BINARY SEMAPHORE API -****************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_BinSemAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_BinSemAPI_Impl_Init(void) -{ - memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); - return (OS_SUCCESS); -} /* end OS_VxWorks_BinSemAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) -{ - SEM_ID tmp_sem_id; - - /* Initialize VxWorks Semaphore. - * The memory for this sem is statically allocated. */ - tmp_sem_id = semBInitialize(OS_impl_bin_sem_table[sem_id].bmem, SEM_Q_PRIORITY, sem_initial_value); - - /* check if semBInitialize failed */ - if(tmp_sem_id == (SEM_ID)0) - { - OS_DEBUG("semBInitialize() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - OS_impl_bin_sem_table[sem_id].vxid = tmp_sem_id; - return OS_SUCCESS; - -} /* end OS_BinSemCreate_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemDelete_Impl (uint32 sem_id) -{ - /* - * As the memory for the sem is statically allocated, delete is a no-op. - */ - OS_impl_bin_sem_table[sem_id].vxid = 0; - return OS_SUCCESS; - -} /* end OS_BinSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGive_Impl (uint32 sem_id) -{ - /* Use common routine */ - return OS_VxWorks_GenericSemGive(OS_impl_bin_sem_table[sem_id].vxid); -} /* end OS_BinSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemFlush_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemFlush_Impl (uint32 sem_id) -{ - /* Flush VxWorks Semaphore */ - if(semFlush(OS_impl_bin_sem_table[sem_id].vxid) != OK) - { - OS_DEBUG("semFlush() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - return OS_SUCCESS; -} /* end OS_BinSemFlush_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTake_Impl (uint32 sem_id) -{ - /* Use common routine */ - return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, WAIT_FOREVER); - -} /* end OS_BinSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) -{ - return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, OS_Milli2Ticks(msecs)); -} /* end OS_BinSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_BinSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) -{ - /* VxWorks has no API for obtaining the current value of a semaphore */ - return OS_SUCCESS; -} /* end OS_BinSemGetInfo_Impl */ - - -/**************************************************************************************** - COUNTING SEMAPHORE API -****************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_CountSemAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_CountSemAPI_Impl_Init(void) -{ - memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); - return (OS_SUCCESS); -} /* end OS_VxWorks_CountSemAPI_Impl_Init */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) -{ - SEM_ID tmp_sem_id; - - /* Initialize VxWorks Semaphore. - * The memory for this sem is statically allocated. */ - tmp_sem_id = semCInitialize(OS_impl_count_sem_table[sem_id].cmem, SEM_Q_PRIORITY, sem_initial_value); - - /* check if semCInitialize failed */ - if(tmp_sem_id == (SEM_ID)0) - { - OS_DEBUG("semCInitialize() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - OS_impl_count_sem_table[sem_id].vxid = tmp_sem_id; - return OS_SUCCESS; - -} /* end OS_CountSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemDelete_Impl (uint32 sem_id) -{ - /* - * As the memory for the sem is statically allocated, delete is a no-op. - */ - OS_impl_count_sem_table[sem_id].vxid = 0; - return OS_SUCCESS; - -} /* end OS_CountSemDelete_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGive_Impl (uint32 sem_id) -{ - /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_count_sem_table[sem_id].vxid); -} /* end OS_CountSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTake_Impl (uint32 sem_id) -{ - return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, WAIT_FOREVER); -} /* end OS_CountSemTake_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemTimedWait_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs) -{ - return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, - OS_Milli2Ticks(msecs)); -} /* end OS_CountSemTimedWait_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_CountSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) -{ - /* VxWorks does not provide an API to get the value */ - return OS_SUCCESS; - -} /* end OS_CountSemGetInfo_Impl */ - -/**************************************************************************************** - MUTEX API -****************************************************************************************/ - - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_MutexAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_MutexAPI_Impl_Init(void) -{ - memset(OS_impl_mut_sem_table, 0, sizeof(OS_impl_mut_sem_table)); - return (OS_SUCCESS); -} /* end OS_VxWorks_MutexAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) -{ - SEM_ID tmp_sem_id; - - /* Initialize VxWorks Semaphore. - * The memory for this sem is statically allocated. */ - tmp_sem_id = semMInitialize(OS_impl_mut_sem_table[sem_id].mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); - - if(tmp_sem_id == (SEM_ID)0) - { - OS_DEBUG("semMInitalize() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - OS_impl_mut_sem_table[sem_id].vxid = tmp_sem_id; - return OS_SUCCESS; -} /* end OS_MutSemCreate_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemDelete_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemDelete_Impl (uint32 sem_id) -{ - /* - * As the memory for the sem is statically allocated, delete is a no-op. - */ - OS_impl_mut_sem_table[sem_id].vxid = 0; - return OS_SUCCESS; - -} /* end OS_MutSemDelete_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGive_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGive_Impl (uint32 sem_id) -{ - /* Give VxWorks Semaphore */ - return OS_VxWorks_GenericSemGive(OS_impl_mut_sem_table[sem_id].vxid); -} /* end OS_MutSemGive_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemTake_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemTake_Impl (uint32 sem_id) -{ - /* Take VxWorks Semaphore */ - return OS_VxWorks_GenericSemTake(OS_impl_mut_sem_table[sem_id].vxid, WAIT_FOREVER); -} /* end OS_MutSemTake_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_MutSemGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) -{ - /* VxWorks provides no additional info */ - return OS_SUCCESS; - -} /* end OS_MutSemGetInfo_Impl */ - -/**************************************************************************************** - TICK API -****************************************************************************************/ - -#ifndef OSAL_OMIT_DEPRECATED - -/**************************************************************************************** - INT API -****************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) -{ - /* The Xenomai-VxWorks emulation layer does not support interrupt control */ - if(intConnect(INUM_TO_IVEC(InterruptNumber), - (VOIDFUNCPTR)InterruptHandler, parameter) != OK) - { - return OS_ERROR; - } - - return OS_SUCCESS; -} /* end OS_IntAttachHandler_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_IntUnlock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntUnlock_Impl (int32 IntLevel) -{ - intUnlock(IntLevel); - return(OS_SUCCESS); -} /* end OS_IntUnlock_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntLock_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntLock_Impl (void) -{ - return (int32)intLock(); -} /* end OS_IntLock_Impl */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_IntEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntEnable_Impl (int32 Level) -{ - int32 RetCode; - int Status; - - Status = intEnable(Level); - - if(Status == OK) - { - RetCode = OS_SUCCESS; - } - else - { - RetCode = OS_ERROR; - } - - return RetCode; -} /* end OS_IntEnable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntDisable_Impl (int32 Level) -{ - int32 RetCode; - int Status; - - Status = intDisable(Level); - - if(Status == OK) - { - RetCode = OS_SUCCESS; - } - else - { - RetCode = OS_ERROR; - } - - return RetCode; -} /* end OS_IntDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) -{ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_IntGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) -{ - *MaskSettingPtr = 0; - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_IntGetMask_Impl */ - -#endif /* OSAL_OMIT_DEPRECATED */ - -/*---------------------------------------------------------------- - * - * Function: OS_HeapGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_HeapGetInfo_Impl (OS_heap_prop_t *heap_prop) -{ - MEM_PART_STATS stats; - STATUS status; - - status = memPartInfoGet(memSysPartId, &stats); - - if (status != OK) - { - return OS_ERROR; - } - - heap_prop->free_bytes = stats.numBytesFree; - heap_prop->free_blocks = stats.numBlocksFree; - heap_prop->largest_free_block = stats.maxBlockSizeFree; - - return (OS_SUCCESS); -} /* end OS_HeapGetInfo_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcAttachHandler_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, - int32 parameter) -{ - /* - ** Not implemented in VxWorks. - */ - return(OS_ERR_NOT_IMPLEMENTED); -} /* end OS_FPUExcAttachHandler_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcEnable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in VxWorks. - */ - return(OS_SUCCESS); -} /* end OS_FPUExcEnable_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcDisable_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) -{ - /* - ** Not implemented in VxWorks. - */ - return(OS_SUCCESS); -} /* end OS_FPUExcDisable_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcSetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcSetMask_Impl(uint32 mask) -{ - int32 Status; - - /* - * only implemented on ppc except ppc440 - * carry-over from previous vxworks osal - */ -#if defined(_PPC_) && CPU != PPC440 - vxFpscrSet( mask); - Status = OS_SUCCESS; -#else - Status = OS_ERR_NOT_IMPLEMENTED; -#endif - - return Status; -} /* end OS_FPUExcSetMask_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_FPUExcGetMask_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_FPUExcGetMask_Impl(uint32 *mask) -{ - int32 Status; - -#if defined(_PPC_) && CPU != PPC440 - *mask = vxFpscrGet(); - Status = OS_SUCCESS; -#else - Status = OS_ERR_NOT_IMPLEMENTED; -#endif - return Status; -} /* end OS_FPUExcGetMask_Impl */ - -/********************************************************************/ -/* CONSOLE OUTPUT */ -/********************************************************************/ - - - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleOutput_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ConsoleOutput_Impl(uint32 local_id) -{ - uint32 StartPos; - uint32 EndPos; - OS_console_internal_record_t *console; - - console = &OS_console_table[local_id]; - StartPos = console->ReadPos; - EndPos = console->WritePos; - while (StartPos != EndPos) - { - putchar(console->BufBase[StartPos]); - ++StartPos; - if (StartPos >= console->BufSize) - { - /* handle wrap */ - StartPos = 0; - } - } - - /* Update the global with the new read location */ - console->ReadPos = StartPos; -} /* end OS_ConsoleOutput_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleWakeup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - - if (local->is_async) - { - /* post the sem for the utility task to run */ - if(semGive(local->datasem) == ERROR) - { - OS_DEBUG("semGive() - vxWorks errno %d\n",errno); - } - } - else - { - /* output directly */ - OS_ConsoleOutput_Impl(local_id); - } -} /* end OS_ConsoleWakeup_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleTask_Entry - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -static void OS_ConsoleTask_Entry(int arg) -{ - uint32 local_id = arg; - OS_impl_console_internal_record_t *local; - - local = &OS_impl_console_table[local_id]; - while (true) - { - OS_ConsoleOutput_Impl(local_id); - if(semTake(local->datasem, WAIT_FOREVER) == ERROR) - { - OS_DEBUG("semTake() - vxWorks errno %d\n",errno); - break; - } - } -} /* end OS_ConsoleTask_Entry */ - -/*---------------------------------------------------------------- - * - * Function: OS_ConsoleCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ConsoleCreate_Impl(uint32 local_id) -{ - OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; - int32 return_code; - - if (local_id == 0) - { - return_code = OS_SUCCESS; - local->is_async = OS_CONSOLE_ASYNC; - - if (local->is_async) - { - OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); - - /* Initialize VxWorks Semaphore. - * The memory for this sem is statically allocated. */ - local->datasem = semCInitialize(local->cmem, SEM_Q_PRIORITY, 0); - - /* check if semCInitialize failed */ - if(local->datasem == (SEM_ID)0) - { - OS_DEBUG("semCInitialize() - vxWorks errno %d\n",errno); - return OS_SEM_FAILURE; - } - - /* spawn the async output helper task */ - local->taskid = taskSpawn(OS_console_table[local_id].device_name, - OS_CONSOLE_TASK_PRIORITY, - 0, - OS_CONSOLE_TASK_STACKSIZE , - (FUNCPTR)OS_ConsoleTask_Entry, - local_id,0,0,0,0,0,0,0,0,0); - - if (local->taskid == (TASK_ID)ERROR) - { - OS_DEBUG("taskSpawn() - vxWorks errno %d\n",errno); - return_code = OS_ERROR; - } - } - } - else - { - /* only one physical console device is implemented */ - return_code = OS_ERR_NOT_IMPLEMENTED; - } - - return return_code; -} /* end OS_ConsoleCreate_Impl */ - - - diff --git a/src/os/vxworks/osfileapi.c b/src/os/vxworks/osfileapi.c deleted file mode 100644 index 09b1b291a..000000000 --- a/src/os/vxworks/osfileapi.c +++ /dev/null @@ -1,328 +0,0 @@ -/* -** File : osfileapi.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original RTEMS implementation by Nicholas Yanchik -** -** Purpose: This file Contains all of the api calls for manipulating -** files in a file system for RTEMS -** -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * Leverage the POSIX-style File I/O as this will also work on vxWorks. - */ - -/* - * VxWorks does not have UID/GID so these are defined as 0. - */ -#define OS_IMPL_SELF_EUID 0 -#define OS_IMPL_SELF_EGID 0 - -/* - * VxWorks needs to cast the argument to "write()" to avoid a warning. - * This can be turned off in a future version if the vendor fixes the - * prototype to be standards-compliant - */ -#define GENERIC_IO_CONST_DATA_CAST (void*) - -/* - * The global file handle table. - * - * This is shared by all OSAL entities that perform low-level I/O. - */ -OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; - -/* - * The directory handle table. - */ -DIR *OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; - - - -/* - * Flag(s) to set on file handles for regular files - * This sets all regular filehandles to be non-blocking by default. - * - * In turn, the implementation will utilize select() to determine - * a filehandle readiness to read/write. - */ -const int OS_IMPL_REGULAR_FILE_FLAGS = 0; - - - -/* - * The "I/O" portable block includes the generic - * posix-style read/write/seek/close operations - */ -#include "../portable/os-impl-posix-io.c" - -/* - * The "Files" portable block includes impl - * calls for named files i.e. FileOpen and FileStat - * This is anything that operates on a pathname. - */ -#include "../portable/os-impl-posix-files.c" - -/* - * VxWorks does not quite follow the POSIX definition - * for the directory access, so the os-impl-posix-dirs block - * cannot be used here. This is similar code but VxWorks - * defines the e.g. mkdir() system calls differently. - */ - - -/*---------------------------------------------------------------- - * - * Function: OS_DirCreate_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirCreate_Impl(const char *local_path, uint32 access) -{ - int32 return_code; - - if ( mkdir(local_path) != OK ) - { - return_code = OS_FS_ERROR; - } - else - { - return_code = OS_FS_SUCCESS; - } - - return return_code; -} /* end OS_DirCreate_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirOpen_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) -{ - OS_impl_dir_table[local_id] = opendir(local_path); - if (OS_impl_dir_table[local_id] == NULL) - { - return OS_FS_ERROR; - } - return OS_FS_SUCCESS; -} /* end OS_DirOpen_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirClose_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirClose_Impl(uint32 local_id) -{ - closedir(OS_impl_dir_table[local_id]); - OS_impl_dir_table[local_id] = NULL; - return OS_FS_SUCCESS; -} /* end OS_DirClose_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRead_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) -{ - struct dirent *de; - - /* NOTE - the readdir() call is non-reentrant .... - * However, this is performed while the global dir table lock is taken. - * Therefore this ensures that only one such call can occur at any given time. - * - * Static analysis tools may warn about this because they do not know - * this function is externally serialized via the global lock. - */ - /* cppcheck-suppress readdirCalled */ - /* cppcheck-suppress nonreentrantFunctionsreaddir */ - de = readdir(OS_impl_dir_table[local_id]); - if (de == NULL) - { - return OS_FS_ERROR; - } - - strncpy(dirent->FileName, de->d_name, OS_MAX_PATH_LEN - 1); - dirent->FileName[OS_MAX_PATH_LEN - 1] = 0; - - return OS_FS_SUCCESS; -} /* end OS_DirRead_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRewind_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRewind_Impl(uint32 local_id) -{ - rewinddir(OS_impl_dir_table[local_id]); - return OS_FS_SUCCESS; -} /* end OS_DirRewind_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_DirRemove_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_DirRemove_Impl(const char *local_path) -{ - if ( rmdir(local_path) < 0 ) - { - return OS_FS_ERROR; - } - - return OS_FS_SUCCESS; -} /* end OS_DirRemove_Impl */ - - -/**************************************************************************************** - DEFINES -****************************************************************************************/ - -#define OS_REDIRECTSTRSIZE 15 -#define OS_SHELL_TMP_FILE_EXT ".out" -#define OS_SHELL_TMP_FILE_EXT_LEN 4 -#define OS_SHELL_CMD_TASK_STACK_SIZE 16384 -#define OS_SHELL_CMD_TASK_PRIORITY 250 - - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_StreamAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_StreamAPI_Impl_Init(void) -{ - uint32 local_id; - - /* - * init all filehandles to -1, which is always invalid. - * this isn't strictly necessary but helps when debugging. - */ - for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) - { - OS_impl_filehandle_table[local_id].fd = -1; - } - - return OS_SUCCESS; -} /* end OS_VxWorks_StreamAPI_Impl_Init */ - - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_DirAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_DirAPI_Impl_Init(void) -{ - memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); - return OS_SUCCESS; -} /* end OS_VxWorks_DirAPI_Impl_Init */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_ShellOutputToFile_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) -{ - int32 ReturnCode = OS_FS_ERROR; - int32 Result = ERROR; - int32 fdCmd; - uint32 cmdidx; - char * shellName; - - /* Create a file to write the command to (or write over the old one) */ - fdCmd = OS_creat(OS_SHELL_CMD_INPUT_FILE_NAME,OS_READ_WRITE); - - if (fdCmd < OS_FS_SUCCESS) - { - return OS_FS_ERROR; - } - - if (OS_ConvertToArrayIndex(fdCmd, &cmdidx) == OS_SUCCESS) - { - /* copy the command to the file, and then seek back to the beginning of the file */ - OS_write(fdCmd, Cmd, strlen(Cmd)); - OS_lseek(fdCmd,0,OS_SEEK_SET); - - /* Create a shell task the will run the command in the file, push output to OS_fd */ - Result = shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, - OS_impl_filehandle_table[cmdidx].fd, - OS_impl_filehandle_table[file_id].fd, - OS_impl_filehandle_table[file_id].fd); - } - - if (Result == OK) - { - /* Wait for the command to terminate */ - do - { - taskDelay(sysClkRateGet()); - } - while (taskNameToId(shellName) != ((TASK_ID)ERROR)); - - ReturnCode = OS_SUCCESS; - } - - /* Close the file descriptor */ - OS_close(fdCmd); - - return ReturnCode; - -} /* end OS_ShellOutputToFile_Impl */ - diff --git a/src/os/vxworks/osloader.c b/src/os/vxworks/osloader.c deleted file mode 100644 index 652a550d8..000000000 --- a/src/os/vxworks/osloader.c +++ /dev/null @@ -1,413 +0,0 @@ -/* -** File : osloader.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original RTEMS implementation by Alan Cudmore -** -** Purpose: This file contains the module loader and symbol lookup functions for the OSAL. -** Currently this relies on the CEXP external module loader. A "static" loader -** is not yet implemented as that code is not open source yet. -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" - -#include -#include /* memset() */ -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -/* - * Vxworks 6.9 has stricter function pointer types - * These are for the symEach() callback - * they are supplied in 6.9 but not defined in 6.4 - */ -#if defined(_WRS_VXWORKS_MAJOR) && (_WRS_VXWORKS_MAJOR > 6 || _WRS_VXWORKS_MINOR >= 9) -/* no cast to FUNCPTR - use real type checking */ -#define SYMEACH_FUNC -#else /* before 6.9 */ -/* in prior versions the symEach `callback is cast to FUNCPTR */ -#define SYMEACH_FUNC (FUNCPTR) -typedef int _Vx_usr_arg_t; -typedef UINT16 SYM_GROUP; -typedef char * SYM_VALUE; -#endif - -typedef struct -{ - char SymbolName[OS_MAX_SYM_LEN]; - cpuaddr SymbolAddress; -} SymbolRecord_t; - -typedef struct -{ - uint32 Sizelimit; - uint32 CurrSize; - int32 StatusCode; - int fd; -} SymbolDumpState_t; - - -/* A global for storing the state in a SymbolDump call */ -static struct -{ - SymbolDumpState_t sym_dump; -#if (OS_MAX_MODULES > 0) - MODULE_ID vxid_table[OS_MAX_MODULES]; -#endif -} OS_impl_module_global; - -/* the system symbol table */ -extern SYMTAB_ID sysSymTbl; - -/**************************************************************************************** - INITIALIZATION FUNCTION - ***************************************************************************************/ - -/*---------------------------------------------------------------- - * - * Function: OS_VxWorks_ModuleAPI_Impl_Init - * - * Purpose: Local helper routine, not part of OSAL API. - * - *-----------------------------------------------------------------*/ -int32 OS_VxWorks_ModuleAPI_Impl_Init(void) -{ - memset(&OS_impl_module_global, 0, sizeof(OS_impl_module_global)); - return(OS_SUCCESS); -} /* end OS_VxWorks_ModuleAPI_Impl_Init */ - - - -/*---------------------------------------------------------------- - * - * Function: OS_SymbolLookup_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) -{ - STATUS vxStatus; - - /* - ** Check parameters - */ - if (( SymbolAddress == NULL ) || (SymbolName == NULL )) - { - return(OS_INVALID_POINTER); - } - - /* - ** Lookup the entry point - ** - ** VxWorks 6.9 has deprecated the "symFindByName" API and it is replaced - ** with a "symFind" API instead. - */ - -#if defined(_WRS_VXWORKS_MAJOR) && (_WRS_VXWORKS_MAJOR > 6 || _WRS_VXWORKS_MINOR >= 9) - { - SYMBOL_DESC SymDesc; - - memset (&SymDesc, 0, sizeof (SYMBOL_DESC)); - SymDesc.mask = SYM_FIND_BY_NAME; - SymDesc.name = (char*)SymbolName; - - vxStatus = symFind(sysSymTbl,&SymDesc); - *SymbolAddress = (cpuaddr)SymDesc.value; - } -#else /* Before VxWorks 6.9 */ - { - SYM_TYPE SymType; - SYM_VALUE SymValue; - - vxStatus = symFindByName (sysSymTbl, (char *)SymbolName, &SymValue, &SymType); - *SymbolAddress = (cpuaddr)SymValue; - } -#endif - - if (vxStatus == ERROR) - { - return(OS_ERROR); - } - - - return(OS_SUCCESS); - -} /* end OS_SymbolLookup_Impl */ - -/*---------------------------------------------------------------- - * - * Function: OS_SymTableIterator_Impl - * - * Purpose: Local helper routine, not part of OSAL API. - * Function called by vxWorks to iterate the vxworks symbol table - * - * Parameters: - * name - The symbol name - * val - The symbol address value - * type - The vxWorks symbol type ( not used ) - * max_size - The maximum size of the file that is written to. - * group - The vxWorks symbol group ( not used ) - * - * Returns: true to tell vxWorks to continue to iterate the symbol table - * false to tell vxWorks to stop iterating the symbol table - * - * The address of the symbol will be stored in the pointer that is passed in. - * - *-----------------------------------------------------------------*/ -static BOOL OS_SymTableIterator_Impl ( char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_arg_t arg, SYM_GROUP group ) -{ - SymbolRecord_t symRecord; - uint32 NextSize; - int status; - SymbolDumpState_t *state; - - /* - * Rather than passing the state pointer through the generic "int" arg, - * use a global. This is OK because dumps are serialized externally. - */ - state = &OS_impl_module_global.sym_dump; - - if (strlen(name) >= OS_MAX_SYM_LEN) - { - OS_DEBUG("%s(): symbol name too long\n", __func__); - state->StatusCode = OS_ERROR; - return(false); - } - - /* - ** Check to see if the maximum size of the file has been reached - */ - NextSize = state->CurrSize + sizeof(symRecord); - if ( NextSize > state->Sizelimit ) - { - /* - ** We exceeded the maximum size, so tell vxWorks to stop - ** However this is not considered an error, just a stop condition. - */ - OS_DEBUG("%s(): symbol table size exceeded\n", __func__); - return(false); - } - - /* - ** Copy symbol name - */ - strncpy(symRecord.SymbolName, name, OS_MAX_SYM_LEN); - - /* - ** Save symbol address - */ - symRecord.SymbolAddress = (cpuaddr)val; - - /* - ** Write entry in file - */ - status = write(state->fd, (char *)&symRecord, sizeof(symRecord)); - /* There is a problem if not all bytes were written OR if we get an error - * value, < 0. */ - if ( status < (int)sizeof(symRecord) ) - { - state->StatusCode = OS_ERROR; - return(false); - } - - state->CurrSize = NextSize; - - /* - ** It's OK to continue - */ - return(true); -} /* end OS_SymTableIterator_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_SymbolTableDump_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_SymbolTableDump_Impl ( const char *local_filename, uint32 SizeLimit ) -{ - SymbolDumpState_t *state; - - /* - * Rather than passing the state pointer through the generic "int" arg, - * use a global. This is OK because dumps are serialized externally. - */ - state = &OS_impl_module_global.sym_dump; - - memset(state, 0, sizeof(*state)); - state->Sizelimit = SizeLimit; - - /* - ** Open file - */ - state->fd = open(local_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); - if ( state->fd < 0 ) - { - OS_DEBUG("open(%s): error: %s\n", local_filename, strerror(errno)); - state->StatusCode = OS_ERROR; - } - else - { - /* - ** Iterate the symbol table - */ - (void) symEach( sysSymTbl, SYMEACH_FUNC OS_SymTableIterator_Impl, 0 ); - - close(state->fd); - } - - return(state->StatusCode); - -} /* end OS_SymbolTableDump_Impl */ - -/**************************************************************************************** - Module Loader API -****************************************************************************************/ - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleLoad_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleLoad_Impl ( uint32 local_id, const char *translated_path ) -{ - int32 return_code; - int fd; - MODULE_ID vxModuleId; - - /* - ** File is ready to load - */ - - /* - ** Open the file - */ - fd = open (translated_path, O_RDONLY, 0); - if( fd < 0 ) - { - OS_DEBUG("OSAL: Error, cannot open application file: %s\n",translated_path); - return_code = OS_ERROR; - } - else - { - /* - ** Load the module - */ - vxModuleId = loadModule (fd, LOAD_ALL_SYMBOLS); - - if( vxModuleId == (MODULE_ID)0 ) - { - OS_DEBUG("OSAL: Error, cannot load module: %s\n",translated_path); - return_code = OS_ERROR; - } - else - { - OS_impl_module_global.vxid_table[local_id] = vxModuleId; - return_code = OS_SUCCESS; - } - - /* - ** Close the file - */ - close(fd); - } - - return(return_code); - -} /* end OS_ModuleLoad_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleUnload_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleUnload_Impl ( uint32 local_id ) -{ - STATUS vxStatus; - - /* - ** Attempt to close/unload the module - */ - vxStatus = unldByModuleId((MODULE_ID )OS_impl_module_global.vxid_table[local_id], 0); - if ( vxStatus == ERROR ) - { - OS_DEBUG("OSAL: Error, Cannot Close/Unload application file: %d\n",vxStatus); - return(OS_ERROR); - } - - return(OS_SUCCESS); - -} /* end OS_ModuleUnload_Impl */ - - -/*---------------------------------------------------------------- - * - * Function: OS_ModuleGetInfo_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_ModuleGetInfo_Impl ( uint32 local_id, OS_module_prop_t *module_prop ) -{ - MODULE_INFO vxModuleInfo; - STATUS vxStatus; - - - module_prop->host_module_id = (cpuaddr)OS_impl_module_global.vxid_table[local_id]; - - /* - ** Get the module info from vxWorks - */ - vxStatus = moduleInfoGet(OS_impl_module_global.vxid_table[local_id], &vxModuleInfo); - if ( vxStatus == ERROR ) - { - OS_DEBUG("OSAL: OS_ModuleInfoGet Error from vxWorks: %d\n",vxStatus); - } - else - { - module_prop->addr.valid = true; - module_prop->addr.code_address = (cpuaddr)vxModuleInfo.segInfo.textAddr; - module_prop->addr.code_size = vxModuleInfo.segInfo.textSize; - module_prop->addr.data_address = (cpuaddr)vxModuleInfo.segInfo.dataAddr; - module_prop->addr.data_size = vxModuleInfo.segInfo.dataSize; - module_prop->addr.bss_address = (cpuaddr)vxModuleInfo.segInfo.bssAddr; - module_prop->addr.bss_size = vxModuleInfo.segInfo.bssSize; - } - - return(OS_SUCCESS); - -} /* end OS_ModuleGetInfo_Impl */ - diff --git a/src/os/vxworks/osnetwork.c b/src/os/vxworks/osnetwork.c deleted file mode 100644 index 259d79615..000000000 --- a/src/os/vxworks/osnetwork.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -** File : osnetwork.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original RTEMS implementation by Nicholas Yanchik -** -** Purpose: This file contains the network functionality for the osapi. -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" - -#ifdef OS_INCLUDE_NETWORK - -#include -#include -#include -#include -#include -#include -#include - -/* Leverage the portable BSD sockets implementation */ -#define BSDSOCKET_HANDLE_OPTIONS 0 -#define OS_HOST_NAME_LEN 48 - -/* - * Use the O_NONBLOCK flag on sockets - */ -const int OS_IMPL_SOCKET_FLAGS = O_NONBLOCK; - - -/* The "in.h" header file supplied in VxWorks 6.9 is missing the "in_port_t" typedef */ -typedef u_short in_port_t; - - -#include "../portable/os-impl-bsd-sockets.c" - - - -/*---------------------------------------------------------------- - * - * Function: OS_NetworkGetID_Impl - * - * Purpose: Implemented per internal OSAL API - * See prototype in os-impl.h for argument/return detail - * - *-----------------------------------------------------------------*/ -int32 OS_NetworkGetID_Impl (int32 *IdBuf) -{ - int host_id; - int32 status; - char host_name [OS_HOST_NAME_LEN]; - - status = OS_NetworkGetHostName_Impl(host_name, sizeof(host_name)); - if (status == OS_SUCCESS) - { - host_id = hostGetByName(host_name); - if (host_id == ERROR) - { - status = OS_ERROR; - } - else - { - *IdBuf = (int32)host_id; - status = OS_SUCCESS; - } - } - - return status; - -} /* end OS_NetworkGetID_Impl */ - - -#endif - diff --git a/src/os/vxworks/osselect.c b/src/os/vxworks/osselect.c deleted file mode 100644 index ed05c04b0..000000000 --- a/src/os/vxworks/osselect.c +++ /dev/null @@ -1,30 +0,0 @@ -/* -** File : osselect.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey -** -** Purpose: This file contains wrappers around the select() system call -** -*/ - -/**************************************************************************************** - INCLUDE FILES -****************************************************************************************/ - -#include "os-vxworks.h" - -#include - -/* - * Use the BSD-style select() API - */ -#include "../portable/os-impl-bsd-select.c" - diff --git a/src/os/vxworks/src/os-impl-binsem.c b/src/os/vxworks/src/os-impl-binsem.c new file mode 100644 index 000000000..112b07fe7 --- /dev/null +++ b/src/os/vxworks/src/os-impl-binsem.c @@ -0,0 +1,189 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-binsem.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" + +#include "os-impl-binsem.h" +#include "osapi-binsem-impl.h" + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +/* Tables where the OS object information is stored */ +OS_impl_binsem_internal_record_t OS_impl_bin_sem_table [OS_MAX_BIN_SEMAPHORES]; + + +/**************************************************************************************** + BINARY SEMAPHORE API +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_BinSemAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_BinSemAPI_Impl_Init(void) +{ + memset(OS_impl_bin_sem_table, 0, sizeof(OS_impl_bin_sem_table)); + return (OS_SUCCESS); +} /* end OS_VxWorks_BinSemAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) +{ + SEM_ID tmp_sem_id; + + /* Initialize VxWorks Semaphore. + * The memory for this sem is statically allocated. */ + tmp_sem_id = semBInitialize(OS_impl_bin_sem_table[sem_id].bmem, SEM_Q_PRIORITY, sem_initial_value); + + /* check if semBInitialize failed */ + if(tmp_sem_id == (SEM_ID)0) + { + OS_DEBUG("semBInitialize() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + OS_impl_bin_sem_table[sem_id].vxid = tmp_sem_id; + return OS_SUCCESS; + +} /* end OS_BinSemCreate_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemDelete_Impl (uint32 sem_id) +{ + /* + * As the memory for the sem is statically allocated, delete is a no-op. + */ + OS_impl_bin_sem_table[sem_id].vxid = 0; + return OS_SUCCESS; + +} /* end OS_BinSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGive_Impl (uint32 sem_id) +{ + /* Use common routine */ + return OS_VxWorks_GenericSemGive(OS_impl_bin_sem_table[sem_id].vxid); +} /* end OS_BinSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemFlush_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemFlush_Impl (uint32 sem_id) +{ + /* Flush VxWorks Semaphore */ + if(semFlush(OS_impl_bin_sem_table[sem_id].vxid) != OK) + { + OS_DEBUG("semFlush() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_BinSemFlush_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTake_Impl (uint32 sem_id) +{ + /* Use common routine */ + return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, WAIT_FOREVER); + +} /* end OS_BinSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemTimedWait_Impl (uint32 sem_id, uint32 msecs) +{ + return OS_VxWorks_GenericSemTake(OS_impl_bin_sem_table[sem_id].vxid, OS_Milli2Ticks(msecs)); +} /* end OS_BinSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_BinSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *bin_prop) +{ + /* VxWorks has no API for obtaining the current value of a semaphore */ + return OS_SUCCESS; +} /* end OS_BinSemGetInfo_Impl */ + + diff --git a/src/os/vxworks/src/os-impl-common.c b/src/os/vxworks/src/os-impl-common.c new file mode 100644 index 000000000..f8de95e82 --- /dev/null +++ b/src/os/vxworks/src/os-impl-common.c @@ -0,0 +1,200 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-common.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" + +#include "osapi-common-impl.h" + +#include +#include +#include +#include +#include + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + + +static TASK_ID OS_idle_task_id; + + +/**************************************************************************************** + INITIALIZATION FUNCTION +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_API_Impl_Init + * + * Purpose: Initialize the tables that the OS API uses to keep track of information + * about objects + * + *-----------------------------------------------------------------*/ +int32 OS_API_Impl_Init(uint32 idtype) +{ + int32 return_code; + + return_code = OS_VxWorks_TableMutex_Init(idtype); + if (return_code != OS_SUCCESS) + { + return return_code; + } + + switch(idtype) + { + case OS_OBJECT_TYPE_OS_TASK: + return_code = OS_VxWorks_TaskAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_QUEUE: + return_code = OS_VxWorks_QueueAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_BINSEM: + return_code = OS_VxWorks_BinSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_COUNTSEM: + return_code = OS_VxWorks_CountSemAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MUTEX: + return_code = OS_VxWorks_MutexAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_MODULE: + return_code = OS_VxWorks_ModuleAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_TIMEBASE: + return_code = OS_VxWorks_TimeBaseAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_STREAM: + return_code = OS_VxWorks_StreamAPI_Impl_Init(); + break; + case OS_OBJECT_TYPE_OS_DIR: + return_code = OS_VxWorks_DirAPI_Impl_Init(); + break; + default: + break; + } + + return(return_code); +} /* end OS_API_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IdleLoop_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_IdleLoop_Impl(void) +{ + TASK_ID tid = taskIdSelf(); + OS_idle_task_id = tid; + taskSuspend(tid); +} /* end OS_IdleLoop_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ApplicationShutdown_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ApplicationShutdown_Impl(void) +{ + taskResume(OS_idle_task_id); +} /* end OS_ApplicationShutdown_Impl */ + + + + +/**************************************************************************************** + GENERIC SEMAPHORE API +****************************************************************************************/ + +/* + * ---------------------------------- + * generic semaphore give/take - + * VxWorks uses the sem semTake()/semGive() API for all types of semaphores. + * Only the initialization is different between them. + * Therefore all semaphore actions can just invoke these generic actions + * ----------------------------------- + */ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_GenericSemGive + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_GenericSemGive(SEM_ID vxid) +{ + /* Give VxWorks Semaphore */ + if(semGive(vxid) != OK) + { + OS_DEBUG("semGive() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + return OS_SUCCESS; +} /* end OS_VxWorks_GenericSemGive */ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_GenericSemTake + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks) +{ + int vx_status; + + /* Take VxWorks Semaphore */ + vx_status = semTake(vxid, sys_ticks); + if (vx_status != OK) + { + /* + * check for the timeout condition, + * which has a different return code and + * not necessarily an error of concern. + */ + if (errno == S_objLib_OBJ_TIMEOUT) + { + return OS_SEM_TIMEOUT; + } + + OS_DEBUG("semTake() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + return OS_SUCCESS; +} /* end OS_VxWorks_GenericSemTake */ + diff --git a/src/os/vxworks/src/os-impl-console.c b/src/os/vxworks/src/os-impl-console.c new file mode 100644 index 000000000..b14f4c917 --- /dev/null +++ b/src/os/vxworks/src/os-impl-console.c @@ -0,0 +1,202 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-console.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-console.h" + +#include "osapi-printf-impl.h" + +/**************************************************************************************** + DEFINES +****************************************************************************************/ +/* + * By default the console output is always asynchronous + * (equivalent to "OS_UTILITY_TASK_ON" being set) + * + * This option was removed from osconfig.h and now is + * assumed to always be on. + */ +#define OS_CONSOLE_ASYNC true +#define OS_CONSOLE_TASK_PRIORITY OS_UTILITYTASK_PRIORITY +#define OS_CONSOLE_TASK_STACKSIZE OS_UTILITYTASK_STACK_SIZE + + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +/* Tables where the OS object information is stored */ +OS_impl_console_internal_record_t OS_impl_console_table [OS_MAX_CONSOLES]; + + +/********************************************************************/ +/* CONSOLE OUTPUT */ +/********************************************************************/ + + + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleOutput_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ConsoleOutput_Impl(uint32 local_id) +{ + uint32 StartPos; + uint32 EndPos; + OS_console_internal_record_t *console; + + console = &OS_console_table[local_id]; + StartPos = console->ReadPos; + EndPos = console->WritePos; + while (StartPos != EndPos) + { + putchar(console->BufBase[StartPos]); + ++StartPos; + if (StartPos >= console->BufSize) + { + /* handle wrap */ + StartPos = 0; + } + } + + /* Update the global with the new read location */ + console->ReadPos = StartPos; +} /* end OS_ConsoleOutput_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleWakeup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_ConsoleWakeup_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + + if (local->is_async) + { + /* post the sem for the utility task to run */ + if(semGive(local->datasem) == ERROR) + { + OS_DEBUG("semGive() - vxWorks errno %d\n",errno); + } + } + else + { + /* output directly */ + OS_ConsoleOutput_Impl(local_id); + } +} /* end OS_ConsoleWakeup_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleTask_Entry + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int OS_VxWorks_ConsoleTask_Entry(int arg) +{ + uint32 local_id = arg; + OS_impl_console_internal_record_t *local; + + local = &OS_impl_console_table[local_id]; + while (true) + { + OS_ConsoleOutput_Impl(local_id); + if(semTake(local->datasem, WAIT_FOREVER) == ERROR) + { + OS_DEBUG("semTake() - vxWorks errno %d\n",errno); + break; + } + } + + return OK; +} /* end OS_ConsoleTask_Entry */ + +/*---------------------------------------------------------------- + * + * Function: OS_ConsoleCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ConsoleCreate_Impl(uint32 local_id) +{ + OS_impl_console_internal_record_t *local = &OS_impl_console_table[local_id]; + int32 return_code; + + if (local_id == 0) + { + return_code = OS_SUCCESS; + local->is_async = OS_CONSOLE_ASYNC; + + if (local->is_async) + { + OS_DEBUG("%s(): Starting Async Console Handler\n", __func__); + + /* Initialize VxWorks Semaphore. + * The memory for this sem is statically allocated. */ + local->datasem = semCInitialize(local->cmem, SEM_Q_PRIORITY, 0); + + /* check if semCInitialize failed */ + if(local->datasem == (SEM_ID)0) + { + OS_DEBUG("semCInitialize() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + /* spawn the async output helper task */ + local->taskid = taskSpawn(OS_console_table[local_id].device_name, + OS_CONSOLE_TASK_PRIORITY, + 0, + OS_CONSOLE_TASK_STACKSIZE , + (FUNCPTR)OS_VxWorks_ConsoleTask_Entry, + local_id,0,0,0,0,0,0,0,0,0); + + if (local->taskid == (TASK_ID)ERROR) + { + OS_DEBUG("taskSpawn() - vxWorks errno %d\n",errno); + return_code = OS_ERROR; + } + } + } + else + { + /* only one physical console device is implemented */ + return_code = OS_ERR_NOT_IMPLEMENTED; + } + + return return_code; +} /* end OS_ConsoleCreate_Impl */ + + + diff --git a/src/os/vxworks/src/os-impl-countsem.c b/src/os/vxworks/src/os-impl-countsem.c new file mode 100644 index 000000000..2e979a1e3 --- /dev/null +++ b/src/os/vxworks/src/os-impl-countsem.c @@ -0,0 +1,167 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-countsem.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-countsem.h" + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + + +/* Tables where the OS object information is stored */ +OS_impl_countsem_internal_record_t OS_impl_count_sem_table [OS_MAX_COUNT_SEMAPHORES]; + +/**************************************************************************************** + COUNTING SEMAPHORE API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_CountSemAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_CountSemAPI_Impl_Init(void) +{ + memset(OS_impl_count_sem_table, 0, sizeof(OS_impl_count_sem_table)); + return (OS_SUCCESS); +} /* end OS_VxWorks_CountSemAPI_Impl_Init */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) +{ + SEM_ID tmp_sem_id; + + /* Initialize VxWorks Semaphore. + * The memory for this sem is statically allocated. */ + tmp_sem_id = semCInitialize(OS_impl_count_sem_table[sem_id].cmem, SEM_Q_PRIORITY, sem_initial_value); + + /* check if semCInitialize failed */ + if(tmp_sem_id == (SEM_ID)0) + { + OS_DEBUG("semCInitialize() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + OS_impl_count_sem_table[sem_id].vxid = tmp_sem_id; + return OS_SUCCESS; + +} /* end OS_CountSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemDelete_Impl (uint32 sem_id) +{ + /* + * As the memory for the sem is statically allocated, delete is a no-op. + */ + OS_impl_count_sem_table[sem_id].vxid = 0; + return OS_SUCCESS; + +} /* end OS_CountSemDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGive_Impl (uint32 sem_id) +{ + /* Give VxWorks Semaphore */ + return OS_VxWorks_GenericSemGive(OS_impl_count_sem_table[sem_id].vxid); +} /* end OS_CountSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTake_Impl (uint32 sem_id) +{ + return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, WAIT_FOREVER); +} /* end OS_CountSemTake_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemTimedWait_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemTimedWait_Impl (uint32 sem_id, uint32 msecs) +{ + return OS_VxWorks_GenericSemTake(OS_impl_count_sem_table[sem_id].vxid, + OS_Milli2Ticks(msecs)); +} /* end OS_CountSemTimedWait_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_CountSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) +{ + /* VxWorks does not provide an API to get the value */ + return OS_SUCCESS; + +} /* end OS_CountSemGetInfo_Impl */ + diff --git a/src/os/vxworks/src/os-impl-dirs.c b/src/os/vxworks/src/os-impl-dirs.c new file mode 100644 index 000000000..328f38bfc --- /dev/null +++ b/src/os/vxworks/src/os-impl-dirs.c @@ -0,0 +1,171 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-dirs.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-dirs.h" + + +/* + * The directory handle table. + */ +OS_impl_dir_internal_record_t OS_impl_dir_table[OS_MAX_NUM_OPEN_DIRS]; + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_DirAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_DirAPI_Impl_Init(void) +{ + memset(OS_impl_dir_table, 0, sizeof(OS_impl_dir_table)); + return OS_SUCCESS; +} /* end OS_VxWorks_DirAPI_Impl_Init */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_DirCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirCreate_Impl(const char *local_path, uint32 access) +{ + int32 return_code; + + if ( mkdir(local_path) != OK ) + { + return_code = OS_FS_ERROR; + } + else + { + return_code = OS_FS_SUCCESS; + } + + return return_code; +} /* end OS_DirCreate_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_DirOpen_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) +{ + OS_impl_dir_table[local_id].dp = opendir(local_path); + if (OS_impl_dir_table[local_id].dp == NULL) + { + return OS_FS_ERROR; + } + return OS_FS_SUCCESS; +} /* end OS_DirOpen_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_DirClose_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirClose_Impl(uint32 local_id) +{ + closedir(OS_impl_dir_table[local_id].dp); + OS_impl_dir_table[local_id].dp = NULL; + return OS_FS_SUCCESS; +} /* end OS_DirClose_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_DirRead_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) +{ + struct dirent *de; + + /* NOTE - the readdir() call is non-reentrant .... + * However, this is performed while the global dir table lock is taken. + * Therefore this ensures that only one such call can occur at any given time. + * + * Static analysis tools may warn about this because they do not know + * this function is externally serialized via the global lock. + */ + /* cppcheck-suppress readdirCalled */ + /* cppcheck-suppress nonreentrantFunctionsreaddir */ + de = readdir(OS_impl_dir_table[local_id].dp); + if (de == NULL) + { + return OS_FS_ERROR; + } + + strncpy(dirent->FileName, de->d_name, OS_MAX_PATH_LEN - 1); + dirent->FileName[OS_MAX_PATH_LEN - 1] = 0; + + return OS_FS_SUCCESS; +} /* end OS_DirRead_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_DirRewind_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirRewind_Impl(uint32 local_id) +{ + rewinddir(OS_impl_dir_table[local_id].dp); + return OS_FS_SUCCESS; +} /* end OS_DirRewind_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_DirRemove_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_DirRemove_Impl(const char *local_path) +{ + if ( rmdir(local_path) < 0 ) + { + return OS_FS_ERROR; + } + + return OS_FS_SUCCESS; +} /* end OS_DirRemove_Impl */ + diff --git a/src/os/vxworks/src/os-impl-errors.c b/src/os/vxworks/src/os-impl-errors.c new file mode 100644 index 000000000..cc7c491b5 --- /dev/null +++ b/src/os/vxworks/src/os-impl-errors.c @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-errors.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "osapi-errors-impl.h" + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; + diff --git a/src/os/vxworks/src/os-impl-files.c b/src/os/vxworks/src/os-impl-files.c new file mode 100644 index 000000000..ac18ad7c9 --- /dev/null +++ b/src/os/vxworks/src/os-impl-files.c @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-files.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-files.h" + +/* + * The global file handle table. + * + * This is shared by all OSAL entities that perform low-level I/O. + */ +OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_StreamAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_StreamAPI_Impl_Init(void) +{ + uint32 local_id; + + /* + * init all filehandles to -1, which is always invalid. + * this isn't strictly necessary but helps when debugging. + */ + for (local_id = 0; local_id < OS_MAX_NUM_OPEN_FILES; ++local_id) + { + OS_impl_filehandle_table[local_id].fd = -1; + OS_impl_filehandle_table[local_id].selectable = false; + } + + return OS_SUCCESS; +} /* end OS_VxWorks_StreamAPI_Impl_Init */ + + diff --git a/src/os/vxworks/osfilesys.c b/src/os/vxworks/src/os-impl-filesys.c similarity index 91% rename from src/os/vxworks/osfilesys.c rename to src/os/vxworks/src/os-impl-filesys.c index 510e38b58..9e606be35 100644 --- a/src/os/vxworks/osfilesys.c +++ b/src/os/vxworks/src/os-impl-filesys.c @@ -1,19 +1,22 @@ /* -** File : osfilesys.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original RTEMS implementation by Nicholas Yanchik -** -** Purpose: This file has the apis for all of the making -** and mounting type of calls for file systems -*/ + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-filesys.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ /**************************************************************************************** INCLUDE FILES @@ -21,6 +24,11 @@ #include "os-vxworks.h" +#include "os-impl-filesys.h" +#include "osapi-filesys-impl.h" +#include "osapi-idmap-impl.h" + + #include #include #include @@ -44,13 +52,6 @@ Data Types ****************************************************************************************/ -typedef struct -{ - BLK_DEV *blkDev; - device_t xbd; - uint32 xbdMaxPartitions; -} OS_impl_filesys_internal_record_t; - /**************************************************************************************** GLOBAL DATA ***************************************************************************************/ @@ -61,7 +62,7 @@ OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; Filesys API ****************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStartVolume_Impl @@ -172,7 +173,7 @@ int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) } /* end OS_FileSysStartVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStopVolume_Impl @@ -201,7 +202,7 @@ int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) } /* end OS_FileSysStopVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysFormatVolume_Impl @@ -230,7 +231,7 @@ int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) } /* end OS_FileSysFormatVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysMountVolume_Impl @@ -264,7 +265,7 @@ int32 OS_FileSysMountVolume_Impl (uint32 filesys_id) } /* end OS_FileSysMountVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysUnmountVolume_Impl @@ -305,7 +306,7 @@ int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id) } /* end OS_FileSysUnmountVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysStatVolume_Impl @@ -338,7 +339,7 @@ int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) } /* end OS_FileSysStatVolume_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_FileSysCheckVolume_Impl diff --git a/src/os/vxworks/src/os-impl-fpu.c b/src/os/vxworks/src/os-impl-fpu.c new file mode 100644 index 000000000..1ffbeec4f --- /dev/null +++ b/src/os/vxworks/src/os-impl-fpu.c @@ -0,0 +1,129 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-fpu.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" + + +/**************************************************************************************** + FPU API (deprecated) +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcAttachHandler_Impl(uint32 ExceptionNumber, osal_task_entry ExceptionHandler, + int32 parameter) +{ + /* + ** Not implemented in VxWorks. + */ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_FPUExcAttachHandler_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcEnable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in VxWorks. + */ + return(OS_SUCCESS); +} /* end OS_FPUExcEnable_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcDisable_Impl(int32 ExceptionNumber) +{ + /* + ** Not implemented in VxWorks. + */ + return(OS_SUCCESS); +} /* end OS_FPUExcDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcSetMask_Impl(uint32 mask) +{ + int32 Status; + + /* + * only implemented on ppc except ppc440 + * carry-over from previous vxworks osal + */ +#if defined(_PPC_) && CPU != PPC440 + vxFpscrSet( mask); + Status = OS_SUCCESS; +#else + Status = OS_ERR_NOT_IMPLEMENTED; +#endif + + return Status; +} /* end OS_FPUExcSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FPUExcGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FPUExcGetMask_Impl(uint32 *mask) +{ + int32 Status; + +#if defined(_PPC_) && CPU != PPC440 + *mask = vxFpscrGet(); + Status = OS_SUCCESS; +#else + Status = OS_ERR_NOT_IMPLEMENTED; +#endif + return Status; +} /* end OS_FPUExcGetMask_Impl */ + diff --git a/src/os/vxworks/src/os-impl-heap.c b/src/os/vxworks/src/os-impl-heap.c new file mode 100644 index 000000000..231c46025 --- /dev/null +++ b/src/os/vxworks/src/os-impl-heap.c @@ -0,0 +1,58 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-heap.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" + +#include + +/**************************************************************************************** + HEAP API +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_HeapGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_HeapGetInfo_Impl (OS_heap_prop_t *heap_prop) +{ + MEM_PART_STATS stats; + STATUS status; + + status = memPartInfoGet(memSysPartId, &stats); + + if (status != OK) + { + return OS_ERROR; + } + + heap_prop->free_bytes = stats.numBytesFree; + heap_prop->free_blocks = stats.numBlocksFree; + heap_prop->largest_free_block = stats.maxBlockSizeFree; + + return (OS_SUCCESS); +} /* end OS_HeapGetInfo_Impl */ + diff --git a/src/os/vxworks/src/os-impl-idmap.c b/src/os/vxworks/src/os-impl-idmap.c new file mode 100644 index 000000000..fffef4537 --- /dev/null +++ b/src/os/vxworks/src/os-impl-idmap.c @@ -0,0 +1,174 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-common.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "osapi-idmap-impl.h" + +#include +#include +#include +#include + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +VX_MUTEX_SEMAPHORE(OS_task_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_queue_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_bin_sem_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_mutex_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_count_sem_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_stream_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_dir_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_timebase_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_module_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_filesys_table_mut_mem); +VX_MUTEX_SEMAPHORE(OS_console_mut_mem); + +VxWorks_GlobalMutex_t VX_MUTEX_TABLE[] = +{ + [OS_OBJECT_TYPE_UNDEFINED] = { NULL }, + [OS_OBJECT_TYPE_OS_TASK] = { .mem = OS_task_table_mut_mem }, + [OS_OBJECT_TYPE_OS_QUEUE] = { .mem = OS_queue_table_mut_mem }, + [OS_OBJECT_TYPE_OS_COUNTSEM] = { .mem = OS_count_sem_table_mut_mem }, + [OS_OBJECT_TYPE_OS_BINSEM] = { .mem = OS_bin_sem_table_mut_mem }, + [OS_OBJECT_TYPE_OS_MUTEX] = { .mem = OS_mutex_table_mut_mem }, + [OS_OBJECT_TYPE_OS_STREAM] = { .mem = OS_stream_table_mut_mem }, + [OS_OBJECT_TYPE_OS_DIR] = { .mem = OS_dir_table_mut_mem }, + [OS_OBJECT_TYPE_OS_TIMEBASE] = { .mem = OS_timebase_table_mut_mem }, + [OS_OBJECT_TYPE_OS_MODULE] = { .mem = OS_module_table_mut_mem }, + [OS_OBJECT_TYPE_OS_FILESYS] = { .mem = OS_filesys_table_mut_mem }, + [OS_OBJECT_TYPE_OS_CONSOLE] = { .mem = OS_console_mut_mem }, +}; + +enum +{ + VX_MUTEX_TABLE_SIZE = (sizeof(VX_MUTEX_TABLE) / sizeof(VX_MUTEX_TABLE[0])) +}; + +/*---------------------------------------------------------------- + * + * Function: OS_Lock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Lock_Global_Impl(uint32 idtype) +{ + VxWorks_GlobalMutex_t *mut; + + if (idtype >= VX_MUTEX_TABLE_SIZE) + { + return OS_ERROR; + } + + mut = &VX_MUTEX_TABLE[idtype]; + if (mut->vxid == (SEM_ID)0) + { + return OS_ERROR; + } + + if (semTake(mut->vxid, WAIT_FOREVER) != OK) + { + OS_DEBUG("semTake() - vxWorks errno %d\n",errno); + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_Lock_Global_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_Unlock_Global_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_Unlock_Global_Impl(uint32 idtype) +{ + VxWorks_GlobalMutex_t *mut; + + if (idtype >= VX_MUTEX_TABLE_SIZE) + { + return OS_ERROR; + } + + mut = &VX_MUTEX_TABLE[idtype]; + if (mut->vxid == (SEM_ID)0) + { + return OS_ERROR; + } + + if (semGive(mut->vxid) != OK) + { + OS_DEBUG("semGive() - vxWorks errno %d\n",errno); + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_Unlock_Global_Impl */ + + + +/**************************************************************************************** + INITIALIZATION FUNCTION +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_TableMutex_Init + * + * Purpose: Initialize the tables that the OS API uses to keep track of information + * about objects + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_TableMutex_Init(uint32 idtype) +{ + int32 return_code = OS_SUCCESS; + SEM_ID semid; + + /* Initialize the table mutex for the given idtype */ + if (idtype < VX_MUTEX_TABLE_SIZE && VX_MUTEX_TABLE[idtype].mem != NULL) + { + semid = semMInitialize (VX_MUTEX_TABLE[idtype].mem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + + if ( semid == (SEM_ID)0 ) + { + OS_DEBUG("Error: semMInitialize() failed - vxWorks errno %d\n",errno); + return_code = OS_ERROR; + } + else + { + VX_MUTEX_TABLE[idtype].vxid = semid; + } + } + + return(return_code); +} /* end OS_VxWorks_TableMutex_Init */ + diff --git a/src/os/vxworks/src/os-impl-interrupts.c b/src/os/vxworks/src/os-impl-interrupts.c new file mode 100644 index 000000000..dbac6fe63 --- /dev/null +++ b/src/os/vxworks/src/os-impl-interrupts.c @@ -0,0 +1,167 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-interrupts.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include +#include + + +/**************************************************************************************** + INT API (deprecated) +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntAttachHandler_Impl (uint32 InterruptNumber, osal_task_entry InterruptHandler, int32 parameter) +{ + /* The Xenomai-VxWorks emulation layer does not support interrupt control */ + if(intConnect(INUM_TO_IVEC(InterruptNumber), + (VOIDFUNCPTR)InterruptHandler, parameter) != OK) + { + return OS_ERROR; + } + + return OS_SUCCESS; +} /* end OS_IntAttachHandler_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_IntUnlock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntUnlock_Impl (int32 IntLevel) +{ + intUnlock(IntLevel); + return(OS_SUCCESS); +} /* end OS_IntUnlock_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntLock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntLock_Impl (void) +{ + return (int32)intLock(); +} /* end OS_IntLock_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_IntEnable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntEnable_Impl (int32 Level) +{ + int32 RetCode; + int Status; + + Status = intEnable(Level); + + if(Status == OK) + { + RetCode = OS_SUCCESS; + } + else + { + RetCode = OS_ERROR; + } + + return RetCode; +} /* end OS_IntEnable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntDisable_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntDisable_Impl (int32 Level) +{ + int32 RetCode; + int Status; + + Status = intDisable(Level); + + if(Status == OK) + { + RetCode = OS_SUCCESS; + } + else + { + RetCode = OS_ERROR; + } + + return RetCode; +} /* end OS_IntDisable_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntSetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntSetMask_Impl ( uint32 MaskSetting ) +{ + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntSetMask_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntGetMask_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_IntGetMask_Impl ( uint32 * MaskSettingPtr ) +{ + *MaskSettingPtr = 0; + return(OS_ERR_NOT_IMPLEMENTED); +} /* end OS_IntGetMask_Impl */ + diff --git a/src/os/vxworks/src/os-impl-loader.c b/src/os/vxworks/src/os-impl-loader.c new file mode 100644 index 000000000..f347037d4 --- /dev/null +++ b/src/os/vxworks/src/os-impl-loader.c @@ -0,0 +1,184 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-loader.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-loader.h" + +#include +#include +#include +#include +#include +#include + + +OS_impl_module_internal_record_t OS_impl_module_table[OS_MAX_MODULES]; + +/**************************************************************************************** + INITIALIZATION FUNCTION + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_ModuleAPI_Impl_Init(void) +{ + memset(&OS_impl_module_table, 0, sizeof(OS_impl_module_table)); + return(OS_SUCCESS); +} /* end OS_VxWorks_ModuleAPI_Impl_Init */ + + + + +/**************************************************************************************** + Module Loader API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleLoad_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleLoad_Impl ( uint32 local_id, const char *translated_path ) +{ + int32 return_code; + int fd; + MODULE_ID vxModuleId; + + /* + ** File is ready to load + */ + + /* + ** Open the file + */ + fd = open (translated_path, O_RDONLY, 0); + if( fd < 0 ) + { + OS_DEBUG("OSAL: Error, cannot open application file: %s\n",translated_path); + return_code = OS_ERROR; + } + else + { + /* + ** Load the module + */ + vxModuleId = loadModule (fd, LOAD_ALL_SYMBOLS); + + if( vxModuleId == (MODULE_ID)0 ) + { + OS_DEBUG("OSAL: Error, cannot load module: %s\n",translated_path); + return_code = OS_ERROR; + } + else + { + OS_impl_module_table[local_id].moduleID = vxModuleId; + return_code = OS_SUCCESS; + } + + /* + ** Close the file + */ + close(fd); + } + + return(return_code); + +} /* end OS_ModuleLoad_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleUnload_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleUnload_Impl ( uint32 local_id ) +{ + STATUS vxStatus; + + /* + ** Attempt to close/unload the module + */ + vxStatus = unldByModuleId(OS_impl_module_table[local_id].moduleID, 0); + if ( vxStatus == ERROR ) + { + OS_DEBUG("OSAL: Error, Cannot Close/Unload application file: %d\n",vxStatus); + return(OS_ERROR); + } + + return(OS_SUCCESS); + +} /* end OS_ModuleUnload_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_ModuleGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ModuleGetInfo_Impl ( uint32 local_id, OS_module_prop_t *module_prop ) +{ + MODULE_INFO vxModuleInfo; + STATUS vxStatus; + + + module_prop->host_module_id = (cpuaddr)OS_impl_module_table[local_id].moduleID; + + /* + ** Get the module info from vxWorks + */ + vxStatus = moduleInfoGet(OS_impl_module_table[local_id].moduleID, &vxModuleInfo); + if ( vxStatus == ERROR ) + { + OS_DEBUG("OSAL: OS_ModuleInfoGet Error from vxWorks: %d\n",vxStatus); + } + else + { + module_prop->addr.valid = true; + module_prop->addr.code_address = (cpuaddr)vxModuleInfo.segInfo.textAddr; + module_prop->addr.code_size = vxModuleInfo.segInfo.textSize; + module_prop->addr.data_address = (cpuaddr)vxModuleInfo.segInfo.dataAddr; + module_prop->addr.data_size = vxModuleInfo.segInfo.dataSize; + module_prop->addr.bss_address = (cpuaddr)vxModuleInfo.segInfo.bssAddr; + module_prop->addr.bss_size = vxModuleInfo.segInfo.bssSize; + } + + return(OS_SUCCESS); + +} /* end OS_ModuleGetInfo_Impl */ + diff --git a/src/os/vxworks/src/os-impl-mutex.c b/src/os/vxworks/src/os-impl-mutex.c new file mode 100644 index 000000000..b24cd204d --- /dev/null +++ b/src/os/vxworks/src/os-impl-mutex.c @@ -0,0 +1,149 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-mutex.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" + +#include "os-impl-mutex.h" +#include "osapi-mutex-impl.h" + +#include + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +/* Console device */ +OS_impl_mutsem_internal_record_t OS_impl_mutex_table [OS_MAX_MUTEXES]; + +/**************************************************************************************** + MUTEX API +****************************************************************************************/ + + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_MutexAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_MutexAPI_Impl_Init(void) +{ + memset(OS_impl_mutex_table, 0, sizeof(OS_impl_mutex_table)); + return (OS_SUCCESS); +} /* end OS_VxWorks_MutexAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) +{ + SEM_ID tmp_sem_id; + + /* Initialize VxWorks Semaphore. + * The memory for this sem is statically allocated. */ + tmp_sem_id = semMInitialize(OS_impl_mutex_table[sem_id].mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + + if(tmp_sem_id == (SEM_ID)0) + { + OS_DEBUG("semMInitalize() - vxWorks errno %d\n",errno); + return OS_SEM_FAILURE; + } + + OS_impl_mutex_table[sem_id].vxid = tmp_sem_id; + return OS_SUCCESS; +} /* end OS_MutSemCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemDelete_Impl (uint32 sem_id) +{ + /* + * As the memory for the sem is statically allocated, delete is a no-op. + */ + OS_impl_mutex_table[sem_id].vxid = 0; + return OS_SUCCESS; + +} /* end OS_MutSemDelete_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGive_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGive_Impl (uint32 sem_id) +{ + /* Give VxWorks Semaphore */ + return OS_VxWorks_GenericSemGive(OS_impl_mutex_table[sem_id].vxid); +} /* end OS_MutSemGive_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemTake_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemTake_Impl (uint32 sem_id) +{ + /* Take VxWorks Semaphore */ + return OS_VxWorks_GenericSemTake(OS_impl_mutex_table[sem_id].vxid, WAIT_FOREVER); +} /* end OS_MutSemTake_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_MutSemGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) +{ + /* VxWorks provides no additional info */ + return OS_SUCCESS; + +} /* end OS_MutSemGetInfo_Impl */ + diff --git a/src/os/vxworks/src/os-impl-network.c b/src/os/vxworks/src/os-impl-network.c new file mode 100644 index 000000000..8df230ddf --- /dev/null +++ b/src/os/vxworks/src/os-impl-network.c @@ -0,0 +1,90 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-network.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-network.h" + +#define OS_HOST_NAME_LEN 48 + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetHostName_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) +{ + int32 return_code; + + if ( gethostname(host_name, name_len) < 0 ) + { + return_code = OS_ERROR; + } + else + { + host_name[name_len - 1] = 0; + return_code = OS_SUCCESS; + } + + return(return_code); +} /* end OS_NetworkGetHostName_Impl */ + + + + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetID_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_NetworkGetID_Impl (int32 *IdBuf) +{ + int host_id; + int32 status; + char host_name [OS_HOST_NAME_LEN]; + + status = OS_NetworkGetHostName_Impl(host_name, sizeof(host_name)); + if (status == OS_SUCCESS) + { + host_id = hostGetByName(host_name); + if (host_id == ERROR) + { + status = OS_ERROR; + } + else + { + *IdBuf = (int32)host_id; + status = OS_SUCCESS; + } + } + + return status; + +} /* end OS_NetworkGetID_Impl */ + diff --git a/src/os/vxworks/src/os-impl-queues.c b/src/os/vxworks/src/os-impl-queues.c new file mode 100644 index 000000000..0f5d11ad3 --- /dev/null +++ b/src/os/vxworks/src/os-impl-queues.c @@ -0,0 +1,211 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-queues.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-queues.h" +#include "osapi-queue-impl.h" + + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ +OS_impl_queue_internal_record_t OS_impl_queue_table [OS_MAX_QUEUES]; + +/**************************************************************************************** + MESSAGE QUEUE API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_QueueAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_QueueAPI_Impl_Init(void) +{ + memset(OS_impl_queue_table, 0, sizeof(OS_impl_queue_table)); + return (OS_SUCCESS); +} /* end OS_VxWorks_QueueAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) +{ + MSG_Q_ID tmp_msgq_id; + int queue_depth = OS_queue_table[queue_id].max_depth; /* maximum number of messages in queue (queue depth) */ + int data_size = OS_queue_table[queue_id].max_size; /* maximum size in bytes of a message */ + + /* Create VxWorks Message Queue */ + tmp_msgq_id = msgQCreate(queue_depth, data_size, MSG_Q_FIFO); + + /* check if message Q create failed */ + if(tmp_msgq_id == 0) + { + OS_DEBUG("msgQCreate() - vxWorks errno %d\n",errno); + return OS_ERROR; + } + + OS_impl_queue_table[queue_id].vxid = tmp_msgq_id; + return OS_SUCCESS; + +} /* end OS_QueueCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueDelete_Impl (uint32 queue_id) +{ + /* Try to delete the queue */ + if (msgQDelete(OS_impl_queue_table[queue_id].vxid) != OK) + { + OS_DEBUG("msgQDelete() - vxWorks errno %d\n",errno); + return OS_ERROR; + } + + OS_impl_queue_table[queue_id].vxid = 0; + return OS_SUCCESS; + +} /* end OS_QueueDelete_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueGet_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, + int32 timeout) +{ + int32 return_code; + STATUS status; + int ticks; + + /* Get Message From Message Queue */ + if (timeout == OS_PEND) + { + ticks = WAIT_FOREVER; + } + else if (timeout == OS_CHECK) + { + ticks = NO_WAIT; + } + else + { + /* msecs rounded to the closest system tick count */ + ticks = OS_Milli2Ticks(timeout); + } + + status = msgQReceive(OS_impl_queue_table[queue_id].vxid, data, size, ticks); + + if(status == ERROR) + { + *size_copied = 0; + if (errno == S_objLib_OBJ_TIMEOUT) + { + return_code = OS_QUEUE_TIMEOUT; + } + else if (errno == S_objLib_OBJ_UNAVAILABLE) + { + return_code = OS_QUEUE_EMPTY; + } + else + { + OS_DEBUG("msgQReceive() - vxWorks errno %d\n",errno); + return_code = OS_ERROR; + } + } + else + { + *size_copied = status; + return_code = OS_SUCCESS; + } + + return return_code; +} /* end OS_QueueGet_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueuePut_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) +{ + int32 return_code; + + if(msgQSend(OS_impl_queue_table[queue_id].vxid, (void*)data, size, NO_WAIT, MSG_PRI_NORMAL) == OK) + { + return_code = OS_SUCCESS; + } + else if(errno == S_objLib_OBJ_UNAVAILABLE) + { + return_code = OS_QUEUE_FULL; + } + else + { + OS_DEBUG("msgQSend() - vxWorks errno %d\n",errno); + return_code = OS_ERROR; + } + + return return_code; + +} /* end OS_QueuePut_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueueGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) +{ + /* No extra info for queues in the OS implementation */ + return OS_SUCCESS; + +} /* end OS_QueueGetInfo_Impl */ + diff --git a/src/os/vxworks/src/os-impl-shell.c b/src/os/vxworks/src/os-impl-shell.c new file mode 100644 index 000000000..74f80b878 --- /dev/null +++ b/src/os/vxworks/src/os-impl-shell.c @@ -0,0 +1,95 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-shell.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-io.h" + +#include +#include +#include + +#define OS_REDIRECTSTRSIZE 15 +#define OS_SHELL_TMP_FILE_EXT ".out" +#define OS_SHELL_TMP_FILE_EXT_LEN 4 +#define OS_SHELL_CMD_TASK_STACK_SIZE 16384 +#define OS_SHELL_CMD_TASK_PRIORITY 250 + + + +/*---------------------------------------------------------------- + * + * Function: OS_ShellOutputToFile_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +{ + int32 ReturnCode = OS_FS_ERROR; + int32 Result = ERROR; + int32 fdCmd; + uint32 cmdidx; + char * shellName; + + /* Create a file to write the command to (or write over the old one) */ + fdCmd = OS_creat(OS_SHELL_CMD_INPUT_FILE_NAME,OS_READ_WRITE); + + if (fdCmd < OS_FS_SUCCESS) + { + return OS_FS_ERROR; + } + + if (OS_ConvertToArrayIndex(fdCmd, &cmdidx) == OS_SUCCESS) + { + /* copy the command to the file, and then seek back to the beginning of the file */ + OS_write(fdCmd, Cmd, strlen(Cmd)); + OS_lseek(fdCmd,0,OS_SEEK_SET); + + /* Create a shell task the will run the command in the file, push output to OS_fd */ + Result = shellGenericInit("INTERPRETER=Cmd", 0, NULL, &shellName, false, false, + OS_impl_filehandle_table[cmdidx].fd, + OS_impl_filehandle_table[file_id].fd, + OS_impl_filehandle_table[file_id].fd); + } + + if (Result == OK) + { + /* Wait for the command to terminate */ + do + { + taskDelay(sysClkRateGet()); + } + while (taskNameToId(shellName) != ((TASK_ID)ERROR)); + + ReturnCode = OS_SUCCESS; + } + + /* Close the file descriptor */ + OS_close(fdCmd); + + return ReturnCode; + +} /* end OS_ShellOutputToFile_Impl */ + diff --git a/src/os/vxworks/src/os-impl-symtab.c b/src/os/vxworks/src/os-impl-symtab.c new file mode 100644 index 000000000..823a1243b --- /dev/null +++ b/src/os/vxworks/src/os-impl-symtab.c @@ -0,0 +1,230 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-symtab.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-symtab.h" + +#include +#include /* memset() */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +typedef struct +{ + char SymbolName[OS_MAX_SYM_LEN]; + cpuaddr SymbolAddress; +} SymbolRecord_t; + +/* A global for storing the state in a SymbolDump call */ +SymbolDumpState_t OS_VxWorks_SymbolDumpState; + +/* the system symbol table */ +extern SYMTAB_ID sysSymTbl; + +/**************************************************************************************** + SYMBOL TABLE API + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolLookup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) +{ + STATUS vxStatus; + SYMBOL_DESC SymDesc; + + /* + ** Check parameters + */ + if (( SymbolAddress == NULL ) || (SymbolName == NULL )) + { + return(OS_INVALID_POINTER); + } + + /* + ** Lookup the entry point + ** + ** VxWorks 6.9 has deprecated the "symFindByName" API and it is replaced + ** with a "symFind" API instead. + */ + + memset (&SymDesc, 0, sizeof (SYMBOL_DESC)); + SymDesc.mask = SYM_FIND_BY_NAME; + SymDesc.name = (char*)SymbolName; + + vxStatus = symFind(sysSymTbl,&SymDesc); + *SymbolAddress = (cpuaddr)SymDesc.value; + + if (vxStatus == ERROR) + { + return(OS_ERROR); + } + + + return(OS_SUCCESS); + +} /* end OS_SymbolLookup_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_SymTableIterator_Impl + * + * Purpose: Local helper routine, not part of OSAL API. + * Function called by vxWorks to iterate the vxworks symbol table + * + * Parameters: + * name - The symbol name + * val - The symbol address value + * type - The vxWorks symbol type ( not used ) + * max_size - The maximum size of the file that is written to. + * group - The vxWorks symbol group ( not used ) + * + * Returns: true to tell vxWorks to continue to iterate the symbol table + * false to tell vxWorks to stop iterating the symbol table + * + * The address of the symbol will be stored in the pointer that is passed in. + * + *-----------------------------------------------------------------*/ +BOOL OS_SymTableIterator_Impl ( char *name, SYM_VALUE val, SYM_TYPE type, _Vx_usr_arg_t arg, SYM_GROUP group ) +{ + SymbolRecord_t symRecord; + uint32 NextSize; + int status; + SymbolDumpState_t *state; + + /* + * Rather than passing the state pointer through the generic "int" arg, + * use a global. This is OK because dumps are serialized externally. + */ + state = &OS_VxWorks_SymbolDumpState; + + if (strlen(name) >= OS_MAX_SYM_LEN) + { + OS_DEBUG("%s(): symbol name too long\n", __func__); + state->StatusCode = OS_ERROR; + return(false); + } + + /* + ** Check to see if the maximum size of the file has been reached + */ + NextSize = state->CurrSize + sizeof(symRecord); + if ( NextSize > state->Sizelimit ) + { + /* + ** We exceeded the maximum size, so tell vxWorks to stop + ** However this is not considered an error, just a stop condition. + */ + OS_DEBUG("%s(): symbol table size exceeded\n", __func__); + return(false); + } + + /* + ** Copy symbol name + */ + strncpy(symRecord.SymbolName, name, OS_MAX_SYM_LEN); + + /* + ** Save symbol address + */ + symRecord.SymbolAddress = (cpuaddr)val; + + /* + ** Write entry in file + */ + status = write(state->fd, (char *)&symRecord, sizeof(symRecord)); + /* There is a problem if not all bytes were written OR if we get an error + * value, < 0. */ + if ( status < (int)sizeof(symRecord) ) + { + state->StatusCode = OS_ERROR; + return(false); + } + + state->CurrSize = NextSize; + + /* + ** It's OK to continue + */ + return(true); +} /* end OS_SymTableIterator_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolTableDump_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_SymbolTableDump_Impl ( const char *local_filename, uint32 SizeLimit ) +{ + SymbolDumpState_t *state; + + /* + * Rather than passing the state pointer through the generic "int" arg, + * use a global. This is OK because dumps are serialized externally. + */ + state = &OS_VxWorks_SymbolDumpState; + + memset(state, 0, sizeof(*state)); + state->Sizelimit = SizeLimit; + + /* + ** Open file + */ + state->fd = open(local_filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); + if ( state->fd < 0 ) + { + OS_DEBUG("open(%s): error: %s\n", local_filename, strerror(errno)); + state->StatusCode = OS_ERROR; + } + else + { + /* + ** Iterate the symbol table + */ + (void) symEach( sysSymTbl, OS_SymTableIterator_Impl, 0 ); + + close(state->fd); + } + + return(state->StatusCode); + +} /* end OS_SymbolTableDump_Impl */ + diff --git a/src/os/vxworks/src/os-impl-tasks.c b/src/os/vxworks/src/os-impl-tasks.c new file mode 100644 index 000000000..b6867531c --- /dev/null +++ b/src/os/vxworks/src/os-impl-tasks.c @@ -0,0 +1,441 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-tasks.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-tasks.h" + +#include "osapi-task-impl.h" +#include "osapi-idmap-impl.h" + +#include +#include +#include + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/* + * macros for stack size manipulation. + * These are normally provided by vxWorks.h if relevant for the platform. + * If they are not defined, use a reasonable default/substitute. + */ +#if defined(_STACK_ALIGN_SIZE) +#define VX_IMPL_STACK_ALIGN_SIZE _STACK_ALIGN_SIZE +#else +#define VX_IMPL_STACK_ALIGN_SIZE 16 +#endif + +#if defined(STACK_ROUND_DOWN) +#define VX_IMPL_STACK_ROUND_DOWN(x) STACK_ROUND_DOWN(x) +#else +#define VX_IMPL_STACK_ROUND_DOWN(x) ((x) & ~(VX_IMPL_STACK_ALIGN_SIZE-1)) +#endif + +#if defined(STACK_ROUND_UP) +#define VX_IMPL_STACK_ROUND_UP(x) STACK_ROUND_UP(x) +#else +#define VX_IMPL_STACK_ROUND_UP(x) (((x) + (VX_IMPL_STACK_ALIGN_SIZE-1)) & ~(VX_IMPL_STACK_ALIGN_SIZE-1)) +#endif + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +/* Tables where the OS object information is stored */ +OS_impl_task_internal_record_t OS_impl_task_table [OS_MAX_TASKS]; + +/*--------------------------------------------------------------------------------------- + Name: OS_VxWorksEntry + + Purpose: A Simple VxWorks-compatible entry point that calls the common task entry function + + NOTES: This wrapper function is only used locally by OS_TaskCreate below + +---------------------------------------------------------------------------------------*/ +int OS_VxWorks_TaskEntry(int arg) +{ + OS_TaskEntryPoint((uint32)arg); + return 0; +} /* end OS_VxWorksEntry */ + + + +/**************************************************************************************** + TASK API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_TaskAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_TaskAPI_Impl_Init(void) +{ + memset(OS_impl_task_table, 0, sizeof(OS_impl_task_table)); + return (OS_SUCCESS); +} /* end OS_VxWorks_TaskAPI_Impl_Init */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) +{ + STATUS status; + int vxflags; + int vxpri; + long actualsz; + long userstackbase; + long actualstackbase; + OS_impl_task_internal_record_t *lrec; + + lrec = &OS_impl_task_table[task_id]; + + /* Create VxWorks Task */ + + /* see if the user wants floating point enabled. If + * so, then se the correct option. + */ + vxflags = 0; + if (flags & OS_FP_ENABLED) + { + vxflags |= VX_FP_TASK; + } + + + /* + * Get priority/stack specs from main struct + * priority should be a direct passthru + */ + vxpri = OS_task_table[task_id].priority; + actualsz = OS_task_table[task_id].stack_size; + userstackbase = (long)OS_task_table[task_id].stack_pointer; + + /* + * NOTE: Using taskInit() here rather than taskSpawn() allows us + * to specify a specific statically-allocated WIND_TCB instance. + * + * This is very important as it allows for efficient reverse-lookup; + * a call to taskTcb() will get the WIND_TCB pointer back, which + * in turn provides an index into OSAL local data structures. With + * this we can have the equivalent of a taskVar that works on both + * UMP and SMP deployments. + * + * The difficulty with taskInit() is that we must also manually + * allocate the stack as well (there is no API that allows + * a specific WIND_TCB but automatically allocates the stack). + * Furthermore, VxWorks uses this pointer directly as the CPU + * stack pointer register, so we need to manually adjust it for + * downward-growing stacks. + * + * NOTE: Allocation of the stack requires a malloc() of some form. + * This is what taskSpawn() effectively does internally to create + * stack. If the system malloc() is unacceptable here then this + * could be replaced with a statically-allocated OSAL stack buffer. + * + * ALSO NOTE: The stack-rounding macros are normally supplied from + * vxWorks.h on relevant platforms. If not provided then it is + * assumed that no specific alignment is needed on this platform. + */ + + if (userstackbase == 0) + { + /* add a little extra in case the base address needs alignment too. + * this helps ensure that the final aligned stack is not less + * than what was originally requested (but might be a bit more) */ + actualsz += VX_IMPL_STACK_ALIGN_SIZE; + actualsz = VX_IMPL_STACK_ROUND_UP(actualsz); + + /* + * VxWorks does not provide a way to deallocate + * a taskInit-provided stack when a task exits. + * + * So in this case we will find the leftover heap + * buffer when OSAL reuses this local record block. + * + * If that leftover heap buffer is big enough it + * can be used directly. Otherwise it needs to be + * re-created. + */ + if (lrec->heap_block_size < actualsz) + { + if (lrec->heap_block != NULL) + { + /* release the old block */ + free(lrec->heap_block); + lrec->heap_block_size = 0; + } + + /* allocate a new heap block to use for a stack */ + lrec->heap_block = malloc(actualsz); + + if (lrec->heap_block != NULL) + { + lrec->heap_block_size = actualsz; + } + + } + + userstackbase = (long)lrec->heap_block; + } + + if (userstackbase == 0) + { + /* no stack - cannot create task */ + return OS_ERROR; + } + + actualstackbase = userstackbase; + + /* also round the base address */ + actualstackbase = VX_IMPL_STACK_ROUND_UP(actualstackbase); + actualsz -= (actualstackbase - userstackbase); + actualsz = VX_IMPL_STACK_ROUND_DOWN(actualsz); + + /* + * On most CPUs the stack grows downward, so assume that to be + * the case in the event that _STACK_DIR is not defined/known + */ +#if !defined(_STACK_DIR) || (_STACK_DIR != _STACK_GROWS_UP) + actualstackbase += actualsz; /* move to last byte of stack block */ +#endif + + status = taskInit( + &lrec->tcb, /* address of new task's TCB */ + (char*)OS_global_task_table[task_id].name_entry, + vxpri, /* priority of new task */ + vxflags, /* task option word */ + (char *)actualstackbase, /* base of new task's stack */ + actualsz, /* size (bytes) of stack needed */ + (FUNCPTR)OS_VxWorks_TaskEntry, /* entry point of new task */ + OS_global_task_table[task_id].active_id, /* 1st arg is ID */ + 0,0,0,0,0,0,0,0,0); + + if (status != OK) + { + return OS_ERROR; + } + + lrec->vxid = (TASK_ID)&lrec->tcb; + + taskActivate(lrec->vxid); + + return OS_SUCCESS; + +} /* end OS_TaskCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelete_Impl (uint32 task_id) +{ + /* + ** Try to delete the task + ** If this fails, not much recourse - the only potential cause of failure + ** to cancel here is that the thread ID is invalid because it already exited itself, + ** and if that is true there is nothing wrong - everything is OK to continue normally. + */ + if (taskDelete(OS_impl_task_table[task_id].vxid) != OK) + { + OS_DEBUG("taskDelete() - vxWorks errno %d\n",errno); + return OS_ERROR; + } + + OS_impl_task_table[task_id].vxid = 0; + return OS_SUCCESS; + +} /* end OS_TaskDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskExit_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_TaskExit_Impl() +{ + taskExit(0); +} /* end OS_TaskExit_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskDelay_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskDelay_Impl (uint32 milli_second) +{ + /* msecs rounded to the closest system tick count */ + int sys_ticks; + + sys_ticks = OS_Milli2Ticks(milli_second); + + /* if successful, the execution of task will pend here until delay finishes */ + if(taskDelay(sys_ticks) != OK) + { + return OS_ERROR; + } + return OS_SUCCESS; + +} /* end OS_TaskDelay_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskSetPriority_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) +{ + /* Set VxWorks Task Priority */ + if(taskPrioritySet(OS_impl_task_table[task_id].vxid, new_priority) != OK) + { + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_TaskSetPriority_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskMatch_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskMatch_Impl(uint32 task_id) +{ + /* + ** Get VxWorks Task Id + */ + if ( taskIdSelf() != OS_impl_task_table[task_id].vxid ) + { + return(OS_ERROR); + } + + + return OS_SUCCESS; +} /* end OS_TaskMatch_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskRegister_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskRegister_Impl (uint32 global_task_id) +{ + return OS_SUCCESS; +} /* end OS_TaskRegister_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetId_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +uint32 OS_TaskGetId_Impl (void) +{ + OS_impl_task_internal_record_t *lrec; + size_t index; + uint32 id; + + id = 0; + lrec = (OS_impl_task_internal_record_t *)taskTcb(taskIdSelf()); + + if (lrec != NULL) + { + index = lrec - &OS_impl_task_table[0]; + if (index < OS_MAX_TASKS) + { + id = OS_global_task_table[index].active_id; + } + } + + return id; + +} /* end OS_TaskGetId_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TaskGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) +{ + union + { + TASK_ID vxid; + uint32 value; + } u; + + /* + * The "OStask_id" is a broken concept and only included for backward compatibility. + * On 32 bit platforms this should produce a backward-compatible result. + * But on 64 bit platforms this value should never be used..... + * using a union defeats a (valid) warning on 64-bit. + */ + u.vxid = OS_impl_task_table[task_id].vxid; + task_prop->OStask_id = u.value; + + return OS_SUCCESS; + +} /* end OS_TaskGetInfo_Impl */ + diff --git a/src/os/vxworks/ostimer.c b/src/os/vxworks/src/os-impl-timebase.c similarity index 90% rename from src/os/vxworks/ostimer.c rename to src/os/vxworks/src/os-impl-timebase.c index 43d1d574a..ac84f176a 100644 --- a/src/os/vxworks/ostimer.c +++ b/src/os/vxworks/src/os-impl-timebase.c @@ -1,24 +1,33 @@ /* -** File : ostimer.c -** -** Copyright (c) 2004-2015, United States government as represented by the -** administrator of the National Aeronautics Space Administration. -** All rights reserved. This software was created at NASA Glenn -** Research Center pursuant to government contracts. -** -** This is governed by the NASA Open Source Agreement and may be used, -** distributed and modified only pursuant to the terms of that agreement. -** -** Author : Joe Hickey based on original RTEMS implementation by Alan Cudmore -** -** Purpose: This file contains the OSAL Timer API for RTEMS -*/ + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file os-impl-timebase.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ /**************************************************************************************** INCLUDE FILES ****************************************************************************************/ #include "os-vxworks.h" +#include "os-impl-timebase.h" + +#include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-timebase-impl.h" #include #include @@ -60,27 +69,6 @@ LOCAL TYPEDEFS ****************************************************************************************/ -enum OS_TimerState -{ - OS_TimerRegState_INIT = 0, - OS_TimerRegState_SUCCESS, - OS_TimerRegState_ERROR -}; - -typedef struct -{ - VX_MUTEX_SEMAPHORE(mmem); - SEM_ID handler_mutex; - int assigned_signal; - sigset_t timer_sigset; - TASK_ID handler_task; - timer_t host_timerid; - enum OS_TimerState timer_state; - uint32 configured_start_time; - uint32 configured_interval_time; - bool reset_flag; -} OS_impl_timebase_internal_record_t; - /**************************************************************************************** GLOBAL DATA ****************************************************************************************/ @@ -93,7 +81,7 @@ static uint32 OS_ClockAccuracyNsec; INTERNAL FUNCTIONS ****************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseLock_Impl @@ -106,7 +94,7 @@ void OS_TimeBaseLock_Impl(uint32 local_id) { semTake(OS_impl_timebase_table[local_id].handler_mutex, WAIT_FOREVER); } /* end OS_TimeBaseLock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseUnlock_Impl @@ -120,7 +108,7 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) semGive(OS_impl_timebase_table[local_id].handler_mutex); } /* end OS_TimeBaseUnlock_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_Impl_UsecToTimespec @@ -128,7 +116,7 @@ void OS_TimeBaseUnlock_Impl(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static void OS_Impl_UsecToTimespec(uint32 usecs, struct timespec *time_spec) +void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec) { if ( usecs < 1000000 ) { @@ -142,7 +130,7 @@ static void OS_Impl_UsecToTimespec(uint32 usecs, struct timespec *time_spec) } } /* end OS_Impl_UsecToTimespec */ - + /*---------------------------------------------------------------- * * Function: OS_VxWorks_SigWait @@ -151,7 +139,7 @@ static void OS_Impl_UsecToTimespec(uint32 usecs, struct timespec *time_spec) * Blocks the calling task until the timer tick arrives * *-----------------------------------------------------------------*/ -static uint32 OS_VxWorks_SigWait(uint32 local_id) +uint32 OS_VxWorks_SigWait(uint32 local_id) { OS_impl_timebase_internal_record_t *local; OS_common_record_t *global; @@ -209,7 +197,7 @@ static uint32 OS_VxWorks_SigWait(uint32 local_id) return tick_time; } /* end OS_VxWorks_SigWait */ - + /*---------------------------------------------------------------- * * Function: OS_VxWorks_RegisterTimer @@ -217,7 +205,7 @@ static uint32 OS_VxWorks_SigWait(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static void OS_VxWorks_RegisterTimer(uint32 local_id) +void OS_VxWorks_RegisterTimer(uint32 local_id) { OS_impl_timebase_internal_record_t *local; struct sigevent evp; @@ -257,7 +245,7 @@ static void OS_VxWorks_RegisterTimer(uint32 local_id) /**************************************************************************************** Entry point for helper thread ****************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_VxWorks_TimeBaseTask @@ -265,7 +253,7 @@ static void OS_VxWorks_RegisterTimer(uint32 local_id) * Purpose: Local helper routine, not part of OSAL API. * *-----------------------------------------------------------------*/ -static int OS_VxWorks_TimeBaseTask(int arg) +int OS_VxWorks_TimeBaseTask(int arg) { uint32 local_id; @@ -284,7 +272,7 @@ static int OS_VxWorks_TimeBaseTask(int arg) /**************************************************************************************** INITIALIZATION FUNCTION ****************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_VxWorks_TimeBaseAPI_Impl_Init @@ -333,7 +321,7 @@ int32 OS_VxWorks_TimeBaseAPI_Impl_Init ( void ) Time Base API ****************************************************************************************/ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseCreate_Impl @@ -516,7 +504,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) return return_code; } /* end OS_TimeBaseCreate_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseSet_Impl @@ -542,8 +530,8 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } else { - OS_Impl_UsecToTimespec(start_time, &timeout.it_value); - OS_Impl_UsecToTimespec(interval_time, &timeout.it_interval); + OS_VxWorks_UsecToTimespec(start_time, &timeout.it_value); + OS_VxWorks_UsecToTimespec(interval_time, &timeout.it_interval); /* ** Program the real timer @@ -615,7 +603,7 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time } /* end OS_TimeBaseSet_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseDelete_Impl @@ -650,7 +638,7 @@ int32 OS_TimeBaseDelete_Impl(uint32 timer_id) return return_code; } /* end OS_TimeBaseDelete_Impl */ - + /*---------------------------------------------------------------- * * Function: OS_TimeBaseGetInfo_Impl @@ -665,10 +653,3 @@ int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) } /* end OS_TimeBaseGetInfo_Impl */ -/**************************************************************************************** - Other Time-Related API Implementation -****************************************************************************************/ - -/* VxWorks implements POSIX-style clock_gettime and clock_settime calls */ -#include "../portable/os-impl-posix-gettime.c" - diff --git a/src/tests/mutex-test/mutex-test.c b/src/tests/mutex-test/mutex-test.c index fbe772a93..eb27ca4b4 100644 --- a/src/tests/mutex-test/mutex-test.c +++ b/src/tests/mutex-test/mutex-test.c @@ -29,7 +29,7 @@ uint32 task_3_stack[TASK_STACK_SIZE]; uint32 task_3_id; uint32 task_3_failures; -uint32 mut_sem_id; +uint32 mutex_id; uint32 shared_obj_owner; int counter = 0; @@ -44,7 +44,7 @@ void task_1(void) while (1) { status = OS_TaskDelay(100); - status = OS_MutSemTake(mut_sem_id); + status = OS_MutSemTake(mutex_id); if ( status != OS_SUCCESS ) { ++task_1_failures; @@ -73,7 +73,7 @@ void task_1(void) } shared_obj_owner = 0; - status = OS_MutSemGive(mut_sem_id); + status = OS_MutSemGive(mutex_id); if ( status != OS_SUCCESS ) { ++task_1_failures; @@ -97,7 +97,7 @@ void task_2(void) { status = OS_TaskDelay(200); - status = OS_MutSemTake(mut_sem_id); + status = OS_MutSemTake(mutex_id); if ( status != OS_SUCCESS ) { ++task_2_failures; @@ -127,7 +127,7 @@ void task_2(void) } shared_obj_owner = 0; - status = OS_MutSemGive(mut_sem_id); + status = OS_MutSemGive(mutex_id); if ( status != OS_SUCCESS ) { ++task_2_failures; @@ -151,7 +151,7 @@ void task_3(void) { status = OS_TaskDelay(300); - status = OS_MutSemTake(mut_sem_id); + status = OS_MutSemTake(mutex_id); if ( status != OS_SUCCESS ) { ++task_3_failures; @@ -180,7 +180,7 @@ void task_3(void) } shared_obj_owner = 0; - status = OS_MutSemGive(mut_sem_id); + status = OS_MutSemGive(mutex_id); if ( status != OS_SUCCESS ) { ++task_3_failures; @@ -218,22 +218,22 @@ void MutexSetup(void) /* ** Create the mutex */ - status = OS_MutSemCreate( &mut_sem_id, "MutSem1", 0); - UtAssert_True(status == OS_SUCCESS, "MutSem1 create Id=%u Rc=%d", (unsigned int)mut_sem_id, (int)status); + status = OS_MutSemCreate( &mutex_id, "MutSem1", 0); + UtAssert_True(status == OS_SUCCESS, "MutSem1 create Id=%u Rc=%d", (unsigned int)mutex_id, (int)status); /* ** Test the mutex to see if it supports nesting */ - status = OS_MutSemTake(mut_sem_id); + status = OS_MutSemTake(mutex_id); UtAssert_True(status == OS_SUCCESS, "OS_MutSemTake 1 Rc=%d", (int)status); - status = OS_MutSemTake(mut_sem_id); + status = OS_MutSemTake(mutex_id); UtAssert_True(status == OS_SUCCESS, "OS_MutSemTake 2 Rc=%d", (int)status); - status = OS_MutSemGive(mut_sem_id); + status = OS_MutSemGive(mutex_id); UtAssert_True(status == OS_SUCCESS, "OS_MutSemGive 2 Rc=%d", (int)status); - status = OS_MutSemGive(mut_sem_id); + status = OS_MutSemGive(mutex_id); UtAssert_True(status == OS_SUCCESS, "OS_MutSemGive 1 Rc=%d", (int)status); /* diff --git a/src/tests/osal-core-test/osal-core-test.c b/src/tests/osal-core-test/osal-core-test.c index a1d7f5458..5624aac41 100644 --- a/src/tests/osal-core-test/osal-core-test.c +++ b/src/tests/osal-core-test/osal-core-test.c @@ -531,7 +531,7 @@ void TestGetInfos(void) OS_task_prop_t task_prop; OS_queue_prop_t queue_prop; OS_bin_sem_prop_t bin_prop; - OS_mut_sem_prop_t mut_prop; + OS_mutex_prop_t mut_prop; /* first step is to create an object to to get the properties of */ diff --git a/src/unit-test-coverage/CMakeLists.txt b/src/unit-test-coverage/CMakeLists.txt index 329d050bf..4ada0be34 100644 --- a/src/unit-test-coverage/CMakeLists.txt +++ b/src/unit-test-coverage/CMakeLists.txt @@ -44,63 +44,56 @@ message(STATUS "Coverage Test Target OS: ${OSALCOVERAGE_TARGET_OSTYPE}") # Utilize the shared UT assert library, along with the standard OSAL includes include_directories(${UT_ASSERT_SOURCE_DIR}/inc) include_directories(${OSAL_SOURCE_DIR}/src/os/inc) -include_directories(${OSAL_SOURCE_DIR}/src/os/shared) +include_directories(${OSAL_SOURCE_DIR}/src/os/shared/inc) +include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) -# The OSALCOVERAGE_STUB_LIB_LIST is a list of stub libraries to link the -# test runner executables with. It will be appended at various points -# depending on what is under test. -set(OSALCOVERAGE_STUB_LIB_LIST) add_subdirectory(ut-stubs) -# The "ut_osapi_stubs" library is the stubs for the OSAL public API -# this should be supplied by the parent build -list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_osapi_stubs) - # A generic function to add a coverage test case source file # This combines the following into an executable # - The test case setup (a C source file starting with "coveragetest" prefix) # - The object code of the unit under test (special build with instrumentation) # - Links to the stub libraries of everything else, plus UT assert -function (add_coverage_tests SETNAME) - foreach(MODNAME ${ARGN}) - set (TESTCASE_SRCFILE) - foreach (SRCFILE - "${PROJECT_SOURCE_DIR}/portable/coveragetest-${MODNAME}.c" - "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" - ) - if (EXISTS "${SRCFILE}") - set (TESTCASE_SRCFILE "${SRCFILE}") - endif (EXISTS "${SRCFILE}") - endforeach() - - if (TESTCASE_SRCFILE) - set(TESTNAME "coverage-${SETNAME}-${MODNAME}") - - if (DEFINED MODULE_LINK_MAP_${MODNAME}) - set(LINKMOD ${MODULE_LINK_MAP_${MODNAME}}) - else() - set(LINKMOD ${MODNAME}) - endif() - +function (add_coverage_testrunner TESTNAME FSW_SRCFILE TESTCASE_SRCFILE) + MESSAGE("TRY=${TESTCASE_SRCFILE}") + #if (EXISTS ${TESTCASE_SRCFILE} AND EXISTS ${FSW_SRCFILE}) + + add_library(utobj_${TESTNAME} OBJECT + ${FSW_SRCFILE} + ) + + # only the actual FSW src file gets the coverage instrumentation + target_compile_options(utobj_${TESTNAME} PRIVATE + ${UT_COVERAGE_COMPILE_FLAGS} + ) + + # both the FSW src file and the adaptor file get compiled with override includes + target_include_directories(utobj_${TESTNAME} PRIVATE + ${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc + ) + + # the testcase is compiled with no special flags or override includes add_executable(${TESTNAME}-testrunner ${TESTCASE_SRCFILE} - $) + $ + ) target_link_libraries(${TESTNAME}-testrunner ${UT_COVERAGE_LINK_FLAGS} - ${OSALCOVERAGE_STUB_LIB_LIST} + ${ARGN} ut_assert ) + add_test(${TESTNAME} ${TESTNAME}-testrunner) + MESSAGE("ADDTEST=${TESTNAME} ${TESTNAME}-testrunner") foreach(TGT ${INSTALL_TARGET_LIST}) install(TARGETS ${TESTNAME}-testrunner DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) endforeach() - endif() - endforeach(MODNAME ${ARGN}) + #endif() -endfunction(add_coverage_tests SETNAME) +endfunction() foreach(SETNAME ${OSALCOVERAGE_TARGET_OSTYPE}) diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-select.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-select.h new file mode 100644 index 000000000..2bad81cda --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-select.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-bsd-select.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_BSD_SELECT_H_ +#define _UT_ADAPTOR_BSD_SELECT_H_ + + +#endif /* _UT_ADAPTOR_BSD_SELECT_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-sockets.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-sockets.h new file mode 100644 index 000000000..7ef57454b --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-bsd-sockets.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-bsd-sockets.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_BSD_SOCKETS_H_ +#define _UT_ADAPTOR_BSD_SOCKETS_H_ + + +#endif /* _UT_ADAPTOR_BSD_SOCKETS_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-console-bsp.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-console-bsp.h new file mode 100644 index 000000000..d8ac52c9c --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-console-bsp.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-console-bsp.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_CONSOLE_BSP_H_ +#define _UT_ADAPTOR_CONSOLE_BSP_H_ + + +#endif /* _UT_ADAPTOR_CONSOLE_BSP_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-loader.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-loader.h new file mode 100644 index 000000000..9d68b804c --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-loader.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-loader.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_NO_LOADER_H_ +#define _UT_ADAPTOR_NO_LOADER_H_ + + +#endif /* _UT_ADAPTOR_NO_LOADER_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-network.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-network.h new file mode 100644 index 000000000..9c0dfca99 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-network.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-network.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_NO_NETWORK_H_ +#define _UT_ADAPTOR_NO_NETWORK_H_ + + +#endif /* _UT_ADAPTOR_NO_NETWORK_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-sockets.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-sockets.h new file mode 100644 index 000000000..490c668ec --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-sockets.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-sockets.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_NO_SOCKETS_H_ +#define _UT_ADAPTOR_NO_SOCKETS_H_ + + +#endif /* _UT_ADAPTOR_NO_SOCKETS_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-symtab.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-symtab.h new file mode 100644 index 000000000..e78d8af8d --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-no-symtab.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-symtab.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_NO_SYMTAB_H_ +#define _UT_ADAPTOR_NO_SYMTAB_H_ + + +#endif /* _UT_ADAPTOR_NO_SYMTAB_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h new file mode 100644 index 000000000..f558ed987 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-files.h @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_PPOSFILEAPI_H_ +#define _UT_PPOSFILEAPI_H_ + +#include + +unsigned int UT_PortablePosixFileTest_GetSelfEUID(void); +unsigned int UT_PortablePosixFileTest_GetSelfEGID(void); + +#endif /* _UT_OSFILEAPI_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h new file mode 100644 index 000000000..3142fd1af --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-portable-posix-io.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_PPOSFILEAPI_H_ +#define _UT_PPOSFILEAPI_H_ + +#include + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ +void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable); + +#endif /* _UT_OSFILEAPI_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dirs.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dirs.h new file mode 100644 index 000000000..de5826464 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dirs.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dirs.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_DIRS_H_ +#define _UT_ADAPTOR_POSIX_DIRS_H_ + + +#endif /* _UT_ADAPTOR_POSIX_DIRS_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-loader.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-loader.h new file mode 100644 index 000000000..58315dd2c --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-loader.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dl-loader.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_DL_LOADER_H_ +#define _UT_ADAPTOR_POSIX_DL_LOADER_H_ + + +#endif /* _UT_ADAPTOR_POSIX_DL_LOADER_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-symtab.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-symtab.h new file mode 100644 index 000000000..525f71d11 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-dl-symtab.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dl-symtab.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_DL_SYMTAB_H_ +#define _UT_ADAPTOR_POSIX_DL_SYMTAB_H_ + + +#endif /* _UT_ADAPTOR_POSIX_DL_SYMTAB_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-files.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-files.h new file mode 100644 index 000000000..3284abae6 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-files.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-files.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_FILES_H_ +#define _UT_ADAPTOR_POSIX_FILES_H_ + + +#endif /* _UT_ADAPTOR_POSIX_FILES_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-gettime.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-gettime.h new file mode 100644 index 000000000..85cae8299 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-gettime.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-gettime.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_GETTIME_H_ +#define _UT_ADAPTOR_POSIX_GETTIME_H_ + + +#endif /* _UT_ADAPTOR_POSIX_GETTIME_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-io.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-io.h new file mode 100644 index 000000000..31b19bee7 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-io.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-io.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_IO_H_ +#define _UT_ADAPTOR_POSIX_IO_H_ + + +#endif /* _UT_ADAPTOR_POSIX_IO_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-network.h b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-network.h new file mode 100644 index 000000000..fb58efe59 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/inc/ut-adaptor-posix-network.h @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-network.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_POSIX_NETWORK_H_ +#define _UT_ADAPTOR_POSIX_NETWORK_H_ + + +#endif /* _UT_ADAPTOR_POSIX_NETWORK_H_ */ + diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-select.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-select.c new file mode 100644 index 000000000..3ce5378ce --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-select.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-bsd-select.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-sockets.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-sockets.c new file mode 100644 index 000000000..50d32128e --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-bsd-sockets.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-bsd-sockets.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-console-bsp.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-console-bsp.c new file mode 100644 index 000000000..656bcf323 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-console-bsp.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-console-bsp.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-loader.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-loader.c new file mode 100644 index 000000000..d45da35b0 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-loader.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-loader.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-network.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-network.c new file mode 100644 index 000000000..c6446e187 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-network.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-network.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-sockets.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-sockets.c new file mode 100644 index 000000000..da1bdc6a6 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-sockets.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-sockets.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-symtab.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-symtab.c new file mode 100644 index 000000000..1daf166f1 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-no-symtab.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-no-symtab.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c new file mode 100644 index 000000000..a06ec31b2 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-files.c @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-portable-posix-files.h" + +#include + +unsigned int UT_PortablePosixFileTest_GetSelfEUID(void) +{ + return OS_IMPL_SELF_EUID; +} + +unsigned int UT_PortablePosixFileTest_GetSelfEGID(void) +{ + return OS_IMPL_SELF_EGID; +} + diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c new file mode 100644 index 000000000..6b4dd5d40 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-portable-posix-io.c @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-portable-posix-io.h" + +#include + + +void UT_PortablePosixIOTest_Set_Selectable(uint32 local_id, bool is_selectable) +{ + OS_impl_filehandle_table[local_id].selectable = is_selectable; +} diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dirs.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dirs.c new file mode 100644 index 000000000..ec93dbd3b --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dirs.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dirs.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-loader.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-loader.c new file mode 100644 index 000000000..3fc256a2f --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-loader.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dl-loader.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-symtab.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-symtab.c new file mode 100644 index 000000000..5ddd9b167 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-dl-symtab.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-dl-symtab.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/coveragetest-posixfile.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-files.c similarity index 86% rename from src/unit-test-coverage/portable/coveragetest-posixfile.c rename to src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-files.c index 592b12c5e..746be281c 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixfile.c +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-files.c @@ -1,27 +1,24 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osfileapi-common" file - * - * Notes: + +/** + * \file ut-adaptor-posix-files.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov * */ -/* - * Includes - */ - #include #include #include @@ -37,10 +34,10 @@ #include #include -#define OSAPI_TEST_FUNCTION_RC(func,exp) \ +#define OSAPI_TEST_FUNCTION_RC(func,exp) \ { \ int32 rcexp = exp; \ - int32 rcact = func; \ + int32 rcact = func; \ UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", \ #func, (long)rcact, #exp, (long)rcexp); \ } @@ -173,29 +170,29 @@ void Test_OS_FileRename_Impl (void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) /* UtTest_Setup * diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-gettime.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-gettime.c new file mode 100644 index 000000000..8cd0ead75 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-gettime.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-gettime.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-io.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-io.c new file mode 100644 index 000000000..cf9a5fd62 --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-io.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-io.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-network.c b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-network.c new file mode 100644 index 000000000..a0afb6e6e --- /dev/null +++ b/src/unit-test-coverage/portable/adaptors/src/ut-adaptor-posix-network.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file ut-adaptor-posix-network.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/coveragetest-posixgettime.c b/src/unit-test-coverage/portable/coveragetest-posixgettime.c deleted file mode 100644 index f88258cf0..000000000 --- a/src/unit-test-coverage/portable/coveragetest-posixgettime.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osfileapi-common" file - * - * Notes: - * - */ - - -/* - * Includes - */ - -#include -#include -#include - -#include -#include - -#include - -#define OSAPI_TEST_FUNCTION_RC(func,exp) \ -{ \ - int32 rcexp = exp; \ - int32 rcact = func; \ - UtAssert_True(rcact == rcexp, "%s (%ld) == %s (%ld)", \ - #func, (long)rcact, #exp, (long)rcexp); \ -} - - -void Test_OS_GetLocalTime_Impl(void) -{ - /* - * Test Case For: - * int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) - */ - OS_time_t timeval; - timeval.seconds = 1; - timeval.microsecs = 1; - OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl(&timeval), OS_SUCCESS); - - UT_SetForceFail(UT_KEY(OCS_clock_gettime), -1); - OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl(&timeval), OS_ERROR); -} - -void Test_OS_SetLocalTime_Impl(void) -{ - /* - * Test Case For: - * int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) - */ - OS_time_t timeval; - timeval.seconds = 1; - timeval.microsecs = 1; - OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl(&timeval), OS_SUCCESS); - - UT_SetForceFail(UT_KEY(OCS_clock_settime), -1); - OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl(&timeval), OS_ERROR); -} - - -/* ------------------- End of test cases --------------------------------------*/ - -/* Osapi_Task_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Task_Setup(void) -{ - UT_ResetState(0); -} - -/* - * Osapi_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void Osapi_TearDown(void) -{ - -} - - -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) - -/* UtTest_Setup - * - * Purpose: - * Registers the test cases to execute with the unit test tool - */ -void UtTest_Setup(void) -{ - ADD_TEST(OS_GetLocalTime_Impl); - ADD_TEST(OS_SetLocalTime_Impl); -} - - diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c new file mode 100644 index 000000000..45f1b9767 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-select.c @@ -0,0 +1,122 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-bsd-select.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-portable-coveragetest.h" + +#include "osapi-select-impl.h" + +#include + +void Test_OS_SelectSingle_Impl(void) +{ + /* Test Case For: + * int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) + */ + uint32 SelectFlags; + uint32 StreamID; + struct OCS_timespec nowtime; + struct OCS_timespec latertime; + + StreamID = 0; + SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, -1), OS_SUCCESS); + SelectFlags = 0; + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_select), 0); + SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + nowtime.tv_sec = 1; + nowtime.tv_nsec = 500000000; + latertime.tv_sec = 10; + latertime.tv_nsec = 0; + UT_SetDataBuffer(UT_KEY(OCS_clock_gettime),&nowtime, sizeof(nowtime), false); + UT_SetDataBuffer(UT_KEY(OCS_clock_gettime),&latertime, sizeof(latertime), false); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 999), OS_ERROR_TIMEOUT); + + UT_SetForceFail(UT_KEY(OCS_select), -1); + SelectFlags = OS_STREAM_STATE_READABLE | OS_STREAM_STATE_WRITABLE; + nowtime.tv_sec = 1; + nowtime.tv_nsec = 0; + latertime.tv_sec = 2; + latertime.tv_nsec = 600000000; + UT_SetDataBuffer(UT_KEY(OCS_clock_gettime),&nowtime, sizeof(nowtime), false); + UT_SetDataBuffer(UT_KEY(OCS_clock_gettime),&latertime, sizeof(latertime), false); + OSAPI_TEST_FUNCTION_RC(OS_SelectSingle_Impl, (StreamID, &SelectFlags, 2100), OS_ERROR); +} /* end OS_SelectSingle_Impl */ + + +void Test_OS_SelectMultiple_Impl(void) +{ + /* Test Case For: + * int32 OS_SelectMultiple_Impl(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs) + */ + OS_FdSet ReadSet; + OS_FdSet WriteSet; + + memset(&ReadSet, 0, sizeof(ReadSet)); + memset(&WriteSet, 0xff, sizeof(WriteSet)); + OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 0), OS_SUCCESS); + memset(&ReadSet, 0xff, sizeof(ReadSet)); + memset(&WriteSet, 0, sizeof(WriteSet)); + UT_SetForceFail(UT_KEY(OCS_select), 0); + OSAPI_TEST_FUNCTION_RC(OS_SelectMultiple_Impl, (&ReadSet, &WriteSet, 1), OS_ERROR_TIMEOUT); +} /* end OS_SelectMultiple_Impl */ + + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_SelectSingle_Impl); + ADD_TEST(OS_SelectMultiple_Impl); +} + + + + diff --git a/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c new file mode 100644 index 000000000..12444b565 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-bsd-sockets.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-bsd-sockets.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c new file mode 100644 index 000000000..7ccc1a3a4 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-console-bsp.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-console-bsp.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-loader.c b/src/unit-test-coverage/portable/src/coveragetest-no-loader.c new file mode 100644 index 000000000..2ab68368c --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-loader.c @@ -0,0 +1,88 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-no-loader.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-portable-coveragetest.h" +#include "osapi-module-impl.h" + +void Test_OS_ModuleLoad_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) + */ + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl, (0,"local"), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_ModuleUnload_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleUnload_Impl ( uint32 module_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl, (0), OS_ERR_NOT_IMPLEMENTED); +} + +void Test_OS_ModuleGetInfo_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) + */ + OS_module_prop_t module_prop; + + memset(&module_prop, 0, sizeof(module_prop)); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl, (0,&module_prop), OS_ERR_NOT_IMPLEMENTED); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_ModuleLoad_Impl); + ADD_TEST(OS_ModuleUnload_Impl); + ADD_TEST(OS_ModuleGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-network.c b/src/unit-test-coverage/portable/src/coveragetest-no-network.c new file mode 100644 index 000000000..540da79b1 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-network.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-no-network.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c b/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c new file mode 100644 index 000000000..1be0ea037 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-sockets.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-no-sockets.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c new file mode 100644 index 000000000..d9cae0ab6 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-no-symtab.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-no-symtab.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c new file mode 100644 index 000000000..891995777 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-dirs.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-dirs.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-dl-loader.c b/src/unit-test-coverage/portable/src/coveragetest-posix-dl-loader.c new file mode 100644 index 000000000..b7a394f5d --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-dl-loader.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-dl-loader.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-dl-symtab.c b/src/unit-test-coverage/portable/src/coveragetest-posix-dl-symtab.c new file mode 100644 index 000000000..1e9646076 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-dl-symtab.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-dl-symtab.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-files.c b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c new file mode 100644 index 000000000..315a779db --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-files.c @@ -0,0 +1,198 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-files.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-portable-coveragetest.h" +#include "ut-adaptor-portable-posix-files.h" + +#include "osapi-file-impl.h" + +#include +#include +#include +#include +#include + + +void Test_OS_FileOpen_Impl(void) +{ + /* + * Test Case For: + * int32 OS_FileOpen_Impl(uint32 local_id, const char *local_path, int32 flags, int32 access) + */ + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0,"local",OS_FILE_FLAG_TRUNCATE,OS_WRITE_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0,"local",0,OS_READ_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0,"local",OS_FILE_FLAG_CREATE,OS_READ_WRITE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0,"local",0,-1234), OS_FS_ERROR); + + + /* failure mode */ + UT_SetForceFail(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileOpen_Impl, (0,"local",0,OS_READ_ONLY), OS_ERROR); +} + +void Test_OS_FileStat_Impl(void) +{ + /* + * Test Case For: + * int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *FileStats) + */ + os_fstat_t FileStats; + struct OCS_stat RefStat; + + /* failure mode */ + UT_SetForceFail(UT_KEY(OCS_stat), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local",&FileStats), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_stat)); + + /* nominal, no permission bits */ + memset(&FileStats,0,sizeof(FileStats)); + OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local",&FileStats), OS_SUCCESS); + UtAssert_True(FileStats.FileModeBits == 0, "File Mode Bits unset"); + + /* all permission bits with uid/gid match */ + RefStat.st_uid = UT_PortablePosixFileTest_GetSelfEUID(); + RefStat.st_gid = UT_PortablePosixFileTest_GetSelfEGID(); + RefStat.st_mode = ~0; + RefStat.st_size = 1234; + RefStat.st_mtime = 5678; + UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); + OSAPI_TEST_FUNCTION_RC(OS_FileStat_Impl, ("local",&FileStats), OS_SUCCESS); + + /* Test that the result checking macros work */ + UtAssert_True(OS_FILESTAT_EXEC(FileStats), "File Exec Bit set"); + UtAssert_True(OS_FILESTAT_WRITE(FileStats), "File Write Bit set"); + UtAssert_True(OS_FILESTAT_READ(FileStats), "File Read Bit set"); + UtAssert_True(OS_FILESTAT_ISDIR(FileStats), "Directory Bit set"); + UtAssert_True(OS_FILESTAT_SIZE(FileStats) == 1234, "Size match"); + UtAssert_True(OS_FILESTAT_TIME(FileStats) == 5678, "Time match"); + +} + +void Test_OS_FileChmod_Impl(void) +{ + /* + * Test Case For: + * int32 OS_FileChmod_Impl(const char *local_path, uint32 access) + */ + struct OCS_stat RefStat; + + /* failure mode 1 (stat) */ + UT_SetForceFail(UT_KEY(OCS_stat), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local",OS_READ_WRITE), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_stat)); + + /* failure mode 2 (chmod) */ + UT_SetForceFail(UT_KEY(OCS_chmod), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local",OS_READ_WRITE), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_chmod)); + + /* all permission bits with uid/gid match */ + RefStat.st_uid = UT_PortablePosixFileTest_GetSelfEUID(); + RefStat.st_gid = UT_PortablePosixFileTest_GetSelfEGID(); + RefStat.st_mode = ~0; + RefStat.st_size = 1234; + RefStat.st_mtime = 5678; + UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); + + /* nominal 1 - full permissions with file owned by own uid/gid */ + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local",OS_READ_WRITE), OS_SUCCESS); + + /* nominal 2 - partial permissions */ + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_READ_ONLY), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local", OS_WRITE_ONLY), OS_SUCCESS); + + /* nominal 3 - non-owned file */ + ++RefStat.st_uid; + ++RefStat.st_gid; + UT_SetDataBuffer(UT_KEY(OCS_stat), &RefStat, sizeof(RefStat), false); + OSAPI_TEST_FUNCTION_RC(OS_FileChmod_Impl, ("local",OS_READ_WRITE), OS_SUCCESS); +} + +void Test_OS_FileRemove_Impl (void) +{ + /* + * Test Case For: + * int32 OS_FileRemove_Impl(const char *local_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_SUCCESS); + + /* failure mode */ + UT_SetForceFail(UT_KEY(OCS_remove), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileRemove_Impl, ("local"), OS_ERROR); + +} + +void Test_OS_FileRename_Impl (void) +{ + /* + * Test Case For: + * int32 OS_FileRename_Impl(const char *old_path, const char *new_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old","new"), OS_SUCCESS); + + /* failure mode */ + UT_SetForceFail(UT_KEY(OCS_rename), -1); + OSAPI_TEST_FUNCTION_RC(OS_FileRename_Impl, ("old","new"), OS_ERROR); +} + + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + memset(OS_stream_table, 0, sizeof(OS_stream_table)); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_FileOpen_Impl); + ADD_TEST(OS_FileStat_Impl); + ADD_TEST(OS_FileChmod_Impl); + ADD_TEST(OS_FileRemove_Impl); + ADD_TEST(OS_FileRename_Impl); +} + + diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c b/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c new file mode 100644 index 000000000..bbe29fac5 --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-gettime.c @@ -0,0 +1,96 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-gettime.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-portable-coveragetest.h" + +#include "osapi-clock-impl.h" + +#include + + +void Test_OS_GetLocalTime_Impl(void) +{ + /* + * Test Case For: + * int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) + */ + OS_time_t timeval; + timeval.seconds = 1; + timeval.microsecs = 1; + OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_clock_gettime), -1); + OSAPI_TEST_FUNCTION_RC(OS_GetLocalTime_Impl, (&timeval), OS_ERROR); +} + +void Test_OS_SetLocalTime_Impl(void) +{ + /* + * Test Case For: + * int32 OS_SetLocalTime_Impl(const OS_time_t *time_struct) + */ + OS_time_t timeval; + timeval.seconds = 1; + timeval.microsecs = 1; + OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_clock_settime), -1); + OSAPI_TEST_FUNCTION_RC(OS_SetLocalTime_Impl, (&timeval), OS_ERROR); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_GetLocalTime_Impl); + ADD_TEST(OS_SetLocalTime_Impl); +} + + diff --git a/src/unit-test-coverage/portable/coveragetest-posixio.c b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c similarity index 74% rename from src/unit-test-coverage/portable/coveragetest-posixio.c rename to src/unit-test-coverage/portable/src/coveragetest-posix-io.c index eaaf3c164..ec3f1a95d 100644 --- a/src/unit-test-coverage/portable/coveragetest-posixio.c +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-io.c @@ -1,50 +1,35 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osfileapi-common" file - * - * Notes: - * + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * */ -/* - * Includes +/** + * \file coveragetest-posix-io.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * */ -#include -#include -#include +#include "os-portable-coveragetest.h" +#include "ut-adaptor-portable-posix-io.h" -#include -#include +#include "osapi-file-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-select-impl.h" #include #include #include #include -#include "ut-osfileapi.h" - -#define OSAPI_TEST_FUNCTION_RC(func,args,exp) \ -{ \ - int32 rcexp = exp; \ - int32 rcact = func args; \ - UtAssert_True(rcact == rcexp, "%s%s (%ld) == %s (%ld)", \ - #func, #args, (long)rcact, #exp, (long)rcexp); \ -} - - void Test_OS_GenericClose_Impl(void) { @@ -99,14 +84,14 @@ void Test_OS_GenericRead_Impl (void) char DestData[sizeof(SrcData)] = { 0 }; UT_SetDataBuffer(UT_KEY(OCS_read),SrcData,sizeof(SrcData),false); - Osapi_Internal_Set_Selectable(0, false); + UT_PortablePosixIOTest_Set_Selectable(0, false); OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl,(0,DestData,sizeof(DestData),0), sizeof(DestData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData),"read() data Valid"); /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_read)); UT_SetDataBuffer(UT_KEY(OCS_read),SrcData,sizeof(SrcData),false); - Osapi_Internal_Set_Selectable(0, true); + UT_PortablePosixIOTest_Set_Selectable(0, true); OSAPI_TEST_FUNCTION_RC(OS_GenericRead_Impl,(0,DestData,sizeof(DestData),0), sizeof(DestData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); @@ -125,7 +110,7 @@ void Test_OS_GenericWrite_Impl(void) char DestData[sizeof(SrcData)] = { 0 }; UT_SetDataBuffer(UT_KEY(OCS_write),DestData,sizeof(DestData),false); - Osapi_Internal_Set_Selectable(0, false); + UT_PortablePosixIOTest_Set_Selectable(0, false); OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl,(0,SrcData,sizeof(SrcData),0), sizeof(SrcData)); UtAssert_MemCmp(SrcData, DestData, sizeof(SrcData), "write() data valid"); @@ -133,7 +118,7 @@ void Test_OS_GenericWrite_Impl(void) /* test invocation of select() in nonblocking mode */ UT_ResetState(UT_KEY(OCS_write)); UT_SetDataBuffer(UT_KEY(OCS_write),DestData,sizeof(DestData),false); - Osapi_Internal_Set_Selectable(0, true); + UT_PortablePosixIOTest_Set_Selectable(0, true); OSAPI_TEST_FUNCTION_RC(OS_GenericWrite_Impl,(0,SrcData,sizeof(SrcData),0), sizeof(SrcData)); UtAssert_True(UT_GetStubCount(UT_KEY(OS_SelectSingle_Impl)) == 1, "OS_SelectSingle() called"); @@ -145,29 +130,31 @@ void Test_OS_GenericWrite_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + memset(OS_stream_table, 0, sizeof(OS_stream_table)); + memset(OS_global_stream_table, 0, sizeof(OS_common_record_t) * OS_MAX_NUM_OPEN_FILES); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) /* UtTest_Setup * diff --git a/src/unit-test-coverage/portable/src/coveragetest-posix-network.c b/src/unit-test-coverage/portable/src/coveragetest-posix-network.c new file mode 100644 index 000000000..ca5fc8f5a --- /dev/null +++ b/src/unit-test-coverage/portable/src/coveragetest-posix-network.c @@ -0,0 +1,19 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + */ + + +/** + * \file coveragetest-posix-network.c + * \ingroup + * \author joseph.p.hickey@nasa.gov + * + */ diff --git a/src/unit-test-coverage/portable/src/os-portable-coveragetest.h b/src/unit-test-coverage/portable/src/os-portable-coveragetest.h new file mode 100644 index 000000000..c2ed2b9c8 --- /dev/null +++ b/src/unit-test-coverage/portable/src/os-portable-coveragetest.h @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file os-vxworks-coveragetest.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _OS_PORTABLE_COVERAGETEST_H_ +#define _OS_PORTABLE_COVERAGETEST_H_ + +/* + * Includes + */ + +#include +#include +#include + + +#include "osapi-shared-globaldefs.h" + + +#define OSAPI_TEST_FUNCTION_RC(func,args,exp) \ +{ \ + int32 rcexp = exp; \ + int32 rcact = func args; \ + UtAssert_True(rcact == rcexp, "%s%s (%ld) == %s (%ld)", \ + #func, #args, (long)rcact, #exp, (long)rcexp); \ +} + +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void); +void Osapi_Test_Teardown(void); + + +#endif /* _OS_PORTABLE_COVERAGETEST_H_ */ + diff --git a/src/unit-test-coverage/posix/CMakeLists.txt b/src/unit-test-coverage/posix/CMakeLists.txt index 79c940750..719940178 100644 --- a/src/unit-test-coverage/posix/CMakeLists.txt +++ b/src/unit-test-coverage/posix/CMakeLists.txt @@ -1,24 +1,72 @@ -# CMake snippet for building the shared OSAL layer coverage tests +# CMake snippet for building the POSIX layer coverage tests +set(POSIX_MODULE_LIST + #binsem + #common + #console + #countsem + #dirs + #files + #filesys + #heap + #loader + #mutex + #network + #queues + #shell + # symtab + #tasks + #timebase +) -set(MODULE_LIST osapi) +set(POSIX_PORTABLE_BLOCK_LIST + posix-gettime + posix-io + posix-files + + #console-bsp + bsd-select + #bsd-sockets + + no-loader + #no-symtab + #no-network + #no-sockets +) # This unit test is allowed to directly include any internal file in # the respective set under test. -include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/inc) +include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}/inc) # The "ut-stubs" contains additional stubs specific to this sub-module add_subdirectory(ut-stubs) +add_subdirectory(adaptors) -# the "modules" contains wrappers around the actual module under test -# (this is not a stub, this is the real code) -add_subdirectory(modules) +set(POSIX_COVERAGE_LINK_LIST + ut-adaptor-posix + ut_posix_impl_stubs + ut_osapi_impl_stubs + ut_osapi_shared_stubs + ut_osapi_stubs + ut_libc_stubs +) -set(MODULE_LINK_MAP_posixio osfileapi) -set(MODULE_LINK_MAP_posixfile osfileapi) -set(MODULE_LINK_MAP_posixdirs osfileapi) -set(MODULE_LINK_MAP_posixgettime ostimer) # Add all coverage tests in the src dir -add_coverage_tests(${SETNAME} ${MODULE_LIST}) +foreach(MODNAME ${POSIX_MODULE_LIST}) + add_coverage_testrunner( + "coverage-${SETNAME}-${MODNAME}" + "${OSAL_SOURCE_DIR}/src/os/${SETNAME}/src/os-impl-${MODNAME}.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" + ${POSIX_COVERAGE_LINK_LIST} + ) +endforeach(MODNAME ${POSIX_MODULE_LIST}) + +foreach(MODNAME ${POSIX_PORTABLE_BLOCK_LIST}) + add_coverage_testrunner( + "coverage-${SETNAME}-${MODNAME}" + "${OSAL_SOURCE_DIR}/src/os/portable/os-impl-${MODNAME}.c" + "${OSALCOVERAGE_SOURCE_DIR}/portable/src/coveragetest-${MODNAME}.c" + ${POSIX_COVERAGE_LINK_LIST} + ) +endforeach(MODNAME ${POSIX_PORTABLE_BLOCK_LIST}) diff --git a/src/unit-test-coverage/posix/adaptors/CMakeLists.txt b/src/unit-test-coverage/posix/adaptors/CMakeLists.txt new file mode 100644 index 000000000..dc21a3b4d --- /dev/null +++ b/src/unit-test-coverage/posix/adaptors/CMakeLists.txt @@ -0,0 +1,35 @@ +# +# Copyright (c) 2019, United States government as represented by the +# administrator of the National Aeronautics Space Administration. +# All rights reserved. This software was created at NASA Goddard +# Space Flight Center pursuant to government contracts. +# +# This is governed by the NASA Open Source Agreement and may be used, +# distributed and modified only according to the terms of that agreement. +# + + +# "Adaptors" help enable the unit test code to reach functions/objects that +# are otherwise not exposed. This is generally required for any OSAL subsystem +# which tracks an internal resource state (i.e. anything with a table). + +# NOTE: These source files are compile with OVERRIDES on the headers just like +# the FSW code is compiled. This is how it is able to include internal headers +# which otherwise would fail. But that also means that adaptor code cannot call +# any library functions, as this would also reach a stub, not the real function. + +add_library(ut-adaptor-${SETNAME} STATIC + src/ut-adaptor-filetable-stub.c + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/src/ut-adaptor-portable-posix-io.c + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/src/ut-adaptor-portable-posix-files.c +) + +# the "override_inc" dir contains replacement versions of the C-library include files. +target_include_directories(ut-adaptor-${SETNAME} PRIVATE + ${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc +) + +target_include_directories(ut-adaptor-${SETNAME} PUBLIC + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/inc + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) diff --git a/src/unit-test-coverage/posix/modules/Makefile b/src/unit-test-coverage/posix/adaptors/Makefile similarity index 100% rename from src/unit-test-coverage/posix/modules/Makefile rename to src/unit-test-coverage/posix/adaptors/Makefile diff --git a/src/unit-test-coverage/posix/modules/README.txt b/src/unit-test-coverage/posix/adaptors/README.txt similarity index 100% rename from src/unit-test-coverage/posix/modules/README.txt rename to src/unit-test-coverage/posix/adaptors/README.txt diff --git a/src/unit-test-coverage/posix/adaptors/inc/ut-adaptor-filetable-stub.h b/src/unit-test-coverage/posix/adaptors/inc/ut-adaptor-filetable-stub.h new file mode 100644 index 000000000..651058865 --- /dev/null +++ b/src/unit-test-coverage/posix/adaptors/inc/ut-adaptor-filetable-stub.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_SHELL_H_ +#define _UT_ADAPTOR_SHELL_H_ + +#include +#include + + +extern void* const UT_FileTableTest_OS_impl_filehandle_table; +extern size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE; + + + +#endif /* _UT_ADAPTOR_SHELL_H_ */ + diff --git a/src/unit-test-coverage/posix/adaptors/src/ut-adaptor-filetable-stub.c b/src/unit-test-coverage/posix/adaptors/src/ut-adaptor-filetable-stub.c new file mode 100644 index 000000000..9b4934e8c --- /dev/null +++ b/src/unit-test-coverage/posix/adaptors/src/ut-adaptor-filetable-stub.c @@ -0,0 +1,50 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-filetable-stub.h" + +#include +#include + + + + +OS_Posix_file_internal_record_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + +void* const UT_FileTableTest_OS_impl_filehandle_table = OS_impl_filehandle_table; +size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE = sizeof(OS_impl_filehandle_table); + + +uid_t OS_IMPL_SELF_EUID = 100; +gid_t OS_IMPL_SELF_EGID = 100; + +/* + * Flag(s) to set on file handles for regular files + * This sets all regular filehandles to be non-blocking by default. + * + * In turn, the implementation will utilize select() to determine + * a filehandle readiness to read/write. + */ +const int OS_IMPL_REGULAR_FILE_FLAGS = 1; + diff --git a/src/unit-test-coverage/posix/modules/CMakeLists.txt b/src/unit-test-coverage/posix/modules/CMakeLists.txt deleted file mode 100644 index 98fdcb0d3..000000000 --- a/src/unit-test-coverage/posix/modules/CMakeLists.txt +++ /dev/null @@ -1,41 +0,0 @@ -# -# Copyright (c) 2019, United States government as represented by the -# administrator of the National Aeronautics Space Administration. -# All rights reserved. This software was created at NASA Goddard -# Space Flight Center pursuant to government contracts. -# -# This is governed by the NASA Open Source Agreement and may be used, -# distributed and modified only according to the terms of that agreement. -# - -# -------------------------------------- -# OSAL SHARED LAYER FOR COVERAGE TESTING -# -------------------------------------- - -# This CMake recipe snippet builds the _actual_ OSAL implementation (not a stub) -# However it differs from the regular non-UT build in the following ways: -# - Each sub-module is compiled to a separate "OBJECT" library -# this simplifies the testrunner linking by allow only one specific -# object file to be linked into each test -# - Each sub-module is wrapped to divert C library calls to the -# stub (OCS) counterpart -# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation - -# the "overrides" dir contains empty versions of the C-library include files. -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) -include_directories(${OSAL_SOURCE_DIR}/src/bsp/shared) -include_directories(${OSAL_SOURCE_DIR}/src/os/shared) - -foreach(MODULE ${MODULE_LIST}) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT - src/ut-${MODULE}.c - ) - target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE - ${UT_COVERAGE_COMPILE_FLAGS} - ) - endif () -endforeach() - - diff --git a/src/unit-test-coverage/posix/modules/src/ut-osapi.c b/src/unit-test-coverage/posix/modules/src/ut-osapi.c deleted file mode 100644 index 534461fae..000000000 --- a/src/unit-test-coverage/posix/modules/src/ut-osapi.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi.c" - -/* Stub objects to satisfy linking requirements - - */ -OS_common_record_t OS_stub_task_table[OS_MAX_TASKS]; -OS_common_record_t * const OS_global_task_table = OS_stub_task_table; -OS_common_record_t OS_stub_queue_table[OS_MAX_QUEUES]; -OS_common_record_t * const OS_global_queue_table = OS_stub_queue_table; - -OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; -OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; -OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - diff --git a/src/unit-test-coverage/posix/src/coveragetest-osapi.c b/src/unit-test-coverage/posix/src/coveragetest-osapi.c index 79f11c479..a7ed9b5e3 100644 --- a/src/unit-test-coverage/posix/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/posix/src/coveragetest-osapi.c @@ -388,7 +388,7 @@ void Test_OS_MutSemGetInfo_Impl(void) { /* * Test Case For: - * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) + * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) */ } @@ -451,29 +451,29 @@ void Test_OS_FPUExcGetMask_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) /* UtTest_Setup * diff --git a/src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt index bb51a05e0..f8f1d1120 100644 --- a/src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/posix/ut-stubs/CMakeLists.txt @@ -1,5 +1,2 @@ add_library(ut_posix_impl_stubs src/osapi-impl-posix-stubs.c) - -list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_posix_impl_stubs) -set(OSALCOVERAGE_STUB_LIB_LIST ${OSALCOVERAGE_STUB_LIB_LIST} PARENT_SCOPE) diff --git a/src/unit-test-coverage/shared/CMakeLists.txt b/src/unit-test-coverage/shared/CMakeLists.txt index 938290788..27b73a45c 100644 --- a/src/unit-test-coverage/shared/CMakeLists.txt +++ b/src/unit-test-coverage/shared/CMakeLists.txt @@ -1,7 +1,5 @@ # CMake snippet for building the shared OSAL layer coverage tests -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/inc) - # A list of modules in the shared OSAL implementation. # Each entry corresponds to a source file name osapi-${MODULE}.c set(MODULE_LIST @@ -13,10 +11,8 @@ set(MODULE_LIST errors file filesys - fpu heap idmap - interrupts module mutex network @@ -26,13 +22,34 @@ set(MODULE_LIST sockets task timebase - time) + time +) + +set(SHARED_COVERAGE_LINK_LIST + ut-adaptor-shared + ut_osapi_impl_stubs + ut_osapi_shared_stubs + ut_osapi_stubs + ut_libc_stubs +) + +add_subdirectory(adaptors) -# The "modules" subdirectory builds the _ACTUAL_ OSAL code (not a stub) -# However it is compiled specially to include the coverage instrumentation, -# and all internal C-library calls should be mapped to the OCS_ version. -add_subdirectory(modules) # Add all coverage tests in the src dir -add_coverage_tests(${SETNAME} ${MODULE_LIST}) +foreach(MODNAME ${MODULE_LIST}) + add_coverage_testrunner( + "coverage-${SETNAME}-${MODNAME}" + "${OSAL_SOURCE_DIR}/src/os/${SETNAME}/src/osapi-${MODNAME}.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" + ${SHARED_COVERAGE_LINK_LIST} + ) +endforeach(MODNAME ${MODULE_LIST}) + +# Add extra defintion to force the OS_STATIC_SYMTABLE_SOURCE to the +# local value within the module coverage test +target_compile_definitions(utobj_coverage-shared-module PRIVATE + "OS_STATIC_SYMTABLE_SOURCE=OS_UT_STATIC_SYMBOL_TABLE" +) + diff --git a/src/unit-test-coverage/shared/adaptors/CMakeLists.txt b/src/unit-test-coverage/shared/adaptors/CMakeLists.txt new file mode 100644 index 000000000..cf6cf9f11 --- /dev/null +++ b/src/unit-test-coverage/shared/adaptors/CMakeLists.txt @@ -0,0 +1,32 @@ +# +# Copyright (c) 2019, United States government as represented by the +# administrator of the National Aeronautics Space Administration. +# All rights reserved. This software was created at NASA Goddard +# Space Flight Center pursuant to government contracts. +# +# This is governed by the NASA Open Source Agreement and may be used, +# distributed and modified only according to the terms of that agreement. +# + + +# "Adaptors" help enable the unit test code to reach functions/objects that +# are otherwise not exposed. This is generally required for any OSAL subsystem +# which tracks an internal resource state (i.e. anything with a table). + +# NOTE: These source files are compile with OVERRIDES on the headers just like +# the FSW code is compiled. This is how it is able to include internal headers +# which otherwise would fail. But that also means that adaptor code cannot call +# any library functions, as this would also reach a stub, not the real function. + +add_library(ut-adaptor-${SETNAME} STATIC + src/ut-adaptor-module.c +) + +# the "override_inc" dir contains replacement versions of the C-library include files. +target_include_directories(ut-adaptor-${SETNAME} PRIVATE + ${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc +) + +target_include_directories(ut-adaptor-${SETNAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-module.h b/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h similarity index 58% rename from src/unit-test-coverage/shared/modules/inc/ut-osapi-module.h rename to src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h index 47668e466..1b0887fc5 100644 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-module.h +++ b/src/unit-test-coverage/shared/adaptors/inc/ut-adaptor-module.h @@ -1,5 +1,23 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ #ifndef _OSAL_UT_OSAPI_MODULE_H_ #define _OSAL_UT_OSAPI_MODULE_H_ @@ -27,6 +45,4 @@ void Test_DummyFunc(void); int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName); int32 Osapi_Call_ModuleLoad_Static(const char *ModuleName); - -#endif /* _OSAL_UT_OSAPI_MODULE_H_ */ - +#endif diff --git a/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c b/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c new file mode 100644 index 000000000..80e1f40be --- /dev/null +++ b/src/unit-test-coverage/shared/adaptors/src/ut-adaptor-module.c @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-module.h" +#include "osapi-module-impl.h" + + +int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) +{ + return OS_SymbolLookup_Static(SymbolAddress, SymbolName); +} + +int32 Osapi_Call_ModuleLoad_Static(const char *ModuleName) +{ + return OS_ModuleLoad_Static(ModuleName); +} + diff --git a/src/unit-test-coverage/shared/modules/CMakeLists.txt b/src/unit-test-coverage/shared/modules/CMakeLists.txt deleted file mode 100644 index 4cd649bbd..000000000 --- a/src/unit-test-coverage/shared/modules/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright (c) 2019, United States government as represented by the -# administrator of the National Aeronautics Space Administration. -# All rights reserved. This software was created at NASA Goddard -# Space Flight Center pursuant to government contracts. -# -# This is governed by the NASA Open Source Agreement and may be used, -# distributed and modified only according to the terms of that agreement. -# - -# -------------------------------------- -# OSAL SHARED LAYER FOR COVERAGE TESTING -# -------------------------------------- - -# This CMake recipe snippet builds the _actual_ OSAL shared API (not a stub) -# However it differs from the regular non-UT build in the following ways: -# - Each sub-module is compiled to a separate "OBJECT" library -# this simplifies the testrunner linking by allow only one specific -# object file to be linked into each test -# - Each sub-module is wrapped to divert C library calls to the -# stub (OCS) counterpart -# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation - -# the "override_inc" dir contains replacement versions of the C-library include files. -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) - -foreach(MODULE ${MODULE_LIST}) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-osapi-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT - src/ut-osapi-${MODULE}.c - ) - target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE - ${UT_COVERAGE_COMPILE_FLAGS} - ) - endif () -endforeach() - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-binsem.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-binsem.h deleted file mode 100644 index 79e97b105..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-binsem.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_BINSEM_H_ -#define _OSAL_UT_OSAPI_BINSEM_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_BINSEM_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-clock.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-clock.h deleted file mode 100644 index 3cb39bbdc..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-clock.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_CLOCK_H_ -#define _OSAL_UT_OSAPI_CLOCK_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_CLOCK_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-common.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-common.h deleted file mode 100644 index df24cee6a..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-common.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_COMMON_H_ -#define _OSAL_UT_OSAPI_COMMON_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_COMMON_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-countsem.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-countsem.h deleted file mode 100644 index 78a0b98b3..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-countsem.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_COUNTSEM_H_ -#define _OSAL_UT_OSAPI_COUNTSEM_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_COUNTSEM_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-dir.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-dir.h deleted file mode 100644 index 3b8c82012..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-dir.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_DIR_H_ -#define _OSAL_UT_OSAPI_DIR_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_DIR_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-errors.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-errors.h deleted file mode 100644 index 529055de4..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-errors.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_ERRORS_H_ -#define _OSAL_UT_OSAPI_ERRORS_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_ERRORS_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-file.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-file.h deleted file mode 100644 index b6ef1d13f..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-file.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_FILE_H_ -#define _OSAL_UT_OSAPI_FILE_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_FILE_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-filesys.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-filesys.h deleted file mode 100644 index c8e38974b..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-filesys.h +++ /dev/null @@ -1,29 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_FILESYS_H_ -#define _OSAL_UT_OSAPI_FILESYS_H_ - -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -bool Osapi_Internal_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj); -int32 Osapi_Internal_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, const OS_VolumeInfo_t *Vol); - - -#endif /* _OSAL_UT_OSAPI_FILESYS_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-fpu.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-fpu.h deleted file mode 100644 index f35e5fa2d..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-fpu.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_FPU_H_ -#define _OSAL_UT_OSAPI_FPU_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_FPU_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-heap.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-heap.h deleted file mode 100644 index 4c19b5ebe..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-heap.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_HEAP_H_ -#define _OSAL_UT_OSAPI_HEAP_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_HEAP_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h deleted file mode 100644 index 09717c307..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-idmap.h +++ /dev/null @@ -1,38 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_IDMAP_H_ -#define _OSAL_UT_OSAPI_IDMAP_H_ - -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -/** - * Wrapper around the OS_ObjectIdFindNext call so the test code can invoke it - * (it is defined as static) - */ -int32 Osapi_Call_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record); - -/** - * Wrapper around the OS_ObjectIdConvertLock call so the test code can invoke it - * (it is defined as static) - */ -int32 Osapi_Call_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj); - - -#endif /* _OSAL_UT_OSAPI_IDMAP_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-interrupts.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-interrupts.h deleted file mode 100644 index c735c77ed..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-interrupts.h +++ /dev/null @@ -1,24 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_INTERRUPTS_H_ -#define _OSAL_UT_OSAPI_INTERRUPTS_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -#endif /* _OSAL_UT_OSAPI_INTERRUPTS_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-mutex.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-mutex.h deleted file mode 100644 index 2663c0ea8..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-mutex.h +++ /dev/null @@ -1,24 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_MUTEX_H_ -#define _OSAL_UT_OSAPI_MUTEX_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -#endif /* _OSAL_UT_OSAPI_MUTEX_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-network.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-network.h deleted file mode 100644 index f746a3f8f..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-network.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_NETWORK_H_ -#define _OSAL_UT_OSAPI_NETWORK_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_NETWORK_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-printf.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-printf.h deleted file mode 100644 index cb3c5ae8c..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-printf.h +++ /dev/null @@ -1,26 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_PRINTF_H_ -#define _OSAL_UT_OSAPI_PRINTF_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_PRINTF_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-queue.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-queue.h deleted file mode 100644 index 8a3fcf2ad..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-queue.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_QUEUE_H_ -#define _OSAL_UT_OSAPI_QUEUE_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_QUEUE_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-select.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-select.h deleted file mode 100644 index 556a083b2..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-select.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_SELECT_H_ -#define _OSAL_UT_OSAPI_SELECT_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_SELECT_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h deleted file mode 100644 index fec3c5ce4..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-sockets.h +++ /dev/null @@ -1,31 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_SOCKETS_H_ -#define _OSAL_UT_OSAPI_SOCKETS_H_ - -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -/** - * Invoke the OS_CreateSocketName() static helper function - */ -void Osapi_Call_CreateSocketName_Static(OS_stream_internal_record_t *sock, - const OS_SockAddr_t *Addr, const char *parent_name); - -#endif /* _OSAL_UT_OSAPI_SOCKETS_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-task.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-task.h deleted file mode 100644 index b9ebb95f2..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-task.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_TASK_H_ -#define _OSAL_UT_OSAPI_TASK_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_TASK_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-time.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-time.h deleted file mode 100644 index 81bec46f0..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-time.h +++ /dev/null @@ -1,26 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_TIME_H_ -#define _OSAL_UT_OSAPI_TIME_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_TIME_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/inc/ut-osapi-timebase.h b/src/unit-test-coverage/shared/modules/inc/ut-osapi-timebase.h deleted file mode 100644 index 885822679..000000000 --- a/src/unit-test-coverage/shared/modules/inc/ut-osapi-timebase.h +++ /dev/null @@ -1,25 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_TIMEBASE_H_ -#define _OSAL_UT_OSAPI_TIMEBASE_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - - -#endif /* _OSAL_UT_OSAPI_TIMEBASE_H_ */ - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-binsem.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-binsem.c deleted file mode 100644 index 6839ead86..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-binsem.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-binsem.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-binsem.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-clock.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-clock.c deleted file mode 100644 index 30aab8328..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-clock.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-clock.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-clock.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-countsem.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-countsem.c deleted file mode 100644 index 951b86d67..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-countsem.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-countsem.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-countsem.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-dir.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-dir.c deleted file mode 100644 index 5c1d85ef5..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-dir.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-dir.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-dir.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-errors.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-errors.c deleted file mode 100644 index c106acd60..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-errors.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-errors.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-errors.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-file.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-file.c deleted file mode 100644 index cfd1f6c3c..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-file.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-file.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-file.c" - -/* - * Stub objects to satisfy linking requirements - - */ -OS_common_record_t OS_stub_file_table[OS_MAX_NUM_OPEN_FILES]; - -OS_common_record_t * const OS_global_stream_table = OS_stub_file_table; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-filesys.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-filesys.c deleted file mode 100644 index eef3dd0cd..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-filesys.c +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-filesys.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-filesys.c" - -/* - * Stub objects to satisfy linking requirements - - */ -OS_common_record_t OS_stub_filesys_table[OS_MAX_FILE_SYSTEMS]; -OS_common_record_t OS_stub_stream_table[OS_MAX_NUM_OPEN_FILES]; -OS_common_record_t * const OS_global_filesys_table = OS_stub_filesys_table; -OS_common_record_t * const OS_global_stream_table = OS_stub_stream_table; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - -/* - * Provide a wrapper so the UT can invoke OS_FileSys_FindVirtMountPoint() - */ -bool Osapi_Internal_FileSys_FindVirtMountPoint(void *ref, uint32 local_id, const OS_common_record_t *obj) -{ - return OS_FileSys_FindVirtMountPoint(ref, local_id, obj); -} - -/* - * Provide a wrapper so the UT can invoke OS_FileSys_InitLocalFromVolTable() - */ -int32 Osapi_Internal_FileSys_InitLocalFromVolTable(OS_filesys_internal_record_t *local, const OS_VolumeInfo_t *Vol) -{ - return OS_FileSys_InitLocalFromVolTable(local, Vol); -} - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-heap.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-heap.c deleted file mode 100644 index 933af12e4..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-heap.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-heap.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-heap.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c deleted file mode 100644 index 50ac5e041..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-idmap.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-idmap.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-idmap.c" - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - -int32 Osapi_Call_ObjectIdFindNext(uint32 idtype, uint32 *array_index, OS_common_record_t **record) -{ - return OS_ObjectIdFindNext(idtype, array_index, record); -} - -int32 Osapi_Call_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 reference_id, OS_common_record_t *obj) -{ - return OS_ObjectIdConvertLock(lock_mode, idtype, reference_id, obj); -} diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-interrupts.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-interrupts.c deleted file mode 100644 index 6a09c9036..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-interrupts.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-interrupts.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-interrupts.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-module.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-module.c deleted file mode 100644 index 9b4af5148..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-module.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-module.h" - -/* - * The UT test case provides its own static symbol table - */ -#define OS_STATIC_SYMTABLE_SOURCE OS_UT_STATIC_SYMBOL_TABLE - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-module.c" - - -int32 Osapi_Call_SymbolLookup_Static(cpuaddr *SymbolAddress, const char *SymbolName) -{ - return OS_SymbolLookup_Static(SymbolAddress, SymbolName); -} - -int32 Osapi_Call_ModuleLoad_Static(const char *ModuleName) -{ - return OS_ModuleLoad_Static(ModuleName); -} diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-mutex.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-mutex.c deleted file mode 100644 index b1679f380..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-mutex.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-mutex.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-mutex.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-network.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-network.c deleted file mode 100644 index 614adaf8b..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-network.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-network.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-network.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-printf.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-printf.c deleted file mode 100644 index 52f18eff9..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-printf.c +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-printf.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-printf.c" - -OS_common_record_t OS_stub_console_table[OS_MAX_TASKS]; -OS_common_record_t * const OS_global_console_table = OS_stub_console_table; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-queue.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-queue.c deleted file mode 100644 index b75a1655b..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-queue.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-queue.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-queue.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-select.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-select.c deleted file mode 100644 index 08f3b1562..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-select.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-select.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-select.c" - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c deleted file mode 100644 index 8a68e7516..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-sockets.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-sockets.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-sockets.c" - -/* Global variables to satisfy external link symbols */ -OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; -OS_common_record_t OS_stub_socket_table[OS_MAX_NUM_OPEN_FILES]; -OS_common_record_t * const OS_global_stream_table = OS_stub_socket_table; - -void Osapi_Call_CreateSocketName_Static(OS_stream_internal_record_t *sock, const OS_SockAddr_t *Addr, const char *parent_name) -{ - OS_CreateSocketName(sock, Addr, parent_name); -} - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-task.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-task.c deleted file mode 100644 index 09fc647da..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-task.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-task.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-task.c" - -/* Stub objects to satisfy linking requirements - - */ -OS_common_record_t OS_stub_task_table[OS_MAX_TASKS]; -OS_common_record_t * const OS_global_task_table = OS_stub_task_table; diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-time.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-time.c deleted file mode 100644 index 74ec80abe..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-time.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-time.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-time.c" - - -/* Stub objects to satisfy linking requirements - - * the time module may look up entities in the timebase table - */ -OS_timebase_internal_record_t OS_timebase_table[OS_MAX_TIMEBASES]; -OS_common_record_t OS_stub_timebase_table[OS_MAX_TIMEBASES]; -OS_common_record_t OS_stub_timecb_table[OS_MAX_TIMERS]; - -OS_common_record_t * const OS_global_timebase_table = OS_stub_timebase_table; -OS_common_record_t * const OS_global_timecb_table = OS_stub_timecb_table; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-timebase.c b/src/unit-test-coverage/shared/modules/src/ut-osapi-timebase.c deleted file mode 100644 index 0c17797a2..000000000 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-timebase.c +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-timebase.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-timebase.c" - -/* Stub objects to satisfy linking requirements - - * the time module may look up entities in the timebase table - */ -OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; -OS_common_record_t OS_stub_timebase_table[OS_MAX_TIMEBASES]; -OS_common_record_t OS_stub_timecb_table[OS_MAX_TIMERS]; - -OS_common_record_t * const OS_global_timebase_table = OS_stub_timebase_table; -OS_common_record_t * const OS_global_timecb_table = OS_stub_timecb_table; - - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - diff --git a/src/unit-test-coverage/shared/src/coveragetest-binsem.c b/src/unit-test-coverage/shared/src/coveragetest-binsem.c index 41cf226c0..701afc0b0 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-binsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-binsem.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-binsem.h" +#include "osapi-binsem-impl.h" #include @@ -193,23 +193,23 @@ void Test_OS_BinSemGetInfo(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-clock.c b/src/unit-test-coverage/shared/src/coveragetest-clock.c index eb8d590a7..f8895a06c 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-clock.c +++ b/src/unit-test-coverage/shared/src/coveragetest-clock.c @@ -13,7 +13,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-clock.h" +#include "osapi-clock-impl.h" void Test_OS_GetLocalTime(void) { @@ -50,23 +50,23 @@ void Test_OS_SetLocalTime(void) UtAssert_True(actual == expected, "OS_SetLocalTime() (%ld) == OS_INVALID_POINTER", (long)actual); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-common.c b/src/unit-test-coverage/shared/src/coveragetest-common.c index b6eeb1ad9..026121ce2 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-common.c +++ b/src/unit-test-coverage/shared/src/coveragetest-common.c @@ -23,7 +23,9 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-common.h" +#include "osapi-common-impl.h" +#include "osapi-task-impl.h" +#include "osapi-timebase-impl.h" #include @@ -262,23 +264,23 @@ void Test_OS_IdleLoopAndShutdown(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-countsem.c b/src/unit-test-coverage/shared/src/coveragetest-countsem.c index 8c3a225d4..11216e749 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-countsem.c +++ b/src/unit-test-coverage/shared/src/coveragetest-countsem.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-countsem.h" +#include "osapi-countsem-impl.h" #include @@ -180,23 +180,23 @@ void Test_OS_CountSemGetInfo(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-dir.c b/src/unit-test-coverage/shared/src/coveragetest-dir.c index 56e88c135..ef3405278 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-dir.c +++ b/src/unit-test-coverage/shared/src/coveragetest-dir.c @@ -13,7 +13,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-dir.h" +#include "osapi-dir-impl.h" /* ********************************************************************************** @@ -180,23 +180,23 @@ void Test_OS_rewinddir(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-errors.c b/src/unit-test-coverage/shared/src/coveragetest-errors.c index 50bff1b66..3a5e96620 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-errors.c +++ b/src/unit-test-coverage/shared/src/coveragetest-errors.c @@ -13,7 +13,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-errors.h" +#include "osapi-errors-impl.h" void Test_OS_GetErrorName(void) { @@ -37,23 +37,23 @@ void Test_OS_GetErrorName(void) UtAssert_True(actual == expected, "OS_GetErrorName(NULL) (%ld) == OS_SUCCESS", (long)actual); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-file.c b/src/unit-test-coverage/shared/src/coveragetest-file.c index feef86180..5dad35b2e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-file.c +++ b/src/unit-test-coverage/shared/src/coveragetest-file.c @@ -23,7 +23,8 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-file.h" +#include "osapi-file-impl.h" +#include "osapi-idmap-impl.h" #include @@ -458,23 +459,25 @@ void Test_OS_ShellOutputToFile(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + memset(OS_stream_table, 0, sizeof(OS_stream_table)); + memset(OS_global_stream_table, 0, sizeof(OS_common_record_t) * OS_MAX_NUM_OPEN_FILES); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-filesys.c b/src/unit-test-coverage/shared/src/coveragetest-filesys.c index e30b38c7b..d1a6375c4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-filesys.c +++ b/src/unit-test-coverage/shared/src/coveragetest-filesys.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-filesys.h" +#include "osapi-filesys-impl.h" #include @@ -525,7 +525,7 @@ void Test_OS_FileSys_FindVirtMountPoint(void) OS_filesys_table[1].flags = 0; OS_filesys_table[1].virtual_mountpt[0] = 0; - result = Osapi_Internal_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (unmounted) == false", refstr); OS_filesys_table[1].flags = OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL; @@ -533,15 +533,15 @@ void Test_OS_FileSys_FindVirtMountPoint(void) /* Verify cases where one is a substring of the other - * these should also return false */ strncpy(OS_filesys_table[1].virtual_mountpt, "/ut11", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = Osapi_Internal_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/u", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = Osapi_Internal_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); UtAssert_True(!result, "OS_FileSys_FindVirtMountPoint(%s) (mountpt=%s) == false", refstr, OS_filesys_table[1].virtual_mountpt); strncpy(OS_filesys_table[1].virtual_mountpt, "/ut", sizeof(OS_filesys_table[1].virtual_mountpt)); - result = Osapi_Internal_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); + result = OS_FileSys_FindVirtMountPoint((void*)refstr, 1, &refobj); UtAssert_True(result, "OS_FileSys_FindVirtMountPoint(%s) (nominal) == true", refstr); } @@ -572,42 +572,42 @@ void Test_OS_FileSys_InitLocalFromVolTable(void) /* this should return OS_ERROR because the mount point was not valid */ memset(&temprec,0,sizeof(temprec)); expected = OS_ERROR; - actual = Osapi_Internal_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[0]); + actual = OS_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[0]); UtAssert_True(actual == expected, "OS_FileSys_InitLocalFromVolTable(0) (%ld) == OS_ERROR", (long)actual); memset(&temprec,0,sizeof(temprec)); expected = OS_SUCCESS; - actual = Osapi_Internal_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[1]); + actual = OS_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[1]); UtAssert_True(actual == expected, "OS_FileSys_InitLocalFromVolTable(1) (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(temprec.fstype == OS_FILESYS_TYPE_MTD, "OS_FileSys_InitLocalFromVolTable(1) fstype(%u) == OS_FILESYS_TYPE_MTD", (unsigned int)temprec.fstype); memset(&temprec,0,sizeof(temprec)); expected = OS_SUCCESS; - actual = Osapi_Internal_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[2]); + actual = OS_FileSys_InitLocalFromVolTable(&temprec, &UT_VOLTAB_TESTCASES[2]); UtAssert_True(actual == expected, "OS_FileSys_InitLocalFromVolTable(1) (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(temprec.fstype == OS_FILESYS_TYPE_VOLATILE_DISK, "OS_FileSys_InitLocalFromVolTable(2) fstype(%u) == OS_FILESYS_TYPE_MTD", (unsigned int)temprec.fstype); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); memset(OS_filesys_table, 0, sizeof(OS_filesys_table)); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-fpu.c b/src/unit-test-coverage/shared/src/coveragetest-fpu.c deleted file mode 100644 index 9d7bd13a4..000000000 --- a/src/unit-test-coverage/shared/src/coveragetest-fpu.c +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osapi-common" file - * - * Notes: - * - */ - - -/* - * Includes - */ - -#include "os-shared-coveragetest.h" -#include "ut-osapi-fpu.h" - -void dummy_fpu_exception_handler(void) -{ -} - -/***************************************************************************** - * - * Test Case for OS_FPUExcAttachHandler() - * int32 OS_FPUExcAttachHandler (uint32 ExceptionNumber, void * ExceptionHandler , - int32 parameter) - * - * - *****************************************************************************/ -void Test_OS_FPUExcAttachHandler(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = OS_FPUExcAttachHandler(1, &dummy_fpu_exception_handler, 0); - - UtAssert_True(actual == expected, "OS_FPUExcAttachHandler() (%ld) == OS_SUCCESS", (long)actual); - - expected = OS_INVALID_POINTER; - actual = OS_FPUExcAttachHandler(1, NULL, 0); - UtAssert_True(actual == expected, "OS_FPUExcAttachHandler() (%ld) == OS_INVALID_POINTER", (long)actual); -} - -/***************************************************************************** - * - * Test Case for OS_FPUExcEnable() - * int32 OS_FPUExcEnable (int32 ExceptionNumber) - * - *****************************************************************************/ -void Test_OS_FPUExcEnable(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = OS_FPUExcEnable(1); - - UtAssert_True(actual == expected, "OS_FPUExcEnable() (%ld) == OS_SUCCESS", (long)actual); -} - -/***************************************************************************** - * - * Test Case for OS_FPUExcDisable() - * int32 OS_FPUExcDisable (int32 ExceptionNumber) - * - *****************************************************************************/ -void Test_OS_FPUExcDisable(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = OS_FPUExcDisable(1); - - UtAssert_True(actual == expected, "OS_FPUExcDisable() (%ld) == OS_SUCCESS", (long)actual); -} - -/***************************************************************************** - * - * Test Case for OS_FPUExcSetMask() - * int32 OS_FPUExcSetMask (uint32 mask) - * - *****************************************************************************/ -void Test_OS_FPUExcSetMask(void) -{ - int32 expected = OS_SUCCESS; - int32 actual = OS_FPUExcSetMask(0x10); - - UtAssert_True(actual == expected, "OS_FPUExcSetMask() (%ld) == OS_SUCCESS", (long)actual); -} - -/***************************************************************************** - * - * Test Case for OS_FPUExcGetMask() - * int32 OS_FPUExcGetMask (uint32 *mask) - * - *****************************************************************************/ -void Test_OS_FPUExcGetMask(void) -{ - uint32 mask; - int32 expected = OS_SUCCESS; - int32 actual = OS_FPUExcGetMask(&mask); - - UtAssert_True(actual == expected, "OS_FPUExcGetMask() (%ld) == OS_SUCCESS", (long)actual); -} - -/* Osapi_Task_Setup - * - * Purpose: - * Called by the unit test tool to set up the app prior to each test - */ -void Osapi_Task_Setup(void) -{ - UT_ResetState(0); -} - -/* - * Osapi_TearDown - * - * Purpose: - * Called by the unit test tool to tear down the app after each test - */ -void Osapi_TearDown(void) -{ - -} - -/* - * Register the test cases to execute with the unit test tool - */ -void UtTest_Setup(void) -{ - ADD_TEST(OS_FPUExcAttachHandler); - ADD_TEST(OS_FPUExcEnable); - ADD_TEST(OS_FPUExcDisable); - ADD_TEST(OS_FPUExcSetMask); - ADD_TEST(OS_FPUExcGetMask); -} - - - - diff --git a/src/unit-test-coverage/shared/src/coveragetest-heap.c b/src/unit-test-coverage/shared/src/coveragetest-heap.c index 2c581b5a4..32551f30e 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-heap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-heap.c @@ -13,7 +13,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-heap.h" +#include "osapi-heap-impl.h" void Test_OS_HeapGetInfo(void) @@ -34,23 +34,23 @@ void Test_OS_HeapGetInfo(void) UtAssert_True(actual == expected, "OS_HeapGetInfo() (%ld) == OS_INVALID_POINTER", (long)actual); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-idmap.c b/src/unit-test-coverage/shared/src/coveragetest-idmap.c index 583a77549..ab6197ef8 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-idmap.c +++ b/src/unit-test-coverage/shared/src/coveragetest-idmap.c @@ -23,7 +23,8 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-idmap.h" +#include "osapi-idmap-impl.h" +#include "osapi-common-impl.h" #include @@ -146,7 +147,7 @@ void Test_OS_ObjectIdConvertLock(void) * Attempt to obtain a lock for the same record with a non-matching ID * This should return an error. */ - actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, + actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, objid + 123, record); expected = OS_ERR_INVALID_ID; @@ -156,7 +157,7 @@ void Test_OS_ObjectIdConvertLock(void) * Use mode OS_LOCK_MODE_NONE with matching ID * This should return success. */ - actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_NONE, + actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_NONE, OS_OBJECT_TYPE_OS_TASK, objid, record); expected = OS_SUCCESS; @@ -168,7 +169,7 @@ void Test_OS_ObjectIdConvertLock(void) */ record->flags = 0; record->refcount = 0; - actual = Osapi_Call_ObjectIdConvertLock(OS_LOCK_MODE_EXCLUSIVE, + actual = OS_ObjectIdConvertLock(OS_LOCK_MODE_EXCLUSIVE, OS_OBJECT_TYPE_OS_TASK, objid, record); expected = OS_SUCCESS; @@ -443,7 +444,7 @@ void Test_OS_ObjectIdFindNext(void) /* Need to first obtain a valid ID to finalize */ expected = OS_SUCCESS; - actual = Osapi_Call_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec1); + actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec1); UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); /* nominal case (success) */ @@ -456,7 +457,7 @@ void Test_OS_ObjectIdFindNext(void) (unsigned long)id1, (unsigned long)rec1->active_id); /* Allocate another ID (should be different!) */ - actual = Osapi_Call_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); + actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(rec2->active_id != rec1->active_id, "OS_ObjectIdFindNext() id (%lx) != %lx", (unsigned long)rec2->active_id, (unsigned long)rec1->active_id); @@ -475,7 +476,7 @@ void Test_OS_ObjectIdFindNext(void) /* next call should re-issue the same id because init failed */ expected = OS_SUCCESS; - actual = Osapi_Call_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); + actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); UtAssert_True(actual == expected, "OS_ObjectIdFindNext() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(rec2->active_id == saved_id, "OS_ObjectIdFindNext() id (%lx) != %lx", (unsigned long)rec2->active_id, (unsigned long)saved_id); @@ -497,7 +498,7 @@ void Test_OS_ObjectIdFindNext(void) saved_id = 0; for (i=0; i < (OS_OBJECT_INDEX_MASK+2); ++i) { - actual = Osapi_Call_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); + actual = OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, NULL, &rec2); /* not usuing UtAssert_True here as it will create thousands of duplicates. */ if (expected != actual) { @@ -558,7 +559,7 @@ void Test_OS_ObjectIdAllocateNew(void) * This test case mainly focuses on additional error checking */ int32 expected = OS_SUCCESS; - int32 actual = ~OS_SUCCESS; //OS_ObjectIdAllocate(); + int32 actual = ~OS_SUCCESS; uint32 objid = 0xFFFFFFFF; OS_common_record_t *rptr = NULL; @@ -604,7 +605,7 @@ void Test_OS_ConvertToArrayIndex(void) OS_common_record_t *rptr = NULL; /* Need a valid ID to work with */ - Osapi_Call_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx1, &rptr); + OS_ObjectIdFindNext(OS_OBJECT_TYPE_OS_TASK, &local_idx1, &rptr); actual = OS_ConvertToArrayIndex(rptr->active_id, &local_idx2); UtAssert_True(actual == expected, "OS_ConvertToArrayIndex() (%ld) == OS_SUCCESS", (long)actual); UtAssert_True(local_idx1 == local_idx1, "local_idx1 (%lu) == local_idx2 (%lu)", @@ -630,7 +631,7 @@ void Test_OS_ForEachObject(void) while (objtype < OS_OBJECT_TYPE_USER) { - Osapi_Call_ObjectIdFindNext(objtype, &local_idx, &rptr); + OS_ObjectIdFindNext(objtype, &local_idx, &rptr); ++objtype; } @@ -644,25 +645,33 @@ void Test_OS_ForEachObject(void) } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + /* for sanity also clear out the task table, which is used by several test cases */ memset(OS_global_task_table, 0, OS_MAX_TASKS * sizeof(OS_common_record_t)); + + /* + * The OS_SharedGlobalVars is also used here, but set the + * "Initialized" field to true by default, as this is needed by most tests. + */ + memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); + OS_SharedGlobalVars.Initialized = true; } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-module.c b/src/unit-test-coverage/shared/src/coveragetest-module.c index e12bf3cde..dad3c4136 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-module.c +++ b/src/unit-test-coverage/shared/src/coveragetest-module.c @@ -23,7 +23,9 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-module.h" +#include "ut-adaptor-module.h" + +#include "osapi-module-impl.h" #include @@ -75,13 +77,17 @@ void Test_OS_ModuleLoad(void) int32 actual = OS_ModuleLoad(&objid, "UT", "File"); UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); + actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); + UtAssert_True(actual == 1, "OS_ModuleLoad_Impl() called (%ld) == 1", (long)actual); UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); - /* for a static module, it should return objid=0 */ + /* for a static module, it should also return a valid objid, but should NOT invoke OS_ModuleLoad_Impl */ actual = OS_ModuleLoad(&objid, "UTS", "File2"); UtAssert_True(actual == expected, "OS_ModuleLoad() (%ld) == OS_SUCCESS", (long)actual); - UtAssert_True(objid == 0, "objid (%lu) == 0", (unsigned long)objid); + actual = UT_GetStubCount(UT_KEY(OS_ModuleLoad_Impl)); + UtAssert_True(actual == 1, "OS_ModuleLoad_Impl() called (%ld) == 1", (long)actual); + UtAssert_True(objid != 0, "objid (%lu) != 0", (unsigned long)objid); /* error cases */ actual = OS_ModuleLoad(NULL,NULL,NULL); @@ -171,23 +177,23 @@ void Test_OS_StaticSymbolLookup(void) cpuaddr addr; /* nominal */ - actual = Osapi_Call_SymbolLookup_Static(&addr, "UT_staticsym"); + actual = OS_SymbolLookup_Static(&addr, "UT_staticsym"); UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s) (%ld) == OS_SUCCESS", "Test_Func1", (long)actual); UtAssert_True(addr == (cpuaddr)&Test_DummyFunc, "OS_SymbolLookup_Static(address=%lx) == %lx", (unsigned long)addr, (unsigned long)&Test_DummyFunc); - actual = Osapi_Call_ModuleLoad_Static("UTS"); + actual = OS_ModuleLoad_Static("UTS"); UtAssert_True(actual == expected, "OS_ModuleLoad_Static(name=%s) (%ld) == OS_SUCCESS", "UT", (long)actual); expected = OS_ERROR; - actual = Osapi_Call_SymbolLookup_Static(&addr, "Invalid"); + actual = OS_SymbolLookup_Static(&addr, "Invalid"); UtAssert_True(actual == expected, "OS_SymbolLookup_Static(name=%s) (%ld) == OS_ERROR", "Invalid", (long)actual); expected = OS_ERR_NAME_NOT_FOUND; - actual = Osapi_Call_ModuleLoad_Static("Invalid"); + actual = OS_ModuleLoad_Static("Invalid"); UtAssert_True(actual == expected, "OS_ModuleLoad_Static(name=%s) (%ld) == OS_SUCCESS", "Invalid", (long)actual); } @@ -254,23 +260,23 @@ void Test_OS_ModuleGetInfo(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-mutex.c b/src/unit-test-coverage/shared/src/coveragetest-mutex.c index 8c49b9d87..f090eb9cd 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-mutex.c +++ b/src/unit-test-coverage/shared/src/coveragetest-mutex.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-mutex.h" +#include "osapi-mutex-impl.h" #include @@ -136,11 +136,11 @@ void Test_OS_MutSemGetInfo(void) { /* * Test Case For: - * int32 OS_MutSemGetInfo (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) + * int32 OS_MutSemGetInfo (uint32 sem_id, OS_mutex_prop_t *mut_prop) */ int32 expected = OS_SUCCESS; int32 actual = ~OS_SUCCESS; - OS_mut_sem_prop_t prop; + OS_mutex_prop_t prop; uint32 local_index = 1; OS_common_record_t utrec; OS_common_record_t *rptr = &utrec; @@ -164,23 +164,23 @@ void Test_OS_MutSemGetInfo(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-network.c b/src/unit-test-coverage/shared/src/coveragetest-network.c index d17ad8426..2aa805b68 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-network.c +++ b/src/unit-test-coverage/shared/src/coveragetest-network.c @@ -13,7 +13,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-network.h" +#include "osapi-network-impl.h" void Test_OS_NetworkAPI_Init(void) @@ -74,23 +74,23 @@ void Test_OS_NetworkGetID (void) UtAssert_True(actual == expected, "OS_NetworkGetID(error) (%ld) == -1", (long)actual); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-printf.c b/src/unit-test-coverage/shared/src/coveragetest-printf.c index a609aaefb..d92c9ae9f 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-printf.c +++ b/src/unit-test-coverage/shared/src/coveragetest-printf.c @@ -23,7 +23,8 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-printf.h" +#include "osapi-printf-impl.h" +#include "osapi-common-impl.h" #include @@ -95,26 +96,27 @@ void Test_OS_printf(void) OS_printf("UnitTest7"); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); memset(OS_console_table, 0, sizeof(OS_console_table)); + memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); OS_console_table[0].BufBase = TestConsoleBuffer; OS_console_table[0].BufSize = sizeof(TestConsoleBuffer); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-queue.c b/src/unit-test-coverage/shared/src/coveragetest-queue.c index e869e18bc..1cc5daf5d 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-queue.c +++ b/src/unit-test-coverage/shared/src/coveragetest-queue.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-queue.h" +#include "osapi-queue-impl.h" #include @@ -193,23 +193,23 @@ void Test_OS_QueueGetInfo(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-select.c b/src/unit-test-coverage/shared/src/coveragetest-select.c index 85f65eeaa..4a094bec2 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-select.c +++ b/src/unit-test-coverage/shared/src/coveragetest-select.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-select.h" +#include "osapi-select-impl.h" #include @@ -119,23 +119,23 @@ void Test_OS_SelectFdAddClearOps(void) UtAssert_True(!OS_SelectFdIsSet(&UtSet, 2), "OS_SelectFdIsSet(2) == false"); } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-sockets.c b/src/unit-test-coverage/shared/src/coveragetest-sockets.c index c7719aa93..18da66c9f 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-sockets.c +++ b/src/unit-test-coverage/shared/src/coveragetest-sockets.c @@ -23,7 +23,9 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-sockets.h" +#include "osapi-sockets-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-file-impl.h" #include @@ -54,19 +56,16 @@ void Test_OS_CreateSocketName(void) * * This focuses on coverage paths, as this function does not return a value */ - OS_stream_internal_record_t testrec; OS_SockAddr_t testaddr; - memset(&testrec, 'x', sizeof(testrec)); - memset(&testaddr, 0, sizeof(testaddr)); UT_SetForceFail(UT_KEY(OS_SocketAddrToString_Impl), OS_ERROR); - Osapi_Call_CreateSocketName_Static(&testrec, &testaddr, "ut"); + OS_CreateSocketName(0, &testaddr, "ut"); /* * The function should have called snprintf() to create the name */ UtAssert_True(UT_GetStubCount(UT_KEY(OCS_snprintf)) == 2, "OS_CreateSocketName() invoked snprintf()"); - UtAssert_True(testrec.stream_name[0] != 'x', "OS_CreateSocketName() set stream name"); + UtAssert_True(OS_stream_table[0].stream_name[0] != 'x', "OS_CreateSocketName() set stream name"); } /***************************************************************************** @@ -455,23 +454,25 @@ void Test_OS_SocketAddr (void) } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + memset(OS_stream_table, 0, sizeof(OS_stream_table)); + memset(OS_global_stream_table, 0, sizeof(OS_common_record_t) * OS_MAX_NUM_OPEN_FILES); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-task.c b/src/unit-test-coverage/shared/src/coveragetest-task.c index add2cff87..020646aa4 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-task.c +++ b/src/unit-test-coverage/shared/src/coveragetest-task.c @@ -23,7 +23,7 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-task.h" +#include "osapi-task-impl.h" #include @@ -298,23 +298,23 @@ void Test_OS_TaskInstallDeleteHandler(void) } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-time.c b/src/unit-test-coverage/shared/src/coveragetest-time.c index b35f76998..eafa03bfa 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-time.c +++ b/src/unit-test-coverage/shared/src/coveragetest-time.c @@ -23,7 +23,9 @@ */ #include "os-shared-coveragetest.h" -#include "ut-osapi-time.h" +#include "osapi-time-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-task-impl.h" #include @@ -319,23 +321,23 @@ void Test_OS_TimerGetInfo(void) } -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/coveragetest-timebase.c b/src/unit-test-coverage/shared/src/coveragetest-timebase.c index b01eda7da..fc499750a 100644 --- a/src/unit-test-coverage/shared/src/coveragetest-timebase.c +++ b/src/unit-test-coverage/shared/src/coveragetest-timebase.c @@ -24,7 +24,10 @@ #include "os-shared-coveragetest.h" -#include "ut-osapi-timebase.h" +#include "osapi-timebase-impl.h" +#include "osapi-time-impl.h" +#include "osapi-task-impl.h" +#include "osapi-common-impl.h" #include @@ -315,23 +318,23 @@ void Test_OS_Milli2Ticks(void) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h index d45952c9f..8baf49fe8 100644 --- a/src/unit-test-coverage/shared/src/os-shared-coveragetest.h +++ b/src/unit-test-coverage/shared/src/os-shared-coveragetest.h @@ -15,7 +15,9 @@ #include #include #include -#include + +//jphfix #include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" /* * Macro to call a function and check its int32 return code @@ -31,17 +33,17 @@ /* * Macro to add a test case to the list of tests to execute */ -#define ADD_TEST(test) UtTest_Add((Test_ ## test),Osapi_Task_Setup,Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test),Osapi_Test_Setup,Osapi_Test_Teardown, #test) /* * Setup function prior to every test */ -void Osapi_Task_Setup(void); +void Osapi_Test_Setup(void); /* * Teardown function after every test */ -void Osapi_TearDown(void); +void Osapi_Test_Teardown(void); #endif diff --git a/src/unit-test-coverage/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/ut-stubs/CMakeLists.txt index aae7fbe9b..a1a26a9c6 100644 --- a/src/unit-test-coverage/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/ut-stubs/CMakeLists.txt @@ -36,6 +36,7 @@ # the OCS functions that are actually used. # add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL + src/bsd-select-stubs.c src/libc-ctype-stubs.c src/libc-stdio-stubs.c src/libc-stdlib-stubs.c @@ -56,6 +57,7 @@ add_library(ut_libc_stubs STATIC EXCLUDE_FROM_ALL src/vxworks-ataDrv-stubs.c src/vxworks-dosFsLib-stubs.c src/vxworks-errnoLib-stubs.c + src/vxworks-hostLib-stubs.c src/vxworks-intLib-stubs.c src/vxworks-loadLib-stubs.c src/vxworks-memPartLib-stubs.c @@ -79,17 +81,36 @@ target_include_directories(ut_libc_stubs PUBLIC # OSAL calls used by or implemented by the shared layer. These # are not public API calls. This is only compiled if used. add_library(ut_osapi_impl_stubs STATIC EXCLUDE_FROM_ALL - src/osapi-base-impl-stubs.c - src/osapi-file-impl-stubs.c - src/osapi-filesys-impl-stubs.c - src/osapi-loader-impl-stubs.c + src/osapi-binsem-impl-stubs.c + src/osapi-common-impl-stubs.c + src/osapi-console-impl-stubs.c + src/osapi-countsem-impl-stubs.c + src/osapi-error-impl-stubs.c + src/osapi-file-impl-stubs.c + src/osapi-filesys-impl-stubs.c + src/osapi-fpu-impl-stubs.c + src/osapi-heap-impl-stubs.c + src/osapi-idmap-impl-stubs.c + src/osapi-loader-impl-stubs.c + src/osapi-mutex-impl-stubs.c src/osapi-network-impl-stubs.c - src/osapi-select-impl-stubs.c - src/osapi-timer-impl-stubs.c) + src/osapi-queue-impl-stubs.c + src/osapi-select-impl-stubs.c + src/osapi-shared-common-stubs.c + src/osapi-shared-debug-stubs.c + src/osapi-shared-idmap-stubs.c + src/osapi-shared-objtable-stubs.c + src/osapi-task-impl-stubs.c + src/osapi-timer-impl-stubs.c +) -list(APPEND OSALCOVERAGE_STUB_LIB_LIST - ut_osapi_impl_stubs - ut_libc_stubs +# The "ut_osapi_shared_stubs" provides stub objects for shared +# objects used by the implementation layer. These +# are not public. This is only compiled if used. +add_library(ut_osapi_shared_stubs STATIC EXCLUDE_FROM_ALL + src/osapi-shared-common-stubs.c + src/osapi-shared-idmap-stubs.c + src/osapi-shared-objtable-stubs.c + src/osapi-shared-debug-stubs.c ) -set(OSALCOVERAGE_STUB_LIB_LIST ${OSALCOVERAGE_STUB_LIB_LIST} PARENT_SCOPE) diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h index c7bed5c4b..8dfbcc6a5 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_hostLib.h @@ -16,7 +16,7 @@ /* ----------------------------------------- */ /* prototypes normally declared in hostLib.h */ /* ----------------------------------------- */ - +extern int OCS_hostGetByName (char *name); #endif /* _OSAL_STUB_HOSTLIB_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h b/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h index 7dbaf15b4..d8249e524 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_symLib.h @@ -19,12 +19,14 @@ /* constants normally defined in symLib.h */ /* ----------------------------------------- */ #define OCS_LOAD_ALL_SYMBOLS 0x1A00 +#define OCS_SYM_FIND_BY_NAME 0x1A01 /* ----------------------------------------- */ /* types normally defined in symLib.h */ /* ----------------------------------------- */ typedef int OCS_SYM_TYPE; - +typedef uintptr_t OCS_SYM_VALUE; +typedef int OCS_SYM_GROUP; typedef struct OCS_SYMBOL OCS_SYMBOL; typedef struct OCS_SYMTAB OCS_SYMTAB; @@ -33,6 +35,15 @@ typedef struct OCS_SYMTAB OCS_SYMTAB; typedef OCS_SYMTAB * OCS_SYMTAB_ID; typedef OCS_SYMBOL * OCS_SYMBOL_ID; +typedef struct OCS_SYMBOL_DESC +{ + unsigned int mask; + char * name; + OCS_SYM_VALUE value; +} OCS_SYMBOL_DESC; + +typedef OCS_BOOL (*OCS_symEach_Routine_t) (char *, OCS_SYM_VALUE, OCS_SYM_TYPE, OCS_Vx_usr_arg_t, OCS_SYM_GROUP); + /* ----------------------------------------- */ /* prototypes normally declared in symLib.h */ /* ----------------------------------------- */ @@ -41,8 +52,8 @@ extern OCS_SYMTAB_ID OCS_sysSymTbl; extern OCS_STATUS OCS_symFindByName(OCS_SYMTAB_ID symTblId, char * name, char ** pValue, OCS_SYM_TYPE * pType); -extern OCS_SYMBOL * OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_FUNCPTR routine, int routineArg); - +extern OCS_SYMBOL * OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_symEach_Routine_t routine, int routineArg); +extern OCS_STATUS OCS_symFind (OCS_SYMTAB_ID symTblId, OCS_SYMBOL_DESC * pSymbol); #endif /* _OSAL_STUB_SYMLIB_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h index 88379430d..4d11a54e7 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_sys_select.h @@ -3,6 +3,7 @@ #define _OSAL_STUB_SYS_SELECT_H_ #include +#include /* ----------------------------------------- */ /* constants normally defined in sys/select.h */ @@ -19,6 +20,10 @@ typedef struct { unsigned int fds; } OCS_fd_set; extern int OCS_select (int nfds, OCS_fd_set * readfds, OCS_fd_set * writefds, OCS_fd_set * exceptfds, struct OCS_timeval * timeout); +extern void OCS_FD_SET(int fd, OCS_fd_set *set); +extern int OCS_FD_ISSET(int fd, OCS_fd_set *set); +extern void OCS_FD_CLR(int fd, OCS_fd_set *set); +extern void OCS_FD_ZERO(OCS_fd_set *set); #endif /* _OSAL_STUB_SYS_SELECT_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h b/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h index c05782245..2ada0f818 100644 --- a/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h +++ b/src/unit-test-coverage/ut-stubs/inc/OCS_vxWorks.h @@ -44,6 +44,8 @@ typedef uint16_t OCS_UINT16; typedef int32_t OCS_INT32; typedef uint32_t OCS_UINT32; +typedef long OCS_Vx_usr_arg_t; + /* Function pointers are used in many VxWorks modules. */ /* * NOTE: The FUNCPTR type in the actual library may be defined diff --git a/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h b/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h index ed34907e1..a532ce9a6 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/hostLib.h @@ -19,6 +19,7 @@ /* ----------------------------------------- */ /* mappings for declarations in hostLib.h */ /* ----------------------------------------- */ +#define hostGetByName OCS_hostGetByName #endif /* _OSAL_OVERRIDE_HOSTLIB_H_ */ diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-common.c b/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h similarity index 55% rename from src/unit-test-coverage/shared/modules/src/ut-osapi-common.c rename to src/unit-test-coverage/ut-stubs/override_inc/selectLib.h index 1c6895c17..c99459c84 100644 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-common.c +++ b/src/unit-test-coverage/ut-stubs/override_inc/selectLib.h @@ -8,13 +8,16 @@ * distributed and modified only according to the terms of that agreement. */ -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-common.h" +/* OSAL coverage stub replacement for selectLib.h */ +#ifndef _OSAL_OVERRIDE_SELECTLIB_H_ +#define _OSAL_OVERRIDE_SELECTLIB_H_ + +#include +#include + +/* ----------------------------------------- */ +/* mappings for declarations in selectLib.h */ +/* ----------------------------------------- */ -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-common.c" +#endif /* _OSAL_OVERRIDE_SELECTLIB_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/symLib.h b/src/unit-test-coverage/ut-stubs/override_inc/symLib.h index 7dcf0784d..75b9dcdf7 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/symLib.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/symLib.h @@ -19,16 +19,21 @@ /* mappings for declarations in symLib.h */ /* ----------------------------------------- */ #define LOAD_ALL_SYMBOLS OCS_LOAD_ALL_SYMBOLS +#define SYM_FIND_BY_NAME OCS_SYM_FIND_BY_NAME #define SYM_TYPE OCS_SYM_TYPE #define SYMTAB OCS_SYMTAB #define SYMBOL OCS_SYMBOL #define SYMTAB_ID OCS_SYMTAB_ID #define SYMBOL_ID OCS_SYMBOL_ID +#define SYMBOL_DESC OCS_SYMBOL_DESC +#define SYM_GROUP OCS_SYM_GROUP +#define SYM_VALUE OCS_SYM_VALUE #define sysSymTbl OCS_sysSymTbl #define symFindByName OCS_symFindByName #define symEach OCS_symEach +#define symFind OCS_symFind #endif /* _OSAL_OVERRIDE_SYMLIB_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h b/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h index aa1168376..56fc06aa1 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/sys/select.h @@ -29,5 +29,9 @@ #define fd_set OCS_fd_set #define select OCS_select +#define FD_SET OCS_FD_SET +#define FD_ISSET OCS_FD_ISSET +#define FD_CLR OCS_FD_CLR +#define FD_ZERO OCS_FD_ZERO #endif /* _OSAL_OVERRIDE_SYS_SELECT_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h b/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h index aef6b0501..1c68559a0 100644 --- a/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h +++ b/src/unit-test-coverage/ut-stubs/override_inc/vxWorks.h @@ -36,6 +36,7 @@ #define INT32 OCS_INT32 #define UINT32 OCS_UINT32 +#define _Vx_usr_arg_t OCS_Vx_usr_arg_t #endif /* _OSAL_OVERRIDE_VXWORKS_H_ */ diff --git a/src/unit-test-coverage/ut-stubs/src/bsd-select-stubs.c b/src/unit-test-coverage/ut-stubs/src/bsd-select-stubs.c new file mode 100644 index 000000000..6848cd21a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/bsd-select-stubs.c @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/* OSAL coverage stub replacement for functions in sys/stat.h */ +#include +#include +#include "utstubs.h" + +#include + +int OCS_select (int nfds, OCS_fd_set * readfds, OCS_fd_set * writefds, OCS_fd_set * exceptfds, struct OCS_timeval * timeout) +{ + return UT_DEFAULT_IMPL_RC(OCS_select, 1); +} + +void OCS_FD_SET(int fd, OCS_fd_set *set) +{ + UT_DEFAULT_IMPL(OCS_FD_SET); +} + +int OCS_FD_ISSET(int fd, OCS_fd_set *set) +{ + return UT_DEFAULT_IMPL(OCS_FD_ISSET); +} + +void OCS_FD_CLR(int fd, OCS_fd_set *set) +{ + UT_DEFAULT_IMPL(OCS_FD_CLR); +} + +void OCS_FD_ZERO(OCS_fd_set *set) +{ + UT_DEFAULT_IMPL(OCS_FD_ZERO); +} + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-base-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-base-impl-stubs.c deleted file mode 100644 index 4a89f2409..000000000 --- a/src/unit-test-coverage/ut-stubs/src/osapi-base-impl-stubs.c +++ /dev/null @@ -1,162 +0,0 @@ -/** - * @file impl-stubs.c - * - * UT assert stubs for low-level implementation functions. - * These are prototyped in the "os-impl.h" file within the shared API - */ - -#include -#include -#include -#include - -#include "utstubs.h" -#include "os-impl.h" - -const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = -{ - { -4444, "UT_ERROR" }, - { 0, NULL } -}; - - -UT_DEFAULT_STUB(OS_API_Impl_Init, (uint32 idtype)) - -void OS_IdleLoop_Impl (void) -{ - UT_DEFAULT_IMPL(OS_IdleLoop_Impl); -} - -void OS_ApplicationShutdown_Impl (void) -{ - UT_DEFAULT_IMPL(OS_ApplicationShutdown_Impl); -} - -/* -** Function prototypes for routines implemented in OS-specific layers -*/ - -/* - * Table locking and unlocking for global objects can be done at the shared code - * layer but the actual implementation is OS-specific - */ -UT_DEFAULT_STUB(OS_Lock_Global_Impl,(uint32 idtype)) -UT_DEFAULT_STUB(OS_Unlock_Global_Impl,(uint32 idtype)) - - - -/* -** Task API -*/ -UT_DEFAULT_STUB(OS_TaskMatch_Impl,(uint32 task_id)) -UT_DEFAULT_STUB(OS_TaskCreate_Impl,(uint32 task_id, uint32 flags)) -UT_DEFAULT_STUB(OS_TaskDelete_Impl,(uint32 task_id)) -void OS_TaskExit_Impl (void) -{ - UT_DEFAULT_IMPL(OS_TaskExit_Impl); -} - -UT_DEFAULT_STUB(OS_TaskDelay_Impl,(uint32 millisecond)) -UT_DEFAULT_STUB(OS_TaskSetPriority_Impl,(uint32 task_id, uint32 new_priority)) -uint32 OS_TaskGetId_Impl (void) -{ - return UT_DEFAULT_IMPL(OS_TaskGetId_Impl); -} -UT_DEFAULT_STUB(OS_TaskGetInfo_Impl,(uint32 task_id, OS_task_prop_t *task_prop)) -UT_DEFAULT_STUB(OS_TaskRegister_Impl,(uint32 global_task_id)) - -/* -** Message Queue API -*/ - -/* -** Queue Create now has the Queue ID returned to the caller. -*/ -UT_DEFAULT_STUB(OS_QueueCreate_Impl,(uint32 queue_id, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueDelete_Impl,(uint32 queue_id)) -UT_DEFAULT_STUB(OS_QueueGet_Impl,(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout)) -UT_DEFAULT_STUB(OS_QueuePut_Impl,(uint32 queue_id, const void *data, uint32 size, uint32 flags)) -UT_DEFAULT_STUB(OS_QueueGetInfo_Impl,(uint32 queue_id, OS_queue_prop_t *queue_prop)) - -/* -** Semaphore API -*/ - -UT_DEFAULT_STUB(OS_BinSemCreate_Impl,(uint32 sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_BinSemFlush_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemGive_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemTake_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl,(uint32 sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_BinSemDelete_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl,(uint32 sem_id, OS_bin_sem_prop_t *bin_prop)) - -UT_DEFAULT_STUB(OS_CountSemCreate_Impl,(uint32 sem_id, uint32 sem_initial_value, uint32 options)) -UT_DEFAULT_STUB(OS_CountSemGive_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemTake_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl,(uint32 sem_id, uint32 msecs)) -UT_DEFAULT_STUB(OS_CountSemDelete_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl,(uint32 sem_id, OS_count_sem_prop_t *count_prop)) - -/* -** Mutex API -*/ - -UT_DEFAULT_STUB(OS_MutSemCreate_Impl,(uint32 sem_id, uint32 options)) -UT_DEFAULT_STUB(OS_MutSemGive_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemTake_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemDelete_Impl,(uint32 sem_id)) -UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl,(uint32 sem_id, OS_mut_sem_prop_t *mut_prop)) - -/* -** Console output API (printf) -*/ -void OS_ConsoleWakeup_Impl(uint32 local_id) -{ - UT_DEFAULT_IMPL(OS_ConsoleWakeup_Impl); -} -int32 OS_ConsoleCreate_Impl(uint32 local_id) -{ - return UT_DEFAULT_IMPL(OS_ConsoleCreate_Impl); -} -void OS_ConsoleOutput_Impl(uint32 local_id) -{ - UT_DEFAULT_IMPL(OS_ConsoleOutput_Impl); -} - -#ifndef OSAL_OMIT_DEPRECATED -/* -** Shared memory API -*/ -UT_DEFAULT_STUB(OS_ShMemInit_Impl,(void)) -UT_DEFAULT_STUB(OS_ShMemCreate_Impl,(uint32 *Id, uint32 NBytes, char* SegName)) -UT_DEFAULT_STUB(OS_ShMemSemTake_Impl,(uint32 Id)) -UT_DEFAULT_STUB(OS_ShMemSemGive_Impl,(uint32 Id)) -UT_DEFAULT_STUB(OS_ShMemAttach_Impl,(uint32 * Address, uint32 Id)) -UT_DEFAULT_STUB(OS_ShMemGetIdByName_Impl,(uint32 *ShMemId, const char *SegName )) -#endif /* OSAL_OMIT_DEPRECATED */ - - -/* -** Call to exit the running application -** Normally embedded applications run forever, but for debugging purposes -** (unit testing for example) this is needed in order to end the test -*/ -void OS_ApplicationExit_Impl(int32 Status) -{ - UT_DEFAULT_IMPL(OS_ApplicationExit_Impl); -} - -/* - * Heap API low-level handler - */ -UT_DEFAULT_STUB(OS_HeapGetInfo_Impl,(OS_heap_prop_t *heap_prop)) - -/* - * FPU API low-level handlers - */ -UT_DEFAULT_STUB(OS_FPUExcAttachHandler_Impl,(uint32 ExceptionNumber, osal_task_entry ExceptionHandler,int32 parameter)) -UT_DEFAULT_STUB(OS_FPUExcEnable_Impl,(int32 ExceptionNumber)) -UT_DEFAULT_STUB(OS_FPUExcDisable_Impl,(int32 ExceptionNumber)) -UT_DEFAULT_STUB(OS_FPUExcSetMask_Impl,(uint32 mask)) -UT_DEFAULT_STUB(OS_FPUExcGetMask_Impl,(uint32 *mask)) - diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c new file mode 100644 index 000000000..dc0f93d73 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-binsem-impl-stubs.c @@ -0,0 +1,29 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-binsem-impl.h" + + +/* +** Semaphore API +*/ + +UT_DEFAULT_STUB(OS_BinSemCreate_Impl,(uint32 sem_id, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_BinSemFlush_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_BinSemGive_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_BinSemTake_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_BinSemTimedWait_Impl,(uint32 sem_id, uint32 msecs)) +UT_DEFAULT_STUB(OS_BinSemDelete_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_BinSemGetInfo_Impl,(uint32 sem_id, OS_bin_sem_prop_t *bin_prop)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c new file mode 100644 index 000000000..11db5b97a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-common-impl-stubs.c @@ -0,0 +1,28 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-common-impl.h" + +UT_DEFAULT_STUB(OS_API_Impl_Init, (uint32 idtype)) + +void OS_IdleLoop_Impl (void) +{ + UT_DEFAULT_IMPL(OS_IdleLoop_Impl); +} + +void OS_ApplicationShutdown_Impl (void) +{ + UT_DEFAULT_IMPL(OS_ApplicationShutdown_Impl); +} + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c new file mode 100644 index 000000000..ab5a8172f --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-console-impl-stubs.c @@ -0,0 +1,32 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-printf-impl.h" + +/* +** Console output API (printf) +*/ +void OS_ConsoleWakeup_Impl(uint32 local_id) +{ + UT_DEFAULT_IMPL(OS_ConsoleWakeup_Impl); +} +int32 OS_ConsoleCreate_Impl(uint32 local_id) +{ + return UT_DEFAULT_IMPL(OS_ConsoleCreate_Impl); +} +void OS_ConsoleOutput_Impl(uint32 local_id) +{ + UT_DEFAULT_IMPL(OS_ConsoleOutput_Impl); +} + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c new file mode 100644 index 000000000..1f8e016ab --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-countsem-impl-stubs.c @@ -0,0 +1,27 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-countsem-impl.h" + +/* +** Semaphore API +*/ + +UT_DEFAULT_STUB(OS_CountSemCreate_Impl,(uint32 sem_id, uint32 sem_initial_value, uint32 options)) +UT_DEFAULT_STUB(OS_CountSemGive_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_CountSemTake_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_CountSemTimedWait_Impl,(uint32 sem_id, uint32 msecs)) +UT_DEFAULT_STUB(OS_CountSemDelete_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_CountSemGetInfo_Impl,(uint32 sem_id, OS_count_sem_prop_t *count_prop)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-error-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-error-impl-stubs.c new file mode 100644 index 000000000..62ee6d973 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-error-impl-stubs.c @@ -0,0 +1,22 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-errors-impl.h" + +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = +{ + { -4444, "UT_ERROR" }, + { 0, NULL } +}; + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c index 4b03e7f79..c5439d530 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-file-impl-stubs.c @@ -11,7 +11,9 @@ #include #include "utstubs.h" -#include "os-impl.h" + +#include "osapi-file-impl.h" +#include "osapi-dir-impl.h" /* diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c index 2863e056d..ea227373f 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-filesys-impl-stubs.c @@ -11,7 +11,7 @@ #include #include "utstubs.h" -#include "os-impl.h" +#include "osapi-filesys-impl.h" /* * File system abstraction layer diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-fpu-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-fpu-impl-stubs.c new file mode 100644 index 000000000..3733b0f00 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-fpu-impl-stubs.c @@ -0,0 +1,25 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-fpu-impl.h" + +/* + * FPU API low-level handlers + */ +UT_DEFAULT_STUB(OS_FPUExcAttachHandler_Impl,(uint32 ExceptionNumber, osal_task_entry ExceptionHandler,int32 parameter)) +UT_DEFAULT_STUB(OS_FPUExcEnable_Impl,(int32 ExceptionNumber)) +UT_DEFAULT_STUB(OS_FPUExcDisable_Impl,(int32 ExceptionNumber)) +UT_DEFAULT_STUB(OS_FPUExcSetMask_Impl,(uint32 mask)) +UT_DEFAULT_STUB(OS_FPUExcGetMask_Impl,(uint32 *mask)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c new file mode 100644 index 000000000..f15d9d90a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-heap-impl-stubs.c @@ -0,0 +1,20 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-heap-impl.h" + +/* + * Heap API low-level handler + */ +UT_DEFAULT_STUB(OS_HeapGetInfo_Impl,(OS_heap_prop_t *heap_prop)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c new file mode 100644 index 000000000..2a3b2653e --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-idmap-impl-stubs.c @@ -0,0 +1,24 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-idmap-impl.h" + +/* + * Table locking and unlocking for global objects can be done at the shared code + * layer but the actual implementation is OS-specific + */ +UT_DEFAULT_STUB(OS_Lock_Global_Impl,(uint32 idtype)) +UT_DEFAULT_STUB(OS_Unlock_Global_Impl,(uint32 idtype)) + + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c index 8e9a4aa9e..97a0148e1 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-loader-impl-stubs.c @@ -11,7 +11,7 @@ #include #include "utstubs.h" -#include "os-impl.h" +#include "osapi-module-impl.h" /* diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c new file mode 100644 index 000000000..8c678e9bf --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-mutex-impl-stubs.c @@ -0,0 +1,27 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-mutex-impl.h" + + +/* +** Mutex API +*/ + +UT_DEFAULT_STUB(OS_MutSemCreate_Impl,(uint32 sem_id, uint32 options)) +UT_DEFAULT_STUB(OS_MutSemGive_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_MutSemTake_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_MutSemDelete_Impl,(uint32 sem_id)) +UT_DEFAULT_STUB(OS_MutSemGetInfo_Impl,(uint32 sem_id, OS_mutex_prop_t *mut_prop)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c index cede63bdb..1b7e4a43e 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-network-impl-stubs.c @@ -11,7 +11,8 @@ #include #include "utstubs.h" -#include "os-impl.h" +#include "osapi-network-impl.h" +#include "osapi-sockets-impl.h" /* * Sockets API abstraction layer diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c new file mode 100644 index 000000000..684e04c85 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-queue-impl-stubs.c @@ -0,0 +1,26 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-queue-impl.h" + +/* +** Message Queue API +*/ + +UT_DEFAULT_STUB(OS_QueueCreate_Impl,(uint32 queue_id, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueDelete_Impl,(uint32 queue_id)) +UT_DEFAULT_STUB(OS_QueueGet_Impl,(uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout)) +UT_DEFAULT_STUB(OS_QueuePut_Impl,(uint32 queue_id, const void *data, uint32 size, uint32 flags)) +UT_DEFAULT_STUB(OS_QueueGetInfo_Impl,(uint32 queue_id, OS_queue_prop_t *queue_prop)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c index 120b59579..c9edca2ec 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-select-impl-stubs.c @@ -11,7 +11,7 @@ #include #include "utstubs.h" -#include "os-impl.h" +#include "osapi-select-impl.h" UT_DEFAULT_STUB(OS_SelectSingle_Impl,(uint32 stream_id, uint32 *SelectFlags, int32 msecs)) UT_DEFAULT_STUB(OS_SelectMultiple_Impl,(OS_FdSet *ReadSet, OS_FdSet *WriteSet, int32 msecs)) diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-common-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-common-stubs.c new file mode 100644 index 000000000..53db602f6 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-common-stubs.c @@ -0,0 +1,28 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include "osapi-common-impl.h" + +OS_SharedGlobalVars_t OS_SharedGlobalVars; + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c new file mode 100644 index 000000000..11622ecee --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-debug-stubs.c @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2004-2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file osapi-shared-debug.c + * + * Created on: April 20, 2020 + * Author: joseph.p.hickey@nasa.gov + * + * Stub implementations for the functions defined in the OSAL API + */ + +#include "osapi-shared-globaldefs.h" + +/***************************************************************************** + * + * Stub function for OS_DebugPrintf() + * This is only relevant when building OSAL with OSAL_CONFIG_DEBUG_PRINTF enabled + * + *****************************************************************************/ +void OS_DebugPrintf(uint32 Level, const char *Func, uint32 Line, const char *Format, ...) +{ +} diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-stubs.c new file mode 100644 index 000000000..660fc265a --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-idmap-stubs.c @@ -0,0 +1,51 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include "osapi-idmap-impl.h" + +OS_common_record_t OS_stub_task_table[OS_MAX_TASKS]; +OS_common_record_t OS_stub_queue_table[OS_MAX_QUEUES]; +OS_common_record_t OS_stub_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; +OS_common_record_t OS_stub_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; +OS_common_record_t OS_stub_mutex_table[OS_MAX_MUTEXES]; +OS_common_record_t OS_stub_console_table[OS_MAX_CONSOLES]; +OS_common_record_t OS_stub_module_table[OS_MAX_MODULES]; +OS_common_record_t OS_stub_filesys_table[OS_MAX_FILE_SYSTEMS]; +OS_common_record_t OS_stub_timebase_table[OS_MAX_TIMEBASES]; +OS_common_record_t OS_stub_timecb_table[OS_MAX_TIMERS]; +OS_common_record_t OS_stub_stream_table[OS_MAX_NUM_OPEN_FILES]; +OS_common_record_t OS_stub_dir_table[OS_MAX_NUM_OPEN_DIRS]; + +OS_common_record_t * const OS_global_task_table = OS_stub_task_table; +OS_common_record_t * const OS_global_queue_table = OS_stub_queue_table; +OS_common_record_t * const OS_global_bin_sem_table = OS_stub_bin_sem_table; +OS_common_record_t * const OS_global_count_sem_table = OS_stub_count_sem_table; +OS_common_record_t * const OS_global_mutex_table = OS_stub_mutex_table; +OS_common_record_t * const OS_global_stream_table = OS_stub_stream_table; +OS_common_record_t * const OS_global_dir_table = OS_stub_dir_table; +OS_common_record_t * const OS_global_timebase_table = OS_stub_timebase_table; +OS_common_record_t * const OS_global_timecb_table = OS_stub_timecb_table; +OS_common_record_t * const OS_global_module_table = OS_stub_module_table; +OS_common_record_t * const OS_global_filesys_table = OS_stub_filesys_table; +OS_common_record_t * const OS_global_console_table = OS_stub_console_table; diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-shared-objtable-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-shared-objtable-stubs.c new file mode 100644 index 000000000..1745ef7be --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-shared-objtable-stubs.c @@ -0,0 +1,60 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include "osapi-binsem-impl.h" +#include "osapi-clock-impl.h" +#include "osapi-countsem-impl.h" +#include "osapi-dir-impl.h" +#include "osapi-errors-impl.h" +#include "osapi-file-impl.h" +#include "osapi-filesys-impl.h" +#include "osapi-fpu-impl.h" +#include "osapi-heap-impl.h" +#include "osapi-idmap-impl.h" +#include "osapi-interrupts-impl.h" +#include "osapi-module-impl.h" +#include "osapi-mutex-impl.h" +#include "osapi-network-impl.h" +#include "osapi-printf-impl.h" +#include "osapi-queue-impl.h" +#include "osapi-select-impl.h" +#include "osapi-sockets-impl.h" +#include "osapi-task-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-time-impl.h" + + +OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; +OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; +OS_bin_sem_internal_record_t OS_bin_sem_table[OS_MAX_BIN_SEMAPHORES]; +OS_count_sem_internal_record_t OS_count_sem_table[OS_MAX_COUNT_SEMAPHORES]; +OS_mutex_internal_record_t OS_mutex_table[OS_MAX_MUTEXES]; +OS_stream_internal_record_t OS_stream_table[OS_MAX_NUM_OPEN_FILES]; +OS_dir_internal_record_t OS_dir_table[OS_MAX_NUM_OPEN_DIRS]; +OS_timebase_internal_record_t OS_timebase_table[OS_MAX_TIMEBASES]; +OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; +OS_module_internal_record_t OS_module_table[OS_MAX_MODULES]; +OS_filesys_internal_record_t OS_filesys_table[OS_MAX_FILE_SYSTEMS]; +OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c new file mode 100644 index 000000000..ead5e7345 --- /dev/null +++ b/src/unit-test-coverage/ut-stubs/src/osapi-task-impl-stubs.c @@ -0,0 +1,37 @@ +/** + * @file impl-stubs.c + * + * UT assert stubs for low-level implementation functions. + * These are prototyped in the "os-impl.h" file within the shared API + */ + +#include +#include +#include +#include + +#include "utstubs.h" + +#include "osapi-task-impl.h" + + +/* +** Task API +*/ +UT_DEFAULT_STUB(OS_TaskMatch_Impl,(uint32 task_id)) +UT_DEFAULT_STUB(OS_TaskCreate_Impl,(uint32 task_id, uint32 flags)) +UT_DEFAULT_STUB(OS_TaskDelete_Impl,(uint32 task_id)) +void OS_TaskExit_Impl (void) +{ + UT_DEFAULT_IMPL(OS_TaskExit_Impl); +} + +UT_DEFAULT_STUB(OS_TaskDelay_Impl,(uint32 millisecond)) +UT_DEFAULT_STUB(OS_TaskSetPriority_Impl,(uint32 task_id, uint32 new_priority)) +uint32 OS_TaskGetId_Impl (void) +{ + return UT_DEFAULT_IMPL(OS_TaskGetId_Impl); +} +UT_DEFAULT_STUB(OS_TaskGetInfo_Impl,(uint32 task_id, OS_task_prop_t *task_prop)) +UT_DEFAULT_STUB(OS_TaskRegister_Impl,(uint32 global_task_id)) + diff --git a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c index 6f32980ee..eeb430be1 100644 --- a/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/osapi-timer-impl-stubs.c @@ -11,7 +11,8 @@ #include #include "utstubs.h" -#include "os-impl.h" +#include "osapi-timebase-impl.h" +#include "osapi-clock-impl.h" /* ** OS Time/Tick related API diff --git a/src/unit-test-coverage/shared/modules/src/ut-osapi-fpu.c b/src/unit-test-coverage/ut-stubs/src/vxworks-hostLib-stubs.c similarity index 65% rename from src/unit-test-coverage/shared/modules/src/ut-osapi-fpu.c rename to src/unit-test-coverage/ut-stubs/src/vxworks-hostLib-stubs.c index 83a6f8074..06c62a4de 100644 --- a/src/unit-test-coverage/shared/modules/src/ut-osapi-fpu.c +++ b/src/unit-test-coverage/ut-stubs/src/vxworks-hostLib-stubs.c @@ -8,13 +8,14 @@ * distributed and modified only according to the terms of that agreement. */ -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi-fpu.h" +/* OSAL coverage stub replacement for hostLib.h */ +#include +#include +#include "utstubs.h" -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi-fpu.c" +#include +int OCS_hostGetByName (char *name) +{ + return (UT_DEFAULT_IMPL(OCS_hostGetByName)); +} diff --git a/src/unit-test-coverage/ut-stubs/src/vxworks-symLib-stubs.c b/src/unit-test-coverage/ut-stubs/src/vxworks-symLib-stubs.c index 651ce4dc5..a6656005e 100644 --- a/src/unit-test-coverage/ut-stubs/src/vxworks-symLib-stubs.c +++ b/src/unit-test-coverage/ut-stubs/src/vxworks-symLib-stubs.c @@ -34,7 +34,8 @@ OCS_STATUS OCS_symFindByName(OCS_SYMTAB_ID symTblId, char * name, char ** pValue { return (UT_DEFAULT_IMPL(OCS_symFindByName)); } -OCS_SYMBOL * OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_FUNCPTR routine, int routineArg) + +OCS_SYMBOL * OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_symEach_Routine_t routine, int routineArg) { int32 Status; OCS_SYMBOL *retval; @@ -52,3 +53,16 @@ OCS_SYMBOL * OCS_symEach(OCS_SYMTAB_ID symTblId, OCS_FUNCPTR routine, int routin return retval; } +OCS_STATUS OCS_symFind (OCS_SYMTAB_ID symTblId, OCS_SYMBOL_DESC * pSymbol) +{ + int32 Status; + + Status = UT_DEFAULT_IMPL(OCS_symFind); + if (Status == 0 && UT_Stub_CopyToLocal(UT_KEY(OCS_symFind), pSymbol, sizeof(*pSymbol)) < sizeof(*pSymbol)) + { + memset(pSymbol,0, sizeof(*pSymbol)); + } + + return Status; +} + diff --git a/src/unit-test-coverage/vxworks/CMakeLists.txt b/src/unit-test-coverage/vxworks/CMakeLists.txt index 7a1041de5..98b33b6de 100644 --- a/src/unit-test-coverage/vxworks/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/CMakeLists.txt @@ -1,24 +1,75 @@ # CMake snippet for building the shared OSAL layer coverage tests -set(MODULE_LIST osapi osfileapi osfilesys osloader osnetwork osselect ostimer posixio posixfile posixgettime printf) +set(VXWORKS_MODULE_LIST + binsem + common + console + countsem + dirs + files + filesys + idmap + heap + loader + mutex + network + queues + shell + symtab + tasks + timebase +) + +set(VXWORKS_PORTABLE_BLOCK_LIST + posix-gettime + posix-io + posix-files + + #console-bsp + bsd-select + #bsd-sockets + + no-loader + #no-symtab + #no-network + #no-sockets +) + + # This unit test is allowed to directly include any internal file in # the respective set under test. -include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/modules/inc) +include_directories(${OSAL_SOURCE_DIR}/src/os/${SETNAME}/inc) # The "ut-stubs" contains additional stubs specific to this sub-module add_subdirectory(ut-stubs) +add_subdirectory(adaptors) -# the "modules" contains wrappers around the actual module under test -# (this is not a stub, this is the real code) -add_subdirectory(modules) - -set(MODULE_LINK_MAP_posixio osfileapi) -set(MODULE_LINK_MAP_posixfile osfileapi) -set(MODULE_LINK_MAP_printf osapi) -set(MODULE_LINK_MAP_posixgettime ostimer) +set(VXWORKS_COVERAGE_LINK_LIST + ut-adaptor-vxworks + ut_vxworks_impl_stubs + ut_osapi_impl_stubs + ut_osapi_shared_stubs + ut_osapi_stubs + ut_libc_stubs +) # Add all coverage tests in the src dir -add_coverage_tests(${SETNAME} ${MODULE_LIST}) +foreach(MODNAME ${VXWORKS_MODULE_LIST}) + add_coverage_testrunner( + "coverage-${SETNAME}-${MODNAME}" + "${OSAL_SOURCE_DIR}/src/os/${SETNAME}/src/os-impl-${MODNAME}.c" + "${CMAKE_CURRENT_SOURCE_DIR}/src/coveragetest-${MODNAME}.c" + ${VXWORKS_COVERAGE_LINK_LIST} + ) +endforeach(MODNAME ${VXWORKS_MODULE_LIST}) + +foreach(MODNAME ${VXWORKS_PORTABLE_BLOCK_LIST}) + add_coverage_testrunner( + "coverage-${SETNAME}-${MODNAME}" + "${OSAL_SOURCE_DIR}/src/os/portable/os-impl-${MODNAME}.c" + "${OSALCOVERAGE_SOURCE_DIR}/portable/src/coveragetest-${MODNAME}.c" + ${VXWORKS_COVERAGE_LINK_LIST} + ) +endforeach(MODNAME ${VXWORKS_PORTABLE_BLOCK_LIST}) diff --git a/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt new file mode 100644 index 000000000..2d67f51f8 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/CMakeLists.txt @@ -0,0 +1,50 @@ +# +# Copyright (c) 2019, United States government as represented by the +# administrator of the National Aeronautics Space Administration. +# All rights reserved. This software was created at NASA Goddard +# Space Flight Center pursuant to government contracts. +# +# This is governed by the NASA Open Source Agreement and may be used, +# distributed and modified only according to the terms of that agreement. +# + + +# "Adaptors" help enable the unit test code to reach functions/objects that +# are otherwise not exposed. This is generally required for any OSAL subsystem +# which tracks an internal resource state (i.e. anything with a table). + +# NOTE: These source files are compile with OVERRIDES on the headers just like +# the FSW code is compiled. This is how it is able to include internal headers +# which otherwise would fail. But that also means that adaptor code cannot call +# any library functions, as this would also reach a stub, not the real function. + +add_library(ut-adaptor-${SETNAME} STATIC + src/ut-adaptor-binsem.c + src/ut-adaptor-common.c + src/ut-adaptor-console.c + src/ut-adaptor-countsem.c + src/ut-adaptor-dirs.c + src/ut-adaptor-files.c + src/ut-adaptor-filesys.c + src/ut-adaptor-idmap.c + src/ut-adaptor-loader.c + src/ut-adaptor-mutex.c + src/ut-adaptor-queues.c + src/ut-adaptor-filetable-stub.c + src/ut-adaptor-symtab.c + src/ut-adaptor-tasks.c + src/ut-adaptor-timebase.c + + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/src/ut-adaptor-portable-posix-io.c + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/src/ut-adaptor-portable-posix-files.c +) + +# the "override_inc" dir contains replacement versions of the C-library include files. +target_include_directories(ut-adaptor-${SETNAME} PRIVATE + ${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc +) + +target_include_directories(ut-adaptor-${SETNAME} PUBLIC + ${OSALCOVERAGE_SOURCE_DIR}/portable/adaptors/inc + ${CMAKE_CURRENT_SOURCE_DIR}/inc +) diff --git a/src/unit-test-coverage/shared/modules/Makefile b/src/unit-test-coverage/vxworks/adaptors/Makefile similarity index 100% rename from src/unit-test-coverage/shared/modules/Makefile rename to src/unit-test-coverage/vxworks/adaptors/Makefile diff --git a/src/unit-test-coverage/shared/modules/README.txt b/src/unit-test-coverage/vxworks/adaptors/README.txt similarity index 100% rename from src/unit-test-coverage/shared/modules/README.txt rename to src/unit-test-coverage/vxworks/adaptors/README.txt diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h new file mode 100644 index 000000000..ac56742d6 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-binsem.h @@ -0,0 +1,47 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_BINSEM_H_ +#define _UT_ADAPTOR_BINSEM_H_ + +#include +#include +#include +#include + + +extern void* const UT_Ref_OS_impl_bin_sem_table; +extern size_t const UT_Ref_OS_impl_bin_sem_table_SIZE; + +/* + * This also needs to expose the keys for the stubs to + * helper functions that the test case needs to configure. + * + * This is because the test case cannot directly include + * the internal header file which provides this API. + */ +extern const UT_EntryKey_t UT_StubKey_GenericSemTake; +extern const UT_EntryKey_t UT_StubKey_GenericSemGive; + +extern int32 UT_Call_OS_VxWorks_BinSemAPI_Impl_Init(void); + +#endif /* _UT_ADAPTOR_BINSEM_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h new file mode 100644 index 000000000..b8e6c434e --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-common.h @@ -0,0 +1,53 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-common.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_COMMON_H_ +#define _UT_ADAPTOR_COMMON_H_ + +#include +#include +#include + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not part of the implementation API. + * + *****************************************************/ + +void UT_CommonTest_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid); + +extern int32 OS_VxWorks_GenericSemTake(OCS_SEM_ID vxid, int sys_ticks); +extern int32 OS_VxWorks_GenericSemGive(OCS_SEM_ID vxid); + +/* + * This also needs to expose the keys for the stubs to + * helper functions that the test case needs to configure. + * + * This is because the test case cannot directly include + * the internal header file which provides this API. + */ +extern const UT_EntryKey_t UT_StubKey_OS_VxWorks_TableMutex_Init; + +#endif /* _UT_ADAPTOR_COMMON_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h new file mode 100644 index 000000000..74eec8855 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-console.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_CONSOLE_H_ +#define _UT_ADAPTOR_CONSOLE_H_ + +#include +#include "ut-adaptor-common.h" + +extern void* const UT_Ref_OS_impl_console_table; +extern size_t const UT_Ref_OS_impl_console_table_SIZE; + + +/** + * Invokes the console helper task entry point + */ +extern void UT_ConsoleTest_TaskEntry(int arg); + +/** + * Force the "is_async" field to a given state for coverage testing + */ +extern void UT_ConsoleTest_SetConsoleAsync(uint32 local_id, bool is_async); + + + +#endif /* _UT_ADAPTOR_CONSOLE_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h new file mode 100644 index 000000000..60364884c --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-countsem.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-countsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_COUNTSEM_H_ +#define _UT_ADAPTOR_COUNTSEM_H_ + +#include +#include +#include + +extern void* const UT_Ref_OS_impl_count_sem_table; +extern size_t const UT_Ref_OS_impl_count_sem_table_SIZE; + + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ + +int32 UT_Call_OS_VxWorks_CountSemAPI_Impl_Init(void); + +#endif /* _UT_ADAPTOR_COUNTSEM_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h new file mode 100644 index 000000000..9dd48c0d7 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-dirs.h @@ -0,0 +1,43 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _OSAL_UT_OSFILEAPI_H_ +#define _OSAL_UT_OSFILEAPI_H_ + +#include + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ + + +/* + * Prototype for table init function (needs to be called from UT) + */ +extern int32 UT_Call_OS_VxWorks_DirAPI_Impl_Init(void); + +#endif /* _UT_OSFILEAPI_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h new file mode 100644 index 000000000..0558a69b5 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-files.h @@ -0,0 +1,54 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_OSFILEAPI_H_ +#define _UT_OSFILEAPI_H_ + +#include + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ + + +/* + * Prototype for table init function (needs to be called from UT) + */ +extern int32 UT_Call_OS_VxWorks_StreamAPI_Impl_Init(void); + +/* + * Allow UT to get the value of the OS_IMPL_SELF_EUID and + * OS_IMPL_SELF_EGID constants. These might be assigned + * at runtime by the init function (above) or they might be + * defined at compile time. + */ +unsigned int UT_FileTest_GetSelfEUID(void); +unsigned int UT_FileTest_GetSelfEGID(void); + +void UT_FileTest_Set_Selectable(uint32 local_id, bool is_selectable); + +#endif /* _UT_OSFILEAPI_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h new file mode 100644 index 000000000..7c1882e0a --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filesys.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfilesys.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_OSFILESYS_H_ +#define _UT_OSFILESYS_H_ + +#include +#include + +extern void* const UT_Ref_OS_impl_filesys_table; +extern size_t const UT_Ref_OS_impl_filesys_table_SIZE; + + +void UT_FileSysTest_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts); + + + + +#endif /* _UT_OSFILESYS_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h new file mode 100644 index 000000000..651058865 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-filetable-stub.h @@ -0,0 +1,35 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_SHELL_H_ +#define _UT_ADAPTOR_SHELL_H_ + +#include +#include + + +extern void* const UT_FileTableTest_OS_impl_filehandle_table; +extern size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE; + + + +#endif /* _UT_ADAPTOR_SHELL_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h new file mode 100644 index 000000000..799e8acdd --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-idmap.h @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-idmap.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_IDMAP_H_ +#define _UT_ADAPTOR_IDMAP_H_ + +#include +#include + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not part of the implementation API. + * + *****************************************************/ +int32 UT_Call_OS_VxWorks_TableMutex_Init(uint32 idtype); +void UT_IdMapTest_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid); + + +#endif /* _UT_ADAPTOR_IDMAP_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h new file mode 100644 index 000000000..b9b67289b --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-loader.h @@ -0,0 +1,37 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_LOADER_H_ +#define _UT_ADAPTOR_LOADER_H_ + +#include +#include +#include +#include + + +extern void* const UT_Ref_OS_impl_module_table; +extern size_t const UT_Ref_OS_impl_module_table_SIZE; + +extern int32 UT_Call_OS_VxWorks_ModuleAPI_Impl_Init(void); + +#endif /* _UT_ADAPTOR_LOADER_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h new file mode 100644 index 000000000..697912e1a --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-mutex.h @@ -0,0 +1,46 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-mutex.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_MUTEX_H_ +#define _UT_ADAPTOR_MUTEX_H_ + +#include +#include +#include + +extern void* const UT_Ref_OS_impl_mutex_table; +extern size_t const UT_Ref_OS_impl_mutex_table_SIZE; + + + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ + +int32 UT_Call_OS_VxWorks_MutexAPI_Impl_Init(void); + +#endif /* _UT_ADAPTOR_MUTEX_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h new file mode 100644 index 000000000..b8f765837 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-queues.h @@ -0,0 +1,45 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-queues.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_QUEUES_H_ +#define _UT_ADAPTOR_QUEUES_H_ + +#include +#include + +extern void* const UT_Ref_OS_impl_queue_table; +extern size_t const UT_Ref_OS_impl_queue_table_SIZE; + + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not part of the implementation API. + * + *****************************************************/ + +int32 UT_Call_OS_VxWorks_QueueAPI_Impl_Init(void); + + +#endif /* _UT_ADAPTOR_QUEUES_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h new file mode 100644 index 000000000..1be9b82b4 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-symtab.h @@ -0,0 +1,32 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-binsem.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_SYMTAB_H_ +#define _UT_ADAPTOR_SYMTAB_H_ + +#include + + +/* jphfix - should be symtab */ +int32 UT_SymTabTest_CallIteratorFunc(const char *name, void* val, uint32 TestSize, uint32 SizeLimit); + +#endif /* _UT_ADAPTOR_SYMTAB_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h new file mode 100644 index 000000000..cd5d6b49f --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-tasks.h @@ -0,0 +1,48 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-tasks.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_ADAPTOR_TASKS_H_ +#define _UT_ADAPTOR_TASKS_H_ + +#include +#include + +extern void* const UT_Ref_OS_impl_task_table; +extern size_t const UT_Ref_OS_impl_task_table_SIZE; + + +/***************************************************** + * + * UT FUNCTION PROTOTYPES + * + * These are functions that need to be invoked by UT + * but are not exposed directly through the implementation API. + * + *****************************************************/ + +int32 UT_Call_OS_VxWorks_TaskAPI_Impl_Init(void); +void UT_TaskTest_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId); +int UT_TaskTest_CallEntryPoint(int arg); +OCS_WIND_TCB* UT_TaskTest_GetTaskTcb(uint32 local_id); + + +#endif /* _UT_ADAPTOR_TASKS_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h new file mode 100644 index 000000000..ac1e0029c --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/inc/ut-adaptor-timebase.h @@ -0,0 +1,61 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-ostimer.h + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +#ifndef _UT_OSTIMER_H_ +#define _UT_OSTIMER_H_ + +#include +#include +#include + +extern void* const UT_Ref_OS_impl_timebase_table; +extern size_t const UT_Ref_OS_impl_timebase_table_SIZE; + + +int32 UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(void); + +void UT_TimeBaseTest_Setup(uint32 local_id, int signo, bool reset_flag); + +/** + * Invokes OS_VxWorks_SigWait() with the given arguments. + * This is normally a static function but exposed via a non-static wrapper for UT purposes. + */ +int32 UT_TimeBaseTest_CallSigWaitFunc(uint32 local_id); + +/* Invokes the static OS_VxWorks_TimeBaseTask() function with given argument */ +int UT_TimeBaseTest_CallHelperTaskFunc(int arg); + +/* Invokes the static OS_VxWorks_RegisterTimer() function with given argument */ +void UT_TimeBaseTest_CallRegisterTimer(uint32 local_id); + +/* Hook functions which set the timer registration state */ +void UT_TimeBaseTest_SetTimeBaseRegState(uint32 local_id, bool is_success); +void UT_TimeBaseTest_ClearTimeBaseRegState(uint32 local_id); + +/* Hook functions which test the timer registration state */ +bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(uint32 local_id); +bool UT_TimeBaseTest_CheckTimeBaseErrorState(uint32 local_id); + +/* Invoke the internal UsecToTimespec API */ +void UT_TimeBaseTest_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec); + +#endif /* _UT_OSTIMER_H_ */ + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-binsem.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-binsem.c new file mode 100644 index 000000000..8ad8c083e --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-binsem.c @@ -0,0 +1,41 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-binsem.h" + +#include +#include + + +void* const UT_Ref_OS_impl_bin_sem_table = OS_impl_bin_sem_table; +size_t const UT_Ref_OS_impl_bin_sem_table_SIZE = sizeof(OS_impl_bin_sem_table); + +const UT_EntryKey_t UT_StubKey_GenericSemTake = UT_KEY(OS_VxWorks_GenericSemTake); +const UT_EntryKey_t UT_StubKey_GenericSemGive = UT_KEY(OS_VxWorks_GenericSemGive); + +int32 UT_Call_OS_VxWorks_BinSemAPI_Impl_Init(void) +{ + return OS_VxWorks_BinSemAPI_Impl_Init(); +} + + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c new file mode 100644 index 000000000..c47a2ad9a --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-common.c @@ -0,0 +1,31 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include +#include +#include + +#include +#include "ut-adaptor-common.h" + +const UT_EntryKey_t UT_StubKey_OS_VxWorks_TableMutex_Init = UT_KEY(OS_VxWorks_TableMutex_Init); + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c new file mode 100644 index 000000000..f8e800b1b --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-console.c @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-console.h" + +#include +#include + +void* const UT_Ref_OS_impl_console_table = OS_impl_console_table; +size_t const UT_Ref_OS_impl_console_table_SIZE = sizeof(OS_impl_console_table); + +void UT_ConsoleTest_TaskEntry(int arg) +{ + OS_VxWorks_ConsoleTask_Entry(arg); +} + +void UT_ConsoleTest_SetConsoleAsync(uint32 local_id, bool is_async) +{ + OS_impl_console_table[local_id].is_async = is_async; +} diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-countsem.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-countsem.c new file mode 100644 index 000000000..40ebcd5de --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-countsem.c @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-countsem.h" + +#include +#include + +void* const UT_Ref_OS_impl_count_sem_table = OS_impl_count_sem_table; +size_t const UT_Ref_OS_impl_count_sem_table_SIZE = sizeof(OS_impl_count_sem_table); + + +int32 UT_Call_OS_VxWorks_CountSemAPI_Impl_Init(void) +{ + return OS_VxWorks_CountSemAPI_Impl_Init(); +} + + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirs.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirs.c new file mode 100644 index 000000000..c4c66e84c --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-dirs.c @@ -0,0 +1,34 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-dirs.h" + +#include +#include + + +int32 UT_Call_OS_VxWorks_DirAPI_Impl_Init(void) +{ + return OS_VxWorks_DirAPI_Impl_Init(); +} + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c new file mode 100644 index 000000000..f8ba9c9a9 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-files.c @@ -0,0 +1,55 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-files.h" + +#include +#include + + + +int32 UT_Call_OS_VxWorks_StreamAPI_Impl_Init(void) +{ + return OS_VxWorks_StreamAPI_Impl_Init(); +} + +/* + * Allow UT to get the value of the OS_IMPL_SELF_EUID and + * OS_IMPL_SELF_EGID constants. These might be assigned + * at runtime by the init function (above) or they might be + * defined at compile time. + */ +unsigned int UT_FileTest_GetSelfEUID(void) +{ + return OS_IMPL_SELF_EUID; +} + +unsigned int UT_FileTest_GetSelfEGID(void) +{ + return OS_IMPL_SELF_EGID; +} + +void UT_FileTest_Set_Selectable(uint32 local_id, bool is_selectable) +{ + OS_impl_filehandle_table[local_id].selectable = is_selectable; +} diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c new file mode 100644 index 000000000..2dbd54d18 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filesys.c @@ -0,0 +1,40 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfilesys.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-filesys.h" + +#include +#include + + + +void* const UT_Ref_OS_impl_filesys_table = OS_impl_filesys_table; +size_t const UT_Ref_OS_impl_filesys_table_SIZE = sizeof(OS_impl_filesys_table); + +void UT_FileSysTest_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts) +{ + OS_impl_filesys_table[id].blkDev = blkdev; + OS_impl_filesys_table[id].xbd = xbddev; + OS_impl_filesys_table[id].xbdMaxPartitions = MaxParts; +} + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c new file mode 100644 index 000000000..9bfd1f088 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-filetable-stub.c @@ -0,0 +1,36 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osfileapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-filetable-stub.h" + +#include +#include + + + + +OS_VxWorks_filehandle_entry_t OS_impl_filehandle_table[OS_MAX_NUM_OPEN_FILES]; + + +void* const UT_FileTableTest_OS_impl_filehandle_table = OS_impl_filehandle_table; +size_t const UT_FileTableTest_OS_impl_filehandle_table_SIZE = sizeof(OS_impl_filehandle_table); diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c new file mode 100644 index 000000000..e606eff68 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-idmap.c @@ -0,0 +1,39 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include +#include +#include + +#include +#include "ut-adaptor-idmap.h" + +int32 UT_Call_OS_VxWorks_TableMutex_Init(uint32 idtype) +{ + return OS_VxWorks_TableMutex_Init(idtype); +} + +void UT_IdMapTest_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid) +{ + VX_MUTEX_TABLE[idtype].vxid = vxid; +} + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-loader.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-loader.c new file mode 100644 index 000000000..5869b6a68 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-loader.c @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osloader.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-loader.h" + +#include +#include + + +void* const UT_Ref_OS_impl_module_table = OS_impl_module_table; +size_t const UT_Ref_OS_impl_module_table_SIZE = sizeof(OS_impl_module_table); + +int32 UT_Call_OS_VxWorks_ModuleAPI_Impl_Init(void) +{ + return OS_VxWorks_ModuleAPI_Impl_Init(); +} + + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-mutex.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-mutex.c new file mode 100644 index 000000000..17c621391 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-mutex.c @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-mutex.h" + +#include +#include + +void* const UT_Ref_OS_impl_mutex_table = OS_impl_mutex_table; +size_t const UT_Ref_OS_impl_mutex_table_SIZE = sizeof(OS_impl_mutex_table); + + +int32 UT_Call_OS_VxWorks_MutexAPI_Impl_Init(void) +{ + return OS_VxWorks_MutexAPI_Impl_Init(); +} + + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-queues.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-queues.c new file mode 100644 index 000000000..f15bf6b88 --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-queues.c @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-adaptor-queues.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-queues.h" + +#include +#include + +void* const UT_Ref_OS_impl_queue_table = OS_impl_queue_table; +size_t const UT_Ref_OS_impl_queue_table_SIZE = sizeof(OS_impl_queue_table); + + +int32 UT_Call_OS_VxWorks_QueueAPI_Impl_Init(void) +{ + return OS_VxWorks_QueueAPI_Impl_Init(); +} + + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c new file mode 100644 index 000000000..42be2af0c --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-symtab.c @@ -0,0 +1,44 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osloader.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-loader.h" + +#include +#include + +/* + * A UT-specific wrapper function to invoke the Symbol Table Iterator. + * This is normally static so it needs this wrapper to call it. + */ +int32 UT_SymTabTest_CallIteratorFunc(const char *name, void* val, uint32 TestSize, uint32 SizeLimit) +{ + OS_VxWorks_SymbolDumpState.Sizelimit = SizeLimit; + OS_VxWorks_SymbolDumpState.CurrSize = TestSize; + /* + * note the internal function is takes a name declared as "char*" to be + * consistent with the VxWorks API, however the implementation does not + * modify this argument. + */ + return OS_SymTableIterator_Impl((char*)name,(OCS_SYM_VALUE)val,0,0,0); +} + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c new file mode 100644 index 000000000..32394b02a --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-tasks.c @@ -0,0 +1,57 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-osapi.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-tasks.h" + +#include +#include + +void* const UT_Ref_OS_impl_task_table = OS_impl_task_table; +size_t const UT_Ref_OS_impl_task_table_SIZE = sizeof(OS_impl_task_table); + + +int32 UT_Call_OS_VxWorks_TaskAPI_Impl_Init(void) +{ + return OS_VxWorks_TaskAPI_Impl_Init(); +} + +void UT_TaskTest_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId) +{ + OS_impl_task_table[local_id].vxid = TaskId; +} + +/* + * Because the task entry point is declared "static", + * in order for the UT to invoke it there must be a non-static + * way to get access to it. + */ +int UT_TaskTest_CallEntryPoint(int arg) +{ + return OS_VxWorks_TaskEntry(arg); +} + +OCS_WIND_TCB* UT_TaskTest_GetTaskTcb(uint32 local_id) +{ + return &OS_impl_task_table[local_id].tcb; +} + diff --git a/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c new file mode 100644 index 000000000..bf60fa46e --- /dev/null +++ b/src/unit-test-coverage/vxworks/adaptors/src/ut-adaptor-timebase.c @@ -0,0 +1,99 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file ut-ostimer.c + * \ingroup adaptors + * \author joseph.p.hickey@nasa.gov + * + */ + +/* pull in the OSAL configuration */ +#include "osconfig.h" +#include "ut-adaptor-timebase.h" + +#include +#include + + +void* const UT_Ref_OS_impl_timebase_table = OS_impl_timebase_table; +size_t const UT_Ref_OS_impl_timebase_table_SIZE = sizeof(OS_impl_timebase_table); + +int32 UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(void) +{ + return OS_VxWorks_TimeBaseAPI_Impl_Init(); +} + + +int32 UT_TimeBaseTest_CallSigWaitFunc(uint32 local_id) +{ + return OS_VxWorks_SigWait(local_id); +} + +int UT_TimeBaseTest_CallHelperTaskFunc(int arg) +{ + return OS_VxWorks_TimeBaseTask(arg); +} + +void UT_TimeBaseTest_CallRegisterTimer(uint32 local_id) +{ + OS_VxWorks_RegisterTimer(local_id); +} + +bool UT_TimeBaseTest_CheckTimeBaseRegisteredState(uint32 local_id) +{ + return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_SUCCESS); +} + +bool UT_TimeBaseTest_CheckTimeBaseErrorState(uint32 local_id) +{ + return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_ERROR); +} + +void UT_TimeBaseTest_ClearTimeBaseRegState(uint32 local_id) +{ + OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_INIT; +} + +void UT_TimeBaseTest_SetTimeBaseRegState(uint32 local_id, bool is_success) +{ + /* Mimic the setting of the Reg state global, which + * is typically done by the task after spawning + */ + if (is_success) + { + OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_SUCCESS; + } + else + { + OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_ERROR; + } +} + +void UT_TimeBaseTest_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec) +{ + OS_VxWorks_UsecToTimespec(usecs, time_spec); +} + +void UT_TimeBaseTest_Setup(uint32 local_id, int signo, bool reset_flag) +{ + static OCS_WIND_TCB FAKE_TASK; + static OCS_SEM FAKE_SEM; + + OS_impl_timebase_table[local_id].assigned_signal = signo; + OS_impl_timebase_table[local_id].handler_task = &FAKE_TASK; + OS_impl_timebase_table[local_id].handler_mutex = &FAKE_SEM; + OS_impl_timebase_table[local_id].reset_flag = reset_flag; +} + diff --git a/src/unit-test-coverage/vxworks/modules/CMakeLists.txt b/src/unit-test-coverage/vxworks/modules/CMakeLists.txt deleted file mode 100644 index 8611d9800..000000000 --- a/src/unit-test-coverage/vxworks/modules/CMakeLists.txt +++ /dev/null @@ -1,39 +0,0 @@ -# -# Copyright (c) 2019, United States government as represented by the -# administrator of the National Aeronautics Space Administration. -# All rights reserved. This software was created at NASA Goddard -# Space Flight Center pursuant to government contracts. -# -# This is governed by the NASA Open Source Agreement and may be used, -# distributed and modified only according to the terms of that agreement. -# - -# -------------------------------------- -# OSAL SHARED LAYER FOR COVERAGE TESTING -# -------------------------------------- - -# This CMake recipe snippet builds the _actual_ OSAL implementation (not a stub) -# However it differs from the regular non-UT build in the following ways: -# - Each sub-module is compiled to a separate "OBJECT" library -# this simplifies the testrunner linking by allow only one specific -# object file to be linked into each test -# - Each sub-module is wrapped to divert C library calls to the -# stub (OCS) counterpart -# - UT_COVERAGE_COMPILE_FLAGS are enabled to include any code coverage instrumentation - -# the "override_inc" dir contains replacement versions of the C-library include files. -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/inc) -include_directories(${OSALCOVERAGE_SOURCE_DIR}/ut-stubs/override_inc) - -foreach(MODULE ${MODULE_LIST}) - if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/ut-${MODULE}.c) - add_library(ut_${SETNAME}_${MODULE} OBJECT - src/ut-${MODULE}.c - ) - target_compile_options(ut_${SETNAME}_${MODULE} PRIVATE - ${UT_COVERAGE_COMPILE_FLAGS} - ) - endif () -endforeach() - - diff --git a/src/unit-test-coverage/vxworks/modules/Makefile b/src/unit-test-coverage/vxworks/modules/Makefile deleted file mode 100644 index dc2e1ae13..000000000 --- a/src/unit-test-coverage/vxworks/modules/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -# Makefile for ut osal -# - -# -# INCLUDES specifies the search paths for include files outside of the current directory. -# Note that the -I is required. -# -INCLUDES += -I./inc -INCLUDES += -I../ut-stubs/inc -INCLUDES += -I$(OSAL)/src/os/inc -INCLUDES += -I$(OSAL)/build/inc -INCLUDES += -I$(OSAL)/src - - -# -# UT_OBJS specifies unit test object files. -# -UT_OBJS := osapi.o -UT_OBJS += osfileapi.o -UT_OBJS += osfilesys.o -UT_OBJS += osloader.o -UT_OBJS += osnetwork.o -UT_OBJS += ostimer.o - -############################################################################### - -COMPILER=gcc -LINKER=ld - -# -# Compiler and Linker Options -# -ENABLE_GCOV = TRUE -ifeq ($(ENABLE_GCOV), TRUE) -GCOV_COPT = --coverage -GCOV_LOPT = --coverage -endif - -#WARNINGS = -Wall -W -ansi -Werror -Wstrict-prototypes -Wundef -WARNINGS = -Wall -Wstrict-prototypes -DEBUGGER = -g - -COPT = $(WARNINGS) $(DEBUGGER) $(GCOV_COPT) -DOSAPI_NO_SPECIAL_ATTRIBS -DSOFTWARE_LITTLE_BIT_ORDER -D_EL -D_ix86_ $(OSAL_M32) - -LOPT = $(GCOV_LOPT) $(OSAL_M32) - -############################################################################### -## "C" COMPILER RULE -## -%.o: src/%.c - $(COMPILER) -c $(COPT) $(INCLUDES) $< - -############################################################################## -## - -all: $(UT_OBJS) - -clean :: - rm -f *.o *.exe *.gcda *.gcno *.gcov gmon.out - -gcov :: - @echo - @gcov -b $(UT_OBJS:.o=.gcda) | \ - awk -f $(OSAL)/build/gcov-parse.awk - @rm -f *.gcda *.gcno - @echo - -# end of file - diff --git a/src/unit-test-coverage/vxworks/modules/README.txt b/src/unit-test-coverage/vxworks/modules/README.txt deleted file mode 100644 index 0b40586c3..000000000 --- a/src/unit-test-coverage/vxworks/modules/README.txt +++ /dev/null @@ -1,38 +0,0 @@ -UT-OSAL README FILE -=================== - -The objective here is to build the OSAL source code but with all calls/references to the underlying -OS remapped to "stub" implementations and/or local definitions of those identifiers. - -The "inc" subdirectory includes empty files for _ALL_ of the header files included by the OSAL source -code. The "inc" subdirectory is in the compiler search path so these empty files will be used in -place of the real system header file. THIS IS THE ONLY PLACE WHERE THESE EMPTY STUBS SHOULD BE -USED IN PLACE OF THE REAL FILE. - -Two exceptions are made: - - maps to the real one, so we have accurate fixed-width types. - - -The paradigm used here: -- Each source file in OSAL has a wrapper here with the same name. - -- First the wrapper includes a header with any "extra" logic that the test case needs to add - This is optional and used in cases where the test needs access to static/private data structures. - -- Then the wrapper #include's "stub-map-to-real.h" - This is an important file that has #define macros that map all identifiers typically supplied - by the C library to one with a "VCS_" prefix. For example, "strcmp" will become "VCS_strcmp". - -- Then it #include's the unmodified OSAL source code, adding that exact code into the same compilation - unit, with the stub-remap macros in place. - - In the same example as above, all calls to "strcmp()" (a library function) will become calls to - "VCS_strcmp" with the same arguments. The implementation of VCS_strcmp() is provided by the test case. - -- Finally the implementation for any "extra" logic is directly implmemented in the wrapper file. - Because this is in the same compilation unit as the OSAL source code, it can access variables that - are defined "static". IMPORTANT: The implementation of these wrappers will also have all stub-mapping - active, so these must avoid using C library calls as they will NOT go to the C library. - - - \ No newline at end of file diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h deleted file mode 100644 index 5f7f39a55..000000000 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osapi.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSAPI_H_ -#define _OSAL_UT_OSAPI_H_ - -#include -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/* - * Prototype for table init functions (need to be called from UT) - */ -int32 OS_VxWorks_TaskAPI_Impl_Init(void); -int32 OS_VxWorks_QueueAPI_Impl_Init(void); -int32 OS_VxWorks_BinSemAPI_Impl_Init(void); -int32 OS_VxWorks_CountSemAPI_Impl_Init(void); -int32 OS_VxWorks_MutexAPI_Impl_Init(void); - -/** - * Purges all state tables and resets back to initial conditions - * Helps avoid cross-test dependencies - */ -void Osapi_Internal_ResetState(void); - -/** - * Sets the "vxid" field on an internal task table entry. - */ -void Osapi_Internal_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId); - -/** - * Sets the "vxid" field on a global table mutex entry. - */ -void Osapi_Internal_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid); - -/** - * Invokes the generic task entry point - */ -int Osapi_Internal_CallEntryPoint(int arg); - -/** - * Invokes the console helper task entry point - */ -void Osapi_Internal_CallConsoleTask_Entry(int arg); - -/** - * Get the (fake) TCB structure for the given id. - */ -OCS_WIND_TCB* Osapi_Internal_GetTaskTcb(uint32 local_id); - -/** - * Force the "is_async" field to a given state for coverage testing - */ -void Osapi_Internal_SetConsoleAsync(uint32 local_id, bool is_async); - -#endif /* _OSAL_UT_OSAPI_H_ */ - diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h deleted file mode 100644 index 68a50bcd8..000000000 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osfileapi.h +++ /dev/null @@ -1,36 +0,0 @@ -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSFILEAPI_H_ -#define _OSAL_UT_OSFILEAPI_H_ - -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - - -/* - * Prototype for table init function (needs to be called from UT) - */ -int32 OS_VxWorks_StreamAPI_Impl_Init(void); -int32 OS_VxWorks_DirAPI_Impl_Init(void); - -/* - * Allow UT to get the value of the OS_IMPL_SELF_EUID and - * OS_IMPL_SELF_EGID constants. These might be assigned - * at runtime by the init function (above) or they might be - * defined at compile time. - */ -unsigned int Osapi_Internal_GetSelfEUID(void); -unsigned int Osapi_Internal_GetSelfEGID(void); - -void Osapi_Internal_Set_Selectable(uint32 local_id, bool is_selectable); - -#endif /* _OSAL_UT_OSTIMER_H_ */ - diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osfilesys.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osfilesys.h deleted file mode 100644 index 149a74258..000000000 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osfilesys.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSFILESYS_H_ -#define _OSAL_UT_OSFILESYS_H_ - -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -void Osapi_Internal_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts); - - - - -#endif /* _OSAL_UT_OSFILESYS_H_ */ - diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-osloader.h b/src/unit-test-coverage/vxworks/modules/inc/ut-osloader.h deleted file mode 100644 index 78e952a5e..000000000 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-osloader.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSLOADER_H_ -#define _OSAL_UT_OSLOADER_H_ - -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/* - * Prototype for table init function (needs to be called from UT) - */ -int32 OS_VxWorks_ModuleAPI_Impl_Init(void); - -/* - * Invokes OS_SymTableIterator_Impl() with the given arguments. - * This is normally a static function but exposed via a non-static wrapper for UT purposes. - */ -int32 Osapi_Internal_CallIteratorFunc(const char *name, void* val, uint32 TestSize, uint32 SizeLimit); - -#endif /* _OSAL_UT_OSLOADER_H_ */ - diff --git a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h b/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h deleted file mode 100644 index 86c9522de..000000000 --- a/src/unit-test-coverage/vxworks/modules/inc/ut-ostimer.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* OSAL coverage stub replacement for file mode bits - * this file is shared by several UT replacement headers */ -#ifndef _OSAL_UT_OSTIMER_H_ -#define _OSAL_UT_OSTIMER_H_ - -#include -#include -#include - -/***************************************************** - * - * UT FUNCTION PROTOTYPES - * - * These are functions that need to be invoked by UT - * but are not exposed directly through the implementation API. - * - *****************************************************/ - -/* - * Prototype for table init function (needs to be called from UT) - */ -int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void); - -void Osapi_Internal_ResetState(void); -void Osapi_Internal_Setup(uint32 local_id, int signo, bool reset_flag); - -/** - * Invokes OS_VxWorks_SigWait() with the given arguments. - * This is normally a static function but exposed via a non-static wrapper for UT purposes. - */ -int32 Osapi_Internal_CallSigWaitFunc(uint32 local_id); - -/* Invokes the static OS_VxWorks_TimeBaseTask() function with given argument */ -int Osapi_Internal_CallHelperTaskFunc(int arg); - -/* Invokes the static OS_VxWorks_RegisterTimer() function with given argument */ -void Osapi_Internal_CallRegisterTimer(uint32 local_id); - -/* Hook functions which set the timer registration state */ -void Osapi_Internal_SetTimeBaseRegState(uint32 local_id, bool is_success); -void Osapi_Internal_ClearTimeBaseRegState(uint32 local_id); - -/* Hook functions which test the timer registration state */ -bool Osapi_Internal_CheckTimeBaseRegisteredState(uint32 local_id); -bool Osapi_Internal_CheckTimeBaseErrorState(uint32 local_id); - -/* Invoke the internal UsecToTimespec API */ -void Osapi_Internal_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec); - -#endif /* _OSAL_UT_OSTIMER_H_ */ - diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c b/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c deleted file mode 100644 index a46f68668..000000000 --- a/src/unit-test-coverage/vxworks/modules/src/ut-osapi.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osapi.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osapi.c" - -/* Stub objects to satisfy linking requirements - - */ -OS_common_record_t OS_stub_task_table[OS_MAX_TASKS]; -OS_common_record_t * const OS_global_task_table = OS_stub_task_table; -OS_common_record_t OS_stub_queue_table[OS_MAX_QUEUES]; -OS_common_record_t * const OS_global_queue_table = OS_stub_queue_table; -OS_common_record_t OS_stub_console_table[OS_MAX_QUEUES]; -OS_common_record_t * const OS_global_console_table = OS_stub_console_table; - -OS_queue_internal_record_t OS_queue_table[OS_MAX_QUEUES]; -OS_task_internal_record_t OS_task_table[OS_MAX_TASKS]; -OS_console_internal_record_t OS_console_table[OS_MAX_CONSOLES]; - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - - -void Osapi_Internal_ResetState(void) -{ - memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); - memset(OS_queue_table, 0, sizeof(OS_queue_table)); - memset(OS_task_table, 0, sizeof(OS_task_table)); - memset(OS_console_table, 0, sizeof(OS_console_table)); - memset(OS_stub_queue_table, 0, sizeof(OS_stub_queue_table)); - memset(OS_stub_task_table, 0, sizeof(OS_stub_task_table)); - memset(OS_stub_console_table, 0, sizeof(OS_stub_console_table)); -} - -void Osapi_Internal_SetImplTableMutex(uint32 idtype, OCS_SEM_ID vxid) -{ - VX_MUTEX_TABLE[idtype].vxid = vxid; -} - -void Osapi_Internal_SetImplTaskId(uint32 local_id, OCS_TASK_ID TaskId) -{ - OS_impl_task_table[local_id].vxid = TaskId; -} - -/* - * Because the task entry point is declared "static", - * in order for the UT to invoke it there must be a non-static - * way to get access to it. - */ -int Osapi_Internal_CallEntryPoint(int arg) -{ - return OS_VxWorksEntry(arg); -} - -void Osapi_Internal_CallConsoleTask_Entry(int arg) -{ - OS_ConsoleTask_Entry(arg); -} - -OCS_WIND_TCB* Osapi_Internal_GetTaskTcb(uint32 local_id) -{ - return &OS_impl_task_table[local_id].tcb; -} - -void Osapi_Internal_SetConsoleAsync(uint32 local_id, bool is_async) -{ - OS_impl_console_table[local_id].is_async = is_async; -} - diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-osfileapi.c b/src/unit-test-coverage/vxworks/modules/src/ut-osfileapi.c deleted file mode 100644 index dfb39ab43..000000000 --- a/src/unit-test-coverage/vxworks/modules/src/ut-osfileapi.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" -#include "ut-osfileapi.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osfileapi.c" - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - - -unsigned int Osapi_Internal_GetSelfEUID(void) -{ - return OS_IMPL_SELF_EUID; -} - -unsigned int Osapi_Internal_GetSelfEGID(void) -{ - return OS_IMPL_SELF_EGID; -} - -void Osapi_Internal_Set_Selectable(uint32 local_id, bool is_selectable) -{ - OS_impl_filehandle_table[local_id].selectable = is_selectable; -} diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-osfilesys.c b/src/unit-test-coverage/vxworks/modules/src/ut-osfilesys.c deleted file mode 100644 index 10f2693df..000000000 --- a/src/unit-test-coverage/vxworks/modules/src/ut-osfilesys.c +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" - - -#include "ut-osfilesys.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osfilesys.c" - -/* For proper linkage this variable must be instantiated here */ -OS_filesys_internal_record_t OS_filesys_table[OS_MAX_FILE_SYSTEMS]; - - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - - -void Osapi_Internal_SetupFileSysEntry(uint32 id, OCS_BLK_DEV *blkdev, OCS_device_t xbddev, uint32 MaxParts) -{ - OS_impl_filesys_table[id].blkDev = blkdev; - OS_impl_filesys_table[id].xbd = xbddev; - OS_impl_filesys_table[id].xbdMaxPartitions = MaxParts; -} - diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-osloader.c b/src/unit-test-coverage/vxworks/modules/src/ut-osloader.c deleted file mode 100644 index 7befd6dcc..000000000 --- a/src/unit-test-coverage/vxworks/modules/src/ut-osloader.c +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "osloader.c" -#include "ut-osloader.h" - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - - -/* - * A UT-specific wrapper function to invoke the Symbol Table Iterator. - * This is normally static so it needs this wrapper to call it. - */ -int32 Osapi_Internal_CallIteratorFunc(const char *name, void* val, uint32 TestSize, uint32 SizeLimit) -{ - OS_impl_module_global.sym_dump.Sizelimit = SizeLimit; - OS_impl_module_global.sym_dump.CurrSize = TestSize; - /* - * note the internal function is takes a name declared as "char*" to be - * consistent with the VxWorks API, however the implementation does not - * modify this argument. - */ - return OS_SymTableIterator_Impl((char*)name,val,0,0,0); -} - diff --git a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c b/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c deleted file mode 100644 index 28d0127a1..000000000 --- a/src/unit-test-coverage/vxworks/modules/src/ut-ostimer.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* pull in the OSAL configuration */ -#include "osconfig.h" - -/* - * Now include all extra logic required to stub-out subsequent calls to - * library functions and replace with our own - */ -#include "ostimer.c" -#include "ut-ostimer.h" - -/* - * Stub objects to satisfy linking requirements - - */ - -OS_timecb_internal_record_t OS_timecb_table[OS_MAX_TIMERS]; -OS_timebase_internal_record_t OS_timebase_table[OS_MAX_TIMEBASES]; - -OS_common_record_t OS_stub_timebase_table[OS_MAX_TIMEBASES]; -OS_common_record_t OS_stub_timecb_table[OS_MAX_TIMERS]; - -OS_common_record_t * const OS_global_timebase_table = OS_stub_timebase_table; -OS_common_record_t * const OS_global_timecb_table = OS_stub_timecb_table; - - -OS_SharedGlobalVars_t OS_SharedGlobalVars = - { - .Initialized = false - }; - -int32 Osapi_Internal_CallSigWaitFunc(uint32 local_id) -{ - return OS_VxWorks_SigWait(local_id); -} - -int Osapi_Internal_CallHelperTaskFunc(int arg) -{ - return OS_VxWorks_TimeBaseTask(arg); -} - -void Osapi_Internal_CallRegisterTimer(uint32 local_id) -{ - OS_VxWorks_RegisterTimer(local_id); -} - -bool Osapi_Internal_CheckTimeBaseRegisteredState(uint32 local_id) -{ - return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_SUCCESS); -} - -bool Osapi_Internal_CheckTimeBaseErrorState(uint32 local_id) -{ - return (OS_impl_timebase_table[local_id].timer_state == OS_TimerRegState_ERROR); -} - -void Osapi_Internal_ClearTimeBaseRegState(uint32 local_id) -{ - OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_INIT; -} - -void Osapi_Internal_SetTimeBaseRegState(uint32 local_id, bool is_success) -{ - /* Mimic the setting of the Reg state global, which - * is typically done by the task after spawning - */ - if (is_success) - { - OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_SUCCESS; - } - else - { - OS_impl_timebase_table[local_id].timer_state = OS_TimerRegState_ERROR; - } -} - -void Osapi_Internal_UsecToTimespec(uint32 usecs, struct OCS_timespec *time_spec) -{ - OS_Impl_UsecToTimespec(usecs, time_spec); -} - -void Osapi_Internal_ResetState(void) -{ - memset(OS_timecb_table, 0, sizeof(OS_timecb_table)); - memset(OS_timebase_table, 0, sizeof(OS_timebase_table)); - memset(OS_stub_timebase_table, 0, sizeof(OS_stub_timebase_table)); - memset(OS_stub_timecb_table, 0, sizeof(OS_stub_timecb_table)); -} - -void Osapi_Internal_Setup(uint32 local_id, int signo, bool reset_flag) -{ - static OCS_WIND_TCB FAKE_TASK; - static OCS_SEM FAKE_SEM; - - OS_impl_timebase_table[local_id].assigned_signal = signo; - OS_impl_timebase_table[local_id].handler_task = &FAKE_TASK; - OS_impl_timebase_table[local_id].handler_mutex = &FAKE_SEM; - OS_impl_timebase_table[local_id].reset_flag = reset_flag; -} - diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c new file mode 100644 index 000000000..8ed34e800 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-binsem.c @@ -0,0 +1,166 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-binsem.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/* + * Includes + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-binsem.h" + +#include "osapi-binsem-impl.h" +#include "osapi-idmap-impl.h" + +#include +#include + +void Test_OS_VxWorks_BinSemAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_BinSemAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_BinSemAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_BinSemCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0,0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semBInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemCreate_Impl(0,0,0), OS_SEM_FAILURE); +} + +void Test_OS_BinSemDelete_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemDelete_Impl (uint32 sem_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemDelete_Impl(0), OS_SUCCESS); +} + +void Test_OS_BinSemGive_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemGive_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_StubKey_GenericSemGive, OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGive_Impl(0), OS_SEM_FAILURE); +} + +void Test_OS_BinSemFlush_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemFlush_Impl (uint32 sem_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semFlush), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_BinSemFlush_Impl(0), OS_SEM_FAILURE); +} + +void Test_OS_BinSemTake_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemTake_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemTake_Impl(0), OS_SUCCESS); +} + +void Test_OS_BinSemTimedWait_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) + */ + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SUCCESS); + + UT_SetForceFail(UT_StubKey_GenericSemTake, OS_SEM_FAILURE); + OSAPI_TEST_FUNCTION_RC(OS_BinSemTimedWait_Impl(0,100), OS_SEM_FAILURE); +} + +void Test_OS_BinSemGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_BinSemGetInfo_Impl (uint32 sem_id, OS_bin_sem_prop_t *sem_prop) + */ + OS_bin_sem_prop_t sem_prop; + memset(&sem_prop, 0xEE, sizeof(sem_prop)); + OSAPI_TEST_FUNCTION_RC(OS_BinSemGetInfo_Impl(0,&sem_prop), OS_SUCCESS); +} + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + + memset(OS_bin_sem_table, 0, sizeof(OS_bin_sem_table)); + memset(OS_global_bin_sem_table, 0, sizeof(OS_common_record_t) * OS_MAX_BIN_SEMAPHORES); + + memset(UT_Ref_OS_impl_bin_sem_table, 0, UT_Ref_OS_impl_bin_sem_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_BinSemAPI_Impl_Init); + ADD_TEST(OS_BinSemCreate_Impl); + ADD_TEST(OS_BinSemDelete_Impl); + ADD_TEST(OS_BinSemGive_Impl); + ADD_TEST(OS_BinSemFlush_Impl); + ADD_TEST(OS_BinSemTake_Impl); + ADD_TEST(OS_BinSemTimedWait_Impl); + ADD_TEST(OS_BinSemGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-common.c b/src/unit-test-coverage/vxworks/src/coveragetest-common.c new file mode 100644 index 000000000..3d9a042af --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-common.c @@ -0,0 +1,144 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-common.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-common.h" + +#include "osapi-common-impl.h" + +#include +#include + +OCS_SEM TestGlobalSem; + + +void Test_OS_API_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_API_Impl_Init(uint32 idtype) + */ + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(0), OS_SUCCESS); + UT_SetForceFail(UT_StubKey_OS_VxWorks_TableMutex_Init, OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + UT_ClearForceFail(UT_StubKey_OS_VxWorks_TableMutex_Init); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_QUEUE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_BINSEM), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_COUNTSEM), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_MUTEX), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_MODULE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_TIMEBASE), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_STREAM), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_API_Impl_Init(OS_OBJECT_TYPE_OS_DIR), OS_SUCCESS); +} + +void Test_OS_IdleLoop_Impl(void) +{ + /* + * Test Case For: + * void OS_IdleLoop_Impl() + */ + /* just call the function for coverage */ + OS_IdleLoop_Impl(); +} + +void Test_OS_ApplicationShutdown_Impl(void) +{ + /* + * Test Case For: + * void OS_ApplicationShutdown_Impl() + */ + /* just call the function for coverage */ + OS_ApplicationShutdown_Impl(); +} + +void Test_OS_VxWorks_GenericSemGive(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_GenericSemGive(SEM_ID vxid) + */ + OCS_SEM_ID SemID = NULL; + + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemGive(SemID), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_semGive), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemGive(SemID), OS_SEM_FAILURE); +} /* end OS_VxWorks_GenericSemGive */ + + +void Test_OS_VxWorks_GenericSemTake(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_GenericSemTake(SEM_ID vxid, int sys_ticks) + */ + OCS_SEM_ID SemID = NULL; + + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 10), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_semTake), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_TIMEOUT); + OCS_errno = OCS_S_objLib_OBJ_ID_ERROR; + OSAPI_TEST_FUNCTION_RC(OS_VxWorks_GenericSemTake(SemID, 0), OS_SEM_FAILURE); + +} /* end OS_VxWorks_GenericSemTake */ + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_API_Impl_Init); + ADD_TEST(OS_IdleLoop_Impl); + ADD_TEST(OS_ApplicationShutdown_Impl); + ADD_TEST(OS_VxWorks_GenericSemGive); + ADD_TEST(OS_VxWorks_GenericSemTake); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c b/src/unit-test-coverage/vxworks/src/coveragetest-console.c similarity index 69% rename from src/unit-test-coverage/vxworks/src/coveragetest-printf.c rename to src/unit-test-coverage/vxworks/src/coveragetest-console.c index 3fb17c207..1c88c8e71 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-printf.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-console.c @@ -1,29 +1,27 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osfileapi-common" file - * - * Notes: - * + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * */ -/* - * Includes +/** + * \file coveragetest-printf.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * */ #include "os-vxworks-coveragetest.h" -#include "ut-osapi.h" +#include "ut-adaptor-console.h" +#include "osapi-printf-impl.h" #include #include @@ -41,14 +39,14 @@ void Test_OS_ConsoleWakeup_Impl(void) */ /* no return code - check for coverage */ - Osapi_Internal_SetConsoleAsync(0, true); + UT_ConsoleTest_SetConsoleAsync(0, true); OS_ConsoleWakeup_Impl(0); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semGive)) == 1, "semGive() called in async mode"); UT_SetForceFail(UT_KEY(OCS_semGive), -1); OS_ConsoleWakeup_Impl(0); - Osapi_Internal_SetConsoleAsync(0, false); + UT_ConsoleTest_SetConsoleAsync(0, false); OS_console_table[0].WritePos = 1; OS_ConsoleWakeup_Impl(0); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_putchar)) == 1, "putchar() called in sync mode"); @@ -72,7 +70,7 @@ void Test_OS_ConsoleCreate_Impl(void) /* Also call the actual console task, to get coverage on it. * This task has an infinite loop, which only exits if semTake fails */ UT_SetDeferredRetcode(UT_KEY(OCS_semTake), 2, OCS_ERROR); - Osapi_Internal_CallConsoleTask_Entry(0); + UT_ConsoleTest_TaskEntry(0); } void Test_OS_ConsoleOutput_Impl(void) @@ -91,33 +89,37 @@ void Test_OS_ConsoleOutput_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + + memset(OS_console_table, 0, sizeof(OS_console_table)); + memset(OS_global_console_table, 0, sizeof(OS_common_record_t) * OS_MAX_CONSOLES); + + memset(UT_Ref_OS_impl_console_table, 0, UT_Ref_OS_impl_console_table_SIZE); + OS_console_table[0].BufBase = TestConsoleBuffer; OS_console_table[0].BufSize = sizeof(TestConsoleBuffer); - OS_console_table[0].ReadPos = 0; - OS_console_table[0].WritePos = 0; } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) /* UtTest_Setup * diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c new file mode 100644 index 000000000..86446dfa2 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-countsem.c @@ -0,0 +1,140 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-countsem.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-countsem.h" + +#include "osapi-countsem-impl.h" + +void Test_OS_VxWorks_CountSemAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_CountSemAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_CountSemAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_CountSemCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemCreate_Impl (uint32 sem_id, uint32 sem_initial_value, uint32 options) + */ + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0,0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semCInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_CountSemCreate_Impl(0,0,0), OS_SEM_FAILURE); +} + +void Test_OS_CountSemDelete_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemDelete_Impl (uint32 sem_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_CountSemDelete_Impl(0), OS_SUCCESS); +} + +void Test_OS_CountSemGive_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemGive_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_CountSemGive_Impl(0), OS_SUCCESS); +} + +void Test_OS_CountSemTake_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemTake_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_CountSemTake_Impl(0), OS_SUCCESS); +} + +void Test_OS_CountSemTimedWait_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemTimedWait_Impl ( uint32 sem_id, uint32 msecs ) + */ + OSAPI_TEST_FUNCTION_RC(OS_CountSemTimedWait_Impl(0, 100), OS_SUCCESS); +} + +void Test_OS_CountSemGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_CountSemGetInfo_Impl (uint32 sem_id, OS_count_sem_prop_t *count_prop) + */ + OS_count_sem_prop_t count_prop; + memset(&count_prop, 0xEE, sizeof(count_prop)); + OSAPI_TEST_FUNCTION_RC(OS_CountSemGetInfo_Impl(0, &count_prop), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + + memset(OS_count_sem_table, 0, sizeof(OS_count_sem_table)); + memset(OS_global_count_sem_table, 0, sizeof(OS_common_record_t) * OS_MAX_BIN_SEMAPHORES); + + memset(UT_Ref_OS_impl_count_sem_table, 0, UT_Ref_OS_impl_count_sem_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_CountSemAPI_Impl_Init); + ADD_TEST(OS_CountSemCreate_Impl); + ADD_TEST(OS_CountSemDelete_Impl); + ADD_TEST(OS_CountSemGive_Impl); + ADD_TEST(OS_CountSemTake_Impl); + ADD_TEST(OS_CountSemTimedWait_Impl); + ADD_TEST(OS_CountSemGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c b/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c new file mode 100644 index 000000000..32659cb79 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-dirs.c @@ -0,0 +1,150 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-dirs.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-dirs.h" + +#include "osapi-dir-impl.h" + +#include +#include +#include +#include +#include + +void Test_OS_VxWorks_DirAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_DirAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_DirAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_DirCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirCreate_Impl(const char *local_path, uint32 access) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_mkdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirCreate_Impl("dir", 0), OS_ERROR); +} + +void Test_OS_DirOpen_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirOpen_Impl(uint32 local_id, const char *local_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_opendir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirOpen_Impl(0, "dir"), OS_ERROR); +} + +void Test_OS_DirClose_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirClose_Impl(uint32 local_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirClose_Impl(0), OS_SUCCESS); +} + +void Test_OS_DirRead_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRead_Impl(uint32 local_id, os_dirent_t *dirent) + */ + os_dirent_t dirent_buff; + + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_readdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRead_Impl(0, &dirent_buff), OS_ERROR); + +} + +void Test_OS_DirRewind_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRewind_Impl(uint32 local_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirRewind_Impl(0), OS_SUCCESS); +} + +void Test_OS_DirRemove_Impl(void) +{ + /* + * Test Case For: + * int32 OS_DirRemove_Impl(const char *local_path) + */ + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_rmdir), -1); + OSAPI_TEST_FUNCTION_RC(OS_DirRemove_Impl("dir"), OS_ERROR); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_DirAPI_Impl_Init); + ADD_TEST(OS_DirCreate_Impl); + ADD_TEST(OS_DirOpen_Impl); + ADD_TEST(OS_DirClose_Impl); + ADD_TEST(OS_DirRead_Impl); + ADD_TEST(OS_DirRewind_Impl); + ADD_TEST(OS_DirRemove_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-files.c b/src/unit-test-coverage/vxworks/src/coveragetest-files.c new file mode 100644 index 000000000..806638cc6 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-files.c @@ -0,0 +1,75 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-files.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-files.h" + +#include "osapi-file-impl.h" + +#include +#include +#include +#include +#include + +void Test_OS_VxWorks_StreamAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_Works_StreamAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_StreamAPI_Impl_Init(), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_StreamAPI_Impl_Init); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c similarity index 84% rename from src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c rename to src/unit-test-coverage/vxworks/src/coveragetest-filesys.c index 04c1d55c2..95234edeb 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfilesys.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-filesys.c @@ -1,29 +1,28 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osfilesys-common" file - * - * Notes: - * + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * */ -/* - * Includes +/** + * \file coveragetest-osfilesys.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * */ #include "os-vxworks-coveragetest.h" -#include "ut-osfilesys.h" +#include "ut-adaptor-filesys.h" + +#include "osapi-filesys-impl.h" #include #include @@ -80,7 +79,7 @@ void Test_OS_FileSysStopVolume_Impl(void) OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(0), OS_SUCCESS); /* Failure to delete XBD layer */ - Osapi_Internal_SetupFileSysEntry(1, NULL, 1, 4); + UT_FileSysTest_SetupFileSysEntry(1, NULL, 1, 4); OSAPI_TEST_FUNCTION_RC(OS_FileSysStopVolume_Impl(1), OS_SUCCESS); UtAssert_True(UT_GetStubCount(UT_KEY(OCS_xbdBlkDevDelete)) == 1, "xbdBlkDevDelete() called"); } @@ -161,24 +160,28 @@ void Test_OS_FileSysCheckVolume_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + memset(OS_filesys_table, 0, sizeof(OS_filesys_table)); + memset(OS_global_filesys_table, 0, sizeof(OS_common_record_t) * OS_MAX_FILE_SYSTEMS); + + memset(UT_Ref_OS_impl_filesys_table, 0, UT_Ref_OS_impl_filesys_table_SIZE); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-heap.c b/src/unit-test-coverage/vxworks/src/coveragetest-heap.c new file mode 100644 index 000000000..12d577859 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-heap.c @@ -0,0 +1,76 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-heap.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "osapi-heap-impl.h" + +#include + + +void Test_OS_HeapGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_HeapGetInfo_Impl(OS_heap_prop_t *heap_prop) + */ + OS_heap_prop_t heap_prop; + + memset(&heap_prop, 0xEE, sizeof(heap_prop)); + OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_memPartInfoGet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_HeapGetInfo_Impl(&heap_prop), OS_ERROR); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_HeapGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c new file mode 100644 index 000000000..57cf5a7d5 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-idmap.c @@ -0,0 +1,119 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-idmap.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-idmap.h" + +#include "osapi-idmap-impl.h" + +#include +#include + +OCS_SEM TestGlobalSem; + + +void Test_OS_Lock_Global_Impl(void) +{ + /* + * Test Case For: + * int32 OS_Lock_Global_Impl(uint32 idtype) + */ + OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(10000), OS_ERROR); + + /* + * Confirm that if vxid is 0/NULL that the function returns error + * and does not call semTake. + */ + UT_IdMapTest_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, (OCS_SEM_ID)0); + OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 0, "semTake() NOT called"); + + UT_IdMapTest_SetImplTableMutex(OS_OBJECT_TYPE_OS_TASK, &TestGlobalSem); + OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_semTake)) == 1, "semTake() called"); + + UT_SetForceFail(UT_KEY(OCS_semTake), -1); + OSAPI_TEST_FUNCTION_RC(OS_Lock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); +} + +void Test_OS_Unlock_Global_Impl(void) +{ + /* + * Test Case For: + * int32 OS_Unlock_Global_Impl(uint32 idtype) + */ + OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(10000), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(0), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_semGive), -1); + OSAPI_TEST_FUNCTION_RC(OS_Unlock_Global_Impl(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); +} + +void Test_OS_API_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_API_Impl_Init(uint32 idtype) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(0), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_semMInitialize), -1); + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_semMInitialize)); + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TableMutex_Init(OS_OBJECT_TYPE_OS_TASK), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_Lock_Global_Impl); + ADD_TEST(OS_Unlock_Global_Impl); + ADD_TEST(OS_API_Impl_Init); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c similarity index 51% rename from src/unit-test-coverage/vxworks/src/coveragetest-osloader.c rename to src/unit-test-coverage/vxworks/src/coveragetest-loader.c index 3ea20b6e3..6b24ed466 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osloader.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-loader.c @@ -1,29 +1,27 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. - * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. - */ - -/* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osloader-common" file - * - * Notes: - * + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * */ -/* - * Includes +/** + * \file coveragetest-osloader.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * */ - #include "os-vxworks-coveragetest.h" -#include "ut-osloader.h" +#include "ut-adaptor-loader.h" + +#include "osapi-module-impl.h" #include #include @@ -38,36 +36,7 @@ void Test_OS_VxWorks_ModuleAPI_Impl_Init(void) /* Test Case For: * int32 OS_VxWorks_ModuleAPI_Impl_Init(void) */ - OSAPI_TEST_FUNCTION_RC(OS_VxWorks_ModuleAPI_Impl_Init(), OS_SUCCESS); -} - -void Test_OS_SymbolLookup_Impl(void) -{ - /* Test Case For: - * int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) - */ - cpuaddr SymAddr; - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); - UT_SetForceFail(UT_KEY(OCS_symFindByName), OCS_ERROR); - OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); -} - -void Test_OS_SymTableIterator_Impl(void) -{ - /* Test Case For: - * BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, int arg, SYM_GROUP group) - */ - uint32 Data = 0; - - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), true); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,101), false); - UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_SYM_LEN + 10); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), false); - UT_ClearForceFail(UT_KEY(OCS_strlen)); - UT_SetForceFail(UT_KEY(OCS_write), -1); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallIteratorFunc("ut",&Data,100,1000), false); - UT_ClearForceFail(UT_KEY(OCS_write)); + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_ModuleAPI_Impl_Init(), OS_SUCCESS); } void Test_OS_ModuleLoad_Impl(void) @@ -117,37 +86,31 @@ void Test_OS_ModuleGetInfo_Impl(void) UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); } -void Test_OS_SymbolTableDump_Impl(void) -{ - /* Test Case For: - * int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) - */ - OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_SUCCESS); - UT_SetForceFail(UT_KEY(OCS_open), -1); - OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_ERROR); - UT_ClearForceFail(UT_KEY(OCS_open)); -} - /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); + + memset(OS_module_table, 0, sizeof(OS_module_table)); + memset(OS_global_module_table, 0, sizeof(OS_common_record_t) * OS_MAX_MODULES); + + memset(UT_Ref_OS_impl_module_table, 0, UT_Ref_OS_impl_module_table_SIZE); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } @@ -161,12 +124,9 @@ void Osapi_TearDown(void) void UtTest_Setup(void) { ADD_TEST(OS_VxWorks_ModuleAPI_Impl_Init); - ADD_TEST(OS_SymTableIterator_Impl); - ADD_TEST(OS_SymbolLookup_Impl); ADD_TEST(OS_ModuleLoad_Impl); ADD_TEST(OS_ModuleUnload_Impl); ADD_TEST(OS_ModuleGetInfo_Impl); - ADD_TEST(OS_SymbolTableDump_Impl); } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c new file mode 100644 index 000000000..2a9c3ca51 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-mutex.c @@ -0,0 +1,124 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-mutex.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-mutex.h" +#include "osapi-mutex-impl.h" + +void Test_OS_VxWorks_MutexAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_MutexAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_MutexAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_MutSemCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_MutSemCreate_Impl (uint32 sem_id, uint32 options) + */ + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_semMInitialize), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_MutSemCreate_Impl(0,0), OS_SEM_FAILURE); +} + +void Test_OS_MutSemDelete_Impl(void) +{ + /* + * Test Case For: + * int32 OS_MutSemDelete_Impl (uint32 sem_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_MutSemDelete_Impl(0), OS_SUCCESS); +} + +void Test_OS_MutSemGive_Impl(void) +{ + /* + * Test Case For: + * int32 OS_MutSemGive_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_MutSemGive_Impl(0), OS_SUCCESS); +} + +void Test_OS_MutSemTake_Impl(void) +{ + /* + * Test Case For: + * int32 OS_MutSemTake_Impl ( uint32 sem_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_MutSemTake_Impl(0), OS_SUCCESS); +} + +void Test_OS_MutSemGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) + */ + OS_mutex_prop_t mut_prop; + memset(&mut_prop, 0xEE, sizeof(mut_prop)); + OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(0,&mut_prop), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_MutexAPI_Impl_Init); + ADD_TEST(OS_MutSemCreate_Impl); + ADD_TEST(OS_MutSemDelete_Impl); + ADD_TEST(OS_MutSemGive_Impl); + ADD_TEST(OS_MutSemTake_Impl); + ADD_TEST(OS_MutSemGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-network.c b/src/unit-test-coverage/vxworks/src/coveragetest-network.c new file mode 100644 index 000000000..ef3bc5aee --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-network.c @@ -0,0 +1,103 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-network.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" + +#include "osapi-network-impl.h" + +#include +#include + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetHostName_Impl + * + * Purpose: Implemented per internal OSAL API + * See description in os-impl.h for argument/return detail + * + *-----------------------------------------------------------------*/ +void Test_OS_NetworkGetHostName_Impl(void) + +{ + /* + * Test Case For: + * int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) + */ + char buffer[16]; + + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName_Impl(buffer, sizeof(buffer)), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_gethostname), -1); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetHostName_Impl(buffer, sizeof(buffer)), OS_ERROR); + +} /* end OS_NetworkGetHostName_Impl */ + + +void Test_OS_NetworkGetID_Impl(void) + +{ + /* + * Test Case For: + * int32 OS_NetworkGetID_Impl (int32 *IdBuf) + */ + int32 IdBuf; + + UT_SetForceFail(UT_KEY(OCS_hostGetByName), 1234); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_SUCCESS); + UtAssert_True(IdBuf == 1234, "IdBuf (%ld) == 1234", (long)IdBuf); + UT_SetForceFail(UT_KEY(OCS_hostGetByName), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_NetworkGetID_Impl(&IdBuf), OS_ERROR); +} /* end OS_NetworkGetID_Impl */ + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_NetworkGetID_Impl); + ADD_TEST(OS_NetworkGetHostName_Impl); +} + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c new file mode 100644 index 000000000..171947813 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-no-module.c @@ -0,0 +1,132 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-osloader.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-no-module.h" + +#include +#include +#include +#include +#include +#include +#include + +void Test_OS_VxWorks_ModuleAPI_Impl_Init(void) +{ + /* Test Case For: + * int32 OS_VxWorks_ModuleAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_ModuleAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_ModuleLoad_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleLoad_Impl ( uint32 module_id, char *translated_path ) + */ + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_open)); + UT_SetForceFail(UT_KEY(OCS_loadModule), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleLoad_Impl(0,"local"), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_loadModule)); +} + +void Test_OS_ModuleUnload_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleUnload_Impl ( uint32 module_id ) + */ + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_unldByModuleId), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleUnload_Impl(0), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_unldByModuleId)); +} + +void Test_OS_ModuleGetInfo_Impl(void) +{ + /* Test Case For: + * int32 OS_ModuleGetInfo_Impl ( uint32 module_id, OS_module_prop_t *module_prop ) + */ + OS_module_prop_t module_prop; + + memset(&module_prop, 0, sizeof(module_prop)); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0,&module_prop), OS_SUCCESS); + UtAssert_True(module_prop.addr.valid, "addresses in output valid"); + + /* + * Note this still returns SUCCESS if the underlying call fails, + * but the boolean in the output struct should be false. + */ + memset(&module_prop, 0, sizeof(module_prop)); + UT_SetForceFail(UT_KEY(OCS_moduleInfoGet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_ModuleGetInfo_Impl(0,&module_prop), OS_SUCCESS); + UT_ClearForceFail(UT_KEY(OCS_moduleInfoGet)); + UtAssert_True(!module_prop.addr.valid, "addresses in output not valid"); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + + + memset(&OS_SharedGlobalVars, 0, sizeof(OS_SharedGlobalVars)); + memset(OS_module_table, 0, sizeof(OS_module_table)); + memset(OS_global_module_table, 0, sizeof(OS_common_record_t) * OS_MAX_MODULES); + + memset(UT_Ref_OS_impl_module_table, 0, UT_Ref_OS_impl_module_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_ModuleAPI_Impl_Init); + ADD_TEST(OS_ModuleLoad_Impl); + ADD_TEST(OS_ModuleUnload_Impl); + ADD_TEST(OS_ModuleGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c index e37cba1cd..fa5e942ef 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osapi.c @@ -1,11 +1,22 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-osapi.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. */ /* @@ -567,9 +578,9 @@ void Test_OS_MutSemGetInfo_Impl(void) { /* * Test Case For: - * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mut_sem_prop_t *mut_prop) + * int32 OS_MutSemGetInfo_Impl (uint32 sem_id, OS_mutex_prop_t *mut_prop) */ - OS_mut_sem_prop_t mut_prop; + OS_mutex_prop_t mut_prop; memset(&mut_prop, 0xEE, sizeof(mut_prop)); OSAPI_TEST_FUNCTION_RC(OS_MutSemGetInfo_Impl(0,&mut_prop), OS_SUCCESS); } @@ -637,24 +648,24 @@ void Test_OS_FPUExcGetMask_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); Osapi_Internal_ResetState(); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c index b7deec7b8..ab77e064b 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-osfileapi.c @@ -1,11 +1,22 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-osfileapi.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. */ /* @@ -151,23 +162,23 @@ void Test_OS_ShellOutputToFile_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-queues.c b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c new file mode 100644 index 000000000..fe9a56929 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-queues.c @@ -0,0 +1,169 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-queues.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/* + * Filename: osapi_testcase_common.c + * + * Purpose: This file contains unit test cases for items in the "osapi-common" file + * + * Notes: + * + */ + + +/* + * Includes + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-queues.h" +#include "osapi-queue-impl.h" + +#include +#include + +void Test_OS_VxWorks_QueueAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_QueueAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_QueueAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_QueueCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_QueueCreate_Impl (uint32 queue_id, uint32 flags) + */ + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0,0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQCreate), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueCreate_Impl(0,0), OS_ERROR); +} + +void Test_OS_QueueDelete_Impl(void) +{ + /* + * Test Case For: + * int32 OS_QueueDelete_Impl (uint32 queue_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQDelete), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_QueueDelete_Impl(0), OS_ERROR); +} + +void Test_OS_QueueGet_Impl(void) +{ + /* + * Test Case For: + * int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, int32 timeout) + */ + char Data[16]; + uint32 ActSz; + + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_PEND), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, 100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQReceive), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_TIMEOUT; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_TIMEOUT); + OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_QUEUE_EMPTY); + OCS_errno = 0; + OSAPI_TEST_FUNCTION_RC(OS_QueueGet_Impl(0, &Data, sizeof(Data), &ActSz, OS_CHECK), OS_ERROR); +} + +void Test_OS_QueuePut_Impl(void) +{ + /* + * Test Case For: + * int32 OS_QueuePut_Impl (uint32 queue_id, const void *data, uint32 size, uint32 flags) + */ + char Data[16] = "Test"; + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_msgQSend), OCS_ERROR); + OCS_errno = OCS_S_objLib_OBJ_UNAVAILABLE; + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_QUEUE_FULL); + OCS_errno = 0; + OSAPI_TEST_FUNCTION_RC(OS_QueuePut_Impl(0, Data, sizeof(Data), 0), OS_ERROR); +} + +void Test_OS_QueueGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_QueueGetInfo_Impl (uint32 queue_id, OS_queue_prop_t *queue_prop) + */ + OS_queue_prop_t queue_prop; + memset(&queue_prop, 0xEE, sizeof(queue_prop)); + OSAPI_TEST_FUNCTION_RC(OS_QueueGetInfo_Impl(0,&queue_prop), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + + memset(OS_queue_table, 0, sizeof(OS_queue_table)); + memset(OS_global_queue_table, 0, sizeof(OS_common_record_t) * OS_MAX_QUEUES); + + memset(UT_Ref_OS_impl_queue_table, 0, UT_Ref_OS_impl_queue_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_QueueAPI_Impl_Init); + ADD_TEST(OS_QueueCreate_Impl); + ADD_TEST(OS_QueueDelete_Impl); + ADD_TEST(OS_QueueGet_Impl); + ADD_TEST(OS_QueuePut_Impl); + ADD_TEST(OS_QueueGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-shell.c b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c new file mode 100644 index 000000000..e2580578a --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-shell.c @@ -0,0 +1,90 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-shell.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-filetable-stub.h" +#include "osapi-file-impl.h" + +#include +#include + +void Test_OS_ShellOutputToFile_Impl(void) +{ + /* + * Test Case For: + * int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) + */ + int32 expected = OS_SUCCESS; + int32 actual; + + /* + * The ShellOutputToFile will loop until the + * taskNameToId() function returns ERROR, so this + * must be set to avoid getting into an endless loop. + */ + UT_SetDeferredRetcode(UT_KEY(OCS_taskNameToId), 2, -1); + + actual = OS_ShellOutputToFile_Impl(0, "TestCmd"); + + UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_SUCCESS", (long)actual); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_shellGenericInit)) == 1, "shellGenericInit() called"); + + /* failure to open the output file */ + UT_SetForceFail(UT_KEY(OS_creat), OS_ERROR); + expected = OS_ERROR; + actual = OS_ShellOutputToFile_Impl(0, "TestCmd"); + UtAssert_True(actual == expected, "OS_ShellOutputToFile_Impl() (%ld) == OS_ERROR", (long)actual); +} + +/* ------------------- End of test cases --------------------------------------*/ + + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + memset(UT_FileTableTest_OS_impl_filehandle_table, 0, UT_FileTableTest_OS_impl_filehandle_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_ShellOutputToFile_Impl); +} + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c new file mode 100644 index 000000000..75889dac9 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-symtab.c @@ -0,0 +1,107 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-osloader.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-symtab.h" +#include "osapi-module-impl.h" + +#include +#include +#include +#include + +void Test_OS_SymbolLookup_Impl(void) +{ + /* Test Case For: + * int32 OS_SymbolLookup_Impl( cpuaddr *SymbolAddress, const char *SymbolName ) + */ + cpuaddr SymAddr; + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(NULL, NULL), OS_INVALID_POINTER); + UT_SetForceFail(UT_KEY(OCS_symFind), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_SymbolLookup_Impl(&SymAddr, "symname"), OS_ERROR); +} + +void Test_OS_SymTableIterator_Impl(void) +{ + /* Test Case For: + * BOOL OS_SymTableIterator_Impl(char *name, SYM_VALUE val, SYM_TYPE type, int arg, SYM_GROUP group) + */ + uint32 Data = 0; + + OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut",&Data,100,1000), true); + OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut",&Data,100,101), false); + UT_SetForceFail(UT_KEY(OCS_strlen), OS_MAX_SYM_LEN + 10); + OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut",&Data,100,1000), false); + UT_ClearForceFail(UT_KEY(OCS_strlen)); + UT_SetForceFail(UT_KEY(OCS_write), -1); + OSAPI_TEST_FUNCTION_RC(UT_SymTabTest_CallIteratorFunc("ut",&Data,100,1000), false); + UT_ClearForceFail(UT_KEY(OCS_write)); +} + +void Test_OS_SymbolTableDump_Impl(void) +{ + /* Test Case For: + * int32 OS_SymbolTableDump_Impl ( const char *filename, uint32 SizeLimit ) + */ + OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_SUCCESS); + UT_SetForceFail(UT_KEY(OCS_open), -1); + OSAPI_TEST_FUNCTION_RC(OS_SymbolTableDump_Impl("file",10000), OS_ERROR); + UT_ClearForceFail(UT_KEY(OCS_open)); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_SymTableIterator_Impl); + ADD_TEST(OS_SymbolLookup_Impl); + ADD_TEST(OS_SymbolTableDump_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c new file mode 100644 index 000000000..bb9477d65 --- /dev/null +++ b/src/unit-test-coverage/vxworks/src/coveragetest-tasks.c @@ -0,0 +1,242 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-tasks.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +#include "os-vxworks-coveragetest.h" +#include "ut-adaptor-tasks.h" + +#include "osapi-task-impl.h" +//jphfix #include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" + +#include + +/* + * A chunk of memory usable as a heap for malloc() emulation + */ +unsigned long TestHeap[4096]; +int TestGlobalSem; + +void Test_OS_VxWorks_TaskAPI_Impl_Init(void) +{ + /* + * Test Case For: + * int32 OS_VxWorks_TaskAPI_Impl_Init(void) + */ + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TaskAPI_Impl_Init(), OS_SUCCESS); +} + +void Test_OS_VxWorksEntry(void) +{ + /* + * Test Case For: + * static int OS_VxWorksEntry(int arg) + */ + OSAPI_TEST_FUNCTION_RC(UT_TaskTest_CallEntryPoint(0),OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OS_TaskEntryPoint)) == 1, "OS_TaskEntryPoint() called"); +} + +void Test_OS_TaskCreate_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskCreate_Impl (uint32 task_id, uint32 flags) + */ + UT_SetDataBuffer(UT_KEY(OCS_malloc), TestHeap, sizeof(TestHeap), false); + UT_SetDataBuffer(UT_KEY(OCS_free), TestHeap, sizeof(TestHeap), false); + + /* create task with stack size of 250 - this should invoke malloc() to get the stack. + * The first call checks the failure path and ensures that a malloc failure gets handled */ + OS_task_table[0].stack_size = 250; + UT_SetForceFail(UT_KEY(OCS_malloc), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0,0), OS_ERROR); + + UT_ClearForceFail(UT_KEY(OCS_malloc)); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0,OS_FP_ENABLED), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 1, "taskInit() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 1, "taskActivate() called"); + + /* create again with smaller stack - this should re-use existing buffer */ + OS_task_table[0].stack_size = 100; + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0,OS_FP_ENABLED), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 2, "malloc() not called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 0, "free() not called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 2, "taskInit() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 2, "taskActivate() called"); + + /* create again with larger stack - this should free existing and malloc() new buffer */ + OS_task_table[0].stack_size = 400; + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0,OS_FP_ENABLED), OS_SUCCESS); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_malloc)) == 3, "malloc() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_free)) == 1, "free() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskInit)) == 3, "taskInit() called"); + UtAssert_True(UT_GetStubCount(UT_KEY(OCS_taskActivate)) == 3, "taskActivate() called"); + + + /* other failure modes */ + UT_SetForceFail(UT_KEY(OCS_taskInit), -1); + OSAPI_TEST_FUNCTION_RC(OS_TaskCreate_Impl(0,0), OS_ERROR); + +} + +void Test_OS_TaskMatch_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskMatch_Impl(uint32 task_id) + */ + UT_TaskTest_SetImplTaskId(0, OCS_taskIdSelf()); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(0), OS_SUCCESS); + UT_TaskTest_SetImplTaskId(0, (OCS_TASK_ID)0); + OSAPI_TEST_FUNCTION_RC(OS_TaskMatch_Impl(0), OS_ERROR); +} + +void Test_OS_TaskDelete_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskDelete_Impl (uint32 task_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(0), OS_SUCCESS); + + /* failure mode */ + UT_SetForceFail(UT_KEY(OCS_taskDelete), -1); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelete_Impl(0), OS_ERROR); +} + +void Test_OS_TaskExit_Impl(void) +{ + /* + * Test Case For: + * void OS_TaskExit_Impl() + */ + /* just call the function for coverage */ + OS_TaskExit_Impl(); +} + +void Test_OS_TaskDelay_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskDelay_Impl(uint32 millisecond) + */ + OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_taskDelay), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskDelay_Impl(100), OS_ERROR); +} + +void Test_OS_TaskSetPriority_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskSetPriority_Impl (uint32 task_id, uint32 new_priority) + */ + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_SUCCESS); + + UT_SetForceFail(UT_KEY(OCS_taskPrioritySet), OCS_ERROR); + OSAPI_TEST_FUNCTION_RC(OS_TaskSetPriority_Impl(0, 100), OS_ERROR); +} + +void Test_OS_TaskRegister_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskRegister_Impl(uint32 global_task_id) + */ + OSAPI_TEST_FUNCTION_RC(OS_TaskRegister_Impl(0), OS_SUCCESS); +} + +void Test_OS_TaskGetId_Impl(void) +{ + /* + * Test Case For: + * uint32 OS_TaskGetId_Impl (void) + */ + OCS_WIND_TCB *TaskTcb; + + OS_global_task_table[1].active_id = 0x12345; + TaskTcb = UT_TaskTest_GetTaskTcb(1); + UT_SetDataBuffer(UT_KEY(OCS_taskTcb), &TaskTcb, sizeof(TaskTcb), false); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetId_Impl(), 0x12345); +} + +void Test_OS_TaskGetInfo_Impl(void) +{ + /* + * Test Case For: + * int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) + */ + OS_task_prop_t task_prop; + memset(&task_prop, 0xEE, sizeof(task_prop)); + OSAPI_TEST_FUNCTION_RC(OS_TaskGetInfo_Impl(0,&task_prop), OS_SUCCESS); +} + + +/* ------------------- End of test cases --------------------------------------*/ + +/* Osapi_Test_Setup + * + * Purpose: + * Called by the unit test tool to set up the app prior to each test + */ +void Osapi_Test_Setup(void) +{ + UT_ResetState(0); + memset(OS_task_table, 0, sizeof(OS_task_table)); + memset(OS_global_task_table, 0, sizeof(OS_common_record_t) * OS_MAX_TASKS); + + memset(UT_Ref_OS_impl_task_table, 0, UT_Ref_OS_impl_task_table_SIZE); +} + +/* + * Osapi_Test_Teardown + * + * Purpose: + * Called by the unit test tool to tear down the app after each test + */ +void Osapi_Test_Teardown(void) +{ + +} + +/* UtTest_Setup + * + * Purpose: + * Registers the test cases to execute with the unit test tool + */ +void UtTest_Setup(void) +{ + ADD_TEST(OS_VxWorks_TaskAPI_Impl_Init); + ADD_TEST(OS_TaskCreate_Impl); + ADD_TEST(OS_VxWorksEntry); + ADD_TEST(OS_TaskMatch_Impl); + ADD_TEST(OS_TaskDelete_Impl); + ADD_TEST(OS_TaskExit_Impl); + ADD_TEST(OS_TaskDelay_Impl); + ADD_TEST(OS_TaskSetPriority_Impl); + ADD_TEST(OS_TaskRegister_Impl); + ADD_TEST(OS_TaskGetId_Impl); + ADD_TEST(OS_TaskGetInfo_Impl); +} + + diff --git a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c similarity index 72% rename from src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c rename to src/unit-test-coverage/vxworks/src/coveragetest-timebase.c index 0067c5035..9d5635407 100644 --- a/src/unit-test-coverage/vxworks/src/coveragetest-ostimer.c +++ b/src/unit-test-coverage/vxworks/src/coveragetest-timebase.c @@ -1,11 +1,22 @@ /* - * Copyright (c) 2019, United States government as represented by the - * administrator of the National Aeronautics Space Administration. - * All rights reserved. This software was created at NASA Goddard - * Space Flight Center pursuant to government contracts. + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file coveragetest-ostimer.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov * - * This is governed by the NASA Open Source Agreement and may be used, - * distributed and modified only according to the terms of that agreement. */ /* @@ -23,7 +34,8 @@ */ #include "os-vxworks-coveragetest.h" -#include "ut-ostimer.h" +#include "ut-adaptor-timebase.h" +#include "osapi-timebase-impl.h" #include #include @@ -37,9 +49,9 @@ void Test_OS_VxWorks_TimeBaseAPI_Impl_Init(void) /* Test Case For: * int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void) */ - OSAPI_TEST_FUNCTION_RC(OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_SUCCESS); + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_SUCCESS); UT_SetForceFail(UT_KEY(OCS_sysClkRateGet), -1); - OSAPI_TEST_FUNCTION_RC(OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_ERROR); + OSAPI_TEST_FUNCTION_RC(UT_Call_OS_VxWorks_TimeBaseAPI_Impl_Init(), OS_ERROR); } @@ -59,9 +71,9 @@ void Test_OS_TimeBaseUnlock_Impl(void) OS_TimeBaseUnlock_Impl(0); } -static int32 Osapi_Internal_TimeBaseRegHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) +static int32 UT_TimeBaseTest_TimeBaseRegHook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context) { - Osapi_Internal_SetTimeBaseRegState(0, true); + UT_TimeBaseTest_SetTimeBaseRegState(0, true); return 0; } @@ -81,13 +93,13 @@ void Test_OS_Impl_UsecToTimespec(void) struct OCS_timespec ts; memset(&ts, 255, sizeof(ts)); - Osapi_Internal_UsecToTimespec(1, &ts); + UT_TimeBaseTest_UsecToTimespec(1, &ts); UtAssert_True(ts.tv_sec == 0, "ts.tv_sec (%ld) == 0", (long)ts.tv_sec); UtAssert_True(ts.tv_nsec == 1000, "ts.tv_nsec (%ld) == 1000", (long)ts.tv_sec); memset(&ts, 255, sizeof(ts)); - Osapi_Internal_UsecToTimespec(1000000000, &ts); + UT_TimeBaseTest_UsecToTimespec(1000000000, &ts); UtAssert_True(ts.tv_sec == 1000, "ts.tv_sec (%ld) == 1000", (long)ts.tv_sec); UtAssert_True(ts.tv_nsec == 0, "ts.tv_nsec (%ld) == 0", (long)ts.tv_sec); } @@ -105,7 +117,7 @@ void Test_OS_TimeBaseCreate_Impl(void) * and therefore cause future calls to skip this block. */ OS_global_timebase_table[1].active_id = 0x1; - Osapi_Internal_Setup(1,OCS_SIGRTMIN, false); + UT_TimeBaseTest_Setup(1,OCS_SIGRTMIN, false); UT_SetForceFail(UT_KEY(OCS_sigismember), true); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_TIMER_ERR_UNAVAILABLE); UT_ResetState(UT_KEY(OCS_sigismember)); @@ -132,25 +144,25 @@ void Test_OS_TimeBaseCreate_Impl(void) * Using the hook function, this sets the global state to * mimic registration success */ - UT_SetHookFunction(UT_KEY(OCS_taskSpawn), Osapi_Internal_TimeBaseRegHook, NULL); + UT_SetHookFunction(UT_KEY(OCS_taskSpawn), UT_TimeBaseTest_TimeBaseRegHook, NULL); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseCreate_Impl(0), OS_SUCCESS); /* * For coverage, call the OS_VxWorks_TimeBaseTask() function. */ - Osapi_Internal_CallHelperTaskFunc(0); + UT_TimeBaseTest_CallHelperTaskFunc(0); /* * Check outputs of OS_VxWorks_RegisterTimer() function. */ - Osapi_Internal_ClearTimeBaseRegState(0); - Osapi_Internal_CallRegisterTimer(0); - UtAssert_True(Osapi_Internal_CheckTimeBaseRegisteredState(0), "timer successfully registered"); + UT_TimeBaseTest_ClearTimeBaseRegState(0); + UT_TimeBaseTest_CallRegisterTimer(0); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseRegisteredState(0), "timer successfully registered"); - Osapi_Internal_ClearTimeBaseRegState(0); + UT_TimeBaseTest_ClearTimeBaseRegState(0); UT_SetForceFail(UT_KEY(OCS_timer_create), -1); - Osapi_Internal_CallRegisterTimer(0); - UtAssert_True(Osapi_Internal_CheckTimeBaseErrorState(0), "timer registration failure state"); + UT_TimeBaseTest_CallRegisterTimer(0); + UtAssert_True(UT_TimeBaseTest_CheckTimeBaseErrorState(0), "timer registration failure state"); } void Test_OS_VxWorks_SigWait(void) @@ -169,17 +181,17 @@ void Test_OS_VxWorks_SigWait(void) memset(&config_value, 0, sizeof(config_value)); UT_SetDataBuffer(UT_KEY(OCS_timer_settime),&config_value,sizeof(config_value),false); UT_SetDataBuffer(UT_KEY(OCS_timer_gettime),&config_value,sizeof(config_value),false); - Osapi_Internal_Setup(0, signo, true); + UT_TimeBaseTest_Setup(0, signo, true); OS_TimeBaseSet_Impl(0, 1111111, 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 1111111); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 1111111); UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 2222222); UT_SetDataBuffer(UT_KEY(OCS_sigwait),&signo,sizeof(signo),false); - OSAPI_TEST_FUNCTION_RC(Osapi_Internal_CallSigWaitFunc(0), 2222222); + OSAPI_TEST_FUNCTION_RC(UT_TimeBaseTest_CallSigWaitFunc(0), 2222222); - Osapi_Internal_Setup(0, 0, false); + UT_TimeBaseTest_Setup(0, 0, false); OS_global_timebase_table[0].active_id = 0; OS_timebase_table[0].nominal_interval_time = 0; } @@ -191,7 +203,7 @@ void Test_OS_TimeBaseSet_Impl(void) */ OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_ERR_NOT_IMPLEMENTED); - Osapi_Internal_Setup(0, OCS_SIGRTMIN, false); + UT_TimeBaseTest_Setup(0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseSet_Impl(0,1,1), OS_SUCCESS); UT_SetForceFail(UT_KEY(OCS_timer_settime), -1); @@ -203,7 +215,7 @@ void Test_OS_TimeBaseDelete_Impl(void) /* Test Case For: * int32 OS_TimeBaseDelete_Impl(uint32 timer_id) */ - Osapi_Internal_Setup(0, OCS_SIGRTMIN, false); + UT_TimeBaseTest_Setup(0, OCS_SIGRTMIN, false); OSAPI_TEST_FUNCTION_RC(OS_TimeBaseDelete_Impl(0), OS_SUCCESS); } @@ -218,24 +230,28 @@ void Test_OS_TimeBaseGetInfo_Impl(void) /* ------------------- End of test cases --------------------------------------*/ -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void) +void Osapi_Test_Setup(void) { UT_ResetState(0); - Osapi_Internal_ResetState(); + + memset(OS_timebase_table, 0, sizeof(OS_timebase_table)); + memset(OS_global_timebase_table, 0, sizeof(OS_common_record_t) * OS_MAX_BIN_SEMAPHORES); + + memset(UT_Ref_OS_impl_timebase_table, 0, UT_Ref_OS_impl_timebase_table_SIZE); } /* - * Osapi_TearDown + * Osapi_Test_Teardown * * Purpose: * Called by the unit test tool to tear down the app after each test */ -void Osapi_TearDown(void) +void Osapi_Test_Teardown(void) { } diff --git a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h index 1790a8886..f9c7a8135 100644 --- a/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h +++ b/src/unit-test-coverage/vxworks/src/os-vxworks-coveragetest.h @@ -1,9 +1,21 @@ /* - * Filename: osapi_testcase_common.c - * - * Purpose: This file contains unit test cases for items in the "osloader-common" file - * - * Notes: + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file os-vxworks-coveragetest.h + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov * */ @@ -17,7 +29,9 @@ #include #include #include -#include + +//jphfix #include "osapi-common-impl.h" +#include "osapi-idmap-impl.h" #define OSAPI_TEST_FUNCTION_RC(func,exp) \ @@ -28,15 +42,16 @@ #func, (long)rcact, #exp, (long)rcexp); \ } -#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Task_Setup, Osapi_TearDown, #test) +#define ADD_TEST(test) UtTest_Add((Test_ ## test), Osapi_Test_Setup, Osapi_Test_Teardown, #test) -/* Osapi_Task_Setup +/* Osapi_Test_Setup * * Purpose: * Called by the unit test tool to set up the app prior to each test */ -void Osapi_Task_Setup(void); -void Osapi_TearDown(void); +void Osapi_Test_Setup(void); +void Osapi_Test_Teardown(void); + -#endif +#endif /* _OS_VXWORKS_COVERAGETEST_H_ */ diff --git a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt index ad1b64289..fd7a0c8a6 100644 --- a/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt +++ b/src/unit-test-coverage/vxworks/ut-stubs/CMakeLists.txt @@ -1,5 +1,13 @@ add_library(ut_vxworks_impl_stubs - src/osapi-impl-vxworks-stubs.c) - -list(APPEND OSALCOVERAGE_STUB_LIB_LIST ut_vxworks_impl_stubs) -set(OSALCOVERAGE_STUB_LIB_LIST ${OSALCOVERAGE_STUB_LIB_LIST} PARENT_SCOPE) + src/vxworks-os-impl-binsem-stubs.c + src/vxworks-os-impl-common-stubs.c + src/vxworks-os-impl-countsem-stubs.c + src/vxworks-os-impl-dir-stubs.c + src/vxworks-os-impl-file-stubs.c + src/vxworks-os-impl-idmap-stubs.c + src/vxworks-os-impl-module-stubs.c + src/vxworks-os-impl-mutex-stubs.c + src/vxworks-os-impl-queue-stubs.c + src/vxworks-os-impl-task-stubs.c + src/vxworks-os-impl-timer-stubs.c +) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/osapi-impl-vxworks-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/osapi-impl-vxworks-stubs.c deleted file mode 100644 index ac80f77bd..000000000 --- a/src/unit-test-coverage/vxworks/ut-stubs/src/osapi-impl-vxworks-stubs.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include -#include "utstubs.h" - - -UT_DEFAULT_STUB(OS_VxWorks_TimeBaseAPI_Impl_Init, (void)) -UT_DEFAULT_STUB(OS_VxWorks_ModuleAPI_Impl_Init, (void)) -UT_DEFAULT_STUB(OS_VxWorks_StreamAPI_Impl_Init, (void)) -UT_DEFAULT_STUB(OS_VxWorks_DirAPI_Impl_Init, (void)) - diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-binsem-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-binsem-stubs.c new file mode 100644 index 000000000..1e51370ba --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-binsem-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_BinSemAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c new file mode 100644 index 000000000..3a5dd2062 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-common-stubs.c @@ -0,0 +1,38 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include +#include + +UT_DEFAULT_STUB(OS_API_Impl_Init, (uint32 idtype)) + +int OS_VxWorks_GenericSemTake(OCS_SEM_ID vxid, int sys_ticks) +{ + return UT_DEFAULT_IMPL(OS_VxWorks_GenericSemTake); +} + +int OS_VxWorks_GenericSemGive(OCS_SEM_ID vxid) +{ + return UT_DEFAULT_IMPL(OS_VxWorks_GenericSemGive); +} diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-countsem-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-countsem-stubs.c new file mode 100644 index 000000000..7af6883b7 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-countsem-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_CountSemAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-dir-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-dir-stubs.c new file mode 100644 index 000000000..9b3c5c32e --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-dir-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_DirAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-file-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-file-stubs.c new file mode 100644 index 000000000..aa38d6925 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-file-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_StreamAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-idmap-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-idmap-stubs.c new file mode 100644 index 000000000..c599c7187 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-idmap-stubs.c @@ -0,0 +1,26 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +UT_DEFAULT_STUB(OS_VxWorks_TableMutex_Init, (uint32 idtype)) + diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-module-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-module-stubs.c new file mode 100644 index 000000000..9e692524c --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-module-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_ModuleAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-mutex-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-mutex-stubs.c new file mode 100644 index 000000000..a71ac4c60 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-mutex-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_MutexAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-queue-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-queue-stubs.c new file mode 100644 index 000000000..31ae561ac --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-queue-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_QueueAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-task-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-task-stubs.c new file mode 100644 index 000000000..1f3976041 --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-task-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_TaskAPI_Impl_Init, (void)) diff --git a/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-timer-stubs.c b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-timer-stubs.c new file mode 100644 index 000000000..deafc44ae --- /dev/null +++ b/src/unit-test-coverage/vxworks/ut-stubs/src/vxworks-os-impl-timer-stubs.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + * + * + */ + + +/** + * \file osapi-impl-vxworks-stubs.c + * \ingroup ut-stubs + * \author joseph.p.hickey@nasa.gov + * + */ +#include +#include +#include "utstubs.h" + +#include + +UT_DEFAULT_STUB(OS_VxWorks_TimeBaseAPI_Impl_Init, (void)) diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c index 8cbbbe37e..c14f77ede 100644 --- a/src/unit-tests/oscore-test/ut_oscore_mutex_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.c @@ -45,13 +45,13 @@ ** OS_SEM_FAILURE if the OS call failed ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_create_test() +void UT_os_mutex_create_test() { int i; int32 res = 0; const char* testDesc; - uint32 mut_sem_id; - uint32 mut_sem_id2; + uint32 mutex_id; + uint32 mutex_id2; char sem_name[UT_OS_NAME_BUFF_SIZE]; char long_sem_name[UT_OS_NAME_BUFF_SIZE]; uint32 test_setup_invalid = 0; @@ -59,15 +59,15 @@ void UT_os_mut_sem_create_test() /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_MutSemCreate(&mut_sem_id, "Good", 0 ); + res = OS_MutSemCreate(&mutex_id, "Good", 0 ); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_create_test_exit_tag; + goto UT_os_mutex_create_test_exit_tag; } /* Clean up */ - OS_MutSemDelete(mut_sem_id); + OS_MutSemDelete(mutex_id); /*-----------------------------------------------------*/ testDesc = "#1 Null-pointer-arg-1"; @@ -81,7 +81,7 @@ void UT_os_mut_sem_create_test() /*-----------------------------------------------------*/ testDesc = "#2 Null-pointer-arg-2"; - res = OS_MutSemCreate(&mut_sem_id, NULL, 0); + res = OS_MutSemCreate(&mutex_id, NULL, 0); if (res == OS_INVALID_POINTER) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -92,7 +92,7 @@ void UT_os_mut_sem_create_test() memset(long_sem_name, 'X', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name)-1] = '\0'; - res = OS_MutSemCreate(&mut_sem_id, long_sem_name, 0); + res = OS_MutSemCreate(&mutex_id, long_sem_name, 0); if (res == OS_ERR_NAME_TOO_LONG) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -106,7 +106,7 @@ void UT_os_mut_sem_create_test() { memset(sem_name, '\0', sizeof(sem_name)); UT_os_sprintf(sem_name, "MUTSEM%d",i); - res = OS_MutSemCreate(&mut_sem_id, sem_name, 0); + res = OS_MutSemCreate(&mutex_id, sem_name, 0); if ( res != OS_SUCCESS ) { testDesc = "#4 No-free-IDs - Mutex Create failed"; @@ -118,7 +118,7 @@ void UT_os_mut_sem_create_test() if ( test_setup_invalid == 0 ) { - res = OS_MutSemCreate(&mut_sem_id, "OneTooMany", 0); + res = OS_MutSemCreate(&mutex_id, "OneTooMany", 0); if (res == OS_ERR_NO_FREE_IDS) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -132,7 +132,7 @@ void UT_os_mut_sem_create_test() testDesc = "#5 Duplicate-name"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id2, "DUPLICATE", 0); + res = OS_MutSemCreate(&mutex_id2, "DUPLICATE", 0); if ( res != OS_SUCCESS ) { testDesc = "#5 Duplicate-name - Mutex Create failed"; @@ -140,14 +140,14 @@ void UT_os_mut_sem_create_test() } else { - res = OS_MutSemCreate(&mut_sem_id, "DUPLICATE", 0); + res = OS_MutSemCreate(&mutex_id, "DUPLICATE", 0); if (res == OS_ERR_NAME_TAKEN) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); /* Reset test environment */ - res = OS_MutSemDelete(mut_sem_id2); + res = OS_MutSemDelete(mutex_id2); } /*-----------------------------------------------------*/ @@ -158,16 +158,16 @@ void UT_os_mut_sem_create_test() /*-----------------------------------------------------*/ testDesc = "#7 Nominal"; - res = OS_MutSemCreate(&mut_sem_id, "Good", 0); + res = OS_MutSemCreate(&mutex_id, "Good", 0); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); /* Reset test environment */ - res = OS_MutSemDelete(mut_sem_id); + res = OS_MutSemDelete(mutex_id); -UT_os_mut_sem_create_test_exit_tag: +UT_os_mutex_create_test_exit_tag: return; } @@ -181,11 +181,11 @@ void UT_os_mut_sem_create_test() ** OS_SEM_FAILURE if the OS call failed ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_delete_test() +void UT_os_mutex_delete_test() { int32 res = 0; const char* testDesc; - uint32 mut_sem_id; + uint32 mutex_id; /*-----------------------------------------------------*/ testDesc = "API not implemented"; @@ -194,7 +194,7 @@ void UT_os_mut_sem_delete_test() if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_delete_test_exit_tag; + goto UT_os_mutex_delete_test_exit_tag; } /*-----------------------------------------------------*/ @@ -215,7 +215,7 @@ void UT_os_mut_sem_delete_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "DeleteTest", 0); + res = OS_MutSemCreate(&mutex_id, "DeleteTest", 0); if ( res != OS_SUCCESS ) { testDesc = "#3 Nominal - Mutex Create failed"; @@ -223,14 +223,14 @@ void UT_os_mut_sem_delete_test() } else { - res = OS_MutSemDelete(mut_sem_id); + res = OS_MutSemDelete(mutex_id); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); } -UT_os_mut_sem_delete_test_exit_tag: +UT_os_mutex_delete_test_exit_tag: return; } @@ -244,11 +244,11 @@ void UT_os_mut_sem_delete_test() ** array of semaphores defined by the system ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_give_test() +void UT_os_mutex_give_test() { int32 res = 0; const char* testDesc; - uint32 mut_sem_id; + uint32 mutex_id; /*-----------------------------------------------------*/ testDesc = "API not implemented"; @@ -257,7 +257,7 @@ void UT_os_mut_sem_give_test() if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_give_test_exit_tag; + goto UT_os_mutex_give_test_exit_tag; } /*-----------------------------------------------------*/ @@ -278,7 +278,7 @@ void UT_os_mut_sem_give_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GiveTest", 0); + res = OS_MutSemCreate(&mutex_id, "GiveTest", 0); if ( res != OS_SUCCESS ) { testDesc = "#3 Nominal - Mutex Create failed"; @@ -286,7 +286,7 @@ void UT_os_mut_sem_give_test() } else { - res = OS_MutSemTake(mut_sem_id); + res = OS_MutSemTake(mutex_id); if ( res != OS_SUCCESS ) { testDesc = "#3 Nominal - Mutex Take failed"; @@ -294,17 +294,17 @@ void UT_os_mut_sem_give_test() } else { - res = OS_MutSemGive(mut_sem_id); + res = OS_MutSemGive(mutex_id); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_MutSemDelete(mut_sem_id); + res = OS_MutSemDelete(mutex_id); } } -UT_os_mut_sem_give_test_exit_tag: +UT_os_mutex_give_test_exit_tag: return; } @@ -318,11 +318,11 @@ void UT_os_mut_sem_give_test() ** array of semaphores defined by the system ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_take_test() +void UT_os_mutex_take_test() { int32 res = 0; const char* testDesc; - uint32 mut_sem_id; + uint32 mutex_id; /*-----------------------------------------------------*/ testDesc = "API not implemented"; @@ -331,7 +331,7 @@ void UT_os_mut_sem_take_test() if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_take_test_exit_tag; + goto UT_os_mutex_take_test_exit_tag; } /*-----------------------------------------------------*/ @@ -352,7 +352,7 @@ void UT_os_mut_sem_take_test() testDesc = "#3 Nominal"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "TakeTest", 0); + res = OS_MutSemCreate(&mutex_id, "TakeTest", 0); if ( res != OS_SUCCESS ) { testDesc = "#3 Nominal - Mutex Create failed"; @@ -360,17 +360,17 @@ void UT_os_mut_sem_take_test() } else { - res = OS_MutSemTake(mut_sem_id); + res = OS_MutSemTake(mutex_id); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - OS_MutSemGive(mut_sem_id); - OS_MutSemDelete(mut_sem_id); + OS_MutSemGive(mutex_id); + OS_MutSemDelete(mutex_id); } -UT_os_mut_sem_take_test_exit_tag: +UT_os_mutex_take_test_exit_tag: return; } @@ -384,11 +384,11 @@ void UT_os_mut_sem_take_test() ** OS_ERR_NAME_NOT_FOUND if the name was not found in the mutex semaphore table ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_get_id_by_name_test() +void UT_os_mutex_get_id_by_name_test() { int32 res = 0; const char* testDesc; - uint32 mut_sem_id; + uint32 mutex_id; char long_sem_name[UT_OS_NAME_BUFF_SIZE]; /*-----------------------------------------------------*/ @@ -398,7 +398,7 @@ void UT_os_mut_sem_get_id_by_name_test() if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_get_id_by_name_test_exit_tag; + goto UT_os_mutex_get_id_by_name_test_exit_tag; } /*-----------------------------------------------------*/ @@ -413,7 +413,7 @@ void UT_os_mut_sem_get_id_by_name_test() /*-----------------------------------------------------*/ testDesc = "#2 Invalid-pointer-arg-2"; - res = OS_MutSemGetIdByName(&mut_sem_id, NULL); + res = OS_MutSemGetIdByName(&mutex_id, NULL); if ( res == OS_INVALID_POINTER ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -424,7 +424,7 @@ void UT_os_mut_sem_get_id_by_name_test() memset(long_sem_name, 'Y', sizeof(long_sem_name)); long_sem_name[sizeof(long_sem_name)-1] = '\0'; - res = OS_MutSemGetIdByName(&mut_sem_id, long_sem_name); + res = OS_MutSemGetIdByName(&mutex_id, long_sem_name); if ( res == OS_ERR_NAME_TOO_LONG ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -433,7 +433,7 @@ void UT_os_mut_sem_get_id_by_name_test() /*-----------------------------------------------------*/ testDesc = "#4 Name-not-found"; - res = OS_MutSemGetIdByName(&mut_sem_id, "NameNotFound"); + res = OS_MutSemGetIdByName(&mutex_id, "NameNotFound"); if ( res == OS_ERR_NAME_NOT_FOUND ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -442,7 +442,7 @@ void UT_os_mut_sem_get_id_by_name_test() testDesc = "#5 Nominal"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GetIDByName", 0); + res = OS_MutSemCreate(&mutex_id, "GetIDByName", 0); if ( res != OS_SUCCESS ) { testDesc = "#5 Nominal - Mutex Create failed"; @@ -450,16 +450,16 @@ void UT_os_mut_sem_get_id_by_name_test() } else { - res = OS_MutSemGetIdByName(&mut_sem_id, "GetIDByName"); + res = OS_MutSemGetIdByName(&mutex_id, "GetIDByName"); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_MutSemDelete(mut_sem_id); + res = OS_MutSemDelete(mutex_id); } -UT_os_mut_sem_get_id_by_name_test_exit_tag: +UT_os_mutex_get_id_by_name_test_exit_tag: return; } @@ -472,27 +472,27 @@ void UT_os_mut_sem_get_id_by_name_test() ** OS_ERR_INVALID_ID if the id passed in is not a valid binary semaphore id ** OS_SUCCESS if succeeded **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_get_info_test() +void UT_os_mutex_get_info_test() { int32 res = 0; const char* testDesc; - uint32 mut_sem_id; - OS_mut_sem_prop_t mut_sem_prop; + uint32 mutex_id; + OS_mutex_prop_t mutex_prop; /*-----------------------------------------------------*/ testDesc = "API not implemented"; - res = OS_MutSemGetInfo(0, &mut_sem_prop); + res = OS_MutSemGetInfo(0, &mutex_prop); if (res == OS_ERR_NOT_IMPLEMENTED) { UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_NA); - goto UT_os_mut_sem_get_info_test_exit_tag; + goto UT_os_mutex_get_info_test_exit_tag; } /*-----------------------------------------------------*/ testDesc = "#1 Invalid-ID-arg"; - res = OS_MutSemGetInfo(99999, &mut_sem_prop); + res = OS_MutSemGetInfo(99999, &mutex_prop); if ( res == OS_ERR_INVALID_ID ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else @@ -501,7 +501,7 @@ void UT_os_mut_sem_get_info_test() /*-----------------------------------------------------*/ testDesc = "#2 Invalid-pointer-arg"; - res = OS_MutSemCreate(&mut_sem_id, "InvalidPtr", 0); + res = OS_MutSemCreate(&mutex_id, "InvalidPtr", 0); if (res != OS_SUCCESS) { testDesc = "#2 Invalid-pointer-arg - Mutex Create failed"; @@ -509,20 +509,20 @@ void UT_os_mut_sem_get_info_test() } else { - res = OS_MutSemGetInfo(mut_sem_id, NULL); + res = OS_MutSemGetInfo(mutex_id, NULL); if ( res == OS_INVALID_POINTER ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - OS_MutSemDelete(mut_sem_id); + OS_MutSemDelete(mutex_id); } /*-----------------------------------------------------*/ testDesc = "#3 Nominal"; /* Setup */ - res = OS_MutSemCreate(&mut_sem_id, "GetInfo", 0); + res = OS_MutSemCreate(&mutex_id, "GetInfo", 0); if ( res != OS_SUCCESS ) { testDesc = "#3 Nominal - Mutex Create failed"; @@ -530,16 +530,16 @@ void UT_os_mut_sem_get_info_test() } else { - res = OS_MutSemGetInfo(mut_sem_id, &mut_sem_prop); + res = OS_MutSemGetInfo(mutex_id, &mutex_prop); if ( res == OS_SUCCESS ) UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_PASS); else UT_OS_TEST_RESULT( testDesc, UTASSERT_CASETYPE_FAILURE); - res = OS_MutSemDelete(mut_sem_id); + res = OS_MutSemDelete(mutex_id); } -UT_os_mut_sem_get_info_test_exit_tag: +UT_os_mutex_get_info_test_exit_tag: return; } diff --git a/src/unit-tests/oscore-test/ut_oscore_mutex_test.h b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h index 87e1a5c66..e599c0f3d 100644 --- a/src/unit-tests/oscore-test/ut_oscore_mutex_test.h +++ b/src/unit-tests/oscore-test/ut_oscore_mutex_test.h @@ -33,12 +33,12 @@ ** Function prototypes **--------------------------------------------------------------------------------*/ -void UT_os_mut_sem_create_test(void); -void UT_os_mut_sem_delete_test(void); -void UT_os_mut_sem_give_test(void); -void UT_os_mut_sem_take_test(void); -void UT_os_mut_sem_get_id_by_name_test(void); -void UT_os_mut_sem_get_info_test(void); +void UT_os_mutex_create_test(void); +void UT_os_mutex_delete_test(void); +void UT_os_mutex_give_test(void); +void UT_os_mutex_take_test(void); +void UT_os_mutex_get_id_by_name_test(void); +void UT_os_mutex_get_info_test(void); /*--------------------------------------------------------------------------------*/ diff --git a/src/unit-tests/oscore-test/ut_oscore_test.c b/src/unit-tests/oscore-test/ut_oscore_test.c index de57cefea..c0e4a85e9 100644 --- a/src/unit-tests/oscore-test/ut_oscore_test.c +++ b/src/unit-tests/oscore-test/ut_oscore_test.c @@ -191,12 +191,12 @@ void UtTest_Setup(void) UtTest_Add(UT_os_count_sem_get_id_by_name_test, NULL, NULL, "OS_CountSemGetIdByName"); UtTest_Add(UT_os_count_sem_get_info_test, NULL, NULL, "OS_CountSemGetInfo"); - UtTest_Add(UT_os_mut_sem_create_test, NULL, NULL, "OS_MutSemCreate"); - UtTest_Add(UT_os_mut_sem_delete_test, NULL, NULL, "OS_MutSemDelete"); - UtTest_Add(UT_os_mut_sem_give_test, NULL, NULL, "OS_MutSemGive"); - UtTest_Add(UT_os_mut_sem_take_test, NULL, NULL, "OS_MutSemTake"); - UtTest_Add(UT_os_mut_sem_get_id_by_name_test, NULL, NULL, "OS_MutSemGetIdByName"); - UtTest_Add(UT_os_mut_sem_get_info_test, NULL, NULL, "OS_MutSemGetInfo"); + UtTest_Add(UT_os_mutex_create_test, NULL, NULL, "OS_MutSemCreate"); + UtTest_Add(UT_os_mutex_delete_test, NULL, NULL, "OS_MutSemDelete"); + UtTest_Add(UT_os_mutex_give_test, NULL, NULL, "OS_MutSemGive"); + UtTest_Add(UT_os_mutex_take_test, NULL, NULL, "OS_MutSemTake"); + UtTest_Add(UT_os_mutex_get_id_by_name_test, NULL, NULL, "OS_MutSemGetIdByName"); + UtTest_Add(UT_os_mutex_get_info_test, NULL, NULL, "OS_MutSemGetInfo"); UtTest_Add(UT_os_queue_create_test, NULL, NULL, "OS_QueueCreate"); UtTest_Add(UT_os_queue_delete_test, NULL, NULL, "OS_QueueDelete"); diff --git a/src/ut-stubs/CMakeLists.txt b/src/ut-stubs/CMakeLists.txt index 0482c6580..e1291268c 100644 --- a/src/ut-stubs/CMakeLists.txt +++ b/src/ut-stubs/CMakeLists.txt @@ -42,7 +42,7 @@ add_library(ut_osapi_stubs STATIC # Some of the internal API definitions in stubs are based on # types/definitions in the os-impl.h internal header file. target_include_directories(ut_osapi_stubs PRIVATE - ${OSAL_SOURCE_DIR}/src/os/shared + ${OSAL_SOURCE_DIR}/src/os/shared/inc ) # These stubs must always link to UT Assert. diff --git a/src/ut-stubs/osapi-utstub-bsp.c b/src/ut-stubs/osapi-utstub-bsp.c new file mode 100644 index 000000000..7e3428c61 --- /dev/null +++ b/src/ut-stubs/osapi-utstub-bsp.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2004-2018, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Glenn + * Research Center pursuant to government contracts. + * + * This is governed by the NASA Open Source Agreement and may be used, + * distributed and modified only according to the terms of that agreement. + */ + +/** + * \file osapi_stubs.c + * + * Created on: Feb 25, 2015 + * Author: joseph.p.hickey@nasa.gov + * + * Stub implementations for the functions defined in the OSAL API + * + * The stub implementation can be used for unit testing applications built + * on top of OSAL. The stubs do not do any real function, but allow + * the return code to be crafted such that error paths in the application + * can be executed. + */ + +#include "utstub-helpers.h" + +/* + ********************************************************************************* + * PUBLIC API (application-callable functions) + ********************************************************************************* + */ + +/*---------------------------------------------------------------- + OS_BSP_GetArgC + See full description in header + ------------------------------------------------------------------*/ +uint32 OS_BSP_GetArgC(void) +{ + int32 status = UT_DEFAULT_IMPL(OS_BSP_GetArgC); + + return status; +} + +/*---------------------------------------------------------------- + OS_BSP_GetArgV + See full description in header + ------------------------------------------------------------------*/ +char * const * OS_BSP_GetArgV(void) +{ + void *buffer; + int32 status; + + status = UT_DEFAULT_IMPL(OS_BSP_GetArgV); + if (status == 0 && + UT_Stub_CopyToLocal(UT_KEY(OS_BSP_GetArgV), &buffer, sizeof(buffer)) < sizeof(buffer)) + { + buffer = NULL; + } + return buffer; +} + diff --git a/src/ut-stubs/osapi-utstub-idmap.c b/src/ut-stubs/osapi-utstub-idmap.c index caa89643d..35b55ae73 100644 --- a/src/ut-stubs/osapi-utstub-idmap.c +++ b/src/ut-stubs/osapi-utstub-idmap.c @@ -29,8 +29,8 @@ */ #include "utstub-helpers.h" -#include "os-impl.h" - +#include "osapi-idmap-impl.h" +//jphfix #include "osapi-common-impl.h" UT_DEFAULT_STUB(OS_ObjectIdInit,(void)) diff --git a/src/ut-stubs/osapi-utstub-mutex.c b/src/ut-stubs/osapi-utstub-mutex.c index 901ab0ef5..3523a3b58 100644 --- a/src/ut-stubs/osapi-utstub-mutex.c +++ b/src/ut-stubs/osapi-utstub-mutex.c @@ -198,7 +198,7 @@ int32 OS_MutSemGetIdByName (uint32 *sem_id, const char *sem_name) ** Returns OS_SUCCESS. ** ******************************************************************************/ -int32 OS_MutSemGetInfo(uint32 sem_id, OS_mut_sem_prop_t *mut_prop) +int32 OS_MutSemGetInfo(uint32 sem_id, OS_mutex_prop_t *mut_prop) { int32 status;