Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 4d05c70dfa7a
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3633671656cc
Choose a head ref
  • 2 commits
  • 18 files changed
  • 1 contributor

Commits on Jan 24, 2017

  1. 2
    Copy the full SHA
    5604d9b View commit details
  2. Copy the full SHA
    3633671 View commit details
24 changes: 20 additions & 4 deletions artiq/firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions artiq/firmware/libboard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -10,3 +10,6 @@ path = "lib.rs"

[dependencies]
log = { version = "0.3", default-features = false }

[features]
uart_console = []
7 changes: 6 additions & 1 deletion artiq/firmware/libboard/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(asm)]
#![feature(asm, lang_items)]
#![no_std]

#[macro_use]
@@ -12,6 +12,8 @@ pub mod spr;
pub mod irq;
pub mod clock;
pub mod uart;
#[cfg(feature = "uart_console")]
pub mod uart_console;

#[cfg(has_i2c)]
pub mod i2c;
@@ -29,6 +31,9 @@ mod ad9154_reg;
#[cfg(has_converter_spi)]
pub mod ad9154;

#[cfg(feature = "uart_console")]
pub use uart_console::Console;

extern {
pub fn flush_cpu_dcache();
pub fn flush_l2_cache();
32 changes: 32 additions & 0 deletions artiq/firmware/libboard/uart_console.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use core::fmt;

pub struct Console;

impl fmt::Write for Console {
fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> {
extern { fn putchar(c: i32) -> i32; }
for c in s.bytes() { unsafe { putchar(c as i32); } }
Ok(())
}
}

#[macro_export]
macro_rules! print {
($($arg:tt)*) => ({
use core::fmt::Write;
write!($crate::uart_console::Console, $($arg)*).unwrap()
})
}

#[macro_export]
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}

#[no_mangle]
#[lang = "panic_fmt"]
pub extern fn panic_fmt(args: fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("panic at {}:{}: {}", file, line, args);
loop {}
}
11 changes: 11 additions & 0 deletions artiq/firmware/libbuild_artiq/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
authors = ["M-Labs"]
name = "build_artiq"
version = "0.0.0"

[lib]
name = "build_artiq"
path = "lib.rs"

[dependencies]
walkdir = "1.0"
48 changes: 48 additions & 0 deletions artiq/firmware/libbuild_artiq/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
extern crate walkdir;

use std::env;
use std::fs::File;
use std::io::{BufRead, BufReader};
use std::path::Path;
use std::process::Command;

use walkdir::WalkDir;

pub fn git_describe() {
let id =
Command::new("git")
.arg("describe")
.arg("--tags")
.arg("--dirty")
.arg("--always")
.arg("--long")
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|mut s| {
let len = s.trim_right().len();
s.truncate(len);
s
})
.unwrap();
let id = id.split("-").collect::<Vec<_>>();
let id = format!("{}+{}.{}", id[0], id[1], id[2]);
println!("cargo:rust-cfg=git_describe={:?}", id);

println!("cargo:rerun-if-changed=../../../.git/HEAD");
for entry in WalkDir::new("../../../.git/refs") {
let entry = entry.unwrap();
println!("cargo:rerun-if-changed={}", entry.path().display());
}
}

pub fn misoc_registers() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());

let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}
}
13 changes: 13 additions & 0 deletions artiq/firmware/liblogger_artiq/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
authors = ["M-Labs"]
name = "logger_artiq"
version = "0.0.0"

[lib]
name = "logger_artiq"
path = "lib.rs"

[dependencies]
log = { version = "0.3", default-features = false, features = [] }
log_buffer = { version = "1.0" }
board = { path = "../libboard" }
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#![no_std]

#[macro_use]
extern crate log;
extern crate log_buffer;
extern crate board;

use core::{mem, ptr};
use core::cell::{Cell, RefCell};
use log::{self, Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter};
use core::fmt::Write;
use log::{Log, LogLevel, LogMetadata, LogRecord, LogLevelFilter};
use log_buffer::LogBuffer;
use board;
use board::{Console, clock};

pub struct BufferLogger {
buffer: RefCell<LogBuffer<&'static mut [u8]>>,
buffer: RefCell<LogBuffer<&'static mut [u8]>>,
trace_to_uart: Cell<bool>
}

unsafe impl Sync for BufferLogger {}

static mut LOGGER: *const BufferLogger = ptr::null();
static mut LOGGER: *const BufferLogger = 0 as *const _;

