mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
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:
committed by
Xiang Xiao
parent
34a2f0cc40
commit
29bf45c371
@@ -119,6 +119,7 @@ config ARCH_SIM
|
|||||||
select ARCH_SETJMP_H
|
select ARCH_SETJMP_H
|
||||||
select ALARM_ARCH
|
select ALARM_ARCH
|
||||||
select ONESHOT
|
select ONESHOT
|
||||||
|
select ONESHOT_COUNT
|
||||||
select SERIAL_CONSOLE
|
select SERIAL_CONSOLE
|
||||||
select SERIAL_IFLOWCONTROL
|
select SERIAL_IFLOWCONTROL
|
||||||
select SCHED_HPWORK
|
select SCHED_HPWORK
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ NXSYMBOLS(sched_yield)
|
|||||||
NXSYMBOLS(select)
|
NXSYMBOLS(select)
|
||||||
NXSYMBOLS(sendmsg)
|
NXSYMBOLS(sendmsg)
|
||||||
NXSYMBOLS(sendto)
|
NXSYMBOLS(sendto)
|
||||||
NXSYMBOLS(setitimer)
|
|
||||||
NXSYMBOLS(setbuf)
|
NXSYMBOLS(setbuf)
|
||||||
NXSYMBOLS(setjmp)
|
NXSYMBOLS(setjmp)
|
||||||
NXSYMBOLS(setsockopt)
|
NXSYMBOLS(setsockopt)
|
||||||
@@ -158,6 +157,8 @@ NXSYMBOLS(syslog)
|
|||||||
NXSYMBOLS(system)
|
NXSYMBOLS(system)
|
||||||
NXSYMBOLS(tcgetattr)
|
NXSYMBOLS(tcgetattr)
|
||||||
NXSYMBOLS(tcsetattr)
|
NXSYMBOLS(tcsetattr)
|
||||||
|
NXSYMBOLS(timer_create)
|
||||||
|
NXSYMBOLS(timer_settime)
|
||||||
NXSYMBOLS(unlink)
|
NXSYMBOLS(unlink)
|
||||||
NXSYMBOLS(usleep)
|
NXSYMBOLS(usleep)
|
||||||
NXSYMBOLS(utimensat)
|
NXSYMBOLS(utimensat)
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* arch/sim/src/sim/posix/sim_hosttime.c
|
* 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
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
* this work for additional information regarding copyright ownership. The
|
* this work for additional information regarding copyright ownership. The
|
||||||
@@ -34,34 +32,51 @@
|
|||||||
|
|
||||||
#include "sim_internal.h"
|
#include "sim_internal.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static uint64_t g_start;
|
||||||
|
static timer_t g_timer;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* 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
|
* Name: host_gettime
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
uint64_t host_gettime(bool rtc)
|
uint64_t host_gettime(bool rtc)
|
||||||
{
|
{
|
||||||
static uint64_t start;
|
|
||||||
struct timespec tp;
|
struct timespec tp;
|
||||||
uint64_t current;
|
uint64_t current;
|
||||||
|
|
||||||
clock_gettime(rtc ? CLOCK_REALTIME : CLOCK_MONOTONIC, &tp);
|
clock_gettime(rtc ? CLOCK_REALTIME : CLOCK_MONOTONIC, &tp);
|
||||||
current = 1000000000ull * tp.tv_sec + tp.tv_nsec;
|
current = 1000000000ull * tp.tv_sec + tp.tv_nsec;
|
||||||
|
|
||||||
if (rtc)
|
return rtc ? current : current - g_start;
|
||||||
{
|
|
||||||
return current;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (start == 0)
|
|
||||||
{
|
|
||||||
start = current;
|
|
||||||
}
|
|
||||||
|
|
||||||
return current - start;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -104,14 +119,19 @@ void host_sleepuntil(uint64_t nsec)
|
|||||||
|
|
||||||
int host_settimer(uint64_t nsec)
|
int host_settimer(uint64_t nsec)
|
||||||
{
|
{
|
||||||
struct itimerval it;
|
struct itimerspec tspec =
|
||||||
|
{
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
it.it_interval.tv_sec = 0;
|
/* Convert to microseconds and set minimum timer to 1 microsecond. */
|
||||||
it.it_interval.tv_usec = 0;
|
|
||||||
it.it_value.tv_sec = nsec / 1000000000;
|
|
||||||
it.it_value.tv_usec = (nsec + 1000) / 1000;
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ int host_unlinkshmem(const char *name);
|
|||||||
|
|
||||||
/* sim_hosttime.c ***********************************************************/
|
/* sim_hosttime.c ***********************************************************/
|
||||||
|
|
||||||
|
int host_inittimer(void);
|
||||||
uint64_t host_gettime(bool rtc);
|
uint64_t host_gettime(bool rtc);
|
||||||
void host_sleep(uint64_t nsec);
|
void host_sleep(uint64_t nsec);
|
||||||
void host_sleepuntil(uint64_t nsec);
|
void host_sleepuntil(uint64_t nsec);
|
||||||
|
|||||||
+132
-327
File diff suppressed because it is too large
Load Diff
@@ -44,6 +44,15 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: host_inittimer
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int host_inittimer(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: host_gettime
|
* Name: host_gettime
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|||||||
Reference in New Issue
Block a user