add erpc lib

This commit is contained in:
xtkuang 2026-11-13 10:24:49 +08:00
parent ac82695467
commit bef898b1b8
37 changed files with 6119 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__ARBITRATED_CLIENT_MANAGER_H_
#define _EMBEDDED_RPC__ARBITRATED_CLIENT_MANAGER_H_
#include "erpc_client_manager.h"
/*!
* @addtogroup infra_client
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
class TransportArbitrator;
/*!
* @brief Client that can share a transport with a server.
*
* This class is a special subclass of ClientManager that works with the TransportArbitrator
* to share a single transport with a Server. This enables, for instance, a single UART to
* be used for bidirectional remote function invocations and replies.
*
* The setTransport() method used on ClientManager is not used with this class. Instead, there
* is a setArbitrator() method. The underlying transport that is shared is set on the arbitrator.
*
* @ingroup infra_client
*/
class ArbitratedClientManager : public ClientManager
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
ArbitratedClientManager(void) : ClientManager(), m_arbitrator(NULL) {}
/*!
* @brief Sets the transport arbitrator instance.
*
* @param[in] arbitrator Transport arbitrator to use.
*/
void setArbitrator(TransportArbitrator *arbitrator);
/*!
* @brief Gets the transport arbitrator instance.
*
* @return TransportArbitrator * Transport arbitrator instance.
*/
TransportArbitrator *getArbitrator(void) { return m_arbitrator; };
protected:
TransportArbitrator *m_arbitrator; //!< Optional transport arbitrator. May be NULL.
/*!
* @brief This function performs request.
*
* Should be called in non server context (do not call another eRPC function in server
* remote call implementation).
*
* @param[in] request Request context to perform.
*/
virtual void performClientRequest(RequestContext &request) override;
//! @brief This method is not used with this class.
void setTransport(Transport *transport) { (void)transport; }
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__ARBITRATED_CLIENT_MANAGER_H_

View File

@ -0,0 +1,162 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2019 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_ARBITRATED_CLIENT_SETUP_H_
#define _ERPC_ARBITRATED_CLIENT_SETUP_H_
#include "erpc_common.h"
#include "erpc_config_internal.h"
#include "erpc_mbf_setup.h"
#if ERPC_PRE_POST_ACTION
#include "erpc_pre_post_action.h"
#endif
#if ERPC_NESTED_CALLS
#include "erpc_server_setup.h"
#endif
#include "erpc_client_manager.h"
#include "erpc_transport_setup.h"
/*!
* @addtogroup client_setup
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
//! @name Arbitrated client setup
//@{
/*!
* @brief Initializes a client that shares its transport with the server.
*
* This function initializes a client with all components necessary for sending client requests
* using the same transport instance as used by a server. Only one instance of the shared
* transport should be created. The transport arbitrator that wraps the shared transport is
* returned. This arbitrator, not the shared transport, should be passed to the server setup
* routine.
*
* Example use:
* @code
* erpc_transport_t arbitrator;
* erpc_transport_t sharedSerial = erpc_transport_serial_init(...);
* erpc_client_t client = erpc_arbitrated_client_init(sharedSerial, message_buffer_factory, &arbitrator);
* erpc_server_init(arbitrator);
* @endcode
*
* @param[in] transport Initiated transport.
* @param[in] message_buffer_factory Initiated message buffer factory.
* @param[out] arbitrator Transport arbitrator reference that should be passed to the server setup API.
*
* @return erpc_client_t Pointer to client structure.
*/
erpc_client_t erpc_arbitrated_client_init(erpc_transport_t transport, erpc_mbf_t message_buffer_factory,
erpc_transport_t *arbitrator);
/*!
* @brief This function sets error handler function.
*
* Given error_handler function is called when error occur inside eRPC infrastructure.
*
* @param[in] client Pointer to client structure.
* @param[in] error_handler Pointer to function error handler.
*/
void erpc_arbitrated_client_set_error_handler(erpc_client_t client, client_error_handler_t error_handler);
/*!
* @brief Can be used to set own crcStart number.
*
* For example can be used generated crc from erpcgen
* which is providing when @crc annotation is used.
* Accessed can be through 'extern const uint32_t erpc_generated_crc;'
*
* @param[in] client Pointer to client structure.
* @param[in] crcStart Set start number for crc.
*/
void erpc_arbitrated_client_set_crc(erpc_client_t client, uint32_t crcStart);
#if ERPC_NESTED_CALLS
/*!
* @brief This function sets server object for handling nested eRPC calls.
*
* @param[in] client Pointer to client structure.
* @param[in] server Initiated server.
*/
void erpc_arbitrated_client_set_server(erpc_client_t client, erpc_server_t server);
/*!
* @brief This function sets server thread id.
*
* @param[in] client Pointer to client structure.
* @param[in] serverThreadId Id of thread where server run function is executed.
*/
void erpc_arbitrated_client_set_server_thread_id(erpc_client_t client, void *serverThreadId);
#endif
#if ERPC_MESSAGE_LOGGING
/*!
* @brief This function adds transport object for logging send/receive messages.
*
* @param[in] client Pointer to client structure.
* @param[in] transport Initiated transport.
*
* @retval True When transport was successfully added.
* @retval False When transport wasn't added.
*/
bool erpc_arbitrated_client_add_message_logger(erpc_client_t client, erpc_transport_t transport);
#endif
#if ERPC_PRE_POST_ACTION
/*!
* @brief This function set callback function executed at the beginning of eRPC call.
*
* @param[in] client Pointer to client structure.
* @param[in] preCB Callback used at the beginning of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_arbitrated_client_add_pre_cb_action(erpc_client_t client, pre_post_action_cb preCB);
/*!
* @brief This function set callback function executed at the end of eRPC call.
*
* @param[in] client Pointer to client structure.
* @param[in] postCB Callback used at the end of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_arbitrated_client_add_post_cb_action(erpc_client_t client, pre_post_action_cb postCB);
#endif
/*!
* @brief This function de-initializes client.
*
* This function de-initializes client and all components which it own.
*
* @param[in] client Pointer to client structure.
*/
void erpc_arbitrated_client_deinit(erpc_client_t client);
//@}
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _ERPC_ARBITRATED_CLIENT_SETUP_H_

View File

@ -0,0 +1,381 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2021 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__BASIC_SERIALIZATION_H_
#define _EMBEDDED_RPC__BASIC_SERIALIZATION_H_
#include "erpc_codec.hpp"
/*!
* @addtogroup infra_codec
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Values of the uint8 flag prefixing nullable values.
*/
enum class null_flag_t
{
kNotNull = 0,
kIsNull
};
/*!
* @brief Simple binary serialization format.
*
* @ingroup infra_codec
*/
class BasicCodec : public Codec
{
public:
static const uint32_t kBasicCodecVersion; /*!< Codec version. */
/*!
* @brief Constructor.
*/
BasicCodec(void);
/*!
* @brief CodecFactory destructor
*/
virtual ~BasicCodec(void);
//! @name Encoding
//@{
/*!
* @brief Prototype for write header of message.
*
* @param[in] type Type of message.
* @param[in] service Which interface is requested.
* @param[in] request Which function need be called.
* @param[in] sequence Send sequence number to be sure that
* received message is reply for current request. or write function.
*/
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) override;
/*!
* @brief Prototype for write data stream.
*
* @param[in] length Size of data stream in bytes.
* @param[in] value Pointer to data stream.
*/
virtual void writeData(uint32_t length, const void *value);
/*!
* @brief Prototype for write boolean value.
*
* @param[in] value Boolean typed value to write.
*/
virtual void write(bool value) override;
/*!
* @brief Prototype for write int8_t value.
*
* @param[in] value int8_t typed value to write.
*/
virtual void write(int8_t value) override;
/*!
* @brief Prototype for write int16_t value.
*
* @param[in] value int16_t typed value to write.
*/
virtual void write(int16_t value) override;
/*!
* @brief Prototype for write int32_t value.
*
* @param[in] value int32_t typed value to write.
*/
virtual void write(int32_t value) override;
/*!
* @brief Prototype for write int64_t value.
*
* @param[in] value int64_t typed value to write.
*/
virtual void write(int64_t value) override;
/*!
* @brief Prototype for write uint8_t value.
*
* @param[in] value uint8_t typed value to write.
*/
virtual void write(uint8_t value) override;
/*!
* @brief Prototype for write uint16_t value.
*
* @param[in] value uint16_t typed value to write.
*/
virtual void write(uint16_t value) override;
/*!
* @brief Prototype for write uint32_t value.
*
* @param[in] value uint32_t typed value to write.
*/
virtual void write(uint32_t value) override;
/*!
* @brief Prototype for write uint64_t value.
*
* @param[in] value uint64_t typed value to write.
*/
virtual void write(uint64_t value) override;
/*!
* @brief Prototype for write float value.
*
* @param[in] value float typed value to write.
*/
virtual void write(float value) override;
/*!
* @brief Prototype for write double value.
*
* @param[in] value double typed value to write.
*/
virtual void write(double value) override;
/*!
* @brief Prototype for write uintptr value.
*
* @param[in] value uintptr typed value to write.
*/
virtual void writePtr(uintptr_t value) override;
/*!
* @brief Prototype for write string value.
*
* @param[in] length of string.
* @param[in] value string value to write.
*/
virtual void writeString(uint32_t length, const char *value) override;
/*!
* @brief Prototype for write binary value.
*
* @param[in] length of binary.
* @param[in] value Binary value to write.
*/
virtual void writeBinary(uint32_t length, const uint8_t *value) override;
/*!
* @brief Prototype for start write list.
*
* @param[in] length Length of list.
*/
virtual void startWriteList(uint32_t length) override;
/*!
* @brief Prototype for start write union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startWriteUnion(int32_t discriminator) override;
/*!
* @brief Writes a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to send.
*/
virtual void writeNullFlag(bool isNull) override;
//@}
//! @name Decoding
//@{
/*!
* @brief Prototype for read header of message.
*
* @param[out] type Type of message.
* @param[out] service Which interface was used.
* @param[out] request Which function was called.
* @param[out] sequence Returned sequence number to be sure that
* received message is reply for current request.
*/
virtual void startReadMessage(message_type_t &type, uint32_t &service, uint32_t &request,
uint32_t &sequence) override;
/*!
* @brief Prototype for read data stream.
*
* @param[in] length Size of data stream in bytes to be read.
* @param[in] value Pointer to data stream to be read.
*/
virtual void readData(uint32_t length, void *value);
/*!
* @brief Prototype for read boolean value.
*
* @param[out] value Boolean typed value to read.
*/
virtual void read(bool &value) override;
/*!
* @brief Prototype for read int8_t value.
*
* @param[out] value int8_t typed value to read.
*/
virtual void read(int8_t &value) override;
/*!
* @brief Prototype for read int16_t value.
*
* @param[out] value int16_t typed value to read.
*/
virtual void read(int16_t &value) override;
/*!
* @brief Prototype for read int32_t value.
*
* @param[out] value int32_t typed value to read.
*/
virtual void read(int32_t &value) override;
/*!
* @brief Prototype for read int64_t value.
*
* @param[out] value int64_t typed value to read.
*/
virtual void read(int64_t &value) override;
/*!
* @brief Prototype for read uint8_t value.
*
* @param[out] value uint8_t typed value to read.
*/
virtual void read(uint8_t &value) override;
/*!
* @brief Prototype for read uint16_t value.
*
* @param[out] value uint16_t typed value to read.
*/
virtual void read(uint16_t &value) override;
/*!
* @brief Prototype for read uint32_t value.
*
* @param[out] value uint32_t typed value to read.
*/
virtual void read(uint32_t &value) override;
/*!
* @brief Prototype for read uint64_t value.
*
* @param[out] value uint64_t typed value to read.
*/
virtual void read(uint64_t &value) override;
/*!
* @brief Prototype for read float value.
*
* @param[out] value float typed value to read.
*/
virtual void read(float &value) override;
/*!
* @brief Prototype for read double value.
*
* @param[out] value double typed value to read.
*/
virtual void read(double &value) override;
/*!
* @brief Prototype for read uintptr value.
*
* @param[out] value uintptr typed value to read.
*/
virtual void readPtr(uintptr_t &value) override;
/*!
* @brief Prototype for read string value.
*
* @param[out] length of string.
* @param[out] value String value to read.
*/
virtual void readString(uint32_t &length, char **value) override;
/*!
* @brief Prototype for read binary value.
*
* @param[out] length of binary. 0 can be valid value or in case of error.
* @param[out] value Binary value to read. Null in case of error.
*/
virtual void readBinary(uint32_t &length, uint8_t **value) override;
/*!
* @brief Prototype for start read list.
*
* @param[out] length Length of list.
*/
virtual void startReadList(uint32_t &length) override;
/*!
* @brief Prototype for start read union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startReadUnion(int32_t &discriminator) override;
/*!
* @brief Reads a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to read.
*/
virtual void readNullFlag(bool &isNull) override;
//@}
};
/*!
* @brief Basic codec factory implements functions from codec factory.
*
* @ingroup infra_codec
*/
class BasicCodecFactory : public CodecFactory
{
public:
/*!
* @brief Constructor.
*/
BasicCodecFactory(void);
/*!
* @brief CodecFactory destructor
*/
virtual ~BasicCodecFactory(void);
/*!
* @brief Return created codec.
*
* @return Pointer to created codec.
*/
virtual Codec *create(void) override;
/*!
* @brief Dispose codec.
*
* @param[in] codec Codec to dispose.
*/
virtual void dispose(Codec *codec) override;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__BASIC_SERIALIZATION_H_

View File

@ -0,0 +1,241 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2020-2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__CLIENT_MANAGER_H_
#define _EMBEDDED_RPC__CLIENT_MANAGER_H_
#ifdef __cplusplus
#include "erpc_client_server_common.hpp"
#if ERPC_NESTED_CALLS
#include "erpc_server.hpp"
#include "erpc_threading.h"
#endif
/*!
* @addtogroup infra_client
* @{
* @file
*/
extern "C" {
#else
#include "erpc_common.h"
#endif
typedef void (*client_error_handler_t)(erpc_status_t err,
uint32_t functionID); /*!< eRPC error handler function type. */
//! @brief Opaque client object type.
typedef struct ClientType *erpc_client_t;
#ifdef __cplusplus
}
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
class RequestContext;
#if ERPC_NESTED_CALLS
class Server;
#endif
/*!
* @brief Base client implementation.
*
* @ingroup infra_client
*/
class ClientManager : public ClientServerCommon
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
ClientManager(void) :
ClientServerCommon(), m_sequence(0), m_errorHandler(NULL)
#if ERPC_NESTED_CALLS
,
m_server(NULL), m_serverThreadId(NULL)
#endif
{
}
/*!
* @brief ClientManager destructor
*/
virtual ~ClientManager(void) {}
/*!
* @brief This function creates request context.
*
* @param[in] isOneway True if need send data only, else false.
*/
virtual RequestContext createRequest(bool isOneway);
/*!
* @brief This function performs request.
*
* @param[in] request Request context to perform.
*/
virtual void performRequest(RequestContext &request);
/*!
* @brief This function releases request context.
*
* @param[in] request Request context to release.
*/
virtual void releaseRequest(RequestContext &request);
/*!
* @brief This function sets error handler function for infrastructure errors.
*
* @param[in] error_handler Pointer to error handler function.
*/
void setErrorHandler(client_error_handler_t error_handler) { m_errorHandler = error_handler; }
/*!
* @brief This function calls error handler callback function with given status.
*
* Function is called in client shim code at the end of function when error occurred.
*
* @param[in] err Specify function status at the end of eRPC call.
* @param[in] functionID Specify eRPC function call.
*/
void callErrorHandler(erpc_status_t err, uint32_t functionID);
#if ERPC_NESTED_CALLS
/*!
* @brief This function sets server used for nested calls.
*
* @param[in] server Server used for nested calls.
*/
void setServer(Server *server) { m_server = server; }
/*!
* @brief This function sets server thread id.
*
* @param[in] serverThreadId Id of thread where server run function is executed.
*/
void setServerThreadId(Thread::thread_id_t serverThreadId) { m_serverThreadId = serverThreadId; }
#endif
protected:
uint32_t m_sequence; //!< Sequence number.
client_error_handler_t m_errorHandler; //!< Pointer to function error handler.
#if ERPC_NESTED_CALLS
Server *m_server; //!< Server used for nested calls.
Thread::thread_id_t m_serverThreadId; //!< Thread in which server run function is called.
#endif
/*!
* @brief This function performs request.
*
* Should be called in non server context (do not call another eRPC function in server
* remote call implementation).
*
* @param[in] request Request context to perform.
*/
virtual void performClientRequest(RequestContext &request);
#if ERPC_NESTED_CALLS
/*!
* @brief This function performs nested request.
*
* Used when from eRPC function server implementation context is called new eRPC function.
*
* @param[in] request Request context to perform.
*/
virtual void performNestedClientRequest(RequestContext &request);
#endif
//! @brief Validate that an incoming message is a reply.
virtual void verifyReply(RequestContext &request);
/*!
* @brief Create message buffer and codec.
*
* The new codec is set to use the new message buffer. Both codec and buffer are allocated
* with the relevant factories.
*
* @return Pointer to created codec with message buffer.
*/
Codec *createBufferAndCodec(void);
private:
ClientManager(const ClientManager &other); //!< Disable copy ctor.
ClientManager &operator=(const ClientManager &other); //!< Disable copy ctor.
};
/*!
* @brief Encapsulates all information about a request.
*
* @ingroup infra_client
*/
class RequestContext
{
public:
/*!
* @brief Constructor.
*
* This function sets request context attributes.
*
* @param[in] sequence Sequence number.
* @param[in] codec Set in inout codec.
* @param[in] isOneway Set information if codec is only oneway or bidirectional.
*/
RequestContext(uint32_t sequence, Codec *codec, bool argIsOneway) :
m_sequence(sequence), m_codec(codec), m_oneway(argIsOneway)
{
}
/*!
* @brief Get inout codec (for writing).
*
* @return Inout codec.
*/
Codec *getCodec(void) { return m_codec; }
/*!
* @brief Get sequence number (be sure that reply belong to current request).
*
* @return Sequence number.
*/
uint32_t getSequence(void) const { return m_sequence; }
/*!
* @brief Returns information if request context is oneway or not.
*
* @retval True when request context is oneway direction, else false.
*/
bool isOneway(void) const { return m_oneway; }
/*!
* @brief Set request context to be oneway type (only send data).
*
* @return Set request context to be oneway.
*/
void setIsOneway(bool oneway) { m_oneway = oneway; }
protected:
uint32_t m_sequence; //!< Sequence number. To be sure that reply belong to current request.
Codec *m_codec; //!< Inout codec. Codec for receiving and sending data.
bool m_oneway; //!< When true, request context will be oneway type (only send data).
};
} // namespace erpc
/*! @} */
#endif
#endif // _EMBEDDED_RPC__CLIENT_MANAGER_H_

