Class: Handshaker
- Inherits:
-
Object
- Object
- Handshaker
- Defined in:
- lib/HDLRuby/hdr_samples/with_class.rb
Instance Method Summary collapse
-
#get_port ⇒ Object
(also: #to_a)
Gets the port of the handshaker as a list of signals.
-
#initialize(type) ⇒ Handshaker
constructor
Create a new handshaker for transmitting +type+ data.
-
#input ⇒ Object
Declares the signals used for input from the handshaker and do the connections of the upper SystemI.
-
#output ⇒ Object
Declares the signals used for output to the handshaker and do the connections of the upper SystemI.
-
#read(target, &blk) ⇒ Object
Generates a blocking read.
-
#reset ⇒ Object
Generate the reset of the handshaker.
-
#write(target, &blk) ⇒ Object
Generates a blocking write.
Constructor Details
#initialize(type) ⇒ Handshaker
Create a new handshaker for transmitting +type+ data.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 8 def initialize(type) # Sets the date type. type = type.to_type @type = type buffer = read_valid = read_ready = write_valid = write_ready = nil HDLRuby::High.cur_system.open do # Declares the registers used for the handshake # The data buffer. buffer = type.inner(HDLRuby.uniq_name) # Declares the handshake control singals. read_valid = inner(HDLRuby.uniq_name) read_ready = inner(HDLRuby.uniq_name) write_valid = inner(HDLRuby.uniq_name) write_ready = inner(HDLRuby.uniq_name) end @buffer = buffer @read_valid = read_valid @read_ready = read_ready @write_valid = write_valid @write_ready = write_ready # puts "@buffer=#{@buffer}" # puts "@read_valid=#{@read_valid}" end |
Instance Method Details
#get_port ⇒ Object Also known as: to_a
Gets the port of the handshaker as a list of signals.
98 99 100 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 98 def get_port return [@buffer,@read_valid,@read_ready,@write_valid,@write_ready] end |
#input ⇒ Object
Declares the signals used for input from the handshaker and do the connections of the upper SystemI
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 50 def input ibuffer = iread_valid = iread_ready = iwrite_valid = iwrite_ready =nil type = @type buffer = @buffer read_valid = @read_valid read_ready = @read_ready write_valid = @write_valid write_ready = @write_ready HDLRuby::High.cur_system.open do # Declares the input signals ibuffer = type.input(HDLRuby.uniq_name) iread_valid = input(HDLRuby.uniq_name) iread_ready = input(HDLRuby.uniq_name) iwrite_valid = output(HDLRuby.uniq_name) iwrite_ready = output(HDLRuby.uniq_name) end @ibuffer = ibuffer @iread_valid = iread_valid @iread_ready = iread_ready @iwrite_valid = iwrite_valid @iwrite_ready = iwrite_ready end |
#output ⇒ Object
Declares the signals used for output to the handshaker and do the connections of the upper SystemI
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 75 def output obuffer = oread_valid = oread_ready = owrite_valid = owrite_ready =nil type = @type buffer = @buffer read_valid = @read_valid read_ready = @read_ready write_valid = @write_valid write_ready = @write_ready HDLRuby::High.cur_system.open do obuffer = type.output(HDLRuby.uniq_name) oread_valid = output(HDLRuby.uniq_name) oread_ready = output(HDLRuby.uniq_name) owrite_valid = input(HDLRuby.uniq_name) owrite_ready = input(HDLRuby.uniq_name) end @obuffer = obuffer @oread_valid = oread_valid @oread_ready = oread_ready @owrite_valid = owrite_valid @owrite_ready = owrite_ready end |
#read(target, &blk) ⇒ Object
Generates a blocking read.
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 104 def read(target,&blk) ibuffer = @ibuffer iread_valid = @iread_valid iread_ready = @iread_ready iwrite_valid = @iwrite_valid iwrite_ready = @iwrite_ready HDLRuby::High.cur_block.open do hif(iread_valid) do iwrite_valid <= 0 iwrite_ready <= 0 hif(iread_ready) do target <= ibuffer iwrite_valid <= 1 blk.call if blk end end helse do iwrite_ready <= 1 end end end |
#reset ⇒ Object
Generate the reset of the handshaker.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 33 def reset read_valid = @read_valid read_ready = @read_ready write_valid = @write_valid write_ready = @write_ready HDLRuby::High.cur_system.open do par do read_valid <= 0 read_ready <= 0 write_valid <= 1 write_ready <= 1 end end end |
#write(target, &blk) ⇒ Object
Generates a blocking write.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/HDLRuby/hdr_samples/with_class.rb', line 127 def write(target,&blk) obuffer = @obuffer oread_valid = @oread_valid oread_ready = @oread_ready owrite_valid = @owrite_valid owrite_ready = @owrite_ready HDLRuby::High.cur_block.open do hif(owrite_valid) do oread_valid <= 0 oread_ready <= 0 hif(owrite_ready) do obuffer <= target oread_valid <= 1 blk.call if blk end end helse do oread_ready <= 1 end end end |