/*
µRtWare is a lightweight publish/subscribe middleware for real-time
applications. It was developed as part of the software habitat for the
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
Copyright (C) 2018..2020 Thomas Schöpping et al.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
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. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#ifndef URT_PRIMITIVES_H
#define URT_PRIMITIVES_H
#include
#include
/*============================================================================*/
/* CONSTANTS */
/*============================================================================*/
/**
* @brief Special constant value for immediate (nonexistent) delays.
*/
#define URT_DELAY_IMMEDIATE (urt_delay_t)0
/**
* @brief Special constant value for infinite delays.
*/
#define URT_DELAY_INFINITE (urt_delay_t)~0
/*============================================================================*/
/* SETTINGS */
/*============================================================================*/
/*============================================================================*/
/* CHECKS */
/*============================================================================*/
/*============================================================================*/
/* DATA STRUCTURES AND TYPES */
/*============================================================================*/
/**
* @brief Type for temporal delays (in microseconds).
*/
#if (URT_CFG_DELAY_WIDTH == 32)
typedef uint32_t urt_delay_t;
#elif (URT_CFG_DELAY_WIDTH == 64)
typedef uint64_t urt_delay_t;
#else
# error "URT_CFG_DELAY_WIDTH must be set to 32 or 64."
#endif
/**
* @brief Type to use for the node stage value.
* @details Use wide types only if you need to synchronize the system very often.
*/
#if (URT_CFG_NODESTAGE_WIDTH == 8)
typedef uint8_t urt_nodestage_t;
#elif (URT_CFG_NODESTAGE_WIDTH == 16)
typedef uint16_t urt_nodestage_t;
#elif (URT_CFG_NODESTAGE_WIDTH == 32)
typedef uint32_t urt_nodestage_t;
#elif (URT_CFG_NODESTAGE_WIDTH == 64)
typedef uint64_t urt_nodestage_t;
#else
# error "URT_CFG_NODESTAGE_WIDTH must be set to 8, 16, 32 or 64."
#endif
/**
* @brief General status type used throughout µRtWare and its interfaces.
*/
typedef enum {
URT_STATUS_OK = 0, /**< Status indicating success. */
URT_STATUS_DEADLINEVIOLATION, /**< Status indicating a violated deadline. */
URT_STATUS_JITTERVIOLATION, /**< Status indicating a violated jitter requirement. */
URT_STATUS_RATEVIOLATION, /**< Status indicating a violated rate requirement. */
URT_STATUS_SYNC_PENDING, /**< Status indicating a synchronization barrier. */
URT_STATUS_SYNC_ERROR, /**< Status indicating a failed synchronization. */
URT_STATUS_NODE_INVALEVTMASK, /**< Status indicating an invalid event mask. */
#if (URT_CFG_PUBSUB_ENABLED == true) || defined(__DOXYGEN__)
URT_STATUS_TOPIC_DUPLICATE, /**< Status indicating multiple use of the same topic ID. */
URT_STATUS_PUBLISH_TIMEOUT, /**< Status indicating a timeout when publishinh a message. */
URT_STATUS_SUBSCRIBE_TOPICSET, /**< Status indicating that the subscriber is already associated to a topic. */
URT_STATUS_FETCH_NOTOPIC, /**< Status indicating that the subscriber is not associated to any topic. */
URT_STATUS_FETCH_NOMESSAGE, /**< Status indicating that no message could be fetched. */
URT_STATUS_UNSUBSCRIBE_NOTOPIC, /**< Status indicating that the subscriber is not associated to an topic. */
#endif /* URT_CFG_PUBSUB_ENABLED == true */
#if (URT_CFG_RPC_ENABLED == true) || defined(__DOXYGEN__)
URT_STATUS_SERVICE_DUPLICATE, /**< Status indicating multiple use of the same service ID. */
URT_STATUS_REQUEST_BADOWNER, /**< Status indicating that a request is currently owned by another component. */
URT_STATUS_REQUEST_LOCKED, /**< Status indicating a currently locked request. */
#endif /* URT_CFG_RPC_ENABLED == true */
} urt_status_t;
#if (URT_CFG_PUBSUB_ENABLED == true) || defined(__DOXYGEN__)
# if (URT_CFG_PUBSUB_TOPICID_WIDTH == 8)
typedef uint8_t urt_topicid_t;
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 16)
typedef uint16_t urt_topicid_t;
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 32)
typedef uint32_t urt_topicid_t;
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 64)
typedef uint64_t urt_topicid_t;
# else
# error "URT_CFG_PUBSUB_TOPICID_WIDTH must be set to 8, 16, 32 or 64."
# endif
#endif /* URT_CFG_PUBSUB_ENABLED == true */
#if (URT_CFG_RPC_ENABLED == true) || defined(__DOXYGEN__)
# if (URT_CFG_RPC_SERVICEID_WIDTH == 8)
typedef uint8_t urt_serviced_t;
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 16)
typedef uint16_t urt_serviced_t;
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 32)
typedef uint32_t urt_serviced_t;
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 64)
typedef uint64_t urt_serviced_t;
# else
# error "URT_CFG_RPC_SERVICEID_WIDTH must be set to 8, 16, 32 or 64."
# endif
#endif /* URT_CFG_RPC_ENABLED == true */
/**
* @brief Usefulness calculation function type.
*
* @param[in] dt Delay to calculate the usefulness for.
* @param[in] param Pointer to optional parameters (may be NULL).
*
* return The usefulness (of some data) after the specified delay as value in range [0, 1].
*/
typedef float (*urt_usefulness_f)(urt_delay_t dt, void* params);
/*============================================================================*/
/* MACROS */
/*============================================================================*/
/*============================================================================*/
/* EXTERN DECLARATIONS */
/*============================================================================*/
/*============================================================================*/
/* INLINE FUNCTIONS */
/*============================================================================*/
#endif /* URT_PRIMITIVES_H */