brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #include "aos/common/control_loop/Timing.h" |
| 2 | |
Brian Silverman | f665d69 | 2013-02-17 22:11:39 -0800 | [diff] [blame^] | 3 | #include <string.h> |
| 4 | |
| 5 | #include "aos/common/logging/logging.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 6 | #include "aos/common/time.h" |
| 7 | |
| 8 | namespace aos { |
| 9 | namespace time { |
| 10 | |
| 11 | void 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 |