From 3d29a7ed14b9445397368a950dea03b73a388674 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 11 Sep 2018 11:27:56 +0800 Subject: [PATCH] firmware: add fmt::Display to RoutingTable --- .../firmware/libboard_artiq/drtio_routing.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/artiq/firmware/libboard_artiq/drtio_routing.rs b/artiq/firmware/libboard_artiq/drtio_routing.rs index f5b7c735c..4a3a08c12 100644 --- a/artiq/firmware/libboard_artiq/drtio_routing.rs +++ b/artiq/firmware/libboard_artiq/drtio_routing.rs @@ -1,4 +1,5 @@ use board_misoc::{csr, config}; +use core::fmt; pub const DEST_COUNT: usize = 256; pub const MAX_HOPS: usize = 32; @@ -26,6 +27,26 @@ impl RoutingTable { } } +impl fmt::Display for RoutingTable { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "RoutingTable {{")?; + for i in 0..DEST_COUNT { + if self.0[i][0] != INVALID_HOP { + write!(f, "{}:", i)?; + for j in 0..MAX_HOPS { + if self.0[i][j] == INVALID_HOP { + break; + } + write!(f, " {}", self.0[i][j])?; + } + write!(f, ";")?; + } + } + write!(f, " }}")?; + Ok(()) + } +} + pub fn config_routing_table(default_n_links: usize) -> RoutingTable { let mut ret = RoutingTable::default_master(default_n_links); let ok = config::read("routing_table", |result| {