HDLRuby 2.3.8 → 2.4.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 164191b6cbfda40e60bc6b253c95a0ff511164007c83adf53c7f86383b404464
4
- data.tar.gz: 5344dd9f624089cab1488d9e10b67e542cb83639db81e397c0d2241c67a43527
3
+ metadata.gz: d90d9d7ef8c4535bbce1db315a06ec6e85c8efe37ddb07828605f72049f5daf2
4
+ data.tar.gz: d3f6d2fb5cccb840c8385ab8af724f6dcfef2efed5d9d263ef50be104f2aba3a
5
5
  SHA512:
6
- metadata.gz: 5e9b00b3fad458789078bcaca6d8d45e7ac5877ff14a3971ce2ddac186ed15a1ad2aa440d3c5619c66f324e9f6dbeda5c8bcf2aa5de3389aa12d631abbd780a4
7
- data.tar.gz: '08dc450e1e3807d85f8ffb22888c037b081bed44dab318fac5fb33611f706c58191a2b06379b0798b61bbf3578d0e058b144ee8995e4212250826366bd306e9e'
6
+ metadata.gz: 548de87c875473eaf522c8db89d7842cd79f2638be583e85a0b9e143bb21ac89a40e447fb2d8d09f55d67543954d59e7880eceb4e515b96de6f959d3cf48edd6
7
+ data.tar.gz: d8fe03171ac0bada3bc7b30625cd8c874d1d98b72757ad180fc4ec52f9803f243058f423fa9047924d33d2e4350f7f3e9acee0dda3d654175e026ed94edee32e
data/README.md CHANGED
@@ -50,6 +50,7 @@ Where:
50
50
  | `-s, --syntax` | Output the Ruby syntax tree |
51
51
  | `-C, --clang` | Output the C code of the simulator |
52
52
  | `-S, --sim` | Output the executable simulator and execute it |
53
+ | `--vcd` | Make the simulator generate a vcd file |
53
54
  | `-d, --directory` | Specify the base directory for loading the HDLRuby files |
54
55
  | `-D, --debug` | Set the HDLRuby debug mode |
55
56
  | `-t, --top system`| Specify the top system describing the circuit to compile |
@@ -0,0 +1,14 @@
1
+
2
+ # A benchmark for the bit string generation in case of signed values.
3
+ system :bstr_bench do
4
+ signed[7..0].inner :val
5
+
6
+ timed do
7
+ val <= 0
8
+ !10.ns
9
+ val <= 26
10
+ !10.ns
11
+ val <= -25
12
+ !10.ns
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+
2
+ # A benchmark for testing the arithmetic with signed values.
3
+ system :neg_arith_bench do
4
+ signed[11..0].inner :x,:y,:z
5
+
6
+ timed do
7
+ x <= 10
8
+ y <= 10
9
+ z <= 0
10
+ !10.ns
11
+ z <= 10 * 10
12
+ !10.ns
13
+ z <= x * y
14
+ !10.ns
15
+ x <= 10
16
+ y <= -10
17
+ !10.ns
18
+ z <= 10 * (-10)
19
+ !10.ns
20
+ z <= x * y
21
+ !10.ns
22
+ x <= -10
23
+ y <= 10
24
+ !10.ns
25
+ z <= (-10) * 10
26
+ !10.ns
27
+ z <= x * y
28
+ !10.ns
29
+ x <= -10
30
+ y <= -10
31
+ !10.ns
32
+ z <= (-10) * (-10)
33
+ !10.ns
34
+ z <= x * y
35
+ !10.ns
36
+ x <= _000000011010
37
+ y <= _000011111010
38
+ z <= 0
39
+ !10.ns
40
+ z <= x * y
41
+ !10.ns
42
+ x <= _000000011010
43
+ y <= _111111111010
44
+ z <= 0
45
+ !10.ns
46
+ z <= x * y
47
+ !10.ns
48
+ end
49
+ end
@@ -31,5 +31,23 @@ system :fix_test do
31
31
  d <= 0
32
32
  !10.ns
33
33
  d <= d + c
34
+ !10.ns
35
+ a <= -0.375.to_fix(4)
36
+ b <= 1.625.to_fix(4)
37
+ !10.ns
38
+ c <= a * b
39
+ !10.ns
40
+ # a <= _00010000
41
+ # b <= _00010101
42
+ a <= _0000111x
43
+ b <= _1110011x
44
+ !10.ns
45
+ # a <= a & _11111110
46
+ # b <= b | _00000001
47
+ a <= a | _00000001
48
+ b <= b | _00000001
49
+ !10.ns
50
+ c <= a * b
51
+ !10.ns
34
52
  end
35
53
  end
