Class: RubyHDL::High::SblockTop

Inherits:
Object
  • Object
show all
Defined in:
lib/HDLRuby/std/sequencer_sw.rb

Overview

Describes a SW implementation of the top block. It cannot contain any statement, but can register objects.

Direct Known Subclasses

Sblock

Instance Method Summary collapse

Constructor Details

#initializeSblockTop

Create a new top block.



45
46
47
48
49
50
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 45

def initialize
  # Initialize the table of callable procs from outside.
  @callables = { }
  # Initialize the list of signals declared in this block.
  @signals = []
end

Instance Method Details

#callable(m, *args, &ruby_block) ⇒ Object

Call a method from there.



138
139
140
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 138

def callable(m,*args,&ruby_block)
  return @callables[m].call(*args,&ruby_block)
end

#callable?(m) ⇒ Boolean

Tell if a method is callable from there.

Returns:

  • (Boolean)


133
134
135
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 133

def callable?(m)
  return @callables.key?(m)
end

#each_signal(&ruby_block) ⇒ Object

Iterate on the signal declared in the block.



143
144
145
146
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 143

def each_signal(&ruby_block)
  return to_enum(:each_signal) unless ruby_block
  @signals.each(&ruby_block)
end

#make_inners(type, *names) ⇒ Object

Generate inner signals with type type and names from names list.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 94

def make_inners(type,*names)
  # puts "make_inners with names=#{names.join(",")}"
  type = type.to_type
  last_sig = nil
  names.each do |name|
    init = nil
    if name.is_a?(Hash) then
      init = name.values[0]
      name = name.keys[0]
      # puts "init=#{init}"
    end
    name = name.to_sym
    # Create and add the signal.
    sig = SignalI.new(name,type,:inner)
    @signals << sig
    # Register it.
    # self.register(name) { puts("sig=",sig.inspect); sig }
    self.register(name) { sig }
    last_sig = sig

    # Sets the initial value if any.
    sig.value = init if init
  end
  return last_sig
end

#make_inputs(type, *names) ⇒ Object

Generate input signals with type type and names from names list.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 58

def make_inputs(type,*names)
  # puts "make_inputs with names=#{names.join(",")}"
  type = type.to_type
  last_sig = nil
  names.each do |name|
    name = name.to_sym
    # Create and add the signal.
    sig = SignalI.new(name,type,:input)
    @signals << sig
    # Register it.
    # self.register(name) { puts("sig=",sig.inspect); sig }
    self.register(name) { sig }
    last_sig = sig
  end
  return last_sig
end

#make_outputs(type, *names) ⇒ Object

Generate output signals with type type and names from names list.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 76

def make_outputs(type,*names)
  # puts "make_outputs with names=#{names.join(",")}"
  type = type.to_type
  last_sig = nil
  names.each do |name|
    name = name.to_sym
    # Create and add the signal.
    sig = SignalI.new(name,type,:output)
    @signals << sig
    # Register it.
    # self.register(name) { puts("sig=",sig.inspect); sig }
    self.register(name) { sig }
    last_sig = sig
  end
  return last_sig
end

#register(name, &ruby_block) ⇒ Object

Register a new object named name generated by ruby_block.



121
122
123
124
125
126
127
128
129
130
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 121

def register(name,&ruby_block)
  # Add a way to call it from the stack of SW blocks.
  ::Object.define_method(name) do |*args|
    RubyHDL::High.call_sblock(name,*args)
  end
  # Add a method for accessing the object.
  # self.define_singleton_method(name,&ruby_block)
  # res = ruby_block.call
  @callables[name] = ruby_block
end

#sequencerObject

The sequencer of the block: none since top Sblock for globals.



53
54
55
# File 'lib/HDLRuby/std/sequencer_sw.rb', line 53

def sequencer
  nil
end