forked from M-Labs/artiq-zynq
add network address config code
This commit is contained in:
parent
e207c073ee
commit
bbe6812792
|
@ -15,7 +15,7 @@ let
|
||||||
version = "0.1.0";
|
version = "0.1.0";
|
||||||
|
|
||||||
src = ./src;
|
src = ./src;
|
||||||
cargoSha256 = "1ybqf370xqcvs94zs542ydm5jszwrfqwlnr3xwn5yn2zp4cnv0vd";
|
cargoSha256 = "0lwsbs1b6538b3zzvazy43xwy4rx1q0chxn3c9529nf3dk6xb22n";
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
pkgs.gnumake
|
pkgs.gnumake
|
||||||
|
|
|
@ -200,7 +200,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libasync"
|
name = "libasync"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f"
|
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#ae4d3e2455d319308d5a1dd27c06a116c8e951f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
"libcortex_a9",
|
"libcortex_a9",
|
||||||
|
@ -212,7 +212,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libboard_zynq"
|
name = "libboard_zynq"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f"
|
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#ae4d3e2455d319308d5a1dd27c06a116c8e951f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"embedded-hal",
|
"embedded-hal",
|
||||||
|
@ -236,7 +236,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcortex_a9"
|
name = "libcortex_a9"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f"
|
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#ae4d3e2455d319308d5a1dd27c06a116c8e951f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"libregister",
|
"libregister",
|
||||||
|
@ -245,7 +245,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libregister"
|
name = "libregister"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f"
|
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#ae4d3e2455d319308d5a1dd27c06a116c8e951f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bit_field",
|
"bit_field",
|
||||||
"vcell",
|
"vcell",
|
||||||
|
@ -255,7 +255,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libsupport_zynq"
|
name = "libsupport_zynq"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#9fcf9243f2dd2e9fcd61d17ddb1d6d495a68893f"
|
source = "git+https://git.m-labs.hk/M-Labs/zc706.git#ae4d3e2455d319308d5a1dd27c06a116c8e951f0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"compiler_builtins",
|
"compiler_builtins",
|
||||||
"libboard_zynq",
|
"libboard_zynq",
|
||||||
|
|
|
@ -7,13 +7,14 @@
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use core::{cmp, str};
|
use core::{cmp, str};
|
||||||
use log::{info, error};
|
use log::info;
|
||||||
|
|
||||||
use libboard_zynq::{timer::GlobalTimer, logger, devc, slcr};
|
use libboard_zynq::{timer::GlobalTimer, logger, devc, slcr};
|
||||||
use libsupport_zynq::ram;
|
use libsupport_zynq::ram;
|
||||||
|
|
||||||
mod sd_reader;
|
mod sd_reader;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod net_settings;
|
||||||
mod proto_core_io;
|
mod proto_core_io;
|
||||||
mod proto_async;
|
mod proto_async;
|
||||||
mod comms;
|
mod comms;
|
||||||
|
@ -49,24 +50,6 @@ pub fn main_core0() {
|
||||||
|
|
||||||
ram::init_alloc_linker();
|
ram::init_alloc_linker();
|
||||||
|
|
||||||
match config::Config::new() {
|
|
||||||
Ok(mut cfg) => {
|
|
||||||
match cfg.read_str("FOO") {
|
|
||||||
Ok(val) => info!("FOO = {}", val),
|
|
||||||
Err(error) => info!("failed to read config FOO: {}", error),
|
|
||||||
}
|
|
||||||
match cfg.read_str("BAR") {
|
|
||||||
Ok(val) => info!("BAR = {}", val),
|
|
||||||
Err(error) => info!("failed to read config BAR: {}", error),
|
|
||||||
}
|
|
||||||
match cfg.read_str("FOOBAR") {
|
|
||||||
Ok(val) => info!("read FOOBAR = {}", val),
|
|
||||||
Err(error) => info!("failed to read config FOOBAR: {}", error),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
Err(error) => error!("config failed: {}", error)
|
|
||||||
}
|
|
||||||
|
|
||||||
if devc::DevC::new().is_done() {
|
if devc::DevC::new().is_done() {
|
||||||
info!("gateware already loaded");
|
info!("gateware already loaded");
|
||||||
// Do not load again: assume that the gateware already present is
|
// Do not load again: assume that the gateware already present is
|
||||||
|
@ -89,5 +72,7 @@ pub fn main_core0() {
|
||||||
pl::csr::rtio_core::reset_phy_write(1);
|
pl::csr::rtio_core::reset_phy_write(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info!("network addresses: {}", net_settings::get_adresses());
|
||||||
|
|
||||||
comms::main(timer);
|
comms::main(timer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
use core::fmt;
|
||||||
|
|
||||||
|
use libboard_zynq::smoltcp::wire::{EthernetAddress, IpAddress};
|
||||||
|
|
||||||
|
use crate::config;
|
||||||
|
|
||||||
|
pub struct NetAddresses {
|
||||||
|
pub hardware_addr: EthernetAddress,
|
||||||
|
pub ipv4_addr: IpAddress,
|
||||||
|
pub ipv6_ll_addr: IpAddress,
|
||||||
|
pub ipv6_addr: Option<IpAddress>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for NetAddresses {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
|
write!(f, "MAC={} IPv4={} IPv6-LL={} IPv6=",
|
||||||
|
self.hardware_addr, self.ipv4_addr, self.ipv6_ll_addr)?;
|
||||||
|
match self.ipv6_addr {
|
||||||
|
Some(addr) => write!(f, "{}", addr)?,
|
||||||
|
None => write!(f, "no configured address")?
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_adresses() -> 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;
|
||||||
|
|
||||||
|
if let Ok(cfg) = config::Config::new() {
|
||||||
|
if let Ok(Ok(addr)) = cfg.read_str("mac").map(|s| s.parse()) {
|
||||||
|
hardware_addr = addr;
|
||||||
|
}
|
||||||
|
if let Ok(Ok(addr)) = cfg.read_str("ip").map(|s| s.parse()) {
|
||||||
|
ipv4_addr = addr;
|
||||||
|
}
|
||||||
|
if let Ok(Ok(addr)) = cfg.read_str("ip6").map(|s| s.parse()) {
|
||||||
|
ipv6_addr = Some(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let ipv6_ll_addr = IpAddress::v6(
|
||||||
|
0xfe80, 0x0000, 0x0000, 0x0000,
|
||||||
|
(((hardware_addr.0[0] ^ 0x02) as u16) << 8) | (hardware_addr.0[1] as u16),
|
||||||
|
((hardware_addr.0[2] as u16) << 8) | 0x00ff,
|
||||||
|
0xfe00 | (hardware_addr.0[3] as u16),
|
||||||
|
((hardware_addr.0[4] as u16) << 8) | (hardware_addr.0[5] as u16));
|
||||||
|
|
||||||
|
NetAddresses {
|
||||||
|
hardware_addr: hardware_addr,
|
||||||
|
ipv4_addr: ipv4_addr,
|
||||||
|
ipv6_ll_addr: ipv6_ll_addr,
|
||||||
|
ipv6_addr: ipv6_addr
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue