amiro-os / core / src / aos_thread.c @ b309b751
History | View | Annotate | Download (1.59 KB)
1 |
/*
|
---|---|
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 |
/**
|
20 |
* @file aos_thread.c
|
21 |
* @brief Thread code.
|
22 |
*
|
23 |
* @addtogroup aos_threads
|
24 |
* @{
|
25 |
*/
|
26 |
|
27 |
#include <aos_thread.h> |
28 |
|
29 |
/**
|
30 |
* @brief Lets the calling thread sleep until the specifide system uptime.
|
31 |
*
|
32 |
* @param[in] t Deadline until the thread will sleep.
|
33 |
*/
|
34 |
void aosThdSleepUntilS(const aos_timestamp_t* t) |
35 |
{ |
36 |
aosDbgCheck(t != NULL);
|
37 |
|
38 |
aos_timestamp_t uptime; |
39 |
|
40 |
// get the current system uptime
|
41 |
aosSysGetUptimeX(&uptime); |
42 |
|
43 |
// while the remaining time is too long, it must be split into multiple sleeps
|
44 |
while ( (*t > uptime) && ((*t - uptime) > AOS_THD_MAX_SLEEP_US) ) {
|
45 |
chThdSleepS(chTimeUS2I(AOS_THD_MAX_SLEEP_US)); |
46 |
aosSysGetUptimeX(&uptime); |
47 |
} |
48 |
|
49 |
// sleep the remaining time
|
50 |
if (*t > uptime) {
|
51 |
sysinterval_t rest = chTimeUS2I(*t - uptime); |
52 |
if (rest > TIME_IMMEDIATE) {
|
53 |
chThdSleepS(rest); |
54 |
} |
55 |
} |
56 |
|
57 |
return;
|
58 |
} |
59 |
|
60 |
/** @} */
|