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