Skip to content

Commit

Permalink
Merge pull request #1983 from JakubSosnovec/iox-1982-freertos-platform
Browse files Browse the repository at this point in the history
iox-#1982 FreeRTOS platform implementation
  • Loading branch information
elfenpiff authored Jul 27, 2023
2 parents a0686bc + 190291a commit 7a5d86b
Show file tree
Hide file tree
Showing 69 changed files with 1,978 additions and 43 deletions.
15 changes: 14 additions & 1 deletion iceoryx_dust/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,27 @@
# SPDX-License-Identifier: Apache-2.0

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//bazel:configure_file.bzl", "configure_file")

configure_file(
name = "iceoryx_dust_deployment_hpp",
src = "cmake/iceoryx_dust_deployment.hpp.in",
out = "include/iceoryx_dust/iceoryx_dust_deployment.hpp",
config = {
"IOX_MAX_NAMED_PIPE_MESSAGE_SIZE": "4096",
"IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES": "10",
},
)

cc_library(
name = "iceoryx_dust",
srcs = glob([
"source/**/*.cpp",
"source/**/*.hpp",
]),
hdrs = glob(["include/**"] + glob(["vocabulary/**"])),
hdrs = glob(["include/**"] + glob(["vocabulary/**"])) + [
":iceoryx_dust_deployment_hpp",
],
includes = [
"include",
"vocabulary/include/",
Expand Down
19 changes: 19 additions & 0 deletions iceoryx_dust/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ include(IceoryxPackageHelper)
include(IceoryxPlatform)
include(IceoryxPlatformSettings)

include(cmake/IceoryxDustDeployment.cmake)

if(CMAKE_SYSTEM_NAME MATCHES Linux OR CMAKE_SYSTEM_NAME MATCHES Darwin)
option(BUILD_SHARED_LIBS "Create shared libraries by default" ON)
endif()
Expand All @@ -46,6 +48,7 @@ iox_add_library(
PUBLIC_LIBS iceoryx_hoofs::iceoryx_hoofs
BUILD_INTERFACE ${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/vocabulary/include
${CMAKE_BINARY_DIR}/generated/iceoryx/include
INSTALL_INTERFACE include/${PREFIX}
EXPORT_INCLUDE_DIRS include/
vocabulary/include/
Expand All @@ -61,6 +64,22 @@ iox_add_library(
source/posix_wrapper/message_queue.cpp
)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/iceoryx_dust_deployment.hpp.in"
"${CMAKE_BINARY_DIR}/generated/iceoryx/include/iceoryx_dust/iceoryx_dust_deployment.hpp" @ONLY)

install(
FILES ${CMAKE_BINARY_DIR}/generated/iceoryx/include/${PROJECT_NAME}/iceoryx_dust_deployment.hpp
DESTINATION include/${PREFIX}/${PROJECT_NAME}/
COMPONENT dev
)

# install deployment file to make posh config accessible by other packages
install(
FILES
cmake/IceoryxDustDeployment.cmake
DESTINATION ${DESTINATION_CONFIGDIR}
)

#
########## dust testing ##########
#
Expand Down
43 changes: 43 additions & 0 deletions iceoryx_dust/cmake/IceoryxDustDeployment.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
# Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
# Copyright (c) 2023 by NXP. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0

# define macro for option configuration
macro(configure_option)
set(ONE_VALUE_ARGS NAME DEFAULT_VALUE)
cmake_parse_arguments(CONFIGURE_OPTION "" "${ONE_VALUE_ARGS}" "" ${ARGN})

if(NOT ${CONFIGURE_OPTION_NAME})
set(${CONFIGURE_OPTION_NAME} ${CONFIGURE_OPTION_DEFAULT_VALUE})
endif()
message(STATUS "[i] ${CONFIGURE_OPTION_NAME}: " ${${CONFIGURE_OPTION_NAME}})
endmacro()

# configure deployment
message(STATUS "[i] <<<<<<<<<<<<< Start iceoryx_dust configuration: >>>>>>>>>>>>>")

configure_option(
NAME IOX_MAX_NAMED_PIPE_MESSAGE_SIZE
DEFAULT_VALUE 4096
)
configure_option(
NAME IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES
DEFAULT_VALUE 10
)

message(STATUS "[i] <<<<<<<<<<<<<< End iceoryx_dust configuration: >>>>>>>>>>>>>>")

32 changes: 32 additions & 0 deletions iceoryx_dust/cmake/iceoryx_dust_deployment.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2023 by NXP. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_POSH_ICEORYX_DUST_DEPLOYMENT_HPP
#define IOX_POSH_ICEORYX_DUST_DEPLOYMENT_HPP

#include <cstdint>

namespace iox
{
namespace build
{
constexpr uint64_t IOX_MAX_NAMED_PIPE_MESSAGE_SIZE = static_cast<uint64_t>(@IOX_MAX_NAMED_PIPE_MESSAGE_SIZE@);
constexpr uint32_t IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES =
static_cast<uint32_t>(@IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES@);
} // namespace build
} // namespace iox

#endif // IOX_POSH_ICEORYX_DUST_DEPLOYMENT_HPP
13 changes: 13 additions & 0 deletions iceoryx_dust/include/iceoryx_dust/internal/cxx/convert.inl
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ inline bool convert::fromString<unsigned long>(const char* v, unsigned long& des
}
#endif

#if defined(__GNUC__) && (INTPTR_MAX == INT32_MAX)
/// introduced for 32-bit arm-none-eabi-gcc since uintptr_t is not uint32_t despite it has the same size
/// who knows why ¯\_(ツ)_/¯
template <>
inline bool convert::fromString<uintptr_t>(const char* v, uintptr_t& dest) noexcept
{
uint64_t temp{0};
bool retVal = fromString(v, temp);
dest = temp;
return retVal;
}
#endif

template <>
inline bool convert::fromString<uint32_t>(const char* v, uint32_t& dest) noexcept
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define IOX_DUST_POSIX_WRAPPER_NAMED_PIPE_HPP

#include "iceoryx_dust/design/creation.hpp"
#include "iceoryx_dust/iceoryx_dust_deployment.hpp"
#include "iceoryx_hoofs/concurrent/lockfree_queue.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/ipc_channel.hpp"
#include "iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp"
Expand All @@ -39,8 +40,8 @@ class NamedPipe : public DesignPattern::Creation<NamedPipe, IpcChannelError>
public:
// no system restrictions at all, except available memory. MAX_MESSAGE_SIZE and MAX_NUMBER_OF_MESSAGES can be
// increased as long as there is enough memory available
static constexpr uint64_t MAX_MESSAGE_SIZE = 4096U;
static constexpr uint32_t MAX_NUMBER_OF_MESSAGES = 10U;
static constexpr uint64_t MAX_MESSAGE_SIZE = build::IOX_MAX_NAMED_PIPE_MESSAGE_SIZE;
static constexpr uint32_t MAX_NUMBER_OF_MESSAGES = build::IOX_MAX_NAMED_PIPE_NUMBER_OF_MESSAGES;
static_assert(MAX_NUMBER_OF_MESSAGES < IOX_SEM_VALUE_MAX,
"The maximum number of supported messages must be less than the maximum allowed semaphore value");

Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/container/include/iox/detail/vector.inl
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ inline bool vector<T, Capacity>::erase(iterator position) noexcept
{
// AXIVION Next Line AutosarC++19_03-M5.0.9 : False positive. Pointer arithmetic occurs here.
uint64_t index{static_cast<uint64_t>(position - begin())};
size_t n{index};
uint64_t n{index};
while ((n + 1U) < size())
{
// AXIVION Next Line AutosarC++19_03-A5.0.1 : Expands to basic variable assignment. Evaluation order is inconsequential.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define IOX_HOOFS_POSIX_WRAPPER_POSIX_CALL_INL

#include "iceoryx_hoofs/posix_wrapper/posix_call.hpp"
#include "iceoryx_platform/errno.hpp"
#include "iox/logging.hpp"

namespace iox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SharedMemoryObject : public FileManagementInterface<SharedMemoryObject>
void* getBaseAddress() noexcept;

/// @brief Returns the underlying file handle of the shared memory
int getFileHandle() const noexcept;
shm_handle_t getFileHandle() const noexcept;

/// @brief True if the shared memory has the ownership. False if an already
/// existing shared memory was opened.
Expand All @@ -85,7 +85,7 @@ class SharedMemoryObject : public FileManagementInterface<SharedMemoryObject>
SharedMemoryObject(SharedMemory&& sharedMemory, MemoryMap&& memoryMap) noexcept;

friend struct FileManagementInterface<SharedMemoryObject>;
int get_file_handle() const noexcept;
shm_handle_t get_file_handle() const noexcept;

private:
SharedMemory m_sharedMemory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ enum class SharedMemoryError
UNKNOWN_ERROR
};

/// @brief Shared memory file descriptor type
using shm_handle_t = int;

/// @brief Creates a bare metal shared memory object with the posix functions
/// shm_open, shm_unlink etc.
/// It must be used in combination with MemoryMap (or manual mmap calls)
Expand All @@ -70,7 +73,7 @@ class SharedMemory : public FileManagementInterface<SharedMemory>
~SharedMemory() noexcept;

/// @brief returns the file handle of the shared memory
int32_t getHandle() const noexcept;
shm_handle_t getHandle() const noexcept;

/// @brief this class has the ownership of the shared memory when the shared
/// memory was created by this class. This is the case when this class
Expand All @@ -88,7 +91,7 @@ class SharedMemory : public FileManagementInterface<SharedMemory>
friend class SharedMemoryBuilder;

private:
SharedMemory(const Name_t& name, const int handle, const bool hasOwnership) noexcept;
SharedMemory(const Name_t& name, const shm_handle_t handle, const bool hasOwnership) noexcept;

bool unlink() noexcept;
bool close() noexcept;
Expand All @@ -98,10 +101,10 @@ class SharedMemory : public FileManagementInterface<SharedMemory>
static SharedMemoryError errnoToEnum(const int32_t errnum) noexcept;

friend struct FileManagementInterface<SharedMemory>;
int32_t get_file_handle() const noexcept;
shm_handle_t get_file_handle() const noexcept;

Name_t m_name;
int m_handle{INVALID_HANDLE};
shm_handle_t m_handle{INVALID_HANDLE};
bool m_hasOwnership{false};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ class UnixDomainSocket
private:
UnixDomainSocket(const IpcChannelName_t& name,
const IpcChannelSide channelSide,
const size_t maxMsgSize = MAX_MESSAGE_SIZE,
const uint64_t maxMsgSize = MAX_MESSAGE_SIZE,
const uint64_t maxMsgNumber = 10U) noexcept;

UnixDomainSocket(const NoPathPrefix_t,
const UdsName_t& name,
const IpcChannelSide channelSide,
const size_t maxMsgSize = MAX_MESSAGE_SIZE,
const uint64_t maxMsgSize = MAX_MESSAGE_SIZE,
const uint64_t maxMsgNumber = 10U) noexcept;

expected<void, IpcChannelError> destroy() noexcept;
Expand All @@ -136,7 +136,7 @@ class UnixDomainSocket
IpcChannelSide m_channelSide = IpcChannelSide::CLIENT;
int32_t m_sockfd{INVALID_FD};
sockaddr_un m_sockAddr{};
size_t m_maxMessageSize{MAX_MESSAGE_SIZE};
uint64_t m_maxMessageSize{MAX_MESSAGE_SIZE};
};


Expand Down
5 changes: 3 additions & 2 deletions iceoryx_hoofs/include/iceoryx_hoofs/posix_wrapper/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "iox/string.hpp"

#include <atomic>
#include <thread>

namespace iox
{
Expand All @@ -34,8 +35,8 @@ constexpr uint64_t MAX_THREAD_NAME_LENGTH = 15U;
using ThreadName_t = string<MAX_THREAD_NAME_LENGTH>;

/// @todo iox-#1365 remove free functions
void setThreadName(iox_pthread_t thread, const ThreadName_t& name) noexcept;
ThreadName_t getThreadName(iox_pthread_t thread) noexcept;
void setThreadName(std::thread::native_handle_type thread, const ThreadName_t& name) noexcept;
ThreadName_t getThreadName(std::thread::native_handle_type thread) noexcept;

enum class ThreadError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Ownership
Ownership(const uid_t uid, const gid_t gid) noexcept;

private:
uid_t m_uid{std::numeric_limits<pid_t>::max()};
uid_t m_uid{std::numeric_limits<uid_t>::max()};
gid_t m_gid{std::numeric_limits<gid_t>::max()};
};

Expand Down
13 changes: 11 additions & 2 deletions iceoryx_hoofs/primitives/include/iox/algorithm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ inline constexpr bool doesContainValue(const T) noexcept;
/// @return true if value is contained in the ValueList, otherwise false
/// @note be aware that value is tested for exact equality with the entries of ValueList and regular floating-point
/// comparison rules apply
template <typename T, typename... ValueList>
template <typename T1, typename T2, typename... ValueList>
inline constexpr bool
doesContainValue(const T value, const T firstValueListEntry, const ValueList... remainingValueListEntries) noexcept;
doesContainValue(const T1 value, const T2 firstValueListEntry, const ValueList... remainingValueListEntries) noexcept;
} // namespace algorithm

namespace internal
Expand Down Expand Up @@ -150,11 +150,20 @@ struct BestFittingTypeImpl<true, true, false>
template <uint64_t Value>
struct BestFittingType
{
// gcc warns here that the uint8_t test for BestFittingType<256> is always true... which is correct, but we need it for
// portability anyway
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtype-limits"
#endif
using Type_t =
typename internal::BestFittingTypeImpl<(Value > static_cast<uint64_t>(std::numeric_limits<uint8_t>::max())),
(Value > static_cast<uint64_t>(std::numeric_limits<uint16_t>::max())),
(Value
> static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()))>::Type_t;
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif
};

template <uint64_t Value>
Expand Down
4 changes: 2 additions & 2 deletions iceoryx_hoofs/primitives/include/iox/detail/algorithm.inl
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ inline constexpr bool doesContainValue(const T) noexcept
return false;
}

