2020-04-11 20:19:39 +08:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
|
|
|
|
extern crate alloc;
|
|
|
|
|
2020-04-11 21:32:44 +08:00
|
|
|
use core::{cmp, str};
|
2020-04-11 22:24:23 +08:00
|
|
|
|
|
|
|
use libboard_zynq::{
|
|
|
|
println,
|
|
|
|
self as zynq, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll},
|
|
|
|
};
|
2020-04-13 13:48:08 +08:00
|
|
|
use libsupport_zynq::{ram, boot};
|
|
|
|
use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}};
|
2020-04-11 21:32:44 +08:00
|
|
|
|
2020-04-13 13:48:08 +08:00
|
|
|
mod comms;
|
2020-04-11 21:32:44 +08:00
|
|
|
mod pl;
|
2020-04-12 20:15:01 +08:00
|
|
|
mod rtio;
|
2020-04-13 13:48:08 +08:00
|
|
|
mod kernel;
|
|
|
|
|
2020-04-11 21:32:44 +08:00
|
|
|
|
|
|
|
fn identifier_read(buf: &mut [u8]) -> &str {
|
|
|
|
unsafe {
|
|
|
|
pl::csr::identifier::address_write(0);
|
|
|
|
let len = pl::csr::identifier::data_read();
|
|
|
|
let len = cmp::min(len, buf.len() as u8);
|
|
|
|
for i in 0..len {
|
|
|
|
pl::csr::identifier::address_write(1 + i);
|
|
|
|
buf[i as usize] = pl::csr::identifier::data_read();
|
|
|
|
}
|
|
|
|
str::from_utf8_unchecked(&buf[..len as usize])
|
|
|
|
}
|
|
|
|
}
|
2020-04-11 20:19:39 +08:00
|
|
|
|
2020-04-13 13:48:08 +08:00
|
|
|
static mut STACK_CORE1: [u32; 512] = [0; 512];
|
|
|
|
static CHANNEL_0TO1: Mutex<Option<sync_channel::Receiver<usize>>> = Mutex::new(None);
|
|
|
|
static CHANNEL_1TO0: Mutex<Option<sync_channel::Sender<usize>>> = Mutex::new(None);
|
|
|
|
|
2020-04-11 20:19:39 +08:00
|
|
|
#[no_mangle]
|
|
|
|
pub fn main_core0() {
|
2020-04-11 22:24:23 +08:00
|
|
|
println!("ARTIQ runtime starting...");
|
|
|
|
|
|
|
|
const CPU_FREQ: u32 = 800_000_000;
|
|
|
|
|
|
|
|
ArmPll::setup(2 * CPU_FREQ);
|
|
|
|
Clocks::set_cpu_freq(CPU_FREQ);
|
|
|
|
IoPll::setup(1_000_000_000);
|
2020-04-12 10:38:52 +08:00
|
|
|
libboard_zynq::stdio::drop_uart(); // reinitialize UART after clocking change
|
2020-04-11 22:24:23 +08:00
|
|
|
let mut ddr = zynq::ddr::DdrRam::new();
|
|
|
|
ram::init_alloc(&mut ddr);
|
|
|
|
|
|
|
|
println!("Detected gateware: {}", identifier_read(&mut [0; 64]));
|
|
|
|
|
2020-04-13 13:48:08 +08:00
|
|
|
let core1_stack = unsafe { &mut STACK_CORE1[..] };
|
|
|
|
let core1 = boot::Core1::start(core1_stack);
|
|
|
|
|
|
|
|
let (mut core0_tx, core1_rx) = sync_channel(4);
|
|
|
|
let (core1_tx, mut core0_rx) = sync_channel(4);
|
|
|
|
*CHANNEL_0TO1.lock() = Some(core1_rx);
|
|
|
|
*CHANNEL_1TO0.lock() = Some(core1_tx);
|
|
|
|
|
|
|
|
comms::main(core0_tx, core0_rx);
|
2020-04-11 20:19:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[no_mangle]
|
|
|
|
pub fn main_core1() {
|
2020-04-13 13:48:08 +08:00
|
|
|
println!("Core1 started");
|
|
|
|
|
|
|
|
let mut core1_tx = None;
|
|
|
|
while core1_tx.is_none() {
|
|
|
|
core1_tx = CHANNEL_1TO0.lock().take();
|
|
|
|
}
|
|
|
|
let mut core1_tx = core1_tx.unwrap();
|
|
|
|
|
|
|
|
let mut core1_rx = None;
|
|
|
|
while core1_rx.is_none() {
|
|
|
|
core1_rx = CHANNEL_0TO1.lock().take();
|
|
|
|
}
|
|
|
|
let mut core1_rx = core1_rx.unwrap();
|
|
|
|
|
|
|
|
kernel::main(core1_tx, core1_rx);
|
2020-04-11 20:19:39 +08:00
|
|
|
}
|