View File

@ -0,0 +1,145 @@
/*
* Copyright 2020 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__CLIENTSERVERCOMMON_H_
#define _EMBEDDED_RPC__CLIENTSERVERCOMMON_H_
#include "erpc_codec.hpp"
#include "erpc_config_internal.h"
#if ERPC_MESSAGE_LOGGING
#include "erpc_message_loggers.hpp"
#endif
#if ERPC_PRE_POST_ACTION
#include "erpc_pre_post_action.h"
#endif
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Common class inherited by client and server class.
*
* @ingroup infra_utility
*/
class ClientServerCommon
#if ERPC_MESSAGE_LOGGING
#ifdef ERPC_OTHER_INHERITANCE
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
public MessageLoggers
#endif
#if ERPC_PRE_POST_ACTION
#ifdef ERPC_OTHER_INHERITANCE
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
public PrePostAction
#endif
{
public:
/*!
* @brief ClientServerCommon constructor.
*/
ClientServerCommon(void)
#ifdef ERPC_OTHER_INHERITANCE
#undef ERPC_OTHER_INHERITANCE
#endif
#if ERPC_MESSAGE_LOGGING
#ifdef ERPC_OTHER_INHERITANCE
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
MessageLoggers()
#endif
#if ERPC_PRE_POST_ACTION
#ifdef ERPC_OTHER_INHERITANCE
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
PrePostAction()
#endif
#ifdef ERPC_OTHER_INHERITANCE
,
#else
#define ERPC_OTHER_INHERITANCE 1
:
#endif
m_messageFactory(NULL), m_codecFactory(NULL), m_transport(NULL){};
/*!
* @brief ClientServerCommon destructor
*/
~ClientServerCommon(void){};
/*!
* @brief This function sets message buffer factory to use.
*
* @param[in] factory Message buffer factory to use.
*/
void setMessageBufferFactory(MessageBufferFactory * factory) { m_messageFactory = factory; }
/*!
* @brief This function sets codec factory to use.
*
* @param[in] factory Codec factory to use.
*/
void setCodecFactory(CodecFactory * factory) { m_codecFactory = factory; }
/*!
* @brief This function sets codec factory to use.
*
* @return CodecFactory * Codec factory to use.
*/
CodecFactory *getCodecFactory(void) { return m_codecFactory; }
/*!
* @brief This function sets transport layer to use.
*
* It also set messageBufferFactory to the same as in transport layer.
*
* @param[in] transport Transport layer to use.
*/
void setTransport(Transport * transport) { m_transport = transport; }
/*!
* @brief This function gets transport instance.
*
* @return Transport * Pointer to transport instance.
*/
Transport *getTransport(void) { return m_transport; }
protected:
MessageBufferFactory *m_messageFactory; //!< Message buffer factory to use.
CodecFactory *m_codecFactory; //!< Codec to use.
Transport *m_transport; //!< Transport layer to use.
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__CLIENTSERVERCOMMON_H_

View File

@ -0,0 +1,148 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2019 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__CLIENT_SETUP_H_
#define _EMBEDDED_RPC__CLIENT_SETUP_H_
#include "erpc_common.h"
#include "erpc_config_internal.h"
#include "erpc_mbf_setup.h"
#if ERPC_PRE_POST_ACTION
#include "erpc_pre_post_action.h"
#endif
#if ERPC_NESTED_CALLS
#include "erpc_server_setup.h"
#endif
#include "erpc_client_manager.h"
#include "erpc_transport_setup.h"
/*!
* @addtogroup client_setup
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
//! @name Client setup
//@{
/*!
* @brief This function initializes client.
*
* This function initializes client with all components necessary for serve client request.
*
* @param[in] transport Initiated transport.
* @param[in] message_buffer_factory Initiated message buffer factory.
*
* @return erpc_client_t Pointer to client structure.
*/
erpc_client_t erpc_client_init(erpc_transport_t transport, erpc_mbf_t message_buffer_factory);
/*!
* @brief This function sets error handler function.
*
* Given error_handler function is called when error occur inside eRPC infrastructure.
*
* @param[in] client Pointer to client structure.
* @param[in] error_handler Pointer to function error handler.
*/
void erpc_client_set_error_handler(erpc_client_t client, client_error_handler_t error_handler);
/*!
* @brief Can be used to set own crcStart number.
*
* For example can be used generated crc from erpcgen
* which is providing when @crc annotation is used.
* Accessed can be through 'extern const uint32_t erpc_generated_crc;'
*
* @param[in] client Pointer to client structure.
* @param[in] crcStart Set start number for crc.
*/
void erpc_client_set_crc(erpc_client_t client, uint32_t crcStart);
#if ERPC_NESTED_CALLS
/*!
* @brief This function sets server object for handling nested eRPC calls.
*
* @param[in] client Pointer to client structure.
* @param[in] server Initiated server.
*/
void erpc_client_set_server(erpc_client_t client, erpc_server_t server);
/*!
* @brief This function sets server thread id.
*
* @param[in] client Pointer to client structure.
* @param[in] serverThreadId Id of thread where server run function is executed.
*/
void erpc_client_set_server_thread_id(erpc_client_t client, void *serverThreadId);
#endif
#if ERPC_MESSAGE_LOGGING
/*!
* @brief This function adds transport object for logging send/receive messages.
*
* @param[in] client Pointer to client structure.
* @param[in] transport Initiated transport.
*
* @retval True When transport was successfully added.
* @retval False When transport wasn't added.
*/
bool erpc_client_add_message_logger(erpc_client_t client, erpc_transport_t transport);
#endif
#if ERPC_PRE_POST_ACTION
/*!
* @brief This function set callback function executed at the beginning of eRPC call.
*
* @param[in] client Pointer to client structure.
* @param[in] preCB Callback used at the beginning of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_client_add_pre_cb_action(erpc_client_t client, pre_post_action_cb preCB);
/*!
* @brief This function set callback function executed at the end of eRPC call.
*
* @param[in] client Pointer to client structure.
* @param[in] postCB Callback used at the end of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_client_add_post_cb_action(erpc_client_t client, pre_post_action_cb postCB);
#endif
/*!
* @brief This function de-initializes client.
*
* This function de-initializes client and all components which it own.
*
* @param[in] client Pointer to client structure.
*/
void erpc_client_deinit(erpc_client_t client);
//@}
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _EMBEDDED_RPC__CLIENT_SETUP_H_

View File

@ -0,0 +1,440 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2021 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__CODEC_H_
#define _EMBEDDED_RPC__CODEC_H_
#include "erpc_common.h"
#include "erpc_message_buffer.hpp"
#include "erpc_transport.hpp"
#include <cstdint>
#include <cstring>
/*!
* @addtogroup infra_codec
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Types of messages that can be encoded.
*/
enum class message_type_t
{
kInvocationMessage = 0,
kOnewayMessage,
kReplyMessage,
kNotificationMessage
};
typedef void *funPtr; // Pointer to functions
typedef funPtr *arrayOfFunPtr; // Pointer to array of functions
/*!
* @brief Abstract serialization encoder/decoder interface.
*
* Codecs write to or read from a MessageBuffer.
*
* @ingroup infra_codec
*/
class Codec
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
Codec(void) : m_cursor(), m_status(kErpcStatus_Success) {}
/*!
* @brief Codec destructor
*/
virtual ~Codec(void) {}
/*!
* @brief Return message buffer used for read and write data.
*
* @return Pointer to used message buffer.
*/
MessageBuffer getBuffer(void) { return m_cursor.getBuffer(); }
MessageBuffer &getBufferRef(void) { return m_cursor.getBufferRef(); }
/*!
* @brief Prototype for set message buffer used for read and write data.
*
* @param[in] buf Message buffer to set.
* @param[in] skip How many bytes to skip from reading.
*/
virtual void setBuffer(MessageBuffer &buf, uint8_t skip = 0)
{
m_cursor.setBuffer(buf, skip);
m_status = kErpcStatus_Success;
}
/*!
* @brief Reset the codec to initial state.
*
* @param[in] skip How many bytes to skip from reading.
*/
virtual void reset(uint8_t skip = 0)
{
MessageBuffer buffer = m_cursor.getBuffer();
m_cursor.setBuffer(buffer, skip);
m_status = kErpcStatus_Success;
}
/*!
* @brief Return current status of eRPC message processing.
*
* @return Current status of eRPC message processing.
*/
erpc_status_t getStatus(void) { return m_status; }
/*!
* @brief Return bool value representing current status.
*
* @retval True Current status value is kErpcStatus_Success.
* @retval False Current status is other than kErpcStatus_Success.
*/
bool isStatusOk(void) { return (m_status == kErpcStatus_Success); }
/*!
* @brief Set current status of eRPC message processing to given value.
*
* @param[in] status New current value.
*/
void updateStatus(erpc_status_t status)
{
if (isStatusOk())
{
m_status = status;
}
}
//! @name Encoding
//@{
/*!
* @brief Prototype for write header of message.
*
* @param[in] type Type of message.
* @param[in] service Which interface is requested.
* @param[in] request Which function need be called.
* @param[in] sequence Send sequence number to be sure that
* received message is reply for current request.
*/
virtual void startWriteMessage(message_type_t type, uint32_t service, uint32_t request, uint32_t sequence) = 0;
/*!
* @brief Prototype for write boolean value.
*
* @param[in] value Boolean typed value to write.
*/
virtual void write(bool value) = 0;
/*!
* @brief Prototype for write int8_t value.
*
* @param[in] value int8_t typed value to write.
*/
virtual void write(int8_t value) = 0;
/*!
* @brief Prototype for write int16_t value.
*
* @param[in] value int16_t typed value to write.
*/
virtual void write(int16_t value) = 0;
/*!
* @brief Prototype for write int32_t value.
*
* @param[in] value int32_t typed value to write.
*/
virtual void write(int32_t value) = 0;
/*!
* @brief Prototype for write int64_t value.
*
* @param[in] value int64_t typed value to write.
*/
virtual void write(int64_t value) = 0;
/*!
* @brief Prototype for write uint8_t value.
*
* @param[in] value uint8_t typed value to write.
*/
virtual void write(uint8_t value) = 0;
/*!
* @brief Prototype for write uint16_t value.
*
* @param[in] value uint16_t typed value to write.
*/
virtual void write(uint16_t value) = 0;
/*!
* @brief Prototype for write uint32_t value.
*
* @param[in] value uint32_t typed value to write.
*/
virtual void write(uint32_t value) = 0;
/*!
* @brief Prototype for write uint64_t value.
*
* @param[in] value uint64_t typed value to write.
*/
virtual void write(uint64_t value) = 0;
/*!
* @brief Prototype for write float value.
*
* @param[in] value float typed value to write.
*/
virtual void write(float value) = 0;
/*!
* @brief Prototype for write double value.
*
* @param[in] value double typed value to write.
*/
virtual void write(double value) = 0;
/*!
* @brief Prototype for write uintptr value.
*
* @param[in] value uintptr typed value to write.
*/
virtual void writePtr(uintptr_t value) = 0;
/*!
* @brief Prototype for write string value.
*
* @param[in] length of string.
* @param[in] value string value to write.
*/
virtual void writeString(uint32_t length, const char *value) = 0;
/*!
* @brief Prototype for write binary value.
*
* @param[in] length of binary.
* @param[in] value Binary value to write.
*/
virtual void writeBinary(uint32_t length, const uint8_t *value) = 0;
/*!
* @brief Prototype for start write list.
*
* @param[in] length Length of list.
*/
virtual void startWriteList(uint32_t length) = 0;
/*!
* @brief Prototype for start write union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startWriteUnion(int32_t discriminator) = 0;
/*!
* @brief Writes a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to send.
*/
virtual void writeNullFlag(bool isNull) = 0;
//@}
//! @name Decoding
//@{
/*!
* @brief Prototype for read header of message.
*
* @param[in] type Type of message.
* @param[in] service Which interface was used.
* @param[in] request Which function was called.
* @param[in] sequence Returned sequence number to be sure that
* received message is reply for current request.
*/
virtual void startReadMessage(message_type_t &type, uint32_t &service, uint32_t &request, uint32_t &sequence) = 0;
/*!
* @brief Prototype for read boolean value.
*
* @param[in] value Boolean typed value to read.
*/
virtual void read(bool &value) = 0;
/*!
* @brief Prototype for read int8_t value.
*
* @param[in] value int8_t typed value to read.
*/
virtual void read(int8_t &value) = 0;
/*!
* @brief Prototype for read int16_t value.
*
* @param[in] value int16_t typed value to read.
*/
virtual void read(int16_t &value) = 0;
/*!
* @brief Prototype for read int32_t value.
*
* @param[in] value int32_t typed value to read.
*/
virtual void read(int32_t &value) = 0;
/*!
* @brief Prototype for read int64_t value.
*
* @param[in] value int64_t typed value to read.
*/
virtual void read(int64_t &value) = 0;
/*!
* @brief Prototype for read uint8_t value.
*
* @param[in] value uint8_t typed value to read.
*/
virtual void read(uint8_t &value) = 0;
/*!
* @brief Prototype for read uint16_t value.
*
* @param[in] value uint16_t typed value to read.
*/
virtual void read(uint16_t &value) = 0;
/*!
* @brief Prototype for read uint32_t value.
*
* @param[in] value uint32_t typed value to read.
*/
virtual void read(uint32_t &value) = 0;
/*!
* @brief Prototype for read uint64_t value.
*
* @param[in] value uint64_t typed value to read.
*/
virtual void read(uint64_t &value) = 0;
/*!
* @brief Prototype for read float value.
*
* @param[in] value float typed value to read.
*/
virtual void read(float &value) = 0;
/*!
* @brief Prototype for read double value.
*
* @param[in] value double typed value to read.
*/
virtual void read(double &value) = 0;
/*!
* @brief Prototype for read uintptr value.
*
* @param[in] value uintptr typed value to read.
*/
virtual void readPtr(uintptr_t &value) = 0;
/*!
* @brief Prototype for read string value.
*
* @param[in] length of string.
* @param[in] value String value to read.
*/
virtual void readString(uint32_t &length, char **value) = 0;
/*!
* @brief Prototype for read binary value.
*
* @param[out] length of binary. 0 can be valid value or in case of error.
* @param[out] value Binary value to read. Null in case of error.
*/
virtual void readBinary(uint32_t &length, uint8_t **value) = 0;
/*!
* @brief Prototype for start read list.
*
* @param[in] length Length of list.
*/
virtual void startReadList(uint32_t &length) = 0;
/*!
* @brief Prototype for start read union.
*
* @param[in] discriminator Discriminator of union.
*/
virtual void startReadUnion(int32_t &discriminator) = 0;
/*!
* @brief Reads a flag indicating whether the next value is null.
*
* @param[in] isNull Null flag to read.
*/
virtual void readNullFlag(bool &isNull) = 0;
protected:
Cursor m_cursor; /*!< Copy data to message buffers. */
erpc_status_t m_status; /*!< Status of serialized data. */
};
/*!
* @brief Abstract interface for codec factory.
*
* @ingroup infra_codec
*/
class CodecFactory
{
public:
/*!
* @brief Constructor.
*/
CodecFactory(void) {}
/*!
* @brief CodecFactory destructor
*/
virtual ~CodecFactory(void) {}
/*!
* @brief Return created codec.
*
* @return Pointer to created codec.
*/
virtual Codec *create(void) = 0;
/*!
* @brief Dispose codec.
*
* @param[in] codec Codec to dispose.
*/
virtual void dispose(Codec *codec) = 0;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__CODEC_H_

View File

@ -0,0 +1,89 @@
/*
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__ERPC_COMMON_H_
#define _EMBEDDED_RPC__ERPC_COMMON_H_
/*!
* @addtogroup infra
* @{
*/
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
/*! @brief eRPC status return codes. */
enum _erpc_status
{
//! No error occurred.
kErpcStatus_Success = 0,
//! Generic failure.
kErpcStatus_Fail = 1,
//! Argument is an invalid value.
kErpcStatus_InvalidArgument = 4,
//! Operated timed out.
kErpcStatus_Timeout = 5,
//! Message header contains an unknown version.
kErpcStatus_InvalidMessageVersion = 6,
//! Expected a reply message but got another message type.
kErpcStatus_ExpectedReply,
//! Message is corrupted.
kErpcStatus_CrcCheckFailed,
//! Attempt to read or write past the end of a buffer.
kErpcStatus_BufferOverrun,
//! Could not find host with given name.
kErpcStatus_UnknownName,
//! Failed to connect to host.
kErpcStatus_ConnectionFailure,
//! Connected closed by peer.
kErpcStatus_ConnectionClosed,
//! Memory allocation error.
kErpcStatus_MemoryError,
//! Server is stopped.
kErpcStatus_ServerIsDown,
//! Transport layer initialization failed.
kErpcStatus_InitFailed,
//! Failed to receive data.
kErpcStatus_ReceiveFailed,
//! Failed to send data.
kErpcStatus_SendFailed,
//! Sending/Receiving callback function which is not defined in IDL.
kErpcStatus_UnknownCallback,
//! Calling eRPC function from another eRPC function. For more information see erpc_common.h.
kErpcStatus_NestedCallFailure,
//! When sending address from bigger architecture to smaller.
kErpcStatus_BadAddressScale
};
/*! @brief Type used for all status and error return values. */
typedef enum _erpc_status erpc_status_t;
/*! @} */
#endif /* _EMBEDDED_RPC__ERPC_COMMON_H_ */

View File

@ -0,0 +1,215 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* Copyright 2020-2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_CONFIG_H_
#define _ERPC_CONFIG_H_
/*!
* @addtogroup config
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
//! @name Threading model options
//@{
#define ERPC_ALLOCATION_POLICY_DYNAMIC (0U) //!< Dynamic allocation policy
#define ERPC_ALLOCATION_POLICY_STATIC (1U) //!< Static allocation policy
#define ERPC_THREADS_NONE (0U) //!< No threads.
#define ERPC_THREADS_PTHREADS (1U) //!< POSIX pthreads.
#define ERPC_THREADS_FREERTOS (2U) //!< FreeRTOS.
#define ERPC_THREADS_ZEPHYR (3U) //!< ZEPHYR.
#define ERPC_THREADS_MBED (4U) //!< Mbed OS
#define ERPC_THREADS_WIN32 (5U) //!< WIN32
#define ERPC_THREADS_THREADX (6U) //!< THREADX
#define ERPC_NOEXCEPT_DISABLED (0U) //!< Disabling noexcept feature.
#define ERPC_NOEXCEPT_ENABLED (1U) //!< Enabling noexcept feature.
#define ERPC_NESTED_CALLS_DISABLED (0U) //!< No nested calls support.
#define ERPC_NESTED_CALLS_ENABLED (1U) //!< Nested calls support.
#define ERPC_NESTED_CALLS_DETECTION_DISABLED (0U) //!< Nested calls detection disabled.
#define ERPC_NESTED_CALLS_DETECTION_ENABLED (1U) //!< Nested calls detection enabled.
#define ERPC_MESSAGE_LOGGING_DISABLED (0U) //!< Trace functions disabled.
#define ERPC_MESSAGE_LOGGING_ENABLED (1U) //!< Trace functions enabled.
#define ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED (0U) //!< Do not use MCMGR for MU ISR management.
#define ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED (1U) //!< Use MCMGR for MU ISR management.
#define ERPC_PRE_POST_ACTION_DISABLED (0U) //!< Pre post shim callbacks functions disabled.
#define ERPC_PRE_POST_ACTION_ENABLED (1U) //!< Pre post shim callback functions enabled.
#define ERPC_PRE_POST_ACTION_DEFAULT_DISABLED (0U) //!< Pre post shim default callbacks functions disabled.
#define ERPC_PRE_POST_ACTION_DEFAULT_ENABLED (1U) //!< Pre post shim default callback functions enabled.
//@}
#ifdef MCUXPRESSO_SDK
#include "erpc_config_gen.h"
#endif /* MCUXPRESSO_SDK */
//! @name Configuration options
//@{
//! @def ERPC_ALLOCATION_POLICY
//!
//! @brief Choose which allocation policy should be used.
//!
//! Set ERPC_ALLOCATION_POLICY_DYNAMIC if dynamic allocations should be used.
//! Set ERPC_ALLOCATION_POLICY_STATIC if static allocations should be used.
//!
//! Default value is ERPC_ALLOCATION_POLICY_DYNAMIC or in case of FreeRTOS it can be auto-detected if __has_include() is
//! supported by compiler. Uncomment comment bellow to use static allocation policy. In case of static implementation
//! user need consider another values to set (ERPC_CODEC_COUNT, ERPC_MESSAGE_LOGGERS_COUNT,
//! ERPC_CLIENTS_THREADS_AMOUNT).
// #define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC)
//! @def ERPC_CODEC_COUNT
//!
//! @brief Set amount of codecs objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to
//! ERPC_ALLOCATION_POLICY_STATIC. For example if client or server is used in one thread then 1. If both are used in one
//! thread per each then 2, ... Default value 2.
// #define ERPC_CODEC_COUNT (2U)
//! @def ERPC_MESSAGE_LOGGERS_COUNT
//!
//! @brief Set amount of message loggers objects used simultaneously in case of ERPC_ALLOCATION_POLICY is set to
//! ERPC_ALLOCATION_POLICY_STATIC.
//! For example if client or server is used in one thread then 1. If both are used in one thread per each then 2, ...
//! For arbitrated client 1 is enough.
//! Default value 0 (May not be used).
// #define ERPC_MESSAGE_LOGGERS_COUNT (0U)
//! @def ERPC_CLIENTS_THREADS_AMOUNT
//!
//! @brief Set amount of client threads objects used in case of ERPC_ALLOCATION_POLICY is set to
//! ERPC_ALLOCATION_POLICY_STATIC. Default value 1 (Most of current cases).
// #define ERPC_CLIENTS_THREADS_AMOUNT (1U)
//! @def ERPC_THREADS
//!
//! @brief Select threading model.
//!
//! Set to one of the @c ERPC_THREADS_x macros to specify the threading model used by eRPC.
//!
//! Leave commented out to attempt to auto-detect. Auto-detection works well for pthreads.
//! FreeRTOS can be detected when building with compilers that support __has_include().
//! Otherwise, the default is no threading.
//#define ERPC_THREADS (ERPC_THREADS_FREERTOS)
//! @def ERPC_DEFAULT_BUFFER_SIZE
//!
//! Uncomment to change the size of buffers allocated by one of MessageBufferFactory.
//! (@ref client_setup and @ref server_setup). The default size is set to 256.
//! For RPMsg transport layer, ERPC_DEFAULT_BUFFER_SIZE must be 2^n - 16.
//#define ERPC_DEFAULT_BUFFER_SIZE (256U)
//! @def ERPC_DEFAULT_BUFFERS_COUNT
//!
//! Uncomment to change the count of buffers allocated by one of statically allocated messages.
//! Default value is set to 2.
//#define ERPC_DEFAULT_BUFFERS_COUNT (2U)
//! @def ERPC_NOEXCEPT
//!
//! @brief Disable/enable noexcept support.
//!
//! Uncomment for using noexcept feature.
//#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED)
//! @def ERPC_NESTED_CALLS
//!
//! Default set to ERPC_NESTED_CALLS_DISABLED. Uncomment when callbacks, or other eRPC
//! functions are called from server implementation of another eRPC call. Nested functions
//! need to be marked as @nested in IDL.
//#define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_ENABLED)
//! @def ERPC_NESTED_CALLS_DETECTION
//!
//! Default set to ERPC_NESTED_CALLS_DETECTION_ENABLED when NDEBUG macro is presented.
//! This serve for locating nested calls in code. Nested calls are calls where inside eRPC function
//! on server side is called another eRPC function (like callbacks). Code need be a bit changed
//! to support nested calls. See ERPC_NESTED_CALLS macro.
//#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED)
//! @def ERPC_MESSAGE_LOGGING
//!
//! Enable eRPC message logging code through the eRPC. Take look into "erpc_message_loggers.h". Can be used for base
//! printing messages, or sending data to another system for data analysis. Default set to
//! ERPC_MESSAGE_LOGGING_DISABLED.
//!
//! Uncomment for using logging feature.
//#define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_ENABLED)
//! @def ERPC_TRANSPORT_MU_USE_MCMGR
//!
//! @brief MU transport layer configuration.
//!
//! Set to one of the @c ERPC_TRANSPORT_MU_USE_MCMGR_x macros to configure the MCMGR usage in MU transport layer.
//!
//! MU transport layer could leverage the Multicore Manager (MCMGR) component for Inter-Core
//! interrupts / MU interrupts management or the Inter-Core interrupts can be managed by itself (MUX_IRQHandler
//! overloading). By default, ERPC_TRANSPORT_MU_USE_MCMGR is set to ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED when mcmgr.h
//! is part of the project, otherwise the ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED option is used. This settings can be
//! overwritten from the erpc_config.h by uncommenting the ERPC_TRANSPORT_MU_USE_MCMGR macro definition. Do not forget
//! to add the MCMGR library into your project when ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED option is used! See the
//! erpc_mu_transport.h for additional MU settings.
//#define ERPC_TRANSPORT_MU_USE_MCMGR ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED
//@}
//! @def ERPC_PRE_POST_ACTION
//!
//! Enable eRPC pre and post callback functions shim code. Take look into "erpc_pre_post_action.h". Can be used for
//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DISABLED.
//!
//! Uncomment for using pre post callback feature.
//#define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_ENABLED)
//! @def ERPC_PRE_POST_ACTION_DEFAULT
//!
//! Enable eRPC pre and post default callback functions. Take look into "erpc_setup_extensions.h". Can be used for
//! detection of eRPC call freeze, ... Default set to ERPC_PRE_POST_ACTION_DEFAULT_DISABLED.
//!
//! Uncomment for using pre post default callback feature.
//#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_ENABLED)
//! @name Assert function definition
//@{
//! User custom asser defition. Include header file if needed before bellow line. If assert is not enabled, default will
//! be used.
// #define erpc_assert(condition)
//@}
//! @def ENDIANES_HEADER
//!
//! Include header file that controls the communication endianness
//!
//! Uncomment for example behaviour for endianness agnostic with:
//! 1. communication in little endian.
//! 2. current processor is big endian.
//! 3. pointer size is 32 bit.
//! 4. float+double scheme not defined, so throws assert if passes.
//! #define ERPC_PROCESSOR_ENDIANNESS_LITTLE 0
//! #define ERPC_COMMUNICATION_LITTLE 1
//! #define ERPC_POINTER_SIZE_16 0
//! #define ERPC_POINTER_SIZE_32 1
//! #define ERPC_POINTER_SIZE_64 0
//! #define ENDIANNESS_HEADER "erpc_endianness_agnostic_example.h"
/*! @} */
#endif // _ERPC_CONFIG_H_
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,232 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_DETECT_H_
#define _ERPC_DETECT_H_
#include "erpc_config.h"
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
/* clang-format off */
// Determine if this is a POSIX system.
#if !defined(ERPC_HAS_POSIX)
// Detect Linux, BSD, Cygwin, and Mac OS X.
#if defined(__linux__) || defined(__GNU__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
defined(__OpenBSD__) || defined(__DragonFly__) || defined(__CYGWIN__) || defined(__MACH__) || \
defined(__MINGW32__)
#define ERPC_HAS_POSIX (1)
#else
#define ERPC_HAS_POSIX (0)
#endif
#endif
// Determine if we are targeting WIN32 environment
#if !defined(ERPC_HAS_WIN32)
#if defined(_WIN32)
#define ERPC_HAS_WIN32 (1)
#else
#define ERPC_HAS_WIN32 (0)
#endif
#endif
// Safely detect FreeRTOSConfig.h.
#define ERPC_HAS_FREERTOSCONFIG_H (0)
#if defined(__has_include)
#if __has_include("FreeRTOSConfig.h")
#undef ERPC_HAS_FREERTOSCONFIG_H
#define ERPC_HAS_FREERTOSCONFIG_H (1)
#endif
#endif
// Detect allocation policy if not already set.
#if !defined(ERPC_ALLOCATION_POLICY)
#if ERPC_HAS_FREERTOSCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOSConfig.h"
#ifdef __cplusplus
}
#endif
#if defined(configSUPPORT_STATIC_ALLOCATION) && configSUPPORT_STATIC_ALLOCATION
#define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_STATIC)
#else
#define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_DYNAMIC)
#endif
#else
#define ERPC_ALLOCATION_POLICY (ERPC_ALLOCATION_POLICY_DYNAMIC)
#endif
#endif
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
#if !defined(ERPC_CODEC_COUNT)
#define ERPC_CODEC_COUNT (2U)
#endif
#if !defined(ERPC_MESSAGE_LOGGERS_COUNT)
#define ERPC_MESSAGE_LOGGERS_COUNT (0U)
#endif
#if !defined(ERPC_CLIENTS_THREADS_AMOUNT)
#define ERPC_CLIENTS_THREADS_AMOUNT (1U)
#endif
#endif
// Safely detect tx_api.h.
#define ERPC_HAS_THREADX_API_H (0)
#if defined(__has_include)
#if __has_include("tx_api.h")
#undef ERPC_HAS_THREADX_API_H
#define ERPC_HAS_THREADX_API_H (1)
#endif
#endif
// Detect threading model if not already set.
#if !defined(ERPC_THREADS)
#if ERPC_HAS_POSIX
// Default to pthreads for POSIX systems.
#define ERPC_THREADS (ERPC_THREADS_PTHREADS)
#elif ERPC_HAS_FREERTOSCONFIG_H
// Use FreeRTOS if we can auto detect it.
#define ERPC_THREADS (ERPC_THREADS_FREERTOS)
#elif ERPC_HAS_WIN32
#define ERPC_THREADS (ERPC_THREADS_WIN32)
#elif ERPC_HAS_THREADX_API_H
#define ERPC_THREADS (ERPC_THREADS_THREADX)
#else
// Otherwise default to no threads.
#define ERPC_THREADS (ERPC_THREADS_NONE)
#endif
#endif
// Handy macro to test threading model. You can also ERPC_THREADS directly to test for threading
// support, i.e. "#if ERPC_THREADS", because ERPC_THREADS_NONE has a value of 0.
#define ERPC_THREADS_IS(_n_) (ERPC_THREADS == (ERPC_THREADS_##_n_))
// Set default buffer size.
#if !defined(ERPC_DEFAULT_BUFFER_SIZE)
//! @brief Size of buffers allocated by BasicMessageBufferFactory in setup functions.
#define ERPC_DEFAULT_BUFFER_SIZE (256U)
#endif
// Set default buffers count.
#if !defined(ERPC_DEFAULT_BUFFERS_COUNT)
//! @brief Count of buffers allocated by StaticMessageBufferFactory.
#define ERPC_DEFAULT_BUFFERS_COUNT (2U)
#endif
// Disable/enable noexcept.
#if !defined(ERPC_NOEXCEPT)
#if ERPC_HAS_POSIX
#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_ENABLED)
#else
#define ERPC_NOEXCEPT (ERPC_NOEXCEPT_DISABLED)
#endif
#endif
//NOEXCEPT support
#if defined(__cplusplus) && __cplusplus >= 201103 && ERPC_NOEXCEPT
#define NOEXCEPT noexcept
#else
#define NOEXCEPT
#endif // NOEXCEPT
// Disabling nesting calls support as default.
#if !defined(ERPC_NESTED_CALLS)
#define ERPC_NESTED_CALLS (ERPC_NESTED_CALLS_DISABLED)
#endif
#if ERPC_NESTED_CALLS && !ERPC_THREADS
#error "Nested calls currently working only with Threads."
#endif
// Enabling nesting calls detection as default for debug.
#if !defined(ERPC_NESTED_CALLS_DETECTION)
#if defined(NDEBUG) || (ERPC_NESTED_CALLS == ERPC_NESTED_CALLS_ENABLED)
#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_DISABLED)
#else
#define ERPC_NESTED_CALLS_DETECTION (ERPC_NESTED_CALLS_DETECTION_ENABLED)
#endif
#endif
// Disabling tracing the eRPC.
#if !defined(ERPC_MESSAGE_LOGGING)
#define ERPC_MESSAGE_LOGGING (ERPC_MESSAGE_LOGGING_DISABLED)
#endif
#if defined(__CC_ARM) || defined(__ARMCC_VERSION) /* Keil MDK */
#define THROW_BADALLOC throw(std::bad_alloc)
#define THROW throw()
#else
#define THROW_BADALLOC
#define THROW
#endif
#ifndef ERPC_TRANSPORT_MU_USE_MCMGR
#if defined(__has_include)
#if (__has_include("mcmgr.h"))
#define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED)
#else
#define ERPC_TRANSPORT_MU_USE_MCMGR (ERPC_TRANSPORT_MU_USE_MCMGR_DISABLED)
#endif
#endif
#else
#if defined(__has_include)
#if ((!(__has_include("mcmgr.h"))) && (ERPC_TRANSPORT_MU_USE_MCMGR == ERPC_TRANSPORT_MU_USE_MCMGR_ENABLED))
#error "Do not forget to add the MCMGR library into your project!"
#endif
#endif
#endif
// Disabling pre and post callback function related code.
#if !defined(ERPC_PRE_POST_ACTION)
#define ERPC_PRE_POST_ACTION (ERPC_PRE_POST_ACTION_DISABLED)
#endif
// Disabling pre and post default callback function code.
#if !defined(ERPC_PRE_POST_ACTION_DEFAULT)
#define ERPC_PRE_POST_ACTION_DEFAULT (ERPC_PRE_POST_ACTION_DEFAULT_DISABLED)
#endif
#if !defined(erpc_assert)
#if ERPC_HAS_FREERTOSCONFIG_H
#ifdef __cplusplus
extern "C" {
#endif
#include "FreeRTOS.h"
#include "task.h"
#ifdef __cplusplus
}
#endif
#define erpc_assert(condition) configASSERT(condition)
#elif defined(ERPC_THREADS) && (ERPC_THREADS == ERPC_THREADS_MBED)
#include "platform/mbed_assert.h"
#define erpc_assert(condition) MBED_ASSERT(condition)
#else
#ifdef __cplusplus
#include <cassert>
#else
#include "assert.h"
#endif
#define erpc_assert(condition) assert(condition)
#endif
#endif
// Disabling endianness agnostic feature.
#ifndef ENDIANNESS_HEADER
#define ENDIANNESS_HEADER "erpc_endianness_undefined.h"
#endif
/* clang-format on */
#endif // _ERPC_DETECT_H_
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,74 @@
/*
* Copyright 2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__CRC16_H_
#define _EMBEDDED_RPC__CRC16_H_
#include <cstdint>
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Class for compute crc16.
*/
class Crc16
{
public:
/*!
* @brief Constructor.
*
* @param[in] crcStart Start value for crc function.
*/
explicit Crc16(uint32_t crcStart);
/*!
* @brief Constructor.
*/
Crc16(void);
/*!
* @brief Crc16 destructor
*/
~Crc16(void);
/*!
* @brief Compute a ITU-CCITT CRC-16 over the provided data.
*
* This implementation is slow but small in size.
*
* @param[in] data Pointer to data used for crc16.
* @param[in] lengthInBytes Data length.
*/
uint16_t computeCRC16(const uint8_t *data, uint32_t lengthInBytes);
/*!
* @brief Set crc start number.
*
* @param[in] crcStart Crc start number.
*/
void setCrcStart(uint32_t crcStart);
protected:
uint32_t m_crcStart; /*!< CRC start number. */
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__CRC16_H_

View File

@ -0,0 +1,188 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2020 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__FRAMED_TRANSPORT_H_
#define _EMBEDDED_RPC__FRAMED_TRANSPORT_H_
#include "erpc_config_internal.h"
#include "erpc_message_buffer.hpp"
#include "erpc_transport.hpp"
#include <cstring>
#if !ERPC_THREADS_IS(NONE)
#include "erpc_threading.h"
#endif
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Base class for framed transport layers.
*
* This class adds simple framing to the data transmitted and received on the
* communications channel. This allows the transport to perform reads and writes
* of a size known in advance. Subclasses must implement the underlyingSend() and
* underlyingReceive() methods to actually transmit and receive data.
*
* Frames have a maximum size of 64kB, as a 16-bit frame size is used.
*
* @note This implementation currently assumes both sides of the communications channel
* are the same endianness.
*
* The frame header includes a CRC-16 over the data for integrity checking. This class
* includes a default CRC-16 implementation that is optimized for code size, but is
* relatively slow. If a faster implementation is desired, you can pass the new CRC
* function to setCRCFunction().
*
* @ingroup infra_transport
*/
class FramedTransport : public Transport
{
public:
/*! @brief Contents of the header that prefixes each message. */
struct Header
{
uint16_t m_crcHeader; //!< CRC-16 over this header structure data
uint16_t m_messageSize; //!< Size in bytes of the message, excluding the header.
uint16_t m_crcBody; //!< CRC-16 over the message data.
};
/*!
* @brief Constructor.
*/
FramedTransport(void);
/*!
* @brief FramedTransport destructor
*/
virtual ~FramedTransport(void);
/**
* @brief Size of data placed in MessageBuffer before serializing eRPC data.
*
* @return uint8_t Amount of bytes, reserved before serialized data.
*/
virtual uint8_t reserveHeaderSize(void) override;
/*!
* @brief Receives an entire message.
*
* The frame header and message data are received. The CRC-16 in the frame header is
* compared with the computed CRC. If the received CRC is invalid, #kErpcStatus_Fail
* will be returned.
*
* The @a message is only filled with the message data, not the frame header.
*
* This function is blocking.
*
* @param[in] message Message buffer, to which will be stored incoming message.
*
* @retval kErpcStatus_Success When receiving was successful.
* @retval kErpcStatus_CrcCheckFailed When receiving failed.
* @retval other Subclass may return other errors from the underlyingReceive() method.
*/
virtual erpc_status_t receive(MessageBuffer *message) override;
/*!
* @brief Function to send prepared message.
*
* @param[in] message Pass message buffer to send.
*
* @retval kErpcStatus_Success When sending was successful.
* @retval other Subclass may return other errors from the underlyingSend() method.
*/
virtual erpc_status_t send(MessageBuffer *message) override;
/*!
* @brief This functions sets the CRC-16 implementation.
*
* @param[in] crcImpl Object containing crc-16 compute function.
*/
virtual void setCrc16(Crc16 *crcImpl) override;
/*!
* @brief This functions gets the CRC-16 object.
*
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 *getCrc16(void) override;
protected:
Crc16 *m_crcImpl; /*!< CRC object. */
#if !ERPC_THREADS_IS(NONE)
Mutex m_sendLock; //!< Mutex protecting send.
Mutex m_receiveLock; //!< Mutex protecting receive.
#endif
/*!
* @brief Adds ability to framed transport to overwrite MessageBuffer when sending data.
*
* Usually we don't want to do that.
*
* @param message MessageBuffer to send.
* @param size size of message to send.
* @param offset data start address offset
*
* @return erpc_status_t kErpcStatus_Success when it finished successful otherwise error.
*/
virtual erpc_status_t underlyingSend(MessageBuffer *message, uint32_t size, uint32_t offset);
/*!
* @brief Adds ability to framed transport to overwrite MessageBuffer when receiving data.
*
* Usually we don't want to do that.
*
* @param message MessageBuffer to send.
* @param size size of message to send.
* @param offset data start address offset
*
* @return erpc_status_t kErpcStatus_Success when it finished successful otherwise error.
*/
virtual erpc_status_t underlyingReceive(MessageBuffer *message, uint32_t size, uint32_t offset);
/*!
* @brief Subclasses must implement this function to send data.
*
* @param[in] data Buffer to send.
* @param[in] size Size of data to send.
*
* @retval kErpcStatus_Success When data was written successfully.
* @retval kErpcStatus_Fail When writing data ends with error.
*/
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) = 0;
/*!
* @brief Subclasses must implement this function to receive data.
*
* @param[inout] data Preallocated buffer for receiving data.
* @param[in] size Size of data to read.
*
* @retval kErpcStatus_Success When data was read successfully.
* @retval kErpcStatus_Fail When reading data ends with error.
*/
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) = 0;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__FRAMED_TRANSPORT_H_

