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
@@ -0,0 +1,63 @@
1
+
2
+ # A benchmark for testing the use of a board model implementing:
3
+ # * a simple adder whose input are set using slide switches, and
4
+ # whose output bits are showns on LEDs.
5
+ # * simple unsigned and signed counters whose values are shown using
6
+ # decimal or hexadecimal displays, and oscilloscopes.
7
+ system :with_board do
8
+ inner :clk, :clk2
9
+ [8].inner clk_cnt: 0
10
+ inner rst: 0
11
+ [8].inner :sw_a, :sw_b
12
+ [9].inner :led_z
13
+ [16].inner counter: 0
14
+ [8].inner :counter8
15
+ signed[8].inner :scounter8
16
+
17
+ # Description of the board.
18
+ # It is updated at each rising edge of +clk2+.
19
+ board(:some_board) do
20
+ actport clk2.posedge
21
+ bt reset: rst
22
+ row
23
+ sw sw_a: sw_a
24
+ sw sw_b: sw_b
25
+ led led_z: led_z
26
+ row
27
+ digit cnt_d: counter
28
+ hexa cnt_h: counter
29
+ digit cnt_s: scounter8
30
+ row
31
+ scope scope: counter8
32
+ scope scope_s:scounter8
33
+ end
34
+
35
+ # The adder.
36
+ led_z <= sw_a.as(bit[9]) + sw_b
37
+
38
+ # The counters and the generation of +clk2+.
39
+ counter8 <= counter[7..0]
40
+ scounter8 <= counter[7..0]
41
+
42
+ seq(clk.posedge) do
43
+ hif(rst) { counter <= 0 }
44
+ helse { counter <= counter + 1 }
45
+ clk_cnt <= clk_cnt + 1
46
+ hif(clk_cnt & 3 == 0) { clk2 <= ~clk2 }
47
+ end
48
+
49
+
50
+
51
+ timed do
52
+ clk <= 0
53
+ clk2 <= 0
54
+ !10.ns
55
+ repeat(1000) do
56
+ clk <= 1
57
+ !10.ns
58
+ clk <= 0
59
+ !10.ns
60
+ end
61
+
62
+ end
63
+ end
@@ -10,7 +10,7 @@ system :bram_test do
10
10
  widthD = 8
11
11
 
12
12
 
13
- input :clk,:rwb
13
+ inner :clk,:rwb
14
14
  [widthA].inner :addr
15
15
  [widthD].inner :din,:dout
16
16
 
@@ -11,7 +11,7 @@ system :bram_stach_test do
11
11
  depth = 16
12
12
 
13
13
 
14
- input :clk, :rst, :ce
14
+ inner :clk, :rst, :ce
15
15
  [2].inner :cmd
16
16
  { frame: bit[depth.width], offset: bit[size.width] }.inner :loc
17
17
  [size.width].inner :frame_size
@@ -10,7 +10,7 @@ system :bram_stach_test do
10
10
  widthD = 8
11
11
 
12
12
 
13
- input :clk, :rst, :ce
13
+ inner :clk, :rst, :ce
14
14
  inner :cmd
15
15
  [widthD].inner :din,:dout
16
16
  inner :empty, :full
@@ -1,5 +1,7 @@
1
1
  require 'std/channel.rb'
2
2
 
3
+ raise "std/channel.rb is deprecated."
4
+
3
5
  include HDLRuby::High::Std
4
6
 
5
7
  # Implementation of a handshaker channel transmitting generic values
@@ -1,6 +1,8 @@
1
1
  require 'std/channel.rb'
2
2
  require 'std/hruby_unit.rb'
3
3
 
4
+ raise "std/channel.rb is deprecated."
5
+
4
6
  include HDLRuby::High::Std
5
7
 
6
8
  # A clocked handshake channel for testing purpuse.
@@ -1,5 +1,7 @@
1
1
  # A class for a handshake transmission.
2
2
 
3
+ raise "Deprecated code."
4
+
3
5
  class Handshaker
4
6
 
5
7
  ## Create a new handshaker for transmitting +type+ data.
@@ -179,7 +181,7 @@ end
179
181
 
180
182
  # A system testing the producer/consumer.
181
183
  system :hs_test do
182
- input :clk,:rst
184
+ inner :clk,:rst
183
185
 
184
186
  # Declares the handshaker
185
187
  hs = Handshaker.new([8])
