Class: HDLRuby::High::Std::SharedSignalI
- Inherits:
-
Object
- Object
- HDLRuby::High::Std::SharedSignalI
- Defined in:
- lib/HDLRuby/std/sequencer_sync.rb
Overview
Describes a signal with shared write.
Instance Method Summary collapse
-
#<=(expr) ⇒ Object
Write access code generation.
-
#add_point ⇒ Object
Adds an access point.
-
#initialize(typ, name, default_value = 0) ⇒ SharedSignalI
constructor
Create a new shared signal of type +typ+.
-
#method_missing(m, *args, &ruby_block) ⇒ Object
For to_expr an all the other methods.
-
#select(arg = nil) ⇒ Object
Selection of the output value code generation.
-
#to_expr ⇒ Object
Read access code generation: actually hidden in the conversion to expression.
Constructor Details
#initialize(typ, name, default_value = 0) ⇒ SharedSignalI
Create a new shared signal of type +typ+. NOTE: for now the arbitration is the priority in order of write access declaration.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 19 def initialize(typ, name, default_value = 0) # Process the arguments. typ = typ.to_type @type = typ name = name.to_sym @name = name @default_value = default_value # Create the name of the access process. @name_sub = HDLRuby.uniq_name(:"#{name}_sub") this = self # Register the shared signal. HDLRuby::High.space_reg(name) { this } # Create the output value and selection of the signal. value_out = nil select = nil HDLRuby::High.cur_system.open do value_out = typ.inner(HDLRuby.uniq_name(:"#{name}_out")) select = [1].inner(HDLRuby.uniq_name(:"#{name}_select") => 0) end @value_out = value_out @select = select # First no access point. @size = 0 # Create the input values. values_in = nil HDLRuby::High.cur_system.open do values_in = typ[-1].inner(HDLRuby.uniq_name(:"#{name}_in")) end @values_in = values_in # The set of access points by sequencer. @points = { } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &ruby_block) ⇒ Object
For to_expr an all the other methods.
117 118 119 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 117 def method_missing(m, *args, &ruby_block) self.to_expr.send(m,*args,&ruby_block) end |
Instance Method Details
#<=(expr) ⇒ Object
Write access code generation.
88 89 90 91 92 93 94 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 88 def <=(expr) # Create a new access point. value_in = self.add_point # Actually implement the access. value_in <= expr.to_expr return self end |
#add_point ⇒ Object
Adds an access point.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 53 def add_point # Maybe a point already exist for current sequencer. sequ = SequencerT.current point = @points[sequ] return @values_in[point] if point # Yes, return it. # No, do create a new one. point = @points[sequ] = @size # Resize the flag and value vectors. @size += 1 size = @size @values_in.type.instance_variable_set(:@range,0..size-1) @select.type.instance_variable_set(:@range,(size-1).width-1..0) # (Re)Generate the access arbitrer. name_sub = @name_sub values_in = @values_in value_out = @value_out select = @select default_value = @default_value # The access arbitrer. HDLRuby::High.cur_system.open do sub(name_sub) do par do hcase(select) size.times do |i| hwhen(i) { value_out <= values_in[i] } end helse { value_out <= default_value } end end end # Return the current access point. return values_in[size-1] end |
#select(arg = nil) ⇒ Object
Selection of the output value code generation. +arg+ can be the index or directly the selected sequencer. If no arg is given, return access to the selection signal direction.
106 107 108 109 110 111 112 113 114 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 106 def select(arg = nil) return @select unless arg if arg.is_a?(SequencerT) then pt = @points[arg] @select <= @points[arg] if pt else @select <= arg end end |
#to_expr ⇒ Object
Read access code generation: actually hidden in the conversion to expression.
98 99 100 101 |
# File 'lib/HDLRuby/std/sequencer_sync.rb', line 98 def to_expr # Return the resulting value. @value_out end |