From 73f44206914d85d5feeb26b25412101d8fe48295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucher?= <cfoucher@laas.fr> Date: Fri, 18 Nov 2022 17:53:23 +0100 Subject: [PATCH] Add a way to suspend asynchronous tasks. --- .../zephyr/public_api/Scheduling.cpp | 13 ++++++++++++ .../zephyr/public_api/Scheduling.h | 21 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp index 8a122a0..692b352 100644 --- a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp +++ b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp @@ -75,3 +75,16 @@ void Scheduling::startAsynchronousTask(uint8_t task_number) } #endif // CONFIG_OWNTECH_SCHEDULING_ENABLE_ASYNCHRONOUS_TASKS + + +// Suspend asynchronous tasks + +void Scheduling::suspendCurrentTaskMs(uint32_t duration_ms) +{ + k_sleep(K_MSEC(duration_ms)); +} + +void Scheduling::suspendCurrentTaskUs(uint32_t duration_us) +{ + k_sleep(K_USEC(duration_us)); +} diff --git a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h index eb3be2d..52a6e5f 100644 --- a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h +++ b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.h @@ -91,6 +91,27 @@ public: #endif // CONFIG_OWNTECH_SCHEDULING_ENABLE_ASYNCHRONOUS_TASKS + /** + * @brief This function allows to suspend an asynchronous + * task for a specified duration expressed in milliseconds. + * For example, you can call this function at the end of an + * asynchronous task main function, when there is no need + * for the task to run permanently. + * + * DO NOT use this function in a synchronous task! + */ + void suspendCurrentTaskMs(uint32_t duration_ms); + + /** + * @brief This function allows to suspend an asynchronous + * task for a specified duration expressed in microseconds. + * For example, you can call this function at the end of an + * asynchronous task main function, when there is no need + * for the task to run permanently. + * + * DO NOT use this function in a synchronous task! + */ + void suspendCurrentTaskUs(uint32_t duration_us); private: static const int DEFAULT_PRIORITY; -- GitLab