From 29f0ad82e438a5af8e8a0b7abe2961343d141275 Mon Sep 17 00:00:00 2001 From: Neil Abcouwer Date: Tue, 13 Jul 2021 12:51:50 -0700 Subject: [PATCH 1/2] Flexibility modifications for doing an out of source baremetal build. Add MIN and MAX size #defs for integers in Basic types. Use U32MAX from basic types in FileDownlink, instead of __UINT32_MAX__. Change interrupt to interrupt_val in BlockDriver (prevented build). Guard on system type and don't include Ip socket using components or LinuxTime in baremetal build. Add Baremetal/Mutex.cpp to Os/CMakeLists.txt. Switchup fatal handler files based on system type. Allow for missing PATH_MAX in ComLogger. Change all instances of FPRIME_USE_BAREMETAL_SCHEDULE to FPRIME_USE_BAREMETAL_SCHEDULER. --- Drv/BlockDriver/BlockDriverComponentAi.xml | 2 +- Drv/CMakeLists.txt | 16 +++++-- Fw/Cfg/CMakeLists.txt | 2 +- Fw/Types/BasicTypes.hpp | 55 ++++++++++++++++++++++ Os/CMakeLists.txt | 1 + Svc/CMakeLists.txt | 8 +++- Svc/ComLogger/ComLogger.hpp | 9 +++- Svc/FatalHandler/CMakeLists.txt | 11 ++++- Svc/FileDownlink/FileDownlink.cpp | 6 +-- cmake/platform/Linux.cmake | 2 +- cmake/platform/platform.cmake.template | 2 +- 11 files changed, 98 insertions(+), 16 deletions(-) diff --git a/Drv/BlockDriver/BlockDriverComponentAi.xml b/Drv/BlockDriver/BlockDriverComponentAi.xml index db99e5757f..135a0888df 100644 --- a/Drv/BlockDriver/BlockDriverComponentAi.xml +++ b/Drv/BlockDriver/BlockDriverComponentAi.xml @@ -60,7 +60,7 @@ Internal interrupt reporting interface - + The interrupt register value diff --git a/Drv/CMakeLists.txt b/Drv/CMakeLists.txt index 027adb4265..f9f69bafab 100644 --- a/Drv/CMakeLists.txt +++ b/Drv/CMakeLists.txt @@ -14,8 +14,14 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriver/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxSerialDriver/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriver/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriver/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Ip/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TcpClient/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TcpServer/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Udp/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SocketIpDriver/") + +# IP Socket is only supported for Linux, Darwin, VxWorks +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR ${CMAKE_SYSTEM_NAME} STREQUAL "VxWorks") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Ip/") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TcpClient/") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TcpServer/") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Udp/") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/SocketIpDriver/") +else() + message(STATUS "Cannot use IP sockets with platform ${CMAKE_SYSTEM_NAME}. Skipping.") +endif() diff --git a/Fw/Cfg/CMakeLists.txt b/Fw/Cfg/CMakeLists.txt index f0b737446f..ecb0c5a769 100644 --- a/Fw/Cfg/CMakeLists.txt +++ b/Fw/Cfg/CMakeLists.txt @@ -9,7 +9,7 @@ set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/ConfigCheck.cpp" ) register_fprime_module() -if (FPRIME_USE_BAREMETAL_SCHEDULE) +if (FPRIME_USE_BAREMETAL_SCHEDULER) target_compile_definitions(Fw_Cfg PUBLIC FW_BAREMETAL_SCHEDULER=1) else() target_compile_definitions(Fw_Cfg PUBLIC FW_BAREMETAL_SCHEDULER=0) diff --git a/Fw/Types/BasicTypes.hpp b/Fw/Types/BasicTypes.hpp index d9fe2dc838..da261dd4e9 100644 --- a/Fw/Types/BasicTypes.hpp +++ b/Fw/Types/BasicTypes.hpp @@ -100,6 +100,61 @@ typedef float F32; //!< 32-bit floating point #define NULL (0) //!< NULL #endif + +#ifndef I8_MAX +#define I8_MAX 127 +#endif + +#ifndef I8_MIN +#define I8_MIN -128 +#endif + +#ifndef U8_MAX +#define U8_MAX 255 +#endif + +#if FW_HAS_16_BIT +#ifndef I16_MAX +#define I16_MAX 32767 +#endif + +#ifndef I16_MIN +#define I16_MIN -32768 +#endif + +#ifndef U16_MAX +#define U16_MAX 65535 +#endif +#endif + +#if FW_HAS_32_BIT +#ifndef I32_MAX +#define I32_MAX 2147483647 +#endif + +#ifndef I32_MIN +#define I32_MIN -2147483648 +#endif + +#ifndef U32_MAX +#define U32_MAX 4294967295 +#endif +#endif + +#if FW_HAS_64_BIT +#ifndef I64_MAX +#define I64_MAX 9223372036854775807 +#endif + +#ifndef I64_MIN +#define I64_MIN -9223372036854775808 +#endif + +#ifndef U64_MAX +#define U64_MAX 18446744073709551615 +#endif +#endif + #define FW_NUM_ARRAY_ELEMENTS(a) (sizeof(a)/sizeof((a)[0])) //!< number of elements in an array #define FW_MAX(a,b) (((a) > (b))?(a):(b)) //!< MAX macro diff --git a/Os/CMakeLists.txt b/Os/CMakeLists.txt index 2f9ebf14d5..4cb2129aaa 100644 --- a/Os/CMakeLists.txt +++ b/Os/CMakeLists.txt @@ -80,6 +80,7 @@ if (FPRIME_USE_BAREMETAL_SCHEDULER) endif() endforeach() list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Baremetal/Task.cpp") + list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/Baremetal/Mutex.cpp") endif() register_fprime_module() diff --git a/Svc/CMakeLists.txt b/Svc/CMakeLists.txt index 37b3d3da70..7111112d0f 100644 --- a/Svc/CMakeLists.txt +++ b/Svc/CMakeLists.txt @@ -31,8 +31,6 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/GroundInterface/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Framer/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FramingProtocol/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Health/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxTime/") -add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxTimer/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PassiveConsoleTextLogger/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PolyDb/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/PrmDb/") @@ -40,3 +38,9 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/RateGroupDriver/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/StaticMemory/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Time/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/TlmChan/") + +if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxTime/") + add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxTimer/") +endif() + \ No newline at end of file diff --git a/Svc/ComLogger/ComLogger.hpp b/Svc/ComLogger/ComLogger.hpp index a0f26aa80c..59893fcb65 100644 --- a/Svc/ComLogger/ComLogger.hpp +++ b/Svc/ComLogger/ComLogger.hpp @@ -17,6 +17,13 @@ #include #include +// some limits.h don't have PATH_MAX +#ifdef PATH_MAX +#define COMLOGGER_PATH_MAX PATH_MAX +#else +#define COMLOGGER_PATH_MAX 255 +#endif + namespace Svc { class ComLogger : @@ -75,7 +82,7 @@ namespace Svc { // The maximum size of a filename enum { MAX_FILENAME_SIZE = NAME_MAX, // as defined in limits.h - MAX_PATH_SIZE = PATH_MAX + MAX_PATH_SIZE = COMLOGGER_PATH_MAX }; // The filename data: diff --git a/Svc/FatalHandler/CMakeLists.txt b/Svc/FatalHandler/CMakeLists.txt index 7f9e3841ff..c40977dfdc 100644 --- a/Svc/FatalHandler/CMakeLists.txt +++ b/Svc/FatalHandler/CMakeLists.txt @@ -6,11 +6,20 @@ # # Note: using PROJECT_NAME as EXECUTABLE_NAME #### + set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentAi.xml" "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentCommonImpl.cpp" - "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentLinuxImpl.cpp" ) + +if(FPRIME_USE_BAREMETAL_SCHEDULER) + list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentBaremetalImpl.cpp") +elseif(${CMAKE_SYSTEM_NAME} STREQUAL "VxWorks") + list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentVxWorksImpl.cpp") +else() + list(APPEND SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/FatalHandlerComponentLinuxImpl.cpp") +endif() + set(MOD_DEPS Os Fw/Logger diff --git a/Svc/FileDownlink/FileDownlink.cpp b/Svc/FileDownlink/FileDownlink.cpp index 87a03f8ec9..6b5a7e8dfb 100644 --- a/Svc/FileDownlink/FileDownlink.cpp +++ b/Svc/FileDownlink/FileDownlink.cpp @@ -179,7 +179,7 @@ namespace Svc { Os::Queue::QueueStatus status = fileQueue.send((U8 *) &entry, sizeof(entry), 0, Os::Queue::QUEUE_NONBLOCKING); if(status != Os::Queue::QUEUE_OK) { - return SendFileResponse(SendFileStatus::ERROR, __UINT32_MAX__); + return SendFileResponse(SendFileStatus::ERROR, U32_MAX); } return SendFileResponse(SendFileStatus::OK, entry.context); } @@ -241,7 +241,7 @@ namespace Svc { .source = FileDownlink::COMMAND, .opCode = opCode, .cmdSeq = cmdSeq, - .context =__UINT32_MAX__ + .context = U32_MAX }; FW_ASSERT(sourceFilename.length() < sizeof(entry.srcFilename)); @@ -274,7 +274,7 @@ namespace Svc { .source = FileDownlink::COMMAND, .opCode = opCode, .cmdSeq = cmdSeq, - .context = __UINT32_MAX__ + .context = U32_MAX }; FW_ASSERT(sourceFilename.length() < sizeof(entry.srcFilename)); diff --git a/cmake/platform/Linux.cmake b/cmake/platform/Linux.cmake index b44cbab0c6..d8e71e19ea 100644 --- a/cmake/platform/Linux.cmake +++ b/cmake/platform/Linux.cmake @@ -5,7 +5,7 @@ #### # Set platform default for baremetal scheduler drivers if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER) - set(FPRIME_USE_BAREMETAL_SCHEDULE OFF) + set(FPRIME_USE_BAREMETAL_SCHEDULER OFF) message(STATUS "Requiring thread library") FIND_PACKAGE ( Threads REQUIRED ) endif() diff --git a/cmake/platform/platform.cmake.template b/cmake/platform/platform.cmake.template index 501c9f3931..8d6a318382 100644 --- a/cmake/platform/platform.cmake.template +++ b/cmake/platform/platform.cmake.template @@ -62,7 +62,7 @@ set(CMAKE_CXX_FLAGS # directory. NOTE: when running without threads, remove this line. # Here there is a check for the using baremetal scheduler if (NOT DEFINED FPRIME_USE_BAREMETAL_SCHEDULER) - set(FPRIME_USE_BAREMETAL_SCHEDULE OFF) + set(FPRIME_USE_BAREMETAL_SCHEDULER OFF) message(STATUS "Requiring thread library") FIND_PACKAGE ( Threads REQUIRED ) endif() From 15af99c254eee6633a1a447f8ca6a208222f62cb Mon Sep 17 00:00:00 2001 From: Neil Abcouwer Date: Tue, 13 Jul 2021 15:34:21 -0700 Subject: [PATCH 2/2] Cast MIN and MAX types for proper comparisons. --- Fw/Types/BasicTypes.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Fw/Types/BasicTypes.hpp b/Fw/Types/BasicTypes.hpp index da261dd4e9..544a4b711e 100644 --- a/Fw/Types/BasicTypes.hpp +++ b/Fw/Types/BasicTypes.hpp @@ -102,56 +102,56 @@ typedef float F32; //!< 32-bit floating point #ifndef I8_MAX -#define I8_MAX 127 +#define I8_MAX (I8)(127) #endif #ifndef I8_MIN -#define I8_MIN -128 +#define I8_MIN (I8)(-128) #endif #ifndef U8_MAX -#define U8_MAX 255 +#define U8_MAX (U8)(255) #endif #if FW_HAS_16_BIT #ifndef I16_MAX -#define I16_MAX 32767 +#define I16_MAX (I16)(32767) #endif #ifndef I16_MIN -#define I16_MIN -32768 +#define I16_MIN (I16)(-32768) #endif #ifndef U16_MAX -#define U16_MAX 65535 +#define U16_MAX (U16)(65535) #endif #endif #if FW_HAS_32_BIT #ifndef I32_MAX -#define I32_MAX 2147483647 +#define I32_MAX (I32)(2147483647) #endif #ifndef I32_MIN -#define I32_MIN -2147483648 +#define I32_MIN (I32)(-2147483648) #endif #ifndef U32_MAX -#define U32_MAX 4294967295 +#define U32_MAX (U32)(4294967295) #endif #endif #if FW_HAS_64_BIT #ifndef I64_MAX -#define I64_MAX 9223372036854775807 +#define I64_MAX (I64)(9223372036854775807) #endif #ifndef I64_MIN -#define I64_MIN -9223372036854775808 +#define I64_MIN (I64)(-9223372036854775808) #endif #ifndef U64_MAX -#define U64_MAX 18446744073709551615 +#define U64_MAX (U64)(18446744073709551615) #endif #endif