diff --git a/src/.gitignore b/src/.gitignore index 331b6e1cf73646379484d1f2fe8fe168894d3a72..bb9caa138e939a38767fd94b6b9cb65b42761ca7 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -4,60 +4,12 @@ # Object files *.o -*.ko *.obj -*.elf -*.disasm - -# Linker output -*.ilk -*.map -*.exp - -# Precompiled Headers -*.gch -*.pch - -# Libraries -*.lib -*.a -*.la -*.lo - -# Shared objects (inc. Windows DLLs) -*.dll -*.so -*.so.* -*.dylib - -# Executables -*.exe -*.out -*.app -*.i*86 -*.x86_64 -*.hex - -# Image -*.iso -*.vhd -*.bin - -# Debug files -*.dSYM/ -*.su -*.idb -*.pdb -*.dump # Kernel Module Compile Results *.cmd -.tmp_versions/ -modules.order -Module.symvers -Mkfile.old -dkms.conf +# kernel special fixdep init/rootfs.c build diff --git a/src/arch/riscv64/port/clock.c b/src/arch/riscv64/port/clock.c index c7b7c562bbe4c368da469245a3b450f3c4a4d1d7..9280a4e6d84cc3ca54dda4d7765844cd0383a6c5 100644 --- a/src/arch/riscv64/port/clock.c +++ b/src/arch/riscv64/port/clock.c @@ -37,6 +37,7 @@ #endif NX_PRIVATE NX_U64 tickDelta = NX_TIMER_CLK_FREQ / NX_TICKS_PER_SECOND; +NX_PRIVATE volatile NX_U64 tickNext = 0; NX_PRIVATE NX_U64 GetTimerCounter() { @@ -45,20 +46,57 @@ NX_PRIVATE NX_U64 GetTimerCounter() return ret; } +NX_U64 NX_ClockGetMicrosecond(void) +{ + NX_U64 us = 0; + + NX_U64 counter = GetTimerCounter() % tickDelta; + + /** + * us in per ms + */ + us = (NX_DIV_ROUND_UP(counter, (tickDelta / 1000))) % 1000; + + /** + * us in time + */ + us += NX_ClockGetMillisecond() * 1000; + return us; +} + void NX_HalClockHandler(void) { - NX_ClockTickGo(); + NX_U64 counter; + /* update timer */ - sbi_set_timer(GetTimerCounter() + tickDelta); + counter = GetTimerCounter(); + if (counter - tickNext >= tickDelta) + { + tickNext = counter + tickDelta; + } + else + { + tickNext += tickDelta; + } + sbi_set_timer(tickNext); + + NX_ClockTickGo(); } NX_INTERFACE NX_Error NX_HalInitClock(void) { + NX_U64 counter; /* Clear the Supervisor-Timer bit in SIE */ ClearCSR(sie, SIE_STIE); /* Set timer */ - sbi_set_timer(GetTimerCounter() + tickDelta); + tickNext = tickDelta; + counter = GetTimerCounter(); + if (counter > tickNext) + { + tickNext = NX_DIV_ROUND_UP(counter, tickDelta) * tickDelta; + } + sbi_set_timer(tickNext); /* Enable the Supervisor-Timer bit in SIE */ SetCSR(sie, SIE_STIE); diff --git a/src/arch/x86/port/clock.c b/src/arch/x86/port/clock.c index 0a996641812f5159cef0669bb1af1665a9782e1f..015af46776cf7d54b89bd6e796ba977e720fb79f 100644 --- a/src/arch/x86/port/clock.c +++ b/src/arch/x86/port/clock.c @@ -134,6 +134,14 @@ enum ctrl_mode_bits #define TIMER_FREQ 1193180 /* clock frequency */ #define COUNTER0_VALUE (TIMER_FREQ / NX_TICKS_PER_SECOND) +/** + * FIXME: support this + */ +NX_U64 NX_ClockGetMicrosecond(void) +{ + return 0; +} + NX_PRIVATE NX_Error ClockHandler(NX_U32 irq, void *arg) { NX_ClockTickGo(); diff --git a/src/include/base/clock.h b/src/include/base/clock.h index 396d7753cf8c9c0456142e06d39c36ba1e3667af..37aa1a5970fec90e71a3367a3a6e0381ae73163b 100644 --- a/src/include/base/clock.h +++ b/src/include/base/clock.h @@ -37,6 +37,9 @@ void NX_ClockTickGo(void); NX_Error NX_ClockTickDelay(NX_ClockTick ticks); +NX_U64 NX_ClockGetMicrosecond(void); +NX_Error NX_DelayMicrosecond(NX_TimeVal us); + NX_INLINE NX_TimeVal NX_ClockTickToMillisecond(NX_ClockTick tick) { return NX_TICKS_TO_MILLISECOND(tick); diff --git a/src/platform/d1/defconfig b/src/platform/d1/defconfig index 5883ee967411a4803dff71d8718f3f7332e63a1d..3c1b29af62375811d679ea58cde5522fd694d5c1 100644 --- a/src/platform/d1/defconfig +++ b/src/platform/d1/defconfig @@ -32,7 +32,7 @@ CONFIG_NX_THREAD_STACK_SIZE=8192 CONFIG_NX_ENABLE_SCHED=y CONFIG_NX_THREAD_MAX_PRIORITY_NR=16 CONFIG_NX_PORCESS_ENV_ARGS=1024 -CONFIG_NX_TICKS_PER_SECOND=100 +CONFIG_NX_TICKS_PER_SECOND=1000 # end of OS Kernel # @@ -47,7 +47,6 @@ CONFIG_NX_PLATFORM_D1=y CONFIG_NX_DRIVER_CONSOLE=y CONFIG_NX_PRINT_BUF_LEN=256 CONFIG_NX_DRIVER_ROMDISK=y -CONFIG_NX_DRIVER_ROMDISK_HOSTOS_PATH="../../romdisk.cpio" # CONFIG_NX_DRIVER_DUMMY is not set CONFIG_NX_DRIVER_NULL=y CONFIG_NX_DRIVER_ZERO=y diff --git a/src/platform/d1/include/nx_configure.h b/src/platform/d1/include/nx_configure.h index 7d30342e0ed8d64472f26ec246f07c7cc5d078a6..5df72d80abc5659a89e8930e0a750e4545d9c32b 100644 --- a/src/platform/d1/include/nx_configure.h +++ b/src/platform/d1/include/nx_configure.h @@ -17,12 +17,11 @@ #define CONFIG_NX_ENABLE_SCHED 1 #define CONFIG_NX_THREAD_MAX_PRIORITY_NR 16 #define CONFIG_NX_PORCESS_ENV_ARGS 1024 -#define CONFIG_NX_TICKS_PER_SECOND 100 +#define CONFIG_NX_TICKS_PER_SECOND 1000 #define CONFIG_NX_PLATFORM_D1 1 #define CONFIG_NX_DRIVER_CONSOLE 1 #define CONFIG_NX_PRINT_BUF_LEN 256 #define CONFIG_NX_DRIVER_ROMDISK 1 -#define CONFIG_NX_DRIVER_ROMDISK_HOSTOS_PATH "../../romdisk.cpio" #define CONFIG_NX_DRIVER_NULL 1 #define CONFIG_NX_DRIVER_ZERO 1 #define CONFIG_NX_DRIVER_MEMINFO 1 diff --git a/src/platform/f133/defconfig b/src/platform/f133/defconfig index cbdd5300c3bab54dd7822c3b151695ab8ab68d0e..d80166ee16ace53035c265273d5204e0ce9398c6 100644 --- a/src/platform/f133/defconfig +++ b/src/platform/f133/defconfig @@ -32,7 +32,7 @@ CONFIG_NX_THREAD_STACK_SIZE=8192 CONFIG_NX_ENABLE_SCHED=y CONFIG_NX_THREAD_MAX_PRIORITY_NR=16 CONFIG_NX_PORCESS_ENV_ARGS=1024 -CONFIG_NX_TICKS_PER_SECOND=100 +CONFIG_NX_TICKS_PER_SECOND=1000 # end of OS Kernel # diff --git a/src/platform/f133/include/nx_configure.h b/src/platform/f133/include/nx_configure.h index dfc7ab14396cb434c75451baae68f535a7bc9fd7..ca65608a34128d4dc192284db478dc543ee6b7db 100644 --- a/src/platform/f133/include/nx_configure.h +++ b/src/platform/f133/include/nx_configure.h @@ -17,7 +17,7 @@ #define CONFIG_NX_ENABLE_SCHED 1 #define CONFIG_NX_THREAD_MAX_PRIORITY_NR 16 #define CONFIG_NX_PORCESS_ENV_ARGS 1024 -#define CONFIG_NX_TICKS_PER_SECOND 100 +#define CONFIG_NX_TICKS_PER_SECOND 1000 #define CONFIG_NX_PLATFORM_F133 1 #define CONFIG_SOC_SUN20IW1 1 #define CONFIG_DRIVERS_CCMU 1 diff --git a/src/platform/f133/tools/SBI/opensbi-f133.bin b/src/platform/f133/tools/SBI/opensbi-f133.bin new file mode 100644 index 0000000000000000000000000000000000000000..5b672910aa26cb7fc301368e684e382bcbf264e5 Binary files /dev/null and b/src/platform/f133/tools/SBI/opensbi-f133.bin differ diff --git a/src/platform/qemu_riscv64/defconfig b/src/platform/qemu_riscv64/defconfig index 6f8d415411a16a2debf9214204e6e174075c6dd4..68ce7ba35236240880a5071d7cd76dd322bdac29 100644 --- a/src/platform/qemu_riscv64/defconfig +++ b/src/platform/qemu_riscv64/defconfig @@ -32,7 +32,7 @@ CONFIG_NX_THREAD_STACK_SIZE=8192 CONFIG_NX_ENABLE_SCHED=y CONFIG_NX_THREAD_MAX_PRIORITY_NR=16 CONFIG_NX_PORCESS_ENV_ARGS=1024 -CONFIG_NX_TICKS_PER_SECOND=100 +CONFIG_NX_TICKS_PER_SECOND=1000 # end of OS Kernel # @@ -48,7 +48,6 @@ CONFIG_NX_UART0_FROM_SBI=y CONFIG_NX_DRIVER_CONSOLE=y CONFIG_NX_PRINT_BUF_LEN=256 CONFIG_NX_DRIVER_ROMDISK=y -CONFIG_NX_DRIVER_ROMDISK_HOSTOS_PATH="../../romdisk.cpio" # CONFIG_NX_DRIVER_DUMMY is not set CONFIG_NX_DRIVER_NULL=y CONFIG_NX_DRIVER_ZERO=y diff --git a/src/platform/qemu_riscv64/include/nx_configure.h b/src/platform/qemu_riscv64/include/nx_configure.h index 6ff566c916e22ff22d8a20d34d1dc7ccf8f80b59..f6ad433e24978518cbc8321093f3abc49cd354f5 100644 --- a/src/platform/qemu_riscv64/include/nx_configure.h +++ b/src/platform/qemu_riscv64/include/nx_configure.h @@ -17,13 +17,12 @@ #define CONFIG_NX_ENABLE_SCHED 1 #define CONFIG_NX_THREAD_MAX_PRIORITY_NR 16 #define CONFIG_NX_PORCESS_ENV_ARGS 1024 -#define CONFIG_NX_TICKS_PER_SECOND 100 +#define CONFIG_NX_TICKS_PER_SECOND 1000 #define CONFIG_NX_PLATFORM_RISCV64_QEMU 1 #define CONFIG_NX_UART0_FROM_SBI 1 #define CONFIG_NX_DRIVER_CONSOLE 1 #define CONFIG_NX_PRINT_BUF_LEN 256 #define CONFIG_NX_DRIVER_ROMDISK 1 -#define CONFIG_NX_DRIVER_ROMDISK_HOSTOS_PATH "../../romdisk.cpio" #define CONFIG_NX_DRIVER_NULL 1 #define CONFIG_NX_DRIVER_ZERO 1 #define CONFIG_NX_DRIVER_MEMINFO 1 diff --git a/src/time/clock.c b/src/time/clock.c index 21a966fe4ca509b1705fca6ca978867fcbb3e97c..c29af47dedb14336f33d54806c72e16d92c48562 100644 --- a/src/time/clock.c +++ b/src/time/clock.c @@ -82,6 +82,16 @@ NX_Error NX_ClockTickDelay(NX_ClockTick ticks) return NX_EOK; } +NX_Error NX_DelayMicrosecond(NX_TimeVal us) +{ + NX_TimeVal start = NX_ClockGetMicrosecond(); + while (NX_ClockGetMicrosecond() < start + us) + { + /* do nothing to delay */ + } + return NX_EOK; +} + NX_PRIVATE void NX_TimerIrqHandler(void *arg) { NX_TimerGo();