Statistics
| Branch: | Revision:

urtware / urt_osal.h @ 6882b76c

History | View | Annotate | Download (29.595 KB)

1 46471486 Thomas Schöpping
/*
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_OSAL_H
23
#define URT_OSAL_H
24
25
#include <urtware.h>
26
27
/*============================================================================*/
28
/* VERSION                                                                    */
29
/*============================================================================*/
30
31
/**
32
 * @brief   The µRtWare operating system abstraction layer interface major version.
33
 * @note    Changes of the major version imply incompatibilities.
34
 */
35
#define URT_OSAL_VERSION_MAJOR                  0
36
37
/**
38
 * @brief   The µRtWare operating system abstraction layer interface minor version.
39
 * @note    A higher minor version implies new functionalty, but all old interfaces are still available.
40
 */
41
#define URT_OSAL_VERSION_MINOR                  1
42
43
/*============================================================================*/
44
/* DEPENDENCIES                                                               */
45
/*============================================================================*/
46
47
#include <stdint.h>
48
49
/*============================================================================*/
50
/* DEBUG                                                                      */
51
/*============================================================================*/
52
53
#if defined(__cplusplus)
54
extern "C" {
55
#endif /* defined(__cplusplus) */
56
57
#if !defined(urtDebugAssert) || defined(__DOXYGEN__)
58
  /**
59
   * @brief Assert function to check a given condition.
60
   *
61
   * @param[in] condition   The condition to check.
62
   */
63
  void urtDebugAssert(const bool condition);
64
#endif /* !defined(urtDebugAssert) */
65
66
#if defined(__cplusplus)
67
}
68
#endif /* defined(__cplusplus) */
69
70
/*============================================================================*/
71
/* MUTEX                                                                      */
72
/*============================================================================*/
73
74
/*
75
 * The following type must be defined by the implementation:
76
 *
77
 * urt_osMutex_t
78
 *    Type to represent a mutex lock object.
79
 *    Is only used via pointers by the API.
80
 */
81
82
#if defined(__cplusplus)
83
extern "C" {
84
#endif /* defined(__cplusplus) */
85
86
#if !defined(urtMutexInit) || defined(__DOXYGEN__)
87
  /**
88
   * @brief   Initialize a mutex lock object.
89
   *
90
   * @param[in] mutex   Pointer to the mutex lock object to initialize.
91
   *                    Must not be NULL.
92
   */
93
  void urtMutexInit(urt_osMutex_t* mutex);
94
#endif /* !defined(urtMutexInit) */
95
96
#if !defined(urtMutexLock) || defined(__DOXYGEN__)
97
  /**
98
   * @brief   Lock a mutex lock.
99
   * @details The calling thread is blocked until the mutex lock could be acquired.
100
   *
101
   * @param[in] mutex   Pointer to the mutex lock to acquire.
102
   *                    Must not be NULL.
103
   */
104
  void urtMutexLock(urt_osMutex_t* mutex);
105
#endif /* !defined(urtMutexLock) */
106
107
#if !defined(urtMutexTryLock) || defined(__DOXYGEN__)
108
  /**
109
   * @brief   Try to lock a mutex lock.
110
   * @details This function does not block but returns immediately.
111
   *
112
   * @param[in] mutex   Pointer to the mutex lock to acquire.
113
   *
114
   * @return  Indicator whether the lock was acquired.
115
   * @retval true   The lock was acquired successfully.
116
   * @retval false  The lock could not be acquired.
117
   */
118
  bool urtMutexTryLock(urt_osMutex_t* mutex);
119
#endif /* !defined(urtMutexTryLock) */
120
121
#if !defined(urtMutexUnlock) || defined(__DOXYGEN__)
122
  /**
123
   * @brief   Unlock an owned mutex lock.
124
   *
125
   * @param[in] mutex   Pointer to the mutex lock to unlock.
126
   *                    Must not be NULL.
127
   */
128
  void urtMutexUnlock(urt_osMutex_t* mutex);
129
#endif /* !defined(urtMutexUnlock) */
130
131
#if defined(__cplusplus)
132
}
133
#endif /* defined(__cplusplus) */
134
135
/*============================================================================*/
136
/* CONDITION VARIABLE                                                         */
137
/*============================================================================*/
138
139
/*
140
 * The following type must be defined by the implementation:
141
 *
142
 * urt_osCondvar_t
143
 *    Type to represent a condition variable object.
144
 *    Is only used via pointers by the API.
145
 */
146
147
/**
148
 * @brief   Status type of condition variables.
149
 */
