2016-08-17 16:39:05 +08:00
|
|
|
#![no_std]
|
2016-12-31 21:34:42 +08:00
|
|
|
#![feature(libc, const_fn, repr_simd, asm, lang_items)]
|
2016-08-17 16:39:05 +08:00
|
|
|
|
2016-12-31 21:26:31 +08:00
|
|
|
extern crate alloc_artiq;
|
2016-08-17 16:39:05 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate std_artiq as std;
|
2016-09-30 02:54:08 +08:00
|
|
|
extern crate libc;
|
2016-09-29 02:25:25 +08:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
|
|
|
extern crate log_buffer;
|
2016-09-27 21:36:55 +08:00
|
|
|
extern crate byteorder;
|
2016-10-02 12:37:24 +08:00
|
|
|
extern crate fringe;
|
|
|
|
extern crate lwip;
|
2016-12-31 21:32:50 +08:00
|
|
|
extern crate board;
|
2016-08-17 16:39:05 +08:00
|
|
|
|
2016-10-30 05:34:25 +08:00
|
|
|
use core::fmt::Write;
|
2016-09-30 04:56:35 +08:00
|
|
|
use logger::BufferLogger;
|
2016-08-30 19:20:04 +08:00
|
|
|
|
2016-10-30 05:34:25 +08:00
|
|
|
extern {
|
|
|
|
fn putchar(c: libc::c_int) -> libc::c_int;
|
|
|
|
fn readchar() -> libc::c_char;
|
2016-11-22 22:45:40 +08:00
|
|
|
fn readchar_nonblock() -> libc::c_int;
|
2016-10-30 05:34:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! print {
|
|
|
|
($($arg:tt)*) => ($crate::print_fmt(format_args!($($arg)*)));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! println {
|
|
|
|
($fmt:expr) => (print!(concat!($fmt, "\n")));
|
|
|
|
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Console;
|
|
|
|
|
|
|
|
impl core::fmt::Write for Console {
|
|
|
|
fn write_str(&mut self, s: &str) -> Result<(), core::fmt::Error> {
|
|
|
|
for c in s.bytes() { unsafe { putchar(c as i32); } }
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn print_fmt(args: self::core::fmt::Arguments) {
|
|
|
|
let _ = Console.write_fmt(args);
|
|
|
|
}
|
|
|
|
|
2016-12-27 01:18:18 +08:00
|
|
|
#[no_mangle]
|
2016-10-30 05:34:25 +08:00
|
|
|
#[lang = "panic_fmt"]
|
2016-12-27 01:18:18 +08:00
|
|
|
pub extern fn panic_fmt(args: self::core::fmt::Arguments, file: &'static str, line: u32) -> ! {
|
2016-10-30 05:34:25 +08:00
|
|
|
let _ = write!(Console, "panic at {}:{}: {}\n", file, line, args);
|
|
|
|
let _ = write!(Console, "waiting for debugger...\n");
|
|
|
|
unsafe {
|
|
|
|
let _ = readchar();
|
|
|
|
loop { asm!("l.trap 0") }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-30 04:56:35 +08:00
|
|
|
mod config;
|
2016-12-09 19:24:00 +08:00
|
|
|
mod rtio_mgt;
|
2016-09-30 08:15:20 +08:00
|
|
|
mod mailbox;
|
2016-10-30 05:34:25 +08:00
|
|
|
mod rpc_queue;
|
2016-09-30 04:56:35 +08:00
|
|
|
|
2016-10-02 12:37:24 +08:00
|
|
|
mod urc;
|
|
|
|
mod sched;
|
2016-09-30 04:56:35 +08:00
|
|
|
mod logger;
|
2016-10-02 02:24:53 +08:00
|
|
|
mod cache;
|
2016-09-30 04:56:35 +08:00
|
|
|
|
2016-10-04 20:38:52 +08:00
|
|
|
mod proto;
|
2016-10-01 12:20:27 +08:00
|
|
|
mod kernel_proto;
|
2016-09-30 04:56:35 +08:00
|
|
|
mod session_proto;
|
2016-10-04 20:38:52 +08:00
|
|
|
mod moninj_proto;
|
2016-10-05 13:59:38 +08:00
|
|
|
mod analyzer_proto;
|
2016-10-30 05:34:25 +08:00
|
|
|
mod rpc_proto;
|
2016-10-01 12:20:27 +08:00
|
|
|
|
|
|
|
mod kernel;
|
2016-09-30 04:56:35 +08:00
|
|
|
mod session;
|
2016-11-06 23:52:27 +08:00
|
|
|
#[cfg(has_rtio_moninj)]
|
2016-10-04 20:38:52 +08:00
|
|
|
mod moninj;
|
2016-10-05 13:59:38 +08:00
|
|
|
#[cfg(has_rtio_analyzer)]
|
|
|
|
mod analyzer;
|
2016-09-07 00:42:13 +08:00
|
|
|
|
|
|
|
extern {
|
|
|
|
fn network_init();
|
|
|
|
fn lwip_service();
|
|
|
|
}
|
|
|
|
|
2016-09-30 06:04:52 +08:00
|
|
|
include!(concat!(env!("OUT_DIR"), "/git_info.rs"));
|
|
|
|
|
2016-10-30 05:34:25 +08:00
|
|
|
// Allow linking with crates that are built as -Cpanic=unwind even if we use -Cpanic=abort.
|
|
|
|
// This is never called.
|
|
|
|
#[allow(non_snake_case)]
|
|
|
|
#[no_mangle]
|
|
|
|
pub extern "C" fn _Unwind_Resume() -> ! {
|
|
|
|
loop {}
|
|
|
|
}
|
|
|
|
|
2016-08-17 16:39:05 +08:00
|
|
|
#[no_mangle]
|
2016-09-07 00:42:13 +08:00
|
|
|
pub unsafe extern fn rust_main() {
|
2016-11-13 04:16:25 +08:00
|
|
|
static mut LOG_BUFFER: [u8; 65536] = [0; 65536];
|
2016-10-02 12:37:24 +08:00
|
|
|
BufferLogger::new(&mut LOG_BUFFER[..])
|
|
|
|
.register(move || {
|
2017-01-02 01:23:27 +08:00
|
|
|
board::clock::init();
|
2016-11-22 22:45:40 +08:00
|
|
|
info!("booting ARTIQ");
|
2016-10-04 14:08:08 +08:00
|
|
|
info!("software version {}", GIT_COMMIT);
|
2016-12-31 21:32:50 +08:00
|
|
|
info!("gateware version {}", board::ident(&mut [0; 64]));
|
2016-09-30 06:04:52 +08:00
|
|
|
|
2017-01-02 01:23:27 +08:00
|
|
|
let t = board::clock::get_ms();
|
2016-11-22 22:45:40 +08:00
|
|
|
info!("press 'e' to erase startup and idle kernels...");
|
2017-01-02 01:23:27 +08:00
|
|
|
while board::clock::get_ms() < t + 1000 {
|
2016-11-22 22:45:40 +08:00
|
|
|
if readchar_nonblock() != 0 && readchar() == b'e' as libc::c_char {
|
|
|
|
config::remove("startup_kernel");
|
|
|
|
config::remove("idle_kernel");
|
|
|
|
info!("startup and idle kernels erased");
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info!("continuing boot");
|
|
|
|
|
2017-01-03 23:11:38 +08:00
|
|
|
#[cfg(has_ad9516)]
|
|
|
|
board::ad9516::init().unwrap();
|
|
|
|
#[cfg(has_converter_spi)]
|
|
|
|
board::ad9154::init().unwrap();
|
2016-09-29 02:25:25 +08:00
|
|
|
network_init();
|
2016-09-07 00:42:13 +08:00
|
|
|
|
2016-09-30 04:56:35 +08:00
|
|
|
let mut scheduler = sched::Scheduler::new();
|
2016-12-09 19:24:00 +08:00
|
|
|
rtio_mgt::startup(&scheduler);
|
2016-10-05 22:15:53 +08:00
|
|
|
scheduler.spawner().spawn(16384, session::thread);
|
2016-11-06 23:52:27 +08:00
|
|
|
#[cfg(has_rtio_moninj)]
|
2016-10-04 20:38:52 +08:00
|
|
|
scheduler.spawner().spawn(4096, moninj::thread);
|
2016-10-05 13:59:38 +08:00
|
|
|
#[cfg(has_rtio_analyzer)]
|
|
|
|
scheduler.spawner().spawn(4096, analyzer::thread);
|
2016-10-01 12:20:27 +08:00
|
|
|
|
2016-09-29 02:25:25 +08:00
|
|
|
loop {
|
2016-10-02 12:37:24 +08:00
|
|
|
scheduler.run();
|
2016-09-29 02:25:25 +08:00
|
|
|
lwip_service();
|
|
|
|
}
|
|
|
|
})
|
2016-08-17 16:39:05 +08:00
|
|
|
}
|
2016-10-06 23:35:43 +08:00
|
|
|
|
2016-10-07 14:27:10 +08:00
|
|
|
#[no_mangle]
|
|
|
|
pub unsafe extern fn isr() {
|
2016-12-31 21:32:50 +08:00
|
|
|
use board::{irq, csr};
|
2016-10-07 14:27:10 +08:00
|
|
|
extern { fn uart_isr(); }
|
|
|
|
|
|
|
|
let irqs = irq::pending() & irq::get_mask();
|
|
|
|
if irqs & (1 << csr::UART_INTERRUPT) != 0 {
|
|
|
|
uart_isr()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 23:35:43 +08:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn sys_now() -> u32 {
|
2017-01-02 01:23:27 +08:00
|
|
|
board::clock::get_ms() as u32
|
2016-10-06 23:35:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn sys_jiffies() -> u32 {
|
2017-01-02 01:23:27 +08:00
|
|
|
board::clock::get_ms() as u32
|
2016-10-06 23:35:43 +08:00
|
|
|
}
|