arch/sim: Add clkdev driver for sim.

This commit added clkdev driver for sim.

Signed-off-by: ouyangxiangzhen <ouyangxiangzhen@xiaomi.com>
This commit is contained in:
ouyangxiangzhen
2025-09-28 19:40:19 +08:00
committed by Xiang Xiao
parent 34a2f0cc40
commit 29bf45c371
6 changed files with 185 additions and 348 deletions
+1
View File
@@ -119,6 +119,7 @@ config ARCH_SIM
select ARCH_SETJMP_H
select ALARM_ARCH
select ONESHOT
select ONESHOT_COUNT
select SERIAL_CONSOLE
select SERIAL_IFLOWCONTROL
select SCHED_HPWORK
+2 -1
View File
@@ -133,7 +133,6 @@ NXSYMBOLS(sched_yield)
NXSYMBOLS(select)
NXSYMBOLS(sendmsg)
NXSYMBOLS(sendto)
NXSYMBOLS(setitimer)
NXSYMBOLS(setbuf)
NXSYMBOLS(setjmp)
NXSYMBOLS(setsockopt)
@@ -158,6 +157,8 @@ NXSYMBOLS(syslog)
NXSYMBOLS(system)
NXSYMBOLS(tcgetattr)
NXSYMBOLS(tcsetattr)
NXSYMBOLS(timer_create)
NXSYMBOLS(timer_settime)
NXSYMBOLS(unlink)
NXSYMBOLS(usleep)
NXSYMBOLS(utimensat)
+40 -20
View File
@@ -1,8 +1,6 @@
/****************************************************************************
* arch/sim/src/sim/posix/sim_hosttime.c
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
@@ -34,34 +32,51 @@
#include "sim_internal.h"
/****************************************************************************
* Private Data
****************************************************************************/
static uint64_t g_start;
static timer_t g_timer;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: host_inittimer
****************************************************************************/
int host_inittimer(void)
{
struct timespec tp;
struct sigevent sigev =
{
0
};
clock_gettime(CLOCK_MONOTONIC, &tp);
g_start = 1000000000ull * tp.tv_sec + tp.tv_nsec;
sigev.sigev_notify = SIGEV_SIGNAL;
sigev.sigev_signo = SIGALRM;
return timer_create(CLOCK_MONOTONIC, &sigev, &g_timer);
}
/****************************************************************************
* Name: host_gettime
****************************************************************************/
uint64_t host_gettime(bool rtc)
{
static uint64_t start;
struct timespec tp;
uint64_t current;
clock_gettime(rtc ? CLOCK_REALTIME : CLOCK_MONOTONIC, &tp);
current = 1000000000ull * tp.tv_sec + tp.tv_nsec;
if (rtc)
{
return current;
}
if (start == 0)
{
start = current;
}
return current - start;
return rtc ? current : current - g_start;
}
/****************************************************************************
@@ -104,14 +119,19 @@ void host_sleepuntil(uint64_t nsec)
int host_settimer(uint64_t nsec)
{
struct itimerval it;
struct itimerspec tspec =
{
0
};
it.it_interval.tv_sec = 0;
it.it_interval.tv_usec = 0;
it.it_value.tv_sec = nsec / 1000000000;
it.it_value.tv_usec = (nsec + 1000) / 1000;
/* Convert to microseconds and set minimum timer to 1 microsecond. */
return setitimer(ITIMER_REAL, &it, NULL);
nsec += g_start;
tspec.it_value.tv_sec = nsec / 1000000000;
tspec.it_value.tv_nsec = nsec % 1000000000;
return timer_settime(g_timer, TIMER_ABSTIME, &tspec, NULL);
}
/****************************************************************************
+1
View File
@@ -256,6 +256,7 @@ int host_unlinkshmem(const char *name);
/* sim_hosttime.c ***********************************************************/
int host_inittimer(void);
uint64_t host_gettime(bool rtc);
void host_sleep(uint64_t nsec);
void host_sleepuntil(uint64_t nsec);
File diff suppressed because it is too large Load Diff
+9
View File
@@ -44,6 +44,15 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: host_inittimer
****************************************************************************/
int host_inittimer(void)
{
return 0;
}
/****************************************************************************
* Name: host_gettime
****************************************************************************/