template <typename T, typename... ValueList>
template <typename T1, typename T2, typename... ValueList>
inline constexpr bool
doesContainValue(const T value, const T firstValueListEntry, const ValueList... remainingValueListEntries) noexcept
doesContainValue(const T1 value, const T2 firstValueListEntry, const ValueList... remainingValueListEntries) noexcept
{
// AXIVION Next Line AutosarC++19_03-M6.2.2 : intentional check for exact equality
return (value == firstValueListEntry) ? true : doesContainValue(value, remainingValueListEntries...);
Expand Down
2 changes: 1 addition & 1 deletion iceoryx_hoofs/source/concurrent/loffli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void LoFFLi::init(not_null<Index_t*> freeIndicesMemory, const uint32_t capacity)
cxx::Expects(capacity > 0 && "A capacity of 0 is not supported!");
constexpr uint32_t INTERNALLY_RESERVED_INDICES{1U};
cxx::Expects(capacity < (std::numeric_limits<Index_t>::max() - INTERNALLY_RESERVED_INDICES)
&& "Requested capacityexceeds limits!");
&& "Requested capacity exceeds limits!");
cxx::Expects(m_head.is_lock_free() && "std::atomic<LoFFLi::Node> must be lock-free!");

m_nextFreeIndex = freeIndicesMemory;
Expand Down
6 changes: 3 additions & 3 deletions iceoryx_hoofs/source/posix_wrapper/posix_access_rights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PosixGroup::PosixGroup(const PosixGroup::groupName_t& name) noexcept
else
{
IOX_LOG(ERROR) << "Error: Group name not found";
m_id = std::numeric_limits<uint32_t>::max();
m_id = std::numeric_limits<gid_t>::max();
}
}

Expand Down Expand Up @@ -149,7 +149,7 @@ PosixUser::groupVector_t PosixUser::getGroups() const noexcept

gid_t userDefaultGroup = getpwnamCall->value->pw_gid;
UninitializedArray<gid_t, MaxNumberOfGroups> groups{}; // groups is initialized in iox_getgrouplist
int32_t numGroups = MaxNumberOfGroups;
auto numGroups = MaxNumberOfGroups;

auto getgrouplistCall = posixCall(iox_getgrouplist)(userName->c_str(), userDefaultGroup, &groups[0], &numGroups)
.failureReturnValue(-1)
Expand Down Expand Up @@ -191,7 +191,7 @@ PosixUser::PosixUser(const PosixUser::userName_t& name) noexcept
else
{
IOX_LOG(ERROR) << "Error: User name not found";
m_id = std::numeric_limits<uint32_t>::max();
m_id = std::numeric_limits<gid_t>::max();
}
}

Expand Down
Loading

0 comments on commit 7a5d86b

Please sign in to comment.