HDLRuby 2.11.12 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/README.html +3274 -0
  3. data/README.md +660 -128
  4. data/ext/hruby_sim/hruby_sim_calc.c +2 -0
  5. data/lib/HDLRuby/backend/hruby_allocator.rb +2 -2
  6. data/lib/HDLRuby/backend/hruby_c_allocator.rb +7 -7
  7. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +2 -1
  8. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  9. data/lib/HDLRuby/hdr_samples/with_bram.rb +3 -3
  10. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +105 -0
  11. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +69 -0
  12. data/lib/HDLRuby/hdr_samples/with_ref_expr.rb +30 -0
  13. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +185 -0
  14. data/lib/HDLRuby/hdr_samples/with_sequencer_deep.rb +91 -0
  15. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +439 -0
  16. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +89 -0
  17. data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +63 -0
  18. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +120 -0
  19. data/lib/HDLRuby/hdrcc.rb +16 -3
  20. data/lib/HDLRuby/hdrlib.rb +1 -1
  21. data/lib/HDLRuby/hruby_db.rb +2 -2
  22. data/lib/HDLRuby/hruby_high.rb +61 -25
  23. data/lib/HDLRuby/hruby_high_fullname.rb +3 -1
  24. data/lib/HDLRuby/hruby_low.rb +2 -2
  25. data/lib/HDLRuby/hruby_low2c.rb +58 -43
  26. data/lib/HDLRuby/hruby_low2hdr.rb +66 -40
  27. data/lib/HDLRuby/hruby_low2high.rb +86 -44
  28. data/lib/HDLRuby/hruby_low2seq.rb +26 -18
  29. data/lib/HDLRuby/hruby_low2sym.rb +14 -13
  30. data/lib/HDLRuby/hruby_low2vhd.rb +78 -43
  31. data/lib/HDLRuby/hruby_low_bool2select.rb +61 -46
  32. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +56 -44
  33. data/lib/HDLRuby/hruby_low_cleanup.rb +18 -16
  34. data/lib/HDLRuby/hruby_low_fix_types.rb +64 -32
  35. data/lib/HDLRuby/hruby_low_mutable.rb +53 -118
  36. data/lib/HDLRuby/hruby_low_resolve.rb +26 -31
  37. data/lib/HDLRuby/hruby_low_with_bool.rb +33 -16
  38. data/lib/HDLRuby/hruby_low_with_port.rb +3 -3
  39. data/lib/HDLRuby/hruby_low_with_var.rb +23 -9
  40. data/lib/HDLRuby/hruby_low_without_concat.rb +19 -13
  41. data/lib/HDLRuby/hruby_low_without_namespace.rb +47 -32
  42. data/lib/HDLRuby/hruby_low_without_parinseq.rb +18 -12
  43. data/lib/HDLRuby/hruby_low_without_select.rb +36 -23
  44. data/lib/HDLRuby/hruby_low_without_subsignals.rb +79 -39
  45. data/lib/HDLRuby/hruby_rcsim.rb +79 -64
  46. data/lib/HDLRuby/hruby_rsim.rb +64 -15
  47. data/lib/HDLRuby/hruby_rsim_mute.rb +2 -3
  48. data/lib/HDLRuby/hruby_rsim_vcd.rb +28 -25
  49. data/lib/HDLRuby/hruby_types.rb +5 -5
  50. data/lib/HDLRuby/hruby_values.rb +19 -8
  51. data/lib/HDLRuby/hruby_verilog.rb +191 -65
  52. data/lib/HDLRuby/hruby_verilog_name.rb +49 -42
  53. data/lib/HDLRuby/soft/stacks.rb +219 -0
  54. data/lib/HDLRuby/std/bram.rb +9 -5
  55. data/lib/HDLRuby/std/clocks.rb +1 -1
  56. data/lib/HDLRuby/std/fsm.rb +39 -10
  57. data/lib/HDLRuby/std/sequencer.rb +2085 -0
  58. data/lib/HDLRuby/std/sequencer_func.rb +533 -0
  59. data/lib/HDLRuby/std/sequencer_sync.rb +400 -0
  60. data/lib/HDLRuby/std/std.rb +13 -0
  61. data/lib/HDLRuby/version.rb +1 -1
  62. data/tuto/adder_sat_flags_vcd.png +0 -0
  63. data/tuto/addsub_vcd.png +0 -0
  64. data/tuto/alu_vcd.png +0 -0
  65. data/tuto/bit_pong_vcd.png +0 -0
  66. data/tuto/checksum_vcd.png +0 -0
  67. data/tuto/circuit_hdr.odg +0 -0
  68. data/tuto/circuit_hdr.png +0 -0
  69. data/tuto/circuit_hie.odg +0 -0
  70. data/tuto/circuit_hie.png +0 -0
  71. data/tuto/circuit_view.odg +0 -0
  72. data/tuto/circuit_view.png +0 -0
  73. data/tuto/clock_counter_vcd.png +0 -0
  74. data/tuto/counter_ext_vcd.png +0 -0
  75. data/tuto/fact_vcd.png +0 -0
  76. data/tuto/hw_flow.odg +0 -0
  77. data/tuto/hw_flow.png +0 -0
  78. data/tuto/maxxer_vcd.png +0 -0
  79. data/tuto/pingpong0_vcd.png +0 -0
  80. data/tuto/pingpong1_vcd.png +0 -0
  81. data/tuto/pingpong2_vcd.png +0 -0
  82. data/tuto/ram_vcd.png +0 -0
  83. data/tuto/serializer_vcd.png +0 -0
  84. data/tuto/sw_flow.odg +0 -0
  85. data/tuto/sw_flow.png +0 -0
  86. data/tuto/the_counter_vcd.png +0 -0
  87. data/tuto/tutorial_sw.html +2359 -0
  88. data/tuto/tutorial_sw.md +2890 -0
  89. data/tuto/tutorial_sw.pdf +0 -0
  90. data/tuto/tutorial_sw_jp.md +417 -0
  91. metadata +46 -2
