Statistics
| Branch: | Tag: | Revision:

amiro-os / core / inc / aos_thread.h @ 3689c350

History | View | Annotate | Download (5.381 KB)

1 e545e620 Thomas Schöpping
/*
2
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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 53710ca3 Marc Rothmann
/**
20
 * @file    aos_thread.h
21
 * @brief   Thread macros and inline functions.
22
 *
23
 * @addtogroup aos_threads
24
 * @{
25
 */
26
27 e545e620 Thomas Schöpping
#ifndef _AMIROOS_THREAD_H_
28
#define _AMIROOS_THREAD_H_
29
30
#include <aos_time.h>
31
#include <aos_system.h>
32
33
/**
34
 * @brief   Minimum thread priority.
35
 */
36 1e5f7648 Thomas Schöpping
#define AOS_THD_LOWPRIO_MIN           ((tprio_t)(LOWPRIO))
37 e545e620 Thomas Schöpping
38
/**
39
 * @brief   Maximum priority for background threads.
40
 */
41 1e5f7648 Thomas Schöpping
#define AOS_THD_LOWPRIO_MAX           ((tprio_t)(LOWPRIO + ((NORMALPRIO - LOWPRIO) / 2)))
42 e545e620 Thomas Schöpping
43
/**
44
 * @brief   Minimum priority for normal/standard threads.
45
 */
46 1e5f7648 Thomas Schöpping
#define AOS_THD_NORMALPRIO_MIN        ((tprio_t)(AOS_THD_LOWPRIO_MAX + 1))
47 e545e620 Thomas Schöpping
48
/**
49
 * @brief   Maximum priority for normal/standard threads.
50
 */
51 1e5f7648 Thomas Schöpping
#define AOS_THD_NORMALPRIO_MAX        ((tprio_t)(NORMALPRIO))
52 e545e620 Thomas Schöpping
53
/**
54
 * @brief   Minimum priority for important threads.
55
 */
56 1e5f7648 Thomas Schöpping
#define AOS_THD_HIGHPRIO_MIN          ((tprio_t)(NORMALPRIO + 1))
57 e545e620 Thomas Schöpping
58
/**
59
 * @brief   Maximum priority for important threads.
60
 */
61 1e5f7648 Thomas Schöpping
#define AOS_THD_HIGHPRIO_MAX          ((tprio_t)(NORMALPRIO + ((HIGHPRIO - NORMALPRIO) / 2)))
62 e545e620 Thomas Schöpping
63
/**
64
 * @brief   Minimum priority for real-time threads.
65
 */
66 1e5f7648 Thomas Schöpping
#define AOS_THD_RTPRIO_MIN            ((tprio_t)(AOS_THD_HIGHPRIO_MAX + 1))
67 e545e620 Thomas Schöpping
68
/**
69
 * @brief   Maximum priority for real-time threads.
70
 */
71 1e5f7648 Thomas Schöpping
#define AOS_THD_RTPRIO_MAX            ((tprio_t)(HIGHPRIO - 1))
72 e545e620 Thomas Schöpping
73
/**
74
 * @brief   Priority for the system control thread.
75
 */
76 1e5f7648 Thomas Schöpping
#define AOS_THD_CTRLPRIO              ((tprio_t)(HIGHPRIO))
77 e545e620 Thomas Schöpping
78
/**
79
 * @brief   Maximum timeframe that can be slept in system ticks.
80
 */
81 1e5f7648 Thomas Schöpping
#define AOS_THD_MAX_SLEEP_ST          TIME_MAX_INTERVAL
82 e545e620 Thomas Schöpping
83
/**
84
 * @brief   Maximum timeframe that can be slept in seconds.
85
 */
86 1e5f7648 Thomas Schöpping
#define AOS_THD_MAX_SLEEP_S           (chTimeI2S(AOS_THD_MAX_SLEEP_ST) - 1)
87 e545e620 Thomas Schöpping
88
/**
89
 * @brief   Maximum timeframe that can be slept in milliseconds.
90
 */
91 1e5f7648 Thomas Schöpping
#define AOS_THD_MAX_SLEEP_MS          (chTimeI2MS(AOS_THD_MAX_SLEEP_ST) - 1)
92 e545e620 Thomas Schöpping
93
/**
94
 * @brief   Maximum timeframe that can be slept in microseconds.
95
 */
