ipxact-dita 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ipxact.rb +11 -0
- data/lib/ipxact/addr.rb +117 -0
- data/lib/ipxact/dita/fig_field.rb +117 -0
- data/lib/ipxact/dita/reg_fig.rb +113 -0
- data/lib/ipxact/ruby_ext/string.rb +34 -0
- data/lib/ipxact/vendor_extensions/magillem_ipxact.rb +9 -0
- metadata +79 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aba34808fe7475d865abcd1d30a4d046ecaf0619
|
4
|
+
data.tar.gz: 3bee2d0b76e862971362c6fbf22dcad034a4c17c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 460ce36f4cd53471c193cee767a91c5895f5083504d983c486dcc40e00805b0d0e1060dd76609205335fd2caa0f648a2b89c06f662d4e0db78e6cd86fe82e251
|
7
|
+
data.tar.gz: fc2f28345bec0a568f8e5c58c9ff948c26a153aa2acab531a18573090a14de6a4d955fa6501a2d0075bca3b543b3985408c0114a900f2ff7033355feb17906a8
|
data/lib/ipxact.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
require_relative 'ipxact/dita/reg_fig'
|
3
|
+
require_relative 'ipxact/addr'
|
4
|
+
|
5
|
+
module Ipxact
|
6
|
+
# @param node [Element] for now, just outputs one address from <ipxact:addressOffset/>
|
7
|
+
# @return [Element] table with columns for register name and address offset
|
8
|
+
def offset_table(node)
|
9
|
+
table(%w())
|
10
|
+
end
|
11
|
+
end
|
data/lib/ipxact/addr.rb
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
|
3
|
+
require 'con_duxml'
|
4
|
+
require_relative 'ruby_ext/string'
|
5
|
+
|
6
|
+
module Addr
|
7
|
+
include ConDuxml
|
8
|
+
|
9
|
+
HEX_POSTFIX = 'h'
|
10
|
+
HEX_PREFIX = '0x'
|
11
|
+
HEX_MAG_DIGS = 4
|
12
|
+
HEX_SEP = '_'
|
13
|
+
|
14
|
+
DEC_POSTFIX = 'd'
|
15
|
+
DEC_MAG_DIGS = 3
|
16
|
+
DEC_SEP = ','
|
17
|
+
|
18
|
+
BIN_POSTFIX = 'b'
|
19
|
+
BIN_PREFIX = '0b'
|
20
|
+
BIN_MAG_DIGS = 4
|
21
|
+
BIN_SEP = ' '
|
22
|
+
|
23
|
+
def bit_range
|
24
|
+
[position, position+width]
|
25
|
+
end
|
26
|
+
|
27
|
+
# @param str [String] string representing number; can be in any base
|
28
|
+
# @param opts [Hash] options are:
|
29
|
+
# :pre => true # radix notation goes at beginning e.g. '0x000F' - default setting
|
30
|
+
# :post => true # radix notation goes at end e.g. 'Fh'
|
31
|
+
# :sep => true # adds separator characters ('_' for hex) every 4 digits
|
32
|
+
# :pad => [Fixnum] # given value indicates total digit width of number e.g. 4 => '000Fh'
|
33
|
+
# @return [String] string representation of hex number
|
34
|
+
def to_hex(str, opts={})
|
35
|
+
s = str.to_dec.to_s(16).upcase
|
36
|
+
s = add_padding(s, opts[:pad]) if opts[:pad]
|
37
|
+
|
38
|
+
if opts[:sep]
|
39
|
+
separator = opts[:sep] == true ? HEX_SEP : opts[:sep]
|
40
|
+
s = add_separators(s, HEX_MAG_DIGS, separator)
|
41
|
+
end
|
42
|
+
|
43
|
+
if opts[:post]
|
44
|
+
s += opts[:post] == true ? HEX_POSTFIX : opts[:post]
|
45
|
+
end
|
46
|
+
if opts[:pre]
|
47
|
+
s = opts[:pre] == true ? HEX_PREFIX : opts[:pre] + s
|
48
|
+
end
|
49
|
+
s
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param str [String] string representing number; can be in any base
|
53
|
+
# @param opts [Hash] options are:
|
54
|
+
# :pre => [boolean, String] # if String, notation, by default '0b'; hash key indicates position; if true,
|
55
|
+
# :post => [boolean, String] # radix notation goes at end e.g. '10b'; cannot contradict :pre
|
56
|
+
# :sep => [boolean] # adds separator characters ('_' for hex) every 4 digits
|
57
|
+
# :pad => [Fixnum] # given value indicates total digit width of number e.g. 4 => '000Fh'
|
58
|
+
# @return [String] string representation of hex number
|
59
|
+
def to_bin(str, opts={})
|
60
|
+
s = str.to_dec.to_s(2)
|
61
|
+
s = add_padding(s, 1) if opts[:pad]
|
62
|
+
|
63
|
+
if opts[:sep]
|
64
|
+
separator = opts[:sep] == true ? BIN_SEP : opts[:sep]
|
65
|
+
s = add_separators(s, BIN_MAG_DIGS, separator)
|
66
|
+
end
|
67
|
+
|
68
|
+
if opts[:post]
|
69
|
+
s += opts[:post] == true ? BIN_POSTFIX : opts[:post]
|
70
|
+
end
|
71
|
+
if opts[:pre]
|
72
|
+
s = (opts[:pre] == true ? BIN_PREFIX : opts[:pre]) + s
|
73
|
+
end
|
74
|
+
s
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param str [String] number as string; can be any base or notation
|
78
|
+
# @return [String] formatted string
|
79
|
+
def to_dec(str, opts={})
|
80
|
+
s = str.to_dec.to_s
|
81
|
+
s = add_padding(s, opts[:pad]) if opts[:pad]
|
82
|
+
|
83
|
+
if opts[:sep]
|
84
|
+
separator = opts[:sep] == true ? DEC_SEP : opts[:sep]
|
85
|
+
s = add_separators(s, DEC_MAG_DIGS, separator)
|
86
|
+
end
|
87
|
+
|
88
|
+
if opts[:post]
|
89
|
+
s += opts[:post] == true ? DEC_POSTFIX : opts[:post]
|
90
|
+
end
|
91
|
+
s
|
92
|
+
end
|
93
|
+
|
94
|
+
# @param str [String] number as string
|
95
|
+
# @param places [Fixnum] number of digits for the whole number
|
96
|
+
# @return [String] string representing number
|
97
|
+
def add_padding(str, places)
|
98
|
+
padding = ''
|
99
|
+
(places - str.size).times do padding << '0' end
|
100
|
+
padding + str
|
101
|
+
end
|
102
|
+
|
103
|
+
def add_separators(str, mag, sep)
|
104
|
+
expr = Regexp.new("\\w{#{mag}}")
|
105
|
+
s = str.reverse.gsub(expr) do |m| m+sep end.reverse
|
106
|
+
str.size%mag == 0 ? s[1..-1] : s
|
107
|
+
end
|
108
|
+
|
109
|
+
private :add_separators, :add_padding
|
110
|
+
|
111
|
+
private
|
112
|
+
|
113
|
+
def get_bin_value
|
114
|
+
av = reset_value.value
|
115
|
+
self[:value].to_s(2).split(//)
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
module Ipxact
|
3
|
+
REGFIG_MAX_ROWBITS = 32
|
4
|
+
|
5
|
+
module FigField
|
6
|
+
include Dita
|
7
|
+
|
8
|
+
@field
|
9
|
+
|
10
|
+
def gen_field_entries(_field, _word_ct)
|
11
|
+
@field = _field
|
12
|
+
@word_ct = _word_ct
|
13
|
+
|
14
|
+
entry = Element.new('entry')
|
15
|
+
if width == 1
|
16
|
+
entry[:colname] = col_start_index.to_s
|
17
|
+
else
|
18
|
+
entry[:namest] = (col_start_index).to_s
|
19
|
+
entry[:nameend] = (col_end_index+1).to_s
|
20
|
+
end
|
21
|
+
entry[:valign] = 'middle'
|
22
|
+
# entry[:outputclass] = 'rotate' if get_bit_width(name) > fig_bit_width # TODO fix this!!!
|
23
|
+
entries = gen_field_access(entry)
|
24
|
+
#entries << get_value_entries
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
attr_reader :word_ct, :field
|
30
|
+
|
31
|
+
def gen_field_access(entry)
|
32
|
+
read = entry
|
33
|
+
write = Element.new('entry')
|
34
|
+
|
35
|
+
#TODO pull out into Duxml#dclone?
|
36
|
+
entry.attributes.each do |k,v| write[k] = v end
|
37
|
+
unless readable?
|
38
|
+
read[:outputclass] = 'shaded'
|
39
|
+
end
|
40
|
+
if readable? == writable?
|
41
|
+
read[:morerows] = '1'
|
42
|
+
name = readable? ? gen_field_name(read) : 'Reserved'
|
43
|
+
return [name]
|
44
|
+
elsif !writable?
|
45
|
+
gen_field_name(read)
|
46
|
+
write[:outputclass] = 'shaded'
|
47
|
+
elsif !readable?
|
48
|
+
gen_field_name(write)
|
49
|
+
else
|
50
|
+
# do nothing
|
51
|
+
end
|
52
|
+
[read, write]
|
53
|
+
end
|
54
|
+
|
55
|
+
def readable?
|
56
|
+
access = field.locate('ipxact:access').first
|
57
|
+
access = source.access.text unless access
|
58
|
+
access.include?('read')
|
59
|
+
end
|
60
|
+
|
61
|
+
def writable?
|
62
|
+
access = field.locate('ipxact:access').first
|
63
|
+
access = source.access.text unless access
|
64
|
+
access.include?('write')
|
65
|
+
end
|
66
|
+
|
67
|
+
def get_value_entries
|
68
|
+
v = []
|
69
|
+
width.times do |i|
|
70
|
+
b = bits[i] ? bits[i] : 0
|
71
|
+
v << e = Element.new('entry')
|
72
|
+
e << b.to_s
|
73
|
+
end
|
74
|
+
v
|
75
|
+
end
|
76
|
+
|
77
|
+
def gen_field_name(entry)
|
78
|
+
if field_name.nil?
|
79
|
+
entry << '-'
|
80
|
+
else
|
81
|
+
entry << Element.new('xref')
|
82
|
+
entry.xref[:href] = get_xref
|
83
|
+
entry.xref << field_name
|
84
|
+
end
|
85
|
+
entry
|
86
|
+
end
|
87
|
+
|
88
|
+
def field_name
|
89
|
+
n = field.locate('ipxact:name')
|
90
|
+
n.empty? ? nil : n.first.text
|
91
|
+
end
|
92
|
+
|
93
|
+
def get_xref
|
94
|
+
"NOT_IMPLEMENTED" # TODO
|
95
|
+
end
|
96
|
+
|
97
|
+
def col_end_index
|
98
|
+
ms_pos - word_ct * REGFIG_MAX_ROWBITS
|
99
|
+
end
|
100
|
+
|
101
|
+
def col_start_index
|
102
|
+
ls_pos - word_ct * REGFIG_MAX_ROWBITS + 1
|
103
|
+
end
|
104
|
+
|
105
|
+
def width
|
106
|
+
field.bitWidth.text.to_i
|
107
|
+
end
|
108
|
+
|
109
|
+
def ls_pos
|
110
|
+
field.bitOffset.text.to_i
|
111
|
+
end
|
112
|
+
|
113
|
+
def ms_pos
|
114
|
+
field.bitOffset.text.to_i + field.bitWidth.text.to_i - 1
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
|
3
|
+
require 'con_duxml'
|
4
|
+
require 'ruby-dita'
|
5
|
+
require_relative 'fig_field'
|
6
|
+
|
7
|
+
module Ipxact
|
8
|
+
include Dita
|
9
|
+
include FigField
|
10
|
+
|
11
|
+
# counts number of words of figure generated so far, where size of word is defined by REGFIG_MAX_ROWBITS
|
12
|
+
@word_ct
|
13
|
+
|
14
|
+
attr_reader :word_ct
|
15
|
+
|
16
|
+
# @param opts [Hash] no options currently supported TODO add options for hide access, hide reset value, etc.
|
17
|
+
# @return [Element] visual rendering of register and its fields in Dita table form; content from <ipxact:register/> in @source
|
18
|
+
def reg_fig(opts={})
|
19
|
+
src = source # TODO not sure if this is ideal, but works for now
|
20
|
+
table = Element.new('table')
|
21
|
+
table[:id] = object_id.to_s+"_regFigure"
|
22
|
+
table[:frame] = 'all'
|
23
|
+
table[:outputclass] = 'crr.regFigure regtable'
|
24
|
+
@word_ct = 0
|
25
|
+
input = src.locate(src_ns + ':field')
|
26
|
+
tgroup = nil
|
27
|
+
until input.empty? do
|
28
|
+
field = input.pop
|
29
|
+
index = row_relative_index field
|
30
|
+
if tgroup.nil?
|
31
|
+
tgroup = gen_tgroup
|
32
|
+
table << tgroup
|
33
|
+
end
|
34
|
+
if index > REGFIG_MAX_ROWBITS
|
35
|
+
table << tgroup = gen_tgroup
|
36
|
+
input << field.split do |bit| bit end
|
37
|
+
next
|
38
|
+
else
|
39
|
+
entries = gen_field_entries(field, word_ct)
|
40
|
+
tgroup.tbody.nodes[1] << entries.first
|
41
|
+
tgroup.tbody.nodes[2] << entries[1] if entries.size > 2
|
42
|
+
tgroup.tbody.nodes[3] << entries.last if entries.last.is_a?(Array)
|
43
|
+
end
|
44
|
+
if field_pos(field) == 0 || index >= REGFIG_MAX_ROWBITS
|
45
|
+
@word_ct += 1 unless field_pos(field) == 0
|
46
|
+
end
|
47
|
+
end
|
48
|
+
table
|
49
|
+
end
|
50
|
+
|
51
|
+
def row_relative_index(field)
|
52
|
+
field_pos(field) + field_width(field) - word_ct*REGFIG_MAX_ROWBITS
|
53
|
+
end
|
54
|
+
|
55
|
+
def small?
|
56
|
+
reg_size < REGFIG_MAX_ROWBITS
|
57
|
+
end
|
58
|
+
|
59
|
+
def large?
|
60
|
+
reg_size > 64
|
61
|
+
end
|
62
|
+
|
63
|
+
def field_pos(field)
|
64
|
+
field.bitOffset.text.to_i
|
65
|
+
end
|
66
|
+
|
67
|
+
def field_width(field)
|
68
|
+
field.bitWidth.text.to_i
|
69
|
+
end
|
70
|
+
|
71
|
+
def gen_tgroup
|
72
|
+
tgroup = Element.new('tgroup')
|
73
|
+
tgroup[:cols] ||= num_cols
|
74
|
+
num_cols.times do |i|
|
75
|
+
tgroup << colspec = Element.new('colspec')
|
76
|
+
colspec[:align] = 'center'
|
77
|
+
colspec[:colname] = i.to_s
|
78
|
+
end
|
79
|
+
|
80
|
+
tgroup << Element.new('tbody')
|
81
|
+
%w(Bits R W Reset).each do |heading|
|
82
|
+
tgroup.tbody << row = Element.new('row')
|
83
|
+
row << Element.new('entry')
|
84
|
+
row.entry << heading
|
85
|
+
end
|
86
|
+
|
87
|
+
set_bit_heading! tgroup.tbody.nodes.first
|
88
|
+
tgroup
|
89
|
+
end
|
90
|
+
|
91
|
+
def set_bit_heading!(bit_row)
|
92
|
+
fig_bit_width.times do |i|
|
93
|
+
bit_row << e = Element.new('entry')
|
94
|
+
e << (fig_bit_width - i-1).to_s
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def reg_size
|
99
|
+
source.size.text.to_i
|
100
|
+
end
|
101
|
+
|
102
|
+
def fig_bit_width
|
103
|
+
REGFIG_MAX_ROWBITS > reg_size ? reg_size : REGFIG_MAX_ROWBITS
|
104
|
+
end
|
105
|
+
|
106
|
+
def bit_range
|
107
|
+
"#{(field_pos(source) + field_width(source) - 1).to_s} - #{field_pos(source).to_s}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def num_cols
|
111
|
+
fig_bit_width+1
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# Copyright (c) 2016 Freescale Semiconductor Inc.
|
2
|
+
PREFIX_HEX = /^('h|0x)[0-9A-Fa-f]+$/
|
3
|
+
POSTFIX_HEX = /^[0-9A-Fa-f]+h$/
|
4
|
+
PREFIX_BIN = /^['0]b[01]+$/
|
5
|
+
POSTFIX_BIN = /^[0-1]+b$/
|
6
|
+
DECIMAL = /^[0-9]+$/
|
7
|
+
NAKED_HEX = /^[0-9A-Fa-f]+$/
|
8
|
+
|
9
|
+
class String
|
10
|
+
# @return [Fixnum] returns base of number represented by this string e.g. '0x0F' => 16
|
11
|
+
def base
|
12
|
+
case self
|
13
|
+
when PREFIX_BIN, POSTFIX_BIN
|
14
|
+
2
|
15
|
+
when PREFIX_HEX, POSTFIX_HEX, NAKED_HEX
|
16
|
+
16
|
17
|
+
when DECIMAL
|
18
|
+
10
|
19
|
+
else
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Fixnum] returns numerical value of string in decimal form
|
25
|
+
def to_dec
|
26
|
+
case self
|
27
|
+
when PREFIX_BIN, PREFIX_HEX then self[2..-1]
|
28
|
+
when POSTFIX_HEX, POSTFIX_BIN then self[0..-2]
|
29
|
+
when DECIMAL, NAKED_HEX then self
|
30
|
+
else
|
31
|
+
raise Exception, "'#{self}' is not a numerical string!"
|
32
|
+
end.to_i(base)
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ipxact-dita
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Kong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: duxml
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.6
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.6
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruby-dita
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.4'
|
41
|
+
description: see README.md
|
42
|
+
email:
|
43
|
+
- peter.kong@nxp.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/ipxact/addr.rb
|
49
|
+
- lib/ipxact/dita/fig_field.rb
|
50
|
+
- lib/ipxact/dita/reg_fig.rb
|
51
|
+
- lib/ipxact/ruby_ext/string.rb
|
52
|
+
- lib/ipxact/vendor_extensions/magillem_ipxact.rb
|
53
|
+
- lib/ipxact.rb
|
54
|
+
homepage: http://www.github.com/Ludocracy/ip-xact
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.9.3
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.8.11
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.0.14.1
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Ruby interface for IP-XACT semiconductor component model including documentation
|
78
|
+
generation
|
79
|
+
test_files: []
|