HDLRuby 3.1.0 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.html +2330 -2670
  4. data/README.md +400 -100
  5. data/ext/hruby_sim/hruby_rcsim_build.c +402 -3
  6. data/ext/hruby_sim/hruby_sim.h +2 -1
  7. data/ext/hruby_sim/hruby_sim_calc.c +34 -7
  8. data/ext/hruby_sim/hruby_sim_core.c +15 -5
  9. data/ext/hruby_sim/hruby_sim_tree_calc.c +112 -23
  10. data/lib/HDLRuby/hdr_samples/c_program/echo.c +33 -0
  11. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
  12. data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
  13. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
  14. data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
  15. data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
  16. data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
  17. data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
  18. data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
  19. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
  20. data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
  21. data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
  22. data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
  23. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
  24. data/lib/HDLRuby/hdr_samples/ruby_program/echo.rb +9 -0
  25. data/lib/HDLRuby/hdr_samples/ruby_program/stdrw.rb +6 -0
  26. data/lib/HDLRuby/hdr_samples/ruby_program/sw_cpu_terminal.rb +614 -0
  27. data/lib/HDLRuby/hdr_samples/ruby_program/sw_inc_mem.rb +32 -0
  28. data/lib/HDLRuby/hdr_samples/ruby_program/sw_log.rb +33 -0
  29. data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
  30. data/lib/HDLRuby/hdr_samples/with_board.rb +63 -0
  31. data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
  32. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
  33. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
  34. data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
  35. data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
  36. data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
  37. data/lib/HDLRuby/hdr_samples/with_clocks.rb +42 -0
  38. data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
  39. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
  40. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
  41. data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
  42. data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
  43. data/lib/HDLRuby/hdr_samples/with_of.rb +1 -1
  44. data/lib/HDLRuby/hdr_samples/with_program_c.rb +28 -0
  45. data/lib/HDLRuby/hdr_samples/with_program_ruby.rb +28 -0
  46. data/lib/HDLRuby/hdr_samples/with_program_ruby_cpu.rb +234 -0
  47. data/lib/HDLRuby/hdr_samples/with_program_ruby_io.rb +23 -0
  48. data/lib/HDLRuby/hdr_samples/with_program_ruby_mem.rb +58 -0
  49. data/lib/HDLRuby/hdr_samples/with_program_ruby_threads.rb +56 -0
  50. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +17 -0
  51. data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
  52. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +10 -0
  53. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +18 -4
  54. data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +2 -4
  55. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
  56. data/lib/HDLRuby/hdrcc.rb +72 -21
  57. data/lib/HDLRuby/hruby_error.rb +13 -0
  58. data/lib/HDLRuby/hruby_high.rb +125 -26
  59. data/lib/HDLRuby/hruby_low.rb +171 -3
  60. data/lib/HDLRuby/hruby_low2programs.rb +47 -0
  61. data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
  62. data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
  63. data/lib/HDLRuby/hruby_low_without_subsignals.rb +1 -1
  64. data/lib/HDLRuby/hruby_rcsim.rb +113 -6
  65. data/lib/HDLRuby/hruby_serializer.rb +2 -1
  66. data/lib/HDLRuby/hruby_verilog.rb +94 -20
  67. data/lib/HDLRuby/hruby_verilog_name.rb +3 -17
  68. data/lib/HDLRuby/std/clocks.rb +118 -50
  69. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  70. data/lib/HDLRuby/std/function_generator.rb +1 -1
  71. data/lib/HDLRuby/std/linear.rb +7 -7
  72. data/lib/HDLRuby/std/sequencer.rb +263 -13
  73. data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
  74. data/lib/HDLRuby/std/sequencer_func.rb +28 -15
  75. data/lib/HDLRuby/std/std.rb +6 -0
  76. data/lib/HDLRuby/ui/hruby_board.rb +1079 -0
  77. data/lib/HDLRuby/version.rb +1 -1
  78. data/lib/c/Rakefile +8 -0
  79. data/lib/c/cHDL.h +12 -0
  80. data/lib/c/extconf.rb +7 -0
  81. data/lib/rubyHDL.rb +33 -0
  82. data/tuto/gui_accum.png +0 -0
  83. data/tuto/gui_board.png +0 -0
  84. data/tuto/tutorial_sw.html +2263 -1890
  85. data/tuto/tutorial_sw.md +957 -62
  86. metadata +43 -5
  87. data/README.pdf +0 -0
  88. data/tuto/tutorial_sw.pdf +0 -0
@@ -4,10 +4,10 @@ module HDLRuby::High::Std
4
4
  # Standard HDLRuby::High library: clocks
