Class: OrigenMemoryImage::Base
- Inherits:
-
Object
- Object
- OrigenMemoryImage::Base
- Defined in:
- lib/origen_memory_image/base.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
- #file_name ⇒ Object
-
#flip_endianness(data, width_in_bytes) ⇒ Object
Reverse the endianness of the given data value, the width of it in bytes must be supplied as the second argument.
-
#initialize(file, options = {}) ⇒ Base
constructor
A new instance of Base.
- #lines ⇒ Object
-
#start_address ⇒ Object
Returns the code execution start address as an int.
-
#to_a(options = {}) ⇒ Object
(also: #to_array)
Returns the s-record as an array of addresses and data.
Constructor Details
#initialize(file, options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 8 9 10 11 12 |
# File 'lib/origen_memory_image/base.rb', line 5 def initialize(file, = {}) if [:source] == String @source = file else @file = file end @ljust_partial_data = [:ljust_partial_data] end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
3 4 5 |
# File 'lib/origen_memory_image/base.rb', line 3 def file @file end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
3 4 5 |
# File 'lib/origen_memory_image/base.rb', line 3 def source @source end |
Instance Method Details
#file_name ⇒ Object
77 78 79 |
# File 'lib/origen_memory_image/base.rb', line 77 def file_name file || 'From source string' end |
#flip_endianness(data, width_in_bytes) ⇒ Object
Reverse the endianness of the given data value, the width of it in bytes must be supplied as the second argument
67 68 69 70 71 72 73 74 75 |
# File 'lib/origen_memory_image/base.rb', line 67 def flip_endianness(data, width_in_bytes) v = 0 width_in_bytes.times do |i| # data[7:0] => data[15:8] start = 8 * i v += data[(start + 7)..start] << ((width_in_bytes - i - 1) * 8) end v end |
#lines ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/origen_memory_image/base.rb', line 81 def lines if file File.readlines(file) else source.split("\n") end end |
#start_address ⇒ Object
Returns the code execution start address as an int
15 16 17 |
# File 'lib/origen_memory_image/base.rb', line 15 def start_address fail "#{self.class} has not implemented the start_address method!" end |
#to_a(options = {}) ⇒ Object Also known as: to_array
Returns the s-record as an array of addresses and data
The output is a 2D array, with each element being an array with element zero being the address of the data and element one being one word of data like this [[ADDR0, DATA0], [ADDR1, DATA1], [ADDR2, DATA2]…]
The block header data and end of block value are not interpreted in any way and the checksum bits are disregarded
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/origen_memory_image/base.rb', line 29 def to_a( = {}) = { flip_endianness: false, data_width_in_bytes: 4, crop: [] }.merge() data = extract_addr_data() if [:crop].count > 0 cropped_data = [] data.each do |addr, data| case [:crop].count when 1 cropped_data.push([addr, data]) if addr >= [:crop][0] when 2 cropped_data.push([addr, data]) if addr >= [:crop][0] && addr <= [:crop][1] else fail 'crop option can only be array of size 1 or 2' end end data = cropped_data end if [:flip_endianness] || [:endianness_change] data.map do |v| [v[0], flip_endianness(v[1], [:data_width_in_bytes])] end else data end end |