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 8

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 7 feddischso
#
50 3 feddischso
########
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 8 feddischso
#  TODO: this was removed because we want to
78
#        support cores, which have a config-file only
79
#        (where config and implementation is in one file)
80
 
81
#   serr_if( coder[ 'hdlfiles' ] == nil,
82
#     'No hdlfiles field found',
83
#     instance: @name,
84
#     fiel:     'hdlfiles' )
85
    @hdlfiles = coder[ 'hdlfiles' ] || {}
86 3 feddischso
    serr_if( !@hdlfiles.is_a?( Hash ),
87
      'HDL file def. != Hash',
88
      instance: @name,
89
      field:    'hdlfiles' )
90 8 feddischso
#   serr_if( @hdlfiles.size  == 0,
91
#     'No HDL files are given',
92
#     instance: @name,
93
#     field:    'hdlfiles' )
94 3 feddischso
 
95
    @hdlfiles.each do |file_name, defn |
96
      serr_if( defn == nil,
97
            'HDL file not defined',
98
            instance:   @name+":"+file_name.to_s )
99
 
100
      serr_if( !defn.is_a?( SOCMaker::HDLFile ),
101
            'HDL file not SOCMaker::HDLFile (use SOCM_HDL_FILE)',
102
            instance: @name+":"+file_name.to_s )
103
    end
104
 
105
  end
106
 
107
 
108
 
109
 
110
 
111
  def generics
112
    @inst_parameters.each_with_index do |(name, val), i|
113
      yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
114
    end
115
  end
116
 
117
 
118
  #
119 8 feddischso
  # TODO  this also exists in component.rb
120
  #       might this be removed?
121
  #       If yes, make sure, that the 'default' stuff
122
  #       is also done in component.rb!!!
123
  #
124 3 feddischso
  # Iterates over interface list.
125
  # For each interface, all ports are processed.
126
  # For each port within each interface, we lookup the port defn
127
  # and yield the call block with
128
  #   - port-name
129
  #   - port-definition
130
  #   - info if last
131
  # as argument
132
  #
133
  #
134
  #
135 8 feddischso
  #def ports( *args )
136 3 feddischso
 
137
 
138 8 feddischso
    #if args.size == 0
139
      #@interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
140 3 feddischso
 
141 8 feddischso
        ## get interface definition
142
        #ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
143 3 feddischso
 
144 8 feddischso
        ## loop over ports in this interface
145
        #ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
146 3 feddischso
 
147 8 feddischso
          ## the reference to the port in the definition
148
          #defn_ref      = port_def.defn
149
          #port_dir      = ifc_def.ports[ defn_ref.to_sym ][ :dir      ]
150
          #port_default  = ifc_def.ports[ defn_ref.to_sym ][ :default  ]
151
          #perr_if( port_dir == nil,
152
                #"Can't find #{defn_ref} in interface " +
153
                #"definition #{ifc_def.name} version "  +
154
                #ifc_def.version + "==>>" + ifc_def.to_yaml )
155 3 feddischso
 
156 8 feddischso
          ## An xor mechanism between port_dir and ifc=>dir is used
157
          ## to determine the direction of a port, for example:
158
          ##  If the interface is declared as input (1) and a port is declared as input (1)
159
          ##  the resulting direction will be an output 1^1 = 0.
160
          ##  But if the overall interface direction is an output (0) and a port is declared
161
          ##  as input, the resulting direction will an input 0^1 = 1.
162
          ## This allows to define a port-direction in the interface definition,
163
          ## and toggle the directions on core-definition level.
164 3 feddischso
 
165 8 feddischso
          ##  (name, direction, length, is_last)
166
          #yield(  port_name.to_s,
167
                  #port_dir ^ ifc.dir,
168
                  #port_def.len,
169
                  #port_default,
170
                  #( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
171
        #end
172
      #end
173 3 feddischso
 
174 8 feddischso
##    elsif args.size == 1
175 3 feddischso
 
176 8 feddischso
##      # get interface (input is the name as string  )
177
##      ifc = @interfaces[ args.first.to_sym  ]
178 3 feddischso
 
179 8 feddischso
##      ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
180
##      ifc.ports.each do |port_name, port_def; port_dir|
181
##        port_def = port_def.defn
182
##        port_dir = ifc_def.ports[ port_def.to_sym ]
183
##        if port_dir == nil
184
##          perr_if( port_dir==nil,
185
##              "Can't find #{port_def} in" +
186
##              "interface definition #{ifc_def.name} " +
187
##              "version #{ifc_def.version}" )
188
##        end
189
##        yield(  port_def.to_s,
190
##                port_name.to_s,
191
##                port_dir ^ ifc.dir )
192
##     end
193 3 feddischso
 
194 8 feddischso
    #else
195 3 feddischso
 
196 8 feddischso
    #end
197 3 feddischso
 
198 8 feddischso
  #end
199 3 feddischso
 
200
 
201 6 feddischso
  # this is a core_def and doesn't have
202
  # sub-cores
203
  def get_core_def( inst )
204
    return nil
205
  end
206 3 feddischso
 
207 7 feddischso
  def consistency_check
208 8 feddischso
    super
209 7 feddischso
  end
210 6 feddischso
 
211 7 feddischso
 
212 3 feddischso
  def param_ok?( param_name, param_value )
213
    param = inst_parameters[ param_name.to_sym ]
214
    param = static_parameters[ param_name.to_sym ] if param == nil
215
    return false if param == nil
216
  end
217
 
218
 
219
  def ==(o)
220
    o.class         == self.class       &&
221
    o.hdlfiles      == self.hdlfiles    &&
222
    super( o )
223
  end
224
 
225
 
226
end # class CoreDef
227
end # module SOCMaker
228
 
229
 
230
# vim: noai:ts=2:sw=2

powered by: WebSVN 2.1.0

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