diff --git a/examples/fulladder.rs b/examples/fulladder.rs index a572dbe..4bc5dab 100644 --- a/examples/fulladder.rs +++ b/examples/fulladder.rs @@ -91,8 +91,8 @@ fn main() { circuit.add_updater(&xor2); circuit.add_updater(&or); - const _0: Ieee1164 = Ieee1164::Strong(Ieee1164Value::Zero); - const _1: Ieee1164 = Ieee1164::Strong(Ieee1164Value::One); + const _0: Ieee1164 = Ieee1164::_0; // this helps to keep the + const _1: Ieee1164 = Ieee1164::_1; // matrix clean and short const VALUES: [[Ieee1164; 5]; 8] = [ [_0, _0, _0, _0, _0], diff --git a/examples/vcd_wire_dump.rs b/examples/vcd_wire_dump.rs index 3905212..16f7900 100644 --- a/examples/vcd_wire_dump.rs +++ b/examples/vcd_wire_dump.rs @@ -7,13 +7,13 @@ use logical::models::{ use logical::{Circuit, Ieee1164, Ieee1164Value, Signal}; fn main() { - let mut val = Ieee1164::Strong(Ieee1164Value::One); + let mut val = Ieee1164::_1; let xor = XorGate::default(); let mux = Mux::default(); let mut input1 = Switch::new_with_value(val); - let input2 = Switch::new_with_value(Ieee1164::Strong(Ieee1164Value::One)); - let mut mux_switch = Switch::new_with_value(Ieee1164::Strong(Ieee1164Value::Zero)); + let input2 = Switch::new_with_value(Ieee1164::_1); + let mut mux_switch = Switch::new_with_value(Ieee1164::_0); let output = Led::default(); let mut sig_input_signal = Signal::new(); @@ -49,7 +49,7 @@ fn main() { circuit.tick(); circuit.tick(); circuit.tick(); - mux_switch.set_value(Ieee1164::Strong(Ieee1164Value::One)); + mux_switch.set_value(Ieee1164::_1); circuit.tick(); let mut dumper = Vcd::new("VCD Example"); diff --git a/src/logicbit/ieee1164.rs b/src/logicbit/ieee1164.rs index f0356ee..964f272 100644 --- a/src/logicbit/ieee1164.rs +++ b/src/logicbit/ieee1164.rs @@ -72,15 +72,15 @@ impl TryFrom for Ieee1164 { fn try_from(c: char) -> Result { Ok(match c.to_ascii_lowercase() { - 'u' => Ieee1164::Uninitialized, - 'x' => Ieee1164::Strong(Ieee1164Value::Unknown), - '0' => Ieee1164::Strong(Ieee1164Value::Zero), - '1' => Ieee1164::Strong(Ieee1164Value::One), - 'z' => Ieee1164::HighImpedance, - 'w' => Ieee1164::Weak(Ieee1164Value::Unknown), - 'l' => Ieee1164::Weak(Ieee1164Value::Zero), - 'h' => Ieee1164::Weak(Ieee1164Value::One), - '*' | '-' | 'd' => Ieee1164::DontCare, + 'u' => Ieee1164::_U, + 'x' => Ieee1164::_X, + '0' => Ieee1164::_0, + '1' => Ieee1164::_1, + 'z' => Ieee1164::_Z, + 'w' => Ieee1164::_W, + 'l' => Ieee1164::_L, + 'h' => Ieee1164::_H, + '*' | '-' | 'd' => Ieee1164::_D, _ => return Err(()), }) } @@ -89,15 +89,15 @@ impl TryFrom for Ieee1164 { impl From for char { fn from(i: Ieee1164) -> Self { match i { - Ieee1164::Uninitialized => 'U', - Ieee1164::Strong(Ieee1164Value::Unknown) => 'X', - Ieee1164::Strong(Ieee1164Value::Zero) => '0', - Ieee1164::Strong(Ieee1164Value::One) => '1', - Ieee1164::HighImpedance => 'Z', - Ieee1164::Weak(Ieee1164Value::Unknown) => 'W', - Ieee1164::Weak(Ieee1164Value::Zero) => 'L', - Ieee1164::Weak(Ieee1164Value::One) => 'H', - Ieee1164::DontCare => '-', + Ieee1164::_U => 'U', + Ieee1164::_X => 'X', + Ieee1164::_0 => '0', + Ieee1164::_1 => '1', + Ieee1164::_Z => 'Z', + Ieee1164::_W => 'W', + Ieee1164::_L => 'L', + Ieee1164::_H => 'H', + Ieee1164::_D => '-', } } } @@ -239,62 +239,62 @@ impl Ieee1164 { !(self.is_1H() || self.is_0L()) } - /// Checks whether this is either [`Ieee1164::_0`], [`Ieee1164::_1`] + /// Checks whether this is either [`Ieee1164::_0`] or [`Ieee1164::_1`] pub fn is_01(self) -> bool { self.is_0() || self.is_1() } - /// Checks whether this is either [`Ieee1164::_1`], [`Ieee1164::_H`] + /// Checks whether this is either [`Ieee1164::_1`] or [`Ieee1164::_H`] pub fn is_1H(self) -> bool { self.is_1() || self.is_H() } - /// Checks whether this is either [`Ieee1164::_0`], [`Ieee1164::_L`] + /// Checks whether this is either [`Ieee1164::_0`] or [`Ieee1164::_L`] pub fn is_0L(self) -> bool { self.is_0() || self.is_L() } - /// Checks whether this is either [`Ieee1164::_U`] + /// Checks whether this is [`Ieee1164::_U`] pub fn is_U(self) -> bool { self == _U } - /// Checks whether this is either [`Ieee1164::_X`] + /// Checks whether this is [`Ieee1164::_X`] pub fn is_X(self) -> bool { self == _X } - /// Checks whether this is either [`Ieee1164::_0`] + /// Checks whether this is [`Ieee1164::_0`] pub fn is_0(self) -> bool { self == _0 } - /// Checks whether this is either [`Ieee1164::_1`] + /// Checks whether this is [`Ieee1164::_1`] pub fn is_1(self) -> bool { self == _1 } - /// Checks whether this is either [`Ieee1164::_Z`] + /// Checks whether this is [`Ieee1164::_Z`] pub fn is_Z(self) -> bool { self == _Z } - /// Checks whether this is either [`Ieee1164::_W`] + /// Checks whether this is [`Ieee1164::_W`] pub fn is_W(self) -> bool { self == _W } - /// Checks whether this is either [`Ieee1164::_L`] + /// Checks whether this is [`Ieee1164::_L`] pub fn is_L(self) -> bool { self == _L } - /// Checks whether this is either [`Ieee1164::_H`] + /// Checks whether this is [`Ieee1164::_H`] pub fn is_H(self) -> bool { self == _H } - /// Checks whether this is either [`Ieee1164::_D`] + /// Checks whether this is [`Ieee1164::_D`] pub fn is_D(self) -> bool { self == _D } @@ -324,7 +324,8 @@ mod tests { #[test] fn not() { - //TODO + let a = Ieee1164::_1; + assert_eq!(Ieee1164::_0, !a); } #[test] diff --git a/src/logicbit/logicvector/masks.rs b/src/logicbit/logicvector/masks.rs index 4510053..4e718e9 100644 --- a/src/logicbit/logicvector/masks.rs +++ b/src/logicbit/logicvector/masks.rs @@ -78,15 +78,15 @@ impl Index for Masks { fn index(&self, index: Ieee1164) -> &u128 { match index { - Ieee1164::Uninitialized => &self._U, - Ieee1164::Strong(Ieee1164Value::Unknown) => &self._X, - Ieee1164::Strong(Ieee1164Value::One) => &self._1, - Ieee1164::Strong(Ieee1164Value::Zero) => &self._0, - Ieee1164::Weak(Ieee1164Value::Unknown) => &self._W, - Ieee1164::Weak(Ieee1164Value::One) => &self._H, - Ieee1164::Weak(Ieee1164Value::Zero) => &self._L, - Ieee1164::HighImpedance => &self._Z, - Ieee1164::DontCare => &self._D, + Ieee1164::_U => &self._U, + Ieee1164::_X => &self._X, + Ieee1164::_1 => &self._1, + Ieee1164::_0 => &self._0, + Ieee1164::_W => &self._W, + Ieee1164::_H => &self._H, + Ieee1164::_L => &self._L, + Ieee1164::_Z => &self._Z, + Ieee1164::_D => &self._D, } } } @@ -94,15 +94,15 @@ impl Index for Masks { impl IndexMut for Masks { fn index_mut(&mut self, index: Ieee1164) -> &mut u128 { match index { - Ieee1164::Uninitialized => &mut self._U, - Ieee1164::Strong(Ieee1164Value::Unknown) => &mut self._X, - Ieee1164::Strong(Ieee1164Value::One) => &mut self._1, - Ieee1164::Strong(Ieee1164Value::Zero) => &mut self._0, - Ieee1164::Weak(Ieee1164Value::Unknown) => &mut self._W, - Ieee1164::Weak(Ieee1164Value::One) => &mut self._H, - Ieee1164::Weak(Ieee1164Value::Zero) => &mut self._L, - Ieee1164::HighImpedance => &mut self._Z, - Ieee1164::DontCare => &mut self._D, + Ieee1164::_U => &mut self._U, + Ieee1164::_X => &mut self._X, + Ieee1164::_1 => &mut self._1, + Ieee1164::_0 => &mut self._0, + Ieee1164::_W => &mut self._W, + Ieee1164::_H => &mut self._H, + Ieee1164::_L => &mut self._L, + Ieee1164::_Z => &mut self._Z, + Ieee1164::_D => &mut self._D, } } } diff --git a/src/models/gates/mod.rs b/src/models/gates/mod.rs index 1340ffa..e550561 100644 --- a/src/models/gates/mod.rs +++ b/src/models/gates/mod.rs @@ -110,32 +110,20 @@ create_simple_1i1o_gate!(Inverter, inv); fn weak_buf(a: Ieee1164) -> Ieee1164 { match a { - Ieee1164::Uninitialized - | Ieee1164::Strong(Ieee1164Value::Unknown) - | Ieee1164::Weak(Ieee1164Value::Unknown) - | Ieee1164::DontCare => Ieee1164::Weak(Ieee1164Value::Unknown), - Ieee1164::Strong(Ieee1164Value::One) | Ieee1164::Weak(Ieee1164Value::One) => Ieee1164::Weak(Ieee1164Value::One), - Ieee1164::Strong(Ieee1164Value::Zero) | Ieee1164::Weak(Ieee1164Value::Zero) => { - Ieee1164::Weak(Ieee1164Value::Zero) - } - Ieee1164::HighImpedance => Ieee1164::HighImpedance, + Ieee1164::_U | Ieee1164::_X | Ieee1164::_W | Ieee1164::_D => Ieee1164::_W, + Ieee1164::_1 | Ieee1164::_H => Ieee1164::_H, + Ieee1164::_0 | Ieee1164::_L => Ieee1164::_L, + Ieee1164::_Z => Ieee1164::_Z, } } create_simple_1i1o_gate!(WeakBuffer, weak_buf); fn weak_inv(a: Ieee1164) -> Ieee1164 { match a { - Ieee1164::Uninitialized - | Ieee1164::Strong(Ieee1164Value::Unknown) - | Ieee1164::Weak(Ieee1164Value::Unknown) - | Ieee1164::DontCare => Ieee1164::Weak(Ieee1164Value::Unknown), - Ieee1164::Strong(Ieee1164Value::One) | Ieee1164::Weak(Ieee1164Value::One) => { - Ieee1164::Weak(Ieee1164Value::Zero) - } - Ieee1164::Strong(Ieee1164Value::Zero) | Ieee1164::Weak(Ieee1164Value::Zero) => { - Ieee1164::Weak(Ieee1164Value::One) - } - Ieee1164::HighImpedance => Ieee1164::HighImpedance, + Ieee1164::_U | Ieee1164::_X | Ieee1164::_W | Ieee1164::_D => Ieee1164::_W, + Ieee1164::_1 | Ieee1164::_H => Ieee1164::_L, + Ieee1164::_0 | Ieee1164::_L => Ieee1164::_H, + Ieee1164::_Z => Ieee1164::_Z, } } create_simple_1i1o_gate!(WeakInverter, weak_inv); diff --git a/src/models/gates/mux.rs b/src/models/gates/mux.rs index 0f698f0..fdd3a91 100644 --- a/src/models/gates/mux.rs +++ b/src/models/gates/mux.rs @@ -20,7 +20,7 @@ impl Updateable for Mux { } else if self.s.value().is_0L() { self.a.value() } else { - Ieee1164::Strong(Ieee1164Value::Unknown) + Ieee1164::_X }); } } diff --git a/src/models/gates/tri.rs b/src/models/gates/tri.rs index 0d67a7e..f6857b9 100644 --- a/src/models/gates/tri.rs +++ b/src/models/gates/tri.rs @@ -17,9 +17,9 @@ impl Updateable for TriBuffer { self.z.replace(if self.s.value().is_1H() { self.a.value() } else if self.s.value().is_0L() { - Ieee1164::HighImpedance + Ieee1164::_Z } else { - Ieee1164::Strong(Ieee1164Value::Unknown) + Ieee1164::_X }); } } diff --git a/src/models/inputs/switch.rs b/src/models/inputs/switch.rs deleted file mode 100644 index a04374f..0000000 --- a/src/models/inputs/switch.rs +++ /dev/null @@ -1,21 +0,0 @@ -use crate::port::Output; -use crate::Port; - -#[derive(Debug, Default)] -pub struct Switch { - pub output: Port, - _private: (), -} - -impl Switch { - pub fn new_with_value(value: T) -> Self { - Self { - output: Port::new(value), - _private: (), - } - } - - pub fn set_value(&mut self, value: T) { - self.output.replace(value); - } -} diff --git a/src/models/outputs/led.rs b/src/models/outputs/led.rs deleted file mode 100644 index b002f88..0000000 --- a/src/models/outputs/led.rs +++ /dev/null @@ -1,14 +0,0 @@ -use crate::port::Input; -use crate::Port; - -#[derive(Debug, Default)] -pub struct Led { - pub input: Port, - _private: (), -} - -impl Led { - pub fn value(&self) -> T { - self.input.value() - } -} diff --git a/src/models/rtlib/arithmic/add.rs b/src/models/rtlib/arithmic/add.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/models/rtlib/arithmic/mod.rs b/src/models/rtlib/arithmic/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/signal.rs b/src/signal.rs index e8e59d6..d7319cf 100644 --- a/src/signal.rs +++ b/src/signal.rs @@ -203,7 +203,7 @@ mod tests { assert_eq!(Ieee1164::Uninitialized, i.value()); } - let val = Ieee1164::Strong(Ieee1164Value::One); + let val = Ieee1164::_1; p.replace(val); s.update(); assert_eq!(val, i.value()); @@ -216,8 +216,8 @@ mod tests { #[test] fn signal_after_disconnect() { - let val_a = Ieee1164::Strong(Ieee1164Value::One); - let val_b = Ieee1164::Strong(Ieee1164Value::Zero); + let val_a = Ieee1164::_1; + let val_b = Ieee1164::_0; let mut p = Port::<_, InOut>::new(val_a); let o = Port::<_, Input>::default(); let mut s = Signal::new(); @@ -234,11 +234,11 @@ mod tests { #[test] fn signal_multiple_ports() { - let val_a = Ieee1164::Weak(Ieee1164Value::One); - let val_b = Ieee1164::Strong(Ieee1164Value::Zero); + let val_a = Ieee1164::_H; + let val_b = Ieee1164::_0; let p1 = Port::<_, InOut>::new(val_a); let p2 = Port::<_, InOut>::new(val_b); - let o = Port::<_, Input>::new(Ieee1164::DontCare); + let o = Port::<_, Input>::new(Ieee1164::_D); let mut s = Signal::new(); s.connect(&p1).unwrap(); @@ -252,8 +252,8 @@ mod tests { fn signal_port_out_of_scope() { let mut s = Signal::new(); - let val_a = Ieee1164::Strong(Ieee1164Value::One); - let val_b = Ieee1164::Strong(Ieee1164Value::Zero); + let val_a = Ieee1164::_1; + let val_b = Ieee1164::_0; let p1 = Port::<_, Output>::new(val_a); let o = Port::<_, Input>::default(); @@ -275,7 +275,7 @@ mod tests { fn disallow_multiple_connects() { let mut s = Signal::new(); - let val = Ieee1164::Strong(Ieee1164Value::One); + let val = Ieee1164::_1; let p = Port::<_, InOut>::new(val); s.connect(&p).unwrap(); s.connect(&p).unwrap();