mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-10 00:25:59 +00:00
Merge pull request 'feat(sync): added periodicDelay function to threads' (#31) from feat/periodicDelay into main
Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/TACOS/pulls/31 Reviewed-by: dario <dario@noreply.git.intern.spaceteamaachen.de>
This commit is contained in:
commit
b53fe2ce00
@ -128,6 +128,14 @@ namespace sta
|
||||
*/
|
||||
void sleep(uint32_t ticks);
|
||||
|
||||
/**
|
||||
* @brief Sleep until next period. Sets itself to WAITING if the watchdog is enabled, preventing
|
||||
* the watchdog from restarting this thread.
|
||||
*
|
||||
* @param frequency
|
||||
*/
|
||||
void periodicDelay(uint32_t frequency);
|
||||
|
||||
#ifdef STA_CAN_BUS_ENABLE
|
||||
/**
|
||||
* @brief Set the ID of the CAN bus this thread is associated with.
|
||||
@ -216,6 +224,7 @@ namespace sta
|
||||
uint32_t canID_;
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
bool terminate_;
|
||||
uint32_t previous_tick_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
@ -31,7 +31,8 @@ namespace sta
|
||||
CAN_queue_{STA_RTOS_CAN_BUS_QUEUE_LENGTH},
|
||||
canID_{0},
|
||||
#endif // STA_CAN_BUS_ENABLE
|
||||
terminate_{false}
|
||||
terminate_{false},
|
||||
previous_tick_{0}
|
||||
{
|
||||
STA_ASSERT(stack_size >= 0);
|
||||
STA_ASSERT(cb_size >= 0);
|
||||
@ -110,6 +111,25 @@ namespace sta
|
||||
|
||||
osDelay(ticks);
|
||||
|
||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||
heartbeat();
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
}
|
||||
|
||||
void TacosThread::periodicDelay(uint32_t frequency){
|
||||
if (previous_tick_ == 0)
|
||||
{
|
||||
previous_tick_ = osKernelGetTickCount();
|
||||
}
|
||||
|
||||
previous_tick_ += osKernelGetTickFreq()/frequency;
|
||||
|
||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||
waiting();
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
|
||||
osDelayUntil(previous_tick_);
|
||||
|
||||
#ifdef STA_TACOS_WATCHDOG_ENABLED
|
||||
heartbeat();
|
||||
#endif // STA_TACOS_WATCHDOG_ENABLED
|
||||
|
Loading…
x
Reference in New Issue
Block a user