View File

@ -0,0 +1,77 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__INTER_THREAD_BUFFER_TRANSPORT_H_
#define _EMBEDDED_RPC__INTER_THREAD_BUFFER_TRANSPORT_H_
#include "erpc_message_buffer.hpp"
#include "erpc_threading.h"
#include "erpc_transport.hpp"
/*!
* @addtogroup itbp_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Very basic transport to send/receive messages between threads.
*
* Can send and receive message buffers to/from another instance of the same class
* associated with another thread. Only one other thread may be communicated with. To set
* things up first create two instances. Then call the linkWithPeer() method on the
* first one, passing the second. The two instances of this class do not have to be
* created on their respective threads, but the send() and receive() calls must be
* invoked on the appropriate thread.
*
* Only a single message may be pending for each of the two threads. If a message is
* pending for a thread and another is sent, then the sender will block until the
* currently pending message is received.
*
* @ingroup itbp_transport
*/
class InterThreadBufferTransport : public Transport
{
public:
InterThreadBufferTransport(void) :
Transport(), m_state(NULL), m_peer(NULL), m_inSem(), m_outSem(1), m_inBuffer(NULL)
{
}
virtual ~InterThreadBufferTransport(void);
void linkWithPeer(InterThreadBufferTransport *peer);
virtual erpc_status_t receive(MessageBuffer *message) override;
virtual erpc_status_t send(MessageBuffer *message) override;
virtual int32_t getAvailable(void) const { return 0; }
protected:
struct SharedState
{
Mutex m_mutex;
};
SharedState *m_state; /*!< */
InterThreadBufferTransport *m_peer; /*!< */
Semaphore m_inSem; /*!< */
Semaphore m_outSem; /*!< */
MessageBuffer *m_inBuffer; /*!< */
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__INTER_THREAD_BUFFER_TRANSPORT_H_

View File

@ -0,0 +1,238 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
#define _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_
#include "erpc_config_internal.h"
#include <new>
#include <stdint.h>
/*!
* @addtogroup infra_utility
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Allocates static storage for an object.
*
* This template class defines storage of the template class' size. Then it
* gives the user explicit control over construction and destruction of the
* object residing in that storage. This is useful for placing objects in
* unions, or other situations where you need static storage but want to delay
* the actual construction of the object.
*
* Objects of this class will act as a pointer to the template argument class
* type. Of course, if the object has not yet been constructed then the
* behavior is undefined if the pointer to it is used.
*
* Note that there is not a constructor or deconstructor. This is because
* members of unions cannot have constructors or deconstructors.
*
* Instances of this template class are aligned to 8 bytes.
*
* @ingroup infra_utility
*/
template <class T>
class ManuallyConstructed
{
public:
//! @name Object access
//@{
T *get(void) { return (m_isConstructed) ? reinterpret_cast<T *>(&m_storage) : nullptr; }
const T *get(void) const { return (m_isConstructed) ? reinterpret_cast<const T *>(&m_storage) : nullptr; }
T *operator->(void) { return get(); }
const T *operator->(void) const { return get(); }
T &operator*(void)
{
if (m_isConstructed)
{
return *get();
}
else
{
memset(&m_storage, 0, sizeof(m_storage) * 8);
return reinterpret_cast<T &>(m_storage);
};
}
const T &operator*(void) const
{
if (m_isConstructed)
{
return *get();
}
else
{
memset(&m_storage, 0, sizeof(m_storage) * 8);
return reinterpret_cast<const T &>(m_storage);
};
}
operator T *(void) { return get(); }
operator const T *(void) const { return get(); }
//@}
//! @name Explicit construction methods
//@{
void construct(void)
{
destroy();
new (m_storage) T;
m_isConstructed = true;
}
template <typename A1>
void construct(const A1 &a1)
{
destroy();
new (m_storage) T(a1);
m_isConstructed = true;
}
template <typename A1, typename A2>
void construct(const A1 &a1, const A2 &a2)
{
destroy();
new (m_storage) T(a1, a2);
m_isConstructed = true;
}
template <typename A1, typename A2, typename A3>
void construct(const A1 &a1, const A2 &a2, const A3 &a3)
{
destroy();
new (m_storage) T(a1, a2, a3);
m_isConstructed = true;
}
template <typename A1, typename A2, typename A3, typename A4>
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4)
{
destroy();
new (m_storage) T(a1, a2, a3, a4);
m_isConstructed = true;
}
template <typename A1, typename A2, typename A3, typename A4, typename A5>
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5)
{
destroy();
new (m_storage) T(a1, a2, a3, a4, a5);
m_isConstructed = true;
}
template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
void construct(const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6)
{
destroy();
new (m_storage) T(a1, a2, a3, a4, a5, a6);
m_isConstructed = true;
}
//@}
/*!
* @brief Invoke the object's destructor.
*
* Behavior is undefined if the objected was not previously initialized.
*/
void destroy(void)
{
if (m_isConstructed)
{
get()->~T();
m_isConstructed = false;
}
}
/*!
* @brief Returns information if object is free or is used.
*
* @return true Object is constructed and used.
* @return false Object wasn't constructed or it was destructed already.
*/
bool isUsed(void) { return m_isConstructed; }
protected:
/*!
* @brief Storage for the object.
*
* An array of uint64 is used to get 8-byte alignment.
*/
uint64_t m_storage[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
/*!
* @brief Track construct/destruct calls.
*
* Based on this variable we can allow or forbid construct/destruct calls.
*/
bool m_isConstructed = false;
};
#define ERPC_MANUALLY_CONSTRUCTED(class, variableName) static ManuallyConstructed<class> variableName
#define ERPC_MANUALLY_CONSTRUCTED_ARRAY(class, variableName, dimension) \
ERPC_MANUALLY_CONSTRUCTED(class, variableName)[dimension]
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
#define ERPC_MANUALLY_CONSTRUCTED_STATIC(class, variableName) ERPC_MANUALLY_CONSTRUCTED(class, variableName)
#else
#define ERPC_MANUALLY_CONSTRUCTED_STATIC(class, variableName)
#endif
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
#define ERPC_MANUALLY_CONSTRUCTED_ARRAY_STATIC(class, variableName, dimension) \
ERPC_MANUALLY_CONSTRUCTED_ARRAY(class, variableName, dimension)
#else
#define ERPC_MANUALLY_CONSTRUCTED_ARRAY_STATIC(class, variableName, dimension)
#endif
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_DYNAMIC
#define ERPC_CREATE_NEW_OBJECT(class, arrayOfObjects, numberOfObjects, ...) \
return new (std::nothrow) class(__VA_ARGS__);
#define ERPC_DESTROY_OBJECT(object, ...) delete object;
#elif ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
#define ERPC_CREATE_NEW_OBJECT(class, arrayOfObjects, numberOfObjects, ...) \
uint8_t objectsIterator; \
class *ret = NULL; \
for (objectsIterator = 0; objectsIterator < numberOfObjects; objectsIterator++) \
{ \
if (!arrayOfObjects[objectsIterator].isUsed()) \
{ \
arrayOfObjects[objectsIterator].construct(__VA_ARGS__); \
ret = arrayOfObjects[objectsIterator].get(); \
break; \
} \
} \
return ret;
#define ERPC_DESTROY_OBJECT(object, arrayOfObjects, numberOfObjects) \
uint8_t objectsIterator; \
for (objectsIterator = 0; objectsIterator < numberOfObjects; objectsIterator++) \
{ \
if (object == arrayOfObjects[objectsIterator].get()) \
{ \
arrayOfObjects[objectsIterator].destroy(); \
break; \
} \
}
#endif
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__MANUALLY_CONSTRUCTED_H_

