OpenCores
URL https://opencores.org/ocsvn/soc_maker/soc_maker/trunk

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [core_def.rb] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      core_def.rb
4
#
5
#  Author:    Christian Hättich
6
#
7
#  Project:   System-On-Chip Maker
8
#
9
#  Target:    Linux / Windows / Mac
10
#
11
#  Language:  ruby
12
#
13
#
14
###############################################################
15
#
16
#
17
#   Copyright (C) 2014  Christian Hättich  - feddischson [ at ] opencores.org
18
#
19
#   This program is free software: you can redistribute it and/or modify
20
#   it under the terms of the GNU General Public License as published by
21
#   the Free Software Foundation, either version 3 of the License, or
22
#   (at your option) any later version.
23
#
24
#   This program is distributed in the hope that it will be useful,
25
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
26
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27
#   GNU General Public License for more details.
28
#
29
#   You should have received a copy of the GNU General Public License
30
#   along with this program.  If not, see .
31
#
32
#
33
###############################################################
34
#
35
#   Description:
36
#     This class represents a core definition.
37
#     It is one of the central classes and holds data,
38
#     which is used to describe and instanciate this core.
39
#     In general, instances of this class desribe a core,
40
#     it's interface and parameters as well as the files,
41
#     which are required for synthesis/simulation.
42
#
43
#     In addition to this core, there exist CoreInst,
44
#     which represents a concret instanciation of a definition
45
#     (see core_inst.rb).
46
#     This class adds two fields to SOCMaker::Component:
47
#         - hdlfiles           : hash of SOCMaker::HDLFile (mandatory,
48
#                                at least one file)
49
 
50
########
51
#
52
# TODO
53
#
54
#
55
###############################################################
56
 
57
 
58
module SOCMaker
59
class CoreDef  < Component
60
  include ERR
61
  include YAML_EXT
62
 
63
  attr_accessor :hdlfiles
64
  def initialize( name, version, hdl_files, toplevel, options = {} )
65
    init_with( { 'name'      => name,
66
                 'version'   => version,
67
                 'hdlfiles'  => hdl_files,
68
                 'toplevel'  => toplevel }.merge( options ) )
69
  end
70
  def encode_with( coder )
71
    super coder
72
    coder[ 'hdlfiles' ] = @hdlfiles
73
  end
74
  def init_with( coder )
75
    super( coder )
76
 
77
    serr_if( coder[ 'hdlfiles' ] == nil,
78
      'No hdlfiles field found',
79
      instance: @name,
80
      fiel:     'hdlfiles' )
81
    @hdlfiles = coder[ 'hdlfiles' ]
82
    serr_if( !@hdlfiles.is_a?( Hash ),
83
      'HDL file def. != Hash',
84
      instance: @name,
85
      field:    'hdlfiles' )
86
    serr_if( @hdlfiles.size  == 0,
87
      'No HDL files are given',
88
      instance: @name,
89
      field:    'hdlfiles' )
90
 
91
    @hdlfiles.each do |file_name, defn |
92
      serr_if( defn == nil,
93
            'HDL file not defined',
94
            instance:   @name+":"+file_name.to_s )
95
 
96
      serr_if( !defn.is_a?( SOCMaker::HDLFile ),
97
            'HDL file not SOCMaker::HDLFile (use SOCM_HDL_FILE)',
98
            instance: @name+":"+file_name.to_s )
99
    end
100
 
101
  end
102
 
103
 
104
  def get_files
105
    unless self.vccmd.nil? or self.vccmd == 0
106
      system( self.vccmd )
107
    end
108
  end
109
 
110
 
111
 
112
 
113
  def generics
114
    @inst_parameters.each_with_index do |(name, val), i|
115
      yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
116
    end
117
  end
118
 
119
 
120
  #
121
  # Iterates over interface list.
122
  # For each interface, all ports are processed.
123
  # For each port within each interface, we lookup the port defn
124
  # and yield the call block with
125
  #   - port-name
126
  #   - port-definition
127
  #   - info if last
128
  # as argument
129
  #
130
  #
131
  #
132
  def ports( *args )
133
 
134
 
135
    if args.size == 0
136
      @interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
137
 
138
        # get interface definition
139
        ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
140
 
141
        # loop over ports in this interface
142
        ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
143
 
144
          # the reference to the port in the definition
145
          defn_ref = port_def.defn
146
          port_dir = ifc_def.ports[ defn_ref.to_sym ]
147
          perr_if( port_dir == nil,
148
                "Can't find #{defn_ref} in interface " +
149
                "definition #{ifc_def.name} version "  +
150
                ifc_def.version + "==>>" + ifc_def.to_yaml )
151
 
152
          # An xor mechanism between port_dir and ifc=>dir is used
153
          # to determine the direction of a port, for example:
154
          #  If the interface is declared as input (1) and a port is declared as input (1)
155
          #  the resulting direction will be an output 1^1 = 0.
156
          #  But if the overall interface direction is an output (0) and a port is declared
157
          #  as input, the resulting direction will an input 0^1 = 1.
158
          # This allows to define a port-direction in the interface definition,
159
          # and toggle the directions on core-definition level.
160
 
161
          #  (name, direction, length, is_last)
162
          yield(  port_name.to_s,
163
                  port_dir ^ ifc.dir,
164
                  port_def.len,
165
                  ( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
166
        end
167
      end
168
 
169
#    elsif args.size == 1
170
 
171
#      # get interface (input is the name as string  )
172
#      ifc = @interfaces[ args.first.to_sym  ]
173
 
174
#      ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
175
#      ifc.ports.each do |port_name, port_def; port_dir|
176
#        port_def = port_def.defn
177
#        port_dir = ifc_def.ports[ port_def.to_sym ]
178
#        if port_dir == nil
179
#          perr_if( port_dir==nil,
180
#              "Can't find #{port_def} in" +
181
#              "interface definition #{ifc_def.name} " +
182
#              "version #{ifc_def.version}" )
183
#        end
184
#        yield(  port_def.to_s,
185
#                port_name.to_s,
186
#                port_dir ^ ifc.dir )
187
#     end
188
 
189
    else
190
 
191
    end
192
 
193
  end
194
 
195
 
196
 
197
 
198
  def param_ok?( param_name, param_value )
199
    param = inst_parameters[ param_name.to_sym ]
200
    param = static_parameters[ param_name.to_sym ] if param == nil
201
    return false if param == nil
202
  end
203
 
204
  def verify( is_soc = false )
205
 
206
    # check hdl-files
207
    @hdlfiles.each do |file_name, defn |
208
      defn.verify
209
    end
210
  end
211
 
212
  def ==(o)
213
    o.class         == self.class       &&
214
    o.hdlfiles      == self.hdlfiles    &&
215
    super( o )
216
  end
217
 
218
 
219
end # class CoreDef
220
end # module SOCMaker
221
 
222
 
223
# vim: noai:ts=2:sw=2

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.