Statistics
| Branch: | Revision:

amiro-apps / middleware / apps_urtosal.h @ 122d81a7

History | View | Annotate | Download (9.404 KB)

1 6d4ba740 Thomas Schöpping
/*
2
AMiRo-Apps is a collection of applications for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2018..2020  Thomas Schöpping et al.
4

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

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

15
You should have received a copy of the GNU General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef APPS_URTOSAL_H
20
#define APPS_URTOSAL_H
21
22
/*============================================================================*/
23
/* DEPENDENCIES                                                               */
24
/*============================================================================*/
25
26
#include <amiroos.h>
27
28
/*============================================================================*/
29
/* DEBUG                                                                      */
30
/*============================================================================*/
31
32
#define urtDebugAssert(condition)               aosDbgAssert(condition)
33
34
/*============================================================================*/
35
/* MUTEX                                                                      */
36
/*============================================================================*/
37
38
/**
39
 * @brief   Mutex lock type.
40
 */
41
typedef mutex_t urt_osMutex_t;
42
43
#define urtMutexInit(mutex)                     chMtxObjectInit(mutex)
44
45
#define urtMutexLock(mutex)                     chMtxLock(mutex)
46
47
#define urtMutexTryLock(mutex)                  chMtxTryLock(mutex)
48
49
#define urtMutexUnlock(mutex)                   chMtxUnlock(mutex)
50
51
/*============================================================================*/
52
/* CONDITION VARIABLE                                                         */
53
/*============================================================================*/
54
55
/**
56
 * @brief   Condition variable type.
57
 */
58
typedef condition_variable_t urt_osCondvar_t;
59
60
#define urtCondvarInit(condvar)                 chCondObjectInit(condvar)
61
62
#define urtCondvarSignal(condvar)               chCondSignal(condvar)
63
64
#define urtCondvarBroadcast condvar)            chCondBroadcast(condvar)
65
66
/*============================================================================*/
67
/* EVENTS                                                                     */
68
/*============================================================================*/
69
70
/**
71
 * @brief   Type representing an event source object.
72
 */
73
typedef event_source_t urt_osEventSource_t;
74
75
/**
76
 * @brief   Type representing an event listener object.
77
 */
78
typedef event_listener_t urt_osEventListener_t;
79
80
/**
81
 * @brief   Type representing event masks.
82
 * @details Event masks can be used to distinguish and filter events.
83
 */
84
typedef eventmask_t urt_osEventMask_t;
85
86
/**
87
 * @brief   Type representing event flags.
88
 * @details Event flags can be used to represent rudimentary metadata or to filter events.
89
 */
90
typedef eventflags_t urt_osEventFlags_t;
91
92
/**
93 db77e6cf skenneweg
 * @brief   Event mask, which is handled with highest priority.
94 6d4ba740 Thomas Schöpping
 */
95
#define URT_EVENTMASK_MAXPRIO                   EVENT_MASK(0)
96
97
#define urtEventSourceInit(source)              chEvtObjectInit(source)
98
99
#define urtEventSourceBroadcast(source, flags)  chEvtBroadcastFlags(source, flags)
100
101
#define urtEventListenerInit(listener)          (void)listener
102
103
#define urtEventListenerGetFlags(listener)      (urt_osEventFlags_t)(listener->flags)
104
105
#define urtEventListenerClearFlags(listener)    (urt_osEventFlags_t)chEvtGetAndClearFlags(listener)
106
107
#define urtEventRegister(source, listener, mask, flags) chEvtRegisterMaskWithFlags(source, listener, mask, flags)
108
109
#define urtEventUnregister(source, listener)    chEvtUnregister(source, listener)
110
111 db77e6cf skenneweg
/**
112
 * @brief    Event flags
113
 */
114
#define URT_EVENTFLAG_TERMINATE                 (urt_osEventFlags_t)1
115
116
#define URT_EVENTFLAG_PROCEED                   (urt_osEventFlags_t)2
117
118 6d4ba740 Thomas Schöpping
/*============================================================================*/
119
/* STREAMS                                                                    */
120
/*============================================================================*/
121
122
#define urtPrintf(fmt, ...)                     aosprintf(fmt, ##__VA_ARGS__)
123
124
#define urtErrPrintf(fmt, ...)                  aosprintf(fmt, ##__VA_ARGS__)
125
126
/*============================================================================*/
127
/* TIME                                                                       */
128
/*============================================================================*/
129
130
/**
131
 * @brief   The urt_osTime_t represents time at an arbitrary precision.
132
 */
133
typedef aos_timestamp_t urt_osTime_t;
134
135
#define urtTime2Us(time)                      (*((urt_osTime_t*)time))
136
137
#define urtTimeAddUs(time, offset)            (*((urt_osTime_t*)time) + offset)
138
139
/*============================================================================*/
140
/* THREAD                                                                     */
141
/*============================================================================*/
142
143
/**
144
 * @brief   Thread object type.
145
 */
146
typedef thread_t urt_osThread_t;
147
148
/**
149
 * @brief   Thread priority data type.
150
 */
