class Zemu::Config::IOPort
Input/Output Port object
Represents an input/output device assigned to one or more ports.
This is an abstract class and cannot be instantiated directly. The when_setup
, when_read
, and when_write
methods can be used to define the behaviour of a subclass.
@example
class MyIODevice < IOPort # Extend the parameters of the object so we can define a port. def params super + "port" end def initialize super # Define the setup for the IO device. # This is some global C code that ends up in "io.c". # Parameters can be used here, as the block is instance-evaluated. when_setup do %Q(zuint8 #{name}_value = 42;) end # Define the logic when reading from an IO port. # The C variable "port" takes the value of the 8-bit port # address being read from, and should be used to identify # if this IO device is the one being used. when_read do %Q(if (port == #{port}) return #{name}_value;) end # Define the logic when writing to the IO port. # Similar to #when_read, but we have access to an extra # C variable, "value". This is the value being written # to the IO port. when_write do %Q(if (port == #{port}) #{name}_value = value;) end end end # The subclass can now be declared as below: device = MyIODevice.new do name "myDevice" port 11 end
Attributes
Public Class Methods
Constructor.
Do not use, as this is an abstract class. Use one of the subclasses instead.
Zemu::ConfigObject::new
# File lib/zemu/config.rb, line 225 def initialize if self.class == Zemu::Config::IOPort raise NotImplementedError, "Cannot construct an instance of the abstract class Zemu::Config::IOPort." end @ports = [] @setup_block = nil @read_block = nil @write_block = nil @clock_block = nil super end
Public Instance Methods
Evaluates the when_clock
block of this IO device and returns the resulting string.
# File lib/zemu/config.rb, line 308 def clock return instance_eval(&@clock_block) unless @clock_block.nil? return "" end
Defines FFI API which will be available to the instance wrapper if this IO device is used.
# File lib/zemu/config.rb, line 314 def functions [] end
Valid parameters for this object. Should be extended by subclasses but NOT REPLACED.
# File lib/zemu/config.rb, line 320 def params %w(name) end
Evaluates the when_read
block of this IO device and returns the resulting string.
# File lib/zemu/config.rb, line 296 def read return instance_eval(&@read_block) unless @read_block.nil? return "" end
Evaluates the when_setup
block of this IO device and returns the resulting string.
# File lib/zemu/config.rb, line 290 def setup return instance_eval(&@setup_block) unless @setup_block.nil? return "" end
Defines the per-cycle behaviour of this IO device.
Expects a block, the return value of which is a string defining the behaviour of the IO device on each system clock cycle. Care must be taken to ensure that this functionality does not conflict with that of any other IO devices.
The block will be instance-evaluated at build-time, so it is possible to use instance variables of the IO device.
# File lib/zemu/config.rb, line 285 def when_clock(&block) @clock_block = block end
Defines the read behaviour of this IO device.
Expects a block, the return value of which is a string containing the behaviour of this IO device when a value is read from the IO bus. Care must be taken to ensure that this functionality does not conflict with that of any other IO devices.
The block will be instance-evaluated at build-time, so it is possible to use instance variables of the IO device.
# File lib/zemu/config.rb, line 259 def when_read(&block) @read_block = block end
Defines the setup behaviour of this IO device.
Expects a block, the return value of which is a string containing all data and function declarations required by this IO device.
The block will be instance-evaluated at build-time, so it is possible to use instance variables of the IO device.
# File lib/zemu/config.rb, line 246 def when_setup(&block) @setup_block = block end
Defines the write behaviour of this IO device.
Expects a block, the return value of which is a string containing the behaviour of this IO device when a value is written to the IO bus. Care must be taken to ensure that this functionality does not conflict with that of any other IO devices.
The block will be instance-evaluated at build-time, so it is possible to use instance variables of the IO device.
# File lib/zemu/config.rb, line 272 def when_write(&block) @write_block = block end
Evaluates the when_write
block of this IO device and returns the resulting string.
# File lib/zemu/config.rb, line 302 def write return instance_eval(&@write_block) unless @write_block.nil? return "" end