@@ -0,0 +1,42 @@
1
+ # A system for testing the clock generator.
2
+ system :with_clocks do
3
+ inner :clk, :rst
4
+ [8].inner :cnt1, :cnt2, :cnt3, :cnt4, :cnt5
5
+ [8].inner :cnta, :cntb, :cntc, :cntd
6
+
7
+ configure_clocks(rst)
8
+
9
+ (cnt1 <= cnt1 + 1).at(clk.posedge)
10
+ (cnt2 <= cnt2 + 1).at(clk.posedge*2)
11
+ (cnt3 <= cnt3 + 1).at(clk.posedge*3)
12
+ (cnt4 <= cnt4 + 1).at(clk.posedge*4)
13
+ (cnt5 <= cnt5 + 1).at(clk.posedge*5)
14
+
15
+ configure_clocks(nil)
16
+
17
+ (cnta <= cnta + 1).at(clk.posedge*2)
18
+ (cntb <= cntb + 1).at(clk.posedge*3)
19
+ (cntc <= cntc + 1).at(clk.posedge*4)
20
+ (cntd <= cntd + 1).at(clk.posedge*5)
21
+
22
+ timed do
23
+ clk <= 0
24
+ rst <= 0
25
+ !10.ns
26
+ clk <= 1
27
+ !10.ns
28
+ clk <= 0
29
+ rst <= 1
30
+ cnt1 <= 0; cnt2 <= 0; cnt3 <= 0; cnt4 <= 0; cnt5 <= 0
31
+ cnta <= 0; cntb <= 0; cntc <= 0; cntd <= 0
32
+ !10.ns
33
+ clk <= 1
34
+ !10.ns
35
+ clk <= 0
36
+ rst <= 0
37
+ repeat(100) do
38
+ !10.ns
39
+ clk <= ~clk
40
+ end
41
+ end
42
+ end
@@ -1,6 +1,8 @@
1
1
  require 'std/channel.rb'
2
2
  require 'std/connector.rb'
3
3
 
4
+ raise "std/channel.rb is deprecated."
5
+
4
6
  include HDLRuby::High::Std
5
7
 
6
8
  # Sample for testing the connectors of channels.
@@ -3,6 +3,8 @@ require "std/fixpoint.rb"
3
3
  require 'std/channel.rb'
4
4
  require 'std/connector.rb'
5
5
 
6
+ raise "std/channel.rb is deprecated."
7
+
6
8
  include HDLRuby::High::Std
7
9
 
8
10
  system :channel_connector do
@@ -11,6 +11,12 @@ system :fix_test do
11
11
  bit[3..0,3..0].inner :x,:y,:z
12
12
  # Declare three 8-bit integer part 8-bit fractional part
13
13
  signed[3..0,3..0].inner :a,:b,:c,:d
14
+ # Declare the comparison results.
15
+ bit.inner :cmpU, :cmpS
16
+
17
+ cmpU <= (x >= y)
18
+ cmpS <= (a >= b)
19
+
14
20
 
15
21
  # Performs calculation between then
16
22
  timed do
@@ -0,0 +1,73 @@
1
+ # Sample for testing advanced expressions with fixpoint.
2
+
3
+ system :with_fixpoint_adv do
4
+ inner :clk,:rst
5
+ signed[8,8].inner :x,:y,:z,:u,:v,:w,:a,:b,:c,:d
6
+ bit.inner :cmp
7
+
8
+ cmp <= (x >= y)
9
+ u <= (x >= y)
10
+
11
+ sequencer(clk,rst) do
12
+ hif(5>4) { w <= _hFFFF }
13
+ helse { w <= _h0000 }
14
+ swhile(w<_h0000) do
15
+ hif(5>6) { w <= _hFFFF }
16
+ helse { w <= _h0000 }
17
+ end
18
+ 5.stimes do
19
+ x <= _h0100
20
+ y <= _hFF34
21
+ a <= _h0100
22
+ b <= _h0100
23
+ c <= _h0100
24
+ step
25
+ x <= x*a
26
+ hif(x>=y) { z <= _hFFFF }
27
+ helse { z <= _h0000 }
28
+ v <= mux(x>=y,_h0000,_hFFFF)
29
+ hif(10>0) { w <= _hFFFF }
30
+ helse { w <= _h0000 }
31
+ d <= a*b*c
32
+ step
33
+ x <= _h0000
34
+ x <= x*a
35
+ y <= _hFE68
36
+ hif(x>=y) { z <= _hFFFF }
37
+ helse { z <= _h0000 }
38
+ v <= mux(x>=y,_h0000,_hFFFF)
39
+ hif(1>20) { w <= _hFFFF }
40
+ helse { w <= _h0000 }
41
+ a <= _h0200
42
+ d <= a*b*c
43
+ step
44
+ x <= _hFE00
45
+ x <= x*a
46
+ y <= _hFE02
47
+ hif(x>=y) { z <= _hFFFF }
48
+ helse { z <= _h0000 }
49
+ v <= mux(x>=y,_h0000,_hFFFF)
50
+ b <= _h0200
51
+ d <= a*b*c
52
+ end
53
+ end
54
+
55
+ def cstep(n=1)
56
+ n.times do
57
+ clk <= ~clk
58
+ !10.ns
59
+ end
60
+ end
61
+
62
+ timed do
63
+ clk <= 0
64
+ rst <= 0
65
+ !10.ns
66
+ cstep(2)
67
+ rst <= 1
68
+ cstep(2)
69
+ rst <= 0
70
+ cstep(40)
71
+ end
72
+
73
+ end
@@ -3,7 +3,7 @@
3
3
  system :leftright_bench do
