From 9a564e07c0d0a4973db703eb24d86564b4e67c1a Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 16 Dec 2016 21:28:25 +0800 Subject: [PATCH] firmware: make libbsp a crate --- artiq/firmware/libbsp/Cargo.toml | 8 ++++++++ artiq/firmware/libbsp/lib.rs | 4 ++++ artiq/firmware/libksupport/Cargo.lock | 5 +++++ artiq/firmware/libksupport/Cargo.toml | 1 + artiq/firmware/libksupport/i2c.rs | 4 ++-- artiq/firmware/libksupport/lib.rs | 3 +-- artiq/firmware/libksupport/rtio.rs | 2 +- artiq/firmware/runtime/Cargo.lock | 5 +++++ artiq/firmware/runtime/Cargo.toml | 1 + artiq/firmware/runtime/analyzer.rs | 2 +- artiq/firmware/runtime/clock.rs | 4 ++-- artiq/firmware/runtime/kernel.rs | 2 +- artiq/firmware/runtime/lib.rs | 7 +++---- artiq/firmware/runtime/mailbox.rs | 2 +- artiq/firmware/runtime/moninj.rs | 2 +- artiq/firmware/runtime/rpc_queue.rs | 2 +- artiq/firmware/runtime/rtio_mgt.rs | 6 +++--- artiq/firmware/runtime/session.rs | 3 ++- 18 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 artiq/firmware/libbsp/Cargo.toml create mode 100644 artiq/firmware/libbsp/lib.rs diff --git a/artiq/firmware/libbsp/Cargo.toml b/artiq/firmware/libbsp/Cargo.toml new file mode 100644 index 000000000..03adef376 --- /dev/null +++ b/artiq/firmware/libbsp/Cargo.toml @@ -0,0 +1,8 @@ +[package] +authors = ["M-Labs"] +name = "bsp" +version = "0.0.0" + +[lib] +name = "bsp" +path = "lib.rs" diff --git a/artiq/firmware/libbsp/lib.rs b/artiq/firmware/libbsp/lib.rs new file mode 100644 index 000000000..b75091413 --- /dev/null +++ b/artiq/firmware/libbsp/lib.rs @@ -0,0 +1,4 @@ +#![feature(asm)] +#![no_std] + +pub mod board; diff --git a/artiq/firmware/libksupport/Cargo.lock b/artiq/firmware/libksupport/Cargo.lock index df5a6a1bb..d5a6cd619 100644 --- a/artiq/firmware/libksupport/Cargo.lock +++ b/artiq/firmware/libksupport/Cargo.lock @@ -2,6 +2,7 @@ name = "ksupport" version = "0.0.0" dependencies = [ + "bsp 0.0.0", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "std_artiq 0.0.0", ] @@ -10,6 +11,10 @@ dependencies = [ name = "alloc_artiq" version = "0.0.0" +[[package]] +name = "bsp" +version = "0.0.0" + [[package]] name = "byteorder" version = "0.5.3" diff --git a/artiq/firmware/libksupport/Cargo.toml b/artiq/firmware/libksupport/Cargo.toml index ef4484bd4..a20632026 100644 --- a/artiq/firmware/libksupport/Cargo.toml +++ b/artiq/firmware/libksupport/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["staticlib"] [dependencies] std_artiq = { path = "../libstd_artiq" } +bsp = { path = "../libbsp" } byteorder = { version = "0.5", default-features = false } [profile.dev] diff --git a/artiq/firmware/libksupport/i2c.rs b/artiq/firmware/libksupport/i2c.rs index 0f299e6cf..0bbf753ad 100644 --- a/artiq/firmware/libksupport/i2c.rs +++ b/artiq/firmware/libksupport/i2c.rs @@ -1,4 +1,4 @@ -use board::csr; +use bsp::board::csr; fn half_period() { unsafe { @@ -16,7 +16,7 @@ fn half_period() { #[cfg(has_i2c)] mod imp { - use board::csr; + use bsp::board::csr; fn sda_bit(busno: u32) -> u32 { 1 << (2 * busno + 1) } fn scl_bit(busno: u32) -> u32 { 1 << (2 * busno) } diff --git a/artiq/firmware/libksupport/lib.rs b/artiq/firmware/libksupport/lib.rs index 79c3ed82d..4543bce4c 100644 --- a/artiq/firmware/libksupport/lib.rs +++ b/artiq/firmware/libksupport/lib.rs @@ -7,9 +7,8 @@ extern crate std_artiq as std; extern crate libc; extern crate byteorder; +extern crate bsp; -#[path = "../libbsp/board.rs"] -mod board; #[path = "../runtime/mailbox.rs"] mod mailbox; diff --git a/artiq/firmware/libksupport/rtio.rs b/artiq/firmware/libksupport/rtio.rs index b7e8cafd0..fbe9c015a 100644 --- a/artiq/firmware/libksupport/rtio.rs +++ b/artiq/firmware/libksupport/rtio.rs @@ -1,7 +1,7 @@ #[path = "../runtime/kernel_proto.rs"] mod kernel_proto; -use board::csr; +use bsp::board::csr; use core::ptr::{read_volatile, write_volatile}; use ::ArtiqList; use ::send; diff --git a/artiq/firmware/runtime/Cargo.lock b/artiq/firmware/runtime/Cargo.lock index eb4659fcb..bd44fd6fb 100644 --- a/artiq/firmware/runtime/Cargo.lock +++ b/artiq/firmware/runtime/Cargo.lock @@ -2,6 +2,7 @@ name = "runtime" version = "0.0.0" dependencies = [ + "bsp 0.0.0", "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "fringe 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -15,6 +16,10 @@ dependencies = [ name = "alloc_artiq" version = "0.0.0" +[[package]] +name = "bsp" +version = "0.0.0" + [[package]] name = "byteorder" version = "0.5.3" diff --git a/artiq/firmware/runtime/Cargo.toml b/artiq/firmware/runtime/Cargo.toml index e67cd848a..8fb0e1498 100644 --- a/artiq/firmware/runtime/Cargo.toml +++ b/artiq/firmware/runtime/Cargo.toml @@ -15,6 +15,7 @@ path = "lib.rs" [dependencies] std_artiq = { path = "../libstd_artiq", features = ["alloc"] } lwip = { path = "../liblwip", default-features = false } +bsp = { path = "../libbsp" } fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] } log = { version = "0.3", default-features = false, features = ["max_level_debug"] } log_buffer = { version = "1.0" } diff --git a/artiq/firmware/runtime/analyzer.rs b/artiq/firmware/runtime/analyzer.rs index ea126512e..22297c4d3 100644 --- a/artiq/firmware/runtime/analyzer.rs +++ b/artiq/firmware/runtime/analyzer.rs @@ -1,5 +1,5 @@ use std::io::{self, Write}; -use board::{self, csr}; +use bsp::board::{self, csr}; use sched::{Waiter, Spawner}; use sched::{TcpListener, TcpStream, SocketAddr, IP_ANY}; use analyzer_proto::*; diff --git a/artiq/firmware/runtime/clock.rs b/artiq/firmware/runtime/clock.rs index 40e56eea9..4d90e266f 100644 --- a/artiq/firmware/runtime/clock.rs +++ b/artiq/firmware/runtime/clock.rs @@ -1,7 +1,7 @@ -use board::csr; +use bsp::board::csr; const INIT: u64 = ::core::i64::MAX as u64; -const FREQ: u64 = ::board::csr::CONFIG_CLOCK_FREQUENCY as u64; +const FREQ: u64 = csr::CONFIG_CLOCK_FREQUENCY as u64; pub fn init() { unsafe { diff --git a/artiq/firmware/runtime/kernel.rs b/artiq/firmware/runtime/kernel.rs index 5096badc1..4ffb322b0 100644 --- a/artiq/firmware/runtime/kernel.rs +++ b/artiq/firmware/runtime/kernel.rs @@ -1,5 +1,5 @@ use core::ptr; -use board::csr; +use bsp::board::csr; use mailbox; use rpc_queue; diff --git a/artiq/firmware/runtime/lib.rs b/artiq/firmware/runtime/lib.rs index 8d4506721..bce19d2b0 100644 --- a/artiq/firmware/runtime/lib.rs +++ b/artiq/firmware/runtime/lib.rs @@ -11,6 +11,7 @@ extern crate log_buffer; extern crate byteorder; extern crate fringe; extern crate lwip; +extern crate bsp; use core::fmt::Write; use logger::BufferLogger; @@ -55,8 +56,6 @@ extern fn panic_fmt(args: self::core::fmt::Arguments, file: &'static str, line: } } -#[path = "../libbsp/board.rs"] -mod board; mod config; mod clock; mod rtio_mgt; @@ -105,7 +104,7 @@ pub unsafe extern fn rust_main() { clock::init(); info!("booting ARTIQ"); info!("software version {}", GIT_COMMIT); - info!("gateware version {}", ::board::ident(&mut [0; 64])); + info!("gateware version {}", bsp::board::ident(&mut [0; 64])); let t = clock::get_ms(); info!("press 'e' to erase startup and idle kernels..."); @@ -138,7 +137,7 @@ pub unsafe extern fn rust_main() { #[no_mangle] pub unsafe extern fn isr() { - use board::{irq, csr}; + use bsp::board::{irq, csr}; extern { fn uart_isr(); } let irqs = irq::pending() & irq::get_mask(); diff --git a/artiq/firmware/runtime/mailbox.rs b/artiq/firmware/runtime/mailbox.rs index 030b7fb28..2b1a42cbb 100644 --- a/artiq/firmware/runtime/mailbox.rs +++ b/artiq/firmware/runtime/mailbox.rs @@ -1,5 +1,5 @@ use core::ptr::{read_volatile, write_volatile}; -use board; +use bsp::board; const MAILBOX: *mut usize = board::mem::MAILBOX_BASE as *mut usize; static mut last: usize = 0; diff --git a/artiq/firmware/runtime/moninj.rs b/artiq/firmware/runtime/moninj.rs index 4db0aca0f..88f6f370f 100644 --- a/artiq/firmware/runtime/moninj.rs +++ b/artiq/firmware/runtime/moninj.rs @@ -1,6 +1,6 @@ use std::vec::Vec; use std::io; -use board::csr; +use bsp::board::csr; use sched::{Waiter, Spawner}; use sched::{UdpSocket, SocketAddr, IP_ANY}; use moninj_proto::*; diff --git a/artiq/firmware/runtime/rpc_queue.rs b/artiq/firmware/runtime/rpc_queue.rs index 3155813eb..7bac85146 100644 --- a/artiq/firmware/runtime/rpc_queue.rs +++ b/artiq/firmware/runtime/rpc_queue.rs @@ -2,7 +2,7 @@ use core::ptr::{read_volatile, write_volatile}; use core::slice; -use board; +use bsp::board; const SEND_MAILBOX: *mut usize = (board::mem::MAILBOX_BASE + 4) as *mut usize; const RECV_MAILBOX: *mut usize = (board::mem::MAILBOX_BASE + 8) as *mut usize; diff --git a/artiq/firmware/runtime/rtio_mgt.rs b/artiq/firmware/runtime/rtio_mgt.rs index 216706f0a..fc94b7992 100644 --- a/artiq/firmware/runtime/rtio_mgt.rs +++ b/artiq/firmware/runtime/rtio_mgt.rs @@ -1,11 +1,11 @@ use config; -use board::csr; +use bsp::board::csr; use sched::Scheduler; #[cfg(has_rtio_crg)] pub mod crg { use clock; - use board::csr; + use bsp::board::csr; pub fn init() { unsafe { csr::rtio_crg::pll_reset_write(0) } @@ -39,7 +39,7 @@ pub mod crg { #[cfg(has_drtio)] mod drtio { - use board::csr; + use bsp::board::csr; use sched::{Scheduler, Waiter, Spawner}; pub fn startup(scheduler: &Scheduler) { diff --git a/artiq/firmware/runtime/session.rs b/artiq/firmware/runtime/session.rs index cf28202d1..024aade89 100644 --- a/artiq/firmware/runtime/session.rs +++ b/artiq/firmware/runtime/session.rs @@ -10,6 +10,7 @@ use urc::Urc; use sched::{ThreadHandle, Waiter, Spawner}; use sched::{TcpListener, TcpStream, SocketAddr, IP_ANY}; use byteorder::{ByteOrder, NetworkEndian}; +use bsp::board; use rpc_proto as rpc; use session_proto as host; @@ -201,7 +202,7 @@ fn process_host_message(waiter: Waiter, session: &mut Session) -> io::Result<()> { match try!(host_read(stream)) { host::Request::Ident => - host_write(stream, host::Reply::Ident(::board::ident(&mut [0; 64]))), + host_write(stream, host::Reply::Ident(board::ident(&mut [0; 64]))), // artiq_corelog host::Request::Log => {