Compare commits

..

23 Commits

Author SHA1 Message Date
occheung dd32b6fe3f cargo fmt 2024-08-26 11:39:58 +08:00
occheung 246ba6795e drtio mgmt: remove lifetime qualifiers 2024-08-26 11:38:06 +08:00
occheung bfa9327a8e drtio mgmt: differentiate aux error and fail packets 2024-08-26 11:34:26 +08:00
occheung 6590084a1f satman: fix unsupported message response 2024-08-23 17:34:25 +08:00
occheung b3b092838c mgmt: update debug prints 2024-08-23 13:10:59 +08:00
occheung 538b50c412 mgmt: fix config reply to host 2024-08-23 13:10:43 +08:00
occheung be1f34bf7b drtio-mgmt: fix len order 2024-08-23 13:10:20 +08:00
occheung f7e2089b5b cargo fmt 2024-08-23 11:54:37 +08:00
occheung 1fc3ea40f7 drtio-mgmt: reorder last param 2024-08-23 11:46:16 +08:00
occheung 1683572838 drtio-mgmt: remove custom payload size 2024-08-23 11:37:55 +08:00
occheung 006981306f drtio_mgmt: reorganize drtio instructions 2024-08-23 11:09:07 +08:00
occheung 5a8db1dcf6 drtio-mgmt: fmt 2024-08-22 17:46:18 +08:00
occheung 37945e3a29 drtio_mgmt: remove satellite errors in mgmt 2024-08-22 13:09:04 +08:00
occheung 31936bee98 cargo fmt 2024-08-21 15:30:15 +08:00
occheung 60c347693f drtio_mgmt: impl unsuppported packets 2024-08-21 15:05:21 +08:00
occheung cc5a666dc6 drtio_proto; remove pull log request 2024-08-21 12:10:12 +08:00
occheung 5364e0fe6e mgmt: suppress warning 2024-08-20 17:06:55 +08:00
occheung c50be213ba remote pull_log: ignore last 2024-08-20 16:57:56 +08:00
occheung 844c083ee4 cargo fmt 2024-08-20 16:49:10 +08:00
occheung b4cc072e8e mgmt: impl pull log 2024-08-20 16:48:04 +08:00
occheung 1a6782db03 drtio_proto: cargo fmt 2024-08-19 12:03:24 +08:00
occheung 740c2f1fc0 runtime/mgmt: dispatch->process 2024-08-19 12:01:36 +08:00
occheung 062a17b9ed init 2024-08-16 17:47:41 +08:00
12 changed files with 556 additions and 212 deletions

8
bare_zynq.json Normal file
View File

@ -0,0 +1,8 @@
{
"target": "kasli_soc",
"variant": "bare_zynq",
"hw_rev": "v1.1",
"drtio_role": "standalone",
"core_addr": "192.168.1.200",
"peripherals": []
}

8
bare_zynq_master.json Normal file
View File

@ -0,0 +1,8 @@
{
"target": "kasli_soc",
"variant": "bare_zynq_master",
"hw_rev": "v1.1",
"drtio_role": "master",
"core_addr": "192.168.1.200",
"peripherals": []
}

7
bare_zynq_sat1.json Normal file
View File

@ -0,0 +1,7 @@
{
"target": "kasli_soc",
"variant": "bare_zynq_sat1",
"hw_rev": "v1.1",
"drtio_role": "satellite",
"peripherals": []
}

7
bare_zynq_sat2.json Normal file
View File

@ -0,0 +1,7 @@
{
"target": "kasli_soc",
"variant": "bare_zynq_sat2",
"hw_rev": "v1.1",
"drtio_role": "satellite",
"peripherals": []
}

View File

