Class: CPU
- Inherits:
-
Object
- Object
- CPU
- Defined in:
- lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb,
lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb
Overview
A generic CPU description
Instance Attribute Summary collapse
-
#abus ⇒ Object
readonly
The address bus.
-
#ack ⇒ Object
readonly
The acknowledge.
-
#allocator ⇒ Object
readonly
Allocator assotiated with the bus of the CPU.
-
#clk ⇒ Object
readonly
The clock.
-
#dbus ⇒ Object
readonly
The data bus.
-
#req ⇒ Object
readonly
The request.
-
#rst ⇒ Object
readonly
The reset.
-
#rwb ⇒ Object
readonly
The read/!write selection.
Instance Method Summary collapse
-
#connect(sig) ⇒ Object
Connect signal +sig+ to the bus allocating an address to access it.
-
#controller ⇒ Object
Generates the bus controller.
-
#initialize(dwidth, awidth, clk, rst) ⇒ CPU
constructor
Creates a new generic CPU whose data bus is +dwidth+ bit wide, address bus is +awidth+ bit wide, clock is +clk+, reset +rst+.
-
#read(sig, &ruby_block) ⇒ Object
Generates a read of sig executing +ruby_block+ on the result.
-
#write(val, sig, &ruby_block) ⇒ Object
Generates a write +val+ to +sig+ executing +ruby_block+ in case of success.
Constructor Details
#initialize(dwidth, awidth, clk, rst) ⇒ CPU
Creates a new generic CPU whose data bus is +dwidth+ bit wide, address bus is +awidth+ bit wide, clock is +clk+, reset +rst+.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 30 def initialize(dwidth,awidth,clk,rst) # Check and set the word and address bus widths awidth = awidth.to_i dwidth = dwidth.to_i @awidth = awidth @dwidth = dwidth # Check and set the signals. @clk = clk.to_ref @rst = rst.to_ref # The allocator of the CPU @allocator = Allocator.new(0..(2**@addr),@data) # Declare the address and data buses and the # rwb/req/ack control signals abus,dbus = nil,nil rwb,req,ack = nil,nil,nil # Declares the data and address bus. HDLRuby::High.cur_system.open do abus = [awidth].input(HDLRuby.uniq_name) dbus = [dwidth].input(HDLRuby.uniq_name) rwb = input(HDLRuby.uniq_name) req = input(HDLRuby.uniq_name) ack = output(HDLRuby.uniq_name) end @abus,@dbus = abus,dbus @rwb,@req,@ack = rwb,req,ack end |
Instance Attribute Details
#abus ⇒ Object (readonly)
The address bus
18 19 20 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 18 def abus @abus end |
#ack ⇒ Object (readonly)
The acknowledge
26 27 28 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 26 def ack @ack end |
#allocator ⇒ Object (readonly)
Allocator assotiated with the bus of the CPU
10 11 12 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 10 def allocator @allocator end |
#clk ⇒ Object (readonly)
The clock.
13 14 15 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 13 def clk @clk end |
#dbus ⇒ Object (readonly)
The data bus
20 21 22 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 20 def dbus @dbus end |
#req ⇒ Object (readonly)
The request
24 25 26 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 24 def req @req end |
#rst ⇒ Object (readonly)
The reset.
15 16 17 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 15 def rst @rst end |
#rwb ⇒ Object (readonly)
The read/!write selection
22 23 24 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 22 def rwb @rwb end |
Instance Method Details
#connect(sig) ⇒ Object
Connect signal +sig+ to the bus allocating an address to access it.
59 60 61 62 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 59 def connect(sig) # Allocates the signal in the address space. @allocator.allocate(sig) end |
#controller ⇒ Object
Generates the bus controller.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 65 def controller clk,rst,req,ack = @clk,@rst,@req,@ack abus,dbus,rwb = @abus,@dbus,@rwb allocator = @allocator HDLRuby::High.cur_system.open do par(clk) do # Bus controller hcase(abus) hif(req) do ack <= 1 allocator.each do |sig,addr| hwhen(addr) do hif(rwb) { dbus <= sig } helse { sig <= dbus } end end end helse do ack <= 0 end end end ## Generates a read of sig executing +ruby_block+ on the result. def read(sig,&ruby_block) addr = @allocator.get(sig) hif(ack == 0) do @abus <= addr @rwb <= 1 @req <= 1 helse @req <= 0 ruby_block.call(@dbus) end end ## Generates a write +val+ to +sig+ executing +ruby_block+ # in case of success. def write(val,sig,&ruby_block) addr = @allocator.get(sig) hif(ack == 0) do @abus <= addr @dbus <= val @rwb <= 0 @req <= 1 helse @req <= 0 ruby_block.call end end end |
#read(sig, &ruby_block) ⇒ Object
Generates a read of sig executing +ruby_block+ on the result.
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 89 def read(sig,&ruby_block) addr = @allocator.get(sig) hif(ack == 0) do @abus <= addr @rwb <= 1 @req <= 1 helse @req <= 0 ruby_block.call(@dbus) end end |
#write(val, sig, &ruby_block) ⇒ Object
Generates a write +val+ to +sig+ executing +ruby_block+ in case of success.
103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb', line 103 def write(val,sig,&ruby_block) addr = @allocator.get(sig) hif(ack == 0) do @abus <= addr @dbus <= val @rwb <= 0 @req <= 1 helse @req <= 0 ruby_block.call end end |