5
5
  #
6
6
  ########################################################################
7
-
7
+ @@__clocks_rst = nil
8
8
 
9
9
  # Initialize the clock generator with +rst+ as reset signal.
10
- def configure_clocks(rst = $rst)
10
+ def configure_clocks(rst = nil)
11
11
  @@__clocks_rst = rst
12
12
  end
13
13
 
@@ -19,13 +19,22 @@ module HDLRuby::High::Std
19
19
  HDLRuby::High.cur_system.open do
20
20
 
21
21
  # Ensures times is a value.
22
- times = times.to_value
22
+ times = times.to_value - 1
23
+ if (times == 0) then
24
+ AnyError.new("Clock multiplier must be >= 2.")
25
+ end
23
26
 
24
27
  # Create the counter.
25
28
  # Create the name of the counter.
26
29
  name = HDLRuby.uniq_name
27
30
  # Declare the counter.
28
- [times.width].inner(name)
31
+ if @@__clocks_rst then
32
+ # There is a reset, so no need to initialize.
33
+ [times.width].inner(name)
34
+ else
35
+ # There is no reset, so need to initialize.
36
+ [times.width].inner(name => times)
37
+ end
29
38
  # Get the signal of the counter.
30
39
  counter = get_inner(name)
31
40
 
@@ -33,51 +42,77 @@ module HDLRuby::High::Std
33
42
  # Create the name of the clock.
34
43
  name = HDLRuby.uniq_name
35
44
  # Declares the clock.
36
- bit.inner(name)
45
+ if @@__clocks_rst then
46
+ # There is a reset, so no need to initialize.
47
+ bit.inner(name)
48
+ else
49
+ # There is no reset, so need to initialize.
50
+ bit.inner(name => times)
51
+ end
37
52
  # Get the signal of the clock.
38
53
  clock = get_inner(name)
39
54
 
40
55
  # Control it.
41
56
  par(event) do
42
- hif(@@__clocks_rst) do
43
- counter.to_ref <= times.to_expr
44
- clock.to_ref <= 0
45
- end
46
- helsif(counter.to_expr == 0) do
47
- counter.to_ref <= times.to_expr
48
- clock.to_ref <= ~ clock.to_expr
49
- end
50
- helse do
51
- counter.to_ref <= counter.to_expr + 1
57
+ if @@__clocks_rst then
58
+ # There is a reset, handle it.
59
+ hif(@@__clocks_rst) do
60
+ counter <= times
61
+ clock <= 0
62
+ end
63
+ helsif(counter.to_expr == 0) do
64
+ counter <= times
65
+ clock <= ~ clock
66
+ end
67
+ helse do
68
+ counter <= counter - 1
69
+ end
70
+ else
71
+ # There is no reset.
72
+ hif(counter == 0) do
73
+ counter <= times
74
+ clock <= ~ clock
75
+ end
76
+ helse do
77
+ counter <= counter - 1
78
+ end
52
79
  end
53
80
  end
54
81
  end
55
82
  return clock
56
83
  end
57
84
 
58
- # module clk_div3(clk,reset, clk_out);
59
-
60
- # input clk;
61
- # input reset;
62
- # output clk_out;
63
-
64
- # reg [1:0] pos_count, neg_count;
65
- # wire [1:0] r_nxt;
66
-
67
- # always @(posedge clk)
68
- # if (reset)
69
- # pos_count <=0;
70
- # else if (pos_count ==2) pos_count <= 0;
71
- # else pos_count<= pos_count +1;
72
85
 
73
- # always @(negedge clk)
74
- # if (reset)
75
- # neg_count <=0;
76
- # else if (neg_count ==2) neg_count <= 0;
77
- # else neg_count<= neg_count +1;
86
+ # https://referencedesigner.com/tutorials/verilogexamples/verilog_ex_07.php
87
+ #
88
+ # module clk_divn #(
89
+ # parameter WIDTH = 3,
90
+ # parameter N = 5)
91
+ #
92
+ # (clk,reset, clk_out);
93
+ #
94
+ # input clk;
95
+ # input reset;
96
+ # output clk_out;
97
+ #
98
+ # reg [WIDTH-1:0] pos_count, neg_count;
99
+ # wire [WIDTH-1:0] r_nxt;
100
+ #
101
+ # always @(posedge clk)
102
+ # if (reset)
103
+ # pos_count <=0;
104
+ # else if (pos_count ==N-1) pos_count <= 0;
105
+ # else pos_count<= pos_count +1;
106
+ #
107
+ # always @(negedge clk)
108
+ # if (reset)
109
+ # neg_count <=0;
110
+ # else if (neg_count ==N-1) neg_count <= 0;
111
+ # else neg_count<= neg_count +1;
112
+ #
113
+ # assign clk_out = ((pos_count > (N>>1)) | (neg_count > (N>>1)));
114
+ # endmodule
78
115
 
