Statistics
| Branch: | Revision:

amiro-apps / middleware / apps_urtosal.h @ 29f22fdb

History | View | Annotate | Download (9.587 KB)

1
/*
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
 * @brief   Event mask, which is handled with highest priority.
94
 */
95
#define URT_EVENTMASK_MAXPRIO                   EVENT_MASK(0)
96

    
97
/**
98
 * @brief   Event mask to select all events,
99
 */
100
#define URT_EVENTMASK_ALL                       ALL_EVENTS
101

    
102
#define urtEventSourceInit(source)              chEvtObjectInit(source)
103

    
104
#define urtEventSourceBroadcast(source, flags)  chEvtBroadcastFlags(source, flags)
105

    
106
#define urtEventListenerInit(listener)          (void)listener
107

    
108
#define urtEventListenerGetFlags(listener)      (urt_osEventFlags_t)(listener->flags)
109

    
110
#define urtEventListenerClearFlags(listener)    (urt_osEventFlags_t)chEvtGetAndClearFlags(listener)
111

    
112
#define urtEventRegister(source, listener, mask, flags) chEvtRegisterMaskWithFlags(source, listener, mask, flags)
113

    
114
#define urtEventUnregister(source, listener)    chEvtUnregister(source, listener)
115

    
116
/**
117
 * @brief    Event flags
118
 */
119
#define URT_EVENTFLAG_TERMINATE                 (urt_osEventFlags_t)1
120

    
121
#define URT_EVENTFLAG_PROCEED                   (urt_osEventFlags_t)2
122

    
123
/*============================================================================*/
124
/* STREAMS                                                                    */
125
/*============================================================================*/
126

    
127
#define urtPrintf(fmt, ...)                     aosprintf(fmt, ##__VA_ARGS__)
128

    
129
#define urtErrPrintf(fmt, ...)                  aosprintf(fmt, ##__VA_ARGS__)
130

    
131
/*============================================================================*/
132
/* TIME                                                                       */
133
/*============================================================================*/
134

    
135
/**
136
 * @brief   The urt_osTime_t represents time at an arbitrary precision.
137
 */
138
typedef aos_timestamp_t urt_osTime_t;
139

    
140
#define urtTime2Us(time)                      (*((urt_osTime_t*)time))
141

    
142
#define urtTimeAddUs(time, offset)            (*((urt_osTime_t*)time) + offset)
143

    
144
/*============================================================================*/
145
/* THREAD                                                                     */
146
/*============================================================================*/
147

    
148
/**
149
 * @brief   Thread object type.
150
 */
151
typedef thread_t urt_osThread_t;
152

    
153
/**
154
 * @brief   Thread priority data type.
155
 */
156
typedef tprio_t urt_osThreadPrio_t;
157

    
158
/**
159
 * @brief   Minimum thread priority.
160
 */
161
#define URT_THREAD_PRIO_LOW_MIN                 AOS_THD_LOWPRIO_MIN
162

    
163
/**
164
 * @brief   Maximum thread priority for low priority class threads.
165
 */
166
#define URT_THREAD_PRIO_LOW_MAX                 AOS_THD_LOWPRIO_MAX
167

    
168
/**
169
 * @brief   Minimum thread priority for normal priority class threads.
170
 */
171
#define URT_THREAD_PRIO_NORMAL_MIN              AOS_THD_NORMALPRIO_MIN
172

    
173
/**
174
 * @brief   Maximum thread priority for normal priority class threads.
175
 */
176
#define URT_THREAD_PRIO_NORMAL_MAX              AOS_THD_NORMALPRIO_MAX
177

    
178
/**
179
 * @brief   Minimum thread priority for high priority class threads.
180
 */
181
#define URT_THREAD_PRIO_HIGH_MIN                AOS_THD_HIGHPRIO_MIN
182

    
183
/**
184
 * @brief   Maximum thread priority for high priority class threads.
185
 */