@@ -0,0 +1,439 @@
1
+ require 'std/sequencer.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Checking the usage of sequencer's enumerable capabilities.
6
+ # - The first sequencer checks sall?
7
+ # - The second sequencer checks sany?
8
+ # - The third sequencer checks schain
9
+ # - The forth sequencer checks smap
10
+ # - The fifth sequencer checks smap with with_index
11
+ # - The sixth sequencer checks scompact
12
+ # - The seventh sequencer checks scount
13
+ # - The eighth sequencer checks scycle
14
+ # - The nineth sequencer checks sfind
15
+ # - The tenth sequencer checks sdrop and sdrop_while
16
+ # - The eleventh sequencer checks seach_cons
17
+ # - The twelveth sequencer checks seach_slice
18
+ # - The thirteenth sequencer checks sto_a
19
+ # - The forteenth sequencer checks sselect
20
+ # - The fifteenth sequencer checks sfind_index
21
+ # - The sixteenth sequencer checks sfirst
22
+ # - The seventeenth sequencer checks sinject
23
+ # - The eighteenth sequencer checks smax
24
+ # - The nineteenth sequencer checks smax_by
25
+ # - The twentieth sequencer checks smax_by
26
+ # - The twenty firth sequencer checks smin
27
+ # - The twenty second sequencer checks smin_by
28
+ # - The twenty third sequencer checks sminmax and sminmax_by
29
+ # - The twenty fourth sequencer checks snone?
30
+ # - The twenty fifth sequencer checks sone?
31
+ # - The twenty sixth sequencer checks sreverse_each
32
+ # - The twenty seventh sequencer checks ssort and ssort_by
33
+ # - The twenty eighth sequencer checks ssum
34
+ # - The twenty nineth sequencer checks stake and stake_while
35
+ # - The thirtieth sequencer checks suniq
36
+ # - The thirty first sequencer checks szip
37
+ #
38
+ # __WARNING__: All the operations on enumerators generate their own result
39
+ # signal. Therefore, in a real circuit, there is no need to
40
+ # declare your own signal for it, as demonstrated in this sample.
41
+ # In other words, the res<num> signals are unnecessary, and
42
+ # assigning the result to them only slows down the circuit without
43
+ # any benefit. Instead, they can be replaced with Ruby variables
44
+ # as shown below:
45
+ # from: res<num> <= <enumerator operation>
46
+ # to: <ruby variable> = <enumerator operation>
47
+ # In this sample it is done this way for an easy vizualization of
48
+ # the multiple results.
49
+ #
50
+ # For instance the first example should be rewritten from:
51
+ # [16].inner :res0, :res1
52
+ # sequencer(clk.posedge,rst) do
53
+ # res0 <= 0; res1 <= 1
54
+ # step
55
+ # res0 <= vals.sall? { |val| val!= _h11 }
56
+ # res1 <= vals.sall? { |val| val!= _h5C }
57
+ # end
58
+ # to:
59
+ # res0 = nil; res1 = nil
60
+ # sequencer(clk.posedge,rst) do
61
+ # res0 = vals.sall? { |val| val!= _h11 }
62
+ # res1 = vals.sall? { |val| val!= _h5C }
63
+ # end
64
+ #
65
+ system :my_seqencer do
66
+
67
+ inner :clk,:rst
68
+
69
+ bit[8][-8].inner vals: [ _h00, _h10, _hA5, _h0B, _hFE, _h34, _h5C, _h44 ]
70
+
71
+ [16].inner :res0, :res1
72
+
73
+ sequencer(clk.posedge,rst) do
74
+ # hprint("#0\n")
75
+ res0 <= 0
76
+ res1 <= 0
77
+ step
78
+ res0 <= vals.sall? { |val| val != _h11 }
79
+ res1 <= vals.sall? { |val| val != _h5C }
80
+ # hprint("#1 res0=",res0," res1=",res1,"\n")
81
+ end
82
+
83
+ [16].inner :res2, :res3
84
+
85
+ sequencer(clk.posedge,rst) do
86
+ # hprint("$0\n")
87
+ res2 <= 0
88
+ res3 <= 0
89
+ step
90
+ res2 <= vals.sany? { |val| val == _h11 }
91
+ res3 <= vals.sany? { |val| val == _h5C }
92
+ # hprint("$1 res2=",res2," res3=",res3,"\n")
93
+ end
94
+
95
+ [16].inner :res4
96
+
97
+ sequencer(clk.posedge,rst) do
98
+ # hprint("!0\n")
99
+ res4 <= 0
100
+ vals.schain(0..10).seach do |elem|
101
+ res4 <= elem
102
+ # hprint("!1 res4=",res4,"\n")
103
+ end
104
+ # hprint("!2 res4=",res4,"\n")
105
+ end
106
+
107
+ [8*8].inner :res5
108
+
109
+ sequencer(clk.posedge,rst) do
110
+ # hprint("%0\n");
111
+ res5 <= 0
112
+ res5 <= vals.smap { |val| val + 1 }
113
+ # hprint("%1 res5=",res5,"\n");
114
+ end
115
+
116
+ [8*8].inner :res6
117
+
118
+ sequencer(clk.posedge,rst) do
119
+ # hprint("&0\n");
120
+ res6 <= 0
121
+ res6 <= vals.smap.with_index { |val,i| val + i }
122
+ # hprint("&1 res6=",res6,"\n");
123
+ end
124
+
125
+ bit[8][-8].inner vals2: [ _h00, _h10, _h00, _h0B, _hFE, _h00, _h5C, _h00 ]
126
+ [8*8].inner :res7
127
+
128
+ sequencer(clk.posedge,rst) do
129
+ # hprint("|0\n");
130
+ res7 <= 0
131
+ res7 <= vals2.scompact
132
+ # hprint("|1 res7=",res7,"\n");
133
+ end
134
+
135
+ [8].inner :res8, :res9, :res10
136
+
137
+ sequencer(clk.posedge,rst) do
138
+ # hprint("(0\n");
139
+ res8 <= 0
140
+ res9 <= 0
141
+ res10 <= 0
142
+ res8 <= vals2.scount
143
+ res9 <= vals2.scount(_h00)
144
+ res10 <= vals2.scount {|elem| elem > _h10 }
145
+ # hprint("(1 res8=",res8," res9=",res9," res10=",res10,"\n");
146
+ end
147
+
148
+ [8].inner :res11, :res12
149
+
150
+ sequencer(clk.posedge,rst) do
151
+ # hprint(")0\n")
152
+ res11 <= 0
153
+ res12 <= 0
154
+ vals.scycle(2) { |elem| res11 <= elem }
155
+ # hprint(")1 res11=",res11,"\n")
156
+ vals2.scycle { |elem| res12 <= elem }
157
+ # hprint(")2 Should never be here! ... res12=",res12,"\n")
158
+ end
159
+
160
+ [8].inner :res13, :res14
161
+
162
+ sequencer(clk.posedge,rst) do
163
+ # hprint("=0\n")
164
+ res13 <= 0
165
+ res14 <= 0
166
+ res13 <= vals.sfind(-1) { |elem| elem > 0 }
167
+ res14 <= vals.sfind(-1) { |elem| elem == _hAA }
168
+ # hprint("=1 res13=",res13," res14=",res14,"\n")
169
+ end
170
+
171
+ [8*8].inner :res15, :res16
172
+
173
+ sequencer(clk.posedge,rst) do
174
+ # hprint("+0\n")
175
+ res15 <= 0
176
+ res16 <= 0
177
+ res15 <= vals.sdrop(3)
178
+ res16 <= vals.sdrop_while { |elem| elem < _hAA }
179
+ # hprint("+1 res15=",res15," res16=",res16,"\n")
180
+ end
181
+
182
+ [8].inner :res17
183
+
184
+ sequencer(clk.posedge,rst) do
185
+ # hprint("*0\n")
186
+ res17 <= 0
187
+ vals.seach_cons(3) { |a,b,c| res17 <= a+b+c }
188
+ # hprint("*1 res17=",res17,"\n")
189
+ end
190
+
191
+ [8].inner :res18
192
+
193
+ sequencer(clk.posedge,rst) do
194
+ # hprint("/0\n")
195
+ res18 <= 0
196
+ vals.seach_slice(3) { |a,b,c| res18 <= a+b+c }
197
+ # hprint("/1 res18=",res18,"\n")
198
+ end
199
+
200
+ [32*4].inner :res19
201
+
202
+ sequencer(clk.posedge,rst) do
203
+ # hprint("~0\n")
204
+ res19 <= 0
205
+ res19 <= (_h00000001.._h00000004).seach.sto_a
206
+ # hprint("~1 res19=",res19,"\n")
207
+ end
208
+
209
+ [8].inner :res21, :res22
210
+
211
+ sequencer(clk.posedge,rst) do
212
+ # hprint(">0\n")
213
+ res21 <= 0
214
+ res22 <= 0
215
+ res21 <= vals.sfind_index(_h0B)
216
+ res22 <= vals.sfind_index { |elem| elem < _hAA }
217
+ # hprint(">1 res21=",res21," res22=",res22,"\n")
218
+ end
219
+
220
+ [4*8].inner :res23
221
+
222
+ sequencer(clk.posedge,rst) do
223
+ # hprint("<0\n")
224
+ res23 <= 0
225
+ res23 <= vals.sfirst(4)
226
+ # hprint("<1 res23=",res23,"\n")
227
+ end
228
+
229
+ inner :res24, :res25
230
+
231
+ sequencer(clk.posedge,rst) do
232
+ # hprint("!0\n")
233
+ res24 <= 0
234
+ res25 <= 0
235
+ res24 <= vals.sinclude?(_h0B)
236
+ res25 <= vals.sinclude?(_hAA)
237
+ # hprint("!1 res24=",res24," res25=",res25,"\n")
238
+ end
239
+
240
+ [8].inner :res26, :res27
241
+
242
+ sequencer(clk.posedge,rst) do
243
+ # hprint(":0\n")
244
+ res26 <= 0
245
+ res27 <= 0
246
+ res26 <= vals.sinject(_h01) { |a,b| a+b }
247
+ res27 <= vals.sinject(:+)
248
+ # hprint(":1 res26=",res26," res27=",res27,"\n")
249
+ end
250
+
251
+ [8].inner :res28
252
+ [8*3].inner :res29
253
+
254
+ sequencer(clk.posedge,rst) do
255
+ # hprint(";0\n")
256
+ res28 <= 0
257
+ res29 <= 0
258
+ res28 <= vals.smax
259
+ res29 <= vals.smax(3)
260
+ # hprint(";1 res28=",res28," res29=",res29,"\n")
261
+ end
262
+
263
+ [8].inner :res30
264
+ [8*3].inner :res31
265
+
266
+ sequencer(clk.posedge,rst) do
267
+ # hprint(",0\n")
268
+ res30 <= 0
269
+ res31 <= 0
270
+ res30 <= vals.smax_by {|e| e.to_signed }
271
+ res31 <= vals.smax_by(3) {|e| e.to_signed }
272
+ # hprint(",1 res30=",res30," res31=",res31,"\n")
273
+ end
274
+
275
+ [8].inner :res32
276
+ [8*3].inner :res33
277
+
278
+ sequencer(clk.posedge,rst) do
279
+ # hprint(".0\n")
280
+ res32 <= 0
281
+ res33 <= 0
282
+ res32 <= vals.smin
283
+ res33 <= vals.smin(3)
284
+ # hprint(".1 res32=",res32," res33=",res33,"\n")
285
+ end
286
+
287
+ [8].inner :res34
288
+ [8*3].inner :res35
289
+
290
+ sequencer(clk.posedge,rst) do
291
+ # hprint(":0\n")
292
+ res34 <= 0
293
+ res35 <= 0
294
+ res34 <= vals.smin_by {|e| e.to_signed }
295
+ res35 <= vals.smin_by(3) {|e| e.to_signed }
296
+ # hprint(":1 res34=",res34," res35=",res35,"\n")
297
+ end
298
+
299
+ [16].inner :res36, :res37
300
+
301
+ sequencer(clk.posedge,rst) do
302
+ # hprint("]0\n")
303
+ res36 <= 0
304
+ res37 <= 0
305
+ res36 <= vals.sminmax
306
+ res37 <= vals.sminmax_by {|e| e.to_signed }
307
+ # hprint("]1 res36=",res36," res37=",res37,"\n")
308
+ end
309
+
310
+ [8].inner :res38, :res39
311
+
312
+ sequencer(clk.posedge,rst) do
313
+ # hprint("[0\n")
314
+ res38 <= 0
315
+ res39 <= 0
316
+ step
317
+ res38 <= vals.snone? { |val| val == _h11 }
318
+ res39 <= vals.snone?(_h5C)
319
+ # hprint("[1 res38=",res38," res39=",res39,"\n")
320
+ end
321
+
322
+ [8].inner :res40, :res41, :res42
323
+
324
+ sequencer(clk.posedge,rst) do
325
+ # hprint("[0\n")
326
+ res40 <= 0
327
+ res41 <= 0
328
+ res42 <= 0
329
+ step
330
+ res40 <= vals.sone?(_h5C)
331
+ res41 <= vals.sone? { |val| val == _h11 }
332
+ res42 <= vals2.sone? { |val| val == _h00 }
333
+ # hprint("[1 res40=",res40," res41=",res41," res42=",res42,"\n")
334
+ end
335
+
336
+ [8].inner :res43
337
+
338
+ sequencer(clk.posedge,rst) do
339
+ # hprint("_0\n")
340
+ res43 <= 0
341
+ step
342
+ (4..10).sreverse_each { |val| res43 <= val }
343
+ # hprint("_1 res43=",res43,"\n")
344
+ end
345
+
346
+ [8*10].inner :res44X, :res45X
347
+ [8*8].inner :res44, :res45
348
+ bit[8][-10].inner valsX: [ _h00, _h10, _hA5, _h0B, _hFE, _h34, _h5C, _h44, _h01, _h82 ]
349
+
350
+ sequencer(clk.posedge,rst) do
351
+ # hprint("@0\n")
352
+ res44 <= 0
353
+ res45 <= 0
354
+ res44X <= 0
355
+ res45X <= 0
356
+ step
357
+ res44 <= vals.ssort
358
+ res45 <= vals.ssort_by { |val| val.to_signed }
359
+ res44X <= valsX.ssort
360
+ res45X <= valsX.ssort_by { |val| val.to_signed }
361
+ # hprint("@1 res44=",res44," res45=",res45,"\n")
362
+ end
363
+
364
+ [8].inner :res46, :res47
365
+
366
+ sequencer(clk.posedge,rst) do
367
+ # hprint("`0\n")
368
+ res46 <= 0
369
+ res47 <= 0
370
+ step
371
+ res46 <= vals.ssum
372
+ res47 <= vals.ssum { |val| val & _h0F }
373
+ # hprint("`1 res46=",res46," res47=",res47,"\n")
374
+ end
375
+
376
+ [8*3].inner :res48
377
+ [8*8].inner :res49
378
+
379
+ sequencer(clk.posedge,rst) do
380
+ # hprint("`0\n")
381
+ res48 <= 0
382
+ res49 <= 0
383
+ step
384
+ res48 <= vals.stake(3)
385
+ res49 <= vals.stake_while { |val| val < _hAA }
386
+ # hprint("`1 res48=",res48," res49=",res49,"\n")
387
+ end
388
+
389
+ bit[8][-8].inner vals3: [ _hFE, _h10, _hA5, _h10, _hFE, _h34, _h5C, _h10 ]
390
+
391
+ [8*8].inner :res50,:res51
392
+
393
+ sequencer(clk.posedge,rst) do
394
+ # hprint("~0\n")
395
+ res50 <= 0
396
+ res51 <= 0
397
+ step
398
+ res50 <= vals3.suniq
399
+ res51 <= vals.suniq { |val| val & _h0F }
400
+ # hprint("~1 res50=",res50," res51=",res51,"\n")
401
+ end
402
+
403
+ [8*4*2].inner :res52
404
+ bit[8][-8].inner :res53
405
+ [3].inner :idx
406
+
407
+ sequencer(clk.posedge,rst) do
408
+ # hprint("}0\n")
409
+ res52 <= 0
410
+ idx <= 0
411
+ step
412
+ res52 <= vals.szip((1..6).to_a.map {|i| i.to_expr.as(bit[8]) })
413
+ vals.szip([_h12]*8) { |a,b| res53[idx] <= a+b; idx <= idx + 1 }
414
+ # hprint("}1 res52=",res52," res53=",res53,"\n")
415
+ end
416
+
417
+
418
+
419
+ timed do
420
+ clk <= 0
421
+ rst <= 0
422
+ !10.ns
423
+ clk <= 1
424
+ !10.ns
425
+ clk <= 0
426
+ rst <= 1
427
+ !10.ns
428
+ clk <= 1
429
+ !10.ns
430
+ clk <= 0
431
+ rst <= 0
432
+ !10.ns
433
+ clk <= 1
434
+ repeat(500) do
435
+ !10.ns
436
+ clk <= ~clk
437
+ end
438
+ end
439
+ end
@@ -0,0 +1,89 @@
1
+ require 'std/sequencer.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Checking the creation of sequencers enumerators.
6
+ # - The first sequencer checks enumerators on signals.
7
+ # - The second sequencer checks enumerators on ranges.
8
+ # - The third sequencer checks enumerators on arrays.
9
+ # - The fourth sequencer checks custom enumerators.
10
+ system :my_seqencer do
11
+
12
+ inner :clk,:rst
13
+
14
+ bit[8][-8].inner vals: [ _h01, _h02, _h03, _h04, _h10, _h20, _h30, _h40 ]
15
+
16
+ [8].inner :res0, :res1
17
+
18
+ sequencer(clk.posedge,rst) do
19
+ # hprint("#0\n")
20
+ res0 <= 0
21
+ res1 <= 0
22
+ res0 <= vals.ssum
23
+ res1 <= res0.ssum(_h00)
24
+ # hprint("#1 res0=",res0," res1=",res1,"\n")
25
+ end
26
+
27
+ [8].inner :res2, :res3
28
+
29
+ sequencer(clk.posedge,rst) do
30
+ # hprint("$0\n")
31
+ res2 <= 0
32
+ res3 <= 0
33
+ res2 <= (1..5).ssum(_h00)
34
+ res3 <= (res3..res2).ssum
35
+ # hprint("$1 res2=",res2," res3=",res3,"\n")
36
+ end
37
+
38
+ [8].inner :res4, :res5
39
+
40
+ sequencer(clk.posedge,rst) do
41
+ # hprint("!0\n")
42
+ res4 <= 0
43
+ res5 <= 0
44
+ res4 <= [_h01,_h02,_h03,_h04].ssum
45
+ res5 <= [1,2,3,4,5].ssum(_h00)
46
+ # hprint("!1 res4=",res4," res5=",res5,"\n")
47
+ end
48
+
49
+ bit[8][-8].inner mem: [ _h01, _h02, _h03, _h04, _h30, _h30, _h30, _h30 ]
50
+
51
+ [8].inner :res6, :addr, :data
52
+
53
+ data <= mem[addr]
54
+
55
+ mem_enum = senumerator(bit[8],8) do |i|
56
+ addr <= i
57
+ step
58
+ data
59
+ end
60
+
61
+ sequencer(clk.posedge,rst) do
62
+ # hprint("~0\n")
63
+ res6 <= 0
64
+ res6 <= mem_enum.ssum
65
+ # hprint("~1 res6=",res6,"\n")
66
+ end
67
+
68
+
69
+ timed do
70
+ clk <= 0
71
+ rst <= 0
72
+ !10.ns
73
+ clk <= 1
74
+ !10.ns
75
+ clk <= 0
76
+ rst <= 1
77
+ !10.ns
78
+ clk <= 1
79
+ !10.ns
80
+ clk <= 0
81
+ rst <= 0
82
+ !10.ns
83
+ clk <= 1
84
+ repeat(100) do
85
+ !10.ns
86
+ clk <= ~clk
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,63 @@
1
+ require 'std/sequencer_func.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+
6
+ # A factorial with default stack depth.
7
+ sdef(:fact) do |n|
8
+ hprint("n=",n,"\n")
9
+ sif(n > 1) { sreturn(n*fact(n-1,20)) } #Recurse setting the stack depth to 20
10
+ selse { sreturn(1) }
11
+ end
12
+
13
+ # A factiorial with very low stack depth for checking overflow.
14
+ sdef(:fact_over,2,proc { stack_overflow_error <= 1 }) do |n|
15
+ hprint("n2=",n,"\n")
16
+ sif(n > 1) { sreturn(n*fact_over(n-1)) }
17
+ selse { sreturn(1) }
18
+ end
19
+
20
+ # Checking the usage of sequencers functions.
21
+ system :my_seqencer do
22
+
23
+ inner :clk,:rst
24
+
25
+ [16].inner :val
26
+ [16].inner :res
27
+
28
+ inner stack_overflow_error: 0
29
+
30
+ sequencer(clk.posedge,rst) do
31
+ 5.stimes do |i|
32
+ val <= i
33
+ res <= fact(val)
34
+ end
35
+ hprint("Going to overflow...\n")
36
+ 4.stimes do |i|
37
+ val <= i
38
+ res <= fact_over(val)
39
+ end
40
+ hprint("stack_overflow_error=",stack_overflow_error,"\n")
41
+ end
42
+
43
+ timed do
44
+ clk <= 0
45
+ rst <= 0
46
+ !10.ns
47
+ clk <= 1
48
+ !10.ns
49
+ clk <= 0
50
+ rst <= 1
51
+ !10.ns
52
+ clk <= 1
53
+ !10.ns
54
+ clk <= 0
55
+ rst <= 0
56
+ !10.ns
57
+ clk <= 1
58
+ repeat(500) do
59
+ !10.ns
60
+ clk <= ~clk
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,120 @@
1
+ require 'std/sequencer_sync.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # Checking the usage of sequencers with synchronizarion.
6
+ system :my_seqencer do
7
+
8
+ inner :clk,:rst
9
+
10
+ [8].inner :res0, :res1
11
+ [8].shared(x0: _hFF,x1: _hFF)
12
+
13
+ arbiter(:arbiter0).(x1)
14
+
15
+ par(clk.posedge) do
16
+ x0.select <= x0.select + 1
17
+ end
18
+
19
+ sequencer(clk.posedge,rst) do
20
+ sloop do
21
+ res0 <= x0 * 2
22
+ res1 <= x1 * 2
23
+ end
24
+ end
25
+
26
+ sequencer(clk.posedge,rst) do
27
+ 10.stimes do |i|
28
+ x0 <= i
29
+ x1 <= i
30
+ arbiter0 <= 1
31
+ end
32
+ arbiter0 <= 0
33
+ end
34
+
35
+ sequencer(clk.posedge,rst) do
36
+ 10.stimes do |i|
37
+ x0 <= 10-i
38
+ x1 <= 10-i
39
+ arbiter0 <= 1
40
+ step
41
+ end
42
+ arbiter0 <= 0
43
+ end
44
+
45
+ sequencer(clk.posedge,rst) do
46
+ 10.stimes do |i|
47
+ step
48
+ arbiter0 <= 1
49
+ x0 <= 128+i
50
+ x1 <= 128+i
51
+ step
52
+ arbiter0 <= 0
53
+ end
54
+ end
55
+
56
+
57
+
58
+ [8].inner :res2, :res20, :res21, :res22
59
+ [8].shared x2: _hFF
60
+
61
+ monitor(:monitor0).(x2)
62
+
63
+ sequencer(clk.posedge,rst) do
64
+ sloop do
65
+ res2 <= x2 * 2
66
+ end
67
+ end
68
+
69
+ sequencer(clk.posedge,rst) do
70
+ x2 <= 0
71
+ monitor0.lock
72
+ 4.stimes do |i|
73
+ res20 <= res2
74
+ x2 <= i + 1
75
+ end
76
+ res20 <= res2
77
+ monitor0.unlock
78
+ end
79
+
80
+ sequencer(clk.posedge,rst) do
81
+ 5.stimes do |i|
82
+ x2 <= 16 + i
83
+ monitor0.lock
84
+ res21 <= res2
85
+ monitor0.unlock
86
+ end
87
+ end
88
+
89
+ sequencer(clk.posedge,rst) do
90
+ 5.stimes do |i|
91
+ x2 <= 32 + i
92
+ monitor0.lock
93
+ res22 <= res2
94
+ step
95
+ monitor0.unlock
96
+ end
97
+ end
98
+
99
+
100
+ timed do
101
+ clk <= 0
102
+ rst <= 0
103
+ !10.ns
104
+ clk <= 1
105
+ !10.ns
106
+ clk <= 0
107
+ rst <= 1
108
+ !10.ns
109
+ clk <= 1
110
+ !10.ns
111
+ clk <= 0
112
+ rst <= 0
113
+ !10.ns
114
+ clk <= 1
115
+ repeat(100) do
116
+ !10.ns
117
+ clk <= ~clk
118
+ end
119
+ end
120
+ end