From: ljsebald <ljs...@us...> - 2023-03-29 02:59:37
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "A pseudo Operating System for the Dreamcast.". The branch, master has been updated via 7237ac56f9141d130c3dac749ccb4becabcd1df5 (commit) from 11cd2c47cf3c025273784d61da08d56fb38495ee (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 7237ac56f9141d130c3dac749ccb4becabcd1df5 Author: Lawrence Sebald <ljs...@us...> Date: Tue Mar 28 22:58:59 2023 -0400 Add timespec_get to libc/c11. ----------------------------------------------------------------------- Summary of changes: doc/CHANGELOG | 1 + include/kos/time.h | 33 +++++++++++++++++++++++++++++++++ include/sys/_types.h | 9 +++++++-- kernel/libc/c11/Makefile | 4 ++-- kernel/libc/c11/timespec_get.c | 21 +++++++++++++++++++++ 5 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 include/kos/time.h create mode 100644 kernel/libc/c11/timespec_get.c diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 2dbec9a..cb6ed7f 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -156,6 +156,7 @@ KallistiOS version 2.1.0 ----------------------------------------------- - DC Fixed wildly out of range start for pvrmark benchmark [Falco Girgis == FG] - DC Removed "navi" subarch, moved code to addons/libnavi [LS] - *** Removed (completely unsupported) support for GCC 3.x and older [LS] +- *** Add timespec_get C11 function to koslib's libc [LS] KallistiOS version 2.0.0 ----------------------------------------------- - DC Broadband Adapter driver fixes [Dan Potter == DP] diff --git a/include/kos/time.h b/include/kos/time.h new file mode 100644 index 0000000..78279b5 --- /dev/null +++ b/include/kos/time.h @@ -0,0 +1,33 @@ +/* KallistiOS ##version## + + kos/time.h + Copyright (C) 2023 Lawrence Sebald +*/ + +/* This will probably go away at some point in the future, if/when Newlib gets + an implementation of this function. But for now, it's here. */ + +#ifndef _TIME_H_ +#error "Do not include this file directly. Use <time.h> instead." +#endif /* !_TIME_H_ */ + +#ifndef __KOS_TIME_H +#define __KOS_TIME_H + +#if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 201112L) + +#include <kos/cdefs.h> + +__BEGIN_DECLS + +/* Forward declaration. */ +struct timespec; + +#define TIME_UTC 1 + +extern int timespec_get(struct timespec *ts, int base); + +__END_DECLS + +#endif /* !defined(__STRICT_ANSI__) || (__STDC_VERSION__ >= 201112L) */ +#endif /* !__KOS_C11TIME_H */ diff --git a/include/sys/_types.h b/include/sys/_types.h index 6a95a24..547f828 100644 --- a/include/sys/_types.h +++ b/include/sys/_types.h @@ -197,12 +197,17 @@ typedef _CLOCK_T_ __clock_t; #define IOV_MAX 1024 #endif -// And this is for old KOS source compatability. +/* This is for old KOS source compatability. */ #include <arch/types.h> -// Include stuff to make pthreads work as well. +/* Include stuff to make pthreads work as well. */ #include <sys/_pthread.h> +/* Grab our C11 time stuff if we got here from <time.h>. */ +#ifdef _TIME_H_ +#include <kos/time.h> +#endif + #ifndef __RESTRICT #if (__STDC_VERSION__ >= 199901L) #define __RESTRICT restrict diff --git a/kernel/libc/c11/Makefile b/kernel/libc/c11/Makefile index df0b67f..4328d16 100644 --- a/kernel/libc/c11/Makefile +++ b/kernel/libc/c11/Makefile @@ -1,7 +1,7 @@ # KallistiOS ##version## # # kernel/libc/c11/Makefile -# Copyright (C) 2014, 2015 Lawrence Sebald +# Copyright (C) 2014, 2015, 2023 Lawrence Sebald # KOS_CFLAGS += -std=c11 @@ -11,6 +11,6 @@ OBJS = call_once.o cnd_broadcast.o cnd_destroy.o cnd_init.o cnd_signal.o \ mtx_timedlock.o mtx_trylock.o mtx_unlock.o thrd_create.o thrd_current.o \ thrd_detach.o thrd_equal.o thrd_exit.o thrd_join.o thrd_sleep.o \ thrd_yield.o tss_create.o tss_delete.o tss_get.o tss_set.o \ - aligned_alloc.o + aligned_alloc.o timespec_get.o include $(KOS_BASE)/Makefile.prefab diff --git a/kernel/libc/c11/timespec_get.c b/kernel/libc/c11/timespec_get.c new file mode 100644 index 0000000..a1f05dc --- /dev/null +++ b/kernel/libc/c11/timespec_get.c @@ -0,0 +1,21 @@ +/* KallistiOS ##version## + + timespec_get.c + Copyright (C) 2023 Lawrence Sebald +*/ + +#include <time.h> +#include <arch/timer.h> +#include <arch/rtc.h> + +int timespec_get(struct timespec *ts, int base) { + if(base == TIME_UTC && ts) { + uint32 s, ms; + + timer_ms_gettime(&s, &ms); + ts->tv_sec = rtc_boot_time() + s; + ts->tv_nsec = ms * 1000 * 1000; + } + + return 0; +} hooks/post-receive -- A pseudo Operating System for the Dreamcast. |