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