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

Subversion Repositories soc_maker

[/] [soc_maker/] [trunk/] [lib/] [soc_maker/] [ifc_def.rb] - Blame information for rev 5

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

Line No. Rev Author Line
1 3 feddischso
###############################################################
2
#
3
#  File:      ifc_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
#
37
#     A small classes, used to group information
38
#     and to verify, auto-correct and auto-complete
39
#     this information:
40
#     The class represents an interface definition:
41
#        - name of the interface (mandatory)
42
#        - a version (mandatory)
43
#        - a direction  (mandatry)
44
#        - ports (hash of type SOCMaker::IfcPort, mandatory)
45
#
46
#     Note: instances of this class are used withing core-definitions.
47
#           Different cores may use the same interface, but with a
48
#           different naming of the ports. For this reason, the name+version
49
#           is used to identify, which interface specification (SOCMaker::IfcSpc)
50
#           is defined. The port-hash makes the relation between the core port-naming
51
#           and the IfcSpc port-naming.
52
#
53
###############################################################
54
 
55
module SOCMaker
56
class IfcDef
57
  include ERR
58
  attr_accessor :name
59
  attr_accessor :dir
60
  attr_accessor :version
61
  attr_accessor :ports
62
 
63
  def initialize( name, version, dir, ports )
64
    init_with( 'name'     => name,
65
               'dir'      => dir,
66
               'version'  => version,
67
               'ports'    => ports )
68
  end
69
  def encode_with( coder )
70
    %w[ name dir version ports ].
71
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
72
  end
73
  def init_with( coder )
74
 
75
    # name
76
    serr_if( coder[ 'name' ] == nil,
77
      'no name defined for this interface',
78
      field:    'name' )
79
    @name = coder[ 'name' ]
80
    verr_if( !@name.is_a?( String ),
81
      'Interface name is not defined as string',
82
      instance: @name.to_s,
83
      field:    'name' )
84
    verr_if( @name.size == 0,
85
        "Name has zero length",
86
        field: "name" )
87
 
88
    # version
89
    serr_if( coder[ 'version' ] == nil,
90
      'version is not given for interface',
91
      instance: @name,
92
      field:    'version' )
93
    @version = coder[ 'version' ]
94
    @version = @version.to_s if @version.is_a?( Numeric )
95
    serr_if( !@version.is_a?( String ),
96
      'Interface version is not defined as string',
97
      instance: @name,
98
      field:    'version' )
99
    verr_if( @version.size == 0,
100
        "Version has zero length",
101
        field: "name" )
102
 
103
 
104
    # ports
105
    serr_if( coder[ 'ports' ] == nil,
106 5 feddischso
      "No ports are given for interface definition",
107 3 feddischso
      field: 'ports' )
108
    @ports = coder[ 'ports' ]
109
    serr_if( !@ports.is_a?( Hash )  ||
110
              @ports.size == 0,
111
      'no ports are given for this interface',
112
      instance: @name,
113
      field:    'ports' )
114
 
115
    @ports.each do |name, port|
116
      serr_if( port == nil, 'no port definition found',
117
        instance: @name + name.to_s,
118
        field:    'ports' )
119
 
120
      serr_if( !port.is_a?( SOCMaker::IfcPort ),
121
        'Port is not of type SocMaker::IfcPort (use SOCM_PORT)',
122
        instance: @name + name.to_s,
123
        field:    'ports' )
124
        port.verify
125
 
126
    end
127
 
128
    # direction
129
    serr_if( coder[ 'dir' ] == nil,
130
      'Interface direction is not given',
131
      instance: @name,
132
      field:    'dir' )
133
    @dir = coder[ 'dir' ]
134
    verr_if( @dir != 0 && @dir != 1,
135
      'Interface direction must be 0 or 1',
136
      instance: @name,
137
      field:    'dir' )
138
 
139
 
140
  end
141
 
142
 
143
  def verify
144
  end
145
 
146
  def ==(o)
147
    o.class         == self.class       &&
148
    o.name          == self.name        &&
149
    o.dir           == self.dir         &&
150
    o.version       == self.version     &&
151
    o.ports         == self.ports
152
  end
153
 
154
 
155
end # IFCDef
156
end # SOCMaker

powered by: WebSVN 2.1.0

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