This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
real time (usually UNIX time) clock support
- Loading branch information
Showing
19 changed files
with
150 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[build] | ||
target-dir = "build" | ||
target = "riscv64gc-unknown-none-elf" | ||
|
||
#[target.riscv64gc-unknown-none-elf] | ||
# rustflags = ["-Clink-arg=-Tlinker.ld","--extern", "__alloc_error_handler=build/liballoc_error_handler.rlib"] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// goldfish.rs | ||
// Authors: 张子辰 <[email protected]> | ||
// Copyright (C) 2022 吴骏东, 张子辰, 蓝俊玮, 郭耸霄 and 陈建绿. | ||
|
||
use super::{RtcDevice, super::Device}; | ||
use core::{slice,str}; | ||
use core::time::Duration; | ||
use crate::device::ioreg_read32; | ||
|
||
const TIME_LOW: usize = 0x00; // R: Get current time, then return low-order 32-bits. | ||
const TIME_HIGH: usize = 0x04; // R: Return high 32-bits, from previous TIME_LOW read. | ||
|
||
pub struct GoldfishRtc { | ||
addr: usize, | ||
name: [u8;32], | ||
name_size: usize, | ||
} | ||
|
||
impl GoldfishRtc { | ||
pub fn new(name: &str, addr: usize) -> Self { | ||
assert!(name.len()<=32); | ||
let mut name1: [u8;32] = [0;32]; | ||
for i in 0..name.len() { | ||
name1[i] = name.as_bytes()[i]; | ||
} | ||
println_bios!("Init goldfish RTC device, name={},addr=0x{:x}.",name,addr); | ||
|
||
Self { | ||
addr, | ||
name: name1, | ||
name_size: name.len() | ||
} | ||
} | ||
|
||
#[inline(always)] | ||
fn reg(&self, r: usize) -> *mut u32{ | ||
(self.addr + r) as *mut u32 | ||
} | ||
|
||
#[inline(always)] | ||
fn reg_read(&self, r: usize) -> u32 { | ||
unsafe{ioreg_read32(self.reg(r))} | ||
} | ||
} | ||
|
||
impl Device for GoldfishRtc { | ||
fn name<'a>(&'a self) -> &'a str { | ||
unsafe {str::from_utf8_unchecked(slice::from_raw_parts(self.name.as_ptr(), self.name_size))} | ||
} | ||
} | ||
|
||
impl RtcDevice for GoldfishRtc { | ||
fn time(&self) -> Duration { | ||
let mut high = self.reg_read(TIME_HIGH); | ||
let mut low = self.reg_read(TIME_LOW); | ||
let high2 = self.reg_read(TIME_HIGH); | ||
if high2 != high { | ||
low = self.reg_read(TIME_LOW); | ||
high = high2; | ||
} | ||
Duration::from_nanos(((high as u64)<<32) + (low as u64)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// rtc/mod.rs | ||
// Authors: 张子辰 <[email protected]> | ||
// Copyright (C) 2022 吴骏东, 张子辰, 蓝俊玮, 郭耸霄 and 陈建绿. | ||
|
||
use super::Device; | ||
use core::time::Duration; | ||
|
||
pub trait RtcDevice: Device { | ||
/// 获取系统时间(通常是UNIX时间) | ||
fn time(&self) -> Duration; | ||
} | ||
|
||
#[cfg(feature="driver_goldfish_rtc")] | ||
pub mod goldfish; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# -*- makefile -*- | ||
.PHONY: @testname@ @[email protected] | ||
@testname@: @[email protected] | ||
qemu-system-riscv64 -machine virt -nographic -bios $$RISCV_BIOS -kernel alloc_buddy0.bin | ||
qemu-system-riscv64 -machine virt -nographic -bios $$RISCV_BIOS -kernel @testname@.bin | ||
|
||
@[email protected]: $(MAKE_ROOT_DIR)/liballoc_error_handler.rlib $(TEST_BUILD_DIR)/deps/liballoc_error_handler.rlib | ||
ifeq ($(MAKE_BUILD_TYPE), release) | ||
cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --release --features rkalloc/__alloc_error_handler | ||
cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --offline --release --features rkalloc/__alloc_error_handler | ||
else | ||
ifeq ($(MAKE_BUILD_TYPE), debug) | ||
cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --features rkalloc/__alloc_error_handler | ||
cd $(TEST_ROOT_DIR)/@testname@ && env RUSTFLAGS="-Clink-arg=-T$(SRC_ROOT_DIR)/linker.ld --extern __alloc_error_handler=$(MAKE_ROOT_DIR)/liballoc_error_handler.rlib" cargo build --offline --features rkalloc/__alloc_error_handler | ||
else | ||
@echo "Unknown build type, expect release/debug." | ||
false | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/sh | ||
|
||
TEST_LIST='alloc_buddy0' | ||
TEST_LIST=$(ls -C $3) | ||
|
||
echo "# Generated by \`$0\` ." > $2 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
[build] | ||
target-dir = "../../build/test" | ||
target = "riscv64gc-unknown-none-elf" | ||
|
||
[target.riscv64gc-unknown-none-elf] | ||
rustflags = ["-Clink-arg=-T../../linker.ld","--extern", "__alloc_error_handler=../../build/liballoc_error_handler.rlib"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build] | ||
target-dir = "../../build/test" | ||
target = "riscv64gc-unknown-none-elf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "test-rkplat_time0" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
rkplat = {path = "../../lib/rkplat", default-features = false, features=["driver_ns16550","driver_goldfish_rtc"]} | ||
rkalloc = {path = "../../lib/rkalloc"} | ||
rkboot = {path = "../../lib/rkboot", default-features = false, features=["alloc_buddy"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![no_std] | ||
#![no_main] | ||
|
||
extern crate rkboot; | ||
#[macro_use] | ||
extern crate rkplat; | ||
|
||
use rkplat::time::{wall_clock,monotonic_clock,get_ticks}; | ||
|
||
#[no_mangle] | ||
fn main(_args: &mut [&str])->i32 { | ||
let time1 = wall_clock(); | ||
let time2 = monotonic_clock(); | ||
let time3 = get_ticks(); | ||
println!("wall_clock()={:?}\nmonotonic_clock()={:?}\nget_ticks()={:?}",time1,time2,time3); | ||
0 | ||
} |