split config code into libconfig
This commit is contained in:
parent
d474cf58a5
commit
42f94487cf
12
src/Cargo.lock
generated
12
src/Cargo.lock
generated
@ -236,6 +236,16 @@ dependencies = [
|
||||
"libboard_zynq",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libconfig"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"core_io",
|
||||
"fatfs",
|
||||
"libboard_zynq",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libcortex_a9"
|
||||
version = "0.0.0"
|
||||
@ -416,11 +426,11 @@ dependencies = [
|
||||
"dwarf",
|
||||
"dyld",
|
||||
"embedded-hal",
|
||||
"fatfs",
|
||||
"futures",
|
||||
"libasync",
|
||||
"libboard_zynq",
|
||||
"libc",
|
||||
"libconfig",
|
||||
"libcortex_a9",
|
||||
"libm",
|
||||
"libregister",
|
||||
|
@ -2,6 +2,7 @@
|
||||
members = [
|
||||
"libc",
|
||||
"libdyld",
|
||||
"libconfig",
|
||||
"libcoreio",
|
||||
"libdwarf",
|
||||
"libunwind",
|
||||
|
15
src/libconfig/Cargo.toml
Normal file
15
src/libconfig/Cargo.toml
Normal file
@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "libconfig"
|
||||
version = "0.1.0"
|
||||
authors = ["M-Labs"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
libboard_zynq = { git = "https://git.m-labs.hk/M-Labs/zynq-rs.git" }
|
||||
core_io = { version = "0.1", features = ["collections"] }
|
||||
fatfs = { version = "0.3", features = ["core_io"], default-features = false }
|
||||
log = "0.4"
|
||||
|
||||
[features]
|
||||
ipv6 = []
|
||||
|
@ -1,10 +1,15 @@
|
||||
use crate::sd_reader;
|
||||
#![no_std]
|
||||
extern crate alloc;
|
||||
|
||||
use core::fmt;
|
||||
use alloc::{string::FromUtf8Error, string::String, vec::Vec};
|
||||
use core_io::{self as io, BufRead, BufReader, Read};
|
||||
|
||||
use libboard_zynq::sdio;
|
||||
|
||||
pub mod sd_reader;
|
||||
pub mod net_settings;
|
||||
pub mod load_pl;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<'a> {
|
||||
SdError(sdio::sd_card::CardInitializationError),
|
@ -1,4 +1,4 @@
|
||||
use crate::sd_reader;
|
||||
use super::sd_reader;
|
||||
use core_io::{Error, Read, Seek, SeekFrom};
|
||||
use libboard_zynq::{devc, sdio};
|
||||
use log::{info, debug};
|
@ -1,8 +1,7 @@
|
||||
use core::fmt;
|
||||
|
||||
use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress};
|
||||
|
||||
use crate::config;
|
||||
use super::Config;
|
||||
|
||||
pub struct NetAddresses {
|
||||
pub hardware_addr: EthernetAddress,
|
||||
@ -23,7 +22,7 @@ impl fmt::Display for NetAddresses {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_adresses(cfg: &config::Config) -> NetAddresses {
|
||||
pub fn get_adresses(cfg: &Config) -> NetAddresses {
|
||||
let mut hardware_addr = EthernetAddress([0x02, 0x00, 0x00, 0x00, 0x00, 0x52]);
|
||||
let mut ipv4_addr = IpAddress::v4(192, 168, 1, 52);
|
||||
let mut ipv6_addr = None;
|
@ -21,7 +21,6 @@ byteorder = { version = "1.3", default-features = false }
|
||||
void = { version = "1", default-features = false }
|
||||
futures = { version = "0.3", default-features = false, features = ["async-await"] }
|
||||
async-recursion = "0.3"
|
||||
fatfs = { version = "0.3", features = ["core_io"], default-features = false }
|
||||
log_buffer = { version = "1.2" }
|
||||
libm = { version = "0.2", features = ["unstable"] }
|
||||
vcell = "0.1"
|
||||
@ -36,3 +35,4 @@ dyld = { path = "../libdyld" }
|
||||
dwarf = { path = "../libdwarf" }
|
||||
unwind = { path = "../libunwind" }
|
||||
libc = { path = "../libc" }
|
||||
libconfig = { path = "../libconfig" }
|
||||
|
@ -20,9 +20,8 @@ use libboard_zynq::{
|
||||
use libcortex_a9::{semaphore::Semaphore, mutex::Mutex};
|
||||
use futures::{select_biased, future::FutureExt};
|
||||
use libasync::{smoltcp::{Sockets, TcpStream}, task};
|
||||
use libconfig::{Config, net_settings};
|
||||
|
||||
use crate::config;
|
||||
use crate::net_settings;
|
||||
use crate::proto_async::*;
|
||||
use crate::kernel;
|
||||
use crate::rpc;
|
||||
@ -315,7 +314,7 @@ async fn handle_connection(stream: &TcpStream, control: Rc<RefCell<kernel::Contr
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main(timer: GlobalTimer, cfg: &config::Config) {
|
||||
pub fn main(timer: GlobalTimer, cfg: &Config) {
|
||||
let net_addresses = net_settings::get_adresses(cfg);
|
||||
info!("network addresses: {}", net_addresses);
|
||||
|
||||
|
@ -21,10 +21,8 @@ use libregister::RegisterW;
|
||||
use nb;
|
||||
use void::Void;
|
||||
use embedded_hal::blocking::delay::DelayMs;
|
||||
use libconfig::{Config, load_pl};
|
||||
|
||||
mod sd_reader;
|
||||
mod config;
|
||||
mod net_settings;
|
||||
mod proto_core_io;
|
||||
mod proto_async;
|
||||
mod comms;
|
||||
@ -39,7 +37,6 @@ mod rtio;
|
||||
mod rtio;
|
||||
mod kernel;
|
||||
mod moninj;
|
||||
mod load_pl;
|
||||
mod eh_artiq;
|
||||
mod panic;
|
||||
mod logger;
|
||||
@ -99,7 +96,7 @@ fn identifier_read(buf: &mut [u8]) -> &str {
|
||||
}
|
||||
}
|
||||
|
||||
fn init_rtio(timer: &mut GlobalTimer, cfg: &config::Config) {
|
||||
fn init_rtio(timer: &mut GlobalTimer, cfg: &Config) {
|
||||
let clock_sel =
|
||||
if let Ok(rtioclk) = cfg.read_str("rtioclk") {
|
||||
match rtioclk.as_ref() {
|
||||
@ -197,11 +194,11 @@ pub fn main_core0() {
|
||||
init_gateware();
|
||||
info!("detected gateware: {}", identifier_read(&mut [0; 64]));
|
||||
|
||||
let cfg = match config::Config::new() {
|
||||
let cfg = match Config::new() {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
warn!("config initialization failed: {}", err);
|
||||
config::Config::new_dummy()
|
||||
Config::new_dummy()
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user