mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/rtos2-utils.git
synced 2025-06-10 18:15:59 +00:00
Added periodic timers
This commit is contained in:
parent
1877c82f37
commit
dcc647a062
@ -10,6 +10,7 @@
|
||||
#include <sta/timer.hpp>
|
||||
|
||||
#include <functional>
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
|
||||
namespace sta
|
||||
@ -30,7 +31,7 @@ namespace sta
|
||||
* @param callback The callback function to call upon timer timeout.
|
||||
* @param arg The argument to pass to the callback function.
|
||||
*/
|
||||
RtosTimer(std::function<void(void*)>, void *arg);
|
||||
RtosTimer(std::function<void(void*)>, void *arg, osTimerType_t type = osTimerOnce);
|
||||
|
||||
/**
|
||||
* @brief Initializes the timer with a callback that has no effect.
|
||||
|
@ -2,17 +2,18 @@
|
||||
#include <sta/debug/debug.hpp>
|
||||
#include <sta/debug/assert.hpp>
|
||||
|
||||
#include "cmsis_os2.h"
|
||||
|
||||
namespace sta {
|
||||
RtosTimer::RtosTimer(std::function<void(void*)> callback, void *arg)
|
||||
RtosTimer::RtosTimer(std::function<void(void*)> callback, void *arg, osTimerType_t type /*= osTimerOnce */)
|
||||
: timer_id_{NULL},
|
||||
timer_attr_{.name="Timer", .attr_bits=osTimerOnce},
|
||||
timer_attr_{.name="Timer", .attr_bits=type},
|
||||
callback_{callback},
|
||||
callbackArg_{arg},
|
||||
running_{false}
|
||||
{
|
||||
// Pass an anonymous function as the callback which will invoke the currently registered callback.
|
||||
timer_id_ = osTimerNew(timeoutHandler, osTimerOnce, this, &timer_attr_);
|
||||
// Pass an anonymous function as the callback which will invoke the currently registered callback.
|
||||
timer_id_ = osTimerNew(timeoutHandler, type, this, &timer_attr_);
|
||||
|
||||
STA_ASSERT_MSG(timer_id_ != NULL, "Failed to create timer!");
|
||||
}
|
||||
@ -68,7 +69,7 @@ namespace sta {
|
||||
void RtosTimer::timeoutHandler(void* arg)
|
||||
{
|
||||
RtosTimer* timer = static_cast<RtosTimer*>(arg);
|
||||
timer->running_ = false;
|
||||
timer->running_ = timer->isRunning();
|
||||
timer->callback_(timer->callbackArg_);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user