arch/sim: Implement arch rtc interface on top of rtc driver
This commit is contained in:
parent
d0d4b7a531
commit
8b5658b918
@ -67,6 +67,7 @@ config ARCH_RISCV
|
||||
config ARCH_SIM
|
||||
bool "Simulation"
|
||||
select ARCH_HAVE_MULTICPU
|
||||
select ARCH_HAVE_RTC_SUBSECONDS
|
||||
select ARCH_HAVE_TLS
|
||||
select ARCH_HAVE_TICKLESS
|
||||
select ARCH_HAVE_POWEROFF
|
||||
|
@ -109,6 +109,10 @@ ifeq ($(CONFIG_ONESHOT),y)
|
||||
CSRCS += up_oneshot.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RTC_DRIVER),y)
|
||||
CSRCS += up_rtc.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NX_LCDDRIVER),y)
|
||||
CSRCS += up_lcd.c
|
||||
else
|
||||
@ -124,15 +128,13 @@ ifeq ($(CONFIG_SIM_TOUCHSCREEN),y)
|
||||
REQUIREDOBJS += up_touchscreen$(OBJEXT)
|
||||
HOSTCFLAGS += -DCONFIG_SIM_TOUCHSCREEN=1
|
||||
HOSTSRCS += up_x11eventloop.c
|
||||
else
|
||||
ifeq ($(CONFIG_SIM_AJOYSTICK),y)
|
||||
else ifeq ($(CONFIG_SIM_AJOYSTICK),y)
|
||||
CSRCS += up_ajoystick.c
|
||||
HOSTCFLAGS += -DCONFIG_SIM_AJOYSTICK=1
|
||||
HOSTSRCS += up_x11eventloop.c
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SIM_IOEXPANDER),y)
|
||||
CSRCS += up_ioexpander.c
|
||||
|
@ -8,6 +8,7 @@ chdir NXchdir
|
||||
clearenv NXclearenv
|
||||
clock NXclock
|
||||
clock_gettime NXclock_gettime
|
||||
clock_settime NXclock_settime
|
||||
close NXclose
|
||||
closedir NXclosedir
|
||||
connect NXconnect
|
||||
|
127
arch/sim/src/sim/up_rtc.c
Normal file
127
arch/sim/src/sim/up_rtc.c
Normal file
@ -0,0 +1,127 @@
|
||||
/****************************************************************************
|
||||
* arch/sim/src/sim/up_rtc.c
|
||||
*
|
||||
* 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
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/timers/rtc.h>
|
||||
#include <nuttx/timers/arch_rtc.h>
|
||||
|
||||
#include "up_internal.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
||||
FAR struct rtc_time *rtctime);
|
||||
static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
||||
FAR const struct rtc_time *rtctime);
|
||||
static bool sim_rtc_havesettime(FAR struct rtc_lowerhalf_s *lower);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct rtc_ops_s g_sim_rtc_ops =
|
||||
{
|
||||
.rdtime = sim_rtc_rdtime,
|
||||
.settime = sim_rtc_settime,
|
||||
.havesettime = sim_rtc_havesettime,
|
||||
};
|
||||
|
||||
static struct rtc_lowerhalf_s g_sim_rtc =
|
||||
{
|
||||
.ops = &g_sim_rtc_ops,
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
static int sim_rtc_rdtime(FAR struct rtc_lowerhalf_s *lower,
|
||||
FAR struct rtc_time *rtctime)
|
||||
{
|
||||
uint64_t nsec;
|
||||
time_t sec;
|
||||
|
||||
|
||||
nsec = host_gettime(true);
|
||||
sec = nsec / NSEC_PER_SEC;
|
||||
nsec -= sec * NSEC_PER_SEC;
|
||||
|
||||
gmtime_r(&sec, (FAR struct tm *)rtctime);
|
||||
rtctime->tm_nsec = nsec;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int sim_rtc_settime(FAR struct rtc_lowerhalf_s *lower,
|
||||
FAR const struct rtc_time *rtctime)
|
||||
{
|
||||
uint64_t nsec;
|
||||
|
||||
nsec = mktime((FAR struct tm *)rtctime);
|
||||
nsec *= NSEC_PER_SEC;
|
||||
nsec += rtctime->tm_nsec;
|
||||
host_settime(true, nsec);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static bool sim_rtc_havesettime(FAR struct rtc_lowerhalf_s *lower)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_rtc_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize the builtin, MCU hardware RTC per the selected
|
||||
* configuration. This function is called once very early in the OS
|
||||
* initialization sequence.
|
||||
*
|
||||
* NOTE that initialization of external RTC hardware that depends on the
|
||||
* availability of OS resources (such as SPI or I2C) must be deferred
|
||||
* until the system has fully booted. Other, RTC-specific initialization
|
||||
* functions are used in that case.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno on failure
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int up_rtc_initialize(void)
|
||||
{
|
||||
up_rtc_set_lowerhalf(&g_sim_rtc);
|
||||
return rtc_initialize(0, &g_sim_rtc);
|
||||
}
|
Loading…
Reference in New Issue
Block a user