Class: HDLRuby::High::Std::ChannelPortB

Inherits:
ChannelPort show all
Defined in:
lib/HDLRuby/std/channel.rb

Overview

Describes port wrapper (Box) for fixing arugments.

Instance Attribute Summary

Attributes inherited from ChannelPort

#scope

Instance Method Summary collapse

Methods inherited from ChannelPort

#wrap

Constructor Details

#initialize(port, *args) ⇒ ChannelPortB

Creates a new channel box over channel port +port+ fixing +args+ as arguments. +args+ is a list of arguments to apply to all read, write and access procedure, nil values meaning that the corresponding argument is not overwritten. It can also be three lists for seperate read, write and access procedures using named arguments as: read: , write: , access:



274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
# File 'lib/HDLRuby/std/channel.rb', line 274

def initialize(port,*args)
    # Ensure port is a channel port.
    unless port.is_a?(ChannelPortR) || port.is_a?(ChannelPortW) ||
            port.is_a?(ChannelPortA) || port.is_a?(ChannelPortB)
        raise "Invalid class for a channel port: #{port.class}"
    end
    @port = port
    # Process the arguments.
    if args.size == 1 && args[0].is_a?(Hash) then
        # Read, write and access are separated.
        @args_read = args[0][:read]
        @args_write = args[0][:write]
        @args_access = args[0][:access]
    else
        @args_read = args
        @args_write = args.clone
        @args_access = args.clone
    end

    @scope = @port.scope
end

Instance Method Details

#read(*args, &ruby_block) ⇒ Object

Performs a read on the channel using +args+ and +ruby_block+ as arguments.



298
299
300
301
302
303
304
305
306
# File 'lib/HDLRuby/std/channel.rb', line 298

def read(*args,&ruby_block)
    # Generate the final arguments: fills the nil with arguments
    # from args
    rargs = @args_read.clone
    rargs.map! { |arg| arg == nil ? args.shift : arg }
    # And add the remaining at the tail.
    rargs += args
    @port.read(*rargs,&ruby_block)
end

#reset(*args, &ruby_block) ⇒ Object

Performs a reset on the channel using +args+ and +ruby_block+ as arguments.



322
323
324
# File 'lib/HDLRuby/std/channel.rb', line 322

def reset(*args,&ruby_block)
    @port.reset(*@args,*args)
end

#write(*args, &ruby_block) ⇒ Object

Performs a write on the channel using +args+ and +ruby_block+ as arguments.



310
311
312
313
314
315
316
317
318
# File 'lib/HDLRuby/std/channel.rb', line 310

def write(*args,&ruby_block)
    # Generate the final arguments: fills the nil with arguments
    # from args
    rargs = @args_write.clone
    rargs.map! { |arg| arg == nil ? args.shift : arg }
    # And add the remaining at the tail.
    rargs += args
    @port.write(*rargs,&ruby_block)
end