blob: 63fda44787fbd09c74306108a6d3462e95d32b1d [file] [log] [blame]
brians343bc112013-02-10 01:53:46 +00001#include "aos/common/logging/logging.h"
2#include "aos/common/control_loop/Timing.h"
3
4#include "aos/common/time.h"
5
6namespace aos {
7namespace time {
8
9void PhasedLoopXMS(int ms, int offset) {
10 // TODO(brians): Rewrite this cleaner.
11 // TODO(brians): Tests!
12 int64_t period_nsec = Time::InMS(ms).nsec();
13 SleepUntil(Time::InNS((Time::Now().ToNSec() / period_nsec +
14 static_cast<int64_t>(1)) * period_nsec +
15 Time::InUS(offset).ToNSec()));
16}
17
18} // namespace timing
19} // namespace aos