Class: OrigenLink::Server::Jtag

Inherits:
Object
  • Object
show all
Defined in:
lib/origen_link/server/jtag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tdiio = 116, tdoio = 124, tmsio = 6, tckio = 119) ⇒ Jtag

Returns a new instance of Jtag.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/origen_link/server/jtag.rb', line 10

def initialize(tdiio = 116, tdoio = 124, tmsio = 6, tckio = 119)
  @tdipin = Pin.new(tdiio, :out)
  @tdopin = Pin.new(tdoio, :in)
  @tmspin = Pin.new(tmsio, :out)
  @tckpin = Pin.new(tckio, :out)
  @tdoval = 0
  @tdostr = ''
  @verbose_enable = true
  @anytdofail = false
  @pins = {}
end

Instance Attribute Details

#anytdofailObject

Returns the value of attribute anytdofail.



8
9
10
# File 'lib/origen_link/server/jtag.rb', line 8

def anytdofail
  @anytdofail
end

#tdovalObject (readonly)

Returns the value of attribute tdoval.



6
7
8
# File 'lib/origen_link/server/jtag.rb', line 6

def tdoval
  @tdoval
end

#verbose_enableObject

Returns the value of attribute verbose_enable.



7
8
9
# File 'lib/origen_link/server/jtag.rb', line 7

def verbose_enable
  @verbose_enable
end

Instance Method Details

#destroyObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/origen_link/server/jtag.rb', line 22

def destroy
  @tdipin.destroy
  @tdopin.destroy
  @tmspin.destroy
  @tckpin.destroy
  @tdipin = nil
  @tdopin = nil
  @tmspin = nil
  @tckpin = nil
  @pins.each_value(&:destroy)
end

#do_cycle(tdival, tmsval, capturetdo = false) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/origen_link/server/jtag.rb', line 34

def do_cycle(tdival, tmsval, capturetdo = false)
  @tdipin.out(tdival)
  @tmspin.out(tmsval)

  @tckpin.out(1)

  if capturetdo
    @tdostr = @tdopin.in + @tdostr
  end
  @tckpin.out(0)
end

#do_dr(numbits, value, options = {}) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/origen_link/server/jtag.rb', line 115

def do_dr(numbits, value, options = {})
  defaults = {
    capturetdo:	      true,
    suppresscomments:	false,
    tdocompare:	      ''
  }
  options = defaults.merge(options)

  if options[:tdocompare] != ''
    capturetdo = true
  else
    capturetdo = options[:tdocompare]
  end

  # Assume starting from run test idle
  # Advance to shift DR
  do_cycle(0, 1)
  do_cycle(0, 0)
  do_cycle(0, 0)

  do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])

  # Return to run test idle
  do_cycle(0, 1)
  do_cycle(0, 0)
end

#do_ir(numbits, value, options = {}) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/origen_link/server/jtag.rb', line 87

def do_ir(numbits, value, options = {})
  defaults = {
    capturetdo:	      false,
    suppresscomments:	false,
    tdocompare:	      ''
  }
  options = defaults.merge(options)

  if options[:tdocompare] != ''
    capturetdo = true
  else
    capturetdo = options[:capturetdo]
  end

  # Assume starting from run test idle
  # Advance to shift IR
  do_cycle(0, 1)
  do_cycle(0, 1)
  do_cycle(0, 0)
  do_cycle(0, 0)

  do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])

  # Return to run test idle
  do_cycle(0, 1)
  do_cycle(0, 0)
end

#do_shift(numbits, value, capturetdo = false, suppresscomments = false, tdocompare = '') ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/origen_link/server/jtag.rb', line 51

