forked from M-Labs/artiq-zynq
Compare commits
No commits in common. "1892320b06c050db067a8933b287069d8c25bd2a" and "93e25169fb358fbc9b9901ed45ea8819817299a0" have entirely different histories.
1892320b06
...
93e25169fb
|
@ -784,11 +784,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
|
||||||
|
|
||||||
let cfg = Rc::new(cfg);
|
let cfg = Rc::new(cfg);
|
||||||
let restart_idle = Rc::new(Semaphore::new(1, 1));
|
let restart_idle = Rc::new(Semaphore::new(1, 1));
|
||||||
mgmt::start(
|
mgmt::start(cfg.clone(), restart_idle.clone(), Some((&aux_mutex, &drtio_routing_table, timer)));
|
||||||
cfg.clone(),
|
|
||||||
restart_idle.clone(),
|
|
||||||
Some(mgmt::DrtioTuple(aux_mutex.clone(), drtio_routing_table.clone(), timer)),
|
|
||||||
);
|
|
||||||
|
|
||||||
task::spawn(async move {
|
task::spawn(async move {
|
||||||
let connection = Rc::new(Semaphore::new(1, 1));
|
let connection = Rc::new(Semaphore::new(1, 1));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use alloc::{rc::Rc, string::String, vec::Vec};
|
use alloc::{rc::Rc, string::String, vec::Vec};
|
||||||
use core::cell::RefCell;
|
use core::{cell::RefCell, ops::Deref};
|
||||||
|
|
||||||
use futures::{future::poll_fn, task::Poll};
|
use futures::{future::poll_fn, task::Poll};
|
||||||
use libasync::{smoltcp::TcpStream, task};
|
use libasync::{smoltcp::TcpStream, task};
|
||||||
|
@ -761,13 +761,7 @@ mod local_coremgmt {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn config_write(
|
pub async fn config_write(stream: &mut TcpStream, cfg: &Rc<Config>, key: &String, value: Vec<u8>, restart_idle: &Rc<Semaphore>) -> Result<()> {
|
||||||
stream: &mut TcpStream,
|
|
||||||
cfg: &Rc<Config>,
|
|
||||||
key: &String,
|
|
||||||
value: Vec<u8>,
|
|
||||||
restart_idle: &Rc<Semaphore>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let value = cfg.write(&key, value);
|
let value = cfg.write(&key, value);
|
||||||
if value.is_ok() {
|
if value.is_ok() {
|
||||||
debug!("write success");
|
debug!("write success");
|
||||||
|
@ -783,12 +777,7 @@ mod local_coremgmt {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn config_remove(
|
pub async fn config_remove(stream: &mut TcpStream, cfg: &Rc<Config>, key: &String, restart_idle: &Rc<Semaphore>) -> Result<()> {
|
||||||
stream: &mut TcpStream,
|
|
||||||
cfg: &Rc<Config>,
|
|
||||||
key: &String,
|
|
||||||
restart_idle: &Rc<Semaphore>,
|
|
||||||
) -> Result<()> {
|
|
||||||
debug!("erase key: {}", key);
|
debug!("erase key: {}", key);
|
||||||
let value = cfg.remove(&key);
|
let value = cfg.remove(&key);
|
||||||
if value.is_ok() {
|
if value.is_ok() {
|
||||||
|
@ -842,10 +831,9 @@ macro_rules! process {
|
||||||
($stream: ident, $drtio_tuple:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{
|
($stream: ident, $drtio_tuple:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{
|
||||||
if $destination == 0 {
|
if $destination == 0 {
|
||||||
local_coremgmt::$func($stream, $($param, )*).await
|
local_coremgmt::$func($stream, $($param, )*).await
|
||||||
} else if let Some(DrtioTuple(ref aux_mutex, ref routing_table, timer)) = $drtio_tuple {
|
} else if let Some((aux_mutex, routing_table, timer)) = $drtio_tuple {
|
||||||
let routing_table = routing_table.borrow();
|
|
||||||
let linkno = routing_table.0[$destination as usize][0] - 1 as u8;
|
let linkno = routing_table.0[$destination as usize][0] - 1 as u8;
|
||||||
remote_coremgmt::$func($stream, &aux_mutex, &routing_table, timer, linkno, $destination, $($param, )*).await
|
remote_coremgmt::$func($stream, aux_mutex, routing_table, timer, linkno, $destination, $($param, )*).await
|
||||||
} else {
|
} else {
|
||||||
error!("coremgmt-over-drtio not supported for panicked device, please reboot");
|
error!("coremgmt-over-drtio not supported for panicked device, please reboot");
|
||||||
write_i8($stream, Reply::Error as i8).await?;
|
write_i8($stream, Reply::Error as i8).await?;
|
||||||
|
@ -861,15 +849,12 @@ macro_rules! process {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct DrtioTuple(pub Rc<Mutex<bool>>, pub Rc<RefCell<RoutingTable>>, pub GlobalTimer);
|
|
||||||
|
|
||||||
async fn handle_connection(
|
async fn handle_connection(
|
||||||
stream: &mut TcpStream,
|
stream: &mut TcpStream,
|
||||||
pull_id: Rc<RefCell<u32>>,
|
pull_id: Rc<RefCell<u32>>,
|
||||||
cfg: Rc<Config>,
|
cfg: Rc<Config>,
|
||||||
restart_idle: Rc<Semaphore>,
|
restart_idle: Rc<Semaphore>,
|
||||||
_drtio_tuple: Option<DrtioTuple>,
|
_drtio_tuple: Option<(&Rc<Mutex<bool>>, &RoutingTable, GlobalTimer)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if !expect(&stream, b"ARTIQ management\n").await? {
|
if !expect(&stream, b"ARTIQ management\n").await? {
|
||||||
return Err(Error::UnexpectedPattern);
|
return Err(Error::UnexpectedPattern);
|
||||||
|
@ -909,28 +894,11 @@ async fn handle_connection(
|
||||||
buffer.set_len(len);
|
buffer.set_len(len);
|
||||||
}
|
}
|
||||||
read_chunk(stream, &mut buffer).await?;
|
read_chunk(stream, &mut buffer).await?;
|
||||||
process!(
|
process!(stream, _drtio_tuple, _destination, config_write, &cfg, &key, buffer, &restart_idle)
|
||||||
stream,
|
|
||||||
_drtio_tuple,
|
|
||||||
_destination,
|
|
||||||
config_write,
|
|
||||||
&cfg,
|
|
||||||
&key,
|
|
||||||
buffer,
|
|
||||||
&restart_idle
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Request::ConfigRemove => {
|
Request::ConfigRemove => {
|
||||||
let key = read_key(stream).await?;
|
let key = read_key(stream).await?;
|
||||||
process!(
|
process!(stream, _drtio_tuple, _destination, config_remove, &cfg, &key, &restart_idle)
|
||||||
stream,
|
|
||||||
_drtio_tuple,
|
|
||||||
_destination,
|
|
||||||
config_remove,
|
|
||||||
&cfg,
|
|
||||||
&key,
|
|
||||||
&restart_idle
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
Request::Reboot => {
|
Request::Reboot => {
|
||||||
process!(stream, _drtio_tuple, _destination, reboot)
|
process!(stream, _drtio_tuple, _destination, reboot)
|
||||||
|
@ -958,7 +926,9 @@ async fn handle_connection(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start(cfg: Rc<Config>, restart_idle: Rc<Semaphore>, drtio_tuple: Option<DrtioTuple>) {
|
pub fn start(cfg: Rc<Config>, restart_idle: Rc<Semaphore>, drtio_tuple: Option<(&Rc<Mutex<bool>>, &Rc<RefCell<RoutingTable>>, GlobalTimer)>) {
|
||||||
|
let drtio_tuple =
|
||||||
|
drtio_tuple.map(|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer));
|
||||||
task::spawn(async move {
|
task::spawn(async move {
|
||||||
let pull_id = Rc::new(RefCell::new(0u32));
|
let pull_id = Rc::new(RefCell::new(0u32));
|
||||||
loop {
|
loop {
|
||||||
|
@ -969,6 +939,14 @@ pub fn start(cfg: Rc<Config>, restart_idle: Rc<Semaphore>, drtio_tuple: Option<D
|
||||||
let drtio_tuple = drtio_tuple.clone();
|
let drtio_tuple = drtio_tuple.clone();
|
||||||
task::spawn(async move {
|
task::spawn(async move {
|
||||||
info!("received connection");
|
info!("received connection");
|
||||||
|
// Avoid consuming the tuple
|
||||||
|
// Keep the borrowed value on stack
|
||||||
|
let drtio_tuple = drtio_tuple
|
||||||
|
.as_ref()
|
||||||
|
.map(|(aux_mutex, routing_table, timer)| (aux_mutex, routing_table.borrow(), *timer));
|
||||||
|
let drtio_tuple = drtio_tuple
|
||||||
|
.as_ref()
|
||||||
|
.map(|(aux_mutex, routing_table, timer)| (*aux_mutex, routing_table.deref(), *timer));
|
||||||
let _ = handle_connection(&mut stream, pull_id, cfg, restart_idle, drtio_tuple)
|
let _ = handle_connection(&mut stream, pull_id, cfg, restart_idle, drtio_tuple)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| warn!("connection terminated: {:?}", e));
|
.map_err(|e| warn!("connection terminated: {:?}", e));
|
||||||
|
|
Loading…
Reference in New Issue