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.



323
324
325
326
327
328
329
# File 'lib/origen_debuggers/j_link.rb', line 323

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.



316
317
318
319
320
# File 'lib/origen_debuggers/j_link.rb', line 316

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.



301
302
303
304
305
306
307
308
309
310
311
312
313
# File 'lib/origen_debuggers/j_link.rb', line 301

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



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

def read(reg_or_val, options = {})
  if reg_or_val.respond_to?(:data)
    cc("[JLink] Read #{reg_or_val.name.upcase} register, address: 0x%06X, expect value: 0x%08X" % [reg_or_val.address, reg_or_val.data])
  end
  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



240
241
242
# File 'lib/origen_debuggers/j_link.rb', line 240

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



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/origen_debuggers/j_link.rb', line 249

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



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

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
219
220
221
# File 'lib/origen_debuggers/j_link.rb', line 216

def write(reg_or_val, options = {})
  if reg_or_val.respond_to?(:data)
    cc("[JLink] Write #{reg_or_val.name.upcase} register, address: 0x%06X with value: 0x%08X" % [reg_or_val.address, reg_or_val.data])
  end
  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



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

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



294
295
296
# File 'lib/origen_debuggers/j_link.rb', line 294

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



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

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