Module: OrigenDebuggers::JLink::Common_API

Included in:
OrigenDebuggers::JLink
Defined in:
lib/origen_debuggers/j_link.rb

Overview

All debuggers should try and support these methods

Instance Method Summary collapse

Instance Method Details

#delay(cycles) ⇒ Object



212
213
214
# File 'lib/origen_debuggers/j_link.rb', line 212

def delay(cycles)
  dw "Sleep #{cycles_to_ms(cycles)}"
end

#extract_address(reg_or_val, options = {}) ⇒ Object

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.



317
318
319
320
321
322
323
# File 'lib/origen_debuggers/j_link.rb', line 317

def extract_address(reg_or_val, options = {})
  addr = options[:addr] || options[:address]
  return addr if addr
  addr = reg_or_val.address if reg_or_val.respond_to?(:address)
  fail 'You must supply an :address option if not providing a register!' unless addr
  addr
end

#extract_data(reg_or_val, options = {}) ⇒ Object

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.



310
311
312
313
314
# File 'lib/origen_debuggers/j_link.rb', line 310

def extract_data(reg_or_val, options = {})
  return options[:data] if options[:data]
  return reg_or_val.data if reg_or_val.respond_to?(:data)
  reg_or_val
end

#extract_size(reg_or_val, options = {}) ⇒ Object

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.



295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'lib/origen_debuggers/j_link.rb', line 295

def extract_size(reg_or_val, options = {})
  size = options[:size] if options[:size]
  unless size
    if reg_or_val.respond_to?(:contains_bits?) && reg_or_val.contains_bits?
      size = reg_or_val.size
    end
  end
  fail 'You must supply an :size option if not providing a register!' unless size
  unless [8, 16, 32].include?(size)
    fail 'Only a size of 8, 16 or 32 is supported!'
  end
  size
end

#read(reg_or_val, options = {}) ⇒ Object Also known as: read_register



221
222
223
# File 'lib/origen_debuggers/j_link.rb', line 221

def read(reg_or_val, options = {})
  send("read#{extract_size(reg_or_val, options)}".to_sym, reg_or_val, options)
end

#read16(data, options = {}) ⇒ Object Also known as: read_word, read_16

Read 16 bits of data to the given byte address



234
235
236
# File 'lib/origen_debuggers/j_link.rb', line 234

def read16(data, options = {})
  read_memory(extract_address(data, options), number: 2)
end

#read32(data, options = {}) ⇒ Object Also known as: read_longword, read_32

Read 32 bits of data to the given byte address

data can be array of registers, if array of data then will auto-incrememnt address



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/origen_debuggers/j_link.rb', line 243

def read32(data, options = {})
  options = { optimize: false,   # whether to use a single command to do the read
              # user may care regarding endianness
              size:     32,        # size of each item in bits
              number:   1,        # default number of items
  }.merge(options)
  options[:optimize] = options[:optimized] if options[:optimized]

  if data.is_a?(Array)
    if options[:optimize]
      # for optimized option assume single starting address for data in array
      read_memory(extract_address(data, options), size: options[:size], number: data.length)
    else
      data.each_index do |i|
        data_item = data[i]
        # do separate writes for each 32-bit word
        read_memory(extract_address(data_item, options) + i * (options[:size] / 8), size: options[:size])
      end
    end
  else
    if options[:optimize]
      read_memory(extract_address(data, options), size: options[:size], number: options[:number])
    else
      read_memory(extract_address(data, options), number: (options[:size] / 8))
    end
  end
end

#read8(data, options = {}) ⇒ Object Also known as: read_byte, read_8

Read 8 bits of data to the given byte address



227
228
229
# File 'lib/origen_debuggers/j_link.rb', line 227

def read8(data, options = {})
  read_memory(extract_address(data, options), number: 1)
end

#write(reg_or_val, options = {}) ⇒ Object Also known as: write_register



216
217
218
# File 'lib/origen_debuggers/j_link.rb', line 216

def write(reg_or_val, options = {})
  send("write#{extract_size(reg_or_val, options)}".to_sym, reg_or_val, options)
end

#write16(data, options = {}) ⇒ Object Also known as: write_word, write_16

Write 16 bits of data to the given byte address



281
282
283
# File 'lib/origen_debuggers/j_link.rb', line 281

def write16(data, options = {})
  dw "w2 0x#{extract_address(data, options).to_s(16).upcase}, 0x#{extract_data(data, options).to_s(16).upcase}"
end

#write32(data, options = {}) ⇒ Object Also known as: write_longword, write_32

Write 32 bits of data to the given byte address



288
289
290
# File 'lib/origen_debuggers/j_link.rb', line 288

def write32(data, options = {})
  dw "w4 0x#{extract_address(data, options).to_s(16).upcase}, 0x#{extract_data(data, options).to_s(16).upcase}"
end

#write8(data, options = {}) ⇒ Object Also known as: write_byte, write_8

Write 8 bits of data to the given byte address



274
275
276
# File 'lib/origen_debuggers/j_link.rb', line 274

def write8(data, options = {})
  dw "w1 0x#{extract_address(data, options).to_s(16).upcase}, 0x#{extract_data(data, options).to_s(16).upcase}"
end