Class: Origen::Registers::Bit

Inherits:
Object
  • Object
show all
Defined in:
lib/origen/registers/bit.rb

Overview

Models bits within Reg objects

Constant Summary collapse

ACCESS_CODES =

The :access property of registers or bits can be set to any of the following key values. Implemented refers to whether the behaviour is accurately modelled by the Origen register model or not.

:base is used in CrossOrigen to set the IP-XACT access type on export.

:read and :write are used in CrossOrigen for IP-XACT export to cover 'readAction' and 'modifiedWriteValue' attributes in the IEEE 1685-2009 schema - they do not affect Origen Core functionality (yet?).

{
  ro:    { implemented: false, base: 'read-only',      write: nil,            read: nil,      writable: false, readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Read-Only' },
  rw:    { implemented: true,  base: 'read-write',     write: nil,            read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Read-Write' },
  rc:    { implemented: false, base: 'read-only',      write: nil,            read: 'clear',  writable: false, readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Read-only, Clear-on-read' },
  rs:    { implemented: false, base: 'read-only',      write: nil,            read: 'set',    writable: false, readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Set-on-read (all bits become '1' on read)" },
  wrc:   { implemented: false, base: 'read-write',     write: nil,            read: 'clear',  writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Writable, clear-on-read' },
  wrs:   { implemented: false, base: 'read-write',     write: nil,            read: 'set',    writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Writable, Sets-on-read' },
  wc:    { implemented: false, base: 'read-write',     write: 'clear',        read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: true,  description: 'Clear-on-write' },
  ws:    { implemented: false, base: 'read-write',     write: 'set',          read: nil,      writable: true,  readable: true,  w1c: false, set_only: true,   clr_only: false, description: 'Set-on-write' },
  wsrc:  { implemented: false, base: 'read-write',     write: 'set',          read: 'clear',  writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Set-on-write, clear-on-read' },
  wcrs:  { implemented: false, base: 'read-write',     write: 'clear',        read: 'set',    writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: 'Clear-on-write, set-on-read' },
  w1c:   { implemented: false, base: 'read-write',     write: 'oneToClear',   read: nil,      writable: true,  readable: true,  w1c: true,  set_only: false,  clr_only: false, description: "Write '1' to clear bits" },
  w1s:   { implemented: false, base: 'read-write',     write: 'oneToSet',     read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '1' to set bits" },
  w1t:   { implemented: false, base: 'read-write',     write: 'oneToToggle',  read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '1' to toggle bits" },
  w0c:   { implemented: false, base: 'read-write',     write: 'zeroToClear',  read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '0' to clear bits" },
  w0s:   { implemented: false, base: 'read-write',     write: 'zeroToSet',    read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '0' to set bits" },
  w0t:   { implemented: false, base: 'read-write',     write: 'zeroToToggle', read: nil,      writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '0' to toggle bits" },
  w1src: { implemented: false, base: 'read-write',     write: 'oneToSet',     read: 'clear',  writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '1' to set and clear-on-read" },
  w1crs: { implemented: false, base: 'read-write',     write: 'oneToClear',   read: 'set',    writable: true,  readable: true,  w1c: true,  set_only: false,  clr_only: false, description: "Write '1' to clear and set-on-read" },
  w0src: { implemented: false, base: 'read-write',     write: 'zeroToSet',    read: 'clear',  writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '0' to set and clear-on-read" },
  w0crs: { implemented: false, base: 'read-write',     write: 'zeroToClear',  read: 'set',    writable: true,  readable: true,  w1c: false, set_only: false,  clr_only: false, description: "Write '0' to clear and set-on-read" },
  wo:    { implemented: false, base: 'write-only', write: nil, read: nil, writable: true, readable: false, w1c: false, set_only: false, clr_only: false, description: 'Write-only' },
  woc:   { implemented: false, base: 'write-only', write: 'clear', read: nil, writable: true, readable: false, w1c: false, set_only: false, clr_only: true, description: "When written sets the field to '0'. Read undeterministic" },
  worz:  { implemented: false, base: 'write-only', write: nil, read: nil, writable: true, readable: false, w1c: false, set_only: false, clr_only: false, description: 'Write-only, Reads zero' },
  wos:   { implemented: false, base: 'write-only', write: 'set', read: nil, writable: true, readable: false, w1c: false, set_only: true, clr_only: false, description: "When written sets all bits to '1'. Read undeterministic" },
  w1:    { implemented: false, base: 'read-writeOnce', write: nil, read: nil, writable: true, readable: true, w1c: false, set_only: false, clr_only: false, description: 'Write-once. Next time onwards, write is ignored. Read returns the value' },
  wo1:   { implemented: false, base: 'writeOnce', write: nil, read: nil, writable: true, readable: false, w1c: false, set_only: false, clr_only: false, description: 'Write-once. Next time onwards, write is ignored. Read is undeterministic' },
  dc:    { implemented: false, base: 'read-write', write: nil, read: nil, writable: true, readable: true, w1c: false, set_only: false, clr_only: false, description: 'RW but no check' },
  rowz:  { implemented: false, base: 'read-only', write: nil, read: 'clear', writable: false, readable: true, w1c: false, set_only: false, clr_only: false, description: 'Read-only, value is cleared on read' }
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

:nodoc:



483
484
485
486
487
488
489
# File 'lib/origen/registers/bit.rb', line 483

def method_missing(method, *args, &block) # :nodoc:
  if (method)
    (method, *args)
  else
    super
  end
end

Instance Attribute Details

#accessObject

Returns the access method for the given bit (a symbol), see the ACCESS_CODES constant for the possible values this can have and their meaning



96
97
98
# File 'lib/origen/registers/bit.rb', line 96

def access
  @access
end

#base_accessObject (readonly)

Returns the basic access string for a given access method. Possible values: read-write, read-only, write-only, writeOnce, read-writeOnce. Used primarily by CrossOrigen IP-XACT import/export.



99
100
101
# File 'lib/origen/registers/bit.rb', line 99

def base_access
  @base_access
end

#clr_only=(value) ⇒ Object (writeonly)

Allow modify of clr_only flag, bit can only be cleared (made 0)



78
79
80
# File 'lib/origen/registers/bit.rb', line 78

def clr_only=(value)
  @clr_only = value
end

#dataObject (readonly)

Current the data value currently held by the bit, 0 or 1



50
51
52
# File 'lib/origen/registers/bit.rb', line 50

def data
  @data
end

#featureObject (readonly)

Any feature associated with the bit/bits



66
67
68
# File 'lib/origen/registers/bit.rb', line 66

def feature
  @feature
end

#metaObject Also known as: meta_data, metadata

Returns any application-specific meta-data attatched to the given bit



91
92
93
# File 'lib/origen/registers/bit.rb', line 91

def meta
  @meta
end

#mod_write_valueObject (readonly)

Returns mod_write_value - what write value modification occurs when written



84
85
86
# File 'lib/origen/registers/bit.rb', line 84

def mod_write_value
  @mod_write_value
end

#nvm_depObject (readonly)

Returns true if bit depends on initial state of NVM in some way



86
87
88
# File 'lib/origen/registers/bit.rb', line 86

def nvm_dep
  @nvm_dep
end

#overlay(value) ⇒ Object (readonly)

Set the overlay attribute to the supplied value



52
53
54
# File 'lib/origen/registers/bit.rb', line 52

def overlay
  @overlay
end

#ownerObject (readonly)

Returns the Reg object that owns the bit



46
47
48
# File 'lib/origen/registers/bit.rb', line 46

def owner
  @owner
end

#positionObject (readonly)

Returns the integer position of the bit within the register



48
49
50
# File 'lib/origen/registers/bit.rb', line 48

def position
  @position
end

#read_actionObject (readonly)

Returns read_action - whether anything happens to the bit when read



82
83
84
# File 'lib/origen/registers/bit.rb', line 82

def read_action
  @read_action
end

#read_data_matches_writeObject (readonly)

If the bit does not read back with the same data as is written to it then this will return true. This property can be assigned durgin the register instantiation, e.g.

add_reg :control,    0x00,    :mode    => { :pos => 8, :bits => 8 },
                              :status  => { :pos => 4, :bits => 2, :read_data_matches_write => false }


58
59
60
# File 'lib/origen/registers/bit.rb', line 58

def read_data_matches_write
  @read_data_matches_write
end

#readable=(value) ⇒ Object (writeonly)

Allow modify of readable flag, bit is readable by read method



74
75
76
# File 'lib/origen/registers/bit.rb', line 74

def readable=(value)
  @readable = value
end

#reset_valObject Also known as: reset_data, reset_value

Returns the reset value of the bit



68
69
70
# File 'lib/origen/registers/bit.rb', line 68

def reset_val
  @reset_val
end

#set_only=(value) ⇒ Object (writeonly)

Allow modify of set_only flag, bit can only be set (made 1)



80
81
82
# File 'lib/origen/registers/bit.rb', line 80

def set_only=(value)
  @set_only = value
end

#startObject (readonly)

Returns true if bit is critical to starting an important operation (like a state machine) so that it can be made not writable during basic register checks



89
90
91
# File 'lib/origen/registers/bit.rb', line 89

def start
  @start
end

#sticky_overlayObject

Returns true if this bit has the sticky_overlay flag set, see Reg#sticky_overlay for a full description. This is true by default.



61
62
63
# File 'lib/origen/registers/bit.rb', line 61

def sticky_overlay
  @sticky_overlay
end

#sticky_storeObject

Returns true if this bit has the sticky_store flag set, see Reg#sticky_store for a full description. This is false by default.



64
65
66
# File 'lib/origen/registers/bit.rb', line 64

def sticky_store
  @sticky_store
end

#unknownObject

Can be set to indicate that the current state of the bit is unknown, e.g. after reading X from a simulation



101
102
103
# File 'lib/origen/registers/bit.rb', line 101

def unknown
  @unknown
end

#w1cObject

Sets or returns the status of “write-one-to-clear”



76
77
78
# File 'lib/origen/registers/bit.rb', line 76

def w1c
  @w1c
end

#writable=(value) ⇒ Object (writeonly)

Allow modify of writable flag, bit is writeable by write method



72
73
74
# File 'lib/origen/registers/bit.rb', line 72

def writable=(value)
  @writable = value
end

Class Method Details

.null(owner, position) ⇒ Object

Returns a 'null' bit object which has value 0 and no other attributes set



411
412
413
# File 'lib/origen/registers/bit.rb', line 411

def self.null(owner, position) # :nodoc:
  Bit.new(owner, position, writable: false)
end

Instance Method Details

#abs_pathObject



226
227
228
# File 'lib/origen/registers/bit.rb', line 226

def abs_path
  @abs_path
end

#access_codesObject



179
180
181
# File 'lib/origen/registers/bit.rb', line 179

def access_codes
  ACCESS_CODES
end

#clear_flagsObject

Clears the read, store, overlay and update_required flags of this bit. The store and overlay flags will not be cleared if the the bit's sticky_store or sticky_overlay attributes are set respectively.



388
389
390
391
392
393
394
# File 'lib/origen/registers/bit.rb', line 388

def clear_flags
  @read = false
  @store = false unless @sticky_store
  @overlay = false unless @sticky_overlay
  @update_required = false
  self
end

#clear_read_flagObject

Clears the read flag of this bit.



397
398
399
400
# File 'lib/origen/registers/bit.rb', line 397

def clear_read_flag
  @read = false
  self
end

#clear_startObject

Clears any start bits that are set



448
449
450
451
452
453
# File 'lib/origen/registers/bit.rb', line 448

def clear_start
  if @start && set?
    @data = 0
  end
  self
end

#clear_w1cObject

Clears any w1c bits that are set



440
441
442
443
444
445
# File 'lib/origen/registers/bit.rb', line 440

def clear_w1c
  if @w1c && set?
    @data = 0
  end
  self
end

#data_in_positionObject

Returns the data shifted by the bit position



435
436
437
# File 'lib/origen/registers/bit.rb', line 435

def data_in_position
  data << position
end

#default_bit_metadataObject

Returns any application specific metadata that has been inherited by the given bit. This does not account for any overridding that may have been applied to this bit specifically however, use the meta method to get that.



240
241
242
243
244
245
246
247
248
# File 'lib/origen/registers/bit.rb', line 240

def 
  if owner
    Origen::Registers..merge(
      Origen::Registers.[owner.owner.class] || {}
    )
  else
    Origen::Registers.
  end
end

#deleteObject

Make this bit disappear, make it unwritable with a data value of 0



260
261
262
263
264
265
266
267
# File 'lib/origen/registers/bit.rb', line 260

def delete
  @sticky_overlay = false
  @sticky_store = false
  clear_flags
  @data = 0
  @writable = false
  self
end

#enabled?Boolean

Returns:

  • (Boolean)


510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
# File 'lib/origen/registers/bit.rb', line 510

def enabled?
  if feature
    value = false
    current_owner = self
    if feature.class == Array
      feature.each do |f|
        current_owner = self
        loop do
          if current_owner.respond_to?(:owner)
            current_owner = current_owner.owner
            if current_owner.respond_to?(:has_feature?)
              if current_owner.has_feature?(f)
                value = true
                break
              end
            end
          else # if current owner does not have a owner
            value = false
            break
          end
        end # loop end
        unless value
          if Origen.top_level && \
             Origen.top_level.respond_to?(:has_feature?) && \
             Origen.top_level.has_feature?(f)
            value = true
            unless value
              break
            end
          end
        end
        unless value
          break # break if feature not found and return false
        end
      end # iterated through all features in array
      value
    else # if feature.class != Array
      loop do
        if current_owner.respond_to?(:owner)
          current_owner = current_owner.owner
          if current_owner.respond_to?(:has_feature?)
            if current_owner.has_feature?(feature)
              value = true
              break
            end
          end
        else # if current owner does not have a owner
          value = false
          break
        end
      end # loop end
      unless value
        if Origen.top_level && \
           Origen.top_level.respond_to?(:has_feature?) && \
           Origen.top_level.has_feature?(feature)
          value = true
        end
      end
      value
    end
  else
    true
  end
end

#enabled_by_feature?(name = nil) ⇒ Boolean Also known as: has_feature_constraint?

Returns true if the bit is constrained by the given/any feature

Returns:

  • (Boolean)


492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/origen/registers/bit.rb', line 492

def enabled_by_feature?(name = nil)
  if !name
    !!feature
  else
    if feature.class == Array
      feature.each do |f|
        if f == name
          return true
        end
      end
      false
    else
      feature == name
    end
  end
end

#extract_meta_data(method, *args) ⇒ Object



474
475
476
477
478
479
480
481
# File 'lib/origen/registers/bit.rb', line 474

def (method, *args)
  method = method.to_s.sub('?', '')
  if method =~ /=/
    instance_variable_set("@#{method.sub('=', '')}", args.first)
  else
    instance_variable_get("@#{method}") || meta[method.to_sym]
  end
end

#has_known_value?Boolean

Returns true if the value of the bit is known. The value will be unknown in cases where the reset value is undefined or determined by a memory location and where the bit has not been written or read to a specific value yet.

Returns:

  • (Boolean)


295
296
297
# File 'lib/origen/registers/bit.rb', line 295

def has_known_value?
  !@unknown && (!@reset_val.is_a?(Symbol) || @updated_post_reset)
end

#has_overlay?(name = nil) ⇒ Boolean

Returns true if the overlay attribute is set, optionally supply an overlay name and this will only return true if the overlay attribute matches that name

Returns:

  • (Boolean)


366
367
368
369
370
371
372
# File 'lib/origen/registers/bit.rb', line 366

def has_overlay?(name = nil)
  if name
    name.to_s == @overlay.to_s
  else
    !!@overlay
  end
end

#inspectObject



250
251
252
# File 'lib/origen/registers/bit.rb', line 250

def inspect
  "<#{self.class}:#{object_id}>"
end

#is_readable?Boolean Also known as: readable?

Returns:

  • (Boolean)


380
381
382
# File 'lib/origen/registers/bit.rb', line 380

def is_readable?
  @readable
end

#is_to_be_read?Boolean

Returns true if the bit's read flag is set

Returns:

  • (Boolean)


355
356
357
# File 'lib/origen/registers/bit.rb', line 355

def is_to_be_read?
  @read
end

#is_to_be_stored?Boolean

Returns true if the bit's store flag is set

Returns:

  • (Boolean)


360
361
362
# File 'lib/origen/registers/bit.rb', line 360

def is_to_be_stored?
  @store
end

#is_writable?Boolean Also known as: writable?

Returns true if the bit is writable

Returns:

  • (Boolean)


375
376
377
# File 'lib/origen/registers/bit.rb', line 375

def is_writable?
  @writable
end

#maskObject

Returns a bit mask for this bit, that is a 1 shifted into the position corresponding to this bit's position. e.g. A bit with position 4 would return %1_0000



405
406
407
408
# File 'lib/origen/registers/bit.rb', line 405

def mask
  mask_val = 1
  mask_val << @position
end

#meta_data_method?(method) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/origen/registers/bit.rb', line 461

def (method)
  attr_name = method.to_s.gsub(/\??=?/, '').to_sym
  if .key?(attr_name)
    if method.to_s =~ /\?/
      [true, false].include?([attr_name])
    else
      true
    end
  else
    false
  end
end

#overlay_strObject

Returns the overlay attribute



350
351
352
# File 'lib/origen/registers/bit.rb', line 350

def overlay_str
  @overlay
end

#path_varObject



222
223
224
# File 'lib/origen/registers/bit.rb', line 222

def path_var
  @path
end

#read(value = nil, _options = {}) ⇒ Object Also known as: assert

Will tag all bits for read and if a data value is supplied it will update the expected data for when the read is performed.



322
323
324
325
326
327
328
329
330
331
# File 'lib/origen/registers/bit.rb', line 322

def read(value = nil, _options = {})
  # First properly assign the args if value is absent...
  if value.is_a?(Hash)
    options = value
    value = nil
  end
  write(value) if value
  @read = true if @readable && @read_data_matches_write
  self
end

#resetObject

Resets the data value back to the reset value and calls Bit#clear_flags



275
276
277
278
279
280
281
282
283
284
# File 'lib/origen/registers/bit.rb', line 275

def reset
  if @reset_val.is_a?(Symbol)
    @data = 0
  else
    @data = @reset_val
  end
  @updated_post_reset = false
  clear_flags
  self
end

#respond_to?(*args) ⇒ Boolean

:nodoc:

Returns:

  • (Boolean)


455
456
457
458
# File 'lib/origen/registers/bit.rb', line 455

def respond_to?(*args) # :nodoc:
  sym = args.first
  (sym) || super(sym)
end

#set?Boolean

Returns true if the bit is set (holds a data value of 1)

Returns:

  • (Boolean)


270
271
272
# File 'lib/origen/registers/bit.rb', line 270

def set?
  @data == 1 ? true : false
end

#set_access(value) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/origen/registers/bit.rb', line 183

def set_access(value)
  unless ACCESS_CODES.keys.include?(value)
    puts 'Invalid access code, must be one of these:'
    ACCESS_CODES.each do |code, meta|
      puts "  :#{code}".ljust(10) + " - #{meta[:description]}"
    end
    puts ''
    fail 'Invalid access code!'
  end
  @access = value

  # Set access attributes by pulling key-value pairs from ACCESS_CODES[<access>]
  @readable = ACCESS_CODES[@access][:readable]
  @writable = ACCESS_CODES[@access][:writable]
  @w1c = ACCESS_CODES[@access][:w1c]
  @set_only = ACCESS_CODES[@access][:set_only]
  @clr_only = ACCESS_CODES[@access][:clr_only]
  @base_access = ACCESS_CODES[@access][:base]
  @read_action = ACCESS_CODES[@access][:read]
  @mod_write_value = ACCESS_CODES[@access][:write]
end

#set_access_from_rwObject

Set @access based on @readable and @writable



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/origen/registers/bit.rb', line 206

def set_access_from_rw
  if @w1c
    @access = :w1c
  elsif @clr_only
    @access = :wc
  elsif @set_only
    @access = :ws
  elsif @readable && @writable
    @access = :rw
  elsif @readable
    @access = :ro
  elsif @writable && @access != :worz
    @access = :wo
  end
end

#setting(value) ⇒ Object

Returns the value you would need to write to the register to put the given value in this bit



417
418
419
420
# File 'lib/origen/registers/bit.rb', line 417

def setting(value)
  value = value & 1 # As this bit can only hold one bit of data force it
  value << @position
end

#shift_out_left {|_self| ... } ⇒ Object

With only one bit it just returns itself

Yields:

  • (_self)

Yield Parameters:



430
431
432
# File 'lib/origen/registers/bit.rb', line 430

def shift_out_left
  yield self
end

#sizeObject

Always returns 1 when asked for size, a BitCollection on the other hand will return something higher



255
256
257
# File 'lib/origen/registers/bit.rb', line 255

def size
  1
end

#storeObject

Sets the store flag attribute



335
336
337
338
# File 'lib/origen/registers/bit.rb', line 335

def store
  @store = true
  self
end

#undefined?Boolean

Returns true if the bit object is a placeholder for bit positions that have not been defined within the parent register

Returns:

  • (Boolean)


288
289
290
# File 'lib/origen/registers/bit.rb', line 288

def undefined?
  @undefined
end

#update_required?Boolean

Returns true if the bit's update_required flag is set, typically this will be the case when a write has changed the data value of the bit but a BitCollection#write! method has not been called yet to apply it to silicon

Returns:

  • (Boolean)


425
426
427
# File 'lib/origen/registers/bit.rb', line 425

def update_required?
  @update_required
end

#write(value, options = {}) ⇒ Object

Set the data value of the bit to the given value (1 or 0) If the bit is read-only, the value of the bit can be forced with 'force: true'



301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/origen/registers/bit.rb', line 301

def write(value, options = {})
  # If an array is written it means a data value and an overlay have been supplied
  # in one go...
  if value.is_a?(Array)
    overlay(value[1])
    value = value[0]
  end
  if (@data != value & 1 && @writable) ||
     (@data != value & 1 && options[:force] == true)
    if ((set?) && (!@set_only)) ||
       ((!set?) && (!@clr_only))
      @data = value & 1
      @update_required = true
      @updated_post_reset = true
    end
  end
  self
end