Line 55... |
Line 55... |
attr_accessor :params
|
attr_accessor :params
|
|
|
def initialize( type, params = {} )
|
def initialize( type, params = {} )
|
init_with( 'type' => type,
|
init_with( 'type' => type,
|
'params' => params )
|
'params' => params )
|
verify
|
|
end
|
end
|
def encode_with( coder )
|
def encode_with( coder )
|
%w[ type params ].
|
%w[ type params ].
|
each { |v| coder[ v ] = instance_variable_get "@#{v}" }
|
each { |v| coder[ v ] = instance_variable_get "@#{v}" }
|
end
|
end
|
Line 77... |
Line 77... |
field: 'params' )
|
field: 'params' )
|
|
|
end
|
end
|
|
|
def ports
|
def ports
|
|
puts "HELP" + @defn.name
|
|
p @ports
|
@ports.each_with_index do |(name, port_def), i|
|
@ports.each_with_index do |(name, port_def), i|
|
yield( name.to_s, port_def[ :len ], port_def[ :dir ], i==@ports.size-1 )
|
yield( name.to_s, port_def[ :dir ], port_def[ :len ], i==@ports.size-1 )
|
end
|
end
|
end
|
end
|
|
|
|
|
def generics
|
def generics
|
Line 94... |
Line 96... |
end
|
end
|
end
|
end
|
|
|
|
|
|
|
def get_len( ifc_name, port_spec_name, inst = nil )
|
|
|
|
if inst == nil
|
|
tmp = @defn.interfaces[ ifc_name.to_sym ].
|
|
ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
|
|
keys.first.to_s
|
|
|
|
return tmp.size == 0 ? 0 : @ports[ tmp.to_sym ][ :len ]
|
|
else
|
|
if inst == @name
|
|
return get_len( ifc_name, port_spec_name )
|
|
else
|
|
return @defn.get_len( ifc_name, port_spec_name, inst )
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
|
|
|
|
def implements_port?( ifc_name, port_spec_name )
|
|
@defn.implements_port?( ifc_name, port_spec_name )
|
|
end
|
|
|
|
|
#
|
|
# Get a port, identified by the interface and port name
|
|
#
|
|
# +ifc_name+:: name of the interface
|
|
# +port_spec_name+:: name of the port
|
|
#
|
def get_port( ifc_name, port_spec_name )
|
def get_port( ifc_name, port_spec_name )
|
tmp = @defn.interfaces[ ifc_name.to_sym ].
|
tmp = @defn.interfaces[ ifc_name.to_sym ].
|
ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
|
ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
|
keys.first.to_s
|
keys.first.to_s
|
return [ tmp, @ports[ tmp.to_sym ] ]
|
return [ tmp, @ports[ tmp.to_sym ] ]
|
end
|
end
|
|
|
|
|
|
# TODO do we need this?
|
|
# def implements_port?( ifc_name, port_spec_name )
|
|
# @defn.implements_port?( ifc_name, port_spec_name )
|
|
# end
|
|
|
|
|
def verify
|
def consistency_check
|
|
|
@defn = SOCMaker::lib.get_core( @type )
|
@defn = SOCMaker::lib.get_core( @type )
|
|
|
|
|
# check, if the instance parameters in the core definition
|
# check, if the instance parameters in the core definition
|
Line 147... |
Line 139... |
# auto-complete to default values
|
# auto-complete to default values
|
@params[ param_name ] ||= param.default
|
@params[ param_name ] ||= param.default
|
end
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# @_params ||= {}
|
# @_params ||= {}
|
# if @params != nil
|
# if @params != nil
|
# @params.each do |name, val|
|
# @params.each do |name, val|
|
#
|
#
|
# param_type = defn.inst_parameters[ name ].type
|
# param_type = defn.inst_parameters[ name ].type
|
Line 195... |
Line 180... |
end
|
end
|
|
|
lerr_if( @defn == nil, 'Core not found in lib',
|
lerr_if( @defn == nil, 'Core not found in lib',
|
field: 'cores' )
|
field: 'cores' )
|
|
|
|
|
|
@defn.consistency_check
|
|
|
|
|
end
|
end
|
|
|
|
|
|
|
|
#
|
|
# Returns the length of a port within an interface.
|
|
# If no instance is given, we know that it is
|
|
# a toplevel interface.
|
|
# Otherwise we check for this and we do a recursive call.
|
|
# If this port is within a interface of a core, we
|
|
# pass the call to the core-definition of this instance, which
|
|
# knows all cores.
|
|
#
|
|
# +ifc_name+:: name of the interface
|
|
# +port_spec_name+:: name of the port
|
|
# +inst+:: name of the instance (optional), default is nil
|
|
#
|
|
def get_port_len( ifc_name, port_spec_name, inst = nil )
|
|
if inst == nil
|
|
tmp = @defn.interfaces[ ifc_name.to_sym ].
|
|
ports.select{ |key,hash| hash.defn == port_spec_name.to_s }.
|
|
keys.first.to_s
|
|
return tmp.size == 0 ? 0 : @ports[ tmp.to_sym ][ :len ]
|
|
else
|
|
if inst == @defn.name.to_sym
|
|
return get_port_len( ifc_name, port_spec_name )
|
|
else
|
|
return @defn.get_port_len( ifc_name, port_spec_name, inst )
|
|
end
|
|
end
|
|
end
|
|
|
|
|
|
#
|
|
# Returns the core definition for an instance (identified by its name)
|
|
#
|
|
# +inst+:: name of the instance
|
|
#
|
def get_core_def( inst )
|
def get_core_def( inst )
|
|
if inst == @defn.name
|
|
return @defn
|
|
else
|
tmp = @defn.get_core_def( inst )
|
tmp = @defn.get_core_def( inst )
|
if tmp != nil
|
perr_if( tmp == nil, "#Processing error: {inst} not found by get_core_def" )
|
return tmp
|
return tmp
|
elsif inst == @name
|
|
return self
|
|
else
|
|
return nil
|
|
end
|
end
|
end
|
end
|
|
|
|
|
|
#
|
|
# Returns a core instance, identified by its name.
|
|
# If it is not a sub-core, we return our self
|
|
#
|
|
# +inst+:: name of the instance
|
|
#
|
|
def get_core_inst( inst )
|
|
if @defn.cores[ inst ] != nil
|
|
return @defn.cores[ inst ]
|
|
else
|
|
return self
|
|
end
|
|
end
|
|
|
|
|
|
#
|
def gen_toplevel( coder = VHDLCoder.new() )
|
# Generate toplevel hdl file for this instance.
|
|
# This assumes, that this instance represents a SOC with
|
|
# further instances.
|
|
#
|
|
#
|
|
# +coder+:: A HDL coder, which is used to create the auto-generated HDL (optional).
|
|
# If no coder is given, a VHDLCoder is used.
|
|
#
|
|
#
|
|
def gen_toplevel( coder = VHDLCoder.new )
|
|
|
|
|
#
|
#
|
# create filename
|
# Get filename
|
#
|
#
|
file_name = @defn.name.dup
|
file_name = coder.filename( @defn.name )
|
if coder.is_a?( VHDLCoder )
|
|
file_name << ".vhd"
|
|
elsif coder.is_a?( VerilogCoder )
|
|
file_name << ".v"
|
|
else
|
|
perr_if( true,
|
|
"No valid coder" )
|
|
end
|
|
|
|
|
|
SOCMaker::logger.proc( "START of creating top-level '" + file_name + "'" )
|
SOCMaker::logger.proc( "START of creating top-level '" + file_name + "'" )
|
|
|
SOCMaker::logger.proc( "verifying first ..." )
|
|
|
|
|
|
# TODO: this is a fix, that the parameters in core_inst.ports are updated.
|
# SOCMaker::logger.proc( "verifying first ..." )
|
# A good approach for verifying, which checks the whole consistency, needs
|
#
|
# to be done
|
# # TODO: this is a fix, that the parameters in core_inst.ports are updated.
|
@defn.cores.each do |inst_name, inst|
|
# # A good approach for verifying, which checks the whole consistency, needs
|
inst.verify
|
# # to be done
|
end
|
# @defn.cores.each do |inst_name, inst|
|
|
# inst.verify
|
|
# end
|
|
|
|
|
#
|
#
|
# Create a unique list of cores and
|
# Create a unique list of cores and
|
# add every core to your implementation.
|
# add for each core a component statement (vhdl only).
|
# Even if there are multiple instances of a core,
|
# Even if there are multiple instances of a core,
|
# we need to decalre it only once
|
# we need to decalre it only once
|
#
|
#
|
@defn.cores.values.uniq{|x| x.type }.each do |inst; spec|
|
@defn.cores.values.uniq{|x| x.type }.each do |inst; spec|
|
|
|
spec = SOCMaker::lib.get_core( inst.type )
|
spec = SOCMaker::lib.get_core( inst.type )
|
SOCMaker::lib.check_nil( spec, "Can't find #{ inst.type } in SOC library" )
|
SOCMaker::lib.check_nil( spec, "Can't find #{ inst.type } in SOC library" )
|
|
|
coder.add_core_declaration( inst.type, spec )
|
coder.add_core_component( inst.type, spec )
|
end
|
end
|
|
|
#core_instances = {}
|
#
|
#@cores.each do |inst_name, _core_inst|
|
# Instanciate each core
|
# # the corresponding core from SOC lib
|
#
|
# core_def = SOCMaker::lib.get_core( _core_inst[ :type ] )
|
|
# core_instances[ inst_name ] = SOCMaker::CoreInst.new( core_def, _core_inst[ :params ] )
|
|
#end
|
|
|
|
|
|
@defn.cores.each do |inst_name, inst|
|
@defn.cores.each do |inst_name, inst|
|
coder.add_core_inst( inst_name.to_s, inst )
|
coder.add_core_instance( inst_name.to_s, inst )
|
end
|
end
|
|
|
|
|
|
|
# Iterate over all connections:
|
# Iterate over all connections:
|
Line 285... |
Line 316... |
con_def[ :mapping ][1],
|
con_def[ :mapping ][1],
|
coder )
|
coder )
|
|
|
end
|
end
|
|
|
SOCMaker::logger.proc( "writing top-level" )
|
|
|
|
|
#
|
|
# Write content to the file
|
|
#
|
|
SOCMaker::logger.proc( "writing top-level" )
|
file_dir = File.join( SOCMaker::conf[ :build_dir ],
|
file_dir = File.join( SOCMaker::conf[ :build_dir ],
|
SOCMaker::conf[ :hdl_dir ] )
|
SOCMaker::conf[ :hdl_dir ] )
|
::FileUtils.mkdir_p file_dir
|
::FileUtils.mkdir_p file_dir
|
file_path = File.join( file_dir, file_name )
|
File.open( File.join( file_dir, file_name ), 'w' ) do |f|
|
File.open( file_path, 'w' ) do |f|
|
f.write( coder.get_hdl_code( self, @defn.name ) )
|
f.write( coder.get_entity( self, "test" ) )
|
|
end
|
end
|
SOCMaker::logger.proc( "END of creating top-level" )
|
SOCMaker::logger.proc( "END of creating top-level hdl code for #{@defn.name}" )
|
|
|
end
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
# This function is called during the toplevel generation
|
|
# for each connection.
|
|
#
|
|
# +name+:: The name of the connection
|
|
# +rule+:: The combination rule (obsolete/unused)
|
|
# +src+:: Source hash with instance name as key and interface name as value
|
|
# +dst+:: Destination hash with instance name as key and interface name as value
|
|
# +coder+:: The HDL coder which is used
|
|
#
|
def gen_toplevel_con( name, rule, src, dst, coder )
|
def gen_toplevel_con( name, rule, src, dst, coder )
|
|
|
src_inst = {};
|
src_inst = {};
|
dst_inst = {};
|
dst_inst = {};
|
|
|
# fetch somehow the spec
|
#
|
|
# Get the interface specification by using the 1st source entry
|
|
# and searching for the core-definition.
|
|
#
|
ifc_spec = SOCMaker::lib.get_ifc(
|
ifc_spec = SOCMaker::lib.get_ifc(
|
get_core_def( src.keys.first.to_s ).interfaces[ src.values.first ].name,
|
get_core_def( src.keys.first.to_s ).interfaces[ src.values.first ].name,
|
get_core_def( src.keys.first.to_s ).interfaces[ src.values.first ].version )
|
get_core_def( src.keys.first.to_s ).interfaces[ src.values.first ].version )
|
|
|
#port_used = {};
|
|
length_tmp = {};
|
|
|
|
|
|
ifc_spec.ports.keys.each do |_name|
|
|
# TODO: bis dahin konnte angenommen werden, dass self auch eine Art instanz ist,
|
|
# aber hier geht das nicht mehr, weil get_len nur für CoreInst definiert ist.
|
|
#
|
#
|
|
# Get the maximum required signal length
|
|
#
|
# create a length table
|
# For each signal in the interface specification,
|
#port_used[ _name ] = false
|
# we create a list. The list has an entry for each source
|
#dst.each do |inst_name, ifc_name|
|
# and destination signal, which defines the length.
|
# port_used[ _name ] ||= get_core_def( inst_name ).implements_port?( ifc_name, _name )
|
#
|
#end
|
# In the second step, the maximum in each list is extracted.
|
#src.each do |inst_name, ifc_name|
|
#
|
# port_used[ _name ] ||= get_core_def( inst_name ).implements_port?( ifc_name, _name )
|
length_tmp = {};
|
#end
|
ifc_spec.ports.keys.each do |_name|
|
|
|
|
|
|
|
length_tmp[ _name ] = []
|
length_tmp[ _name ] = []
|
dst.each do |inst_name, ifc_name|
|
dst.each do |inst_name, ifc_name|
|
length_tmp[ _name ] << get_len( ifc_name, _name, inst_name )
|
length_tmp[ _name ] << get_port_len( ifc_name, _name, inst_name )
|
end
|
end
|
src.each do |inst_name, ifc_name|
|
src.each do |inst_name, ifc_name|
|
length_tmp[ _name ] << get_len( ifc_name, _name, inst_name )
|
length_tmp[ _name ] << get_port_len( ifc_name, _name, inst_name )
|
end
|
end
|
|
|
end
|
end
|
|
|
# getting the maximum length for each signal
|
|
max_length = Hash[ length_tmp.map{ |key, arr| [ key, arr.max ] } ]
|
max_length = Hash[ length_tmp.map{ |key, arr| [ key, arr.max ] } ]
|
|
|
|
|
p max_length
|
#
|
coder.ifc_declaration( ifc_spec, name, max_length )
|
# Prepare a hash for all sources and destinations, where
|
|
# the instance name is the key and the core-instance is
|
|
# the value.
|
|
#
|
src.keys.each do |inst_name|
|
src.keys.each do |inst_name|
|
src_inst[ inst_name ] = @defn.cores[ inst_name ]
|
src_inst[ inst_name ] = get_core_inst( inst_name )
|
end
|
end
|
dst.keys.each do |inst_name|
|
dst.keys.each do |inst_name|
|
dst_inst[ inst_name ] = @defn.cores[ inst_name ]
|
dst_inst[ inst_name ] = get_core_inst( inst_name )
|
end
|
end
|
|
|
coder.ifc_assignment( ifc_spec, name, max_length, src_inst, dst_inst, src, dst )
|
#
|
|
# create the declaraion and assignments
|
|
#
|
|
coder.add_ifc_connection( ifc_spec, name, max_length, src_inst, dst_inst, src, dst )
|
|
|
end
|
end
|
|
|
|
|
|
#
|
|
# Returns a string describing this instance
|
|
#
|
|
|
|
|
def to_s
|
def to_s
|
"type: #{type}\n" +
|
"type: #{type}\n" +
|
"params: #{params}\n"
|
"params: #{params}\n"
|
end
|
end
|
|
|
|
#
|
|
# Equal operator
|
|
#
|
def ==(o)
|
def ==(o)
|
o.class == self.class &&
|
o.class == self.class &&
|
o.type == self.type &&
|
o.type == self.type &&
|
o.params == self.params
|
o.params == self.params
|
end
|
end
|