View File

@ -0,0 +1,85 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_MBF_SETUP_H_
#define _ERPC_MBF_SETUP_H_
#include "erpc_transport_setup.h"
/*!
* @addtogroup message_buffer_factory_setup
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////////////////////////
//! @brief Opaque MessageBufferFactory object type.
typedef struct ErpcMessageBufferFactory *erpc_mbf_t;
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
//! @name MessageBufferFactory setup
//@{
/*!
* @brief Create MessageBuffer factory which is using dynamic allocated buffers.
*/
erpc_mbf_t erpc_mbf_dynamic_init(void);
/*!
* @brief Deinit MessageBuffer factory.
*
* @param[in] mbf MessageBuffer factory which was initialized in init function.
*/
void erpc_mbf_dynamic_deinit(erpc_mbf_t mbf);
/*!
* @brief Create MessageBuffer factory which is using RPMSG LITE zero copy buffers.
*
* Has to be used with RPMSG lite zero copy transport.
*/
erpc_mbf_t erpc_mbf_rpmsg_init(erpc_transport_t transport);
/*!
* @brief Deinit MessageBuffer factory.
*
* @param[in] mbf MessageBuffer factory which was initialized in init function.
*/
void erpc_mbf_rpmsg_deinit(erpc_mbf_t mbf);
/*!
* @brief Create MessageBuffer factory which is using static allocated buffers.
*/
erpc_mbf_t erpc_mbf_static_init(void);
/*!
* @brief Deinit MessageBuffer factory.
*
* @param[in] mbf MessageBuffer factory which was initialized in init function.
*/
void erpc_mbf_static_deinit(erpc_mbf_t mbf);
//@}
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _ERPC_MBF_SETUP_H_

View File

