Skip to content

Commit

Permalink
Dev/abcouwer/cmake baremetal fixes (#821)
Browse files Browse the repository at this point in the history
* 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.

* Cast MIN and MAX types for proper comparisons.

Co-authored-by: Neil Abcouwer <neil.abcouwer@jpl.nasa.gov>
  • Loading branch information
nabcouwer and abcouwer-jpl authored Jul 14, 2021
1 parent 5cdfceb commit 2a96785
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Drv/BlockDriver/BlockDriverComponentAi.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
Internal interrupt reporting interface
</comment>
<args>
<arg name="interrupt" type="U32">
<arg name="interrupt_val" type="U32">
<comment>The interrupt register value</comment>
</arg>
</args>
Expand Down
16 changes: 11 additions & 5 deletions Drv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion Fw/Cfg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions Fw/Types/BasicTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,61 @@ typedef float F32; //!< 32-bit floating point
#define NULL (0) //!< NULL
#endif


#ifndef I8_MAX
#define I8_MAX (I8)(127)
#endif

#ifndef I8_MIN
#define I8_MIN (I8)(-128)
#endif

#ifndef U8_MAX
#define U8_MAX (U8)(255)
#endif

#if FW_HAS_16_BIT
#ifndef I16_MAX
#define I16_MAX (I16)(32767)
#endif

#ifndef I16_MIN
#define I16_MIN (I16)(-32768)
#endif

#ifndef U16_MAX
#define U16_MAX (U16)(65535)
#endif
#endif

#if FW_HAS_32_BIT
#ifndef I32_MAX
#define I32_MAX (I32)(2147483647)
#endif

#ifndef I32_MIN
#define I32_MIN (I32)(-2147483648)
#endif

#ifndef U32_MAX
#define U32_MAX (U32)(4294967295)
#endif
#endif

#if FW_HAS_64_BIT
#ifndef I64_MAX
#define I64_MAX (I64)(9223372036854775807)
#endif

#ifndef I64_MIN
#define I64_MIN (I64)(-9223372036854775808)
#endif

#ifndef U64_MAX
#define U64_MAX (U64)(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
Expand Down
1 change: 1 addition & 0 deletions Os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
8 changes: 6 additions & 2 deletions Svc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ 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/")
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()

9 changes: 8 additions & 1 deletion Svc/ComLogger/ComLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@
#include <stdio.h>
#include <cstdarg>

// 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 :
Expand Down Expand Up @@ -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:
Expand Down
11 changes: 10 additions & 1 deletion Svc/FatalHandler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Svc/FileDownlink/FileDownlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion cmake/platform/Linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion cmake/platform/platform.cmake.template
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2a96785

Please sign in to comment.