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
This commit is contained in:
Harald Welte 2019-05-17 19:15:08 +02:00
parent 8a534f189b
commit b98478a1fe
1 changed files with 14 additions and 5 deletions

View File

@ -14,15 +14,21 @@ void *g_msgb_ctx;
***********************************************************************/
#include <sys/time.h>
#include "driver_init.h"
/* FIXME: Implement it bsed on jiffies and/or RTC! */
int _gettimeofday(struct timeval *tv, void *tz)
volatile uint64_t jiffies;
void SysTick_Handler(void)
{
tv->tv_sec = 0;
tv->tv_usec = 0;
return 0;
jiffies++;
}
int _gettimeofday(struct timeval *tv, void *tz)
{
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);
}