Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libs/bsw/middleware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,17 @@ target_include_directories(
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)

target_link_libraries(middlewareHeaders INTERFACE etl)

add_library(
middleware
src/middleware/core/ClusterConnection.cpp
src/middleware/core/ClusterConnectionBase.cpp
src/middleware/core/DatabaseManipulator.cpp
src/middleware/core/IClusterConnectionConfigurationBase.cpp
src/middleware/core/LoggerApi.cpp
src/middleware/core/ProxyBase.cpp
src/middleware/core/SkeletonBase.cpp)

target_include_directories(middleware PUBLIC include)

target_link_libraries(middleware PUBLIC etl)
8 changes: 4 additions & 4 deletions libs/bsw/middleware/doc/dd/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The core software unit of the middleware provides the key algorithms needed for
Middleware Message
------------------

Middleware is a service-oriented message passing system, and as such the ``MiddlewareMessage`` class is the fundamental unit of communication.
Middleware is a service-oriented message passing system, and as such the ``Message`` class is the fundamental unit of communication.
This class consists of a header and a payload.
The header has the following information:

Expand All @@ -19,11 +19,11 @@ The header has the following information:
* Address ID - identifies the recipient of the message within the destination cluster.

The middleware services' nodes will be scattered across different clusters in the ECU.
This means that messages can travel between clusters, and as such the ``MiddlewareMessage`` needs to have information about its origin and destination.
This means that messages can travel between clusters, and as such the ``Message`` needs to have information about its origin and destination.
Additionally, there may exist several possible recipients of a message, and as such, each recipient needs to have a unique identifier after system initialization.
To this end, the header contains the source cluster ID, target cluster ID, and address ID fields.

Finally, the payload contains the actual data being transmitted. This payload can be up to MAX_PAYLOAD_SIZE (currently 20 bytes long) and is stored directly within the ``MiddlewareMessage`` object.
If the payload exceeds this size, the middleware employs its own memory management system and stores an external handle within the ``MiddlewareMessage`` object.
Finally, the payload contains the actual data being transmitted. This payload can be up to MAX_PAYLOAD_SIZE (currently 20 bytes long) and is stored directly within the ``Message`` object.
If the payload exceeds this size, the middleware employs its own memory management system and stores an external handle within the ``Message`` object.
This handle contains information about the location and size of the payload in the middleware's memory region, as well as a flag indicating whether the payload is shared among multiple messages.
In case of internal errors, the payload can store an error code instead, which is delivered to any recipient waiting for a response.
2 changes: 1 addition & 1 deletion libs/bsw/middleware/doc/dd/queue.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Queue
=====

The queue folder contains a multi-producer single-consumer queue implementation, which is composed of a non-templated base class and a generic templated class.
This queue will be unique to each cluster in the middleware system, and will be used to store ``MiddlewareMessage`` objects.
This queue will be unique to each cluster in the middleware system, and will be used to store ``Message`` objects.
The queue must be declared with a ``QueueTraits`` type, which is a templated structure that contains the following members:

* T - the type that will be contained in the queue
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Copyright 2025 BMW AG

#pragma once

#include <cstdint>

namespace middleware
{
namespace concurrency
{

/**
* \brief Suspend all interrupts.
* \details Platform-specific function that suspends all interrupts to ensure critical sections
* are protected. This is used in conjunction with lock strategies for thread-safe operations.
* The implementation must be provided for each platform integration.
*/
extern void suspendAllInterrupts();

/**
* \brief Scoped lock for single-core protection.
* \details RAII-style lock that protects critical sections within a single core by disabling
* interrupts or using other single-core synchronization mechanisms. The lock is acquired in the
* constructor and automatically released in the destructor, ensuring proper cleanup even in the
* presence of exceptions.
* The implementation must be provided for each platform integration.
*/
struct ScopedCoreLock
{
/**
* \brief Constructor that acquires the core lock.
* \details Acquires the single-core lock by suspending interrupts or using other
* synchronization mechanisms.
*/
ScopedCoreLock();

/**
* \brief Destructor that releases the core lock.
* \details Releases the single-core lock by restoring interrupts or releasing the
* synchronization mechanism.
*/
~ScopedCoreLock();

ScopedCoreLock(ScopedCoreLock const&) = delete;
ScopedCoreLock& operator=(ScopedCoreLock const&) = delete;
};

/**
* \brief Scoped lock for ECU-wide (multi-core) protection.
* \details RAII-style lock that protects critical sections across multiple cores in an ECU by
* using hardware-supported spinlocks or other multi-core synchronization mechanisms. The lock is
* acquired in the constructor and automatically released in the destructor, ensuring proper
* cleanup even in the presence of exceptions.
* The implementation must be provided for each platform integration.
*/
struct ScopedECULock
{
/**
* \brief Constructor that acquires the ECU lock.
* \details Acquires the ECU-wide lock using the provided spinlock variable for multi-core
* synchronization.
*
* \param lock pointer to the volatile spinlock variable
*/
ScopedECULock(uint8_t volatile* lock);

/**
* \brief Destructor that releases the ECU lock.
* \details Releases the ECU-wide lock, allowing other cores to acquire it.
*/
~ScopedECULock();

ScopedECULock(ScopedECULock const&) = delete;
ScopedECULock& operator=(ScopedECULock const&) = delete;
};

} // namespace concurrency
} // namespace middleware
Loading
Loading