summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorxqyjlj <[email protected]>2023-07-20 14:17:45 +0800
committerMan, Jianting (Meco) <[email protected]>2023-07-20 09:25:18 -0400
commit5f0328ee4195d523f66734f2e1d4fc87ed03a109 (patch)
tree8211cc007a357da5a4201de52df45f65342b5634
parent0b966bfca0bc369c0f8cc1fdd7ad7155ef4d0384 (diff)
✨ feat(ktime): add RT_USING_KTIME to kconfig build
-rw-r--r--components/Kconfig1
-rw-r--r--components/drivers/rtc/soft_rtc.c11
-rw-r--r--components/ktime/Kconfig3
-rw-r--r--components/ktime/SConscript2
-rw-r--r--components/libc/compilers/common/ctime.c16
-rw-r--r--components/libc/posix/Kconfig3
-rw-r--r--src/Kconfig1
7 files changed, 28 insertions, 9 deletions
diff --git a/components/Kconfig b/components/Kconfig
index d9b9bc60df..5aee4360a0 100644
--- a/components/Kconfig
+++ b/components/Kconfig
@@ -34,5 +34,6 @@ source "$RTT_DIR/components/libc/Kconfig"
source "$RTT_DIR/components/net/Kconfig"
source "$RTT_DIR/components/utilities/Kconfig"
source "$RTT_DIR/components/vbus/Kconfig"
+source "$RTT_DIR/components/ktime/Kconfig"
endmenu
diff --git a/components/drivers/rtc/soft_rtc.c b/components/drivers/rtc/soft_rtc.c
index 3d84e547ad..ec74b7e372 100644
--- a/components/drivers/rtc/soft_rtc.c
+++ b/components/drivers/rtc/soft_rtc.c
@@ -13,7 +13,9 @@
#include <rtthread.h>
#include <rtdevice.h>
+#ifdef RT_USING_KTIME
#include <ktime.h>
+#endif
#ifdef RT_USING_SOFT_RTC
@@ -38,8 +40,11 @@ static rt_device_t source_device = RT_NULL;
static struct rt_device soft_rtc_dev;
static rt_tick_t init_tick;
static time_t init_time;
+
+#ifdef RT_USING_KTIME
static struct timeval init_tv = {0};
static struct timespec init_ts = {0};
+#endif
#ifdef RT_USING_ALARM
@@ -92,10 +97,12 @@ static void _source_device_control(int cmd, void *args)
static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
{
time_t *t;
+#ifdef RT_USING_KTIME
struct timeval *tv;
struct timespec *ts;
struct timeval _tv;
struct timespec _ts;
+#endif
struct tm time_temp;
RT_ASSERT(dev != RT_NULL);
@@ -123,6 +130,7 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
soft_rtc_alarm_update(&wkalarm);
break;
#endif
+#ifdef RT_USING_KTIME
case RT_DEVICE_CTRL_RTC_GET_TIMEVAL:
tv = (struct timeval *)args;
rt_ktime_boottime_get_us(&_tv);
@@ -154,6 +162,9 @@ static rt_err_t soft_rtc_control(rt_device_t dev, int cmd, void *args)
ts->tv_sec = 0;
ts->tv_nsec = (rt_ktime_cputimer_getres() / RT_KTIME_RESMUL);
break;
+#endif
+ default:
+ return -RT_EINVAL;
}
return RT_EOK;
diff --git a/components/ktime/Kconfig b/components/ktime/Kconfig
new file mode 100644
index 0000000000..170271c222
--- /dev/null
+++ b/components/ktime/Kconfig
@@ -0,0 +1,3 @@
+menuconfig RT_USING_KTIME
+ bool "Ktime: kernel time"
+ default n
diff --git a/components/ktime/SConscript b/components/ktime/SConscript
index 0ec9655697..6eedb84818 100644
--- a/components/ktime/SConscript
+++ b/components/ktime/SConscript
@@ -14,6 +14,6 @@ if rtconfig.ARCH in list:
src += Glob("src/" + rtconfig.ARCH + "/*.c")
CPPPATH = [cwd, cwd + "/inc"]
-group = DefineGroup('ktime', src, depend=[''], CPPPATH=CPPPATH)
+group = DefineGroup('ktime', src, depend=['RT_USING_KTIME'], CPPPATH=CPPPATH)
Return('group')
diff --git a/components/libc/compilers/common/ctime.c b/components/libc/compilers/common/ctime.c
index 4f3e424f68..bec2d24b4f 100644
--- a/components/libc/compilers/common/ctime.c
+++ b/components/libc/compilers/common/ctime.c
@@ -25,7 +25,6 @@
*/
#include "sys/time.h"
-#include <ktime.h>
#include <rthw.h>
#include <rtthread.h>
#include <sys/errno.h>
@@ -40,6 +39,9 @@
#if defined( RT_USING_RTC ) || defined( RT_USING_CPUTIME)
#include <rtdevice.h>
#endif
+#ifdef RT_USING_KTIME
+#include "ktime.h"
+#endif
#define DBG_TAG "time"
#define DBG_LVL DBG_INFO
@@ -459,7 +461,7 @@ int settimeofday(const struct timeval *tv, const struct timezone *tz)
}
RTM_EXPORT(settimeofday);
-#ifdef RT_USING_POSIX_DELAY
+#if defined(RT_USING_POSIX_DELAY) && defined(RT_USING_KTIME)
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
{
struct timespec old_ts = {0};
@@ -501,9 +503,9 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
return 0;
}
RTM_EXPORT(nanosleep);
-#endif /* RT_USING_POSIX_DELAY */
+#endif /* RT_USING_POSIX_DELAY && RT_USING_KTIME */
-#ifdef RT_USING_POSIX_CLOCK
+#if defined(RT_USING_POSIX_CLOCK) && defined(RT_USING_KTIME)
int clock_getres(clockid_t clockid, struct timespec *res)
{
@@ -693,9 +695,9 @@ int rt_timespec_to_tick(const struct timespec *time)
}
RTM_EXPORT(rt_timespec_to_tick);
-#endif /* RT_USING_POSIX_CLOCK */
+#endif /* RT_USING_POSIX_CLOCK && RT_USING_KTIME */
-#ifdef RT_USING_POSIX_TIMER
+#if defined(RT_USING_POSIX_TIMER) && defined(RT_USING_KTIME)
#include <resource_id.h>
@@ -1111,7 +1113,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
return 0;
}
RTM_EXPORT(timer_settime);
-#endif /* RT_USING_POSIX_TIMER */
+#endif /* RT_USING_POSIX_TIMER && RT_USING_KTIME */
/* timezone */
diff --git a/components/libc/posix/Kconfig b/components/libc/posix/Kconfig
index 148014407a..f8c929b45c 100644
--- a/components/libc/posix/Kconfig
+++ b/components/libc/posix/Kconfig
@@ -47,6 +47,7 @@ if RT_USING_POSIX_FS
endif
config RT_USING_POSIX_DELAY
+ select RT_USING_KTIME
bool "Enable delay APIs, sleep()/usleep()/msleep() etc"
default n
@@ -56,7 +57,7 @@ config RT_USING_POSIX_CLOCK
default n
config RT_USING_POSIX_TIMER
- select RT_USING_TIMER_SOFT
+ select RT_USING_KTIME
select RT_USING_RESOURCE_ID
bool "Enable timer APIs, timer_create()/timer_gettime() etc"
default n
diff --git a/src/Kconfig b/src/Kconfig
index ed280c0020..b869559952 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -34,6 +34,7 @@ config RT_USING_SMART
select RT_USING_POSIX_CLOCK
select RT_USING_POSIX_FS
select RT_USING_POSIX_TERMIOS
+ select RT_USING_KTIME
depends on ARCH_ARM_CORTEX_M || ARCH_ARM_ARM9 || ARCH_ARM_CORTEX_A || ARCH_ARMV8 || ARCH_RISCV64
help
RT-Thread Smart is a microkernel based operating system on RT-Thread.