186
#define URT_THREAD_PRIO_HIGH_MAX                AOS_THD_HIGHPRIO_MAX
187

    
188
/**
189
 * @brief   Minimum thread priority for real-time class threads.
190
 */
191
#define URT_THREAD_PRIO_RT_MIN                  AOS_THD_RTPRIO_MIN
192

    
193
/**
194
 * @brief   maximum thread priority for real-time class threads.
195
 */
196
#define URT_THREAD_PRIO_RT_MAX                  AOS_THD_RTPRIO_MAX
197

    
198
/**
199
 * @brief   Maximum number of seconds a thread can sleep.
200
 */
201
#define URT_THREAD_SLEEP_MAX                    (float)AOS_THD_MAX_SLEEP_S
202

    
203
/**
204
 * @brief   Maximum number of seconds a thread can sleep.
205
 */
206
#define URT_THREAD_SSLEEP_MAX                   (unsigned int)AOS_THD_MAX_SLEEP_S
207

    
208
/**
209
 * @brief   Maximum number of milliseconds a thread can sleep.
210
 */
211
#define URT_THREAD_MSLEEP_MAX                   (unsigned int)AOS_THD_MAX_SLEEP_MS
212

    
213
/**
214
 * @brief   Maximum number of microseconds a thread can sleep.
215
 */
216
#define URT_THREAD_USLEEP_MAX                   (urt_delay_t)AOS_THD_MAX_SLEEP_US
217

    
218
/**
219
 * @brief   Macro function to layout a thread memory.
220
 * @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).
221
 *          The layout in memory as well as the metadata may differ between kernels and event hardware ports.
222
 *
223
 * @param[in]   varname     The name of the resulting buffer variable.
224
 * @param[in]   stacksize   The size of the thread's stack.
225
 */
226
#define URT_THREAD_MEMORY(varname, stacksize)   THD_WORKING_AREA(varname, stacksize)
227

    
228
#define urtThreadStart(thread)                  chThdStart(thread)
229

    
230
#define urtThreadYield()                        chThdYield()
231

    
232
#define urtThreadGetPriority()                  chThdGetPriorityX()
233

    
234
#define urtThreadSetPriority(prio) {                                              \
235
  aosDbgCheck(prio >= URT_THREAD_PRIO_LOW_MIN && prio <= URT_THREAD_PRIO_RT_MAX)  \
236
  chThdSetPriority(prio);                                                         \
237
}
238

    
239
#define urtThreadSleep(seconds)                 aosThdSleep(seconds)
240

    
241
#define urtThreadSSleep(seconds)                aosThdSSleep(seconds)
242

    
243
#define urtThreadMSleep(seconds)                aosThdMSleep(seconds)
244

    
245
#define urtThreadUSleep(seconds)                aosThdUSleep(seconds)
246

    
247
#define urtThreadSleepUntil(time)               aosThdSleepUntil(time)
248

    
249
#define urtThreadExit()                         chThdExit(MSG_OK)
250

    
251
#define urtThreadShouldTerminate()              chThdShouldTerminateX()
252

    
253
#define urtThreadJoin(thread)                   (void)chThdWait(thread)
254

    
255
#define urtThreadGetSelf()                      chThdGetSelfX()
256

    
257
#define urtThreadGetChildren(thread)            (thread->children)
258

    
259
#define urtThreadGetSibling(thread)             (thread->sibling)
260

    
261
#define urtThreadGetParent(thread)              (thread->parent)
262

    
263
/*============================================================================*/
264
/* TIMER                                                                      */
265
/*============================================================================*/
266

    
267
/**
268
 * @brief   Timer object type.
269
 */
270
typedef aos_timer_t urt_osTimer_t;
271

    
272
#define urtTimerInit(timer)                     aosTimerInit(timer)
273

    
274
#define urtTimerReset(timer)                    aosTimerReset(timer)
275

    
276
#define urtTimerIsArmeed(timer)                 aosTimerIsArmed(timer)
277

    
278
#endif /* APPS_URTOSAL_H */