Update from previous chapters.

This commit is contained in:
Yifan Wu 2021-01-06 00:19:10 +08:00
parent 3851c2d561
commit c33c0f8aea
7 changed files with 31 additions and 21 deletions

View file

@ -15,7 +15,7 @@ pub fn kernel_stack_position(app_id: usize) -> (usize, usize) {
}
#[cfg(feature = "board_k210")]
pub const CPU_FREQ: usize = 10000000;
pub const CLOCK_FREQ: usize = 10000000;
#[cfg(feature = "board_qemu")]
pub const CPU_FREQ: usize = 12500000;
pub const CLOCK_FREQ: usize = 12500000;

View file

@ -2,10 +2,10 @@ use crate::task::{
suspend_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) -> ! {
println!("[kernel] Application exited with code {}", xstate);
pub fn sys_exit(exit_code: i32) -> ! {
println!("[kernel] Application exited with code {}", exit_code);
exit_current_and_run_next();
panic!("Unreachable in sys_exit!");
}
@ -16,5 +16,5 @@ pub fn sys_yield() -> isize {
}
pub fn sys_get_time() -> isize {
get_time() as isize
get_time_ms() as isize
}

View file

@ -1,13 +1,18 @@
use riscv::register::time;
use crate::sbi::set_timer;
use crate::config::CPU_FREQ;
use crate::config::CLOCK_FREQ;
const TICKS_PER_SEC: usize = 100;
const MSEC_PER_SEC: usize = 1000;
pub fn get_time() -> usize {
time::read()
}
pub fn get_time_ms() -> usize {
time::read() / (CLOCK_FREQ / MSEC_PER_SEC)
}
pub fn set_next_trigger() {
set_timer(get_time() + CPU_FREQ / TICKS_PER_SEC);
set_timer(get_time() + CLOCK_FREQ / TICKS_PER_SEC);
}