150
typedef enum {
151
  URT_CONDVAR_WAITSTATUS_SIGNAL = 1,    /**< The condition variable has been signaled individually. */
152
  URT_CONDVAR_WAITSTATUS_BROADCAST = 2, /**< The condition variable has been signal via broadcast. */
153
  URT_CONDVAR_WAITSTATUS_TIMEOUT = 0,   /**< Waiting for the condition variable timed out. */
154
} urt_osCondvarWaitStatus_t;
155
156
#if defined(__cplusplus)
157
extern "C" {
158
#endif /* defined(__cplusplus) */
159
160
#if !defined(urtCondvarInit) || defined(__DOXYGEN__)
161
  /**
162
   * @brief   Initialize a condition variable object.
163
   *
164
   * @param[in] condvar   Pointer to the object to initialize.
165
   *                      Must not be NULL.
166
   */
167
  void urtCondvarInit(urt_osCondvar_t* condvar);
168
#endif /* !defined(urtCondvarInit) */
169
170
#if !defined(urtCondvarSignal) || defined(__DOXYGEN__)
171
  /**
172
   * @brief   Signal a condition variable (wake one waiting thread).
173
   *
174
   * @param[in] condvar   Pointer to the condition variable to signal.
175
   *                      Must not be NULL.
176
   */
177
  void urtCondvarSignal(urt_osCondvar_t* condvar);
178
#endif /* !defined(urtCondvarSignal) */
179
180
#if !defined(urtCondvarBroadcast) || defined(__DOXYGEN__)
181
  /**
182
   * @brief   Signal a condition variable via broadcast (wake all waiting threads).
183
   *
184
   * @param[in] condvar   Pointer to the condition variable to signal via broadcast.
185
   *                      Must not be NULL.
186
   */
187
  void urtCondvarBroadcast(urt_osCondvar_t* condvar);
188
#endif /* !defined(urtCondvarBroadcast) */
189
190 0de5bed8 Thomas Schöpping
#if (!defined(urtCondvarWait) && (URT_CFG_OSAL_CONDVAR_TIMEOUT == true)) || defined(__DOXYGEN__)
191 46471486 Thomas Schöpping
  /**
192
   * @brief   Wait for a condition variable to be signaled or timeout.
193
   *
194
   * @param[in] condvar   Pointer to the condition variabel to wait for.
195
   *                      Must not be NULL.
196
   * @param[in] mutex     Pointer to the associated mutex lock.
197
   *                      Must not be NULL.
198
   *                      Mutex must be acquired when this function is called.
199
   * @param[in] timeout   Timeout (in microseconds) when the function will return even without the condition variable being signaled.
200
   *                      Use URT_DELAY_INFINITE to deactivate timeout.
201
   * @return
202
   */
203
  urt_osCondvarWaitStatus_t urtCondvarWait(urt_osCondvar_t* condvar, urt_osMutex_t* mutex, urt_delay_t timeout);
204 0de5bed8 Thomas Schöpping
#else /* !defined(urtCondvarWait) && (URT_CFG_OSAL_CONDVAR_TIMEOUT == true) */
205
  urt_osCondvarWaitStatus_t urtCondvarWait(urt_osCondvar_t* condvar, urt_osMutex_t* mutex);
206
#endif /* !defined(urtCondvarWait) && (URT_CFG_OSAL_CONDVAR_TIMEOUT == true) */
207 46471486 Thomas Schöpping
208
#if defined(__cplusplus)
209
}
210
#endif /* defined(__cplusplus) */
211
212
/*============================================================================*/
213
/* EVENTS                                                                     */
214
/*============================================================================*/
215
216
/*
217
 * The following types and constants must be defined by the implementation:
218
 *
219
 * urt_osEventSource_t
220
 *    Type to represent an event source object.
221
 *    Is only used via pointers by the API.
222
 *
223
 * urt_osEventListener_t
224
 *    Type to represent an event listener object.
225
 *    Is only used via pointers by the API.
226
 *
227
 * urt_osEventMask_t
228
 *    Integer type to represent event masks.
229
 *
230
 * urt_osEventFlags_t
231
 *    Integer type to represent event flags.
232
 *
233
 * URT_EVENTMASK_MAXPRIO
234
 *    Constant of type urt_osEventMask_t to specify the event mask that is
235
 *    handled with maximum priority.
236
 *    This constant is typically either 0x0..1 (low values have high priority)
237
 *    or 0x8..0 (high values have high priority).
238
 *    A value of 0 indicates that priorities are not supported.
239 4ea18a07 Svenja
 *
240
 * URT_EVENTMASK_ALL
241
 *    Constant of type urt_osEventMask_t to filter no events at all.
242
 *    Typically is 0xF..F.
243 46471486 Thomas Schöpping
 */
244
245
/**