151
typedef tprio_t urt_osThreadPrio_t;
152
153
/**
154
 * @brief   Minimum thread priority.
155
 */
156
#define URT_THREAD_PRIO_LOW_MIN                 AOS_THD_LOWPRIO_MIN
157
158
/**
159
 * @brief   Maximum thread priority for low priority class threads.
160
 */
161
#define URT_THREAD_PRIO_LOW_MAX                 AOS_THD_LOWPRIO_MAX
162
163
/**
164
 * @brief   Minimum thread priority for normal priority class threads.
165
 */
166
#define URT_THREAD_PRIO_NORMAL_MIN              AOS_THD_NORMALPRIO_MIN
167
168
/**
169
 * @brief   Maximum thread priority for normal priority class threads.
170
 */
171
#define URT_THREAD_PRIO_NORMAL_MAX              AOS_THD_NORMALPRIO_MAX
172
173
/**
174
 * @brief   Minimum thread priority for high priority class threads.
175
 */
176
#define URT_THREAD_PRIO_HIGH_MIN                AOS_THD_HIGHPRIO_MIN
177
178
/**
179
 * @brief   Maximum thread priority for high priority class threads.
180
 */
181
#define URT_THREAD_PRIO_HIGH_MAX                AOS_THD_HIGHPRIO_MAX
182
183
/**
184
 * @brief   Minimum thread priority for real-time class threads.
185
 */
186
#define URT_THREAD_PRIO_RT_MIN                  AOS_THD_RTPRIO_MIN
187
188
/**
189
 * @brief   maximum thread priority for real-time class threads.
190
 */
191
#define URT_THREAD_PRIO_RT_MAX                  AOS_THD_RTPRIO_MAX
192
193
/**
194
 * @brief   Maximum number of seconds a thread can sleep.
195
 */
196
#define URT_THREAD_SLEEP_MAX                    (float)AOS_THD_MAX_SLEEP_S
197
198
/**
199
 * @brief   Maximum number of seconds a thread can sleep.
200
 */
201
#define URT_THREAD_SSLEEP_MAX                   (unsigned int)AOS_THD_MAX_SLEEP_S
202
203
/**
204
 * @brief   Maximum number of milliseconds a thread can sleep.
205
 */
206
#define URT_THREAD_MSLEEP_MAX                   (unsigned int)AOS_THD_MAX_SLEEP_MS
207
208
/**
209
 * @brief   Maximum number of microseconds a thread can sleep.
210
 */
211
#define URT_THREAD_USLEEP_MAX                   (urt_delay_t)AOS_THD_MAX_SLEEP_US
212
213
/**
214
 * @brief   Macro function to layout a thread memory.
215
 * @details The overall memory required for a thread usually is a combination of the stack and some further data (i.e. the thread object itself).
216
 *          The layout in memory as well as the metadata may differ between kernels and event hardware ports.
217
 *
218
 * @param[in]   varname     The name of the resulting buffer variable.
219
 * @param[in]   stacksize   The size of the thread's stack.
220
 */
221
#define URT_THREAD_MEMORY(varname, stacksize)   THD_WORKING_AREA(varname, stacksize)
222
223
#define urtThreadStart(thread)                  chThdStart(thread)
224
225
#define urtThreadYield()                        chThdYield()
226
227
#define urtThreadGetPriority()                  chThdGetPriorityX()
228
229
#define urtThreadSetPriority(prio) {                                              \
230
  aosDbgCheck(prio >= URT_THREAD_PRIO_LOW_MIN && prio <= URT_THREAD_PRIO_RT_MAX)  \
231
  chThdSetPriority(prio);                                                         \
232
}
233
234
#define urtThreadSleep(seconds)                 aosThdSleep(seconds)
235
236
#define urtThreadSSleep(seconds)                aosThdSSleep(seconds)
237
238
#define urtThreadMSleep(seconds)                aosThdMSleep(seconds)
239
240
#define urtThreadUSleep(seconds)                aosThdUSleep(seconds)
241
242
#define urtThreadSleepUntil(time)               aosThdSleepUntil(time)
243
244
#define urtThreadExit()                         chThdExit(MSG_OK)
245
246
#define urtThreadJoin(thread)                   (void)chThdWait(thread)
247
248
#define urtThreadGetSelf()                      chThdGetSelfX()
249
250
#define urtThreadGetChildren(thread)            (thread->children)
251
252
#define urtThreadGetSibling(thread)             (thread->sibling)
253
254
#define urtThreadGetParent(thread)              (thread->parent)
255
256
/*============================================================================*/
257
/* TIMER                                                                      */
258
/*============================================================================*/
259
260
/**
261
 * @brief   Timer object type.
262
 */
263
typedef aos_timer_t urt_osTimer_t;
264
265
#define urtTimerInit(timer)                     aosTimerInit(timer)
266
267
#define urtTimerReset(timer)                    aosTimerReset(timer)
268
269
#define urtTimerIsArmeed(timer)                 aosTimerIsArmed(timer)
270
271
#endif /* APPS_URTOSAL_H */