From 83b92f3a7ff6311fb496ef7571f8ff4a2b7472cb Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 17 Apr 2020 15:43:00 +0800 Subject: [PATCH] send simple messages between cores --- runtime/src/comms.rs | 29 ++++++++++++----------------- runtime/src/kernel.rs | 30 ++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/runtime/src/comms.rs b/runtime/src/comms.rs index b1465d1c..96fddeca 100644 --- a/runtime/src/comms.rs +++ b/runtime/src/comms.rs @@ -154,26 +154,21 @@ async fn handle_connection(stream: &TcpStream, control: Rc { let length = read_i32(&stream).await? as usize; - let kernel_buffer = unsafe { &mut kernel::KERNEL_BUFFER }; - if kernel_buffer.len() < length { + if length < 1024*1024 { + let mut buffer = vec![0; length]; + read_chunk(&stream, &mut buffer).await?; + + let mut control = control.borrow_mut(); + control.restart(); + control.tx.async_send(kernel::Message::LoadRequest).await; + let reply = control.rx.async_recv().await; + println!("core0 received: {:?}", reply); + + send_header(&stream, Reply::LoadCompleted).await?; + } else { read_drain(&stream, length).await?; send_header(&stream, Reply::LoadFailed).await?; - } else { - read_chunk(&stream, &mut kernel_buffer[..length]).await?; - send_header(&stream, Reply::LoadCompleted).await?; } - println!("length={}, {:?}", length, &kernel_buffer[..256]); - - let mut control = control.borrow_mut(); - control.restart(); - for i in 0..10 { - control.tx.async_send(i).await; - let j = control.rx.async_recv().await; - println!("{} -> {}", i, j); - } - - // TODO: dyld - } _ => return Err(Error::UnrecognizedPacket) } diff --git a/runtime/src/kernel.rs b/runtime/src/kernel.rs index 1f648a83..8dccb077 100644 --- a/runtime/src/kernel.rs +++ b/runtime/src/kernel.rs @@ -1,15 +1,25 @@ 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); +use dyld; + + +#[derive(Debug)] +pub enum Message { + LoadRequest, + LoadReply, +} + +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, + pub tx: sync_channel::Sender, + pub rx: sync_channel::Receiver, } impl Control { @@ -44,8 +54,6 @@ impl Control { } } -pub static mut KERNEL_BUFFER: [u8; 16384] = [0; 16384]; - #[no_mangle] pub fn main_core1() { println!("Core1 started"); @@ -62,9 +70,11 @@ pub fn main_core1() { } let core1_rx = core1_rx.unwrap(); - for i in core1_rx { - core1_tx.send(*i * *i); + for message in core1_rx { + println!("core1 received: {:?}", message); + match *message { + Message::LoadRequest => core1_tx.send(Message::LoadReply), + _ => println!("Core1 received unexpected message: {:?}", message), + } } - - loop {} }