impl BufferLogger {
pub fn new(buffer: &'static mut [u8]) -> BufferLogger {
@@ -44,11 +50,11 @@ impl BufferLogger {
}

pub fn clear(&self) {
borrow_mut!(self.buffer).clear()
self.buffer.borrow_mut().clear()
}

pub fn extract<R, F: FnOnce(&str) -> R>(&self, f: F) -> R {
f(borrow_mut!(self.buffer).extract())
f(self.buffer.borrow_mut().extract())
}

pub fn disable_trace_to_uart(&self) {
@@ -60,6 +66,9 @@ impl BufferLogger {
}
}

// required for impl Log
unsafe impl Sync for BufferLogger {}

impl Log for BufferLogger {
fn enabled(&self, _metadata: &LogMetadata) -> bool {
true
@@ -69,9 +78,8 @@ impl Log for BufferLogger {
if self.enabled(record.metadata()) {
let force_uart = match self.buffer.try_borrow_mut() {
Ok(mut buffer) => {
use core::fmt::Write;
writeln!(buffer, "[{:12}us] {:>5}({}): {}",
board::clock::get_us(), record.level(),
clock::get_us(), record.level(),
record.target(), record.args()).unwrap();
false
}
@@ -85,8 +93,9 @@ impl Log for BufferLogger {
// Printing to UART is really slow, so avoid doing that when we have an alternative
// route to retrieve the debug messages.
if self.trace_to_uart.get() || record.level() <= LogLevel::Info || force_uart {
println!("[{:12}us] {:>5}({}): {}",
board::clock::get_us(), record.level(), record.target(), record.args());
writeln!(Console, "[{:12}us] {:>5}({}): {}",
clock::get_us(), record.level(),
record.target(), record.args()).unwrap();
}
}
}
12 changes: 6 additions & 6 deletions artiq/firmware/runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -4,21 +4,21 @@ name = "runtime"
version = "0.0.0"
build = "build.rs"

[build-dependencies]
walkdir = "1.0"

[lib]
name = "runtime"
crate-type = ["staticlib"]
path = "lib.rs"

[build-dependencies]
build_artiq = { path = "../libbuild_artiq" }

[dependencies]
alloc_artiq = { path = "../liballoc_artiq" }
std_artiq = { path = "../libstd_artiq", features = ["alloc"] }
board = { path = "../libboard" }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
logger_artiq = { path = "../liblogger_artiq" }
log = { version = "0.3", default-features = false, features = [] }
log_buffer = { version = "1.0" }
board = { path = "../libboard", features = ["uart_console"] }
fringe = { version = "= 1.1.0", default-features = false, features = ["alloc"] }
byteorder = { version = "1.0", default-features = false }

[dependencies.smoltcp]
53 changes: 3 additions & 50 deletions artiq/firmware/runtime/build.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,6 @@
extern crate walkdir;

use std::env;
use std::fs::File;
use std::io::{Write, BufRead, BufReader};
use std::path::Path;
use std::process::Command;

use walkdir::WalkDir;
extern crate build_artiq;

fn main() {
let out_dir = env::var("BUILDINC_DIRECTORY").unwrap();
let cfg_path = Path::new(&out_dir).join("generated").join("rust-cfg");
println!("cargo:rerun-if-changed={}", cfg_path.to_str().unwrap());

let f = BufReader::new(File::open(&cfg_path).unwrap());
for line in f.lines() {
println!("cargo:rustc-cfg={}", line.unwrap());
}

let out_dir = env::var("OUT_DIR").unwrap();
let dest_path = Path::new(&out_dir).join("git_info.rs");
let mut f = File::create(&dest_path).unwrap();

let id = git_describe().unwrap();
let id = id.split("-").collect::<Vec<_>>();
let id = format!("{}+{}.{}", id[0], id[1], id[2]);
writeln!(f, "const GIT_COMMIT: &'static str = {:?};", id).unwrap();

println!("cargo:rerun-if-changed=../../../.git/HEAD");
for entry in WalkDir::new("../../../.git/refs") {
let entry = entry.unwrap();
println!("cargo:rerun-if-changed={}", entry.path().display());
}
}

// Returns `None` if git is not available.
fn git_describe() -> Option<String> {
Command::new("git")
.arg("describe")
.arg("--tags")
.arg("--dirty")
.arg("--always")
.arg("--long")
.output()
.ok()
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|mut s| {
let len = s.trim_right().len();
s.truncate(len);
s
})
build_artiq::git_describe();
build_artiq::misoc_registers();
}
Loading