skullc-peripherals/Threads/Inc/threads_timer.hpp
2021-06-24 13:15:10 +03:00

55 lines
985 B
C++

/*
* threads_timer.hpp
*
* Created on: Jun 23, 2021
* Author: erki
*/
#ifndef SKULLC_THREADS_TIMER_HPP_
#define SKULLC_THREADS_TIMER_HPP_
#include <cstdint>
#include <tuple>
#include "threads_signal.hpp"
extern "C" {
struct tmrTimerControl;
typedef struct tmrTimerControl* TimerHandle_t;
}
namespace Threads
{
struct TimeoutSignal
{
};
class Timer
{
public:
Timer(Signallable<TimeoutSignal>* signal, const char* name, const std::int32_t period_ms, const bool auto_reload = true);
~Timer();
void setAutoReload(const bool auto_reload);
void setPeriod(const std::int32_t period_ms);
BaseType_t setPeriodFromIsr(const std::int32_t period_ms);
bool start();
bool stop();
std::pair<bool, BaseType_t> startFromIsr();
std::pair<bool, BaseType_t> stopFromIsr();
private:
TimerHandle_t timer_;
Signallable<TimeoutSignal>* signal_;
static void timeoutHandler_(TimerHandle_t timer);
};
}// namespace Threads
#endif /* SKULLC_THREADS_TIMER_HPP_ */