Statistics
| Branch: | Revision:

urtware / inc / urt_primitives.h @ fb72e91b

History | View | Annotate | Download (6.79 KB)

1
/*
2
µRtWare is a lightweight publish/subscribe middleware for real-time
3
applications. It was developed as part of the software habitat for the
4
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
5

6
Copyright (C) 2018..2020  Thomas Schöpping et al.
7

8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12

13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17

18
You should have received a copy of the GNU General Public License
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21

    
22
#ifndef URT_PRIMITIVES_H
23
#define URT_PRIMITIVES_H
24

    
25
#include <urtware.h>
26
#include <stdint.h>
27

    
28
/*============================================================================*/
29
/* CONSTANTS                                                                  */
30
/*============================================================================*/
31

    
32
/**
33
 * @brief Special constant value for immediate (nonexistent) delays.
34
 */
35
#define URT_DELAY_IMMEDIATE                     (urt_delay_t)0
36

    
37
/**
38
 * @brief Special constant value for infinite delays.
39
 */
40
#define URT_DELAY_INFINITE                      (urt_delay_t)~0
41

    
42
/*============================================================================*/
43
/* SETTINGS                                                                   */
44
/*============================================================================*/
45

    
46
/*============================================================================*/
47
/* CHECKS                                                                     */
48
/*============================================================================*/
49

    
50
/*============================================================================*/
51
/* DATA STRUCTURES AND TYPES                                                  */
52
/*============================================================================*/
53

    
54
/**
55
 * @brief   Type for temporal delays (in microseconds).
56
 */
57
#if (URT_CFG_DELAY_WIDTH == 32)
58
  typedef uint32_t urt_delay_t;
59
#elif (URT_CFG_DELAY_WIDTH == 64)
60
  typedef uint64_t urt_delay_t;
61
#else
62
# error "URT_CFG_DELAY_WIDTH must be set to 32 or 64."
63
#endif
64

    
65
/**
66
 * @brief   Type to use for the node stage value.
67
 * @details Use wide types only if you need to synchronize the system very often.
68
 */
69
#if (URT_CFG_NODESTAGE_WIDTH == 8)
70
  typedef uint8_t urt_nodestage_t;
71
#elif (URT_CFG_NODESTAGE_WIDTH == 16)
72
  typedef uint16_t urt_nodestage_t;
73
#elif (URT_CFG_NODESTAGE_WIDTH == 32)
74
  typedef uint32_t urt_nodestage_t;
75
#elif (URT_CFG_NODESTAGE_WIDTH == 64)
76
  typedef uint64_t urt_nodestage_t;
77
#else
78
# error "URT_CFG_NODESTAGE_WIDTH must be set to 8, 16, 32 or 64."
79
#endif
80

    
81
/**
82
 * @brief   General status type used throughout µRtWare and its interfaces.
83
 */
84
typedef enum {
85
  URT_STATUS_OK = 0,              /**< Status indicating success. */
86
  URT_STATUS_DEADLINEVIOLATION,   /**< Status indicating a violated deadline. */
87
  URT_STATUS_JITTERVIOLATION,     /**< Status indicating a violated jitter requirement. */
88
  URT_STATUS_RATEVIOLATION,       /**< Status indicating a violated rate requirement. */
89
  URT_STATUS_SYNC_PENDING,        /**< Status indicating a synchronization barrier. */
90
  URT_STATUS_SYNC_ERROR,          /**< Status indicating a failed synchronization. */
91
  URT_STATUS_NODE_INVALEVTMASK,   /**< Status indicating an invalid event mask. */
92
#if (URT_CFG_PUBSUB_ENABLED == true) || defined(__DOXYGEN__)
93
  URT_STATUS_TOPIC_DUPLICATE,     /**< Status indicating multiple use of the same topic ID. */
94
  URT_STATUS_PUBLISH_TIMEOUT,     /**< Status indicating a timeout when publishinh a message. */
95
  URT_STATUS_SUBSCRIBE_TOPICSET,  /**< Status indicating that the subscriber is already associated to a topic. */
96
  URT_STATUS_FETCH_NOTOPIC,       /**< Status indicating that the subscriber is not associated to any topic. */
97
  URT_STATUS_FETCH_NOMESSAGE,     /**< Status indicating that no message could be fetched. */
98
  URT_STATUS_UNSUBSCRIBE_NOTOPIC, /**< Status indicating that the subscriber is not associated to an topic. */
99
#endif /* URT_CFG_PUBSUB_ENABLED == true */
100
#if (URT_CFG_RPC_ENABLED == true) || defined(__DOXYGEN__)
101
  URT_STATUS_SERVICE_DUPLICATE,   /**< Status indicating multiple use of the same service ID. */
102
  URT_STATUS_REQUEST_BADOWNER,    /**< Status indicating that a request is currently owned by another component. */
103
  URT_STATUS_REQUEST_LOCKED,      /**< Status indicating a currently locked request. */
104
#endif /* URT_CFG_RPC_ENABLED == true */
105
} urt_status_t;
106

    
107
#if (URT_CFG_PUBSUB_ENABLED == true) || defined(__DOXYGEN__)
108
# if (URT_CFG_PUBSUB_TOPICID_WIDTH == 8)
109
    typedef uint8_t urt_topicid_t;
110
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 16)
111
    typedef uint16_t urt_topicid_t;
112
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 32)
113
    typedef uint32_t urt_topicid_t;
114
# elif (URT_CFG_PUBSUB_TOPICID_WIDTH == 64)
115
    typedef uint64_t urt_topicid_t;
116
# else
117
#   error "URT_CFG_PUBSUB_TOPICID_WIDTH must be set to 8, 16, 32 or 64."
118
# endif
119
#endif /* URT_CFG_PUBSUB_ENABLED == true */
120

    
121
#if (URT_CFG_RPC_ENABLED == true) || defined(__DOXYGEN__)
122
# if (URT_CFG_RPC_SERVICEID_WIDTH == 8)
123
    typedef uint8_t urt_serviced_t;
124
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 16)
125
    typedef uint16_t urt_serviced_t;
126
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 32)
127
    typedef uint32_t urt_serviced_t;
128
# elif (URT_CFG_RPC_SERVICEID_WIDTH == 64)
129
    typedef uint64_t urt_serviced_t;
130
# else
131
#   error "URT_CFG_RPC_SERVICEID_WIDTH must be set to 8, 16, 32 or 64."
132
# endif
133
#endif /* URT_CFG_RPC_ENABLED == true */
134

    
135
/**
136
 * @brief   Usefulness calculation function type.
137
 *
138
 * @param[in] dt  Delay to calculate the usefulness for.
139
 * @param[in] param Pointer to optional parameters (may be NULL).
140
 *
141
 * return   The usefulness (of some data) after the specified delay as value in range [0, 1].
142
 */
143
typedef float (*urt_usefulness_f)(urt_delay_t dt, void* params);
144

    
145
/*============================================================================*/
146
/* MACROS                                                                     */
147
/*============================================================================*/
148

    
149
/*============================================================================*/
150
/* EXTERN DECLARATIONS                                                        */
151
/*============================================================================*/
152

    
153
/*============================================================================*/
154
/* INLINE FUNCTIONS                                                           */
155
/*============================================================================*/
156

    
157
#endif /* URT_PRIMITIVES_H */