aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/chsleep.c14
-rw-r--r--src/include/sleep.h3
2 files changed, 17 insertions, 0 deletions
diff --git a/src/chsleep.c b/src/chsleep.c
index 859333b79..7f9f161f1 100644
--- a/src/chsleep.c
+++ b/src/chsleep.c
@@ -39,4 +39,18 @@ void chThdSleep(systime_t time) {
}
#endif /* CH_USE_SLEEP */
+#ifdef CH_USE_SYSTEMTIME
+/**
+ * Checks if the current system time is within the specified time window.
+ * @param start the start of the time window (inclusive)
+ * @param end the end of the time window (non inclusive)
+ */
+bool_t chSysInTimeWindow(systime_t start, systime_t end) {
+
+ systime_t time = chSysGetTime();
+ return end >= start ? (time >= start) && (time < end) :
+ (time >= start) || (time < end);
+}
+#endif /* CH_USE_SYSTEMTIME */
+
/** @} */
diff --git a/src/include/sleep.h b/src/include/sleep.h
index 51c4ac5d0..c718bb4ba 100644
--- a/src/include/sleep.h
+++ b/src/include/sleep.h
@@ -31,6 +31,9 @@ extern "C" {
#ifdef CH_USE_SLEEP
void chThdSleep(systime_t time);
#endif /* CH_USE_SLEEP */
+#ifdef CH_USE_SYSTEMTIME
+bool_t chSysInTimeWindow(systime_t start, systime_t end);
+#endif /* CH_USE_SYSTEMTIME */
#ifdef __cplusplus
}
#endif