-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathfabric_config_loader.dart
More file actions
142 lines (130 loc) · 4.39 KB
/
fabric_config_loader.dart
File metadata and controls
142 lines (130 loc) · 4.39 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import 'package:rohd/rohd.dart';
import 'package:rohd_hcl/rohd_hcl.dart';
/// Streams configuration bits into the FPGA fabric config chain.
class FabricConfigLoader extends Module {
Logic get clk => input('clk');
Logic get start => input('start');
Logic get done => output('done');
Logic get cfgIn => output('cfgIn');
Logic get cfgLoad => output('cfgLoad');
final int totalBits;
FabricConfigLoader(
Logic clk,
Logic start,
this.totalBits,
DataPortInterface readPort,
) : super(name: 'fabric_config_loader') {
clk = addInput('clk', clk);
start = addInput('start', start);
addOutput('done');
addOutput('cfgIn');
addOutput('cfgLoad');
readPort = readPort.clone()
..connectIO(
this,
readPort,
inputTags: {DataPortGroup.data},
outputTags: {DataPortGroup.control},
uniquify: (orig) => 'rd_$orig',
);
final wordWidth = readPort.data.width;
final wordsNeeded = (totalBits + wordWidth - 1) ~/ wordWidth;
final active = Logic(name: 'active');
final wordAddr = Logic(width: readPort.addr.width, name: 'wordAddr');
final wordBuf = Logic(width: wordWidth, name: 'wordBuf');
final bitIdx = Logic(width: wordWidth.bitLength, name: 'bitIdx');
final totalShifted = Logic(
width: totalBits.bitLength,
name: 'totalShifted',
);
final shifting = Logic(name: 'shifting');
final wordReady = Logic(name: 'wordReady');
final allDone = Logic(name: 'allDone');
Sequential(
clk,
[
If(
start,
then: [
active < Const(1),
wordAddr < Const(0, width: wordAddr.width),
bitIdx < Const(0, width: bitIdx.width),
totalShifted < Const(0, width: totalShifted.width),
shifting < Const(0),
wordReady < Const(0),
allDone < Const(0),
],
orElse: [
If(
active & ~allDone,
then: [
If(
~shifting & ~wordReady,
then: [
wordBuf < readPort.data,
wordReady < Const(1),
bitIdx < Const(0, width: bitIdx.width),
],
orElse: [
If(
wordReady & ~shifting,
then: [shifting < Const(1)],
orElse: [
If(
shifting,
then: [
bitIdx < bitIdx + 1,
totalShifted < totalShifted + 1,
If(
totalShifted.eq(
Const(totalBits - 1, width: totalShifted.width),
),
then: [
// All bits shifted
allDone < Const(1),
shifting < Const(0),
],
orElse: [
If(
bitIdx.eq(
Const(wordWidth - 1, width: bitIdx.width),
),
then: [
// Word exhausted, fetch next
shifting < Const(0),
wordReady < Const(0),
wordAddr < wordAddr + 1,
],
),
],
),
],
),
],
),
],
),
],
),
],
),
],
reset: start,
resetValues: {
active: Const(0),
shifting: Const(0),
wordReady: Const(0),
allDone: Const(0),
wordAddr: Const(0, width: wordAddr.width),
wordBuf: Const(0, width: wordWidth),
bitIdx: Const(0, width: bitIdx.width),
totalShifted: Const(0, width: totalShifted.width),
},
);
readPort.en <= active & ~allDone & ~shifting & ~wordReady;
readPort.addr <= wordAddr;
cfgIn <= mux(shifting, wordBuf[bitIdx], Const(0));
cfgLoad <= allDone;
done <= allDone;
}
}