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 7

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
    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
 
105
 
106
 
107
  def generics
108
    @inst_parameters.each_with_index do |(name, val), i|
109
      yield( name.to_s, val.type, val.default, i == @inst_parameters.size-1 )
110
    end
111
  end
112
 
113
 
114
  #
115
  # Iterates over interface list.
116
  # For each interface, all ports are processed.
117
  # For each port within each interface, we lookup the port defn
118
  # and yield the call block with
119
  #   - port-name
120
  #   - port-definition
121
  #   - info if last
122
  # as argument
123
  #
124
  #
125
  #
126
  def ports( *args )
127
 
128
 
129
    if args.size == 0
130
      @interfaces.values.each_with_index do | ifc, i_ifc; ifc_def|
131
 
132
        # get interface definition
133
        ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
134
 
135
        # loop over ports in this interface
136
        ifc.ports.each_with_index do |(port_name, port_def), i_port; port_dir|
137
 
138
          # the reference to the port in the definition
139
          defn_ref = port_def.defn
140
          port_dir = ifc_def.ports[ defn_ref.to_sym ]
141
          perr_if( port_dir == nil,
142
                "Can't find #{defn_ref} in interface " +
143
                "definition #{ifc_def.name} version "  +
144
                ifc_def.version + "==>>" + ifc_def.to_yaml )
145
 
146
          # An xor mechanism between port_dir and ifc=>dir is used
147
          # to determine the direction of a port, for example:
148
          #  If the interface is declared as input (1) and a port is declared as input (1)
149
          #  the resulting direction will be an output 1^1 = 0.
150
          #  But if the overall interface direction is an output (0) and a port is declared
151
          #  as input, the resulting direction will an input 0^1 = 1.
152
          # This allows to define a port-direction in the interface definition,
153
          # and toggle the directions on core-definition level.
154
 
155
          #  (name, direction, length, is_last)
156
          yield(  port_name.to_s,
157
                  port_dir ^ ifc.dir,
158
                  port_def.len,
159
                  ( (i_port == ifc.ports.size-1 ) and (i_ifc == @interfaces.size-1 ) ) )
160
        end
161
      end
162
 
163
#    elsif args.size == 1
164
 
165
#      # get interface (input is the name as string  )
166
#      ifc = @interfaces[ args.first.to_sym  ]
167
 
168
#      ifc_def = SOCMaker::lib.get_ifc( ifc.name, ifc.version )
169
#      ifc.ports.each do |port_name, port_def; port_dir|
170
#        port_def = port_def.defn
171
#        port_dir = ifc_def.ports[ port_def.to_sym ]
172
#        if port_dir == nil
173
#          perr_if( port_dir==nil,
174
#              "Can't find #{port_def} in" +
175
#              "interface definition #{ifc_def.name} " +
176
#              "version #{ifc_def.version}" )
177
#        end
178
#        yield(  port_def.to_s,
179
#                port_name.to_s,
180
#                port_dir ^ ifc.dir )
181
#     end
182
 
183
    else
184
 
185
    end
186
 
187
  end
188
 
189
 
190 6 feddischso
  # this is a core_def and doesn't have
191
  # sub-cores
192
  def get_core_def( inst )
193
    return nil
194
  end
195 3 feddischso
 
196 7 feddischso
  def consistency_check
197 3 feddischso
 
198 7 feddischso
  end
199 6 feddischso
 
200 7 feddischso
 
201 3 feddischso
  def param_ok?( param_name, param_value )
202
    param = inst_parameters[ param_name.to_sym ]
203
    param = static_parameters[ param_name.to_sym ] if param == nil
204
    return false if param == nil
205
  end
206
 
207
 
208
  def ==(o)
209
    o.class         == self.class       &&
210
    o.hdlfiles      == self.hdlfiles    &&
211
    super( o )
212
  end
213
 
214
 
215
end # class CoreDef
216
end # module SOCMaker
217
 
218
 
219
# 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.