summaryrefslogtreecommitdiffstats
path: root/cpukit/libtest/t-test-time.c
diff options
context:
space:
mode:
Diffstat (limited to 'cpukit/libtest/t-test-time.c')
-rw-r--r--cpukit/libtest/t-test-time.c60
1 files changed, 57 insertions, 3 deletions
diff --git a/cpukit/libtest/t-test-time.c b/cpukit/libtest/t-test-time.c
index 156ceaad1f..2acb75f799 100644
--- a/cpukit/libtest/t-test-time.c
+++ b/cpukit/libtest/t-test-time.c
@@ -1,7 +1,16 @@
-/*
- * SPDX-License-Identifier: BSD-2-Clause
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
*
- * Copyright (C) 2018 embedded brains GmbH
+ * @ingroup RTEMSTestFrameworkImpl
+ *
+ * @brief This source file contains the implementation of the time and ticks
+ * test support.
+ */
+
+/*
+ * Copyright (C) 2018 embedded brains GmbH & Co. KG
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -35,6 +44,7 @@
#include <time.h>
#ifdef __rtems__
+#include <rtems.h>
#include <rtems/counter.h>
#include <rtems/score/timecounter.h>
#endif
@@ -231,8 +241,52 @@ T_now_dummy(void)
memory_order_relaxed);
}
+#ifndef __rtems__
T_time
T_now_tick(void)
{
return T_ticks_to_time(T_tick());
}
+#else /* __rtems__ */
+#if defined(RTEMS_SMP)
+static rtems_interrupt_lock T_time_lock =
+ RTEMS_INTERRUPT_LOCK_INITIALIZER("Test Time Lock");
+#endif
+
+static T_ticks T_tick_last;
+
+static T_time T_tick_time;
+
+static bool T_tick_initialized;
+
+T_time
+T_now_tick(void)
+{
+ rtems_interrupt_lock_context lock_context;
+ T_ticks ticks;
+ T_time now;
+
+ ticks = T_tick();
+
+ rtems_interrupt_lock_acquire(&T_time_lock, &lock_context);
+
+ if (T_tick_initialized) {
+ T_ticks last;
+
+ last = T_tick_last;
+ T_tick_last = ticks;
+
+ now = T_tick_time;
+ now += T_ticks_to_time(ticks - last);
+ T_tick_time = now;
+ } else {
+ T_tick_initialized = true;
+ T_tick_last = ticks;
+ now = 0;
+ }
+
+ rtems_interrupt_lock_release(&T_time_lock, &lock_context);
+
+ return now;
+}
+#endif /* __rtems__ */