From 6c18e24418629298b7b8f2be26c1e86d47774d10 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 17 Apr 2020 13:18:23 +0800 Subject: [PATCH] merge control.rs into kernel.rs --- runtime/src/comms.rs | 8 ++---- runtime/src/control.rs | 38 -------------------------- runtime/src/kernel.rs | 62 ++++++++++++++++++++++++++++++++++++++---- runtime/src/main.rs | 27 +----------------- 4 files changed, 61 insertions(+), 74 deletions(-) delete mode 100644 runtime/src/control.rs diff --git a/runtime/src/comms.rs b/runtime/src/comms.rs index 895884ca..cf5cc881 100644 --- a/runtime/src/comms.rs +++ b/runtime/src/comms.rs @@ -18,11 +18,9 @@ use libboard_zynq::{ }, }; use libsupport_zynq::alloc::{vec, vec::Vec}; -use libcortex_a9::sync_channel; use libasync::{smoltcp::{Sockets, TcpStream}, task}; use crate::kernel; -use crate::control::KernelControl; #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -143,7 +141,7 @@ async fn send_header(stream: &TcpStream, reply: Reply) -> Result<()> { Ok(()) } -async fn handle_connection(stream: TcpStream, control: Rc>>) -> Result<()> { +async fn handle_connection(stream: TcpStream, control: Rc>>) -> Result<()> { expect(&stream, b"ARTIQ coredev\n").await?; loop { expect(&stream, &[0x5a, 0x5a, 0x5a, 0x5a]).await?; @@ -172,7 +170,7 @@ async fn handle_connection(stream: TcpStream, control: Rc return Err(Error::UnrecognizedPacket) } @@ -219,7 +217,7 @@ pub fn main() { Sockets::init(32); - let control: Rc>> = Rc::new(RefCell::new(None)); + let control: Rc>> = Rc::new(RefCell::new(None)); task::spawn(async move { loop { diff --git a/runtime/src/control.rs b/runtime/src/control.rs deleted file mode 100644 index a36f6a07..00000000 --- a/runtime/src/control.rs +++ /dev/null @@ -1,38 +0,0 @@ -use alloc::{vec, vec::Vec}; -use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}}; -use libsupport_zynq::boot::Core1; - -pub static CHANNEL_0TO1: Mutex>> = Mutex::new(None); -pub static CHANNEL_1TO0: Mutex>> = Mutex::new(None); - -/// Interface for core 0 to control core 1 start and reset -pub struct KernelControl { - core1: Core1>, - pub tx: sync_channel::Sender, - pub rx: sync_channel::Receiver, -} - -impl KernelControl { - pub fn start(stack_size: usize) -> Self { - let stack = vec![0; stack_size / 4]; - let core1 = Core1::start(stack); - - let (core0_tx, core1_rx) = sync_channel(4); - let (core1_tx, core0_rx) = sync_channel(4); - *CHANNEL_0TO1.lock() = Some(core1_rx); - *CHANNEL_1TO0.lock() = Some(core1_tx); - - KernelControl { - core1, - tx: core0_tx, - rx: core0_rx, - } - } - - pub fn reset(self) { - *CHANNEL_0TO1.lock() = None; - *CHANNEL_1TO0.lock() = None; - - self.core1.reset(); - } -} diff --git a/runtime/src/kernel.rs b/runtime/src/kernel.rs index a39c8af9..342794a8 100644 --- a/runtime/src/kernel.rs +++ b/runtime/src/kernel.rs @@ -1,11 +1,63 @@ -use libcortex_a9::sync_channel; +use alloc::{vec, vec::Vec}; +use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}}; +use libboard_zynq::println; +use libsupport_zynq::boot::Core1; + +static CHANNEL_0TO1: Mutex>> = Mutex::new(None); +static CHANNEL_1TO0: Mutex>> = Mutex::new(None); + +pub struct Control { + core1: Core1>, + pub tx: sync_channel::Sender, + pub rx: sync_channel::Receiver, +} + +impl Control { + pub fn start(stack_size: usize) -> Self { + let stack = vec![0; stack_size / 4]; + let core1 = Core1::start(stack); + + let (core0_tx, core1_rx) = sync_channel(4); + let (core1_tx, core0_rx) = sync_channel(4); + *CHANNEL_0TO1.lock() = Some(core1_rx); + *CHANNEL_1TO0.lock() = Some(core1_tx); + + Control { + core1, + tx: core0_tx, + rx: core0_rx, + } + } + + pub fn reset(self) { + *CHANNEL_0TO1.lock() = None; + *CHANNEL_1TO0.lock() = None; + + self.core1.reset(); + } +} pub static mut KERNEL_BUFFER: [u8; 16384] = [0; 16384]; -pub fn main(mut sc_tx: sync_channel::Sender, mut sc_rx: sync_channel::Receiver) { - for i in sc_rx { - sc_tx.send(*i * *i); +#[no_mangle] +pub fn main_core1() { + 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 core1_rx = core1_rx.unwrap(); + + for i in core1_rx { + core1_tx.send(*i * *i); } - loop {} + loop {} } diff --git a/runtime/src/main.rs b/runtime/src/main.rs index c3716479..773b3612 100644 --- a/runtime/src/main.rs +++ b/runtime/src/main.rs @@ -9,14 +9,12 @@ use libboard_zynq::{ println, self as zynq, clocks::Clocks, clocks::source::{ClockSource, ArmPll, IoPll}, }; -use libsupport_zynq::{ram, boot}; -use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}}; +use libsupport_zynq::ram; mod comms; mod pl; mod rtio; mod kernel; -mod control; fn identifier_read(buf: &mut [u8]) -> &str { @@ -32,10 +30,6 @@ fn identifier_read(buf: &mut [u8]) -> &str { } } -static mut STACK_CORE1: [u32; 512] = [0; 512]; -static CHANNEL_0TO1: Mutex>> = Mutex::new(None); -static CHANNEL_1TO0: Mutex>> = Mutex::new(None); - #[no_mangle] pub fn main_core0() { println!("ARTIQ runtime starting..."); @@ -53,22 +47,3 @@ pub fn main_core0() { comms::main(); } - -#[no_mangle] -pub fn main_core1() { - 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); -}