mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-24 18:36:24 +04:00
Update sys_time unit to ms && Update clock freq of K210.
This commit is contained in:
parent
62513f62fe
commit
e4fee9944e
@ -5,7 +5,7 @@ pub const APP_BASE_ADDRESS: usize = 0x80100000;
|
|||||||
pub const APP_SIZE_LIMIT: usize = 0x20000;
|
pub const APP_SIZE_LIMIT: usize = 0x20000;
|
||||||
|
|
||||||
#[cfg(feature = "board_k210")]
|
#[cfg(feature = "board_k210")]
|
||||||
pub const CPU_FREQ: usize = 10000000;
|
pub const CLOCK_FREQ: usize = 403000000 / 62;
|
||||||
|
|
||||||
#[cfg(feature = "board_qemu")]
|
#[cfg(feature = "board_qemu")]
|
||||||
pub const CPU_FREQ: usize = 12500000;
|
pub const CLOCK_FREQ: usize = 12500000;
|
@ -2,7 +2,7 @@ use crate::task::{
|
|||||||
suspend_current_and_run_next,
|
suspend_current_and_run_next,
|
||||||
exit_current_and_run_next,
|
exit_current_and_run_next,
|
||||||
};
|
};
|
||||||
use crate::timer::get_time;
|
use crate::timer::get_time_ms;
|
||||||
|
|
||||||
pub fn sys_exit(xstate: i32) -> ! {
|
pub fn sys_exit(xstate: i32) -> ! {
|
||||||
println!("[kernel] Application exited with code {}", xstate);
|
println!("[kernel] Application exited with code {}", xstate);
|
||||||
@ -16,5 +16,5 @@ pub fn sys_yield() -> isize {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn sys_get_time() -> isize {
|
pub fn sys_get_time() -> isize {
|
||||||
get_time() as isize
|
get_time_ms() as isize
|
||||||
}
|
}
|
@ -1,13 +1,18 @@
|
|||||||
use riscv::register::time;
|
use riscv::register::time;
|
||||||
use crate::sbi::set_timer;
|
use crate::sbi::set_timer;
|
||||||
use crate::config::CPU_FREQ;
|
use crate::config::CLOCK_FREQ;
|
||||||
|
|
||||||
const TICKS_PER_SEC: usize = 100;
|
const TICKS_PER_SEC: usize = 100;
|
||||||
|
const MSEC_PER_SEC: usize = 1000;
|
||||||
|
|
||||||
pub fn get_time() -> usize {
|
pub fn get_time() -> usize {
|
||||||
time::read()
|
time::read()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_next_trigger() {
|
pub fn get_time_ms() -> usize {
|
||||||
set_timer(get_time() + CPU_FREQ / TICKS_PER_SEC);
|
time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_next_trigger() {
|
||||||
|
set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
|
||||||
}
|
}
|
@ -9,7 +9,7 @@ use user_lib::{sys_get_time, sys_yield};
|
|||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
fn main() -> i32 {
|
fn main() -> i32 {
|
||||||
let current_timer = sys_get_time();
|
let current_timer = sys_get_time();
|
||||||
let wait_for = current_timer + 10000000;
|
let wait_for = current_timer + 3000;
|
||||||
while sys_get_time() < wait_for {
|
while sys_get_time() < wait_for {
|
||||||
sys_yield();
|
sys_yield();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user