1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use super::max31856_sim::MAX31856Simulator;
use crate::core::prelude::*;
use crate::widgets::prelude::SPIConfig;
#[derive(LogicBlock)]
pub struct MuxedMAX31856Simulators {
pub mosi: Signal<In, Bit>,
pub mclk: Signal<In, Bit>,
pub msel: Signal<In, Bit>,
pub miso: Signal<Out, Bit>,
pub addr: Signal<In, Bits<3>>,
pub clock: Signal<In, Clock>,
adcs: [MAX31856Simulator; 8],
}
impl MuxedMAX31856Simulators {
pub fn new(config: SPIConfig) -> Self {
Self {
mosi: Default::default(),
mclk: Default::default(),
msel: Default::default(),
miso: Default::default(),
addr: Default::default(),
clock: Default::default(),
adcs: [
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
MAX31856Simulator::new(config),
],
}
}
}
impl Logic for MuxedMAX31856Simulators {
#[hdl_gen]
fn update(&mut self) {
self.miso.next = true;
for i in 0_usize..8_usize {
self.adcs[i].clock.next = self.clock.val();
self.adcs[i].mosi.next = self.mosi.val();
self.adcs[i].mclk.next = self.mclk.val();
self.adcs[i].msel.next = true;
if self.addr.val().index() == i {
self.adcs[i].msel.next = self.msel.val();
self.miso.next = self.adcs[i].miso.val();
}
}
}
}
#[test]
fn test_mux_is_synthesizable() {
use super::ad7193_sim::AD7193Config;
let mut uut = MuxedMAX31856Simulators::new(AD7193Config::hw().spi);
uut.mclk.connect();
uut.mosi.connect();
uut.msel.connect();
uut.addr.connect();
uut.clock.connect();
uut.connect_all();
yosys_validate("mux_31865", &generate_verilog(&uut)).unwrap();
}