@ -0,0 +1,407 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__MESSAGE_BUFFER_H_
#define _EMBEDDED_RPC__MESSAGE_BUFFER_H_
#include "erpc_common.h"
#include <cstddef>
#include <stdint.h>
/*!
* @addtogroup infra_codec
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Represents a memory buffer containing a message.
*
* The MessageBuffer object does not own the buffer memory. It simply provides an interface
* to accessing that memory in a convenient manner.
*
* @ingroup infra_codec
*/
class MessageBuffer
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
MessageBuffer(void) : m_buf(NULL), m_len(0), m_used(0) {}
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*
* @param[in] buffer Pointer to buffer.
* @param[in] length Length of buffer.
*/
MessageBuffer(uint8_t *buffer, uint16_t length) : m_buf(buffer), m_len(length), m_used(0) {}
MessageBuffer(const MessageBuffer &buffer);
/*!
* @brief This function set new buffer and his length.
*
* This function set buffer to read/write data.
*
* @param[in] buffer Pointer to another buffer to read/write data.
* @param[in] length Length of buffer.
*/
void set(uint8_t *buffer, uint16_t length)
{
m_buf = buffer;
m_len = length;
m_used = 0;
}
/*!
* @brief This function returns pointer to buffer to read/write.
*
* @return Pointer to buffer to read/write.
*/
uint8_t *get(void) { return m_buf; }
/*!
* @brief This function returns pointer to buffer to read/write.
*
* @return Pointer to buffer to read/write.
*/
const uint8_t *get(void) const { return m_buf; }
/*!
* @brief This function returns length of buffer.
*
* @return Length of buffer.
*/
uint16_t getLength(void) const { return m_len; }
/*!
* @brief This function returns length of used space of buffer.
*
* @return Length of used space of buffer.
*/
uint16_t getUsed(void) const { return m_used; }
/*!
* @brief This function returns length of free space of buffer.
*
* @return Length of free space of buffer.
*/
uint16_t getFree(void) const { return m_len - m_used; }
/*!
* @brief This function sets length of used space of buffer.
*
* @param[in] used Length of used space of buffer.
*/
void setUsed(uint16_t used);
/*!
* @brief This function read data from local buffer.
*
* @param[in] offset Offset in local buffer.
* @param[inout] data Given buffer to save read data.
* @param[in] length Length of data to read.
*
* @return Status from reading data.
*/
erpc_status_t read(uint16_t offset, void *data, uint32_t length);
/*!
* @brief This function write data to local buffer.
*
* @param[in] offset Offset in local buffer.
* @param[inout] data Given buffer from which are copied data.
* @param[in] length Length of data to write.
*
* @return Status from reading data.
*/
erpc_status_t write(uint16_t offset, const void *data, uint32_t length);
/*!
* @brief This function copy given message buffer to local instance.
*
* @param[in] other MesageBuffer to copy.
*
* @return Status from reading data.
*/
erpc_status_t copy(const MessageBuffer *other);
/*!
* @brief This function swap message buffer attributes between given instance and local instance.
*
* @param[in] other MesageBuffer to swap.
*/
void swap(MessageBuffer *other);
/*!
* @brief Casting operator return local buffer.
*/
operator uint8_t *(void) { return m_buf; }
/*!
* @brief Casting operator return local buffer.
*/
operator const uint8_t *(void) const { return m_buf; }
/*!
* @brief Array operator return value of buffer at given index.
*
* @param[in] index Index in buffer.
*/
uint8_t &operator[](int index) { return m_buf[index]; }
/*!
* @brief Array operator return value of buffer at given index.
*
* @param[in] index Index in buffer.
*/
const uint8_t &operator[](int index) const { return m_buf[index]; }
private:
uint8_t *volatile m_buf; /*!< Buffer used to read write data. */
uint16_t volatile m_len; /*!< Length of buffer. */
uint16_t volatile m_used; /*!< Used buffer bytes. */
};
/*!
* @brief Cursor within a MessageBuffer.
*/
class Cursor
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
Cursor(void) : m_buffer(), m_pos(NULL) {}
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*
* @param[in] buffer MessageBuffer for sending/receiving.
*/
explicit Cursor(MessageBuffer &buffer) : m_buffer(buffer), m_pos(buffer.get()) {}
/*!
* @brief Set message buffer.
*
* @param[in] buffer Message buffer to set.
* @param[in] reserved Moved cursor position outside of reserved memory.
*/
void setBuffer(MessageBuffer &buffer, uint8_t reserved = 0);
/*!
* @brief Get message buffer.
*/
MessageBuffer getBuffer(void);
/*!
* @brief Get message buffer.
*/
MessageBuffer &getBufferRef(void);
/*!
* @brief Return position in buffer.
*
* Return position, where it last write/read.
*
* @return Return position in buffer.
*/
uint8_t *get(void) { return m_pos; }
/*!
* @brief Return position in buffer.
*
* Return position, where it last write/read.
*
* @return Return position in buffer.
*/
const uint8_t *get(void) const { return m_pos; }
/*!
* @brief Return remaining free space in current buffer.
*
* @return Remaining free space in current buffer.
*/
uint16_t getRemaining(void) const { return m_buffer.getLength() - (uint16_t)(m_pos - m_buffer.get()); }
/*!
* @brief Return remaining space from used of current buffer.
*
* @return Remaining space from used of current buffer.
*/
uint16_t getRemainingUsed(void) const { return m_buffer.getUsed() - (uint16_t)(m_pos - m_buffer.get()); }
/*!
* @brief Read data from current buffer.
*
* @param[out] data Pointer to value, where copy read data.
* @param[in] length How much bytes need be read.
*
* @retval kErpcStatus_Success
* @retval kErpcStatus_BufferOverrun
*/
erpc_status_t read(void *data, uint32_t length);
/*!
* @brief Read data from current buffer.
*
* @param[out] data Pointer to value to be sent.
* @param[in] length How much bytes need be wrote.
*
* @retval kErpcStatus_Success
* @retval kErpcStatus_BufferOverrun
*/
erpc_status_t write(const void *data, uint32_t length);
/*!
* @brief Casting operator return local buffer.
*/
operator uint8_t *(void) { return m_pos; }
/*!
* @brief Casting operator return local buffer.
*/
operator const uint8_t *(void) const { return m_pos; }
/*!
* @brief Array operator return value of buffer at given index.
*
* @param[in] index Index in buffer.
*/
uint8_t &operator[](int index);
/*!
* @brief Array operator return value of buffer at given index.
*
* @param[in] index Index in buffer.
*/
const uint8_t &operator[](int index) const;
/*!
* @brief Sum operator return local buffer.
*
* @param[in] n Summing with n.
*
* @return Current cursor instance.
*/
Cursor &operator+=(uint16_t n);
/*!
* @brief Subtract operator return local buffer.
*
* @param[in] n Subtracting with n.
*
* @return Current cursor instance.
*/
Cursor &operator-=(uint16_t n);
/*!
* @brief Sum +1 operator.
*
* @return Current cursor instance.
*/
Cursor &operator++(void);
/*!
* @brief Subtract -1 operator.
*
* @return Current cursor instance.
*/
Cursor &operator--(void);
private:
MessageBuffer m_buffer; /*!< Buffer for reading or writing data. */
uint8_t *m_pos; /*!< Position in buffer, where it last write/read */
};
/*!
* @brief Abstract interface for message buffer factory.
*
* @ingroup infra_codec
*/
class MessageBufferFactory
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
MessageBufferFactory(void);
/*!
* @brief MessageBufferFactory destructor
*/
virtual ~MessageBufferFactory(void);
/*!
* @brief This function creates new message buffer.
*
* @return New created MessageBuffer.
*/
virtual MessageBuffer create(void) = 0;
/*!
* @brief This function creates new message buffer with reserved bytes at the beginning
*
* Reserved bytes can be used by transport to write transport related header file data.
*
* @param[in] reserveHeaderSize Reserved amount of bytes at the beginning of message buffer.
*
* @return New created MessageBuffer.
*/
MessageBuffer create(uint8_t reserveHeaderSize);
/*!
* @brief This function informs server if it has to create buffer for received message.
*
* @return Has to return TRUE when server need create buffer for receiving message.
*/
virtual bool createServerBuffer(void);
/*!
* @brief This function is preparing output buffer on server side.
*
* This function do decision if this function want reuse buffer, or use new buffer.
* In case of using new buffer function has to free given buffer.
*
* @param[in] message MessageBuffer which can be reused.
* @param[in] reserveHeaderSize Reserved amount of bytes at the beginning of message buffer.
*/
virtual erpc_status_t prepareServerBufferForSend(MessageBuffer &message, uint8_t reserveHeaderSize = 0);
/*!
* @brief This function disposes message buffer.
*
* @param[in] buf MessageBuffer to dispose.
*/
virtual void dispose(MessageBuffer *buf) = 0;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__MESSAGE_BUFFER_H_

View File

@ -0,0 +1,125 @@
/*
* Copyright 2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__LOGEVENTLISTENERS_H_
#define _EMBEDDED_RPC__LOGEVENTLISTENERS_H_
#include "erpc_transport.hpp"
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Logging messages objects used for logging sent/received messages.
*
* @ingroup infra_utility
*/
class MessageLogger
{
public:
/*!
* @brief MessageLogger constructor.
*/
explicit MessageLogger(Transport *transport) : m_next(NULL), m_transport(transport){};
/*!
* @brief MessageLogger destructor
*/
~MessageLogger(void){};
/*!
* @brief Return next logger.
*
* @return Pointer to next logger.
*/
MessageLogger *getNext(void) { return m_next; }
/*!
* @brief Set next logger.
*
* @param[in] next Pointer to next logger.
*/
void setNext(MessageLogger *next) { m_next = next; }
/*!
* @brief Returns next transport object used for logging messages.
*
* @return Transport object used for logging messages.
*/
Transport *getLogger(void) { return m_transport; }
protected:
MessageLogger *m_next; /*!< Pointer to next logger. */
Transport *m_transport; /*!< Pointer to transport object used for logging messages. */
};
/*!
* @brief Logging messages functionality.
*
* @ingroup infra_utility
*/
class MessageLoggers
{
public:
/*!
* @brief Constructor.
*/
MessageLoggers(void) : m_logger(NULL){};
/*!
* @brief Transport destructor
*/
~MessageLoggers(void);
/*!
* @brief This function add given transport to newly created MessageLogger object.
*
* @param[in] transport Transport used for logging messages
*
* @retval True When transport was successfully added.
* @retval False When transport wasn't added.
*/
bool addMessageLogger(Transport *transport);
protected:
MessageLogger *m_logger; /*!< Pointer to first logger. */
/*!
* @brief This function add given transport to newly created MessageLogger object.
*
* @param[in] msg Buffer which will be logged.
*
* @return The eRPC status based on transport type.
*/
erpc_status_t logMessage(MessageBuffer *msg);
private:
/**
* @brief This function create new MessageLogger object
*
* @param[in] transport Transport used by MessageLogger.
*
* @return MessageLogger* Returns new MessageLogger object.
*/
MessageLogger *create(Transport *transport);
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__LOGEVENTLISTENERS_H_

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__PORT_H_
#define _EMBEDDED_RPC__PORT_H_
#include "erpc_config_internal.h"
/*!
* @addtogroup port_mem
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include <stddef.h>
/*!
* @brief This function is used for allocating space.
*
* @param[in] size Size of memory block which should be allocated.
*
* @return Pointer to allocated space or NULL.
*/
void *erpc_malloc(size_t size);
/*!
* @brief This function free given memory block.
*
* @param[in] ptr Pointer to memory which should be freed, or NULL.
*/
void erpc_free(void *ptr);
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _EMBEDDED_RPC__PORT_H_

View File

@ -0,0 +1,93 @@
/*
* Copyright 2020 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__PREPOSTACTION_H_
#define _EMBEDDED_RPC__PREPOSTACTION_H_
#ifdef __cplusplus
#include <cstddef>
/*!
* @addtogroup infra_transport
* @{
* @file
*/
extern "C" {
#endif
typedef void (*pre_post_action_cb)(void);
#ifdef __cplusplus
}
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Client and server may used cb functions before and after rpc call.
*
* @ingroup infra_utility
*/
class PrePostAction
{
public:
/*!
* @brief PrePostAction constructor.
*/
PrePostAction(void) : m_preCB(NULL), m_postCB(NULL){};
/*!
* @brief This function sets "before eRPC call start" callback function.
*
* @param[in] preCB Pointer for callback function. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void addPreCB(pre_post_action_cb preCB);
/*!
* @brief This function sets "after eRPC call finish" callback function.
*
* @param[in] postCB Pointer for callback function. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void addPostCB(pre_post_action_cb postCB);
/*!
* @brief This function returns "before eRPC call start" callback function.
*
* @return preCB Pointer for callback function.
*/
pre_post_action_cb getPreCB(void) { return m_preCB; }
/*!
* @brief This function returns "after eRPC call finish" callback function.
*
* @return postCB Pointer for callback function.
*/
pre_post_action_cb getPostCB(void) { return m_postCB; }
/*!
* @brief PrePostAction destructor
*/
~PrePostAction(void){};
protected:
pre_post_action_cb m_preCB; /*!< Pointer to "before eRPC call start" callback function. */
pre_post_action_cb m_postCB; /*!< Pointer to after eRPC call finish" callback function. */
};
} // namespace erpc
/*! @} */
#endif
#endif // _EMBEDDED_RPC__PREPOSTACTION_H_

View File

@ -0,0 +1,78 @@
/*
* This file is part of the Bus Pirate project (http://code.google.com/p/the-bus-pirate/).
*
* Written and maintained by the Bus Pirate project and http://dangerousprototypes.com
*
* To the extent possible under law, the project has
* waived all copyright and related or neighboring rights to Bus Pirate. This
* work is published from United States.
*
* For details see: http://creativecommons.org/publicdomain/zero/1.0/.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* OS independent serial interface
*
* Heavily based on Pirate-Loader:
* http://the-bus-pirate.googlecode.com/svn/trunk/bootloader-v4/pirate-loader/source/pirate-loader.c
*
*/
#ifndef MYSERIAL_H_
#define MYSERIAL_H_
#ifdef __APPLE__
#include <IOKit/serial/ioss.h>
#include <sys/ioctl.h>
#define B1500000 1500000
#define B1000000 1000000
#define B921600 921600
#endif
#include <stdint.h>
#ifdef _WIN32
#include <time.h>
#include <windows.h>
#define B115200 115200
#define B921600 921600
typedef long speed_t;
#else
#include <sys/select.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <unistd.h>
#endif
/*!
* @addtogroup port_serial
* @{
* @file
*/
#if __cplusplus
extern "C" {
#endif
int serial_setup(int fd, speed_t speed);
int serial_set_read_timeout(int fd, uint8_t vtime, uint8_t vmin);
int serial_write(int fd, const char *buf, int size);
int serial_read(int fd, char *buf, int size);
int serial_open(const char *port);
int serial_close(int fd);
#if __cplusplus
}
#endif
/*! @} */
#endif

View File

@ -0,0 +1,103 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SERIAL_TRANSPORT_H_
#define _EMBEDDED_RPC__SERIAL_TRANSPORT_H_
#include "erpc_framed_transport.hpp"
#include <string>
extern "C" {
#ifdef _WIN32
typedef long speed_t;
#else
#include <termios.h>
#endif
}
/*!
* @addtogroup serial_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Serial transport layer for host PC
*
* @ingroup serial_transport
*/
class SerialTransport : public FramedTransport
{
public:
/*!
* @brief Constructor.
*
* @param[in] portName Port name.
* @param[in] baudRate Baudrate.
*/
SerialTransport(const char *portName, speed_t baudRate);
/*!
* @brief Destructor.
*/
virtual ~SerialTransport(void);
/*!
* @brief Initialize Serial peripheral.
*
* @param[in] vtime Read timeout.
* @param[in] vmin Read timeout min.
*
* @return Status of init function.
*/
erpc_status_t init(uint8_t vtime, uint8_t vmin);
private:
using FramedTransport::underlyingReceive;
using FramedTransport::underlyingSend;
/*!
* @brief Receive data from Serial peripheral.
*
* @param[inout] data Preallocated buffer for receiving data.
* @param[in] size Size of data to read.
*
* @retval kErpcStatus_ReceiveFailed Serial failed to receive data.
* @retval kErpcStatus_Success Successfully received all data.
*/
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
/*!
* @brief Write data to Serial peripheral.
*
* @param[in] data Buffer to send.
* @param[in] size Size of data to send.
*
* @retval kErpcStatus_ReceiveFailed Serial failed to receive data.
* @retval kErpcStatus_Success Successfully received all data.
*/
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
private:
int m_serialHandle; /*!< Serial handle id. */
const char *m_portName; /*!< Port name. */
speed_t m_baudRate; /*!< Bauderate. */
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__SERIAL_TRANSPORT_H_

View File

@ -0,0 +1,199 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SERVER_H_
#define _EMBEDDED_RPC__SERVER_H_
#include "erpc_client_server_common.hpp"
#include "erpc_config_internal.h"
#if ERPC_NESTED_CALLS
#include "erpc_client_manager.h"
#endif
/*!
* @addtogroup infra_server
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
#if ERPC_NESTED_CALLS
class RequestContext;
#endif
/*!
* @brief Abstract interface for service, which can be executed on server side.
*
* @ingroup infra_server
*/
class Service
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
Service(uint32_t serviceId) : m_serviceId(serviceId), m_next(NULL) {}
/*!
* @brief Service destructor
*/
virtual ~Service(void) {}
/*!
* @brief Return service id number.
*
* @return Service id number.
*/
uint32_t getServiceId(void) const { return m_serviceId; }
/*!
* @brief Return next service.
*
* @return Pointer to next service.
*/
Service *getNext(void) { return m_next; }
/*!
* @brief Set next service.
*
* @param[in] next Pointer to next service.
*/
void setNext(Service *next) { m_next = next; }
/*!
* @brief This function call function implementation of current service.
*
* @param[in] methodId Id number of function, which is requested.
* @param[in] sequence Sequence number. To be sure that reply from server belongs to client request.
* @param[in] codec For reading and writing data.
* @param[in] messageFactory Used for setting output buffer.
*
* @return Based on handleInvocation implementation.
*/
virtual erpc_status_t handleInvocation(uint32_t methodId, uint32_t sequence, Codec *codec,
MessageBufferFactory *messageFactory, Transport *transport) = 0;
protected:
uint32_t m_serviceId; /*!< Service unique id. */
Service *m_next; /*!< Pointer to next service. */
};
/*!
* @brief Based server functionality.
*
* @ingroup infra_server
*/
class Server : public ClientServerCommon
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
Server(void) : ClientServerCommon(), m_firstService(NULL) {}
/*!
* @brief Server destructor
*/
virtual ~Server(void) {}
/*!
* @brief Add service.
*
* @param[in] service Service to use.
*/
void addService(Service *service);
/*!
* @brief Remove service.
*
* @param[in] service Service to remove.
*/
void removeService(Service *service);
/*!
* @brief This function runs the server.
*/
virtual erpc_status_t run(void) = 0;
/*!
* @brief This function stop the server.
*/
virtual void stop(void) = 0;
protected:
Service *m_firstService; /*!< Contains pointer to first service. */
/*!
* @brief Process message.
*
* @param[in] codec Inout codec to use.
* @param[in] msgType Type of received message. Based on message type will be (will be not) sent respond.
* @param[in] serviceId To identify interface.
* @param[in] methodId To identify function in interface.
* @param[in] sequence To connect correct answer with correct request.
*
* @returns #kErpcStatus_Success or based on codec startReadMessage.
*/
virtual erpc_status_t processMessage(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
uint32_t sequence);
/*!
* @brief Read head of message to identify type of message.
*
* @param[in] codec Inout codec to use.
* @param[out] msgType Type of received message. Based on message type will be (will be not) sent respond.
* @param[out] serviceId To identify interface.
* @param[out] methodId To identify function in interface.
* @param[out] sequence To connect correct answer with correct request.
*
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
virtual erpc_status_t readHeadOfMessage(Codec *codec, message_type_t &msgType, uint32_t &serviceId,
uint32_t &methodId, uint32_t &sequence);
/*!
* @brief This function finds service base on service ID.
*
* @param[in] serviceId Service id number.
*
* @return Pointer to service or NULL.
*/
virtual Service *findServiceWithId(uint32_t serviceId);
#if ERPC_NESTED_CALLS
friend class ClientManager;
friend class ArbitratedClientManager;
/*!
* @brief This function runs the server.
*
* @param[in] Request context to check that answer was for nested call.
*/
virtual erpc_status_t run(RequestContext &request) = 0;
#endif
private:
// Disable copy ctor.
Server(const Server &other); /*!< Disable copy ctor. */
Server &operator=(const Server &other); /*!< Disable copy ctor. */
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__SERVER_H_

View File