@@ -0,0 +1,53 @@
1
+ require 'std/memory.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+
6
+
7
+
8
+
9
+ # A system testing the rom channel.
10
+ system :rorm_test do
11
+ inner :clk,:rst
12
+ [8].inner :value
13
+ inner :addr
14
+
15
+ # Declares a 8-bit-data and 1 element rom address synchronous memory
16
+ # on negative edge of clk.
17
+ # mem_rom([8],2,clk,rst,[_00000110,_00000111], rinc: :rst).(:romI)
18
+ mem_rom([8],1,clk,rst,[_00000110], rinc: :rst).(:romI)
19
+ rd = romI.branch(:rinc)
20
+
21
+ par(clk.posedge) do
22
+ hif(rst) { addr <= 0 }
23
+ helse do
24
+ rd.read(value)
25
+ end
26
+ end
27
+
28
+ timed do
29
+ clk <= 0
30
+ rst <= 0
31
+ !10.ns
32
+ clk <= 1
33
+ !10.ns
34
+ clk <= 0
35
+ rst <= 1
36
+ !10.ns
37
+ clk <= 1
38
+ !10.ns
39
+ clk <= 0
40
+ !10.ns
41
+ clk <= 1
42
+ !10.ns
43
+ clk <= 0
44
+ rst <= 0
45
+ !10.ns
46
+ 10.times do
47
+ clk <= 1
48
+ !10.ns
49
+ clk <= 0
50
+ !10.ns
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,300 @@
1
+ require "std/channel.rb"
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Channel describing a buffered queue storing data of +typ+ type of +depth+,
6
+ # synchronized through clk and reset on +rst+.
7
+ channel(:queue) do |typ,depth,clk,rst|
8
+ # The inner buffer of the queue.
9
+ typ[-depth].inner :buffer
10
+ # The read and write pointers.
11
+ [depth.width].inner :rptr, :wptr
12
+ # The read and write command signals.
13
+ inner :rcmd, :wcmd
14
+ # The read and write ack signals.
15
+ inner :rack, :wack
16
+ # The ack check deactivator (for synchron accesses).
17
+ inner :hrack, :hwack
18
+ # The read/write data registers.
19
+ typ.inner :rdata, :wdata
20
+
21
+ # The process handling the decoupled access to the buffer.
22
+ par(clk.posedge) do
23
+ # rack <= 0
24
+ # wack <= 0
25
+ hif (~rcmd) { rack <= 0 }
26
+ hif (~wcmd) { wack <= 0 }
27
+ hif(rst) { rptr <= 0; wptr <= 0 }
28
+ hif(rcmd & (hrack|~rack) & (rptr != wptr)) do
29
+ rptr <= (rptr + 1) % depth
30
+ rack <= 1
31
+ end
32
+ hif(wcmd & (hwack|~wack) & (((wptr+1) % depth) != rptr)) do
33
+ buffer[wptr] <= wdata
34
+ # buffer[1] <= wdata
35
+ wptr <= (wptr + 1) % depth
36
+ wack <= 1
37
+ end
38
+ end
39
+ par { rdata <= buffer[rptr] }
40
+
41
+ reader_output :rcmd, :rptr, :hrack
42
+ reader_input :rdata, :rack
43
+
44
+ # The read primitive.
45
+ reader do |blk,target|
46
+ if (cur_behavior.on_event?(clk.posedge,clk.negedge)) then
47
+ # Same clk event, synchrone case: perform a direct access.
48
+ # Now perform the access.
49
+ top_block.unshift do
50
+ rcmd <= 0
51
+ hrack <= 1
52
+ end
53
+ seq do
54
+ rptr <= (rptr + 1) % depth
55
+ target <= rdata
56
+ blk.call if blk
57
+ end
58
+ else
59
+ # Different clk event, perform a decoupled access.
60
+ top_block.unshift do
61
+ rcmd <= 0
62
+ hrack <= 0
63
+ end
64
+ seq do
65
+ hif(rack) do
66
+ blk.call if blk
67
+ end
68
+ helse do
69
+ rcmd <= 1
70
+ target <= rdata
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ writer_output :wcmd, :wdata, :hwack
77
+ writer_input :wack
78
+
79
+ # The write primitive.
80
+ writer do |blk,target|
81
+ if (cur_behavior.on_event?(clk.negedge,clk.posedge)) then
82
+ # Same clk event, synchrone case: perform a direct access.
83
+ top_block.unshift do
84
+ wcmd <= 0
85
+ hwack <= 1
86
+ end
87
+ wcmd <= 1
88
+ wdata <= target
89
+ blk.call if blk
90
+ else
91
+ # Different clk event, asynchrone case: perform a decoupled access.
92
+ top_block.unshift do
93
+ wcmd <= 0
94
+ hwack <= 0
95
+ end
96
+ seq do
97
+ hif(wack) do
98
+ blk.call if blk
99
+ end
100
+ helse { wcmd <= 1 }
101
+ wdata <= target
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ # Channel describing a register of +typ+ type.
109
+ channel(:register) do |typ|
110
+ # The register.
111
+ typ.inner :buffer
112
+
113
+ reader_input :buffer
114
+
115
+ # The read primitive.
116
+ reader do |blk,target|
117
+ target <= buffer
118
+ blk.call if blk
119
+ end
120
+
121
+ writer_output :buffer
122
+
123
+ # The read primitive.
124
+ writer do |blk,target|
125
+ buffer <= target
126
+ blk.call if blk
127
+ end
128
+ end
129
+
130
+
131
+
132
+ # Channel describing a handshake for transmitting data of +typ+ type, reset
133
+ # by +rst+
134
+ channel(:handshake) do |typ|
135
+ # The data signal.
136
+ typ.inner :data
137
+ # The request and acknowledge.
138
+ typ.inner :req, :ack
139
+
140
+ reader_input :ack, :data
141
+ reader_output :req
142
+
143
+ # The read primitive.
144
+ reader do |blk,target|
145
+ top_block.unshift do
146
+ req <= 0
147
+ end
148
+ hif(ack == 0) do
149
+ req <= 1
150
+ end
151
+ helsif(req) do
152
+ target <= data
153
+ req <= 0
154
+ blk.call if blk
155
+ end
156
+ end
157
+
158
+ writer_input :req
159
+ writer_output :ack, :data
160
+
161
+ # The read primitive.
162
+ writer do |blk,target|
163
+ top_block.unshift do
164
+ ack <= 0
165
+ end
166
+ hif(req) do
167
+ hif(~ack) do
168
+ data <= target
169
+ blk.call if blk
170
+ end
171
+ ack <= 1
172
+ end
173
+ end
174
+ end
175
+
176
+
177
+ # $mode = :sync
178
+ # $mode = :nsync
179
+ # $mode = :async
180
+ # $mode = :proco # Producter / Consummer
181
+ # $channel = :register
182
+ # $channel = :handshake
183
+ # $channel = :queue
184
+
185
+ # The configuration scenarii
186
+ $scenarii = [ [:sync, :register], [:sync, :handshake], [:sync, :queue],
187
+ [:nsync, :register], [:nsync, :handshake], [:nsync, :queue],
188
+ [:async, :register], [:async, :handshake], [:async, :queue],
189
+ [:proco, :register], [:proco, :handshake], [:proco, :queue] ]
190
+
191
+ # The configuration
192
+ $mode, $channel = $scenarii[11]
193
+
194
+ # Testing the queue channel.
195
+ system :test_queue do
196
+ inner :clk, :rst, :clk2, :clk3
197
+ [8].inner :idata, :odata
198
+ [4].inner :counter
199
+
200
+ if $channel == :register then
201
+ register(bit[8]).(:my_ch)
202
+ elsif $channel == :handshake then
203
+ handshake(bit[8],rst).(:my_ch)
204
+ elsif $channel == :queue then
205
+ queue(bit[8],5,clk,rst).(:my_ch)
206
+ end
207
+
208
+ ev = $mode == :sync ? clk.posedge :
209
+ $mode == :nsync ? clk.negedge : clk2.posedge
210
+
211
+ if $mode != :proco then
212
+ # Sync/Neg sync and async tests mode
213
+ par(ev) do
214
+ hif(rst) do
215
+ counter <= 0
216
+ idata <= 0
217
+ odata <= 0
218
+ end
219
+ helse do
220
+ hif (counter < 4) do
221
+ my_ch.write(idata) do
222
+ idata <= idata + 1
223
+ counter <= counter + 1
224
+ end
225
+ end
226
+ helsif ((counter > 10) & (counter < 15)) do
227
+ my_ch.read(odata) do
228
+ idata <= idata - odata
229
+ counter <= counter + 1
230
+ end
231
+ end
232
+ helse do
233
+ counter <= counter + 1
234
+ end
235
+ end
236
+ end
237
+ else
238
+ # Producter/consumer mode
239
+ # Producer
240
+ par(clk2.posedge) do
241
+ hif(rst) do
242
+ idata <= 0
243
+ end
244
+ helse do
245
+ my_ch.write(idata) do
246
+ idata <= idata + 1
247
+ end
248
+ end
249
+ end
250
+ # Consumer
251
+ par(clk3.posedge) do
252
+ hif(rst) do
253
+ counter <= 0
254
+ end
255
+ helse do
256
+ my_ch.read(odata) do
257
+ counter <= counter + 1
258
+ end
259
+ end
260
+ end
261
+ end
262
+
263
+ timed do
264
+ clk <= 0
265
+ clk2 <= 0
266
+ clk3 <= 0
267
+ rst <= 0
268
+ !10.ns
269
+ clk <= 1
270
+ !10.ns
271
+ clk <= 0
272
+ rst <= 1
273
+ !3.ns
274
+ clk2 <= 1
275
+ !3.ns
276
+ clk3 <= 0
277
+ !4.ns
278
+ clk <= 1
279
+ !10.ns
280
+ clk <= 0
281
+ !3.ns
282
+ clk2 <= 0
283
+ !3.ns
284
+ clk3 <= 1
285
+ !2.ns
286
+ rst <= 0
287
+ !2.ns
288
+ 64.times do
289
+ clk <= 1
290
+ !10.ns
291
+ clk <= 0
292
+ !3.ns
293
+ clk2 <= ~clk2
294
+ !3.ns
295
+ hif (clk2 == 0) { clk3 <= ~ clk3 }
296
+ !4.ns
297
+ end
298
+ end
299
+ end
300
+