@ -11,17 +11,16 @@
"src-pythonparser": "src-pythonparser" "src-pythonparser": "src-pythonparser"
}, },
"locked": { "locked": {
"lastModified": 1722417433, "dirtyRev": "378d962edb37a7c2a94e963251822246be009b0e-dirty",
"narHash": "sha256-QEbcVdL1sUQEbMCvCUvPM8DKqwOth3gJpdiLTf4hPN8=", "dirtyShortRev": "378d962ed-dirty",
"ref": "refs/heads/master", "lastModified": 1721962540,
"rev": "0623480c82c28d57e14dc4f363374758a52284d3", "narHash": "sha256-BJG4l1V7kJXBWgBkfYKq8xW8rCfc7fnjCSp5xMiGvsU=",
"revCount": 8952,
"type": "git", "type": "git",
"url": "https://github.com/m-labs/artiq.git" "url": "file:///home/occheung/artiq"
}, },
"original": { "original": {
"type": "git", "type": "git",
"url": "https://github.com/m-labs/artiq.git" "url": "file:///home/occheung/artiq"
} }
}, },
"artiq-comtools": { "artiq-comtools": {
@ -37,11 +36,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1720768567, "lastModified": 1717637438,
"narHash": "sha256-3VoK7o5MtHtbHLrc6Pv+eQWFtaz5Gd/YWyV5TD3c5Ss=", "narHash": "sha256-BXFidNm3Em8iChPGu1L0s2bY+f2yQ0VVid4MuOoTehw=",
"owner": "m-labs", "owner": "m-labs",
"repo": "artiq-comtools", "repo": "artiq-comtools",
"rev": "f93570d8f2ed5a3cfb3e1c16ab00f2540551e994", "rev": "78d27026efe76a13f7b4698a554f55811369ec4d",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -102,16 +101,16 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1721924956, "lastModified": 1720386169,
"narHash": "sha256-Sb1jlyRO+N8jBXEX9Pg9Z1Qb8Bw9QyOgLDNMEpmjZ2M=", "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "5ad6a14c6bf098e98800b091668718c336effc95", "rev": "194846768975b7ad2c4988bdb82572c00222c0d7",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "NixOS",
"ref": "nixos-unstable", "ref": "nixos-24.05",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
@ -131,11 +130,11 @@
] ]
}, },
"locked": { "locked": {
"lastModified": 1722046723, "lastModified": 1720491570,
"narHash": "sha256-G7/gHz8ORRvHd1/RIURrdcswKRPe9K0FsIYR4v5jSWo=", "narHash": "sha256-PHS2BcQ9kxBpu9GKlDg3uAlrX/ahQOoAiVmwGl6BjD4=",
"owner": "oxalica", "owner": "oxalica",
"repo": "rust-overlay", "repo": "rust-overlay",
"rev": "56baac5e6b2743d4730e664ea64f6d8a2aad0fbb", "rev": "b970af40fdc4bd80fd764796c5f97c15e2b564eb",
"type": "github" "type": "github"
}, },
"original": { "original": {
@ -168,11 +167,11 @@
"src-migen": { "src-migen": {
"flake": false, "flake": false,
"locked": { "locked": {
"lastModified": 1721561053, "lastModified": 1720332047,
"narHash": "sha256-z3LRhNmKZrjr6rFD0yxtccSa/SWvFIYmb+G/D5d2Jd8=", "narHash": "sha256-FdYVEHVtXHrzPhBqpXOTo9uHQAtuCsDPmAPY8JrfHOY=",
"owner": "m-labs", "owner": "m-labs",
"repo": "migen", "repo": "migen",
"rev": "9279e8623f8433bc4f23ac51e5e2331bfe544417", "rev": "60739a161e64630ce7ba62d1a5bac1252b66c3b9",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -1,7 +1,8 @@
{ {
description = "ARTIQ port to the Zynq-7000 platform"; description = "ARTIQ port to the Zynq-7000 platform";
inputs.artiq.url = git+https://github.com/m-labs/artiq.git; # inputs.artiq.url = git+https://github.com/m-labs/artiq.git;
inputs.artiq.url = git+file:///home/occheung/artiq;
inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; }; inputs.mozilla-overlay = { url = github:mozilla/nixpkgs-mozilla; flake = false; };
inputs.zynq-rs.url = git+https://git.m-labs.hk/m-labs/zynq-rs; inputs.zynq-rs.url = git+https://git.m-labs.hk/m-labs/zynq-rs;
inputs.zynq-rs.inputs.nixpkgs.follows = "artiq/nixpkgs"; inputs.zynq-rs.inputs.nixpkgs.follows = "artiq/nixpkgs";
@ -109,7 +110,7 @@
fsblTargets = ["zc702" "zc706" "zed"]; fsblTargets = ["zc702" "zc706" "zed"];
sat_variants = [ sat_variants = [
# kasli-soc satellite variants # kasli-soc satellite variants
"satellite" "satellite" "bare_zynq_sat1" "bare_zynq_sat2"
# zc706 satellite variants # zc706 satellite variants
"nist_clock_satellite" "nist_qc2_satellite" "acpki_nist_clock_satellite" "acpki_nist_qc2_satellite" "nist_clock_satellite" "nist_qc2_satellite" "acpki_nist_clock_satellite" "acpki_nist_qc2_satellite"
"nist_clock_satellite_100mhz" "nist_qc2_satellite_100mhz" "acpki_nist_clock_satellite_100mhz" "acpki_nist_qc2_satellite_100mhz" "nist_clock_satellite_100mhz" "nist_qc2_satellite_100mhz" "acpki_nist_clock_satellite_100mhz" "acpki_nist_qc2_satellite_100mhz"
@ -364,6 +365,10 @@
(board-package-set { target = "zc706"; variant = "acpki_nist_qc2_satellite_100mhz"; }) // (board-package-set { target = "zc706"; variant = "acpki_nist_qc2_satellite_100mhz"; }) //
(board-package-set { target = "kasli_soc"; variant = "demo"; json = ./demo.json; }) // (board-package-set { target = "kasli_soc"; variant = "demo"; json = ./demo.json; }) //
(board-package-set { target = "kasli_soc"; variant = "master"; json = ./kasli-soc-master.json; }) // (board-package-set { target = "kasli_soc"; variant = "master"; json = ./kasli-soc-master.json; }) //
(board-package-set { target = "kasli_soc"; variant = "bare_zynq"; json = ./bare_zynq.json; }) //
(board-package-set { target = "kasli_soc"; variant = "bare_zynq_master"; json = ./bare_zynq_master.json; }) //
(board-package-set { target = "kasli_soc"; variant = "bare_zynq_sat1"; json = ./bare_zynq_sat1.json; }) //
(board-package-set { target = "kasli_soc"; variant = "bare_zynq_sat2"; json = ./bare_zynq_sat2.json; }) //
(board-package-set { target = "kasli_soc"; variant = "satellite"; json = ./kasli-soc-satellite.json; }); (board-package-set { target = "kasli_soc"; variant = "satellite"; json = ./kasli-soc-satellite.json; });
hydraJobs = packages.x86_64-linux // { inherit zc706-hitl-tests; inherit gateware-sim; inherit fmt-check; }; hydraJobs = packages.x86_64-linux // { inherit zc706-hitl-tests; inherit gateware-sim; inherit fmt-check; };

222
src/Cargo.lock generated
View File

@ -2,6 +2,15 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.4" version = "0.7.4"
@ -246,10 +255,10 @@ dependencies = [
"libsupport_zynq", "libsupport_zynq",
"log", "log",
"log_buffer", "log_buffer",
"nalgebra",
"nb 0.1.3", "nb 0.1.3",
"unwind", "unwind",
"vcell", "vcell",
"nalgebra",
"void", "void",
] ]
@ -383,6 +392,19 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577" checksum = "c75de51135344a4f8ed3cfe2720dc27736f7711989703a0b43aadf3753c55577"
[[package]]
name = "nalgebra"
version = "0.32.6"
source = "git+https://git.m-labs.hk/M-labs/nalgebra?rev=dd00f9b#dd00f9b46046e0b931d1b470166db02fd29591be"
dependencies = [
"approx",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]] [[package]]
name = "nb" name = "nb"
version = "0.1.3" version = "0.1.3"
@ -398,6 +420,15 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae" checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae"
[[package]]
name = "num-complex"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085"
dependencies = [
"num-traits",
]
[[package]] [[package]]
name = "num-derive" name = "num-derive"
version = "0.3.3" version = "0.3.3"
@ -409,6 +440,26 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"autocfg",
"num-integer",
"num-traits",
]
[[package]] [[package]]
name = "num-traits" name = "num-traits"
version = "0.2.15" version = "0.2.15"
@ -416,8 +467,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [ dependencies = [
"autocfg", "autocfg",
"libm",
] ]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]] [[package]]
name = "pin-project-lite" name = "pin-project-lite"
version = "0.2.9" version = "0.2.9"
@ -501,6 +559,7 @@ name = "satman"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"build_zynq", "build_zynq",
"byteorder",
"core_io", "core_io",
"cslice", "cslice",
"embedded-hal", "embedded-hal",
@ -515,6 +574,8 @@ dependencies = [
"libregister", "libregister",
"libsupport_zynq", "libsupport_zynq",
"log", "log",
"num-derive",
"num-traits",
"unwind", "unwind",
] ]
@ -524,6 +585,18 @@ version = "0.1.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac" checksum = "d4f410fedcf71af0345d7607d246e7ad15faaadd49d240ee3b24e5dc21a820ac"
[[package]]
name = "simba"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50582927ed6f77e4ac020c057f37a268fc6aebc29225050365aacbb9deeeddc4"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
]
[[package]] [[package]]
name = "smoltcp" name = "smoltcp"
version = "0.7.5" version = "0.7.5"
@ -556,6 +629,12 @@ dependencies = [
"log", "log",
] ]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.5" version = "1.0.5"
@ -572,147 +651,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "nalgebra"
version = "0.32.6"
source = "git+https://git.m-labs.hk/M-labs/nalgebra?rev=dd00f9b#dd00f9b46046e0b931d1b470166db02fd29591be"
dependencies = [
"approx",
"matrixmultiply",
"nalgebra-macros",
"num-complex",
"num-rational",
"num-traits",
"simba",
"typenum",
]
[[package]]
name = "approx"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cab112f0a86d568ea0e627cc1d6be74a1e9cd55214684db5561995f6dad897c6"
dependencies = [
"num-traits",
]
[[package]]
name = "matrixmultiply"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7574c1cf36da4798ab73da5b215bbf444f50718207754cb522201d78d1cd0ff2"
dependencies = [
"autocfg",
"rawpointer",
]
[[package]]
name = "nalgebra-macros"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "91761aed67d03ad966ef783ae962ef9bbaca728d2dd7ceb7939ec110fffad998"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "num-complex"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26873667bbbb7c5182d4a37c1add32cdf09f841af72da53318fdb81543c15085"
dependencies = [
"num-traits",
]
[[package]]
name = "num-rational"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a"
dependencies = [
"num-bigint",
"num-integer",
"num-traits",
]
[[package]]
name = "simba"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50582927ed6f77e4ac020c057f37a268fc6aebc29225050365aacbb9deeeddc4"
dependencies = [
"approx",
"num-complex",
"num-traits",
"paste",
"wide",
]
[[package]]
name = "typenum"
version = "1.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825"
[[package]]
name = "rawpointer"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3"
[[package]]
name = "num-bigint"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e0d047c1062aa51e256408c560894e5251f08925980e53cf1aa5bd00eec6512"
dependencies = [
"num-integer",
"num-traits",
]
[[package]]
name = "num-integer"
version = "0.1.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
dependencies = [
"num-traits",
]
[[package]]
name = "paste"
version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
[[package]]
name = "wide"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd89cf484471f953ee84f07c0dff0ea20e9ddf976f03cabdf5dda48b221f22e7"
features = ["no_std"]
dependencies = [
"bytemuck",
"safe_arch",
]
[[package]]
name = "bytemuck"
version = "1.16.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b236fc92302c97ed75b38da1f4917b5cdda4984745740f153a5d3059e48d725e"
[[package]]
name = "safe_arch"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "794821e4ccb0d9f979512f9c1973480123f9bd62a90d74ab0f9426fcf8f4a529"
dependencies = [
"bytemuck",
]
[[package]] [[package]]
name = "vcell" name = "vcell"
version = "0.1.3" version = "0.1.3"

View File

@ -783,7 +783,7 @@ pub fn main(timer: GlobalTimer, cfg: Config) {
} }
} }
mgmt::start(cfg, Some((&aux_mutex, &drtio_routing_table, timer))); mgmt::start(cfg, &aux_mutex, &drtio_routing_table, timer);
task::spawn(async move { task::spawn(async move {
let connection = Rc::new(Semaphore::new(1, 1)); let connection = Rc::new(Semaphore::new(1, 1));
@ -886,7 +886,7 @@ pub fn soft_panic_main(timer: GlobalTimer, cfg: Config) -> ! {
Sockets::init(32); Sockets::init(32);
mgmt::start(cfg, None); // mgmt::start(cfg);
// getting eth settings disables the LED as it resets GPIO // getting eth settings disables the LED as it resets GPIO
// need to re-enable it here // need to re-enable it here

View File

@ -1,5 +1,5 @@
use alloc::{rc::Rc, string::String, vec::Vec}; use alloc::{rc::Rc, string::String, vec::Vec};
use core::{cell::RefCell, ops::Deref}; use core::cell::RefCell;
use futures::{future::poll_fn, task::Poll}; use futures::{future::poll_fn, task::Poll};
use libasync::{smoltcp::TcpStream, task}; use libasync::{smoltcp::TcpStream, task};
@ -81,18 +81,24 @@ pub enum Reply {
ConfigData = 7, ConfigData = 7,
} }
async fn read_log_level_filter(stream: &mut TcpStream) -> Result<log::LevelFilter> { pub fn byte_to_level_filter(level_byte: u8) -> Result<log::LevelFilter> {
Ok(match read_i8(stream).await? { Ok(match level_byte {
0 => log::LevelFilter::Off, 0 => log::LevelFilter::Off,
1 => log::LevelFilter::Error, 1 => log::LevelFilter::Error,
2 => log::LevelFilter::Warn, 2 => log::LevelFilter::Warn,
3 => log::LevelFilter::Info, 3 => log::LevelFilter::Info,
4 => log::LevelFilter::Debug, 4 => log::LevelFilter::Debug,
5 => log::LevelFilter::Trace, 5 => log::LevelFilter::Trace,
lv => return Err(Error::UnknownLogLevel(lv as u8)), lv => return Err(Error::UnknownLogLevel(lv)),
}) })
} }
async fn read_log_level_filter(stream: &mut TcpStream) -> Result<log::LevelFilter> {
let level_byte = read_i8(stream).await? as u8;
byte_to_level_filter(level_byte)
}
async fn get_logger_buffer_pred<F>(f: F) -> LogBufferRef<'static> async fn get_logger_buffer_pred<F>(f: F) -> LogBufferRef<'static>
where F: Fn(&LogBufferRef) -> bool { where F: Fn(&LogBufferRef) -> bool {
poll_fn(|ctx| { poll_fn(|ctx| {
@ -738,23 +744,19 @@ mod local_coremgmt {
#[cfg(has_drtio)] #[cfg(has_drtio)]
macro_rules! process { macro_rules! process {
($stream: ident, $drtio_tuple:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{ ($stream: ident, $timer:ident, $aux_mutex:ident, $routing_table:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{
if $destination == 0 { if $destination == 0 {
local_coremgmt::$func($stream, $($param, )*).await local_coremgmt::$func($stream, $($param, )*).await
} else if let Some((aux_mutex, routing_table, timer)) = $drtio_tuple {
let linkno = routing_table.0[$destination as usize][0] - 1 as u8;
remote_coremgmt::$func($stream, aux_mutex, routing_table, timer, linkno, $destination, $($param, )*).await
} else { } else {
error!("coremgmt-over-drtio not supported for panicked device, please reboot"); let linkno = $routing_table.0[$destination as usize][0] - 1 as u8;
write_i8($stream, Reply::Error as i8).await?; remote_coremgmt::$func($stream, $aux_mutex, $routing_table, $timer, linkno, $destination, $($param, )*).await
Err(drtio::Error::LinkDown.into())
} }
}} }}
} }
#[cfg(not(has_drtio))] #[cfg(not(has_drtio))]
macro_rules! process { macro_rules! process {
($stream: ident, $drtio_tuple:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{ ($stream: ident, $timer:ident, $aux_mutex:ident, $routing_table:ident, $destination:expr, $func:ident $(, $param:expr)*) => {{
local_coremgmt::$func($stream, $($param, )*).await local_coremgmt::$func($stream, $($param, )*).await
}} }}
} }
@ -763,7 +765,9 @@ async fn handle_connection(
stream: &mut TcpStream, stream: &mut TcpStream,
pull_id: Rc<RefCell<u32>>, pull_id: Rc<RefCell<u32>>,
cfg: Rc<Config>, cfg: Rc<Config>,
_drtio_tuple: Option<(&Rc<Mutex<bool>>, &RoutingTable, GlobalTimer)>, _aux_mutex: &Rc<Mutex<bool>>,
_routing_table: &RoutingTable,
_timer: GlobalTimer,
) -> Result<()> { ) -> Result<()> {
if !expect(&stream, b"ARTIQ management\n").await? { if !expect(&stream, b"ARTIQ management\n").await? {
return Err(Error::UnexpectedPattern); return Err(Error::UnexpectedPattern);
@ -779,11 +783,13 @@ async fn handle_connection(
} }
let msg: Request = FromPrimitive::from_i8(msg?).ok_or(Error::UnrecognizedPacket)?; let msg: Request = FromPrimitive::from_i8(msg?).ok_or(Error::UnrecognizedPacket)?;
match msg { match msg {
Request::GetLog => process!(stream, _drtio_tuple, _destination, get_log), Request::GetLog => process!(stream, _timer, _aux_mutex, _routing_table, _destination, get_log),
Request::ClearLog => process!(stream, _drtio_tuple, _destination, clear_log), Request::ClearLog => process!(stream, _timer, _aux_mutex, _routing_table, _destination, clear_log),
Request::PullLog => process!( Request::PullLog => process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
pull_log, pull_log,
&pull_id &pull_id
@ -792,7 +798,9 @@ async fn handle_connection(
let lvl = read_log_level_filter(stream).await?; let lvl = read_log_level_filter(stream).await?;
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
set_log_filter, set_log_filter,
lvl lvl
@ -802,7 +810,9 @@ async fn handle_connection(
let lvl = read_log_level_filter(stream).await?; let lvl = read_log_level_filter(stream).await?;
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
set_uart_log_filter, set_uart_log_filter,
lvl lvl
@ -812,7 +822,9 @@ async fn handle_connection(
let key = read_key(stream).await?; let key = read_key(stream).await?;
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
config_read, config_read,
&cfg, &cfg,
@ -830,7 +842,9 @@ async fn handle_connection(
read_chunk(stream, &mut buffer).await?; read_chunk(stream, &mut buffer).await?;
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
config_write, config_write,
&cfg, &cfg,
@ -842,7 +856,9 @@ async fn handle_connection(
let key = read_key(stream).await?; let key = read_key(stream).await?;
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
config_remove, config_remove,
&cfg, &cfg,
@ -850,15 +866,17 @@ async fn handle_connection(
) )
} }
Request::Reboot => { Request::Reboot => {
process!(stream, _drtio_tuple, _destination, reboot) process!(stream, _timer, _aux_mutex, _routing_table, _destination, reboot)
} }
Request::ConfigErase => { Request::ConfigErase => {
process!(stream, _drtio_tuple, _destination, config_erase) process!(stream, _timer, _aux_mutex, _routing_table, _destination, config_erase)
} }
Request::DebugAllocator => { Request::DebugAllocator => {
process!( process!(
stream, stream,
_drtio_tuple, _timer,
_aux_mutex,
_routing_table,
_destination, _destination,
debug_allocator debug_allocator
) )
@ -869,15 +887,12 @@ async fn handle_connection(
pub fn start( pub fn start(
cfg: Config, cfg: Config,
drtio_tuple: Option<( aux_mutex: &Rc<Mutex<bool>>,
&Rc<Mutex<bool>>, routing_table: &Rc<RefCell<drtio_routing::RoutingTable>>,
&Rc<RefCell<drtio_routing::RoutingTable>>, timer: GlobalTimer,
GlobalTimer,
)>,
) { ) {
let drtio_tuple = drtio_tuple.map( let aux_mutex = aux_mutex.clone();
|(aux_mutex, routing_table, timer)| (aux_mutex.clone(), routing_table.clone(), timer) let routing_table = routing_table.clone();
);
task::spawn(async move { task::spawn(async move {
let pull_id = Rc::new(RefCell::new(0u32)); let pull_id = Rc::new(RefCell::new(0u32));
let cfg = Rc::new(cfg); let cfg = Rc::new(cfg);
@ -885,19 +900,12 @@ pub fn start(
let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap(); let mut stream = TcpStream::accept(1380, 2048, 2048).await.unwrap();
let pull_id = pull_id.clone(); let pull_id = pull_id.clone();
let cfg = cfg.clone(); let cfg = cfg.clone();
let aux_mutex = aux_mutex.clone();
let drtio_tuple = drtio_tuple.clone(); let routing_table = routing_table.clone();
task::spawn(async move { task::spawn(async move {
info!("received connection"); info!("received connection");
// Avoid consuming the tuple let routing_table = routing_table.borrow();
// Keep the borrowed value on stack let _ = handle_connection(&mut stream, pull_id, cfg, &aux_mutex, &routing_table, timer)
let drtio_tuple = drtio_tuple.as_ref().map(
|(aux_mutex, routing_table, timer)| (aux_mutex, routing_table.borrow(), *timer)
);
let drtio_tuple = drtio_tuple.as_ref().map(
|(aux_mutex, routing_table, timer)| (*aux_mutex, routing_table.deref(), *timer)
);
let _ = handle_connection(&mut stream, pull_id, cfg, drtio_tuple)
.await .await
.map_err(|e| warn!("connection terminated: {:?}", e)); .map_err(|e| warn!("connection terminated: {:?}", e));
let _ = stream.flush().await; let _ = stream.flush().await;

View File

@ -540,7 +540,7 @@ pub mod drtio {
} }
} }
pub async fn partition_data<PacketF, HandlerF>( pub async fn partition_data<PacketF, HandlerF, E>(
linkno: u8, linkno: u8,
aux_mutex: &Rc<Mutex<bool>>, aux_mutex: &Rc<Mutex<bool>>,
routing_table: &RoutingTable, routing_table: &RoutingTable,
@ -548,10 +548,11 @@ pub mod drtio {
data: &[u8], data: &[u8],
packet_f: PacketF, packet_f: PacketF,
reply_handler_f: HandlerF, reply_handler_f: HandlerF,
) -> Result<(), Error> ) -> Result<(), E>
where where
PacketF: Fn(&[u8; MASTER_PAYLOAD_MAX_SIZE], PayloadStatus, usize) -> Packet, PacketF: Fn(&[u8; MASTER_PAYLOAD_MAX_SIZE], PayloadStatus, usize) -> Packet,
HandlerF: Fn(&Packet) -> Result<(), Error>, HandlerF: Fn(&Packet) -> Result<(), E>,
E: From<Error>,
{ {
let mut i = 0; let mut i = 0;
while i < data.len() { while i < data.len() {
@ -887,6 +888,363 @@ pub mod drtio {
) )
.await .await
} }
// pub async fn destination_get_log(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<Vec<u8>, Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let mut remote_log: Vec<u8> = Vec::new();
// loop {
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationGetLogRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationGetLogReply {
// last,
// length,
// data,
// } => {
// remote_log.extend(&data[0..length as usize]);
// if last {
// return Ok(remote_log);
// }
// }
// _ => return Err(Error::UnexpectedReply),
// }
// }
// }
// pub async fn destination_clear_log(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationClearLogRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => return Err(Error::ClearLogFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_pull_log(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<Vec<u8>, Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let mut remote_log: Vec<u8> = Vec::new();
// loop {
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationPullLogRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationPullLogReply {
// destination: 0,
// last,
// length,
// data,
// } => {
// remote_log.extend(&data[0..length as usize]);
// if last {
// return Ok(remote_log);
// }
// }
// _ => return Err(Error::UnexpectedReply),
// }
// }
// }
// pub async fn destination_set_log_level(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// log_level: log::LevelFilter,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationSetLogLevelRequest {
// destination: destination,
// log_level: log_level as u8,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => return Err(Error::SetLogLevelFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_set_uart_log_level(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// log_level: log::LevelFilter,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationSetUartLogLevelRequest {
// destination: destination,
// log_level: log_level as u8,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => return Err(Error::SetUartLogLevelFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_read_config(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// key: &[u8],
// ) -> Result<Vec<u8>, Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let length = key.len();
// // Assume key and value can fit within a DRTIO AUX packet together
// let mut key_slice: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
// key_slice[..length].clone_from_slice(key);
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationConfigReadRequest {
// destination: destination,
// length: length as u16,
// key: key_slice,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationConfigReadReply {
// destination: 0,
// succeeded: true,
// length,
// value,
// } => Ok(Vec::from(&value[..length as usize])),
// Packet::DestinationConfigReadReply {
// destination: 0,
// succeeded: false,
// ..
// } => Err(Error::ReadConfigFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_write_config(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// key: &str,
// value: &[u8],
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let total_len = 4 + key.len() + 4 + value.len();
// let mut payload = Cursor::new(Vec::with_capacity(total_len));
// payload.write_string(key).unwrap();
// payload.write_bytes(value).unwrap();
// assert_eq!(value[value.len()-1], payload.get_ref()[total_len-1]);
// partition_data(
// linkno,
// aux_mutex,
// routing_table,
// timer,
// &payload.get_ref(),
// |slice, status, len| Packet::DestinationConfigWriteRequest {
// destination: destination,
// length: len as u16,
// last: status.is_last(),
// data: *slice,
// },
// |reply| match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => Err(Error::WriteConfigFail(destination)),
// _ => Err(Error::UnexpectedReply),
// },
// ).await
// }
// pub async fn destination_remove_config(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// key: &[u8],
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let length = key.len();
// let mut key_slice: [u8; CORE_MGMT_PAYLOAD_MAX_SIZE] = [0; CORE_MGMT_PAYLOAD_MAX_SIZE];
// key_slice[..length].clone_from_slice(key);
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationConfigRemoveRequest {
// destination: destination,
// length: length as u16,
// key: key_slice,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => Err(Error::RemoveConfigFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_erase_config(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationConfigEraseRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => Err(Error::EraseConfigFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_reboot(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationRebootRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// Packet::DestinationMgmtAck {
// succeeded: false,
// } => Err(Error::RebootFail(destination)),
// _ => Err(Error::UnexpectedReply),
// }
// }
// pub async fn destination_allocator_debug(
// aux_mutex: &Rc<Mutex<bool>>,
// routing_table: &RoutingTable,
// timer: GlobalTimer,
// destination: u8,
// ) -> Result<(), Error> {
// let linkno = routing_table.0[destination as usize][0] - 1;
// let reply = aux_transact(
// aux_mutex,
// linkno,
// routing_table,
// &Packet::DestinationAllocatorDebugRequest {
// destination: destination,
// },
// timer,
// )
// .await?;
// match reply {
// Packet::DestinationMgmtAck {
// succeeded: true,
// } => Ok(()),
// _ => Err(Error::UnexpectedReply),
// }
// }
} }
#[cfg(not(has_drtio))] #[cfg(not(has_drtio))]

View File

@ -14,8 +14,11 @@ default = ["target_zc706", ]
build_zynq = { path = "../libbuild_zynq" } build_zynq = { path = "../libbuild_zynq" }
[dependencies] [dependencies]
num-traits = { version = "0.2", default-features = false }
num-derive = "0.3"
log = { version = "0.4", default-features = false } log = { version = "0.4", default-features = false }
core_io = { version = "0.1", features = ["collections"] } core_io = { version = "0.1", features = ["collections"] }
byteorder = { version = "1.3", default-features = false }
cslice = "0.3" cslice = "0.3"
embedded-hal = "0.2" embedded-hal = "0.2"

View File

@ -4,9 +4,12 @@
#[macro_use] #[macro_use]
extern crate log; extern crate log;
extern crate byteorder;
extern crate core_io; extern crate core_io;
extern crate cslice; extern crate cslice;
extern crate embedded_hal; extern crate embedded_hal;
extern crate num_derive;
extern crate num_traits;
extern crate io; extern crate io;
extern crate ksupport; extern crate ksupport;