@ -0,0 +1,174 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SERVER_SETUP_H_
#define _EMBEDDED_RPC__SERVER_SETUP_H_
#include "erpc_common.h"
#include "erpc_config_internal.h"
#include "erpc_mbf_setup.h"
#include "erpc_transport_setup.h"
#if ERPC_PRE_POST_ACTION
#include "erpc_pre_post_action.h"
#endif
/*!
* @addtogroup server_setup
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
//! @brief Opaque server object type.
typedef struct ServerType *erpc_server_t;
//! @name Server setup
//@{
/*!
* @brief This function initializes server.
*
* This function initializes server with all components necessary for running server.
*
* @param[in] transport Initiated transport.
* @param[in] message_buffer_factory Initiated message buffer factory.
*
* @return erpc_server_t Pointer to server structure.
*/
erpc_server_t erpc_server_init(erpc_transport_t transport, erpc_mbf_t message_buffer_factory);
/*!
* @brief This function de-initializes server.
*
* This function de-initializes server and all components which it own.
*
* @param[in] server Pointer to server structure.
*/
void erpc_server_deinit(erpc_server_t server);
/*!
* @brief This function adds service to server.
*
* Services contain implementations of functions called from client to server.
*
* @param[in] server Pointer to server structure.
* @param[in] service Service which contains implementations of functions called from client to server.
*/
void erpc_add_service_to_server(erpc_server_t server, void *service);
/*!
* @brief This function removes service from server.
*
* @param[in] server Pointer to server structure.
* @param[in] service Service which contains implementations of functions called from client to server.
*/
void erpc_remove_service_from_server(erpc_server_t server, void *service);
/*!
* @brief Can be used to set own crcStart number.
*
* For example can be used generated crc from erpcgen
* which is providing when @crc annotation is used.
* Accessed can be through 'extern const uint32_t erpc_generated_crc;'
*
* @param[in] server Pointer to server structure.
* @param[in] crcStart Set start number for crc.
*/
void erpc_server_set_crc(erpc_server_t server, uint32_t crcStart);
//@}
//! @name Server control
//@{
/*!
* @brief This function calls server implementation until it is stopped.
*
* This is blocking method, where server is trying read (and if it is requested also send) message
* until it is stopped.
*
* @param[in] server Pointer to server structure.
*
* @return Return one of status from erpc_common.h
*/
erpc_status_t erpc_server_run(erpc_server_t server);
/*!
* @brief This function calls server implementation only once.
*
* This is non-blocking method, where server is trying read (and if it is requested also send) message only once.
*
* @param[in] server Pointer to server structure.
*
* @return Return one of status from erpc_common.h
*/
erpc_status_t erpc_server_poll(erpc_server_t server);
/*!
* @brief This functions should be used when client is calling quit server.
*
* This method sets server from On to OFF. When the server returns from its implementation,
* erpc_server_deinit() function should be called.
*
* @param[in] server Pointer to server structure.
*/
void erpc_server_stop(erpc_server_t server);
#if ERPC_MESSAGE_LOGGING
/*!
* @brief This function adds transport object for logging send/receive messages.
*
* @param[in] server Pointer to server structure.
* @param[in] transport Initiated transport.
*
* @retval True When transport was successfully added.
* @retval False When transport wasn't added.
*/
bool erpc_server_add_message_logger(erpc_server_t server, erpc_transport_t transport);
#endif
#if ERPC_PRE_POST_ACTION
/*!
* @brief This function set callback function executed at the beginning of eRPC call.
*
* @param[in] server Pointer to server structure.
* @param[in] preCB Callback used at the beginning of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_server_add_pre_cb_action(erpc_server_t server, pre_post_action_cb preCB);
/*!
* @brief This function set callback function executed at the end of eRPC call.
*
* @param[in] server Pointer to server structure.
* @param[in] postCB Callback used at the end of eRPC call. When NULL and ERPC_PRE_POST_ACTION_DEFAULT
* is enabled then default function will be set.
*/
void erpc_server_add_post_cb_action(erpc_server_t server, pre_post_action_cb postCB);
#endif
//@}
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _EMBEDDED_RPC__SERVER_SETUP_H_

View File

@ -0,0 +1,94 @@
/*
* Copyright 2020 NXP
* Copyright 2020 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SETUP_EXTENSIONS_H_
#define _EMBEDDED_RPC__SETUP_EXTENSIONS_H_
#include "erpc_config_internal.h"
#include <stdint.h>
#if !ERPC_THREADS_IS(NONE)
#if ERPC_THREADS_IS(FREERTOS)
#include "FreeRTOS.h"
#include "task.h"
#include "timers.h"
#endif
#endif // ERPC_THREADS
/*!
* @addtogroup port_setup_extensions
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
namespace erpc {
/*!
* @brief This function is used for default pre erpc call action.
*/
void erpc_pre_cb_default(void);
/*!
* @brief This function is used for default post erpc call action.
*/
void erpc_post_cb_default(void);
} // namespace erpc
extern "C" {
#endif
#if ERPC_THREADS_IS(FREERTOS)
typedef TimerCallbackFunction_t erpc_call_timer_cb_default_t;
#else
typedef void *erpc_call_timer_cb_default_t;
#endif
/*!
* @brief This function is used for initializing variables for task freeze detection.
*
* @param[in] erpc_call_timer_cb Callback function called when eRPC call freeze.
* When NULL default callback will be used.
* @param[in] waitTimeMs Platform specific time to throw error cb in case of eRPC call freeze in [ms].
*/
void erpc_init_call_progress_detection_default(erpc_call_timer_cb_default_t erpc_call_timer_cb, uint32_t waitTimeMs);
/*!
* @brief This function is used for deinitialization variables for task freeze detection.
*/
void erpc_deinit_call_progress_detection_default(void);
/*!
* @brief This function returns default eRPC call progress status.
*
* @return True if eRPC call is in progress, otherwise False.
*/
bool erpc_is_call_in_progress_default(void);
/*!
* @brief This function resets eRPC state.
*
* Can be used when user reinitialize communication between client and server.
*/
void erpc_reset_in_progress_state_default(void);
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _EMBEDDED_RPC__SETUP_EXTENSIONS_H_

View File

@ -0,0 +1,128 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__SIMPLE_SERVER_H_
#define _EMBEDDED_RPC__SIMPLE_SERVER_H_
#include "erpc_server.hpp"
/*!
* @addtogroup infra_server
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Based server implementation.
*
* @ingroup infra_server
*/
class SimpleServer : public Server
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*/
SimpleServer(void);
virtual ~SimpleServer(void);
/*!
* @brief Run server in infinite loop.
*
* Will never jump out from this function.
*/
virtual erpc_status_t run(void) override;
/*!
* @brief Run server implementation only if exist message to process.
*
* If is message to process, server process it and jumps out from this function,
* useful for bare-metal because doesn't block main loop, when are not messages
* to process.
*
* @return Return true when server is ON, else false.
*/
virtual erpc_status_t poll(void);
/*!
* @brief This function sets server from ON to OFF
*/
virtual void stop(void) override;
protected:
bool m_isServerOn; /*!< Information if server is ON or OFF. */
/*!
* @brief Run server implementation.
*
* This function call functions for receiving data, process this data and
* if reply exist, send it back.
*/
erpc_status_t runInternal(void);
/*!
* @brief This function handle receiving request message and reading base info about message.
*
* @param[in] codec Inout codec to use.
* @param[in] buff Inout codec to use.
* @param[out] msgType Type of received message. Based on message type will be (will be not) sent respond.
* @param[out] serviceId To identify interface.
* @param[out] methodId To identify function in interface.
* @param[out] sequence To connect correct answer with correct request.
*
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
erpc_status_t runInternalBegin(Codec **codec, MessageBuffer &buff, message_type_t &msgType, uint32_t &serviceId,
uint32_t &methodId, uint32_t &sequence);
/*!
* @brief This function process message and handle sending respond.
*
* @param[in] codec Inout codec to use.
* @param[in] msgType Type of received message. Based on message type will be (will be not) sent respond.
* @param[in] serviceId To identify interface.
* @param[in] methodId To identify function in interface.
* @param[in] sequence To connect correct answer with correct request.
*
* @returns #kErpcStatus_Success or based on service handleInvocation.
*/
erpc_status_t runInternalEnd(Codec *codec, message_type_t msgType, uint32_t serviceId, uint32_t methodId,
uint32_t sequence);
#if ERPC_NESTED_CALLS
/*!
* @brief This function runs the server.
*
* @param[in] Request context to check that answer was for nested call.
*/
virtual erpc_status_t run(RequestContext &request) override;
#endif
/*!
* @brief Disposing message buffers and codecs.
*
* @param[in] codec Pointer to codec to dispose. It contains also message buffer to dispose.
*/
void disposeBufferAndCodec(Codec *codec);
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__SIMPLE_SERVER_H_

View File

@ -0,0 +1,120 @@
/*
* Copyright (c) 2015-2016, Freescale Semiconductor, Inc.
* Copyright 2021 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __embedded_rpc__static_queue__
#define __embedded_rpc__static_queue__
#include <cstring>
#include <cstdint>
/*!
* @addtogroup infra_utility
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Template class which implements static queue as ring buffer
*
* @ingroup infra_utility
*/
template <class T, uint32_t elementCount>
class StaticQueue
{
public:
/*!
* @brief Constructor of StaticQueue class.
*
* This function sets capacity of queue, m_head and m_tail indexes to zero.
*/
StaticQueue(void)
{
m_capacity = elementCount;
m_head = 0;
m_tail = 0;
(void)memset(m_storage, 0, sizeof(m_storage));
}
/*!
* @brief Destructor of StaticQueue class.
*
* This function free allocated buffer for m_data.
*/
~StaticQueue(void) {}
/*!
* @brief This function adds element to queue.
*
* @param[in] element Element for adding.
*
* @retval true Element was added.
* @retval false Element was not added, queue is full.
*/
bool add(T element)
{
if ((m_head + 1U) % m_capacity != m_tail)
{
(void)std::memcpy(m_storage[m_head], &element, sizeof(T));
m_head = (m_head + 1U) % m_capacity;
return true;
}
return false;
}
/*!
* @brief This function returns element from queue.
*
* @param[out] element Pointer to element to which will be copied element from queue.
*
* @retval true Element was copied from queue.
* @retval false Element was not copied, queue is empty.
*/
bool get(T *element)
{
if (m_tail != m_head)
{
(void)std::memcpy(element, m_storage[m_tail], sizeof(T));
m_tail = (m_tail + 1U) % m_capacity;
return true;
}
return false;
}
/*!
* @brief This function returns number of elements in queue.
*
* @return Number of elements in queue.
*/
uint32_t size(void)
{
if (m_head >= m_tail)
{
return m_head - m_tail;
}
return (m_capacity - m_tail + m_head);
}
protected:
uint64_t m_storage[elementCount]
[(sizeof(T) + sizeof(uint64_t) - 1U) / sizeof(uint64_t)]; /*!< Preallocated space based on data
type size and elements count. */
uint32_t m_capacity; /*!< Capacity of queue */
uint32_t volatile m_head; /*!< Index to free slot */
uint32_t volatile m_tail; /*!< Index to slot with m_data */
};
} // namespace erpc
/*! @} */
#endif // defined(__embedded_rpc__static_queue__)

View File

