Method: Origen::Registers::Bit#initialize

Defined in:
lib/origen/registers/bit.rb

#initialize(owner, position, options = {}) ⇒ Bit

Returns a new instance of Bit.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/origen/registers/bit.rb', line 103

def initialize(owner, position, options = {})
  options = {
    start:                   false,        # whether bit starts a state machine so be careful
    read_data_matches_write: true,
    read:                    false,
    overlay:                 false,
    store:                   false,
    sticky_overlay:          true,
    sticky_store:            false,
    nvm_dep:                 false        # whether is an NVM dependent bit
  }.merge(options)
  @owner = owner
  @position = position
  @undefined = options.delete(:undefined)
  @reset_val = (options.delete(:res) || options.delete(:reset) || options.delete(:data) || 0)
  if @reset_val.is_a?(Symbol)
    @data = 0
  else
    @reset_val &= 1 unless @reset_val.is_a?(Symbol)
    @data = @reset_val
  end

  access_code = options.delete(:access)
  # If access has been defined then none of these other attributes can be
  if access_code
    conflicts = [:readable, :writable, :clr_only, :set_only, :w1c]
    if conflicts.any? { |k| options.key?(k) }
      puts 'The following attributes cannot be set in combination with :access'
      puts "  #{conflicts.join(', ')}"
      puts ''
      puts 'Use :access to defined the required behavior, the above attributes will be deprecated in future.'
      puts ''
      fail 'Conflicting access!'
    end
    set_access(access_code)
  else
    options = {
      writable: true,         # whether bit is writable
      readable: true,         # whether bit is readable
      clr_only: false,        # whether bit is clear only
      set_only: false,        # whether bit is set only
      w1c:      false        # whether bit is w1c (when written to 1 immediately becomes 0)
    }.merge(options)
    @readable = options.delete(:readable)
    @writable = options.delete(:writable)
    @clr_only = options.delete(:clr_only)
    @set_only = options.delete(:set_only)
    @w1c = options.delete(:w1c)
    set_access_from_rw
  end
  # Would like to get this integrated with access as well
  @read_data_matches_write = options.delete(:read_data_matches_write)

  @feature = options.delete(:feature)
  if !!feature && @writable
    @writable = enabled?
  end
  @path     = options.delete(:path)
  @abs_path = options.delete(:abs_path)
  @start = options.delete(:start)
  @read = options.delete(:read)
  @overlay = options.delete(:overlay)
  @store = options.delete(:store)
  @update_required = false
  @sticky_store = options.delete(:sticky_store)
  @sticky_overlay = options.delete(:sticky_overlay)
  @nvm_dep = (options.delete(:nvm_dep) ? 1 : 0)
  # Delete some other noise that can be left over...
  options.delete(:bits)
  options.delete(:pos)
  options.delete(:position)
  options.delete(:data)
  # Whatever is left must be custom application meta-data
  @meta = ().merge(options)
end