Statistics
| Branch: | Tag: | Revision:

amiro-os / os / core / src / aos_thread.c @ e545e620

History | View | Annotate | Download (1.46 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
#include <aos_thread.h>
20

    
21
/**
22
 * @brief   Lets the calling thread sleep until the specifide system uptime.
23
 *
24
 * @param[in] t     Deadline until the thread will sleep.
25
 */
26
void aosThdSleepUntilS(const aos_timestamp_t* t)
27
{
28
  aosDbgCheck(t != NULL);
29

    
30
  aos_timestamp_t uptime;
31

    
32
  // get the current system uptime
33
  aosSysGetUptimeX(&uptime);
34

    
35
  // while the remaining time is too long, it must be split into multiple sleeps
36
  while ( (*t > uptime) && ((*t - uptime) > THD_MAX_SLEEP_US) ) {
37
    chThdSleepS(US2ST(THD_MAX_SLEEP_US));
38
    aosSysGetUptimeX(&uptime);
39
  }
40

    
41
  // sleep the remaining time
42
  if (*t > uptime) {
43
    systime_t rest = US2ST(*t - uptime);
44
    if (rest > TIME_IMMEDIATE) {
45
      chThdSleepS(rest);
46
    }
47
  }
48

    
49
  return;
50
}