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