aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2019-05-17 19:15:08 +0200
committerHarald Welte <laforge@gnumonks.org>2019-05-17 19:19:18 +0200
commitb98478a1fecc5c451cbcebd00e456e622aa2ceab (patch)
treeab35418b0aed51fe16875e4110772686a75f78e7
parent8a534f189b040c3d8aa5a5a322c22fff159f2fa3 (diff)
libosmo_emb: Implement _gettimeofday() on simplistic 'jiffies' counter.
We simply use the SysTick timer to count at 1KHz and fill a 64bit jiffies conunter. This counter is then used to fill tv_sec and tv_usec in the gettimeofday() implementation. NOTE: tv_sec will not indicate the seconds since the epoch (Jan 01, 1970), but rather since system startup. For the existign users, particularly osmo_timer, this doesn't matter. Change-Id: I9dbbb730996bde1e7039f790d76d7243739a8419
-rw-r--r--sysmoOCTSIM/libosmo_emb.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/sysmoOCTSIM/libosmo_emb.c b/sysmoOCTSIM/libosmo_emb.c
index 887887d..b100560 100644
--- a/sysmoOCTSIM/libosmo_emb.c
+++ b/sysmoOCTSIM/libosmo_emb.c
@@ -14,16 +14,22 @@ void *g_msgb_ctx;
***********************************************************************/
#include <sys/time.h>
+#include "driver_init.h"
+
+volatile uint64_t jiffies;
+
+void SysTick_Handler(void)
+{
+ jiffies++;
+}
-/* FIXME: Implement it bsed on jiffies and/or RTC! */
int _gettimeofday(struct timeval *tv, void *tz)
{
- tv->tv_sec = 0;
- tv->tv_usec = 0;
+ tv->tv_sec = jiffies / 1000;
+ tv->tv_usec = (jiffies % 1000) * 1000;
return 0;
}
-
/***********************************************************************
* Logging
***********************************************************************/
@@ -124,4 +130,7 @@ void libosmo_emb_init(void)
stderr_target = log_target_create_stderr_raw();
log_add_target(stderr_target);
log_set_all_filter(stderr_target, 1);
+
+ /* timer */
+ SysTick_Config(SystemCoreClock / 1000);
}