###############################################################
|
###############################################################
|
#
|
#
|
# File: core_def.rb
|
# File: core_def.rb
|
#
|
#
|
# Author: Christian Hättich
|
# Author: Christian Hättich
|
#
|
#
|
# Project: System-On-Chip Maker
|
# Project: System-On-Chip Maker
|
#
|
#
|
# Target: Linux / Windows / Mac
|
# Target: Linux / Windows / Mac
|
#
|
#
|
# Language: ruby
|
# Language: ruby
|
#
|
#
|
#
|
#
|
###############################################################
|
###############################################################
|
#
|
#
|
#
|
#
|
# Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
|
# Copyright (C) 2014 Christian Hättich - feddischson [ at ] opencores.org
|
#
|
#
|
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
# the Free Software Foundation, either version 3 of the License, or
|
# the Free Software Foundation, either version 3 of the License, or
|
# (at your option) any later version.
|
# (at your option) any later version.
|
#
|
#
|
# This program is distributed in the hope that it will be useful,
|
# This program is distributed in the hope that it will be useful,
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
#
|
#
|
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
# along with this program. If not, see .
|
# along with this program. If not, see .
|
#
|
#
|
#
|
#
|
###############################################################
|
###############################################################
|
#
|
#
|
# Description:
|
# Description:
|
# This class represents a core definition.
|
# This class represents a core definition.
|
# It is one of the central classes and holds data,
|
# It is one of the central classes and holds data,
|
# which is used to describe and instanciate this core.
|
# which is used to describe and instanciate this core.
|
# In general, instances of this class desribe a core,
|
# In general, instances of this class desribe a core,
|
# it's interface and parameters as well as the files,
|
# it's interface and parameters as well as the files,
|
# which are required for synthesis/simulation.
|
# which are required for synthesis/simulation.
|
#
|
#
|
# In addition to this core, there exist CoreInst,
|
# In addition to this core, there exist CoreInst,
|
# which represents a concret instanciation of a definition
|
# which represents a concret instanciation of a definition
|
# (see core_inst.rb).
|
# (see core_inst.rb).
|
# This class adds two fields to SOCMaker::Component:
|
# This class adds two fields to SOCMaker::Component:
|
# - hdlfiles : hash of SOCMaker::HDLFile (mandatory,
|
# - hdlfiles : hash of SOCMaker::HDLFile (mandatory,
|
# at least one file)
|
# at least one file)
|
|
|
########
|
########
|
#
|
#
|
# TODO
|
# TODO
|
#
|
#
|
#
|
#
|
###############################################################
|
###############################################################
|
|
|
|
|
module SOCMaker
|
module SOCMaker
|
class CoreDef < Component
|
class CoreDef < Component
|
include ERR
|
include ERR
|
include YAML_EXT
|
include YAML_EXT
|
|
|
attr_accessor :hdlfiles
|
attr_accessor :hdlfiles
|
def initialize( name, version, hdl_files, toplevel, options = {} )
|
def initialize( name, version, hdl_files, toplevel, options = {} )
|
init_with( { 'name' => name,
|
init_with( { 'name' => name,
|
'version' => version,
|
'version' => version,
|
'hdlfiles' => hdl_files,
|
'hdlfiles' => hdl_files,
|
'toplevel' => toplevel }.merge( options ) )
|
'toplevel' => toplevel }.merge( options ) )
|
end
|
end
|
def encode_with( coder )
|
def encode_with( coder )
|
super coder
|
super coder
|
coder[ 'hdlfiles' ] = @hdlfiles
|
coder[ 'hdlfiles' ] = @hdlfiles
|
end
|
end
|
def init_with( coder )
|
def init_with( coder )
|
super( coder )
|
super( coder )
|
|
|
serr_if( coder[ 'hdlfiles' ] == nil,
|
serr_if( coder[ 'hdlfiles' ] == nil,
|
'No hdlfiles field found',
|
'No hdlfiles field found',
|
instance: @name,
|
instance: @name,
|
fiel: 'hdlfiles' )
|
fiel: 'hdlfiles' )
|
@hdlfiles = coder[ 'hdlfiles' ]
|
@hdlfiles = coder[ 'hdlfiles' ]
|
serr_if( !@hdlfiles.is_a?( Hash ),
|
serr_if( !@hdlfiles.is_a?( Hash ),
|
'HDL file def. != Hash',
|
'HDL file def. != Hash',
|
instance: @name,
|
instance: @name,
|
field: 'hdlfiles' )
|
field: 'hdlfiles' )
|
serr_if( @hdlfiles.size == 0,
|
serr_if( @hdlfiles.size == 0,
|
'No HDL files are given',
|
'No HDL files are given',
|
instance: @name,
|
instance: @name,
|
field: 'hdlfiles' )
|
field: 'hdlfiles' )
|
|
|
@hdlfiles.each do |file_name, defn |
|
@hdlfiles.each do |file_name, defn |
|
serr_if( defn == nil,
|
serr_if( defn == nil,
|
'HDL file not defined',
|
'HDL file not defined',
|
instance: @name+":"+file_name.to_s )
|
instance: @name+":"+file_name.to_s )
|
|
|
serr_if( !defn.is_a?( SOCMaker::HDLFile ),
|
serr_if( !defn.is_a?( SOCMaker::HDLFile ),
|
'HDL file not SOCMaker::HDLFile (use SOCM_HDL_FILE)',
|
'HDL file not SOCMaker::HDLFile (use SOCM_HDL_FILE)',
|
instance: @name+":"+file_name.to_s )
|
instance: @name+":"+file_name.to_s )
|
end
|
end
|
|
|
end
|
end
|
|
|
|
|
def get_files
|
# def get_files
|
unless self.vccmd.nil? or self.vccmd == 0
|
# unless self.vccmd.nil? or self.vccmd.size == 0
|
system( self.vccmd )
|
# system( self.vccmd )
|
end
|
# end
|
end
|
# end
|
|
|
|
|
|
|
|
|
def generics
|
def generics
|
@inst_parameters.each_with_index do |(name, val), i|
|
@inst_parameters.each_with_index do |(name, val), i|
|
yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
|
yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
|
end
|
end
|
end
|
end
|
|
|
|
|
#
|
#
|
# Iterates over interface list.
|
# Iterates over interface list.
|
# For each interface, all ports are processed.
|
# For each interface, all ports are processed.
|
# For each port within each interface, we lookup the port defn
|
# For each port within each interface, we lookup the port defn
|
# and yield the call block with
|
# and yield the call block with
|
# - port-name
|
# - port-name
|
# - port-definition
|
# - port-definition
|
# - info if last
|
# - info if last
|
# as argument
|
# as argument
|
#
|
#
|
#
|
#
|
#
|
#
|
def ports( *args )
|
def ports( *args )
|
|
|
|
|
if args.size == 0
|
if args.size == 0
|
@interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
|
@interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
|
|
|
# get interface definition
|
# get interface definition
|
ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
|
ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
|
|
|
# loop over ports in this interface
|
# loop over ports in this interface
|
ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
|
ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
|
|
|
# the reference to the port in the definition
|
# the reference to the port in the definition
|
defn_ref = port_def.defn
|
defn_ref = port_def.defn
|
port_dir = ifc_def.ports[ defn_ref.to_sym ]
|
port_dir = ifc_def.ports[ defn_ref.to_sym ]
|
perr_if( port_dir == nil,
|
perr_if( port_dir == nil,
|
"Can't find #{defn_ref} in interface " +
|
"Can't find #{defn_ref} in interface " +
|
"definition #{ifc_def.name} version " +
|
"definition #{ifc_def.name} version " +
|
ifc_def.version + "==>>" + ifc_def.to_yaml )
|
ifc_def.version + "==>>" + ifc_def.to_yaml )
|
|
|
# An xor mechanism between port_dir and ifc=>dir is used
|
# An xor mechanism between port_dir and ifc=>dir is used
|
# to determine the direction of a port, for example:
|
# to determine the direction of a port, for example:
|
# If the interface is declared as input (1) and a port is declared as input (1)
|
# If the interface is declared as input (1) and a port is declared as input (1)
|
# the resulting direction will be an output 1^1 = 0.
|
# the resulting direction will be an output 1^1 = 0.
|
# But if the overall interface direction is an output (0) and a port is declared
|
# But if the overall interface direction is an output (0) and a port is declared
|
# as input, the resulting direction will an input 0^1 = 1.
|
# as input, the resulting direction will an input 0^1 = 1.
|
# This allows to define a port-direction in the interface definition,
|
# This allows to define a port-direction in the interface definition,
|
# and toggle the directions on core-definition level.
|
# and toggle the directions on core-definition level.
|
|
|
# (name, direction, length, is_last)
|
# (name, direction, length, is_last)
|
yield( port_name.to_s,
|
yield( port_name.to_s,
|
port_dir ^ ifc.dir,
|
port_dir ^ ifc.dir,
|
port_def.len,
|
port_def.len,
|
( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
|
( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
|
end
|
end
|
end
|
end
|
|
|
# elsif args.size == 1
|
# elsif args.size == 1
|
|
|
# # get interface (input is the name as string )
|
# # get interface (input is the name as string )
|
# ifc = @interfaces[ args.first.to_sym ]
|
# ifc = @interfaces[ args.first.to_sym ]
|
|
|
# ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
|
# ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
|
# ifc.ports.each do |port_name, port_def; port_dir|
|
# ifc.ports.each do |port_name, port_def; port_dir|
|
# port_def = port_def.defn
|
# port_def = port_def.defn
|
# port_dir = ifc_def.ports[ port_def.to_sym ]
|
# port_dir = ifc_def.ports[ port_def.to_sym ]
|
# if port_dir == nil
|
# if port_dir == nil
|
# perr_if( port_dir==nil,
|
# perr_if( port_dir==nil,
|
# "Can't find #{port_def} in" +
|
# "Can't find #{port_def} in" +
|
# "interface definition #{ifc_def.name} " +
|
# "interface definition #{ifc_def.name} " +
|
# "version #{ifc_def.version}" )
|
# "version #{ifc_def.version}" )
|
# end
|
# end
|
# yield( port_def.to_s,
|
# yield( port_def.to_s,
|
# port_name.to_s,
|
# port_name.to_s,
|
# port_dir ^ ifc.dir )
|
# port_dir ^ ifc.dir )
|
# end
|
# end
|
|
|
else
|
else
|
|
|
end
|
end
|
|
|
end
|
end
|
|
|
|
|
|
|
|
|
def param_ok?( param_name, param_value )
|
def param_ok?( param_name, param_value )
|
param = inst_parameters[ param_name.to_sym ]
|
param = inst_parameters[ param_name.to_sym ]
|
param = static_parameters[ param_name.to_sym ] if param == nil
|
param = static_parameters[ param_name.to_sym ] if param == nil
|
return false if param == nil
|
return false if param == nil
|
end
|
end
|
|
|
def verify( is_soc = false )
|
def verify( is_soc = false )
|
|
|
# check hdl-files
|
# check hdl-files
|
@hdlfiles.each do |file_name, defn |
|
@hdlfiles.each do |file_name, defn |
|
defn.verify
|
defn.verify
|
end
|
end
|
end
|
end
|
|
|
def ==(o)
|
def ==(o)
|
o.class == self.class &&
|
o.class == self.class &&
|
o.hdlfiles == self.hdlfiles &&
|
o.hdlfiles == self.hdlfiles &&
|
super( o )
|
super( o )
|
end
|
end
|
|
|
|
|
end # class CoreDef
|
end # class CoreDef
|
end # module SOCMaker
|
end # module SOCMaker
|
|
|
|
|
# vim: noai:ts=2:sw=2
|
# vim: noai:ts=2:sw=2
|
|
|