class HDLRuby::High::Std::PipelineT

Describes a high-level pipeline type.

Attributes

name[R]

The name of the pipeline type.

namespace[R]

The namespace associated with the pipeline

Public Class Methods

new(name) click to toggle source

Creates a new pipeline type with name.

The proc ruby_block is executed when instantiating the fsm.

# File lib/HDLRuby/std/pipeline.rb, line 77
def initialize(name)
    # Check and set the name
    @name = name.to_sym

    # Initialize the internals of the pipeline.


    # Initialize the environment for building the pipeline

    # The stages
    @stages = []

    # The event synchronizing the pipeline
    @mk_ev = proc { $clk.posedge }

    # The reset
    @mk_rst = proc { $rst }

    # Creates the namespace to execute the pipeline block in.
    @namespace = Namespace.new(self)

    # Generates the function for setting up the pipeline.
    obj = self # For using the right self within the proc
    HDLRuby::High.space_reg(@name) do |&ruby_block|
        if ruby_block then
            # Builds the pipeline.
            obj.build(&ruby_block)
        else
            # Return the pipeline as is.
            return obj
        end
    end

end

Public Instance Methods

build(&ruby_block) click to toggle source

builds the pipeline by executing ruby_block.

# File lib/HDLRuby/std/pipeline.rb, line 113
def build(&ruby_block)
    # Use local variable for accessing the attribute since they will
    # be hidden when opening the sytem.
    name      = @name
    stages    = @stages
    namespace = @namespace
    this      = self
    mk_ev     = @mk_ev
    mk_rst    = @mk_rst
    scope     = HDLRuby::High.cur_system.scope

    return_value = nil

    # Enters the current system
    HDLRuby::High.cur_system.open do
        sub do
            HDLRuby::High.space_push(namespace)
            # Execute the instantiation block
            return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
            HDLRuby::High.space_pop

            # Create the pipeline code.
            
            # Declare and register the pipeline registers generators.
            prs = []
            stages.each do |st|
                st.each do |rn|
                    r = PipeSignal.new(name.to_s+"::"+rn.to_s,scope)
                    prs << r
                    namespace.add_method(rn) { r }
                end
            end

            # Build the pipeline structure.
            return_value = par(mk_ev.call) do
                hif(mk_rst.call == 0) do
                    # No reset, pipeline handling.
                    stages.each do |st|
                        # Generate the code for the stage.
                        HDLRuby::High.space_push(namespace)
                        HDLRuby::High.top_user.instance_exec(&st.code)
                        HDLRuby::High.space_pop
                    end
                end
                helse do
                    prs.each { |r| r <= 0 }
                end
            end
        end
    end

    return return_value
end
for_event(event = nil,&ruby_block) click to toggle source

Sets the event synchronizing the pipeline.

# File lib/HDLRuby/std/pipeline.rb, line 170
def for_event(event = nil,&ruby_block)
    if event then
        # An event is passed as argument, use it.
        @mk_ev = proc { event.to_event }
    else
        # No event given, use the ruby_block as event generator.
        @mk_ev = ruby_block
    end
end
for_reset(reset = nil,&ruby_block) click to toggle source

Sets the reset.

# File lib/HDLRuby/std/pipeline.rb, line 181
def for_reset(reset = nil,&ruby_block)
    if reset then
        # An reset is passed as argument, use it.
        @mk_rst = proc { reset.to_expr }
    else
        # No reset given, use the ruby_block as event generator.
        @mk_rst = ruby_block
    end
end
stage(*regs, &ruby_block) click to toggle source

Declare a new stage synchronized on registers declared in regs and executing ruby_block.

# File lib/HDLRuby/std/pipeline.rb, line 194
def stage(*regs, &ruby_block)
    # Create the resulting state
    result = Stage.new
    # Test and set the registers.
    regs.each do |reg|
        # Ensure it is a symbol.
        reg = reg.to_sym
        # Add it.
        result << reg
    end
    # Sets the generation code.
    result.code = ruby_block
    # Add it to the list of states.
    @stages << result
    # Return it.
    return result
end