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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// A simple, local bus for attaching stuff together on the FPGA
use crate::core::prelude::*;

// Ultimately, a device will have multiple ports.  It will represent
// a "chunk" of bus addresses that can be communicated with via the
// controller.  The question is how do those addresses get routed
// and what do they mean.  Suppose we have 5 ports to describe a
// device.  The natural way to integrate those is to stack them
// behind a bridge:
//
//              +-------
//  --- bus --> | port 1
//              | port 2
//              |   |
//              | port 5
//              +-------
//
// This means each port simply needs a "chip-select" type line, and the address
// of the port is N + base, where base is the base address of the bridge.
//
// We can then stack bridges using a router.  The router will need to assign
// non-overlapping addresses to the bridges, and route the traffic based
// on those ranges.  For example, if there are 2 of these 5-port devices
// attached to bridges B1 and B2.  Then we need to do something like
//
//             +--------+              +-------
//             |        | ---- bus --> |  B1
//  -- bus --> |        |              +-------
//             |        | ---- bus --> |  B2
//             +--------+              +-------

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "SoCBusResponder"]
pub struct SoCBusController<const D: usize, const A: usize> {
    pub address: Signal<Out, Bits<A>>,
    pub address_strobe: Signal<Out, Bit>,
    pub from_controller: Signal<Out, Bits<D>>,
    pub to_controller: Signal<In, Bits<D>>,
    pub ready: Signal<In, Bit>,
    pub strobe: Signal<Out, Bit>,
    pub clock: Signal<Out, Clock>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "SoCBusController"]
pub struct SoCBusResponder<const D: usize, const A: usize> {
    pub address: Signal<In, Bits<A>>,
    pub address_strobe: Signal<In, Bit>,
    pub from_controller: Signal<In, Bits<D>>,
    pub to_controller: Signal<Out, Bits<D>>,
    pub ready: Signal<Out, Bit>,
    pub strobe: Signal<In, Bit>,
    pub clock: Signal<In, Clock>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "SoCPortResponder"]
pub struct SoCPortController<const D: usize> {
    pub select: Signal<Out, Bit>,
    pub from_controller: Signal<Out, Bits<D>>,
    pub to_controller: Signal<In, Bits<D>>,
    pub ready: Signal<In, Bit>,
    pub strobe: Signal<Out, Bit>,
    pub clock: Signal<Out, Clock>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "SoCPortController"]
pub struct SoCPortResponder<const D: usize> {
    pub select: Signal<In, Bit>,
    pub from_controller: Signal<In, Bits<D>>,
    pub to_controller: Signal<Out, Bits<D>>,
    pub ready: Signal<Out, Bit>,
    pub strobe: Signal<In, Bit>,
    pub clock: Signal<In, Clock>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "FIFOWriteResponder"]
pub struct FIFOWriteController<T: Synth> {
    pub data: Signal<Out, T>,
    pub write: Signal<Out, Bit>,
    pub full: Signal<In, Bit>,
    pub almost_full: Signal<In, Bit>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "FIFOWriteController"]
pub struct FIFOWriteResponder<T: Synth> {
    pub data: Signal<In, T>,
    pub write: Signal<In, Bit>,
    pub full: Signal<Out, Bit>,
    pub almost_full: Signal<Out, Bit>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "FIFOReadResponder"]
pub struct FIFOReadController<T: Synth> {
    pub data: Signal<In, T>,
    pub read: Signal<Out, Bit>,
    pub empty: Signal<In, Bit>,
    pub almost_empty: Signal<In, Bit>,
}

#[derive(Clone, Debug, Default, LogicInterface)]
#[join = "FIFOReadController"]
pub struct FIFOReadResponder<T: Synth> {
    pub data: Signal<Out, T>,
    pub read: Signal<In, Bit>,
    pub empty: Signal<Out, Bit>,
    pub almost_empty: Signal<Out, Bit>,
}