def do_shift(numbits, value, capturetdo = false, suppresscomments = false, tdocompare = '')
  @tdoval = 0
  @tdostr = ''
  (numbits - 1).times do |bit|
    do_cycle(value[bit], 0, capturetdo)
  end
  do_cycle(value[numbits - 1], 1, capturetdo)

  @tdoval = @tdostr.to_i(2) if capturetdo

  if !(suppresscomments) && @verbose_enable && capturetdo
    puts 'TDO output = 0x' + @tdoval.to_s(16)
  end

  if capturetdo && tdocompare != ''
    thiscomparefail = false
    numbits.times do |bit|
      if tdocompare[numbits - 1 - bit] == 'H'
        compareval = 1
      elsif tdocompare[numbits - 1 - bit] == 'L'
        compareval = 0
      else
        compareval = @tdoval[bit]
      end

      if @tdoval[bit] != compareval
        @anytdofail = true
        thiscomparefail = true
      end
    end

    tdovalstr = @tdoval.to_s(2)
    tdovalstr = '0' * (numbits - tdovalstr.length) + tdovalstr
  end
end

#do_tlrObject



46
47
48
49
# File 'lib/origen_link/server/jtag.rb', line 46

def do_tlr
  8.times { do_cycle(0, 1) }
  do_cycle(0, 0)
end

#pause_drObject



142
143
144
145
146
147
148
149
150
151
# File 'lib/origen_link/server/jtag.rb', line 142

def pause_dr
  do_cycle(0, 1)
  do_cycle(0, 0)
  do_cycle(0, 0)
  do_cycle(0, 1)
  do_cycle(0, 0)
  do_cycle(0, 1)
  do_cycle(0, 1)
  do_cycle(0, 0)
end

#pause_irObject



153
154
155
156
# File 'lib/origen_link/server/jtag.rb', line 153

def pause_ir
  do_cycle(0, 1)
  pause_dr
end

#processmessage(message) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/origen_link/server/jtag.rb', line 190

def processmessage(message)
  message.strip!
  split_message = message.split(':')
  response = ''
  case split_message[0]
    when 'jtag_ir'
      args = split_message[1].split(',')
      do_ir(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
      response = @tdoval.to_s(16)
    when 'jtag_dr'
      args = split_message[1].split(',')
      do_dr(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
      response = @tdoval.to_s(16)
    when 'jtag_pause_dr'
      pause_dr
      response = 'done'
    when 'jtag_pause_ir'
      pause_ir
      response = 'done'
    when 'jtag_reset'
      do_tlr
      response = 'done'
    when 'jtag_pin_set'
      pinlist = split_message[1].split(',')
      pinlist.each do |pin|
        @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
        @pins[pin].out(1)
      end
      response = 'done'
    when 'jtag_pin_clear'
      pinlist = split_message[1].split(',')
      pinlist.each do |pin|
        @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
        @pins[pin].out(0)
      end
      response = 'done'
    when 'jtag_pin_read'
      pinlist = split_message[1].split(',')
      pinlist.each do |pin|
        @pins[pin] = Pin.new(pin, :in) unless @pins.key?(pin)
        response = response + @pins[pin].in
      end
      response
    when 'jtag_adc_read'
      response = read_adc(split_message[1])
      response
  end
end

#read_adc(csl) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/origen_link/server/jtag.rb', line 158

def read_adc(csl)
  channel_list = csl.split(',')
  response = ''
  channel_list.each do |channel|
    file_name = '/sys/bus/iio/devices/'
    case channel
      when 'A0'
        file_name = file_name + 'iio:device0/in_voltage0_raw'
      when 'A1'
        file_name = file_name + 'iio:device0/in_voltage1_raw'
      when 'A2'
        file_name = file_name + 'iio:device0/in_voltage2_raw'
      when 'A3'
        file_name = file_name + 'iio:device0/in_voltage3_raw'
      when 'A4'
        file_name = file_name + 'iio:device1/in_voltage0_raw'
      when 'A5'
        file_name = file_name + 'iio:device1/in_voltage1_raw'
    end
    response = response + ',' unless response.size == 0
    if File.exist?(file_name)
      File.open(file_name, 'r') do |file|
        reading = file.gets
        response = response + reading.strip
      end
    else
      response = response + '-1'
    end
  end
  response
end

#string_to_val(base_indicator, numstr) ⇒ Object



239
240
241
242
243
244
245
246
247
248
# File 'lib/origen_link/server/jtag.rb', line 239

def string_to_val(base_indicator, numstr)
  case base_indicator
    when 'h'
      numstr.to_i(16)
    when 'd'
      numstr.to_i(10)
    when 'b'
      numstr.to_i(2)
  end
end