Merge pull request #9164 from polarvid/shell/rv64-tick

[libcpu/rv64] feat: unify tick.c
This commit is contained in:
Bernard Xiong authored and GitHub committed 2024-07-17 09:58:06 +08:00
commit 019b8cd24b
15 files changed
+801 -167

No files matched your search

+277 -53
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -12,6 +12,7 @@ osource "$PKGS_DIR/Kconfig"
config BOARD_allwinnerd1s
bool
select ARCH_RISCV64
select ARCH_USING_RISCV_COMMON64
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_CACHE
+42 -6
View File
@@ -68,6 +68,7 @@
#define KERNEL_VADDR_START 0x40000000
#define ARCH_RISCV
#define ARCH_RISCV64
#define ARCH_USING_RISCV_COMMON64
/* RT-Thread Components */
@@ -143,6 +144,9 @@
#define RT_SYSTEM_WORKQUEUE_PRIORITY 23
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V2
#define RT_USING_CPUTIME
#define RT_USING_CPUTIME_RISCV
#define CPUTIME_TIMER_FREQ 24000000
#define RT_USING_NULL
#define RT_USING_ZERO
#define RT_USING_RANDOM
@@ -243,6 +247,18 @@
/* Wiced WiFi */
/* end of Wiced WiFi */
/* CYW43012 WiFi */
/* end of CYW43012 WiFi */
/* BL808 WiFi */
/* end of BL808 WiFi */
/* CYW43439 WiFi */
/* end of CYW43439 WiFi */
/* end of Wi-Fi */
/* IoT Cloud */
@@ -274,10 +290,6 @@
/* u8g2: a monochrome graphic library */
/* end of u8g2: a monochrome graphic library */
/* PainterEngine: A cross-platform graphics application framework written in C language */
/* end of PainterEngine: A cross-platform graphics application framework written in C language */
/* end of multimedia packages */
/* tools packages */
@@ -305,16 +317,38 @@
/* peripheral libraries and drivers */
/* HAL & SDK Drivers */
/* STM32 HAL & SDK Drivers */
/* end of STM32 HAL & SDK Drivers */
/* Infineon HAL Packages */
/* end of Infineon HAL Packages */
/* Kendryte SDK */
/* end of Kendryte SDK */
/* end of HAL & SDK Drivers */
/* sensors drivers */
/* end of sensors drivers */
/* touch drivers */
/* end of touch drivers */
/* end of peripheral libraries and drivers */
/* AI packages */
/* end of AI packages */
/* Signal Processing and Control Algorithm Packages */
/* end of Signal Processing and Control Algorithm Packages */
/* miscellaneous packages */
/* project laboratory */
@@ -333,9 +367,9 @@
/* Arduino libraries */
/* Projects */
/* Projects and Demos */
/* end of Projects */
/* end of Projects and Demos */
/* Sensors */
@@ -365,6 +399,8 @@
/* Other */
/* end of Other */
/* Signal IO */
/* end of Signal IO */
+70 -1
View File
@@ -97,6 +97,7 @@ CONFIG_RT_USING_CACHE=y
CONFIG_ARCH_MM_MMU=y
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_RISCV64=y
CONFIG_ARCH_USING_RISCV_COMMON64=y
#
# RT-Thread Components
@@ -184,7 +185,9 @@ CONFIG_RT_USING_SERIAL_V1=y
CONFIG_RT_SERIAL_USING_DMA=y
CONFIG_RT_SERIAL_RB_BUFSZ=64
# CONFIG_RT_USING_CAN is not set
# CONFIG_RT_USING_CPUTIME is not set
CONFIG_RT_USING_CPUTIME=y
CONFIG_RT_USING_CPUTIME_RISCV=y
CONFIG_CPUTIME_TIMER_FREQ=25000000
# CONFIG_RT_USING_I2C is not set
# CONFIG_RT_USING_PHY is not set
# CONFIG_RT_USING_ADC is not set
@@ -1296,6 +1299,72 @@ CONFIG_RT_USING_ADT_REF=y
# end of Arduino libraries
# end of RT-Thread online packages
#
# Privated Packages of RealThread
#
# CONFIG_PKG_USING_CODEC is not set
# CONFIG_PKG_USING_PLAYER is not set
# CONFIG_PKG_USING_MPLAYER is not set
# CONFIG_PKG_USING_PERSIMMON_SRC is not set
# CONFIG_PKG_USING_JS_PERSIMMON is not set
# CONFIG_PKG_USING_JERRYSCRIPT_WIN32 is not set
#
# Network Utilities
#
# CONFIG_PKG_USING_MDNS is not set
# CONFIG_PKG_USING_UPNP is not set
# end of Network Utilities
# CONFIG_PKG_USING_WICED is not set
# CONFIG_PKG_USING_CLOUDSDK is not set
# CONFIG_PKG_USING_POWER_MANAGER is not set
# CONFIG_PKG_USING_RT_OTA is not set
# CONFIG_PKG_USING_RTINSIGHT is not set
# CONFIG_PKG_USING_SMARTCONFIG is not set
# CONFIG_PKG_USING_RTX is not set
# CONFIG_RT_USING_TESTCASE is not set
# CONFIG_PKG_USING_NGHTTP2 is not set
# CONFIG_PKG_USING_AVS is not set
# CONFIG_PKG_USING_ALI_LINKKIT is not set
# CONFIG_PKG_USING_STS is not set
# CONFIG_PKG_USING_DLMS is not set
# CONFIG_PKG_USING_AUDIO_FRAMEWORK is not set
# CONFIG_PKG_USING_ZBAR is not set
# CONFIG_PKG_USING_MCF is not set
# CONFIG_PKG_USING_URPC is not set
# CONFIG_PKG_USING_DCM is not set
# CONFIG_PKG_USING_EMQ is not set
# CONFIG_PKG_USING_CFGM is not set
# CONFIG_PKG_USING_RT_CMSIS_DAP is not set
# CONFIG_PKG_USING_SMODULE is not set
# CONFIG_PKG_USING_SNFD is not set
# CONFIG_PKG_USING_UDBD is not set
# CONFIG_PKG_USING_BENCHMARK is not set
# CONFIG_PKG_USING_UBJSON is not set
# CONFIG_PKG_USING_DATATYPE is not set
# CONFIG_PKG_USING_FASTFS is not set
# CONFIG_PKG_USING_RIL is not set
# CONFIG_PKG_USING_WATCH_DCM_SVC is not set
# CONFIG_PKG_USING_WATCH_APP_FWK is not set
# CONFIG_PKG_USING_GUI_TEST is not set
# CONFIG_PKG_USING_PMEM is not set
# CONFIG_PKG_USING_LWRDP is not set
# CONFIG_PKG_USING_MASAN is not set
# CONFIG_PKG_USING_BSDIFF_LIB is not set
# CONFIG_PKG_USING_PRC_DIFF is not set
#
# RT-Thread Smart
#
# CONFIG_PKG_USING_UKERNEL is not set
# end of RT-Thread Smart
# CONFIG_PKG_USING_TRACE_AGENT is not set
# CONFIG_PKG_USING_DLOG is not set
# CONFIG_PKG_USING_EXT4 is not set
# end of Privated Packages of RealThread
#
# General Drivers Configuration
#
+4 -3
View File
@@ -13,6 +13,7 @@ rsource "board/Kconfig"
config BSP_USING_CV18XX
bool
select ARCH_RISCV64
select ARCH_USING_RISCV_COMMON64
select RT_USING_SYSTEM_WORKQUEUE
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
@@ -26,7 +27,7 @@ config C906_PLIC_PHY_ADDR
default 0x70000000
config IRQ_MAX_NR
int
int
default 64
config TIMER_CLK_FREQ
@@ -40,7 +41,7 @@ config GPIO_IRQ_BASE
config SYS_GPIO_IRQ_BASE
int
default 70
config __STACKSIZE__
int "stack size for interrupt"
default 4096
@@ -72,5 +73,5 @@ choice
config BOARD_TYPE_MILKV_DUO256M_SPINOR
select SOC_TYPE_SG2002
bool "milkv-duo256m-spinor"
endchoice
+16
View File
@@ -63,6 +63,7 @@
#define ARCH_MM_MMU
#define ARCH_RISCV
#define ARCH_RISCV64
#define ARCH_USING_RISCV_COMMON64
/* RT-Thread Components */
@@ -123,6 +124,9 @@
#define RT_USING_SERIAL_V1
#define RT_SERIAL_USING_DMA
#define RT_SERIAL_RB_BUFSZ 64
#define RT_USING_CPUTIME
#define RT_USING_CPUTIME_RISCV
#define CPUTIME_TIMER_FREQ 25000000
#define RT_USING_NULL
#define RT_USING_ZERO
#define RT_USING_RANDOM
@@ -435,6 +439,18 @@
/* end of Arduino libraries */
/* end of RT-Thread online packages */
/* Privated Packages of RealThread */
/* Network Utilities */
/* end of Network Utilities */
/* RT-Thread Smart */
/* end of RT-Thread Smart */
/* end of Privated Packages of RealThread */
/* General Drivers Configuration */
#define BSP_USING_UART
File diff suppressed because it is too large. Load diff
+1
View File
@@ -14,6 +14,7 @@ config BOARD_QEMU_VIRT_RV64
bool
select ARCH_RISCV64
select ARCH_CONTEXT_EXTEND
select ARCH_USING_RISCV_COMMON64
select RT_USING_COMPONENTS_INIT
select RT_USING_USER_MAIN
select RT_USING_CACHE
+39 -6
View File
@@ -71,6 +71,7 @@
#define ARCH_MM_MMU
#define ARCH_RISCV
#define ARCH_RISCV64
#define ARCH_USING_RISCV_COMMON64
#define ARCH_REMAP_KERNEL
/* RT-Thread Components */
@@ -290,6 +291,18 @@
/* Wiced WiFi */
/* end of Wiced WiFi */
/* CYW43012 WiFi */
/* end of CYW43012 WiFi */
/* BL808 WiFi */
/* end of BL808 WiFi */
/* CYW43439 WiFi */
/* end of CYW43439 WiFi */
/* end of Wi-Fi */
/* IoT Cloud */
@@ -321,10 +334,6 @@
/* u8g2: a monochrome graphic library */
/* end of u8g2: a monochrome graphic library */
/* PainterEngine: A cross-platform graphics application framework written in C language */
/* end of PainterEngine: A cross-platform graphics application framework written in C language */
/* end of multimedia packages */
/* tools packages */
@@ -352,16 +361,38 @@
/* peripheral libraries and drivers */
/* HAL & SDK Drivers */
/* STM32 HAL & SDK Drivers */
/* end of STM32 HAL & SDK Drivers */
/* Infineon HAL Packages */
/* end of Infineon HAL Packages */
/* Kendryte SDK */
/* end of Kendryte SDK */
/* end of HAL & SDK Drivers */
/* sensors drivers */
/* end of sensors drivers */
/* touch drivers */
/* end of touch drivers */
/* end of peripheral libraries and drivers */
/* AI packages */
/* end of AI packages */
/* Signal Processing and Control Algorithm Packages */
/* end of Signal Processing and Control Algorithm Packages */
/* miscellaneous packages */
/* project laboratory */
@@ -380,9 +411,9 @@
/* Arduino libraries */
/* Projects */
/* Projects and Demos */
/* end of Projects */
/* end of Projects and Demos */
/* Sensors */
@@ -412,6 +443,8 @@
/* Other */
/* end of Other */
/* Signal IO */
/* end of Signal IO */
@@ -31,4 +31,8 @@ uint64_t clock_cpu_millisecond(uint64_t cpu_tick);
int clock_cpu_setops(const struct rt_clock_cputime_ops *ops);
#ifdef RT_USING_CPUTIME_RISCV
int riscv_cputime_init(void);
#endif /* RT_USING_CPUTIME_RISCV */
#endif
+9
View File
@@ -262,6 +262,15 @@ config ARCH_RISCV64
select ARCH_CPU_64BIT
bool
if ARCH_RISCV64
config ARCH_USING_RISCV_COMMON64
bool
depends on ARCH_RISCV64
select RT_USING_CPUTIME
help
Using the common64 implementation under ./libcpu/risc-v
endif
config ARCH_REMAP_KERNEL
bool
depends on RT_USING_SMART
+25 -19
View File
@@ -6,44 +6,50 @@
* Change Logs:
* Date Author Notes
* 2018/10/28 Bernard The unify RISC-V porting code.
* 2024/07/08 Shell Using CPUTIME as tick
*/
#include <rthw.h>
#include <rtthread.h>
#include <drivers/cputime.h>
#include <encoding.h>
#include "sbi.h"
#include "tick.h"
static volatile uint64_t time_elapsed = 0;
#ifdef RT_USING_KTIME
#include <ktime.h>
#endif
static volatile unsigned long tick_cycles = 0;
static unsigned long tick_delta = TIMER_CLK_FREQ / RT_TICK_PER_SECOND;
static uint64_t get_ticks()
{
__asm__ __volatile__(
"rdtime %0"
: "=r"(time_elapsed));
return time_elapsed;
}
int tick_isr(void)
{
rt_tick_increase();
sbi_set_timer(get_ticks() + tick_delta);
sbi_set_timer(clock_cpu_gettime() + tick_cycles);
return 0;
}
/* BSP should config clockbase frequency */
RT_STATIC_ASSERT(defined_clockbase_freq, CPUTIME_TIMER_FREQ != 0);
/* Sets and enable the timer interrupt */
int rt_hw_tick_init(void)
{
/* calculate the tick cycles */
tick_cycles = CPUTIME_TIMER_FREQ / RT_TICK_PER_SECOND;
/* Clear the Supervisor-Timer bit in SIE */
clear_csr(sie, SIP_STIP);
/* Set timer */
sbi_set_timer(get_ticks() + tick_delta);
/* Init riscv timer */
riscv_cputime_init();
/* Set timer */
sbi_set_timer(clock_cpu_gettime() + tick_cycles);
#ifdef RT_USING_KTIME
rt_ktime_cputimer_init();
#endif
/* Enable the Supervisor-Timer bit in SIE */
set_csr(sie, SIP_STIP);
@@ -61,10 +67,10 @@ void rt_hw_us_delay(rt_uint32_t us)
unsigned long end_time;
unsigned long run_time;
start_time = get_ticks();
end_time = start_time + us * (TIMER_CLK_FREQ / 1000000);
start_time = clock_cpu_gettime();
end_time = start_time + us * (CPUTIME_TIMER_FREQ / 1000000);
do
{
run_time = get_ticks();
run_time = clock_cpu_gettime();
} while(run_time < end_time);
}
}
+1 -5
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -11,10 +11,6 @@
#ifndef TICK_H__
#define TICK_H__
/* timer clock is 24 MHZ */
#ifndef TIMER_CLK_FREQ
#define TIMER_CLK_FREQ (24000000)
#endif
int tick_isr(void);
int rt_hw_tick_init(void);
+31 -18
View File
@@ -6,11 +6,13 @@
* Change Logs:
* Date Author Notes
* 2018/10/28 Bernard The unify RISC-V porting code.
* 2024/07/08 Shell Using CPUTIME as tick
*/
#include <rthw.h>
#include <rtthread.h>
#include <drivers/cputime.h>
#include <encoding.h>
#include "sbi.h"
@@ -18,40 +20,32 @@
#include <ktime.h>
#endif
static volatile uint64_t time_elapsed = 0;
static volatile unsigned long tick_cycles = 0;
static uint64_t get_ticks()
{
__asm__ __volatile__(
"rdtime %0"
: "=r"(time_elapsed));
return time_elapsed;
}
int tick_isr(void)
{
// uint64_t core_id = current_coreid();
// clint->mtimecmp[core_id] += tick_cycles;
rt_tick_increase();
sbi_set_timer(get_ticks() + tick_cycles);
sbi_set_timer(clock_cpu_gettime() + tick_cycles);
return 0;
}
/* BSP should config clockbase frequency */
RT_STATIC_ASSERT(defined_clockbase_freq, CPUTIME_TIMER_FREQ != 0);
/* Sets and enable the timer interrupt */
int rt_hw_tick_init(void)
{
/* Read core id */
// unsigned long core_id = current_coreid();
/* calculate the tick cycles */
tick_cycles = CPUTIME_TIMER_FREQ / RT_TICK_PER_SECOND;
/* Clear the Supervisor-Timer bit in SIE */
clear_csr(sie, SIP_STIP);
/* calculate the tick cycles */
tick_cycles = CPUTIME_TIMER_FREQ / RT_TICK_PER_SECOND;
/* Init riscv timer */
riscv_cputime_init();
/* Set timer */
sbi_set_timer(get_ticks() + tick_cycles);
sbi_set_timer(clock_cpu_gettime() + tick_cycles);
#ifdef RT_USING_KTIME
rt_ktime_cputimer_init();
@@ -61,3 +55,22 @@ int rt_hw_tick_init(void)
return 0;
}
/**
* This function will delay for some us.
*
* @param us the delay time of us
*/
void rt_hw_us_delay(rt_uint32_t us)
{
unsigned long start_time;
unsigned long end_time;
unsigned long run_time;
start_time = clock_cpu_gettime();
end_time = start_time + us * (CPUTIME_TIMER_FREQ / 1000000);
do
{
run_time = clock_cpu_gettime();
} while(run_time < end_time);
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
* Copyright (c) 2006-2024, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*