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 10

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 10 feddischso
#        - a id (mandatory)
43 3 feddischso
#        - 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 10 feddischso
#           different naming of the ports. For this reason, the name+id
49 3 feddischso
#           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 10 feddischso
#           TODO
53 3 feddischso
#
54
###############################################################
55
 
56
module SOCMaker
57
class IfcDef
58
  include ERR
59
  attr_accessor :name
60
  attr_accessor :dir
61 10 feddischso
  attr_accessor :id
62 3 feddischso
  attr_accessor :ports
63
 
64 10 feddischso
  def initialize( name, id, dir, ports )
65 3 feddischso
    init_with( 'name'     => name,
66
               'dir'      => dir,
67 10 feddischso
               'id'  => id,
68 3 feddischso
               'ports'    => ports )
69
  end
70
  def encode_with( coder )
71 10 feddischso
    %w[ name dir id ports ].
72 3 feddischso
          each { |v| coder[ v ] = instance_variable_get "@#{v}" }
73
  end
74
  def init_with( coder )
75
 
76
    # name
77
    serr_if( coder[ 'name' ] == nil,
78
      'no name defined for this interface',
79
      field:    'name' )
80
    @name = coder[ 'name' ]
81
    verr_if( !@name.is_a?( String ),
82
      'Interface name is not defined as string',
83
      instance: @name.to_s,
84
      field:    'name' )
85
    verr_if( @name.size == 0,
86
        "Name has zero length",
87
        field: "name" )
88
 
89 10 feddischso
    # id
90
    serr_if( coder[ 'id' ] == nil,
91
      'id is not given for interface',
92 3 feddischso
      instance: @name,
93 10 feddischso
      field:    'id' )
94
    @id = coder[ 'id' ]
95
    serr_if( !@id.is_a?( String ),
96
      'Interface id is not defined as string',
97 3 feddischso
      instance: @name,
98 10 feddischso
      field:    'id' )
99
    verr_if( @id.size == 0,
100 3 feddischso
        "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
 
125
    end
126
 
127
    # direction
128
    serr_if( coder[ 'dir' ] == nil,
129
      'Interface direction is not given',
130
      instance: @name,
131
      field:    'dir' )
132
    @dir = coder[ 'dir' ]
133
    verr_if( @dir != 0 && @dir != 1,
134
      'Interface direction must be 0 or 1',
135
      instance: @name,
136
      field:    'dir' )
137
 
138
 
139
  end
140
 
141
 
142
 
143
  def ==(o)
144
    o.class         == self.class       &&
145
    o.name          == self.name        &&
146
    o.dir           == self.dir         &&
147 10 feddischso
    o.id       == self.id     &&
148 3 feddischso
    o.ports         == self.ports
149
  end
150
 
151
 
152
end # IFCDef
153
end # SOCMaker

powered by: WebSVN 2.1.0

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