mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-12 02:36:00 +00:00
33 lines
927 B
C++
33 lines
927 B
C++
#include <sta/rtos/timer.hpp>
|
|
#include <sta/debug/debug.hpp>
|
|
#include <sta/debug/assert.hpp>
|
|
|
|
namespace sta {
|
|
RtosTimer::RtosTimer(){}
|
|
|
|
RtosTimer::RtosTimer(void (*callback)(void *arg), void *arg) {
|
|
timer_attr_.name = "Timer";
|
|
timer_attr_.attr_bits = osTimerOnce;
|
|
timer_attr_.cb_size = sizeof(osTimerAttr_t);
|
|
|
|
timer_id_ = osTimerNew(callback, osTimerOnce, arg, &timer_attr_);
|
|
STA_ASSERT_MSG(timer_id_ != 0, "Failed to initialize timer");
|
|
}
|
|
|
|
RtosTimer::~RtosTimer() {
|
|
osTimerDelete(timer_id_);
|
|
}
|
|
|
|
void RtosTimer::start(uint32_t millis) {
|
|
osStatus_t status = osTimerStart(timer_id_, millis);
|
|
|
|
if (status != osOK) STA_DEBUG_PRINTLN("Timer start failed");
|
|
}
|
|
|
|
void RtosTimer::stop() {
|
|
osStatus_t status = osTimerStop(timer_id_);
|
|
|
|
if (status != osOK) STA_DEBUG_PRINTLN("Timer stop failed");
|
|
}
|
|
} // namespace sta
|