Module: Ipxact

Includes:
Dita, FigField
Defined in:
lib/ipxact/dita/fig_field.rb,
lib/ipxact.rb,
lib/ipxact/dita/reg_fig.rb,
lib/ipxact/vendor_extensions/magillem_ipxact.rb

Overview

Copyright © 2016 Freescale Semiconductor Inc.

Defined Under Namespace

Modules: FigField, Magillem

Constant Summary collapse

REGFIG_MAX_ROWBITS =
32

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FigField

#gen_field_entries

Instance Attribute Details

#word_ctObject (readonly)

Returns the value of attribute word_ct.



14
15
16
# File 'lib/ipxact/dita/reg_fig.rb', line 14

def word_ct
  @word_ct
end

Instance Method Details

#bit_rangeObject



106
107
108
# File 'lib/ipxact/dita/reg_fig.rb', line 106

def bit_range
  "#{(field_pos(source) + field_width(source) - 1).to_s} - #{field_pos(source).to_s}"
end

#field_pos(field) ⇒ Object



63
64
65
# File 'lib/ipxact/dita/reg_fig.rb', line 63

def field_pos(field)
  field.bitOffset.text.to_i
end

#field_width(field) ⇒ Object



67
68
69
# File 'lib/ipxact/dita/reg_fig.rb', line 67

def field_width(field)
  field.bitWidth.text.to_i
end

#fig_bit_widthObject



102
103
104
# File 'lib/ipxact/dita/reg_fig.rb', line 102

def fig_bit_width
  REGFIG_MAX_ROWBITS > reg_size ? reg_size : REGFIG_MAX_ROWBITS
end

#gen_tgroupObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/ipxact/dita/reg_fig.rb', line 71

def gen_tgroup
  tgroup = Element.new('tgroup')
  tgroup[:cols] ||= num_cols
  num_cols.times do |i|
    tgroup << colspec = Element.new('colspec')
    colspec[:align] = 'center'
    colspec[:colname] = i.to_s
  end

  tgroup << Element.new('tbody')
  %w(Bits R W Reset).each do |heading|
    tgroup.tbody << row = Element.new('row')
    row << Element.new('entry')
    row.entry << heading
  end

  set_bit_heading! tgroup.tbody.nodes.first
  tgroup
end

#large?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ipxact/dita/reg_fig.rb', line 59

def large?
  reg_size > 64
end

#num_colsObject



110
111
112
# File 'lib/ipxact/dita/reg_fig.rb', line 110

def num_cols
  fig_bit_width+1
end

#offset_table(node) ⇒ Element

Returns table with columns for register name and address offset.

Parameters:

  • node (Element)

    for now, just outputs one address from <ipxact:addressOffset/>

Returns:

  • (Element)

    table with columns for register name and address offset



8
9
10
# File 'lib/ipxact.rb', line 8

def offset_table(node)
  table(%w())
end

#reg_fig(opts = {}) ⇒ Element

Returns visual rendering of register and its fields in Dita table form; content from <ipxact:register/> in @source.

Parameters:

  • opts (Hash) (defaults to: {})

    no options currently supported TODO add options for hide access, hide reset value, etc.

Returns:

  • (Element)

    visual rendering of register and its fields in Dita table form; content from <ipxact:register/> in @source



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ipxact/dita/reg_fig.rb', line 18

def reg_fig(opts={})
  src = source # TODO not sure if this is ideal, but works for now
  table = Element.new('table')
  table[:id] = object_id.to_s+"_regFigure"
  table[:frame] = 'all'
  table[:outputclass] = 'crr.regFigure regtable'
  @word_ct = 0
  input = src.locate(src_ns + ':field')
  tgroup = nil
  until input.empty? do
    field = input.pop
    index = row_relative_index field
    if tgroup.nil?
      tgroup = gen_tgroup
      table << tgroup
    end
    if index > REGFIG_MAX_ROWBITS
      table << tgroup = gen_tgroup
      input << field.split do |bit| bit end
      next
    else
      entries = gen_field_entries(field, word_ct)
      tgroup.tbody.nodes[1] << entries.first
      tgroup.tbody.nodes[2] << entries[1] if entries.size > 2
      tgroup.tbody.nodes[3] << entries.last if entries.last.is_a?(Array)
    end
    if field_pos(field) == 0 || index >= REGFIG_MAX_ROWBITS
      @word_ct += 1 unless field_pos(field) == 0
    end
  end
  table
end

#reg_sizeObject



98
99
100
# File 'lib/ipxact/dita/reg_fig.rb', line 98

def reg_size
  source.size.text.to_i
end

#row_relative_index(field) ⇒ Object



51
52
53
# File 'lib/ipxact/dita/reg_fig.rb', line 51

def row_relative_index(field)
  field_pos(field) + field_width(field) - word_ct*REGFIG_MAX_ROWBITS
end

#set_bit_heading!(bit_row) ⇒ Object



91
92
93
94
95
96
# File 'lib/ipxact/dita/reg_fig.rb', line 91

def set_bit_heading!(bit_row)
  fig_bit_width.times do |i|
    bit_row << e = Element.new('entry')
    e << (fig_bit_width - i-1).to_s
  end
end

#small?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/ipxact/dita/reg_fig.rb', line 55

def small?
  reg_size < REGFIG_MAX_ROWBITS
end