mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/TACOS.git
synced 2025-06-10 16:45:59 +00:00
feat(sync): added periodicDelay function to threads
This commit is contained in:
parent
e03f624c5b
commit
40727728d0
@ -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,11 @@
|
||||
|
||||
#include <functional>
|
||||
#include <cstring>
|
||||
#include <cmsis_os2.h>
|
||||
|
||||
// Include FreeRTOS configuration for the system tick rate.
|
||||
typedef uint32_t TickType_t;
|
||||
#include <FreeRTOSConfig.h>
|
||||
|
||||
namespace sta
|
||||
{
|
||||
@ -31,7 +35,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 +115,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_ += configTICK_RATE_HZ/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