79
- # assign clk_out = ((pos_count == 2) | (neg_count == 2));
80
- # endmodule
81
116
 
82
117
  # Creates a clock inverted every +times+ occurence of an +event+ and its
83
118
  # everted.
@@ -87,13 +122,22 @@ module HDLRuby::High::Std
87
122
  # Enters the current system
88
123
  HDLRuby::High.cur_system.open do
89
124
  # Ensure times is a value.
90
- times = times.to_value
125
+ times = times.to_value
126
+ if (times == 1) then
127
+ AnyError.new("Clock multiplier must be >= 2.")
128
+ end
91
129
 
92
130
  # Create the event counter.
93
131
  # Create the name of the counter.
94
132
  name = HDLRuby.uniq_name
95
133
  # Declare the counter.
96
- [times.width].inner(name)
134
+ if @@__clocks_rst then
135
+ # There is a reset, so no need to initialize.
136
+ [times.width].inner(name)
137
+ else
138
+ # There is no reset, so need to initialize.
139
+ [times.width].inner(name => 0)
140
+ end
97
141
  # Get the signal of the counter.
98
142
  counter = get_inner(name)
99
143
 
@@ -101,7 +145,13 @@ module HDLRuby::High::Std
101
145
  # Create the name of the counter.
102
146
  name = HDLRuby.uniq_name
103
147
  # Declare the counter.
104
- [times.width].inner(name)
148
+ if @@__clocks_rst then
149
+ # There is a reset, so no need to initialize.
150
+ [times.width].inner(name)
151
+ else
152
+ # There is no reset, so need to initialize.
153
+ [times.width].inner(name => 0)
154
+ end
105
155
  # Get the signal of the counter.
106
156
  counter_inv = get_inner(name)
107
157
 
@@ -109,32 +159,50 @@ module HDLRuby::High::Std
109
159
  # Create the name of the clock.
110
160
  name = HDLRuby.uniq_name
111
161
  # Declare the clock.
112
- bit.inner(name)
162
+ if @@__clocks_rst then
163
+ # There is a reset, so no need to initialize.
164
+ bit.inner(name)
165
+ else
166
+ # There is no reset, so need to initialize.
167
+ bit.inner(name => 0)
168
+ end
113
169
  # Get the signal of the clock.
114
170
  clock = get_inner(name)
115
171
 
116
- # Control the event counter
172
+ # Control the even counter.
117
173
  par(event) do
118
- hif(@@__clocks_rst | counter.to_expr == 0) do
119
- counter.to_ref <= times.to_expr/2 + 1
174
+ if @@__clocks_rst then
175
+ hif(@@__clocks_rst) { counter <= 0 }
176
+ helsif(counter == times-1) { counter <= 0 }
177
+ helse { counter <= counter + 1 }
178
+ else
179
+ hif(counter == times-1) { counter <= 0 }
180
+ helse { counter <= counter + 1 }
120
181
  end
121
182
  end
122
- # Control the inverteed event counter
183
+
184
+ # Control the odd counter.
123
185
  par(event.invert) do
124
- hif(@@__clocks_rst | counter_inv.to_expr == 0) do
125
- counter_inv.to_ref <= times.to_expr/2 + 1
186
+ if @@__clocks_rst then
187
+ hif(@@__clocks_rst) { counter_inv <= 0 }
188
+ helsif(counter == times-1) { counter_inv <= 0 }
189
+ helse { counter_inv <= counter_inv + 1 }
190
+ else
191
+ hif(counter == times-1) { counter_inv <= 0 }
192
+ helse { counter_inv <= counter_inv + 1 }
126
193
  end
127
194
  end
128
- # Compute the clock.
129
- clock.to_ref <= (counter.to_expr == times.to_expr/2 + 1) |
130
- (counter_inv.to_expr == times.to_expr/2 + 1)
195
+
196
+ clock <= ((counter > (times/2)) | (counter_inv > (times/2)))
131
197
  end
132
- # Return it.
198
+ # Return the clock.
133
199
  return clock
134
200
  end
201
+
135
202
  end
136
203
 
137
204
 
205
+
138
206
  class HDLRuby::High::Event
139
207
  # Enhance the events with multiply operator.
140
208
 
@@ -53,9 +53,9 @@ module HDLRuby::High::Std
53
53
  # Redefine the multiplication and division for fixed point.
