16 typedef SYSUTM time_type;
17 typedef ER error_type;
24 m_error = get_utm(&m_last_value);
28 time_type operator()() {
return value(); }
30 operator bool()
const {
return is_ok(); }
32 bool is_ok()
const {
return m_error == E_OK; }
34 error_type error()
const {
return m_error; }
37 error_type e = m_error;
42 time_type m_last_value;
46 template <
typename Timer>
47 void wait(Timer & timer,
typename Timer::time_type time) {
48 typename Timer::time_type base = timer.value();
50 typename Timer::time_type new_base = timer.value();
51 typename Timer::time_type difference = new_base - base;
52 if (time < difference)
60 template <
typename Timer,
typename Process>
61 void wait(Timer & timer,
typename Timer::time_type time, Process process) {
62 typename Timer::time_type base = timer.value();
64 typename Timer::time_type new_base = timer.value();
65 typename Timer::time_type difference = new_base - base;
66 if (time < difference)
75 template <
typename Timer,
typename Process>
76 typename Timer::time_type wait(Timer & timer,
typename Timer::time_type time, Process process,
int) {
77 typename Timer::time_type base = timer.value();
81 return timer.value() - base;
84 typename Timer::time_type base_time = base;
86 typename Timer::time_type new_base = timer.value();
87 typename Timer::time_type difference = new_base - base;
88 if (time < difference)
93 typename Timer::time_type res = timer.value() - base_time;
94 return res == 0 ? 1 : res;
101 template <
typename Timer>
105 typedef typename Timer::time_type time_type;
108 : m_timer(0), m_running(
false)
112 : m_timer(&timer), m_running(
true)
117 void init(Timer & timer) {
120 m_base = m_timer->value();
123 void init_stopped(Timer & timer) {
131 m_base = m_timer->value();
136 bool running()
const {
147 m_base = m_timer->value();
152 m_base = m_timer->value() - m_base;
159 m_base = m_timer->value() - m_base;
164 time_type operator()()
const {
return this->
get(); }
166 time_type
get()
const {
168 return m_timer->value() - m_base;
173 void set(time_type value) {
175 m_base = m_timer->value() - value;
180 void decrease(time_type time) {
189 volatile bool m_running;
190 volatile time_type m_base;
193 template <
typename Timer>
199 typedef typename base_type::time_type time_type;
208 void init(Timer & timer, time_type timeout) {
213 void init_stopped(Timer & timer, time_type timeout) {
219 this->
set(m_timeout + 1);
223 this->decrease(m_timeout);
226 operator bool()
const {
return (*
this)() > m_timeout; }
228 void set_timeout(
const time_type & value) {
232 time_type get_timeout()
const {
return m_timeout; }
234 void reset(
const time_type & new_timeout) {
236 m_timeout = new_timeout;
239 time_type remaining()
const {
return *
this ? 0 : (m_timeout - (*this)()); }
242 volatile time_type m_timeout;
269 void reset(
const bool& start =
true)
291 Timeout(detail::timeout<detail::us_counter_t>::time_type timeout)
297 extern void wait(detail::us_counter_t::time_type time);
299 template <
typename Process>
300 void wait(detail::us_counter_t::time_type time, Process process)
302 detail::wait(detail::us_counter, time, process);
305 template <
typename Process>
306 void wait(detail::us_counter_t::time_type time, Process process,
int)
308 detail::wait(detail::us_counter, time, process, 0);
311 extern void delayMs(
const unsigned int& ms);
312 extern void delayUs(
const unsigned int& us);
314 extern detail::us_counter_t::time_type usec(detail::us_counter_t::time_type t);
315 extern detail::us_counter_t::time_type msec(detail::us_counter_t::time_type t);
316 extern detail::us_counter_t::time_type sec(detail::us_counter_t::time_type t);