diff --git a/src/bsp/5020-vxworks7/CMakeLists.txt b/src/bsp/5020-vxworks7/CMakeLists.txt new file mode 100644 index 000000000..ba70dc6af --- /dev/null +++ b/src/bsp/5020-vxworks7/CMakeLists.txt @@ -0,0 +1,27 @@ +###################################################################### +# +# CMAKE build recipe for MCP750 Board Support Package (BSP) +# +###################################################################### + +add_library(osal_5020-vxworks7_impl OBJECT + src/bsp_start.c + src/bsp_console.c +) + +target_include_directories(osal_5020-vxworks7_impl PUBLIC + $ENV{WIND_BASE}/target/h + #$ENV{WIND_BASE}/target/h/wrn/coreip + #$ENV{WIND_BASE}/target/config/mcp750 +) + +# NOTE: the __PPC__ and MCP750 macros are referenced in some system headers. +# therefore all code compiled for this platform should always define these symbols. +target_compile_definitions(osal_5020-vxworks7_impl PUBLIC + "__PPC__" + #"MCP750" +) + +# This BSP only works with "vxworks" OS layer. +# Confirming this reduces risk of accidental misconfiguration +set(OSAL_EXPECTED_OSTYPE "vxworks7" PARENT_SCOPE) diff --git a/src/bsp/5020-vxworks7/build_options.cmake b/src/bsp/5020-vxworks7/build_options.cmake new file mode 100644 index 000000000..d9b097934 --- /dev/null +++ b/src/bsp/5020-vxworks7/build_options.cmake @@ -0,0 +1,11 @@ +########################################################################## +# +# Build options for "mcp750-vxworks" BSP +# +########################################################################## + +# This indicates where to stage target binaries created during the build +set(OSAL_BSP_STAGING_INSTALL_DIR "CF:0") + +# The "-u" switch is required to ensure that "ldppc" pulls in the OS_BSPMain entry point +target_link_libraries(osal_bsp -uOS_BSPMain) diff --git a/src/bsp/5020-vxworks7/src/bsp.mak b/src/bsp/5020-vxworks7/src/bsp.mak new file mode 100644 index 000000000..f1ebaf8cd --- /dev/null +++ b/src/bsp/5020-vxworks7/src/bsp.mak @@ -0,0 +1,21 @@ +############################################################################### +# File: bsp.mak +# +# Purpose: +# Compile Board Support Package routines +# +# History: +# +############################################################################### + +# Subsystem produced by this makefile. +TARGET = bsp.o + +#============================================================================== +# Object files required to build subsystem. +OBJS = bsp_start.o bsp_voltab.o + +#============================================================================== +# Source files required to build subsystem; used to generate dependencies. +SOURCES = bsp_start.c bsp_voltab.c + diff --git a/src/bsp/5020-vxworks7/src/bsp_console.c b/src/bsp/5020-vxworks7/src/bsp_console.c new file mode 100644 index 000000000..710b1a007 --- /dev/null +++ b/src/bsp/5020-vxworks7/src/bsp_console.c @@ -0,0 +1,52 @@ +/****************************************************************************** +** File: bsp_console.c +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** OSAL BSP debug console abstraction +** +******************************************************************************/ + +#include +#include +#include + +#include "mcp750_bsp_internal.h" +#include "bsp-impl.h" + +/**************************************************************************************** + BSP CONSOLE IMPLEMENTATION FUNCTIONS + ****************************************************************************************/ + +/*---------------------------------------------------------------- + OS_BSP_ConsoleOutput_Impl + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) +{ + while (DataLen > 0) + { + putchar(*Str); + ++Str; + --DataLen; + } +} + +/*---------------------------------------------------------------- + OS_BSP_ConsoleSetMode_Impl() definition + See full description in header + ------------------------------------------------------------------*/ +void OS_BSP_ConsoleSetMode_Impl(uint32 ModeBits) +{ + /* ignored; not implemented */ +} + + diff --git a/src/bsp/5020-vxworks7/src/bsp_start.c b/src/bsp/5020-vxworks7/src/bsp_start.c new file mode 100644 index 000000000..6c47c4eaf --- /dev/null +++ b/src/bsp/5020-vxworks7/src/bsp_start.c @@ -0,0 +1,65 @@ +/****************************************************************************** +** File: bsp_start.c +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** Purpose: +** +** OSAL main entry point. +** +** History: +** +******************************************************************************/ + +/* +** Include Files +*/ +#include +#include + +#include "mcp750_bsp_internal.h" + +/****************************************************************************** +** Function: OS_BSPMain() +** +** Purpose: +** vxWorks/BSP Application entry point. +** +** Arguments: +** (none) +** +** Return: +** integer return code, with zero indicating normal exit, nonzero +** indicating an off-nominal condition +*/ + +int OS_BSPMain(void) +{ + /* + * Initially clear the global object (this contains return code) + */ + memset(&OS_BSP_Global, 0, sizeof(OS_BSP_Global)); + + /* + * Call application specific entry point. + * This should set up all user tasks and resources, then return + */ + OS_Application_Startup(); + + /* + * OS_Application_Run() implements the background task. + * The user application may provide this, or a default implementation + * is used which just calls OS_IdleLoop(). + */ + OS_Application_Run(); + + /* + * Return to shell with the current status code + */ + return OS_BSP_Global.AppStatus; +} diff --git a/src/bsp/5020-vxworks7/src/mcp750_bsp_internal.h b/src/bsp/5020-vxworks7/src/mcp750_bsp_internal.h new file mode 100644 index 000000000..7b6d84363 --- /dev/null +++ b/src/bsp/5020-vxworks7/src/mcp750_bsp_internal.h @@ -0,0 +1,27 @@ +/****************************************************************************** +** File: mcp750_bsp_internal.h +** +** +** This is governed by the NASA Open Source Agreement and may be used, +** distributed and modified only pursuant to the terms of that agreement. +** +** Copyright (c) 2004-2006, United States government as represented by the +** administrator of the National Aeronautics Space Administration. +** All rights reserved. +** +** +** Purpose: +** Header file for internal data to the MCP750 BSP +** +******************************************************************************/ + +#ifndef _MCP750_BSP_INTERNAL_H_ +#define _MCP750_BSP_INTERNAL_H_ + +/* +** OSAL includes +*/ +#include "osapi.h" +#include "bsp-impl.h" + +#endif /* _MCP750_BSP_INTERNAL_H_ */ diff --git a/src/bsp/generic-linux/src/bsp_console.c b/src/bsp/generic-linux/src/bsp_console.c index fecab0af9..8ff9689a0 100644 --- a/src/bsp/generic-linux/src/bsp_console.c +++ b/src/bsp/generic-linux/src/bsp_console.c @@ -86,7 +86,7 @@ void OS_BSP_ConsoleOutput_Impl(const char *Str, uint32 DataLen) break; } Str += WriteLen; - DataLen -= WriteLen; + DataLen -= (uint32)WriteLen; } } diff --git a/src/bsp/generic-linux/src/bsp_start.c b/src/bsp/generic-linux/src/bsp_start.c index 4106b010b..b98db5d19 100644 --- a/src/bsp/generic-linux/src/bsp_start.c +++ b/src/bsp/generic-linux/src/bsp_start.c @@ -69,7 +69,7 @@ void OS_BSP_Initialize(void) { if (fgets(buffer,sizeof(buffer),fp) != NULL) { - OS_BSP_Global.MaxQueueDepth = strtoul(buffer, NULL, 10); + OS_BSP_Global.MaxQueueDepth = (uint32)strtoul(buffer, NULL, 10); BSP_DEBUG("Maximum user msg queue depth = %u\n", (unsigned int)OS_BSP_Global.MaxQueueDepth); } fclose(fp); @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) * might still want to use library "getopt" and this expects the * first parameter to be this way. */ - OS_BSP_Global.ArgC = argc; + OS_BSP_Global.ArgC = (uint32)argc; OS_BSP_Global.ArgV = argv; /* diff --git a/src/os/portable/os-impl-bsd-select.c b/src/os/portable/os-impl-bsd-select.c index 136600c3e..919f43603 100644 --- a/src/os/portable/os-impl-bsd-select.c +++ b/src/os/portable/os-impl-bsd-select.c @@ -140,7 +140,7 @@ static void OS_FdSet_ConvertOut_Impl(fd_set *output, OS_FdSet *Input) osfd = OS_impl_filehandle_table[id].fd; if (osfd < 0 || !FD_ISSET(osfd, output)) { - Input->object_ids[offset] &= ~(1 << bit); + Input->object_ids[offset] &= (uint8)~(1 << bit); } } ++bit; @@ -285,11 +285,11 @@ int32 OS_SelectSingle_Impl(uint32 stream_id, uint32 *SelectFlags, int32 msecs) { if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &rd_set)) { - *SelectFlags &= ~OS_STREAM_STATE_READABLE; + *SelectFlags &= (uint32)~OS_STREAM_STATE_READABLE; } if (!FD_ISSET(OS_impl_filehandle_table[stream_id].fd, &wr_set)) { - *SelectFlags &= ~OS_STREAM_STATE_WRITABLE; + *SelectFlags &= (uint32)~OS_STREAM_STATE_WRITABLE; } } else diff --git a/src/os/portable/os-impl-bsd-sockets.c b/src/os/portable/os-impl-bsd-sockets.c index d7eb1b586..108e0188f 100644 --- a/src/os/portable/os-impl-bsd-sockets.c +++ b/src/os/portable/os-impl-bsd-sockets.c @@ -428,7 +428,7 @@ int32 OS_SocketRecvFrom_Impl(uint32 sock_id, void *buffer, uint32 buflen, OS_Soc } else { - os_result = recvfrom(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, waitflags, sa, &addrlen); + os_result = (int)recvfrom(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, waitflags, sa, &addrlen); if (os_result < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) @@ -493,7 +493,7 @@ int32 OS_SocketSendTo_Impl(uint32 sock_id, const void *buffer, uint32 buflen, co return OS_ERR_BAD_ADDRESS; } - os_result = sendto(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); + os_result = (int)sendto(OS_impl_filehandle_table[sock_id].fd, buffer, buflen, MSG_DONTWAIT, sa, addrlen); if (os_result < 0) { OS_DEBUG("sendto: %s\n",strerror(errno)); diff --git a/src/os/portable/os-impl-console-bsp.c b/src/os/portable/os-impl-console-bsp.c index 336a8d9d1..377190a04 100644 --- a/src/os/portable/os-impl-console-bsp.c +++ b/src/os/portable/os-impl-console-bsp.c @@ -76,9 +76,9 @@ void OS_ConsoleOutput_Impl(uint32 local_id) } OS_BSP_ConsoleOutput_Impl(&console->BufBase[StartPos], - WriteSize); + (uint32)WriteSize); - StartPos += WriteSize; + StartPos += (uint32)WriteSize; if (StartPos >= console->BufSize) { /* handle wrap */ diff --git a/src/os/portable/os-impl-posix-files.c b/src/os/portable/os-impl-posix-files.c index a4dbf9391..ac7bbc211 100644 --- a/src/os/portable/os-impl-posix-files.c +++ b/src/os/portable/os-impl-posix-files.c @@ -143,8 +143,8 @@ int32 OS_FileStat_Impl(const char *local_path, os_fstat_t *FileStats) return OS_ERROR; } - FileStats->FileSize = st.st_size; - FileStats->FileTime = st.st_mtime; + FileStats->FileSize = (uint32)st.st_size; + FileStats->FileTime = (int32)st.st_mtime; /* note that the "fst_mode" member is already zeroed by the caller */ if (S_ISDIR(st.st_mode)) diff --git a/src/os/portable/os-impl-posix-gettime.c b/src/os/portable/os-impl-posix-gettime.c index 8557ec782..5d10fcb9f 100644 --- a/src/os/portable/os-impl-posix-gettime.c +++ b/src/os/portable/os-impl-posix-gettime.c @@ -77,8 +77,8 @@ int32 OS_GetLocalTime_Impl(OS_time_t *time_struct) if (Status == 0) { - time_struct -> seconds = time.tv_sec; - time_struct -> microsecs = time.tv_nsec / 1000; + time_struct -> seconds = (uint32)time.tv_sec; + time_struct -> microsecs = (uint32)time.tv_nsec / 1000; ReturnCode = OS_SUCCESS; } else diff --git a/src/os/portable/os-impl-posix-io.c b/src/os/portable/os-impl-posix-io.c index 62578e334..65b17d7d0 100644 --- a/src/os/portable/os-impl-posix-io.c +++ b/src/os/portable/os-impl-posix-io.c @@ -103,7 +103,7 @@ int32 OS_GenericClose_Impl(uint32 local_id) int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence) { int where; - int32 result; + off_t result; switch(whence) { @@ -144,7 +144,7 @@ int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence) } } - return result; + return (int32)result; } /* end OS_GenericSeek_Impl */ /*---------------------------------------------------------------- @@ -158,7 +158,7 @@ int32 OS_GenericSeek_Impl (uint32 local_id, int32 offset, uint32 whence) int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 timeout) { int32 return_code; - int os_result; + ssize_t os_result; uint32 operation; return_code = OS_SUCCESS; @@ -190,12 +190,12 @@ int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 t } else { - return_code = os_result; + return_code = (int32)os_result; } } } - return (return_code); + return (int32)(return_code); } /* end OS_GenericRead_Impl */ /*---------------------------------------------------------------- @@ -209,7 +209,7 @@ int32 OS_GenericRead_Impl (uint32 local_id, void *buffer, uint32 nbytes, int32 t int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, int32 timeout) { int32 return_code; - int os_result; + ssize_t os_result; uint32 operation; return_code = OS_SUCCESS; @@ -244,11 +244,11 @@ int32 OS_GenericWrite_Impl(uint32 local_id, const void *buffer, uint32 nbytes, i } else { - return_code = os_result; + return_code = (int32)os_result; } } } - return (return_code); + return (int32)(return_code); } /* end OS_GenericWrite_Impl */ diff --git a/src/os/portable/os-impl-posix-network.c b/src/os/portable/os-impl-posix-network.c index 29a254267..7ec198c75 100644 --- a/src/os/portable/os-impl-posix-network.c +++ b/src/os/portable/os-impl-posix-network.c @@ -92,7 +92,7 @@ int32 OS_NetworkGetHostName_Impl (char *host_name, uint32 name_len) int32 OS_NetworkGetID_Impl (int32 *IdBuf) { /* gethostid() has no failure modes */ - *IdBuf = gethostid(); + *IdBuf = (int32)gethostid(); return OS_SUCCESS; } /* end OS_NetworkGetID_Impl */ diff --git a/src/os/posix/src/os-impl-binsem.c b/src/os/posix/src/os-impl-binsem.c index 0aff787c7..1a012d005 100644 --- a/src/os/posix/src/os-impl-binsem.c +++ b/src/os/posix/src/os-impl-binsem.c @@ -203,7 +203,7 @@ int32 OS_BinSemCreate_Impl (uint32 sem_id, uint32 initial_value, uint32 options) ** fill out the proper OSAL table fields */ - sem->current_value = initial_value; + sem->current_value = (sig_atomic_t)initial_value; return_code = OS_SUCCESS; } diff --git a/src/os/posix/src/os-impl-filesys.c b/src/os/posix/src/os-impl-filesys.c index bd29c12f0..c189eeee7 100644 --- a/src/os/posix/src/os-impl-filesys.c +++ b/src/os/posix/src/os-impl-filesys.c @@ -324,7 +324,7 @@ int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) return OS_ERROR; } - result->block_size = stat_buf.f_bsize; + result->block_size = (uint32)stat_buf.f_bsize; result->blocks_free = stat_buf.f_bfree; result->total_blocks = stat_buf.f_blocks; diff --git a/src/os/posix/src/os-impl-queues.c b/src/os/posix/src/os-impl-queues.c index eac3ffe8a..5da7f3e2a 100644 --- a/src/os/posix/src/os-impl-queues.c +++ b/src/os/posix/src/os-impl-queues.c @@ -230,7 +230,7 @@ int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_c } else { - OS_Posix_CompAbsDelayTime( timeout, &ts); + OS_Posix_CompAbsDelayTime( (uint32)timeout, &ts); } /* @@ -274,7 +274,7 @@ int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_c } else { - *size_copied = sizeCopied; + *size_copied = (uint32)sizeCopied; /* SDS: size_copied should probaby be ssize_t */ return_code = OS_SUCCESS; } diff --git a/src/os/posix/src/os-impl-tasks.c b/src/os/posix/src/os-impl-tasks.c index 16f77271d..4fa5a2fe7 100644 --- a/src/os/posix/src/os-impl-tasks.c +++ b/src/os/posix/src/os-impl-tasks.c @@ -423,7 +423,7 @@ int32 OS_Posix_TaskAPI_Impl_Init(void) } #endif - POSIX_GlobalVars.PageSize = sysconf(_SC_PAGESIZE); + POSIX_GlobalVars.PageSize = (size_t)sysconf(_SC_PAGESIZE); return OS_SUCCESS; } /* end OS_Posix_TaskAPI_Impl_Init */ diff --git a/src/os/posix/src/os-impl-timebase.c b/src/os/posix/src/os-impl-timebase.c index 36b872757..75d4141f2 100644 --- a/src/os/posix/src/os-impl-timebase.c +++ b/src/os/posix/src/os-impl-timebase.c @@ -277,7 +277,7 @@ int32 OS_Posix_TimeBaseAPI_Impl_Init(void) * Pre-calculate the clock tick to microsecond conversion factor. * This is used by OS_Tick2Micros(), OS_Milli2Ticks(), etc. */ - OS_SharedGlobalVars.TicksPerSecond = sysconf(_SC_CLK_TCK); + OS_SharedGlobalVars.TicksPerSecond = (int32)sysconf(_SC_CLK_TCK); if (OS_SharedGlobalVars.TicksPerSecond <= 0) { OS_DEBUG("Error: Unable to determine OS ticks per second: %s\n",strerror(errno)); @@ -420,7 +420,7 @@ int32 OS_TimeBaseCreate_Impl(uint32 timer_id) * The output is irrelevant here; the objective is to just ensure * that the signal is not already pending. */ - i = sysconf( _SC_SIGQUEUE_MAX); + i = (int)sysconf( _SC_SIGQUEUE_MAX); do { ts.tv_sec = 0; @@ -507,8 +507,8 @@ int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time ** Convert from Microseconds to timespec structures */ memset(&timeout, 0, sizeof(timeout)); - OS_UsecToTimespec(start_time, &timeout.it_value); - OS_UsecToTimespec(interval_time, &timeout.it_interval); + OS_UsecToTimespec((uint32)start_time, &timeout.it_value); + OS_UsecToTimespec((uint32)interval_time, &timeout.it_interval); /* ** Program the real timer diff --git a/src/os/shared/src/osapi-common.c b/src/os/shared/src/osapi-common.c index ffe53f7bb..be0b5751b 100644 --- a/src/os/shared/src/osapi-common.c +++ b/src/os/shared/src/osapi-common.c @@ -90,7 +90,7 @@ int32 OS_API_Init(void) { int32 return_code = OS_SUCCESS; uint32 idtype; - uint32 microSecPerSec; + int32 microSecPerSec; if (OS_SharedGlobalVars.Initialized != false) { diff --git a/src/os/shared/src/osapi-errors.c b/src/os/shared/src/osapi-errors.c index fef7f1863..faa4148aa 100644 --- a/src/os/shared/src/osapi-errors.c +++ b/src/os/shared/src/osapi-errors.c @@ -103,7 +103,7 @@ static const OS_ErrorTable_Entry_t OS_GLOBAL_ERROR_NAME_TABLE[] = *-----------------------------------------------------------------*/ int32 OS_GetErrorName(int32 error_num, os_err_name_t* err_name) { - uint32 return_code; + int32 return_code; const OS_ErrorTable_Entry_t *Error; if (err_name == NULL) diff --git a/src/os/shared/src/osapi-file.c b/src/os/shared/src/osapi-file.c index 007c25bb6..95a7771ca 100644 --- a/src/os/shared/src/osapi-file.c +++ b/src/os/shared/src/osapi-file.c @@ -527,7 +527,7 @@ int32 OS_cp (const char *src, const char *dest) wr_total = 0; while (wr_total < rd_size) { - wr_size = OS_write((uint32)file2, ©block[wr_total], rd_size - wr_total); + wr_size = OS_write((uint32)file2, ©block[wr_total], (uint32)(rd_size - wr_total)); if (wr_size < 0) { return_code = wr_size; @@ -539,11 +539,11 @@ int32 OS_cp (const char *src, const char *dest) if (file1 >= 0) { - OS_close(file1); + OS_close((uint32)file1); } if (file2 >= 0) { - OS_close(file2); + OS_close((uint32)file2); } return return_code; diff --git a/src/os/shared/src/osapi-filesys.c b/src/os/shared/src/osapi-filesys.c index 627ebe33e..75db4cd70 100644 --- a/src/os/shared/src/osapi-filesys.c +++ b/src/os/shared/src/osapi-filesys.c @@ -577,7 +577,7 @@ int32 OS_unmount (const char *mountpoint) { /* mark as mounted in the local table. * For now this does both sides (system and virtual) */ - local->flags &= ~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); + local->flags &= (uint8)~(OS_FILESYS_FLAG_IS_MOUNTED_SYSTEM | OS_FILESYS_FLAG_IS_MOUNTED_VIRTUAL); } OS_Unlock_Global(LOCAL_OBJID_TYPE); @@ -631,7 +631,7 @@ int32 OS_fsBlocksFree (const char *name) if (return_code == OS_SUCCESS) { - return_code = statfs.blocks_free; + return_code = (int32)statfs.blocks_free; /* SDS: this should be 64-bit return */ } } else diff --git a/src/os/shared/src/osapi-idmap.c b/src/os/shared/src/osapi-idmap.c index 2d172bf3d..a3ea57d27 100644 --- a/src/os/shared/src/osapi-idmap.c +++ b/src/os/shared/src/osapi-idmap.c @@ -325,7 +325,7 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 ref } exclusive_bits = OS_OBJECT_EXCL_REQ_FLAG; - obj->flags |= exclusive_bits; + obj->flags |= (uint16)exclusive_bits; } } else @@ -369,7 +369,7 @@ int32 OS_ObjectIdConvertLock(OS_lock_mode_t lock_mode, uint32 idtype, uint32 ref * In case any exclusive bits were set locally, unset them now * before the lock is (maybe) released. */ - obj->flags &= ~exclusive_bits; + obj->flags &= (uint16)~exclusive_bits; /* * If the operation failed, then we always unlock the global table. @@ -1206,7 +1206,7 @@ int32 OS_GetResourceName(uint32 object_id, char *buffer, uint32 buffer_size) uint32 idtype; OS_common_record_t *record; int32 return_code; - uint32 name_len; + size_t name_len; uint32 local_id; /* sanity check the passed-in buffer and size */ diff --git a/src/os/shared/src/osapi-network.c b/src/os/shared/src/osapi-network.c index 20bc99b97..4ccfa929d 100644 --- a/src/os/shared/src/osapi-network.c +++ b/src/os/shared/src/osapi-network.c @@ -69,7 +69,7 @@ int32 OS_NetworkAPI_Init(void) *-----------------------------------------------------------------*/ int32 OS_NetworkGetHostName (char *host_name, uint32 name_len) { - uint32 return_code; + int32 return_code; if ( host_name == NULL) { diff --git a/src/os/shared/src/osapi-select.c b/src/os/shared/src/osapi-select.c index 839a70d1a..8692f8573 100644 --- a/src/os/shared/src/osapi-select.c +++ b/src/os/shared/src/osapi-select.c @@ -135,7 +135,7 @@ int32 OS_SelectFdAdd(OS_FdSet *Set, uint32 objid) return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) { - Set->object_ids[local_id >> 3] |= 1 << (local_id & 0x7); + Set->object_ids[local_id >> 3] |= (uint8)(1 << (local_id & 0x7)); } return return_code; @@ -159,7 +159,7 @@ int32 OS_SelectFdClear(OS_FdSet *Set, uint32 objid) return_code = OS_ObjectIdToArrayIndex(OS_OBJECT_TYPE_OS_STREAM, objid, &local_id); if (return_code == OS_SUCCESS) { - Set->object_ids[local_id >> 3] &= ~(1 << (local_id & 0x7)); + Set->object_ids[local_id >> 3] &= (uint8)~(1 << (local_id & 0x7)); } return return_code; diff --git a/src/os/shared/src/osapi-sockets.c b/src/os/shared/src/osapi-sockets.c index 7f33b94d7..120e7dcb7 100644 --- a/src/os/shared/src/osapi-sockets.c +++ b/src/os/shared/src/osapi-sockets.c @@ -90,7 +90,7 @@ int32 OS_SocketAPI_Init(void) *-----------------------------------------------------------------*/ void OS_CreateSocketName(uint32 local_id, const OS_SockAddr_t *Addr, const char *parent_name) { - int32 len; + size_t len; uint16 port; OS_stream_internal_record_t *sock = &OS_stream_table[local_id]; diff --git a/src/os/shared/src/osapi-task.c b/src/os/shared/src/osapi-task.c index a041db4f3..30cb026aa 100644 --- a/src/os/shared/src/osapi-task.c +++ b/src/os/shared/src/osapi-task.c @@ -538,7 +538,7 @@ int32 OS_TaskFindIdBySystemData(uint32 *task_id, const void *sysdata, size_t sys } /* The "sysdata" and "sysdata_size" must be passed to the underlying impl for validation */ - return_code = OS_TaskValidateSystemData_Impl(sysdata, sysdata_size); + return_code = OS_TaskValidateSystemData_Impl(sysdata, (uint32)sysdata_size); if (return_code != OS_SUCCESS) { return return_code; diff --git a/src/os/shared/src/osapi-time.c b/src/os/shared/src/osapi-time.c index 31b76c8df..5ed754a9c 100644 --- a/src/os/shared/src/osapi-time.c +++ b/src/os/shared/src/osapi-time.c @@ -300,7 +300,7 @@ int32 OS_TimerCreate(uint32 *timer_id, const char *timer_name, uint32 *accuracy, } else { - *accuracy = OS_SharedGlobalVars.MicroSecPerTick; + *accuracy = (uint32)OS_SharedGlobalVars.MicroSecPerTick; } return return_code; diff --git a/src/os/shared/src/osapi-timebase.c b/src/os/shared/src/osapi-timebase.c index 44b5d9f97..ee4241ba2 100644 --- a/src/os/shared/src/osapi-timebase.c +++ b/src/os/shared/src/osapi-timebase.c @@ -153,7 +153,7 @@ int32 OS_TimeBaseCreate(uint32 *timer_id, const char *timebase_name, OS_TimerSyn OS_timebase_table[local_id].external_sync = external_sync; if (external_sync == NULL) { - OS_timebase_table[local_id].accuracy_usec = OS_SharedGlobalVars.MicroSecPerTick; + OS_timebase_table[local_id].accuracy_usec = (uint32)OS_SharedGlobalVars.MicroSecPerTick; } else { @@ -213,7 +213,7 @@ int32 OS_TimeBaseSet(uint32 timer_id, uint32 start_time, uint32 interval_time) /* Need to take the time base lock to ensure that no ticks are currently being processed */ OS_TimeBaseLock_Impl(local_id); - return_code = OS_TimeBaseSet_Impl(local_id, start_time, interval_time); + return_code = OS_TimeBaseSet_Impl(local_id, (int32)start_time, (int32)interval_time); if (return_code == OS_SUCCESS) { @@ -500,7 +500,7 @@ void OS_TimeBase_CallbackThread(uint32 timebase_id) curr_cb_public_id = OS_global_timecb_table[curr_cb_local_id].active_id; timecb = &OS_timecb_table[curr_cb_local_id]; saved_wait_time = timecb->wait_time; - timecb->wait_time -= tick_time; + timecb->wait_time -= (int32)tick_time; while (timecb->wait_time <= 0) { timecb->wait_time += timecb->interval_time; @@ -583,10 +583,10 @@ int32 OS_Milli2Ticks(uint32 milli_seconds) unsigned long num_of_ticks; num_of_ticks = (unsigned long)milli_seconds; - num_of_ticks *= OS_SharedGlobalVars.TicksPerSecond; + num_of_ticks *= (unsigned long)OS_SharedGlobalVars.TicksPerSecond; num_of_ticks = (num_of_ticks + 999) / 1000; - return((uint32)num_of_ticks); + return((int32)num_of_ticks); } /* end OS_Milli2Ticks */ diff --git a/src/os/vxworks7/CMakeLists.txt b/src/os/vxworks7/CMakeLists.txt new file mode 100644 index 000000000..1833f3d15 --- /dev/null +++ b/src/os/vxworks7/CMakeLists.txt @@ -0,0 +1,91 @@ +###################################################################### +# +# CMAKE build recipe for VxWorks OSAL implementation +# +###################################################################### + +# This CMake script generates targets specific to the VxWorks implementation +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-heap.c + src/os-impl-idmap.c + src/os-impl-mutex.c + src/os-impl-queues.c + src/os-impl-tasks.c + src/os-impl-timebase.c +) + +# The FPU and interrupt modules are deprecated. +# If the "OMIT_DEPRECATED" switch is set, then these are not built. +if (NOT OMIT_DEPRECATED) + list(APPEND VXWORKS_BASE_SRCLIST + src/os-impl-fpu.c + src/os-impl-interrupts.c + ) +endif (NOT OMIT_DEPRECATED) + + + + +# 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 + ../portable/os-impl-posix-dirs.c +) + +if (OSAL_CONFIG_INCLUDE_SHELL) + list(APPEND VXWORKS_IMPL_SRCLIST + src/os-impl-shell.c + ) +else () + list(APPEND VXWORKS_IMPL_SRCLIST + ../portable/os-impl-no-shell.c + ) +endif () + +# 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-loader.c + src/os-impl-symtab.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 + src/os-impl-network.c + ../portable/os-impl-bsd-sockets.c # Use BSD socket layer 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_vxworks7_impl OBJECT + ${VXWORKS_BASE_SRCLIST} + ${VXWORKS_IMPL_SRCLIST} +) diff --git a/src/os/vxworks7/build_options.cmake b/src/os/vxworks7/build_options.cmake new file mode 100644 index 000000000..4009d0cee --- /dev/null +++ b/src/os/vxworks7/build_options.cmake @@ -0,0 +1,9 @@ +########################################################################## +# +# Build options for "vxworks" implementation layer +# +########################################################################## + +# this file is a placeholder for VxWorks-specific compile tuning +# currently no extra flags/definitions needed + diff --git a/src/os/vxworks7/inc/os-impl-binsem.h b/src/os/vxworks7/inc/os-impl-binsem.h new file mode 100644 index 000000000..665de9ca8 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-console.h b/src/os/vxworks7/inc/os-impl-console.h new file mode 100644 index 000000000..96547be82 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-countsem.h b/src/os/vxworks7/inc/os-impl-countsem.h new file mode 100644 index 000000000..c0ae5be12 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-dirs.h b/src/os/vxworks7/inc/os-impl-dirs.h new file mode 100644 index 000000000..ac1ec5c96 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-files.h b/src/os/vxworks7/inc/os-impl-files.h new file mode 100644 index 000000000..f01121436 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-filesys.h b/src/os/vxworks7/inc/os-impl-filesys.h new file mode 100644 index 000000000..17d92e147 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-gettime.h b/src/os/vxworks7/inc/os-impl-gettime.h new file mode 100644 index 000000000..0a9e13d06 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-io.h b/src/os/vxworks7/inc/os-impl-io.h new file mode 100644 index 000000000..df8c55c5a --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-loader.h b/src/os/vxworks7/inc/os-impl-loader.h new file mode 100644 index 000000000..7d136d6a4 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-mutex.h b/src/os/vxworks7/inc/os-impl-mutex.h new file mode 100644 index 000000000..b85e384fc --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-network.h b/src/os/vxworks7/inc/os-impl-network.h new file mode 100644 index 000000000..479acfa1e --- /dev/null +++ b/src/os/vxworks7/inc/os-impl-network.h @@ -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 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 +#include +#include +#include +#include +#include + + +#endif /* INCLUDE_OS_IMPL_NETWORK_H_ */ + diff --git a/src/os/vxworks7/inc/os-impl-queues.h b/src/os/vxworks7/inc/os-impl-queues.h new file mode 100644 index 000000000..700093a6c --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-select.h b/src/os/vxworks7/inc/os-impl-select.h new file mode 100644 index 000000000..b6f14ee9c --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-sockets.h b/src/os/vxworks7/inc/os-impl-sockets.h new file mode 100644 index 000000000..6f9e0bd35 --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-symtab.h b/src/os/vxworks7/inc/os-impl-symtab.h new file mode 100644 index 000000000..e4b03e55a --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-impl-tasks.h b/src/os/vxworks7/inc/os-impl-tasks.h new file mode 100644 index 000000000..43bf5a61c --- /dev/null +++ b/src/os/vxworks7/inc/os-impl-tasks.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-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 +{ + /* SDS: WIND_TCB was moved to a private taskLib file. There is an API to access fields within. In this case, + * OSAL wants to store other data with WIND_TCB in a single allocaiton of memory, so we only need the size. */ + char tcb[VX_WIND_TCB_SIZE]; /* 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/vxworks7/inc/os-impl-timebase.h b/src/os/vxworks7/inc/os-impl-timebase.h new file mode 100644 index 000000000..5b42a2f7c --- /dev/null +++ b/src/os/vxworks7/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/vxworks7/inc/os-vxworks.h b/src/os/vxworks7/inc/os-vxworks.h new file mode 100644 index 000000000..b48575b78 --- /dev/null +++ b/src/os/vxworks7/inc/os-vxworks.h @@ -0,0 +1,91 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 +****************************************************************************************/ + +#include +#include +#include +#include +#include + +#include +#include + +#include + + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + TYPEDEFS +****************************************************************************************/ + +typedef struct +{ + void * const mem; + SEM_ID vxid; +} VxWorks_GlobalMutex_t; + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +extern VxWorks_GlobalMutex_t VX_MUTEX_TABLE[]; + + +/**************************************************************************************** + VXWORKS IMPLEMENTATION FUNCTION PROTOTYPES +****************************************************************************************/ + +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); +int32 OS_VxWorks_TimeBaseAPI_Impl_Init(void); +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/vxworks7/src/os-impl-binsem.c b/src/os/vxworks7/src/os-impl-binsem.c new file mode 100644 index 000000000..bdb9a6573 --- /dev/null +++ b/src/os/vxworks7/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 "os-shared-binsem.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 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 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 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 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 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 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 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/vxworks7/src/os-impl-common.c b/src/os/vxworks7/src/os-impl-common.c new file mode 100644 index 000000000..b24fe5399 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-common.c @@ -0,0 +1,203 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-common.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 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 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. + * + * SDS: if sys_ticks == 0, then if the semaphore can not + * be taken S_objLib_OBJ_UNAVAILABLE will be returned + */ + if ((errno == S_objLib_OBJ_TIMEOUT) || (!sys_ticks && (errno == S_objLib_OBJ_UNAVAILABLE))) + { + 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/vxworks7/src/os-impl-console.c b/src/os/vxworks7/src/os-impl-console.c new file mode 100644 index 000000000..499bf6bad --- /dev/null +++ b/src/os/vxworks7/src/os-impl-console.c @@ -0,0 +1,170 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-printf.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_ConsoleWakeup_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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 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/vxworks7/src/os-impl-countsem.c b/src/os/vxworks7/src/os-impl-countsem.c new file mode 100644 index 000000000..1eb7844f2 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-countsem.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-countsem.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-countsem.h" +#include "os-shared-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 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 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 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 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 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 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/vxworks7/src/os-impl-dirs.c b/src/os/vxworks7/src/os-impl-dirs.c new file mode 100644 index 000000000..41cd7a420 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-dirs.c @@ -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 os-impl-dirs.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-dirs.h" +#include "os-shared-dir.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 */ + diff --git a/src/os/vxworks7/src/os-impl-errors.c b/src/os/vxworks7/src/os-impl-errors.c new file mode 100644 index 000000000..97daf14a7 --- /dev/null +++ b/src/os/vxworks7/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 "os-shared-errors.h" + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +const OS_ErrorTable_Entry_t OS_IMPL_ERROR_NAME_TABLE[] = { { 0, NULL } }; + diff --git a/src/os/vxworks7/src/os-impl-files.c b/src/os/vxworks7/src/os-impl-files.c new file mode 100644 index 000000000..c8025ac56 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-files.c @@ -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 os-impl-files.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-files.h" +#include "os-shared-file.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/vxworks7/src/os-impl-filesys.c b/src/os/vxworks7/src/os-impl-filesys.c new file mode 100644 index 000000000..6ac0c40bd --- /dev/null +++ b/src/os/vxworks7/src/os-impl-filesys.c @@ -0,0 +1,399 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 +****************************************************************************************/ + +#include "os-vxworks.h" + +#include "os-impl-filesys.h" +#include "os-shared-filesys.h" +#include "os-shared-idmap.h" + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef USE_VXWORKS_ATA_DRIVER +#include "drv/hdisk/ataDrv.h" +#endif + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/**************************************************************************************** + Data Types +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA + ***************************************************************************************/ + +OS_impl_filesys_internal_record_t OS_impl_filesys_table[OS_MAX_FILE_SYSTEMS]; + +/**************************************************************************************** + Filesys API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysStartVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysStartVolume_Impl (uint32 filesys_id) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + int32 return_code; + + memset(impl, 0, sizeof (*impl)); + return_code = OS_ERR_NOT_IMPLEMENTED; + switch(local->fstype) + { + case OS_FILESYS_TYPE_FS_BASED: + { + /* pass through for FS based volumes, assume already mounted */ + OS_DEBUG("OSAL: Mapping an FS_BASED disk at: %s\n",(unsigned long)local->system_mountpt ); + return_code = OS_SUCCESS; + break; + } + + case OS_FILESYS_TYPE_VOLATILE_DISK: + { + OS_DEBUG("OSAL: Starting a RAM disk at: 0x%08lX\n",(unsigned long)local->address ); + + /* + ** Create the ram disk device + ** The 32 is the number of blocks per track. + ** Other values dont seem to work here + */ + impl->blkDev = ramDevCreate (local->address, local->blocksize , 32 , local->numblocks, 0); + impl->xbdMaxPartitions = 1; + break; + } + +#ifdef USE_VXWORKS_ATA_DRIVER + case OS_FILESYS_TYPE_NORMAL_DISK: + { + /* + ** Create the Flash disk device + ** This code requires an ATA driver in the BSP, so it must be + ** left out of the compilation BSPs without. + */ + OS_DEBUG("OSAL: Starting an ATA DISK: %s\n", local->volume_name); + impl->xbdMaxPartitions = 4; + impl->blkDev = ataDevCreate(0, 0, 0, 0); + break; + } +#endif + + default: + break; + } + + if (impl->xbdMaxPartitions > 0) + { + /* + * This code is common to RAM disks and ATA disks + * (and anything else that relies on the xbd layer) + */ + + if (impl->blkDev == NULL) + { + /* there was an error calling the "DevCreate" function */ + OS_DEBUG("OSAL: Error creating low level block device\n"); + return_code = OS_FS_ERR_DRIVE_NOT_CREATED; + } + else + { + /* + * Connect the low level block device to the xbd device + */ + impl->xbd = xbdBlkDevCreateSync(impl->blkDev, local->volume_name); + if (impl->xbd == NULLDEV) + { + return_code = OS_FS_ERR_DRIVE_NOT_CREATED; + } + else + { + /* + * Always using partition ":0" + * + * For ATA disks, this is different than the previous implementation + * which would try to open() all possible partitions in order until + * one was successful. + * + * From the original OS_GetPhysDeviceName() implementation comments: + * + * The disk XBD code will add ":X" to the volume name you give to a disk, where + * X is the partition number. While RAM disks are always 0 ( "RAM:0" ), + * a physical disk such as a compact flash disk can be ":0", or ":1" etc, + * depending on how the disk was partitioned. + * + * But there are two issues with trying all possible devices like that: + * - Trying with open() actually mounts the filesystem, meaning it must + * have a pre-existing dosFs on it + * - It might not be consistent between devices/cards or even run-to-run. + * (i.e. if a partition was formatted manually and then the software + * restarted, a different block device might get mounted the second time) + */ + snprintf(local->system_mountpt, sizeof(local->system_mountpt), + "%s:0", local->volume_name); + + return_code = OS_SUCCESS; + } + } + } + + return return_code; + +} /* end OS_FileSysStartVolume_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysStopVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysStopVolume_Impl (uint32 filesys_id) +{ + OS_impl_filesys_internal_record_t *impl = &OS_impl_filesys_table[filesys_id]; + + if (impl->xbdMaxPartitions > 0 && impl->xbd != NULLDEV) + { + xbdBlkDevDelete(impl->xbd, NULL); + impl->xbd = NULLDEV; + impl->xbdMaxPartitions = 0; + } + + /* + * TBD: The VxWorks documentation does not seem to indicate any + * "DevDelete" operation as the complement to ramDevCreate/ataDevCreate. + */ + + return OS_SUCCESS; + +} /* end OS_FileSysStopVolume_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysFormatVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysFormatVolume_Impl (uint32 filesys_id) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + int status; + + /* + ** Call the dos format routine + */ + status = dosFsVolFormat(local->system_mountpt, DOS_OPT_BLANK, NULL); + if ( status == -1 ) + { + OS_DEBUG("OSAL: dosFsVolFormat failed. Errno = %d\n",errnoGet()); + return OS_FS_ERR_DRIVE_NOT_CREATED; + } + + return OS_SUCCESS; + +} /* end OS_FileSysFormatVolume_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysMountVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysMountVolume_Impl (uint32 filesys_id) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + int32 status; + int fd; + + /* + * Calling open() on the physical device path + * mounts the device. + */ + fd = open ( local->system_mountpt, O_RDONLY, 0644 ); + if ( fd < 0 ) + { + status = OS_ERROR; + } + else + { + status = OS_SUCCESS; + close(fd); + } + + return status; + +} /* end OS_FileSysMountVolume_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysUnmountVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysUnmountVolume_Impl (uint32 filesys_id) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + int32 status; + int fd; + + /* + ** vxWorks uses an ioctl to unmount + */ + fd = open ( local->system_mountpt, O_RDONLY, 0644 ); + if ( fd < 0 ) + { + status = OS_ERROR; + } + else + { + if ( ioctl( fd, FIOUNMOUNT,0) < 0 ) + { + status = OS_ERROR; + } + else + { + status = OS_SUCCESS; + } + + close(fd); + } + + return status; + +} /* end OS_FileSysUnmountVolume_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysStatVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysStatVolume_Impl (uint32 filesys_id, OS_statvfs_t *result) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + struct statfs stat_buf; + int return_code; + + if (statfs(local->system_mountpt, &stat_buf) != 0) + { + return_code = OS_ERROR; + memset(result, 0, sizeof(*result)); + } + else + { + result->block_size = stat_buf.f_bsize; + result->blocks_free = stat_buf.f_bfree; + result->total_blocks = stat_buf.f_blocks; + return_code = OS_SUCCESS; + } + + return return_code; + +} /* end OS_FileSysStatVolume_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_FileSysCheckVolume_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_FileSysCheckVolume_Impl (uint32 filesys_id, bool repair) +{ + OS_filesys_internal_record_t *local = &OS_filesys_table[filesys_id]; + STATUS chk_status; + int flags; + int fd; + + fd = open (local->system_mountpt, O_RDONLY, 0); + if (fd < 0) + { + return OS_ERROR; + } + + /* Fix the disk if there are errors */ + if (repair) + { + flags = DOS_CHK_REPAIR; + } + else + { + flags = DOS_CHK_ONLY; + } + + flags |= DOS_CHK_VERB_SILENT; + + chk_status = ioctl(fd, FIOCHKDSK, flags); + + close(fd); + + if (chk_status != OK) + { + return OS_ERROR; + } + + return OS_SUCCESS; + +} /* end OS_FileSysCheckVolume_Impl */ + + + + diff --git a/src/os/vxworks7/src/os-impl-heap.c b/src/os/vxworks7/src/os-impl-heap.c new file mode 100644 index 000000000..d84b75b53 --- /dev/null +++ b/src/os/vxworks7/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 vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-shared-heap.h" + +#include + +/**************************************************************************************** + HEAP API +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_HeapGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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/vxworks7/src/os-impl-idmap.c b/src/os/vxworks7/src/os-impl-idmap.c new file mode 100644 index 000000000..c61f7b936 --- /dev/null +++ b/src/os/vxworks7/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-idmap.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-shared-idmap.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 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 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/vxworks7/src/os-impl-interrupts.c b/src/os/vxworks7/src/os-impl-interrupts.c new file mode 100644 index 000000000..280f6bcf4 --- /dev/null +++ b/src/os/vxworks7/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 +#include + +#include "os-vxworks.h" +#include "os-shared-interrupts.h" + +/**************************************************************************************** + INT API (deprecated) +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_IntAttachHandler_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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 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 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 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 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 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 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/vxworks7/src/os-impl-loader.c b/src/os/vxworks7/src/os-impl-loader.c new file mode 100644 index 000000000..449c55532 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-loader.c @@ -0,0 +1,185 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-module.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 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 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 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/vxworks7/src/os-impl-mutex.c b/src/os/vxworks7/src/os-impl-mutex.c new file mode 100644 index 000000000..03623bca8 --- /dev/null +++ b/src/os/vxworks7/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 "os-shared-mutex.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 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 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 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 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 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 */ + diff --git a/src/os/vxworks7/src/os-impl-network.c b/src/os/vxworks7/src/os-impl-network.c new file mode 100644 index 000000000..5818b7ee8 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-network.c @@ -0,0 +1,91 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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" +#include "os-shared-network.h" + +#define OS_HOST_NAME_LEN 48 + +/*---------------------------------------------------------------- + * + * Function: OS_NetworkGetHostName_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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 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/vxworks7/src/os-impl-no-module.c b/src/os/vxworks7/src/os-impl-no-module.c new file mode 100644 index 000000000..c9cd01407 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-no-module.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-no-module.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES + ***************************************************************************************/ + +#include "os-vxworks.h" + + +/**************************************************************************************** + INITIALIZATION FUNCTION + ***************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_ModuleAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_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_VxWorks_ModuleAPI_Impl_Init */ + + diff --git a/src/os/vxworks7/src/os-impl-queues.c b/src/os/vxworks7/src/os-impl-queues.c new file mode 100644 index 000000000..9f302effb --- /dev/null +++ b/src/os/vxworks7/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 "os-shared-queue.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 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 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 for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_QueueGet_Impl (uint32 queue_id, void *data, uint32 size, uint32 *size_copied, + int32 timeout) +{ + int32 return_code; + uint64 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 = (uint32)status; /* ok to convert to 32 here, because it will never be larger */ + return_code = OS_SUCCESS; + } + + return return_code; +} /* end OS_QueueGet_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_QueuePut_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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 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/vxworks7/src/os-impl-shell.c b/src/os/vxworks7/src/os-impl-shell.c new file mode 100644 index 000000000..dede37e64 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-shell.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 os-impl-shell.c + * \ingroup vxworks + * \author joseph.p.hickey@nasa.gov + * + */ + +/**************************************************************************************** + INCLUDE FILES +****************************************************************************************/ + +#include "os-vxworks.h" +#include "os-impl-io.h" +#include "os-shared-shell.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 for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_ShellOutputToFile_Impl(uint32 file_id, const char *Cmd) +{ + int32 ReturnCode = OS_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_SUCCESS) + { + return OS_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/vxworks7/src/os-impl-symtab.c b/src/os/vxworks7/src/os-impl-symtab.c new file mode 100644 index 000000000..2c4ba20b7 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-symtab.c @@ -0,0 +1,231 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-module.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 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; + uint64 NextSize; + ssize_t 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 = (uint32)NextSize; + + /* + ** It's OK to continue + */ + return(true); +} /* end OS_SymTableIterator_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_SymbolTableDump_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype 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/vxworks7/src/os-impl-tasks.c b/src/os/vxworks7/src/os-impl-tasks.c new file mode 100644 index 000000000..4096bbc19 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-tasks.c @@ -0,0 +1,459 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-task.h" +#include "os-shared-idmap.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 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( + (WIND_TCB*)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 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 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 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 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 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 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 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 for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskGetInfo_Impl (uint32 task_id, OS_task_prop_t *task_prop) +{ + return OS_SUCCESS; +} /* end OS_TaskGetInfo_Impl */ + +/*---------------------------------------------------------------- + * + * Function: OS_TaskValidateSystemData_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TaskValidateSystemData_Impl(const void *sysdata, uint32 sysdata_size) +{ + if (sysdata == NULL || sysdata_size != sizeof(TASK_ID)) + { + return OS_INVALID_POINTER; + } + return OS_SUCCESS; +} + +/*---------------------------------------------------------------- + * + * Function: OS_TaskIdMatchSystemData_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +bool OS_TaskIdMatchSystemData_Impl(void *ref, uint32 local_id, const OS_common_record_t *obj) +{ + const TASK_ID *target = (const TASK_ID *)ref; + + return (*target == OS_impl_task_table[local_id].vxid); +} + + + diff --git a/src/os/vxworks7/src/os-impl-timebase.c b/src/os/vxworks7/src/os-impl-timebase.c new file mode 100644 index 000000000..b299ba1e0 --- /dev/null +++ b/src/os/vxworks7/src/os-impl-timebase.c @@ -0,0 +1,647 @@ +/* + * + * Copyright (c) 2020, United States government as represented by the + * administrator of the National Aeronautics Space Administration. + * All rights reserved. This software was created at NASA Goddard + * Space Flight Center pursuant to government contracts. + * + * This 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 "os-shared-common.h" +#include "os-shared-idmap.h" +#include "os-shared-timebase.h" + +#include +#include +#include +#include +#include + + +/**************************************************************************************** + DEFINES +****************************************************************************************/ + +/* Each "timebase" resource spawns an dedicated servicing task- + * this task (not the timer ISR) is the context that calls back to + * the user application. + * + * This should run at the highest priority to reduce latency. + */ +#define OSAL_TIMEBASE_TASK_STACK_SIZE 4096 +#define OSAL_TIMEBASE_TASK_PRIORITY 0 +#define OSAL_TIMEBASE_TASK_OPTION_WORD 0 + +#define OSAL_TIMEBASE_REG_WAIT_LIMIT 100 +/* + * Prefer to use the MONOTONIC clock if available, as it will not get distrupted by setting + * the time like the REALTIME clock will. + */ +#define OS_PREFERRED_CLOCK CLOCK_MONOTONIC + +/**************************************************************************************** + LOCAL TYPEDEFS +****************************************************************************************/ + +/**************************************************************************************** + GLOBAL DATA +****************************************************************************************/ + +OS_impl_timebase_internal_record_t OS_impl_timebase_table[OS_MAX_TIMEBASES]; + +static uint32 OS_ClockAccuracyNsec; + +/**************************************************************************************** + INTERNAL FUNCTIONS +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_TimeBaseLock_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +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 + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +void OS_TimeBaseUnlock_Impl(uint32 local_id) +{ + semGive(OS_impl_timebase_table[local_id].handler_mutex); +} /* end OS_TimeBaseUnlock_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_Impl_UsecToTimespec + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +void OS_VxWorks_UsecToTimespec(uint32 usecs, struct timespec *time_spec) +{ + if ( usecs < 1000000 ) + { + time_spec->tv_nsec = (usecs * 1000); + time_spec->tv_sec = 0; + } + else + { + time_spec->tv_sec = usecs / 1000000; + time_spec->tv_nsec = (usecs % 1000000) * 1000; + } +} /* end OS_Impl_UsecToTimespec */ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_SigWait + * + * Purpose: Local helper routine, not part of OSAL API. + * Blocks the calling task until the timer tick arrives + * + *-----------------------------------------------------------------*/ +uint32 OS_VxWorks_SigWait(uint32 local_id) +{ + OS_impl_timebase_internal_record_t *local; + OS_common_record_t *global; + uint32 active_id; + uint32 tick_time; + int signo; + int ret; + + local = &OS_impl_timebase_table[local_id]; + global = &OS_global_timebase_table[local_id]; + active_id = global->active_id; + tick_time = 0; + + if (active_id != 0 && local->assigned_signal > 0) + { + /* + * Pend for the tick arrival + */ + ret = sigwait(&local->timer_sigset, &signo); + + /* + * The sigwait() can be interrupted.... + * Only return nonzero interval time if it is an actual timer signal. + * This value will get added to the free-run counter. + * + * NOTE: This always returns the nominal interval time. + * + * This value will likely be wrong on the first tick + * after starting a new timebase or reconfiguring an + * existing one. This is because interval times + * are relative, and the exact instant that the reconfig + * takes effect is not knowable. + * + * This is OK because free-run counter values + * are only expected to be valid in steady-state + * conditions. Samples from before/after a reconfig + * are generally not comparable. + */ + if (ret == OK && signo == local->assigned_signal && + global->active_id == active_id) + { + if (local->reset_flag) + { + /* first interval after reset, use start time */ + tick_time = local->configured_start_time; + local->reset_flag = false; + } + else + { + tick_time = local->configured_interval_time; + } + } + } + + return tick_time; +} /* end OS_VxWorks_SigWait */ + + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_RegisterTimer + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +void OS_VxWorks_RegisterTimer(uint32 local_id) +{ + OS_impl_timebase_internal_record_t *local; + struct sigevent evp; + int status; + + local = &OS_impl_timebase_table[local_id]; + + + memset(&evp, 0, sizeof(evp)); + evp.sigev_notify = SIGEV_SIGNAL; + evp.sigev_signo = local->assigned_signal; + + + /* + ** Create the timer + ** + ** The result is not returned from this function, because + ** this is a different task context from the original creator. + ** + ** The registration status is returned through the OS_impl_timebase_table entry, + ** which is checked by the creator before returning. + ** + ** If set to ERROR, then this task will be subsequently deleted. + */ + status = timer_create(OS_PREFERRED_CLOCK, &evp, &local->host_timerid); + if (status < 0) + { + OS_DEBUG("timer_create() failed: errno=%d\n", errno); + local->timer_state = OS_TimerRegState_ERROR; + } + else + { + local->timer_state = OS_TimerRegState_SUCCESS; + } +} /* end OS_VxWorks_RegisterTimer */ + +/**************************************************************************************** + Entry point for helper thread +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_TimeBaseTask + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int OS_VxWorks_TimeBaseTask(int arg) +{ + uint32 local_id; + + if (OS_ConvertToArrayIndex(arg, &local_id) == OS_SUCCESS) + { + OS_VxWorks_RegisterTimer(local_id); + OS_TimeBase_CallbackThread(arg); + } + + return 0; +} /* end OS_VxWorks_TimeBaseTask */ + + + + +/**************************************************************************************** + INITIALIZATION FUNCTION +****************************************************************************************/ + +/*---------------------------------------------------------------- + * + * Function: OS_VxWorks_TimeBaseAPI_Impl_Init + * + * Purpose: Local helper routine, not part of OSAL API. + * + *-----------------------------------------------------------------*/ +int32 OS_VxWorks_TimeBaseAPI_Impl_Init ( void ) +{ + int clockRate; + + /* + ** sysClkRateGet returns ticks/second. + */ + clockRate = sysClkRateGet(); + + if (clockRate <= 0) + { + return OS_ERROR; + } + + OS_SharedGlobalVars.TicksPerSecond = clockRate; + + /* + * Store the clock accuracy for 1 tick. + * + * Compute the clock accuracy in Nanoseconds (ns per tick) + * This really should be an exact/whole number result; otherwise this + * will round to the nearest nanosecond. + */ + OS_ClockAccuracyNsec = (1000000000 + (OS_SharedGlobalVars.TicksPerSecond / 2)) / + OS_SharedGlobalVars.TicksPerSecond; + + + /* + * Finally compute the Microseconds per tick that is used for OS_Tick2Micros() call + * This must further round again to the nearest microsecond, so it is undesirable to use + * this for time computations if the result is not exact. + */ + OS_SharedGlobalVars.MicroSecPerTick = (OS_ClockAccuracyNsec + 500) / 1000; + + return(OS_SUCCESS); +} /* end OS_VxWorks_TimeBaseAPI_Impl_Init */ + +/**************************************************************************************** + Time Base API +****************************************************************************************/ + + +/*---------------------------------------------------------------- + * + * Function: OS_TimeBaseCreate_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TimeBaseCreate_Impl(uint32 timer_id) +{ + /* + * The tick_sem is a simple semaphore posted by the ISR and taken by the + * timebase helper task (created later). + */ + int32 return_code; + OS_impl_timebase_internal_record_t *local; + OS_common_record_t *global; + int signo; + sigset_t inuse; + uint32 i; + + + return_code = OS_SUCCESS; + local = &OS_impl_timebase_table[timer_id]; + global = &OS_global_timebase_table[timer_id]; + + sigemptyset(&local->timer_sigset); + local->assigned_signal = 0; + local->handler_task = 0; + local->handler_mutex = (SEM_ID)0; + local->host_timerid = 0; + local->timer_state = OS_TimerRegState_INIT; + local->reset_flag = false; + + /* + * Set up the necessary OS constructs + * + * If an external sync function is used then there is nothing to do here - + * we simply call that function and it should synchronize to the time source. + * + * If no external sync function is provided then this will set up a VxWorks + * timer to locally simulate the timer tick using the CPU clock. + */ + if (OS_timebase_table[timer_id].external_sync == NULL) + { + /* + * find an RT signal that is not used by another time base object. + * This the global lock is held here so there is no chance of + * the underlying tables changing. + */ + sigemptyset(&inuse); + + for(i = 0; i < OS_MAX_TIMEBASES; ++i) + { + if (OS_global_timebase_table[i].active_id != 0 && + OS_impl_timebase_table[i].assigned_signal > 0) + { + /* mark signal as in-use */ + sigaddset(&inuse, OS_impl_timebase_table[i].assigned_signal); + } + } + + for (signo = SIGRTMIN; + signo <= SIGRTMAX; + ++signo) + { + if (!sigismember(&inuse, signo)) + { + /* signal is available, stop search */ + break; + } + } + + if (signo < SIGRTMIN || signo > SIGRTMAX) + { + /* no available signal for timer */ + OS_DEBUG("No free RT signals to use for simulated time base\n"); + return_code = OS_TIMER_ERR_UNAVAILABLE; + } + else + { + /* + * Note that VxWorks appears to always send the timer signal + * to the task that called timer_create(). This is different + * than e.g. POSIX where the signal is sent to the process + * and masks can be modified to direct the signal to the + * correct task. + * + * Therefore, we choose the signal now, but defer calling + * timer_create to the internal helper task. + */ + local->assigned_signal = signo; + sigaddset(&local->timer_sigset, signo); + + /* + * Use local sigwait() wrapper as a sync function for the local task. + */ + OS_timebase_table[timer_id].external_sync = OS_VxWorks_SigWait; + } + } + + if (return_code == OS_SUCCESS) + { + /* + * Create the handler_mutex. + * This controls access to the callback list for this timebase + * + * Note memory for this sem is statically allocated, so if a failure + * occurs there is no need to free the memory later. + */ + local->handler_mutex = semMInitialize(local->mmem, SEM_Q_PRIORITY | SEM_INVERSION_SAFE); + if ( local->handler_mutex == (SEM_ID)0 ) + { + OS_DEBUG("Error: Handler Mutex could not be initialized: errno=%d\n",errno); + return_code = OS_TIMER_ERR_INTERNAL; + } + } + + /* + * Spawn a dedicated time base handler thread + * + * This alleviates the need to handle expiration in the context of a signal handler - + * The handler thread can call a BSP synchronized delay implementation as well as the + * application callback function. It should run with elevated priority to reduce latency. + * + * Note the thread will not actually start running until this function exits and releases + * the global table lock. + */ + if (return_code == OS_SUCCESS) + { + local->handler_task = taskSpawn( + (char*)global->name_entry, + OSAL_TIMEBASE_TASK_PRIORITY, /* priority */ + OSAL_TIMEBASE_TASK_OPTION_WORD, /* task option word */ + OSAL_TIMEBASE_TASK_STACK_SIZE, /* size (bytes) of stack needed */ + (FUNCPTR)OS_VxWorks_TimeBaseTask, + global->active_id, /* 1st arg is ID */ + 0,0,0,0,0,0,0,0,0); + + /* check if taskSpawn failed */ + if (local->handler_task == ((TASK_ID)ERROR)) + { + OS_DEBUG("taskSpawn() - vxWorks errno: %d\n",errno); + return_code = OS_TIMER_ERR_INTERNAL; + } + else + { + /* + * Wait for the newly-spawned task to call timer_create(). + * If this is successful, then return success, otherwise + * return failure. + * + * As the task runs with a high priority, it should preempt + * this task and therefore it should probably already be + * complete by the time execution gets here. But for + * multi-core machines it is possible that an extra delay + * is necessary. + */ + i = OSAL_TIMEBASE_REG_WAIT_LIMIT; + while(local->timer_state == OS_TimerRegState_INIT && i > 0) + { + OS_TaskDelay(1); + --i; + } + + /* + * If the timer wasn't fully created successfully, + * then delete the task. + */ + if (local->timer_state != OS_TimerRegState_SUCCESS) + { + OS_DEBUG("Error during timer registration\n"); + taskDelete(local->handler_task); + return_code = OS_TIMER_ERR_INTERNAL; + } + } + } + + + return return_code; +} /* end OS_TimeBaseCreate_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TimeBaseSet_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TimeBaseSet_Impl(uint32 timer_id, int32 start_time, int32 interval_time) +{ + OS_impl_timebase_internal_record_t *local; + struct itimerspec timeout; + int32 return_code; + int status; + + local = &OS_impl_timebase_table[timer_id]; + + /* There is only something to do here if we are generating a simulated tick */ + if (local->assigned_signal <= 0) + { + /* An externally synced timebase does not need to be set */ + return_code = OS_ERR_NOT_IMPLEMENTED; + } + else + { + OS_VxWorks_UsecToTimespec(start_time, &timeout.it_value); + OS_VxWorks_UsecToTimespec(interval_time, &timeout.it_interval); + + /* + ** Program the real timer + */ + status = timer_settime(local->host_timerid, + 0, /* Flags field can be zero */ + &timeout, /* struct itimerspec */ + NULL); /* Oldvalue */ + + if (status == OK) + { + return_code = OS_SUCCESS; + + /* + * VxWorks will round the interval up to the next higher + * system tick interval. Sometimes this can make a substantial + * difference in the actual time, particularly as the error + * accumulates over time. + * + * timer_gettime() will reveal the actual interval programmed, + * after all rounding/adjustments, which can be used to determine + * the actual start_time/interval_time that will be realized. + * + * If this actual interval is different than the intended value, + * it may indicate the need for better tuning on the app/config/bsp + * side, and so a DEBUG message is generated. + */ + status = timer_gettime(local->host_timerid, &timeout); + if (status == OK) + { + local->configured_start_time = + (uint32)((timeout.it_value.tv_sec * 1000000) + + (timeout.it_value.tv_nsec / 1000)); + local->configured_interval_time = + (uint32)((timeout.it_interval.tv_sec * 1000000) + + (timeout.it_interval.tv_nsec / 1000)); + + if (local->configured_start_time != start_time) + { + OS_DEBUG("WARNING: timer %lu start_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)start_time, + (unsigned long)local->configured_start_time); + } + if (local->configured_interval_time != interval_time) + { + OS_DEBUG("WARNING: timer %lu interval_time requested=%luus, configured=%luus\n", + (unsigned long)timer_id, + (unsigned long)interval_time, + (unsigned long)local->configured_interval_time); + } + + } + + } + else + { + return_code = OS_TIMER_ERR_INVALID_ARGS; + } + + } + + if (!local->reset_flag && return_code == OS_SUCCESS) + { + local->reset_flag = true; + } + + return return_code; +} /* end OS_TimeBaseSet_Impl */ + + + +/*---------------------------------------------------------------- + * + * Function: OS_TimeBaseDelete_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TimeBaseDelete_Impl(uint32 timer_id) +{ + OS_impl_timebase_internal_record_t *local; + int32 return_code; + + local = &OS_impl_timebase_table[timer_id]; + return_code = OS_SUCCESS; + + /* An assigned_signal value indicates the OS timer needs deletion too */ + if (local->assigned_signal > 0) + { + /* this also implies the sync sem needs delete too */ + timer_delete(local->host_timerid); + local->host_timerid = 0; + local->assigned_signal = 0; + } + + /* + ** Delete the task associated with this timebase + */ + taskDelete(local->handler_task); + local->handler_task = 0; + + return return_code; +} /* end OS_TimeBaseDelete_Impl */ + + +/*---------------------------------------------------------------- + * + * Function: OS_TimeBaseGetInfo_Impl + * + * Purpose: Implemented per internal OSAL API + * See prototype for argument/return detail + * + *-----------------------------------------------------------------*/ +int32 OS_TimeBaseGetInfo_Impl (uint32 timer_id, OS_timebase_prop_t *timer_prop) +{ + return OS_SUCCESS; + +} /* end OS_TimeBaseGetInfo_Impl */ +