@ -0,0 +1,156 @@
/*
* Copyright (c) 2015, Freescale Semiconductor, Inc.
* Copyright 2016 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__TCP_TRANSPORT_H_
#define _EMBEDDED_RPC__TCP_TRANSPORT_H_
#if defined(__MINGW32__)
#include <winsock2.h>
#endif
#include "erpc_framed_transport.hpp"
#include "erpc_threading.h"
/*!
* @addtogroup tcp_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Client side of TCP/IP transport.
*
* @ingroup tcp_transport
*/
class TCPTransport : public FramedTransport
{
public:
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*
* @param[in] isServer True when this transport is used for server side application.
*/
explicit TCPTransport(bool isServer);
/*!
* @brief Constructor.
*
* This function initializes object attributes.
*
* @param[in] host Specify the host name or IP address of the computer.
* @param[in] port Specify the listening port number.
* @param[in] isServer True when this transport is used for server side application.
*/
TCPTransport(const char *host, uint16_t port, bool isServer);
/*!
* @brief TCPTransport destructor
*/
virtual ~TCPTransport(void);
/*!
* @brief This function set host and port of this transport layer.
*
* @param[in] host Specify the host name or IP address of the computer.
* @param[in] port Specify the listening port number.
*/
void configure(const char *host, uint16_t port);
/*!
* @brief This function will create host on server side, or connect client to the server.
*
* @retval #kErpcStatus_Success When creating host was successful or client connected successfully.
* @retval #kErpcStatus_UnknownName Host name resolution failed.
* @retval #kErpcStatus_ConnectionFailure Connecting to the specified host failed.
*/
virtual erpc_status_t open(void);
/*!
* @brief This function disconnects client or stop server host.
*
* @param[in] stopServer Specify is server shall be closed as well (stop listen())
* @retval #kErpcStatus_Success Always return this.
*/
virtual erpc_status_t close(bool stopServer = true);
protected:
bool m_isServer; /*!< If true then server is using transport, else client. */
const char *m_host; /*!< Specify the host name or IP address of the computer. */
uint16_t m_port; /*!< Specify the listening port number. */
#if defined(__MINGW32__)
SOCKET m_socket; /*!< Socket number. */
#else
int m_socket; /*!< Socket number. */
#endif
Thread m_serverThread; /*!< Pointer to server thread. */
bool m_runServer; /*!< Thread is executed while this is true. */
using FramedTransport::underlyingReceive;
using FramedTransport::underlyingSend;
/*!
* @brief This function connect client to the server.
*
* @retval kErpcStatus_Success When client connected successfully.
* @retval kErpcStatus_Fail When client doesn't connected successfully.
*/
virtual erpc_status_t connectClient(void);
/*!
* @brief This function read data.
*
* @param[inout] data Preallocated buffer for receiving data.
* @param[in] size Size of data to read.
*
* @retval #kErpcStatus_Success When data was read successfully.
* @retval #kErpcStatus_ReceiveFailed When reading data ends with error.
* @retval #kErpcStatus_ConnectionClosed Peer closed the connection.
*/
virtual erpc_status_t underlyingReceive(uint8_t *data, uint32_t size) override;
/*!
* @brief This function writes data.
*
* @param[in] data Buffer to send.
* @param[in] size Size of data to send.
*
* @retval #kErpcStatus_Success When data was written successfully.
* @retval #kErpcStatus_SendFailed When writing data ends with error.
* @retval #kErpcStatus_ConnectionClosed Peer closed the connection.
*/
virtual erpc_status_t underlyingSend(const uint8_t *data, uint32_t size) override;
/*!
* @brief Server thread function.
*/
void serverThread(void);
/*!
* @brief Thread entry point.
*
* Control is passed to the serverThread() method of the TCPTransport instance pointed to
* by the @c arg parameter.
*
* @param arg Thread argument. The pointer to the TCPTransport instance is passed through
* this argument.
*/
static void serverThreadStub(void *arg);
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__TCP_TRANSPORT_H_

View File

@ -0,0 +1,540 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2023 NXP
* Copyright 2021 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __embedded_rpc__thread__
#define __embedded_rpc__thread__
#include "erpc_config_internal.h"
#include <stdint.h>
// Exclude the rest of the file if threading is disabled.
#if !ERPC_THREADS_IS(NONE)
#if ERPC_THREADS_IS(PTHREADS)
#include <pthread.h>
#elif ERPC_THREADS_IS(FREERTOS)
#include "FreeRTOS.h"
#include "semphr.h"
#include "task.h"
#elif ERPC_THREADS_IS(ZEPHYR)
#include <zephyr/kernel.h>
#elif ERPC_THREADS_IS(MBED)
#if MBED_CONF_RTOS_PRESENT
#include "rtos.h"
#else
#warning mbed-rpc: Threading is enabled but Mbed RTOS is not present!
#endif
#elif ERPC_THREADS_IS(WIN32)
#include "windows.h"
#elif ERPC_THREADS_IS(THREADX)
#include "tx_api.h"
#endif // ERPC_THREADS
/*!
* @addtogroup port_threads
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////////////////////////
//! @brief Thread function type.
//!
//! @param arg User provided argument that was passed into the start() method.
typedef void (*thread_entry_t)(void *arg);
////////////////////////////////////////////////////////////////////////////////
// Declarations
////////////////////////////////////////////////////////////////////////////////
#if defined(__cplusplus)
namespace erpc {
/*!
* @brief Simple thread class.
*
* @ingroup port_threads
*/
class Thread
{
public:
//! @brief Unique identifier for a thread.
typedef void *thread_id_t;
#if ERPC_THREADS_IS(FREERTOS)
typedef StackType_t *thread_stack_pointer;
#else
typedef void *thread_stack_pointer;
#endif
/*!
* @brief Default constructor for use with the init() method.
*
* If this constructor is used, the init() method must be called before the thread can be
* started.
*
* @param[in] name Optional name for the thread.
*/
Thread(const char *name = 0);
/*!
* @brief Constructor.
*
* This constructor fully initializes the thread object.
*
* @param[in] entry
* @param[in] priority
* @param[in] stackSize
* @param[in] name Optional name for the thread.
* @param[in] stackPtr Mandatory task stack pointer for static api usage.
*/
Thread(thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0, const char *name = 0,
thread_stack_pointer stackPtr = NULL);
/*!
* @brief Destructor.
*/
virtual ~Thread(void);
/*!
* @brief This function sets name for thread.
*
* @param[in] name Name for thread.
*/
void setName(const char *name) { m_name = name; }
/*!
* @brief This function returns name of thread.
*
* @return Name of thread.
*/
const char *getName(void) const { return m_name; }
/*!
* @brief This function initializes thread.
*
* @param[in] entry Entry function.
* @param[in] priority Task priority.
* @param[in] stackSize Stack size.
* @param[in] stackPtr Mandatory task stack pointer for static api usage.
*/
void init(thread_entry_t entry, uint32_t priority = 0, uint32_t stackSize = 0,
thread_stack_pointer stackPtr = NULL);
/*!
* @brief This function starts thread execution.
*
* @param[in] arg Function argument.
*/
void start(void *arg = 0);
/*!
* @brief This function puts thread to sleep.
*
* @param[in] usecs Time for sleeping in [us].
*/
static void sleep(uint32_t usecs);
/*!
* @brief This function returns current thread id.
*
* @return Thread id.
*/
thread_id_t getThreadId(void) const
{
#if ERPC_THREADS_IS(PTHREADS)
return reinterpret_cast<thread_id_t>(m_thread);
#elif ERPC_THREADS_IS(FREERTOS)
return reinterpret_cast<thread_id_t>(m_task);
#elif ERPC_THREADS_IS(ZEPHYR)
return reinterpret_cast<thread_id_t>(m_thread_id);
#elif ERPC_THREADS_IS(MBED)
return reinterpret_cast<thread_id_t>(m_thread->get_id());
#elif ERPC_THREADS_IS(WIN32)
return reinterpret_cast<thread_id_t>(m_thread);
#elif ERPC_THREADS_IS(THREADX)
return reinterpret_cast<thread_id_t>(m_thread.tx_thread_id);
#endif
}
/*!
* @brief This function returns thread id where function is called.
*
* @return Thread id.
*/
static thread_id_t getCurrentThreadId(void)
{
#if ERPC_THREADS_IS(PTHREADS)
return reinterpret_cast<thread_id_t>(pthread_self());
#elif ERPC_THREADS_IS(FREERTOS)
return reinterpret_cast<thread_id_t>(xTaskGetCurrentTaskHandle());
#elif ERPC_THREADS_IS(ZEPHYR)
return reinterpret_cast<thread_id_t>(k_current_get());
#elif ERPC_THREADS_IS(MBED)
return reinterpret_cast<thread_id_t>(rtos::ThisThread::get_id());
#elif ERPC_THREADS_IS(WIN32)
return reinterpret_cast<thread_id_t>(GetCurrentThread());
#elif ERPC_THREADS_IS(THREADX)
return reinterpret_cast<thread_id_t>(tx_thread_identify());
#endif
}
#if ERPC_THREADS_IS(ZEPHYR)
/*!
* @brief This function sets stack pointer for Zephyr task.
*
* @param[in] stack Stack pointer.
*/
void setStackPointer(k_thread_stack_t *stack) { m_stack = stack; }
#endif
/*!
* @brief This function returns Thread instance where functions is called.
*
* @return Thread instance.
*/
static Thread *getCurrentThread(void);
/*!
* @brief Compare operator compares two threads.
*
* @param[in] o Thread instance.
*
* @retval true When threads are same.
* @retval false When threads aren't same.
*/
bool operator==(Thread &o);
protected:
/*!
* @brief This function execute entry function.
*/
virtual void threadEntryPoint(void);
private:
const char *m_name; /*!< Thread name. */
thread_entry_t m_entry; /*!< Thread entry function. */
void *m_arg; /*!< Entry parameter. */
uint32_t m_stackSize; /*!< Stack size. */
uint32_t m_priority; /*!< Task priority. */
thread_stack_pointer m_stackPtr; /*!< Task pointer. */
#if ERPC_THREADS_IS(PTHREADS)
static pthread_key_t s_threadObjectKey; /*!< Thread key. */
pthread_t m_thread; /*!< Current thread. */
#elif ERPC_THREADS_IS(FREERTOS)
TaskHandle_t m_task; /*!< Current task. */
Thread *m_next; /*!< Pointer to next Thread. */
static Thread *s_first; /*!< Pointer to first Thread. */
#if ERPC_ALLOCATION_POLICY == ERPC_ALLOCATION_POLICY_STATIC
StaticTask_t m_staticTask; /*!< Hold static task data. */
#endif
#elif ERPC_THREADS_IS(ZEPHYR)
struct k_thread m_thread; /*!< Current thread. */
k_tid_t m_thread_id;
k_thread_stack_t *m_stack; /*!< Pointer to stack. */
#elif ERPC_THREADS_IS(MBED)
rtos::Thread *m_thread; /*!< Underlying Thread instance */
Thread *m_next; /*!< Pointer to next Thread. */
static Thread *s_first; /*!< Pointer to first Thread. */
#elif ERPC_THREADS_IS(WIN32)
HANDLE m_thread;
unsigned int m_thrdaddr;
Thread *m_next; /*!< Pointer to next Thread. */
static Thread *s_first; /*!< Pointer to first Thread. */
static CRITICAL_SECTION m_critical_section;
static BOOL m_critical_section_inited;
#elif ERPC_THREADS_IS(THREADX)
TX_THREAD m_thread; /*!< Underlying Thread instance */
Thread *m_next; /*!< Pointer to next Thread. */
static Thread *s_first; /*!< Pointer to first Thread. */
#endif
#if ERPC_THREADS_IS(PTHREADS)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg Thread to execute.
*/
static void *threadEntryPointStub(void *arg);
#elif ERPC_THREADS_IS(FREERTOS)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg Thread to execute.
*/
static void threadEntryPointStub(void *arg);
#elif ERPC_THREADS_IS(ZEPHYR)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg1 Thread to execute.
* @param[in] arg2
* @param[in] arg3
*/
static void threadEntryPointStub(void *arg1, void *arg2, void *arg3);
#elif ERPC_THREADS_IS(MBED)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg Thread to execute.
*/
static void threadEntryPointStub(void *arg);
#elif ERPC_THREADS_IS(WIN32)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg Thread to execute.
*/
static unsigned WINAPI threadEntryPointStub(void *arg);
#elif ERPC_THREADS_IS(THREADX)
/*!
* @brief This function execute threadEntryPoint function.
*
* @param[in] arg Thread to execute.
*/
static void threadEntryPointStub(ULONG arg);
#endif
private:
/*!
* @brief Copy constructor.
*
* @param[in] o Thread to copy.
*/
Thread(const Thread &o);
/*!
* @brief Assign operator.
*
* @param[in] o Thread to assign.
*/
Thread &operator=(const Thread &o);
};
/*!
* @brief Mutex.
*
* If the OS supports it, the mutex will be recursive.
*
* @ingroup port_threads
*/
class Mutex
{
public:
/*!
* @brief
*/
class Guard
{
public:
/*!
* @brief Constructor.
*
* @param[in] mutex to lock.
*/
Guard(Mutex &mutex) : m_mutex(mutex) { (void)m_mutex.lock(); }
/*!
* @brief Destructor.
*/
~Guard(void) { (void)m_mutex.unlock(); }
private:
Mutex &m_mutex; /*!< Mutex to lock. */
};
/*!
* @brief Constructor.
*/
Mutex(void);
/*!
* @brief Destructor.
*/
~Mutex(void);
/*!
* @brief This function try lock mutex.
*
* @retval true When mutex locked successfully.
* @retval false When mutex didn't locked.
*/
bool tryLock(void);
/*!
* @brief This function lock mutex.
*
* @retval true When mutex locked successfully.
* @retval false When mutex didn't locked.
*/
bool lock(void);
/*!
* @brief This function unlock mutex.
*
* @retval true When mutex unlocked successfully.
* @retval false When mutex didn't unlocked.
*/
bool unlock(void);
#if ERPC_THREADS_IS(PTHREADS)
/*!
* @brief This function returns pointer to mutex.
*
* @return Pointer to mutex.
*/
pthread_mutex_t *getPtr(void) { return &m_mutex; }
#endif
private:
#if ERPC_THREADS_IS(PTHREADS)
pthread_mutex_t m_mutex; /*!< Mutex.*/
#elif ERPC_THREADS_IS(FREERTOS)
SemaphoreHandle_t m_mutex; /*!< Mutex.*/
StaticSemaphore_t m_staticQueue; /*!< Static queue. */
#elif ERPC_THREADS_IS(ZEPHYR)
struct k_mutex m_mutex; /*!< Mutex.*/
#elif ERPC_THREADS_IS(MBED)
rtos::Mutex *m_mutex; /*!< Mutex. */
#elif ERPC_THREADS_IS(WIN32)
HANDLE m_mutex;
#elif ERPC_THREADS_IS(THREADX)
TX_MUTEX m_mutex;
#endif
private:
/*!
* @brief Copy constructor.
*
* @param[in] o Mutex to copy.
*/
Mutex(const Mutex &o);
/*!
* @brief Copy constructor.
*
* @param[in] o Mutex to copy.
*/
Mutex &operator=(const Mutex &o);
};
/*!
* @brief Simple semaphore class.
*
* @ingroup port_threads
*/
class Semaphore
{
public:
/*!
* @brief Variable for semaphore to wait forever.
*/
static const uint32_t kWaitForever = 0xffffffffu;
/*!
* @brief Constructor.
*
* @param[in] count Semaphore number.
*/
Semaphore(int count = 0);
/*!
* @brief Destructor.
*/
~Semaphore(void);
/*!
* @brief This function puts semaphore.
*/
void put(void);
#if ERPC_THREADS_IS(FREERTOS)
/*!
* @brief This function puts semaphore from interrupt.
*/
void putFromISR(void);
#endif // ERPC_HAS_FREERTOS
/*!
* @brief This function get semaphore.
*
* @param[in] timeoutUsecs Time how long can wait for getting semaphore in [us].
*
* @retval true When semaphore got successfully.
* @retval false When failed getting semaphore or if timeout expired.
*/
bool get(uint32_t timeoutUsecs = kWaitForever);
/*!
* @brief This function returns semaphore count number.
*
* @return Semaphore count number.
*/
int getCount(void) const;
private:
#if ERPC_THREADS_IS(PTHREADS)
int m_count; /*!< Semaphore count number. */
pthread_cond_t m_cond; /*!< Condition variable. Allows threads to suspend execution and relinquish the processors
until some predicate on shared data is satisfied. */
Mutex m_mutex; /*!< Mutext. */
#elif ERPC_THREADS_IS(FREERTOS)
SemaphoreHandle_t m_sem; /*!< Semaphore. */
StaticSemaphore_t m_staticQueue; /*!< Static queue. */
#elif ERPC_THREADS_IS(ZEPHYR)
struct k_sem m_sem; /*!< Semaphore. */
#elif ERPC_THREADS_IS(MBED)
rtos::Semaphore *m_sem; /*!< Semaphore. */
int m_count; /*!< Semaphore count number. */
#elif ERPC_THREADS_IS(WIN32)
Mutex m_mutex; /*!< Mutext. */
int m_count;
HANDLE m_sem;
#elif ERPC_THREADS_IS(THREADX)
TX_SEMAPHORE m_sem; /*!< Semaphore. */
#endif
private:
/*!
* @brief Copy constructor.
*
* @param[in] o Semaphore to copy.
*/
Semaphore(const Semaphore &o);
/*!
* @brief Copy constructor.
*
* @param[in] o Semaphore to copy.
*/
Semaphore &operator=(const Semaphore &o);
};
} // namespace erpc
#endif // defined(__cplusplus)
/*! @} */
#endif // ERPC_THREADS
#endif // defined(__embedded_rpc__thread__)
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,134 @@
/*
* Copyright (c) 2014, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _EMBEDDED_RPC__TRANSPORT_H_
#define _EMBEDDED_RPC__TRANSPORT_H_
#include "erpc_common.h"
#include "erpc_crc16.hpp"
#include "erpc_message_buffer.hpp"
#include <cstring>
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
/*!
* @brief Abstract interface for transport layer.
*
* @ingroup infra_transport
*/
class Transport
{
public:
/*!
* @brief Constructor.
*/
Transport(void) {}
/*!
* @brief Transport destructor
*/
virtual ~Transport(void) {}
/**
* @brief Size of data placed in MessageBuffer before serializing eRPC data.
*
* @return uint8_t Amount of bytes, reserved before serialized data.
*/
virtual uint8_t reserveHeaderSize(void) { return 0; }
/*!
* @brief Prototype for receiving message.
*
* Each transport layer need define this function.
*
* @param[out] message Will return pointer to received message buffer.
*
* @return based on receive implementation.
*/
virtual erpc_status_t receive(MessageBuffer *message) = 0;
/*!
* @brief Prototype for send message.
*
* Each transport layer need define this function.
*
* @param[in] message Pass message buffer to send.
*
* @return based on send implementation.
*/
virtual erpc_status_t send(MessageBuffer *message) = 0;
/*!
* @brief Poll for an incoming message.
*
* This function should return true if are some messages to process by server,
* the return value should be tested before calling receive function to avoid
* waiting for a new message (receive can be implemented as blocking function).
*
* @retval True when a message is available to process, else false.
*/
virtual bool hasMessage(void) { return true; }
/*!
* @brief This functions sets the CRC-16 implementation.
*
* @param[in] crcImpl Object containing crc-16 compute function.
*/
virtual void setCrc16(Crc16 *crcImpl) { (void)crcImpl; }
/*!
* @brief This functions gets the CRC-16 object.
*
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 *getCrc16(void) { return NULL; }
};
/*!
* @brief Abstract interface for transport factory.
*
* @ingroup infra_transport
*/
class TransportFactory
{
public:
/*!
* @brief Constructor.
*/
TransportFactory(void) {}
/*!
* @brief TransportFactory destructor
*/
virtual ~TransportFactory(void) {}
/*!
* @brief Return created transport object.
*
* @return Pointer to created transport object.
*/
virtual Transport *create(void) = 0;
};
} // namespace erpc
/*! @} */
#endif // _EMBEDDED_RPC__TRANSPORT_H_

View File