54
54
  typ.define_operator(:*) do |left,right|
55
55
  if (typ.signed?) then
56
- (left.as(signed[isize+fsize*2])*right) >> fsize
56
+ ((left.as(signed[isize+fsize*2])*right) >> fsize).as(typ)
57
57
  else
58
- (left.as(bit[isize+fsize*2])*right) >> fsize
58
+ ((left.as(bit[isize+fsize*2])*right) >> fsize).as(typ)
59
59
  end
60
60
  end
61
61
  typ.define_operator(:/) do |left,right|
@@ -75,7 +75,7 @@ module HDLRuby::High::Std
75
75
  base <= lut[address]
76
76
 
77
77
  # Assign the next_data discrete value.
78
- next_data <= lut[address+_b1.as(address.type)]
78
+ next_data <= mux(address < lut_size-1,lut[address],lut[address+_b1.as(address.type)])
79
79
  end
80
80
 
81
81
 
@@ -16,7 +16,7 @@ module HDLRuby::High::Std
16
16
  # - +ruby_block+: the code of the linear computation kernel, it takes
17
17
  # as argument +ev+, and its own req and ack signals
18
18
  # (resp. +req_ker+ +ack_ker+).
19
- function :linearun do |num,ev,req,ack,ruby_block|
19
+ hdef :linearun do |num,ev,req,ack,ruby_block|
20
20
  # Ensure ev is really an event.
21
21
  ev = ev.posedge unless ev.is_a?(Event)
22
22
 
@@ -57,7 +57,7 @@ module HDLRuby::High::Std
57
57
  # Delcares a vector product by a scalar value.
58
58
  #
59
59
  # Can be used for scaling a vector.
60
- function :scale do |typ,ev,req,ack,left,rights,prods,
60
+ hdef :scale do |typ,ev,req,ack,left,rights,prods,
61
61
  mul = proc { |x,y| x*y }|
62
62
  # Ensure ev is really an event.
63
63
  ev = ev.posedge unless ev.is_a?(Event)
@@ -101,7 +101,7 @@ module HDLRuby::High::Std
101
101
  # Declares a 1-dimension vector adder.
102
102
  #
103
103
  # Can be used for the sum of two vectors.
104
- function :add_n do |typ,ev,req,ack,lefts, rights, sums,
104
+ hdef :add_n do |typ,ev,req,ack,lefts, rights, sums,
105
105
  add = proc { |x,y| x+y }|
106
106
  # Ensure ev is really an event.
107
107
  ev = ev.posedge unless ev.is_a?(Event)
@@ -143,7 +143,7 @@ module HDLRuby::High::Std
143
143
  end
144
144
 
145
145
  # Declares a 1-dimension vector element-wise multiplier.
146
- function :mul_n do |typ,ev,req,ack,lefts, rights, prods,
146
+ hdef :mul_n do |typ,ev,req,ack,lefts, rights, prods,
147
147
  mul = proc { |x,y| x*y }|
148
148
  add_n(typ,ev,req,ack,lefts,rights,prods,mul)
149
149
  end
@@ -152,7 +152,7 @@ module HDLRuby::High::Std
152
152
  # Declares a simple multiplier accumulator.
153
153
  #
154
154
  # Can be used for the scalar product of two vectors.
155
- function :mac do |typ,ev,req,ack,left, right, acc,
155
+ hdef :mac do |typ,ev,req,ack,left, right, acc,
156
156
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
157
157
  # Ensure ev is really an event.
158
158
  ev = ev.posedge unless ev.is_a?(Event)
@@ -193,7 +193,7 @@ module HDLRuby::High::Std
193
193
  # Declares a simple multiple mac with single right data.
194
194
  #
195
195
  # Can be used for the product of a martix-vector product.
196
- function :mac_n1 do |typ,ev,req,ack,lefts, right, accs,
196
+ hdef :mac_n1 do |typ,ev,req,ack,lefts, right, accs,
197
197
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
198
198
  # Ensure ev is really an event.
199
199
  ev = ev.posedge unless ev.is_a?(Event)
@@ -262,7 +262,7 @@ module HDLRuby::High::Std
262
262
  # Declares a simple pipelined multiple mac with single right data.
263
263
  #
264
264
  # Can be used for the product of a martix-vector product.
265
- function :mac_np do |typ,ev,req,ack,lefts, rights, last,
265
+ hdef :mac_np do |typ,ev,req,ack,lefts, rights, last,
266
266
  mul = proc { |x,y| x*y }, add = proc { |x,y| x+y }|
267
267
  # Ensure ev is really an event.
268
268
  ev = ev.posedge unless ev.is_a?(Event)