96 1e5f7648 Thomas Schöpping
#define AOS_THD_MAX_SLEEP_US          (chTimeI2US(AOS_THD_MAX_SLEEP_ST) - 1)
97 e545e620 Thomas Schöpping
98
#ifdef __cplusplus
99
extern "C" {
100
#endif
101
  void aosThdSleepUntilS(const aos_timestamp_t* t);
102
#ifdef __cplusplus
103
}
104
#endif
105
106
/**
107
 * @brief   Lets the calling thread sleep the specified amount of microseconds.
108
 *
109
 * @param[in] us    Time to sleep in microseconds.
110
 */
111
static inline void aosThdUSleepS(const aos_interval_t us)
112
{
113
  aos_timestamp_t ut;
114
115
  aosSysGetUptimeX(&ut);
116
  ut += us;
117
  aosThdSleepUntilS(&ut);
118
119
  return;
120
}
121
122
/**
123
 * @brief   Lets the calling thread sleep the specified amount of milliseconds.
124
 *
125
 * @param[in] ms    Time to sleep in milliseconds.
126
 */
127
static inline void aosThdMSleepS(const uint32_t ms)
128
{
129
  aos_timestamp_t ut;
130
131
  aosSysGetUptimeX(&ut);
132
  ut += (aos_timestamp_t)ms * MICROSECONDS_PER_MILLISECOND;
133
  aosThdSleepUntilS(&ut);
134
135
  return;
136
}
137
138
/**
139
 * @brief   Lets the calling thread sleep the specified amount of seconds.
140
 *
141
 * @param[in] s     Time to sleep in seconds.
142
 */
143
static inline void aosThdSSleepS(const uint32_t s)
144
{
145
  aos_timestamp_t ut;
146
147
  aosSysGetUptimeX(&ut);
148
  ut += (aos_timestamp_t)s * MICROSECONDS_PER_SECOND;
149
  aosThdSleepUntilS(&ut);
150
151
  return;
152
}
153
154
/**
155
 * @brief   Lets the calling thread sleep the specified amount of seconds.
156
 *
157
 * @param[in] s     Time to sleep in seconds.
158
 */
159
static inline void aosThdSleepS(const float s)
160
{
161
  aos_timestamp_t ut;
162
163
  aosSysGetUptimeX(&ut);
164
  ut += (aos_timestamp_t)(s * MICROSECONDS_PER_SECOND);
165
  aosThdSleepUntilS(&ut);
166
167
  return;
168
}
169
170
/**
171
 * @brief   Lets the calling thread sleep the specified amount of microseconds.
172
 *
173
 * @param[in] us    Time to sleep in microseconds.
174
 */
175
static inline void aosThdUSleep(const uint32_t us)
176
{
177
  chSysLock();
178
  aosThdUSleepS(us);
179
  chSysUnlock();
180
181
  return;
182
}
183
184
/**
185
 * @brief   Lets the calling thread sleep the specified amount of milliseconds.
186
 *
187
 * @param[in] ms    Time to sleep in milliseconds.
188
 */
189
static inline void aosThdMSleep(const uint32_t ms)
190
{
191
  chSysLock();
192
  aosThdMSleepS(ms);
193
  chSysUnlock();
194
195
  return;
196
}
197
198
/**
199
 * @brief   Lets the calling thread sleep the specified amount of seconds.
200
 *
201
 * @param[in] s     Time to sleep in seconds.
202
 */
203
static inline void aosThdSSleep(const uint32_t s)
204
{
205
  chSysLock();
206
  aosThdSSleepS(s);
207
  chSysUnlock();
208
209
  return;
210
}
211
212
/**
213
 * @brief   Lets the calling thread sleep the specified amount of seconds.
214
 *
215
 * @param[in] s     Time to sleep in seconds.
216
 */
217
static inline void aosThdSleep(const float s)
218
{
219
  chSysLock();
220
  aosThdSleepS(s);
221
  chSysUnlock();
222
223
  return;
224
}
225
226
/**
227
 * @brief   Lets the calling thread sleep until the specifide system uptime.
228
 *
229
 * @param[in] t     Deadline until the thread will sleep.
230
 */
231
static inline void aosThdSleepUntil(const aos_timestamp_t* t)
232
{
233
  chSysLock();
234
  aosThdSleepUntilS(t);
235
  chSysUnlock();
236
237
  return;
238
}
239
240
#endif /* _AMIROOS_THREAD_H_ */
241 53710ca3 Marc Rothmann
242
/** @} */