forked from M-Labs/artiq-zynq
cleaning up RTIO_DEVICE_MAP
This commit is contained in:
parent
15f9d1a9e5
commit
7a2a527916
|
@ -35,6 +35,7 @@ pub mod rtio;
|
|||
#[rustfmt::skip]
|
||||
#[path = "../../../build/pl.rs"]
|
||||
pub mod pl;
|
||||
use core::ptr::addr_of;
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -115,6 +116,7 @@ pub async fn report_async_rtio_errors() {
|
|||
}
|
||||
}
|
||||
|
||||
// use interior mutability -> no need for this to be a static mut (no volatile r/ws or FFI)
|
||||
static mut RTIO_DEVICE_MAP: BTreeMap<u32, String> = BTreeMap::new();
|
||||
|
||||
fn read_device_map(cfg: &Config) -> BTreeMap<u32, String> {
|
||||
|
@ -146,15 +148,14 @@ fn read_device_map(cfg: &Config) -> BTreeMap<u32, String> {
|
|||
device_map
|
||||
}
|
||||
|
||||
fn _resolve_channel_name(channel: u32, device_map: &BTreeMap<u32, String>) -> String {
|
||||
match device_map.get(&channel) {
|
||||
Some(val) => val.clone(),
|
||||
None => String::from("unknown"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_channel_name(channel: u32) -> String {
|
||||
_resolve_channel_name(channel, unsafe { &RTIO_DEVICE_MAP })
|
||||
unsafe {
|
||||
let ptr: *const BTreeMap<u32, String> = addr_of!(RTIO_DEVICE_MAP);
|
||||
match ptr.as_ref().unwrap().get(&channel) {
|
||||
Some(val) => val.clone(),
|
||||
None => String::from("unknown"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setup_device_map(cfg: &Config) {
|
||||
|
|
Loading…
Reference in New Issue