MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/systemic/Timer.cpp
2024-06-07 11:12:56 +03:00

63 lines
1.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Timer.cpp
*
* Created on: 20 дек. 2017 г.
* Author: titov
*/
#include "Timer.hh"
float systemic::Timer::system_tick_frequency_khz = 0.0f;
systemic::Timer::Timer() : state(off), time_stamp(0ull), time_delay(0ull) {}
void systemic::Timer::start( time_t delay ) {
time_stamp = std::clock();
time_delay = delay * system_tick_frequency_khz;
//todo memory-order
state = active;
}
void systemic::Timer::stop() {
state = off;
}
bool systemic::Timer::delayElapsed() const {
if( state == active
&& ( std::clock() - time_stamp ) >= time_delay ) {
state = elapsed;
}
return state == elapsed;
}
bool systemic::Timer::delayFinished() {
bool result = delayElapsed();
if( result ) stop();
return result;
}
bool systemic::Timer::isActive() const {
return state != off;
}
void systemic::Timer::setSystemTickFrequency( unsigned long frequency ) {
system_tick_frequency_khz = frequency / 1000.0f;
}
systemic::time_t systemic::seconds2time( float time_in_secods ) {
return time_in_secods * 1000.0f;
}
float systemic::time2seconds( time_t time_ ) {
return time_ * 0.001f;
}