4
4
  [8].inner :l,:r0,:r1,:lr
5
5
 
6
- par do
6
+ seq do
7
7
  lr <= r0*2
8
8
  l <= [lr[7],lr[6..0]].to_expr + r1
9
9
  end
@@ -28,7 +28,7 @@ end
28
28
 
29
29
 
30
30
  # A system for testing inheritance and of?
31
- system :with_reconf do
31
+ system :with_of do
32
32
  input :clk,:rst
33
33
  input :d
34
34
  output :q
@@ -0,0 +1,28 @@
1
+
2
+ # A benchmark for testing the use of Ruby software code.
3
+ system :with_ruby_prog do
4
+ inner :clk
5
+ [8].inner :count, :echo
6
+
7
+ program(:c,:echo) do
8
+ actport clk.posedge
9
+ inport inP: count
10
+ outport outP: echo
11
+ code "c_program/c_program"
12
+ end
13
+
14
+
15
+ timed do
16
+ clk <= 0
17
+ count <= 0
18
+ !10.ns
19
+ repeat(10) do
20
+ clk <= 1
21
+ !10.ns
22
+ count <= count + 1
23
+ clk <= 0
24
+ !10.ns
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+
2
+ # A benchmark for testing the use of Ruby software code.
3
+ system :with_ruby_prog do
4
+ inner :clk
5
+ [8].inner :count, :echo
6
+
7
+ program(:ruby,:echo) do
8
+ actport clk.posedge
9
+ inport inP: count
10
+ outport outP: echo
11
+ code "ruby_program/echo.rb"
12
+ end
13
+
14
+
15
+ timed do
16
+ clk <= 0
17
+ count <= 0
18
+ !10.ns
19
+ repeat(10) do
20
+ clk <= 1
21
+ !10.ns
22
+ count <= count + 1
23
+ clk <= 0
24
+ !10.ns
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,234 @@
1
+
2
+ # A benchmark for testing the use of Ruby software code.
3
+ system :with_ruby_prog_cpu do
4
+ ## The processor interface signals.
5
+
6
+ inner :sim # The signal configuring the simulation.
7
+
8
+ inner :clk, :rst
9
+ inner :br, :bg, :rwb
10
+ [16].inner :addr
11
+ [8].inner :dout #, :din
12
+ inner :req, :ack
13
+
14
+ [8].inner :key_reg # Memory-mapped register containing the latest key.
15
+
16
+ ## The configuration parameters.
17
+ [9].inner :hSIZE, :hSTART, :hEND # Display horizontal size and borders.
18
+ [8].inner :vSIZE, :vSTART, :vEND # Display vertical size and borders.
19
+ [8].inner :rxCYCLE # Time for transmitting one bit with the UART
20
+ [16].inner :vADDR, :kADDR # The display and keyboard start addresses
21
+
22
+ program(:ruby,:configure) do
23
+ actport sim.posedge
24
+ outport hSIZE: hSIZE, hSTART: hSTART, hEND: hEND
25
+ outport vSIZE: vSIZE, vSTART: vSTART, vEND: vEND
26
+ outport rxCYCLE: rxCYCLE
27
+ outport vADDR: vADDR, kADDR: kADDR
28
+ code "ruby_program/sw_cpu_terminal.rb"
29
+ end
30
+
31
+ ## The processor model.
32
+
33
+ # This is the bus part of the CPU.
34
+ program(:ruby,:cpu_bus) do
35
+ actport clk.posedge
36
+ inport br: br # Bus request
37
+ outport bg: bg # Bus granted
38
+ inport ain: addr
39
+ inport aout: addr
40
+ inport rwb: rwb
41
+ # inport din: din
42
+ outport dout: dout
43
+
44
+ inport key_reg: key_reg
45
+
46
+ code "ruby_program/sw_cpu_terminal.rb"
47
+ end
48
+
49
+ # This is the reset part of the CPU.
50
+ program(:ruby, :cpu_rst) do
51
+ actport rst.posedge
52
+ code "ruby_program/sw_cpu_terminal.rb"
53
+ end
54
+
55
+ # This is the interrupt part of the CPU.
56
+ program(:ruby,:cpu_irq) do
57
+ actport req.posedge
58
+ outport ack: ack
59
+ code "ruby_program/sw_cpu_terminal.rb"
60
+ end
61
+
62
+
63
+ ## Simplistic circuitry that generates a monochrome video signal
64
+ # For a 320x200 screen with 512-320 pixels horizontal blank and
65
+ # 256-200 lines vertical blank and centered screen.
66
+ # The memory bus is requested at the begining of a line, and if it is
67
+ # not granted on time the pixels are skipped.
68
+
69
+ [1].inner :vclk_count
70
+ inner :vclk
71
+ [9].inner :hcount
72
+ [8].inner :vcount
73
+ [16].inner :vaddr
74
+ inner :hblank, :vblank
75
+ [8].inner :pixel
76
+
77
+ # Generate the video clock: every 4 cycles (for not too long simulation).
78
+ # NOTE: requires reset to last two cycles or more.
79
+ seq(clk.posedge) do
80
+ hif(rst) { vclk_count <= 0; vclk <=0 }
81
+ helse do
82
+ vclk_count <= vclk_count + 1
83
+ hif(vclk_count == 1) { vclk <= ~vclk }
84
+ end
85
+ end
86
+
87
+ # Generates the signal.
88
+ seq(vclk.posedge,rst.posedge) do
89
+ hif(rst) do
90
+ hcount <= 0; vcount <= 0
91
+ hblank <= 0; vblank <= 0
92
+ vaddr <= vADDR
93
+ pixel <= 0
94
+ end
95
+ helse do
96
+ hif((hcount >= hSIZE + hSTART) | (hcount < hSTART)) { hblank <= 1 }
97
+ hif((vcount >= vSIZE + vSTART) | (vcount < vSTART)) { vblank <= 1 }
98
+ hif((hcount < hSIZE+hSTART) & (vcount < vSIZE+vSTART) & (vcount >= vSTART)) { br <= 1 } #; rwb <= 1 }
99
+ helse { br <= 0} #; rwb <= 0 }
100
+ hif((hcount >= hSTART) & (hcount < hSIZE+hSTART) &
101
+ (vcount >= vSTART) & (vcount < vSIZE+vSTART)) do
102
+ hblank <= 0; vblank <= 0
103
+ hif(bg) { pixel <= dout }
104
+ vaddr <= vaddr + 1
105
+ end
106
+ hcount <= hcount + 1
107
+ hif(hcount >= hSIZE+hSTART+hEND) do
108
+ hcount <= 0
109
+ vcount <= vcount + 1
110
+ hif (vcount >= vSIZE+vSTART+vEND) do
111
+ vcount <= 0
112
+ vaddr <= vADDR
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ # Connect to the memory as well as the keyboard register.
119
+ rwb <= mux(bg, _b0, _b1)
120
+ # addr <= mux(bg, kADDR, vaddr)
121
+ addr <= mux(bg, _hzz, vaddr)
122
+
123
+ # # Connect the key register.
124
+ # din <= mux(~bg, _hzz, key_reg)
125
+
126
+ # This is the monitor simulator.
127
+ program(:ruby,:monitor) do
128
+ actport vclk.negedge
129
+ inport vblank: vblank, hblank: hblank, pixel: pixel
130
+ code "ruby_program/sw_cpu_terminal.rb"
131
+ end
132
+
133
+
134
+ ## Simplisitic circuitry that receives bytes from a UART and write them
135
+ # into a memory-map register before raising an interrupt.
136
+ # Only 8-bit values, and no parity.
137
+
138
+ # The clock signal generation of the keyboard device
139
+ [2].inner :uclk_count
140
+ inner :uclk, :urst
141
+
142
+ # Generate the UART chip clock: every 8 cycles (for not too long
143
+ # simulation).
144
+ seq(clk.posedge) do
145
+ hif(rst) { uclk_count <= 0; uclk <= 0; urst <= 1 }
146
+ helse do
147
+ uclk_count <= uclk_count + 1
148
+ hif(uclk_count == 1) { uclk <= ~uclk }
149
+ hif(uclk_count == 0) { urst <= 0 }
150
+ end
151
+ end
152
+
153
+ # The UART signals.
154
+ inner :rx
155
+
156
+ # This is the UART keyboard simulator.
157
+ program(:ruby,:keyboard) do
158
+ actport uclk.negedge
159
+ outport rx: rx
160
+ code "ruby_program/sw_cpu_terminal.rb"
161
+ end
162
+
163
+ # The signals for getting key values from UART
164
+ [2].inner :rx_bit_count # The received bit count.
165
+ [8].inner :rx_bits # The rx bit buffer (a shift register).
166
+
167
+ # The sequencer receiving the keyboard data and writing the to a
168
+ # memory-mapped register.
169
+ sequencer(uclk.posedge,urst) do
170
+ sloop do
171
+ # At first no interrupt and nothing received yet.
172
+ req <= 0
173
+ rx_bit_count <= 0
174
+ rx_bits <= 0
175
+ key_reg <= 0
176
+
177
+ # Wait for a start bit: falling edge of rx.
178
+ swhile(rx != 0)
179
+ # Now can get the 8 bits.
180
+ 8.stimes do
181
+ # Wait one Rx cycle.
182
+ rxCYCLE.stimes;
183
+ # Get one bit.
184
+ rx_bits <= [rx_bits[6..0],rx]
185
+ end
186
+ # All is done, wait end of transmission.
187
+ swhile(rx == 0)
188
+ # Save the received value.
189
+ key_reg <= rx_bits
190
+ # And wait the computer is ready to receive an interrupt
191
+ # and the BUS is not used by the video chip.
192
+ swhile((ack == 1) | (rwb == 1) )
193
+ # Now raise an interrupt.
194
+ req <= 1
195
+ # Wait for its process to start.
196
+ swhile(ack != 0)
197
+ end
198
+ end
199
+
200
+
201
+
202
+
203
+ ## The simulation part.
204
+
205
+ timed do
206
+ clk <= 0
207
+ rst <= 0
208
+ sim <= 0
209
+ !10.ns
210
+ sim <= 1
211
+ !10.ns
212
+ sim <= 0
213
+ repeat(5) do
214
+ !10.ns
215
+ clk <= 1
216
+ !10.ns
217
+ clk <= 0
218
+ end
219
+ rst <= 1
220
+ repeat(5) do
221
+ !10.ns
222
+ clk <= 1
223
+ !10.ns
224
+ clk <= 0
225
+ end
226
+ rst <= 0
227
+ repeat(10_000_000) do
228
+ !10.ns
229
+ clk <= 1
230
+ !10.ns
231
+ clk <= 0
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,23 @@
1
+ system :accum do
2
+ inner :clk
3
+ [32].inner :sigI, :sigO
4
+
5
+ program(:ruby,:stdrw) do
6
+ actport clk.posedge
7
+ outport sigI: sigI
8
+ inport sigO: sigO
9
+ code "ruby_program/stdrw.rb"
10
+ end
11
+
12
+ (sigO <= sigO+sigI).at(clk.negedge)
13
+
14
+ timed do
15
+ clk <= 0
16
+ sigO <= 0
17
+ sigI <= 0
18
+ repeat(10) do
19
+ !10.ns
20
+ clk <= ~clk
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,58 @@
1
+
2
+ # A benchmark for testing the use of Ruby software code.
3
+ system :with_ruby_prog_mem do
4
+ inner :clk, :req, :rwb
5
+ [8].inner :addr, :index, :count, :data
6
+
7
+ # This is actually a CPU embedded memory.
8
+ program(:ruby,:mem) do
9
+ actport clk.posedge
10
+ inport addr: addr
11
+ inport rwb: rwb
12
+ inport din: count
13
+ outport dout: data
14
+ code "ruby_program/sw_inc_mem.rb"
15
+ end
16
+
17
+ # This is real software.
18
+ program(:ruby,:inc_mem) do
19
+ actport req.posedge
20
+ inport index: index
21
+ code "ruby_program/sw_inc_mem.rb"
22
+ end
23
+
24
+
25
+ timed do
26
+ clk <= 0
27
+ addr <= 0
28
+ index <= 0
29
+ req <= 0
30
+ count <= 0
31
+ rwb <= 0
32
+ !10.ns
33
+ req <= 1
34
+ !10.ns
35
+ repeat(10) do
36
+ clk <= 1
37
+ req <= 0
38
+ !10.ns
39
+ req <= 1
40
+ clk <= 0
41
+ count <= count + 2
42
+ addr <= addr + 1
43
+ !10.ns
44
+ index <= index + 1
45
+ end
46
+ !10.ns
47
+ addr <= 0
48
+ clk <= 0
49
+ rwb <= 1
50
+ repeat(10) do
51
+ !10.ns
52
+ clk <= 1
53
+ !10.ns
54
+ clk <= 0
55
+ addr <= addr + 1
56
+ end
57
+ end
58
+ end