libconfig: remove Config struct

Replaced with module level functions.
This commit is contained in:
2025-07-14 13:14:19 +08:00
committed by sb10q
parent 1c64f4488a
commit 8223d263f6
12 changed files with 74 additions and 121 deletions

View File

@@ -1,7 +1,7 @@
use alloc::format;
use libboard_zynq::timer;
use libconfig::Config;
use libconfig;
use log::{debug, error, info};
use crate::pl;
@@ -203,7 +203,7 @@ pub unsafe fn align_wordslip(trx_no: u8) -> bool {
false
}
pub fn init(cfg: &Config) {
pub fn init() {
for trx_no in 0..pl::csr::CONFIG_EEM_DRTIO_COUNT {
unsafe {
pl::csr::eem_transceiver::transceiver_sel_write(trx_no as u8);
@@ -211,7 +211,7 @@ pub fn init(cfg: &Config) {
let key = format!("eem_drtio_delay{}", trx_no);
let cfg_read = cfg.read(&key);
let cfg_read = libconfig::read(&key);
match cfg_read {
Ok(record) => {
info!("loading calibrated timing values from sd card");
@@ -223,7 +223,7 @@ pub fn init(cfg: &Config) {
info!("calibrating...");
let config = unsafe { assign_delay() };
match cfg.write(&key, config.as_bytes().to_vec()) {
match libconfig::write(&key, config.as_bytes().to_vec()) {
Ok(()) => {
info!("storing calibration timing values into sd card");
}

View File

@@ -1,6 +1,6 @@
use core::fmt;
use libconfig::Config;
use libconfig;
use log::{info, warn};
#[cfg(has_drtio_routing)]
@@ -56,9 +56,9 @@ impl fmt::Display for RoutingTable {
}
}
pub fn config_routing_table(default_n_links: usize, cfg: &Config) -> RoutingTable {
pub fn config_routing_table(default_n_links: usize) -> RoutingTable {
let mut ret = RoutingTable::default_master(default_n_links);
if let Ok(data) = cfg.read("routing_table") {
if let Ok(data) = libconfig::read("routing_table") {
if data.len() == DEST_COUNT * MAX_HOPS {
for i in 0..DEST_COUNT {
for j in 0..MAX_HOPS {

View File

@@ -13,7 +13,7 @@ use alloc::{collections::BTreeMap, string::String};
use byteorder::NativeEndian;
use io::{Cursor, ProtoRead};
use libasync::block_async;
use libconfig::Config;
use libconfig;
use log::{error, warn};
#[cfg(has_drtiosat)]
pub use pl::csr::drtiosat as rtio_core;
@@ -109,10 +109,9 @@ pub async fn report_async_rtio_errors() {
static mut RTIO_DEVICE_MAP: BTreeMap<u32, String> = BTreeMap::new();
fn read_device_map(cfg: &Config) -> BTreeMap<u32, String> {
fn read_device_map() -> BTreeMap<u32, String> {
let mut device_map: BTreeMap<u32, String> = BTreeMap::new();
let _ = cfg
.read("device_map")
let _ = libconfig::read("device_map")
.and_then(|raw_bytes| {
let mut bytes_cr = Cursor::new(raw_bytes);
let size = bytes_cr.read_u32::<NativeEndian>().unwrap();
@@ -147,8 +146,8 @@ pub fn resolve_channel_name(channel: u32) -> String {
}
}
pub fn setup_device_map(cfg: &Config) {
pub fn setup_device_map() {
unsafe {
RTIO_DEVICE_MAP = read_device_map(cfg);
RTIO_DEVICE_MAP = read_device_map();
}
}

View File

@@ -25,7 +25,7 @@ use libboard_zynq::{self as zynq,
time::{Duration, Instant},
wire::IpCidr},
timer};
use libconfig::{Config, net_settings};
use libconfig::{self, net_settings};
use libcortex_a9::{mutex::Mutex,
semaphore::Semaphore,
sync_channel::{Receiver, Sender}};
@@ -884,8 +884,8 @@ async fn handle_connection(
}
}
pub fn main(cfg: Config) {
let net_addresses = net_settings::get_addresses(&cfg);
pub fn main() {
let net_addresses = net_settings::get_addresses();
info!("network addresses: {}", net_addresses);
let eth = zynq::eth::Eth::eth0(net_addresses.hardware_addr.0.clone());
@@ -927,24 +927,21 @@ pub fn main(cfg: Config) {
let aux_mutex: Rc<Mutex<bool>> = Rc::new(Mutex::new(false));
#[cfg(has_drtio)]
let drtio_routing_table = Rc::new(RefCell::new(drtio_routing::config_routing_table(
pl::csr::DRTIO.len(),
&cfg,
)));
let drtio_routing_table = Rc::new(RefCell::new(drtio_routing::config_routing_table(pl::csr::DRTIO.len())));
#[cfg(not(has_drtio))]
let drtio_routing_table = Rc::new(RefCell::new(drtio_routing::RoutingTable::default_empty()));
let up_destinations = Rc::new(RefCell::new([false; drtio_routing::DEST_COUNT]));
#[cfg(has_drtio_routing)]
drtio_routing::interconnect_disable_all();
rtio_mgt::startup(&aux_mutex, &drtio_routing_table, &up_destinations, &cfg);
ksupport::setup_device_map(&cfg);
rtio_mgt::startup(&aux_mutex, &drtio_routing_table, &up_destinations);
ksupport::setup_device_map();
analyzer::start(&aux_mutex, &drtio_routing_table, &up_destinations);
moninj::start(&aux_mutex, &drtio_routing_table);
let control: Rc<RefCell<kernel::Control>> = Rc::new(RefCell::new(kernel::Control::start()));
if let Ok(buffer) = cfg.read("startup_kernel") {
if let Ok(buffer) = libconfig::read("startup_kernel") {
info!("Loading startup kernel...");
let routing_table = drtio_routing_table.borrow();
if let Ok(()) = task::block_on(handle_flash_kernel(
@@ -968,10 +965,8 @@ pub fn main(cfg: Config) {
}
}
let cfg = Rc::new(cfg);
let restart_idle = Rc::new(Semaphore::new(1, 1));
mgmt::start(
cfg.clone(),
restart_idle.clone(),
Some(mgmt::DrtioContext(aux_mutex.clone(), drtio_routing_table.clone())),
);
@@ -999,7 +994,7 @@ pub fn main(cfg: Config) {
connection.async_wait().await;
}
let maybe_idle_kernel = cfg.read("idle_kernel").ok();
let maybe_idle_kernel = libconfig::read("idle_kernel").ok();
if maybe_idle_kernel.is_none() && maybe_stream.is_none() {
control.borrow_mut().restart(); // terminate idle kernel if running
}
@@ -1074,8 +1069,8 @@ pub fn main(cfg: Config) {
})
}
pub fn soft_panic_main(cfg: Config) -> ! {
let net_addresses = net_settings::get_addresses(&cfg);
pub fn soft_panic_main() -> ! {
let net_addresses = net_settings::get_addresses();
info!("network addresses: {}", net_addresses);
let eth = zynq::eth::Eth::eth0(net_addresses.hardware_addr.0.clone());
@@ -1116,7 +1111,7 @@ pub fn soft_panic_main(cfg: Config) -> ! {
Sockets::init(32);
let dummy = Rc::new(Semaphore::new(0, 1));
mgmt::start(Rc::new(cfg), dummy, None);
mgmt::start(dummy, None);
// getting eth settings disables the LED as it resets GPIO
// need to re-enable it here

View File

@@ -22,7 +22,7 @@ use libboard_artiq::io_expander;
use libboard_artiq::{cxp_grabber, cxp_phys};
use libboard_artiq::{identifier_read, logger, pl};
use libboard_zynq::{gic, mpcore, timer};
use libconfig::Config;
use libconfig;
use libcortex_a9::l2c::enable_l2_cache;
use libsupport_zynq::{exception_vectors, ram};
use log::{info, warn};
@@ -132,18 +132,13 @@ pub fn main_core0() {
));
}
let cfg = match Config::new() {
Ok(cfg) => cfg,
Err(err) => {
warn!("config initialization failed: {}", err);
Config::new_dummy()
}
};
rtio_clocking::init(&cfg);
if let Err(err) = libconfig::init() {
warn!("config initialization failed: {}", err);
}
rtio_clocking::init();
#[cfg(has_drtio_eem)]
drtio_eem::init(&cfg);
drtio_eem::init();
#[cfg(has_grabber)]
task::spawn(grabber::grabber_thread());
@@ -156,5 +151,5 @@ pub fn main_core0() {
task::spawn(cxp_grabber::thread(ksupport::kernel::i2c::get_bus()));
}
comms::main(cfg);
comms::main();
}

View File

@@ -8,7 +8,7 @@ use libasync::{smoltcp::TcpStream, task};
use libboard_artiq::{drtio_routing::RoutingTable,
logger::{BufferLogger, LogBufferRef}};
use libboard_zynq::smoltcp;
use libconfig::Config;
use libconfig;
use libcortex_a9::{mutex::Mutex, semaphore::Semaphore};
use log::{self, debug, error, info, warn};
use num_derive::FromPrimitive;
@@ -354,7 +354,6 @@ mod remote_coremgmt {
routing_table: &RoutingTable,
linkno: u8,
destination: u8,
_cfg: &Rc<Config>,
key: &String,
) -> Result<()> {
let mut config_key: [u8; MASTER_PAYLOAD_MAX_SIZE] = [0; MASTER_PAYLOAD_MAX_SIZE];
@@ -415,7 +414,6 @@ mod remote_coremgmt {
routing_table: &RoutingTable,
linkno: u8,
destination: u8,
_cfg: &Rc<Config>,
key: &String,
value: Vec<u8>,
_restart_idle: &Rc<Semaphore>,
@@ -463,7 +461,6 @@ mod remote_coremgmt {
routing_table: &RoutingTable,
linkno: u8,
destination: u8,
_cfg: &Rc<Config>,
key: &String,
_restart_idle: &Rc<Semaphore>,
) -> Result<()> {
@@ -610,7 +607,6 @@ mod remote_coremgmt {
routing_table: &RoutingTable,
linkno: u8,
destination: u8,
_cfg: &Rc<Config>,
image: Vec<u8>,
) -> Result<()> {
let mut image = &image[..];
@@ -747,8 +743,8 @@ mod local_coremgmt {
Ok(())
}
pub async fn config_read(stream: &mut TcpStream, cfg: &Rc<Config>, key: &String) -> Result<()> {
let value = cfg.read(&key);
pub async fn config_read(stream: &mut TcpStream, key: &String) -> Result<()> {
let value = libconfig::read(&key);
if let Ok(value) = value {
debug!("got value");
write_i8(stream, Reply::ConfigData as i8).await?;
@@ -762,12 +758,11 @@ mod local_coremgmt {
pub async fn config_write(
stream: &mut TcpStream,
cfg: &Rc<Config>,
key: &String,
value: Vec<u8>,
restart_idle: &Rc<Semaphore>,
) -> Result<()> {
let value = cfg.write(&key, value);
let value = libconfig::write(&key, value);
if value.is_ok() {
debug!("write success");
if key == "idle_kernel" {
@@ -782,14 +777,9 @@ mod local_coremgmt {
Ok(())
}
pub async fn config_remove(
stream: &mut TcpStream,
cfg: &Rc<Config>,
key: &String,
restart_idle: &Rc<Semaphore>,
) -> Result<()> {
pub async fn config_remove(stream: &mut TcpStream, key: &String, restart_idle: &Rc<Semaphore>) -> Result<()> {
debug!("erase key: {}", key);
let value = cfg.remove(&key);
let value = libconfig::remove(&key);
if value.is_ok() {
debug!("erase success");
if key == "idle_kernel" {
@@ -823,7 +813,7 @@ mod local_coremgmt {
Ok(())
}
pub async fn image_write(stream: &mut TcpStream, cfg: &Rc<Config>, image: Vec<u8>) -> Result<()> {
pub async fn image_write(stream: &mut TcpStream, image: Vec<u8>) -> Result<()> {
let mut image = image.clone();
let image_ref = &image[..];
let bin_len = image.len() - 4;
@@ -838,7 +828,7 @@ mod local_coremgmt {
if actual_crc == expected_crc {
info!("CRC passed. Writing boot image to SD card...");
image.truncate(bin_len);
cfg.write("boot", image).expect("failed to write boot image");
libconfig::write("boot", image).expect("failed to write boot image");
reboot(stream).await?;
} else {
error!(
@@ -882,7 +872,6 @@ pub struct DrtioContext(pub Rc<Mutex<bool>>, pub Rc<RefCell<RoutingTable>>);
async fn handle_connection(
stream: &mut TcpStream,
pull_id: Rc<RefCell<u32>>,
cfg: Rc<Config>,
restart_idle: Rc<Semaphore>,
_drtio_context: Option<DrtioContext>,
) -> Result<()> {
@@ -913,7 +902,7 @@ async fn handle_connection(
}
Request::ConfigRead => {
let key = read_key(stream).await?;
process!(stream, _drtio_context, _destination, config_read, &cfg, &key)
process!(stream, _drtio_context, _destination, config_read, &key)
}
Request::ConfigWrite => {
let key = read_key(stream).await?;
@@ -929,7 +918,6 @@ async fn handle_connection(
_drtio_context,
_destination,
config_write,
&cfg,
&key,
buffer,
&restart_idle
@@ -937,15 +925,7 @@ async fn handle_connection(
}
Request::ConfigRemove => {
let key = read_key(stream).await?;
process!(
stream,
_drtio_context,
_destination,
config_remove,
&cfg,
&key,
&restart_idle
)
process!(stream, _drtio_context, _destination, config_remove, &key, &restart_idle)
}
Request::Reboot => {
process!(stream, _drtio_context, _destination, reboot)
@@ -967,24 +947,23 @@ async fn handle_connection(
buffer.set_len(len as usize);
}
read_chunk(stream, &mut buffer).await?;
process!(stream, _drtio_context, _destination, image_write, &cfg, buffer)
process!(stream, _drtio_context, _destination, image_write, buffer)
}
}?;
}
}
pub fn start(cfg: Rc<Config>, restart_idle: Rc<Semaphore>, drtio_context: Option<DrtioContext>) {
pub fn start(restart_idle: Rc<Semaphore>, drtio_context: Option<DrtioContext>) {
task::spawn(async move {
let pull_id = Rc::new(RefCell::new(0u32));
loop {
let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap();
let pull_id = pull_id.clone();
let cfg = cfg.clone();
let restart_idle = restart_idle.clone();
let drtio_context = drtio_context.clone();
task::spawn(async move {
info!("received connection");
let _ = handle_connection(&mut stream, pull_id, cfg, restart_idle, drtio_context)
let _ = handle_connection(&mut stream, pull_id, restart_idle, drtio_context)
.await
.map_err(|e| warn!("connection terminated: {:?}", e));
let _ = stream.flush().await;

View File

@@ -1,7 +1,7 @@
#[cfg(feature = "target_kasli_soc")]
use libboard_zynq::error_led::ErrorLED;
use libboard_zynq::{print, println, timer};
use libconfig::Config;
use libconfig;
use libcortex_a9::regs::MPIDR;
use libregister::RegisterR;
use log::error;
@@ -59,11 +59,8 @@ fn soft_panic(info: &core::panic::PanicInfo) -> ! {
}
error!("panic message: {}", info.message());
timer::start();
let cfg = match Config::new() {
Ok(cfg) => cfg,
Err(_) => Config::new_dummy(),
};
soft_panic_main(cfg);
let _ = libconfig::init();
soft_panic_main();
}
#[lang = "eh_personality"]

View File

@@ -9,7 +9,7 @@ use libboard_artiq::si5324;
#[cfg(has_si5324)]
use libboard_zynq::i2c::I2c;
use libboard_zynq::timer;
use libconfig::Config;
use libconfig;
use log::{info, warn};
#[cfg(feature = "target_ebaz4205")]
use {libboard_zynq::slcr, libregister::RegisterRW};
@@ -29,9 +29,9 @@ pub enum RtioClock {
}
#[allow(unreachable_code)]
fn get_rtio_clock_cfg(cfg: &Config) -> RtioClock {
fn get_rtio_clock_cfg() -> RtioClock {
let mut res = RtioClock::Default;
if let Ok(clk) = cfg.read_str("rtio_clock") {
if let Ok(clk) = libconfig::read_str("rtio_clock") {
res = match clk.as_ref() {
"int_125" => RtioClock::Int_125,
"int_100" => RtioClock::Int_100,
@@ -409,7 +409,7 @@ fn get_si549_setting(clk: RtioClock) -> si549::FrequencySetting {
}
#[cfg(feature = "target_ebaz4205")]
fn set_fclk0_freq(clk: RtioClock, cfg: &Config) {
fn set_fclk0_freq(clk: RtioClock) {
let io_pll_freq: u32 = 1_000_000_000; // Hardcoded in zynq-rs
let mut target_freq = 0;
let mut divisor0 = 1u8;
@@ -440,8 +440,8 @@ fn set_fclk0_freq(clk: RtioClock, cfg: &Config) {
);
}
pub fn init(cfg: &Config) {
let clk = get_rtio_clock_cfg(cfg);
pub fn init() {
let clk = get_rtio_clock_cfg();
#[cfg(has_si5324)]
{
let i2c = i2c::get_bus();
@@ -470,7 +470,7 @@ pub fn init(cfg: &Config) {
{
match clk {
RtioClock::Int_100 | RtioClock::Int_125 => {
set_fclk0_freq(clk, cfg);
set_fclk0_freq(clk);
}
_ => {} // Not set for external clocks
}

View File

@@ -2,7 +2,7 @@ use alloc::rc::Rc;
use core::cell::RefCell;
use libboard_artiq::{drtio_routing, drtio_routing::RoutingTable, pl::csr};
use libconfig::Config;
use libconfig;
use libcortex_a9::mutex::Mutex;
use log::{info, warn};
@@ -1056,8 +1056,8 @@ fn toggle_sed_spread(val: u8) {
}
}
fn setup_sed_spread(cfg: &Config) {
if let Ok(spread_enable) = cfg.read_str("sed_spread_enable") {
fn setup_sed_spread() {
if let Ok(spread_enable) = libconfig::read_str("sed_spread_enable") {
match spread_enable.as_ref() {
"1" => toggle_sed_spread(1),
"0" => toggle_sed_spread(0),
@@ -1076,9 +1076,8 @@ pub fn startup(
aux_mutex: &Rc<Mutex<bool>>,
routing_table: &Rc<RefCell<RoutingTable>>,
up_destinations: &Rc<RefCell<[bool; drtio_routing::DEST_COUNT]>>,
cfg: &Config,
) {
setup_sed_spread(cfg);
setup_sed_spread();
drtio::startup(aux_mutex, routing_table, up_destinations);
unsafe {
csr::rtio_core::reset_phy_write(1);

View File

@@ -62,7 +62,7 @@ async fn process_aux_packet<'a, 'b>(
dma_manager: &mut DmaManager,
analyzer: &mut Analyzer,
kernel_manager: &mut KernelManager<'a>,
core_manager: &mut CoreManager<'b>,
core_manager: &mut CoreManager,
router: &mut Router,
) -> Result<(), drtioaux::Error> {
// In the code below, *_chan_sel_write takes an u8 if there are fewer than 256 channels,
@@ -1346,7 +1346,7 @@ pub async fn process_aux_packets<'a, 'b>(
dma_manager: &mut DmaManager,
analyzer: &mut Analyzer,
kernel_manager: &mut KernelManager<'a>,
core_manager: &mut CoreManager<'b>,
core_manager: &mut CoreManager,
router: &mut Router,
) {
let result = match drtioaux::recv(0) {

View File

@@ -46,7 +46,6 @@ use libboard_artiq::{drtio_routing, drtioaux, drtioaux_async, identifier_read, l
#[cfg(feature = "target_kasli_soc")]
use libboard_zynq::error_led::ErrorLED;
use libboard_zynq::{i2c::I2c, print, println, timer};
use libconfig::Config;
use libcortex_a9::{l2c::enable_l2_cache, regs::MPIDR};
use libregister::RegisterR;
use libsupport_zynq::{exception_vectors, ram};
@@ -295,15 +294,11 @@ pub fn main_core0() {
#[cfg(has_si549)]
si549::helper_setup(&SI549_SETTINGS).expect("cannot initialize helper Si549");
let mut cfg = match Config::new() {
Ok(cfg) => cfg,
Err(err) => {
warn!("config initialization failed: {}", err);
Config::new_dummy()
}
};
if let Err(err) = libconfig::init() {
warn!("config initialization failed: {}", err);
}
if let Ok(spread_enable) = cfg.read_str("sed_spread_enable") {
if let Ok(spread_enable) = libconfig::read_str("sed_spread_enable") {
match spread_enable.as_ref() {
"1" => toggle_sed_spread(1),
"0" => toggle_sed_spread(0),
@@ -319,7 +314,7 @@ pub fn main_core0() {
#[cfg(has_drtio_eem)]
{
drtio_eem::init(&cfg);
drtio_eem::init();
unsafe { csr::eem_transceiver::rx_ready_write(1) }
}
@@ -385,7 +380,7 @@ pub fn main_core0() {
let mut dma_manager = DmaManager::new();
let mut analyzer = Analyzer::new();
let mut kernel_manager = KernelManager::new(&control);
let mut core_manager = CoreManager::new(&mut cfg);
let mut core_manager = CoreManager::new();
drtioaux::reset(0);
drtiosat_reset(false);
@@ -425,7 +420,7 @@ pub fn main_core0() {
})
}
async fn linkup_service<'a, 'b>(
async fn linkup_service<'a>(
repeaters: &mut [repeater::Repeater],
routing_table: &mut drtio_routing::RoutingTable,
rank: &mut u8,
@@ -434,7 +429,7 @@ async fn linkup_service<'a, 'b>(
dma_manager: &mut DmaManager,
analyzer: &mut Analyzer,
kernel_manager: &mut KernelManager<'a>,
core_manager: &mut CoreManager<'b>,
core_manager: &mut CoreManager,
router: &mut Router,
) {
process_aux_packets(

View File

@@ -6,7 +6,6 @@ use crc::crc32;
use io::ProtoRead;
use libboard_artiq::{drtioaux_proto::SAT_PAYLOAD_MAX_SIZE,
logger::{BufferLogger, LogBufferRef}};
use libconfig::Config;
use log::{LevelFilter, debug, error, info, warn};
use crate::routing::{SliceMeta, Sliceable};
@@ -42,18 +41,16 @@ pub fn clear_log() {
buffer.clear();
}
pub struct Manager<'a> {
cfg: &'a mut Config,
pub struct Manager {
last_log: Sliceable,
config_payload: Vec<u8>,
last_value: Sliceable,
image_payload: Vec<u8>,
}
impl<'a> Manager<'_> {
pub fn new(cfg: &mut Config) -> Manager {
impl Manager {
pub fn new() -> Manager {
Manager {
cfg: cfg,
last_log: Sliceable::new(0, Vec::new()),
config_payload: Vec::new(),
last_value: Sliceable::new(0, Vec::new()),
@@ -75,8 +72,7 @@ impl<'a> Manager<'_> {
}
pub fn fetch_config_value(&mut self, key: &str) -> Result<()> {
self.cfg
.read(&key)
libconfig::read(&key)
.map(|value| {
debug!("got value");
self.last_value = Sliceable::new(0, value)
@@ -104,16 +100,14 @@ impl<'a> Manager<'_> {
debug!("write key: {}", key);
let value = payload.read_bytes::<NativeEndian>().unwrap();
self.cfg
.write(&key, value)
libconfig::write(&key, value)
.map(|()| debug!("write success"))
.map_err(|err| error!("failed to write: {:?}", err))
}
pub fn remove_config(&mut self, key: &str) -> Result<()> {
debug!("erase key: {}", key);
self.cfg
.remove(&key)
libconfig::remove(&key)
.map(|()| debug!("erase success"))
.map_err(|err| warn!("failed to erase: {:?}", err))
}
@@ -141,7 +135,7 @@ impl<'a> Manager<'_> {
if actual_crc == expected_crc {
info!("CRC passed. Writing boot image to SD card...");
image.truncate(bin_len);
self.cfg.write("boot", image).expect("failed to write boot image");
libconfig::write("boot", image).expect("failed to write boot image");
} else {
panic!(
"CRC failed, images have not been written to flash.\n(actual {:08x}, expected {:08x})",