From 9a50de8b4ef47e26f591e157f9ba98ec13af3cc4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Mon, 12 Oct 2020 03:56:10 +0800 Subject: [PATCH] refactor: utra -> utralib naming this cleans up some namespace issues when including the utra crate which also refers to utra::generated::utra, and there are CONST at the crate-level, and also functions at the module-level which need disambiguation. By naming the crate utra-lib this saves a bit of syntatic wrangling at the top of every file. --- Cargo.lock | 6 +++--- examples/graphics-server/Cargo.toml | 2 +- examples/graphics-server/src/backend/betrusted.rs | 6 +++--- examples/shell/Cargo.toml | 2 +- examples/shell/src/main.rs | 2 ++ examples/shell/src/timer.rs | 8 +++++--- kernel/Cargo.lock | 4 ++-- kernel/Cargo.toml | 2 +- kernel/src/main.rs | 3 ++- svd2utra/src/generate.rs | 4 ++-- {utra => utralib}/.gitignore | 0 {utra => utralib}/Cargo.lock | 0 {utra => utralib}/Cargo.toml | 2 +- {utra => utralib}/README.md | 0 {utra => utralib}/build.rs | 0 {utra => utralib}/src/lib.rs | 2 +- 16 files changed, 24 insertions(+), 19 deletions(-) rename {utra => utralib}/.gitignore (100%) rename {utra => utralib}/Cargo.lock (100%) rename {utra => utralib}/Cargo.toml (93%) rename {utra => utralib}/README.md (100%) rename {utra => utralib}/build.rs (100%) rename {utra => utralib}/src/lib.rs (76%) diff --git a/Cargo.lock b/Cargo.lock index 51ba133d3..904d46de2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -213,7 +213,7 @@ version = "0.1.0" dependencies = [ "embedded-graphics", "minifb", - "utra", + "utralib", "xous", ] @@ -720,7 +720,7 @@ version = "0.1.0" dependencies = [ "bitflags", "graphics-server", - "utra", + "utralib", "xous", ] @@ -824,7 +824,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] -name = "utra" +name = "utralib" version = "0.1.0" dependencies = [ "svd2utra", diff --git a/examples/graphics-server/Cargo.toml b/examples/graphics-server/Cargo.toml index 637a37363..9e2ac4b26 100644 --- a/examples/graphics-server/Cargo.toml +++ b/examples/graphics-server/Cargo.toml @@ -10,7 +10,7 @@ xous = { path = "../../xous-rs" } embedded-graphics = "0.6" [target.'cfg(not(any(windows,unix)))'.dependencies] -utra = { path = "../../utra"} +utralib = { path = "../../utralib"} [target.'cfg(any(windows,unix))'.dependencies] minifb = "0.17" diff --git a/examples/graphics-server/src/backend/betrusted.rs b/examples/graphics-server/src/backend/betrusted.rs index 26694ab0d..7c33d9f74 100644 --- a/examples/graphics-server/src/backend/betrusted.rs +++ b/examples/graphics-server/src/backend/betrusted.rs @@ -1,6 +1,6 @@ use embedded_graphics::{drawable::Pixel, geometry::Size, pixelcolor::BinaryColor, DrawTarget}; use xous::MemoryRange; -use utra; +use utralib::generated::*; const FB_WIDTH_WORDS: usize = 11; const FB_WIDTH_PIXELS: usize = 336; @@ -20,7 +20,7 @@ pub struct XousDisplay { impl XousDisplay { pub fn new() -> XousDisplay { let fb = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::HW_MEMLCD_MEM), + xous::MemoryAddress::new(HW_MEMLCD_MEM), None, ((FB_WIDTH_WORDS * FB_LINES * 4) + 4096) & !4095, xous::MemoryFlags::R | xous::MemoryFlags::W, @@ -28,7 +28,7 @@ impl XousDisplay { .expect("couldn't map frame buffer"); let control = xous::syscall::map_memory( - xous::MemoryAddress::new(utra::HW_MEMLCD_BASE), + xous::MemoryAddress::new(HW_MEMLCD_BASE), None, 4096, xous::MemoryFlags::R | xous::MemoryFlags::W, diff --git a/examples/shell/Cargo.toml b/examples/shell/Cargo.toml index 381b172b6..4cfee6125 100644 --- a/examples/shell/Cargo.toml +++ b/examples/shell/Cargo.toml @@ -11,4 +11,4 @@ xous = { path = "../../xous-rs" } graphics-server = { path = "../graphics-server" } [target.'cfg(not(any(windows,unix)))'.dependencies] -utra = { path = "../../utra"} +utralib = { path = "../../utralib"} diff --git a/examples/shell/src/main.rs b/examples/shell/src/main.rs index 56ab1217f..7d6bdc487 100644 --- a/examples/shell/src/main.rs +++ b/examples/shell/src/main.rs @@ -16,6 +16,8 @@ mod timer; // } // } +extern crate utralib; + fn move_lfsr(mut lfsr: u32) -> u32 { lfsr ^= lfsr >> 7; lfsr ^= lfsr << 9; diff --git a/examples/shell/src/timer.rs b/examples/shell/src/timer.rs index 1b750b126..1fd5f4b82 100644 --- a/examples/shell/src/timer.rs +++ b/examples/shell/src/timer.rs @@ -4,6 +4,8 @@ const SYSTEM_CLOCK_FREQUENCY: u32 = 100_000_000; #[cfg(baremetal)] const TIMER_BASE: usize = 0xF000_3000; +use utralib::generated::*; + #[cfg(baremetal)] fn timer_tick(_irq_no: usize, _arg: *mut usize) { println!(">>> Timer tick"); @@ -21,7 +23,7 @@ pub fn init() { use xous::{MemoryAddress, MemorySize}; println!("Allocating timer..."); xous::rsyscall(xous::SysCall::MapMemory( - MemoryAddress::new(utra::HW_TIMER0_BASE), + MemoryAddress::new(HW_TIMER0_BASE), MemoryAddress::new(TIMER_BASE), MemorySize::new(4096).unwrap(), xous::MemoryFlags::R | xous::MemoryFlags::W, @@ -42,8 +44,8 @@ pub fn init() { en(true); // Set EV_ENABLE - let ptr = TIMER_BASE as *mut usize; - unsafe { ptr.add(7).write_volatile(1) }; + let mut timer = CSR::new(TIMER_BASE as *mut u32); + unsafe { timer.wfo(utra::timer0::EV_ENABLE_ENABLE, 0b1); } } #[cfg(not(baremetal))] diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 470b771a9..8644d6bb7 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -218,7 +218,7 @@ dependencies = [ "riscv", "sha3", "stats_alloc", - "utra", + "utralib", "xous", ] @@ -458,7 +458,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] -name = "utra" +name = "utralib" version = "0.1.0" dependencies = [ "svd2utra", diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 05505f481..f87c73480 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -12,7 +12,7 @@ stats_alloc = { version = "0.1.8", optional = true } sha3 = { default-features = false, version = "0.8.2" } [target.'cfg(not(any(windows, unix)))'.dependencies] -utra = { path = "../utra"} +utralib = { path = "../utralib"} [target.'cfg(target_arch = "riscv32")'.dependencies] riscv = "0.5.6" diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 1a6b624c7..d45b6cbf6 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -25,6 +25,7 @@ mod syscall; use services::SystemServices; use xous_kernel::*; +use utralib::generated::*; #[cfg(baremetal)] use core::panic::PanicInfo; @@ -64,7 +65,7 @@ pub extern "C" fn init(arg_offset: *const u32, init_offset: *const u32, rpt_offs mem::MemoryManager::with_mut(|memory_manager| { memory_manager .map_range( - utra::HW_UART_BASE as *mut u8, + HW_UART_BASE as *mut u8, ((debug::SUPERVISOR_UART.base as u32) & !4095) as *mut u8, 4096, PID::new(1).unwrap(), diff --git a/svd2utra/src/generate.rs b/svd2utra/src/generate.rs index db0082b60..8d003c0f6 100644 --- a/svd2utra/src/generate.rs +++ b/svd2utra/src/generate.rs @@ -588,7 +588,7 @@ fn print_peripherals(peripherals: &[Peripheral], out: &mut U) -> std:: for peripheral in peripherals { writeln!( out, - "pub const HW_{}_BASE : usize = {};", + "pub const HW_{}_BASE : usize = 0x{:08x};", peripheral.name.to_uppercase(), peripheral.base )?; } @@ -606,7 +606,7 @@ fn print_peripherals(peripherals: &[Peripheral], out: &mut U) -> std:: writeln!( out, " pub const {}: crate::Register = crate::Register::new({});", - register.name.to_uppercase(), register.offset + register.name.to_uppercase(), register.offset / 4 )?; for field in ®ister.fields { writeln!( diff --git a/utra/.gitignore b/utralib/.gitignore similarity index 100% rename from utra/.gitignore rename to utralib/.gitignore diff --git a/utra/Cargo.lock b/utralib/Cargo.lock similarity index 100% rename from utra/Cargo.lock rename to utralib/Cargo.lock diff --git a/utra/Cargo.toml b/utralib/Cargo.toml similarity index 93% rename from utra/Cargo.toml rename to utralib/Cargo.toml index 7eccd1e7b..981419f70 100644 --- a/utra/Cargo.toml +++ b/utralib/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "utra" +name = "utralib" version = "0.1.0" authors = ["Sean Cross "] edition = "2018" diff --git a/utra/README.md b/utralib/README.md similarity index 100% rename from utra/README.md rename to utralib/README.md diff --git a/utra/build.rs b/utralib/build.rs similarity index 100% rename from utra/build.rs rename to utralib/build.rs diff --git a/utra/src/lib.rs b/utralib/src/lib.rs similarity index 76% rename from utra/src/lib.rs rename to utralib/src/lib.rs index 09f3a9355..6cf78339f 100644 --- a/utra/src/lib.rs +++ b/utralib/src/lib.rs @@ -1,3 +1,3 @@ #![cfg_attr(target_os = "none", no_std)] -mod generated; +pub mod generated; pub use generated::*;