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.
-
#has_start_record ⇒ Object
Returns true if a start (jump address) record exists.
-
#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
84 85 86 |
# File 'lib/origen_memory_image/base.rb', line 84 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
74 75 76 77 78 79 80 81 82 |
# File 'lib/origen_memory_image/base.rb', line 74 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 |
#has_start_record ⇒ Object
Returns true if a start (jump address) record exists
20 21 22 23 24 |
# File 'lib/origen_memory_image/base.rb', line 20 def has_start_record start_address unless @start_address @start_record_found = false if @start_record_found.nil? @start_record_found end |
#lines ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/origen_memory_image/base.rb', line 88 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/origen_memory_image/base.rb', line 36 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 |