@ -0,0 +1,230 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#if !defined(__embedded_rpc__transport_arbitrator__)
#define __embedded_rpc__transport_arbitrator__
#include "erpc_client_manager.h"
#include "erpc_codec.hpp"
#include "erpc_threading.h"
#include "erpc_transport.hpp"
/*!
* @addtogroup infra_transport
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Classes
////////////////////////////////////////////////////////////////////////////////
namespace erpc {
class Codec;
/*!
* @brief Interposer to share transport between client and server.
*
* Allocates memory for client receive request info. This memory is never freed. It is put on a
* free list and is reused for future client receives. The class will allocate as many client
* receive info structs as the maximum number of simultaneous client receive requests from different
* threads.
*
* @ingroup infra_transport
*/
class TransportArbitrator : public Transport
{
public:
//! @brief Represents a single client's receive request.
typedef uintptr_t client_token_t;
/*!
* @brief Constructor.
*/
TransportArbitrator(void);
/*!
* @brief Destructor.
*/
virtual ~TransportArbitrator(void);
/**
* @brief Size of data placed in MessageBuffer before serializing eRPC data.
*
* @return uint8_t Amount of bytes, reserved before serialized data.
*/
virtual uint8_t reserveHeaderSize(void) override;
/*!
* @brief Prototype for receiving message.
*
* Each transport layer need define this function.
*
* @param[out] message Will return pointer to received message buffer.
*
* @return based on receive implementation.
*/
virtual erpc_status_t receive(MessageBuffer *message) override;
/*!
* @brief Prototype for send message.
*
* Each transport layer need define this function.
*
* @param[in] message Pass message buffer to send.
*
* @return based on send implementation.
*/
virtual erpc_status_t send(MessageBuffer *message) override;
/*!
* @brief Check if the underlying shared transport has a message
*
* @retval The underlying transport is expected to return true when a message is available to
* process and false otherwise.
*/
virtual bool hasMessage(void) override;
/*!
* @brief This functions sets the CRC-16 implementation.
*
* @param[in] crcImpl Object containing crc-16 compute function.
*/
virtual void setCrc16(Crc16 *crcImpl) override;
/*!
* @brief This functions gets the CRC-16 object.
*
* @return Crc16* Pointer to CRC-16 object containing crc-16 compute function.
*/
virtual Crc16 *getCrc16(void) override;
/*!
* @brief This function set shared client/server transport.
*
* @param[in] shared Shared client/server transport.
*/
void setSharedTransport(Transport *shared);
/*!
* @brief This function returns shared client/server transport.
*
* @return Transport * Returns shared client/server transport.
*/
Transport *getSharedTransport(void);
/*!
* @brief This function set codec.
*
* @param[in] codec Codec.
*/
void setCodec(Codec *codec);
/*!
* @brief This function get codec.
*
* @return Codec * Pointer to codec used within transport.
*/
Codec *getCodec(void);
/*!
* @brief Add a client request to the client list.
*
* This call is made by the client thread prior to sending the invocation to the server. It
* ensures that the transport arbitrator has the client's response message buffer ready in
* case it sees the response before the client even has a chance to call clientReceive().
*
* @param[in] request Reuquest context for receive action.
*
* @return A token is returned to the client
*/
client_token_t prepareClientReceive(RequestContext &request);
/*!
* @brief Receive method for the client.
*
* Blocks until the a reply message is received with the expected sequence number that is
* associated with @a token. The client must have called prepareClientReceive() previously.
*
* @param[in] token The token previously returned by prepareClientReceive().
*
* @return erpc_status_t Return erpc status of client receive function.
*/
erpc_status_t clientReceive(client_token_t token);
/*!
* @brief This function free client token.
*
* @param[in] token the client token to remove.
*/
void removePendingClient(client_token_t token);
/*!
* @brief Request info for a client trying to receive a response.
*/
struct PendingClientInfo
{
RequestContext *m_request; /*!< Client request context. */
Semaphore m_sem; /*!< Client semaphore. */
bool m_isValid; /*!< This struct validation. */
PendingClientInfo *m_next; /*!< Next client pending information. */
/*!
* @brief Constructor.
*/
PendingClientInfo(void);
/*!
* @brief Destructor.
*/
~PendingClientInfo(void);
};
protected:
Transport *m_sharedTransport; //!< Transport being shared through this arbitrator.
Codec *m_codec; //!< Codec used to read incoming message headers.
PendingClientInfo *m_clientList; //!< Active client receive requests.
PendingClientInfo *m_clientFreeList; //!< Unused client receive info structs.
Mutex m_clientListMutex; //!< Mutex guarding the client active and free lists.
/*!
* @brief Create a Pending Client object.
*
* @return PendingClientInfo* Return created object.
*/
PendingClientInfo *createPendingClient(void);
/*!
* @brief This function adds pending client.
*
* @return Pending client information.
*/
PendingClientInfo *addPendingClient(void);
/*!
* @brief This function removes pending client list.
*
* @param[in] list Pending client list to remove.
*/
void freeClientList(PendingClientInfo *list);
private:
// Disable copy ctor.
TransportArbitrator(const TransportArbitrator &other); /*!< Disable copy ctor. */
TransportArbitrator &operator=(const TransportArbitrator &other); /*!< Disable copy ctor. */
};
} // namespace erpc
/*! @} */
#endif // defined(__embedded_rpc__transport_arbitrator__)
////////////////////////////////////////////////////////////////////////////////
// EOF
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,598 @@
/*
* Copyright (c) 2014-2016, Freescale Semiconductor, Inc.
* Copyright 2016-2024 NXP
* Copyright 2019 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_TRANSPORT_SETUP_H_
#define _ERPC_TRANSPORT_SETUP_H_
/*!
* @addtogroup transport_setup
* @{
* @file
*/
////////////////////////////////////////////////////////////////////////////////
// Types
////////////////////////////////////////////////////////////////////////////////
//! @brief Opaque transport object type.
typedef struct ErpcTransport *erpc_transport_t;
//! @brief Ready callback object type for RPMsg-Lite transport.
typedef void (*rpmsg_ready_cb)(void);
////////////////////////////////////////////////////////////////////////////////
// API
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
//! @name Transport setup
//@{
//! @name DSPI transport setup
//@{
/*!
* @brief Create a DSPI master transport.
*
* Create DSPI master transport instance, to be used at master core.
*
* @param[in] baseAddr Base address of DSPI peripheral used in this transport layer.
* @param[in] baudRate DSPI baud rate.
* @param[in] srcClock_Hz DSPI source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_dspi_master_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize DSPI master transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_dspi_master_deinit(erpc_transport_t transport);
/*!
* @brief Create a DSPI slave transport.
*
* Create DSPI slave transport instance, to be used at slave core.
*
* @param[in] baseAddr Base address of DSPI peripheral used in this transport layer.
* @param[in] baudRate DSPI baud rate.
* @param[in] srcClock_Hz DSPI source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_dspi_slave_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize DSPI slave transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_dspi_slave_deinit(erpc_transport_t transport);
//@}
//! @name I2C transport setup
//@{
/*!
* @brief Create an I2C slave transport.
*
* Create I2C slave transport instance, to be used at slave core.
*
* @param[in] baseAddr Base address of I2C peripheral used in this transport layer.
* @param[in] baudRate SPI baud rate.
* @param[in] srcClock_Hz I2C source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_i2c_slave_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize I2C slave transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_i2c_slave_deinit(erpc_transport_t transport);
//@}
//! @name LPI2C transport setup
//@{
/*!
* @brief Create an LPI2C slave transport.
*
* Create LPI2C slave transport instance, to be used at slave core.
*
* @param[in] baseAddr Base address of LPI2C peripheral used in this transport layer.
* @param[in] baudRate SPI baud rate.
* @param[in] srcClock_Hz LPI2C source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_lpi2c_slave_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize LPI2C slave transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_lpi2c_slave_deinit(erpc_transport_t transport);
//@}
//! @name LPSPI transport setup
//@{
/*!
* @brief Create a LPSPI slave transport.
*
* Create LPSPI slave transport instance, to be used at slave core.
*
* @param[in] baseAddr Base address of LPSPI peripheral used in this transport layer.
* @param[in] baudRate LPSPI baud rate.
* @param[in] srcClock_Hz LPSPI source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_lpspi_slave_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize LPSPI slave transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_lpspi_slave_deinit(erpc_transport_t transport);
//@}
//! @name MU transport setup
//@{
/*!
* @brief Create an MU transport.
*
* Create Messaging Unit (MU) transport instance, to be used on both the server
* and the client side. Base address of the MU peripheral needs to be passed.
*
* @param[in] baseAddr Base address of MU peripheral.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_mu_init(void *baseAddr);
/*!
* @brief Deinitialize MU transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_mu_deinit(erpc_transport_t transport);
//@}
//! @name Linux RPMSG endpoint setup
//@{
/*!
* @brief Create an Linux RPMSG endpoint transport.
*
* This function is using RPMSG endpoints based on this implementation:
* github.com/nxp-mcuxpresso/rpmsg-sysfs/tree/0aa1817545a765c200b1b2f9b6680a420dcf9171 .
*
* When local/remote address is set to '-1', then default addresses will be used.
* When type is set to '0', then Datagram model will be used, else Stream.
*
* @param[in] local_addr Local endpoint address.
* @param[in] type Datagram (0) or Stream (1).
* @param[in] remote_addr Remote endpoint address.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_linux_init(int16_t local_addr, int8_t type, int16_t remote_addr);
/*!
* @brief Deinitialize an Linux RPMSG endpoint transport.
*
* This function deinitialize the Linux RPMSG endpoint transport.
*
* @param[in] transport Transport which was returned from init function.
*/
void erpc_transport_rpmsg_linux_deinit(erpc_transport_t transport);
//@}
//! @name RPMsg-Lite transport setup
//@{
/*!
* @brief Create an RPMsg-Lite transport.
*
* Create RPMsg-Lite baremetal transport instance, to be used at master core.
*
* @param[in] src_addr Address of local RPMsg endpoint used for communication.
* @param[in] dst_addr Address of remote RPMsg endpoint used for communication.
* @param[in] rpmsg_link_id Link ID used to define the rpmsg-lite instance, see
* rpmsg_platform.h
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_lite_master_init(uint32_t src_addr, uint32_t dst_addr, uint32_t rpmsg_link_id);
/*!
* @brief Deinitialize RPMsg-Lite transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_rpmsg_lite_master_deinit(erpc_transport_t transport);
/*!
* @brief Create an RPMsg-Lite transport.
*
* Create RPMsg-Lite baremetal transport instance, to be used at slave/remote
* core.
*
* @param[in] src_addr Address of local RPMsg endpoint used for communication.
* @param[in] dst_addr Address of remote RPMsg endpoint used for communication.
* @param[in] start_address Shared memory base address used for this instance of
* RPMsg-Lite.
* @param[in] rpmsg_link_id Link ID used to define the rpmsg-lite instance, see
* rpmsg_platform.h.
* @param[in] ready Callback function, which gets called, when RPMsg is
* initialized and master core can be notified.
* @param[in] nameservice_name Name of the nameservice channel to be announced
* to the other core.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_lite_remote_init(uint32_t src_addr, uint32_t dst_addr, void *start_address,
uint32_t rpmsg_link_id, rpmsg_ready_cb ready,
char *nameservice_name);
/*!
* @brief Deinitialize RPMsg-Lite transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_rpmsg_lite_remote_deinit(erpc_transport_t transport);
/*!
* @brief Create an RPMsg-Lite RTOS transport.
*
* Create RPMsg-Lite RTOS transport instance, to be used at master core.
*
* @param[in] src_addr Address of local RPMsg endpoint used for communication.
* @param[in] dst_addr Address of remote RPMsg endpoint used for communication.
* @param[in] rpmsg_link_id Link ID used to define the rpmsg-lite instance, see
* rpmsg_platform.h
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_lite_rtos_master_init(uint32_t src_addr, uint32_t dst_addr,
uint32_t rpmsg_link_id);
/*!
* @brief Deinitialize RPMsg-Lite RTOS transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_rpmsg_lite_rtos_master_deinit(erpc_transport_t transport);
/*!
* @brief Create an RPMsg-Lite RTOS transport.
*
* Create RPMsg-Lite RTOS transport instance, to be used at slave/remote core.
*
* @param[in] src_addr Address of local RPMsg endpoint used for communication.
* @param[in] dst_addr Address of remote RPMsg endpoint used for communication.
* @param[in] start_address Shared memory base address used for this instance of
* RPMsg-Lite.
* @param[in] rpmsg_link_id Link ID used to define the rpmsg-lite instance, see
* rpmsg_platform.h.
* @param[in] ready Callback function, which gets called, when RPMsg is
* initialized and master core can be notified.
* @param[in] nameservice_name Name of the nameservice channel to be announced
* to the other core.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_lite_rtos_remote_init(uint32_t src_addr, uint32_t dst_addr, void *start_address,
uint32_t rpmsg_link_id, rpmsg_ready_cb ready,
char *nameservice_name);
/*!
* @brief Deinitialize RPMsg-Lite RTOS transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_rpmsg_lite_rtos_remote_deinit(erpc_transport_t transport);
/*!
* @brief Create an RPMsg-Lite TTY transport.
*
* Create RPMsg-Lite TTY transport instance, to be used at slave/remote core.
* This function is mainly used with Linux running on the master core.
*
* @param[in] src_addr Address of local RPMsg endpoint used for communication.
* @param[in] dst_addr Address of remote RPMsg endpoint used for communication.
* @param[in] start_address Shared memory base address used for this instance of
* RPMsg-Lite.
* @param[in] rpmsg_link_id Link ID used to define the rpmsg-lite instance, see
* rpmsg_platform.h.
* @param[in] ready Callback function, which gets called, when RPMsg is
* initialized and master core can be notified.
* @param[in] nameservice_name Name of the nameservice channel to be announced
* to the other core.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_rpmsg_lite_tty_rtos_remote_init(uint32_t src_addr, uint32_t dst_addr,
void *start_address, uint32_t rpmsg_link_id,
rpmsg_ready_cb ready, char *nameservice_name);
/*!
* @brief Deinitialize an RPMSG lite tty rtos transport.
*
* This function deinitialize the RPMSG lite tty rtos transport.
*
* @param[in] transport Transport which was returned from init function.
*/
void erpc_transport_rpmsg_lite_tty_rtos_remote_deinit(erpc_transport_t transport);
//@}
//! @name Host PC serial port transport setup
//@{
/*!
* @brief Create a host PC serial port transport.
*
* Create a host PC serial port transport instance.
*
* @param[in] portName Port name.
* @param[in] baudRate Baud rate.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_serial_init(const char *portName, long baudRate);
/*!
* @brief Deinitialize a host PC serial port transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_serial_deinit(erpc_transport_t transport);
//@}
//! @name SPI transport setup
//@{
/*!
* @brief Create a SPI master transport.
*
* Create SPI master transport instance, to be used at master core.
*
* @param[in] baseAddr Base address of SPI peripheral used in this transport layer.
* @param[in] baudRate SPI baud rate.
* @param[in] srcClock_Hz SPI source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_spi_master_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize SPI master transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_spi_master_deinit(erpc_transport_t transport);
/*!
* @brief Create a SPI slave transport.
*
* Create SPI slave transport instance, to be used at slave core.
*
* @param[in] baseAddr Base address of SPI peripheral used in this transport layer.
* @param[in] baudRate SPI baud rate.
* @param[in] srcClock_Hz SPI source clock in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_spi_slave_init(void *baseAddr, uint32_t baudRate, uint32_t srcClock_Hz);
/*!
* @brief Deinitialize SPI slave transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_spi_slave_deinit(erpc_transport_t transport);
//@}
//! @name SPIdev transport setup
//@{
/*!
* @brief Create a SPIdev transport.
*
* Create SPIdev master transport instance, to be used at master core.
*
* @param[in] spidev SPI device name.
* @param[in] speed_Hz SPI clock speed in Hz.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_spidev_master_init(const char *spidev, uint32_t speed_Hz);
/*!
* @brief Deinitialize SPIdev transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_spidev_master_deinit(erpc_transport_t transport);
//@}
//! @name TCP transport setup
//@{
/*!
* @brief Create and open TCP transport
*
* For server, create a TCP listen socket and wait for connections
* For client, connect to server
*
* @param[in] host hostname/IP address to listen on or server to connect to
* @param[in] port port to listen on or server to connect to
* @param[in] isServer true if we are a server
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_tcp_init(const char *host, uint16_t port, bool isServer);
/*!
* @brief Close TCP connection
*
* For server, stop listening and close all sockets. Note that the server mode
* uses and accept() which is a not-recommended blocking method so we can't exit
* until a connection attempts is made. This is a deadlock but assuming that TCP
* code is supposed to be for test, I assume it's acceptable. Otherwise a non-blocking
* socket or select() shoudl be used
* For client, close server connection
*
* @param[in] transport Transport which was returned from init function.
*/
void erpc_transport_tcp_close(erpc_transport_t transport);
/*!
* @brief Deinitialize TCP transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_tcp_deinit(erpc_transport_t transport);
//@}
//! @name CMSIS UART transport setup
//@{
/*!
* @brief Create a CMSIS UART transport.
*
* Create a CMSIS UART transport instance, to be used on both the server
* and the client side.
*
* @param[in] uartDrv CMSIS USART driver structure address (Driver Control Block).
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_cmsis_uart_init(void *uartDrv);
/*!
* @brief Deinitialize CMSIS UART transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_cmsis_uart_deinit(erpc_transport_t transport);
//@}
//! @name Zephyr transports setup
//@{
/*!
* @brief Create a Zephyr UART transport.
*
* Create a Zephyr UART transport instance, to be used on both the server
* and the client side.
*
* @param[in] dev Zephyr UART device address.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_zephyr_uart_init(void *dev);
/*!
* @brief Deinitialize Zephyr UART transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_zephyr_uart_deinit(erpc_transport_t transport);
/*!
* @brief Create a Zephyr MBOX transport.
*
* Create a Zephyr MBOX transport instance, to be used on both the server
* and the client side.
*
* @param[in] dev Zephyr MBOX device address.
* @param[in] tx_channel Zephyr MBOX transmit channel.
* @param[in] rx_channel Zephyr MBOX receive channel.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_zephyr_mbox_init(void *dev, void *tx_channel, void *rx_channel);
/*!
* @brief Deinitialize Zephyr MBOX transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_zephyr_mbox_deinit(erpc_transport_t transport);
//@}
//! @name USB CDC transport setup
//@{
/*!
* @brief Create an USB CDC transport.
*
* Create an USB CDC transport instance.
*
* @param[in] serialHandle Pointer to point to a memory space of size #SERIAL_MANAGER_HANDLE_SIZE allocated by the
* caller, see serial manager header file.
* @param[in] serialConfig Pointer to user-defined configuration structure allocated by the caller, see serial manager
* header file.
* @param[in] usbCdcConfig Pointer to serial port usb config structure allocated by the caller, see serial manager
* header file.
* @param[in] usbRingBuffer Pointer to point serial manager ring buffer allocated by the caller, see serial manager
* header file.
* @param[in] usbRingBufferLength Serial manager ring buffer size.
*
* @return Return NULL or erpc_transport_t instance pointer.
*/
erpc_transport_t erpc_transport_usb_cdc_init(void *serialHandle, void *serialConfig, void *usbCdcConfig,
uint8_t *usbRingBuffer, uint32_t usbRingBufferLength);
/*!
* @brief Deinitialize USB CDC transport.
*
* @param[in] transport Transport which was initialized with init function.
*/
void erpc_transport_usb_cdc_deinit(erpc_transport_t transport);
//@}
//@}
#ifdef __cplusplus
}
#endif
/*! @} */
#endif // _ERPC_TRANSPORT_SETUP_H_

View File

@ -0,0 +1,17 @@
/*
* Copyright 2023 ACRIOS Systems s.r.o.
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdint.h>
namespace erpc {
typedef void *functionPtr_t;
typedef functionPtr_t *arrayOfFunctionPtr_t;
bool findIndexOfFunction(const arrayOfFunctionPtr_t sourceArrayOfFunctionPtr, uint16_t sourceArrayLength,
const functionPtr_t functionPtr, uint16_t &retVal);
} // namespace erpc

View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2016, Freescale Semiconductor, Inc.
* Copyright 2016-2025 NXP
* All rights reserved.
*
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef _ERPC_VERSION_H_
#define _ERPC_VERSION_H_
/*!
* @addtogroup infra
* @{
*/
////////////////////////////////////////////////////////////////////////////////
// Definitions
////////////////////////////////////////////////////////////////////////////////
//! @brief String version of eRPC.
#define ERPC_VERSION "1.14.0"
//! @brief Integer version of eRPC.
#define ERPC_VERSION_NUMBER 11400
/*! @} */
#endif /* _ERPC_VERSION_H_ */

Binary file not shown.

View File

@ -0,0 +1,6 @@
Official eRPC 1.14.0 SDK for Linux x86_64.
Built from the upstream 1.14.0 tag with GCC on this server.
Release static library, PIC enabled; Linux pthread and serial transports.
Headers and runtime library come from erpc_c; erpcgen is a host build tool.
Link applications using -I<prefix>/include/erpc -L<prefix>/lib -lerpc -pthread.
The cmvr_es head implementation, request.txt and project CMake were not changed.

View File

@ -0,0 +1,35 @@
{
"project": "EmbeddedRPC/erpc",
"tag": "1.14.0",
"source_url": "https://github.com/EmbeddedRPC/erpc/tree/1.14.0",
"source_archive_sha256": "119db152e961f1b3bec9dae8ce719517181b7ef58f18d976649cd9e627952a21",
"architecture": "x86_64-linux-gnu",
"compiler": "g++ (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0",
"build_type": "Release",
"position_independent_code": true,
"threading": "POSIX pthreads (Linux autodetection)",
"generator_version": "erpcgen 1.14.0\nCopyright 2016-2021 NXP. All rights reserved.",
"build_session": "/tmp/cmvr-erpc-sdk-1.14.0-19_qlrpl",
"build_command": [
"make",
"erpc",
"erpcgen",
"MAKETHREADS=4",
"build=release",
"FLEX=/tmp/cmvr-erpc-sdk-1.14.0-19_qlrpl/build-tools/usr/bin/flex",
"BISON=/tmp/cmvr-erpc-sdk-1.14.0-19_qlrpl/build-tools/usr/bin/bison"
],
"extra_environment": {
"CXXFLAGS": "-fPIC",
"CFLAGS": "-fPIC"
},
"tests": {
"generator_version": true,
"whole_archive_shared_link": true,
"installed_codec_crc_and_pthread_smoke": true,
"original_head_idl_generation": true,
"generated_sources_compiled": 5,
"generated_head_client_shared_link": true
},
"original_head_idl_sha256": "b61e0c1d12f5619942c5ce14bfc0650ea03fe6b8756264196e2fd3d2a2892a94"
}