forked from M-Labs/nac3
1
0
Fork 0

send simple messages between cores

This commit is contained in:
Sebastien Bourdeauducq 2020-04-17 15:43:00 +08:00
parent abe0a549b5
commit 83b92f3a7f
2 changed files with 32 additions and 27 deletions

View File

@ -154,26 +154,21 @@ async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Contr
}, },
Request::LoadKernel => { Request::LoadKernel => {
let length = read_i32(&stream).await? as usize; let length = read_i32(&stream).await? as usize;
let kernel_buffer = unsafe { &mut kernel::KERNEL_BUFFER }; if length < 1024*1024 {
if kernel_buffer.len() < length { let mut buffer = vec![0; length];
read_drain(&stream, length).await?; read_chunk(&stream, &mut buffer).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(); let mut control = control.borrow_mut();
control.restart(); control.restart();
for i in 0..10 { control.tx.async_send(kernel::Message::LoadRequest).await;
control.tx.async_send(i).await; let reply = control.rx.async_recv().await;
let j = control.rx.async_recv().await; println!("core0 received: {:?}", reply);
println!("{} -> {}", i, j);
send_header(&stream, Reply::LoadCompleted).await?;
} else {
read_drain(&stream, length).await?;
send_header(&stream, Reply::LoadFailed).await?;
} }
// TODO: dyld
} }
_ => return Err(Error::UnrecognizedPacket) _ => return Err(Error::UnrecognizedPacket)
} }

View File

@ -1,15 +1,25 @@
use alloc::{vec, vec::Vec}; use alloc::{vec, vec::Vec};
use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}}; use libcortex_a9::{mutex::Mutex, sync_channel::{self, sync_channel}};
use libboard_zynq::println; use libboard_zynq::println;
use libsupport_zynq::boot::Core1; use libsupport_zynq::boot::Core1;
static CHANNEL_0TO1: Mutex<Option<sync_channel::Receiver<usize>>> = Mutex::new(None); use dyld;
static CHANNEL_1TO0: Mutex<Option<sync_channel::Sender<usize>>> = Mutex::new(None);
#[derive(Debug)]
pub enum Message {
LoadRequest,
LoadReply,
}
static CHANNEL_0TO1: Mutex<Option<sync_channel::Receiver<Message>>> = Mutex::new(None);
static CHANNEL_1TO0: Mutex<Option<sync_channel::Sender<Message>>> = Mutex::new(None);
pub struct Control { pub struct Control {
core1: Core1<Vec<u32>>, core1: Core1<Vec<u32>>,
pub tx: sync_channel::Sender<usize>, pub tx: sync_channel::Sender<Message>,
pub rx: sync_channel::Receiver<usize>, pub rx: sync_channel::Receiver<Message>,
} }
impl Control { impl Control {
@ -44,8 +54,6 @@ impl Control {
} }
} }
pub static mut KERNEL_BUFFER: [u8; 16384] = [0; 16384];
#[no_mangle] #[no_mangle]
pub fn main_core1() { pub fn main_core1() {
println!("Core1 started"); println!("Core1 started");
@ -62,9 +70,11 @@ pub fn main_core1() {
} }
let core1_rx = core1_rx.unwrap(); let core1_rx = core1_rx.unwrap();
for i in core1_rx { for message in core1_rx {
core1_tx.send(*i * *i); println!("core1 received: {:?}", message);
match *message {
Message::LoadRequest => core1_tx.send(Message::LoadReply),
_ => println!("Core1 received unexpected message: {:?}", message),
}
} }
loop {}
} }