origen_link 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,78 +1,78 @@
1
- require 'sinatra/base'
2
- module OrigenLink
3
- class Listener < Sinatra::Base
4
- def self.port
5
- @port || 20_020
6
- end
7
-
8
- def self.environment
9
- @environment || :production
10
- end
11
-
12
- def self.target_object
13
- @target_object || dut
14
- end
15
-
16
- def self.run!(options = {})
17
- @port = options[:port]
18
- @environment = options[:environment]
19
- @target_object = options[:dut]
20
- super
21
- end
22
-
23
- def target_object
24
- self.class.target_object
25
- end
26
-
27
- def expand_path(path)
28
- path.split('.').each do |p|
29
- if p =~ /(.*)\[(\d+)(:(\d+))?\]$/
30
- msb = Regexp.last_match(2).to_i
31
- lsb = Regexp.last_match(4).to_i if Regexp.last_match(4)
32
- yield Regexp.last_match(1)
33
- if lsb
34
- yield '[]', msb..lsb
35
- else
36
- yield '[]', msb
37
- end
38
- else
39
- yield p
40
- end
41
- end
42
- end
43
-
44
- get '/hello_world' do
45
- 'Hello there'
46
- end
47
-
48
- get '/dut_class' do
49
- target_object.class.to_s
50
- end
51
-
52
- post '/register' do
53
- t = target_object
54
- expand_path(params[:path]) do |method, arg|
55
- if arg
56
- t = t.send(method, arg)
57
- else
58
- t = t.send(method)
59
- end
60
- end
61
- t.write!(params[:data].to_i)
62
- nil
63
- end
64
-
65
- get '/register' do
66
- t = target_object
67
- expand_path(params[:path]) do |method, arg|
68
- if arg
69
- t = t.send(method, arg)
70
- else
71
- t = t.send(method)
72
- end
73
- end
74
- t.sync
75
- t.data.to_s
76
- end
77
- end
78
- end
1
+ require 'sinatra/base'
2
+ module OrigenLink
3
+ class Listener < Sinatra::Base
4
+ def self.port
5
+ @port || 20_020
6
+ end
7
+
8
+ def self.environment
9
+ @environment || :production
10
+ end
11
+
12
+ def self.target_object
13
+ @target_object || dut
14
+ end
15
+
16
+ def self.run!(options = {})
17
+ @port = options[:port]
18
+ @environment = options[:environment]
19
+ @target_object = options[:dut]
20
+ super
21
+ end
22
+
23
+ def target_object
24
+ self.class.target_object
25
+ end
26
+
27
+ def expand_path(path)
28
+ path.split('.').each do |p|
29
+ if p =~ /(.*)\[(\d+)(:(\d+))?\]$/
30
+ msb = Regexp.last_match(2).to_i
31
+ lsb = Regexp.last_match(4).to_i if Regexp.last_match(4)
32
+ yield Regexp.last_match(1)
33
+ if lsb
34
+ yield '[]', msb..lsb
35
+ else
36
+ yield '[]', msb
37
+ end
38
+ else
39
+ yield p
40
+ end
41
+ end
42
+ end
43
+
44
+ get '/hello_world' do
45
+ 'Hello there'
46
+ end
47
+
48
+ get '/dut_class' do
49
+ target_object.class.to_s
50
+ end
51
+
52
+ post '/register' do
53
+ t = target_object
54
+ expand_path(params[:path]) do |method, arg|
55
+ if arg
56
+ t = t.send(method, arg)
57
+ else
58
+ t = t.send(method)
59
+ end
60
+ end
61
+ t.write!(params[:data].to_i)
62
+ nil
63
+ end
64
+
65
+ get '/register' do
66
+ t = target_object
67
+ expand_path(params[:path]) do |method, arg|
68
+ if arg
69
+ t = t.send(method, arg)
70
+ else
71
+ t = t.send(method)
72
+ end
73
+ end
74
+ t.sync
75
+ t.data.to_s
76
+ end
77
+ end
78
+ end
@@ -1,251 +1,251 @@
1
- require 'origen_link/server/pin'
2
-
3
- module OrigenLink
4
- module Server
5
- class Jtag
6
- attr_reader :tdoval
7
- attr_accessor :verbose_enable
8
- attr_accessor :anytdofail
9
-
10
- def initialize(tdiio = 116, tdoio = 124, tmsio = 6, tckio = 119)
11
- @tdipin = Pin.new(tdiio, :out)
12
- @tdopin = Pin.new(tdoio, :in)
13
- @tmspin = Pin.new(tmsio, :out)
14
- @tckpin = Pin.new(tckio, :out)
15
- @tdoval = 0
16
- @tdostr = ''
17
- @verbose_enable = true
18
- @anytdofail = false
19
- @pins = {}
20
- end
21
-
22
- def destroy
23
- @tdipin.destroy
24
- @tdopin.destroy
25
- @tmspin.destroy
26
- @tckpin.destroy
27
- @tdipin = nil
28
- @tdopin = nil
29
- @tmspin = nil
30
- @tckpin = nil
31
- @pins.each_value(&:destroy)
32
- end
33
-
34
- def do_cycle(tdival, tmsval, capturetdo = false)
35
- @tdipin.out(tdival)
36
- @tmspin.out(tmsval)
37
-
38
- @tckpin.out(1)
39
-
40
- if capturetdo
41
- @tdostr = @tdopin.in + @tdostr
42
- end
43
- @tckpin.out(0)
44
- end
45
-
46
- def do_tlr
47
- 8.times { do_cycle(0, 1) }
48
- do_cycle(0, 0)
49
- end
50
-
51
- def do_shift(numbits, value, capturetdo = false, suppresscomments = false, tdocompare = '')
52
- @tdoval = 0
53
- @tdostr = ''
54
- (numbits - 1).times do |bit|
55
- do_cycle(value[bit], 0, capturetdo)
56
- end
57
- do_cycle(value[numbits - 1], 1, capturetdo)
58
-
59
- @tdoval = @tdostr.to_i(2) if capturetdo
60
-
61
- if !(suppresscomments) && @verbose_enable && capturetdo
62
- puts 'TDO output = 0x' + @tdoval.to_s(16)
63
- end
64
-
65
- if capturetdo && tdocompare != ''
66
- thiscomparefail = false
67
- numbits.times do |bit|
68
- if tdocompare[numbits - 1 - bit] == 'H'
69
- compareval = 1
70
- elsif tdocompare[numbits - 1 - bit] == 'L'
71
- compareval = 0
72
- else
73
- compareval = @tdoval[bit]
74
- end
75
-
76
- if @tdoval[bit] != compareval
77
- @anytdofail = true
78
- thiscomparefail = true
79
- end
80
- end
81
-
82
- tdovalstr = @tdoval.to_s(2)
83
- tdovalstr = '0' * (numbits - tdovalstr.length) + tdovalstr
84
- end
85
- end
86
-
87
- def do_ir(numbits, value, options = {})
88
- defaults = {
89
- capturetdo: false,
90
- suppresscomments: false,
91
- tdocompare: ''
92
- }
93
- options = defaults.merge(options)
94
-
95
- if options[:tdocompare] != ''
96
- capturetdo = true
97
- else
98
- capturetdo = options[:capturetdo]
99
- end
100
-
101
- # Assume starting from run test idle
102
- # Advance to shift IR
103
- do_cycle(0, 1)
104
- do_cycle(0, 1)
105
- do_cycle(0, 0)
106
- do_cycle(0, 0)
107
-
108
- do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])
109
-
110
- # Return to run test idle
111
- do_cycle(0, 1)
112
- do_cycle(0, 0)
113
- end
114
-
115
- def do_dr(numbits, value, options = {})
116
- defaults = {
117
- capturetdo: true,
118
- suppresscomments: false,
119
- tdocompare: ''
120
- }
121
- options = defaults.merge(options)
122
-
123
- if options[:tdocompare] != ''
124
- capturetdo = true
125
- else
126
- capturetdo = options[:tdocompare]
127
- end
128
-
129
- # Assume starting from run test idle
130
- # Advance to shift DR
131
- do_cycle(0, 1)
132
- do_cycle(0, 0)
133
- do_cycle(0, 0)
134
-
135
- do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])
136
-
137
- # Return to run test idle
138
- do_cycle(0, 1)
139
- do_cycle(0, 0)
140
- end
141
-
142
- def pause_dr
143
- do_cycle(0, 1)
144
- do_cycle(0, 0)
145
- do_cycle(0, 0)
146
- do_cycle(0, 1)
147
- do_cycle(0, 0)
148
- do_cycle(0, 1)
149
- do_cycle(0, 1)
150
- do_cycle(0, 0)
151
- end
152
-
153
- def pause_ir
154
- do_cycle(0, 1)
155
- pause_dr
156
- end
157
-
158
- def read_adc(csl)
159
- channel_list = csl.split(',')
160
- response = ''
161
- channel_list.each do |channel|
162
- file_name = '/sys/bus/iio/devices/'
163
- case channel
164
- when 'A0'
165
- file_name = file_name + 'iio:device0/in_voltage0_raw'
166
- when 'A1'
167
- file_name = file_name + 'iio:device0/in_voltage1_raw'
168
- when 'A2'
169
- file_name = file_name + 'iio:device0/in_voltage2_raw'
170
- when 'A3'
171
- file_name = file_name + 'iio:device0/in_voltage3_raw'
172
- when 'A4'
173
- file_name = file_name + 'iio:device1/in_voltage0_raw'
174
- when 'A5'
175
- file_name = file_name + 'iio:device1/in_voltage1_raw'
176
- end
177
- response = response + ',' unless response.size == 0
178
- if File.exist?(file_name)
179
- File.open(file_name, 'r') do |file|
180
- reading = file.gets
181
- response = response + reading.strip
182
- end
183
- else
184
- response = response + '-1'
185
- end
186
- end
187
- response
188
- end
189
-
190
- def processmessage(message)
191
- message.strip!
192
- split_message = message.split(':')
193
- response = ''
194
- case split_message[0]
195
- when 'jtag_ir'
196
- args = split_message[1].split(',')
197
- do_ir(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
198
- response = @tdoval.to_s(16)
199
- when 'jtag_dr'
200
- args = split_message[1].split(',')
201
- do_dr(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
202
- response = @tdoval.to_s(16)
203
- when 'jtag_pause_dr'
204
- pause_dr
205
- response = 'done'
206
- when 'jtag_pause_ir'
207
- pause_ir
208
- response = 'done'
209
- when 'jtag_reset'
210
- do_tlr
211
- response = 'done'
212
- when 'jtag_pin_set'
213
- pinlist = split_message[1].split(',')
214
- pinlist.each do |pin|
215
- @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
216
- @pins[pin].out(1)
217
- end
218
- response = 'done'
219
- when 'jtag_pin_clear'
220
- pinlist = split_message[1].split(',')
221
- pinlist.each do |pin|
222
- @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
223
- @pins[pin].out(0)
224
- end
225
- response = 'done'
226
- when 'jtag_pin_read'
227
- pinlist = split_message[1].split(',')
228
- pinlist.each do |pin|
229
- @pins[pin] = Pin.new(pin, :in) unless @pins.key?(pin)
230
- response = response + @pins[pin].in
231
- end
232
- response
233
- when 'jtag_adc_read'
234
- response = read_adc(split_message[1])
235
- response
236
- end
237
- end
238
-
239
- def string_to_val(base_indicator, numstr)
240
- case base_indicator
241
- when 'h'
242
- numstr.to_i(16)
243
- when 'd'
244
- numstr.to_i(10)
245
- when 'b'
246
- numstr.to_i(2)
247
- end
248
- end
249
- end
250
- end
251
- end
1
+ require 'origen_link/server/pin'
2
+
3
+ module OrigenLink
4
+ module Server
5
+ class Jtag
6
+ attr_reader :tdoval
7
+ attr_accessor :verbose_enable
8
+ attr_accessor :anytdofail
9
+
10
+ def initialize(tdiio = 116, tdoio = 124, tmsio = 6, tckio = 119)
11
+ @tdipin = Pin.new(tdiio, :out)
12
+ @tdopin = Pin.new(tdoio, :in)
13
+ @tmspin = Pin.new(tmsio, :out)
14
+ @tckpin = Pin.new(tckio, :out)
15
+ @tdoval = 0
16
+ @tdostr = ''
17
+ @verbose_enable = true
18
+ @anytdofail = false
19
+ @pins = {}
20
+ end
21
+
22
+ def destroy
23
+ @tdipin.destroy
24
+ @tdopin.destroy
25
+ @tmspin.destroy
26
+ @tckpin.destroy
27
+ @tdipin = nil
28
+ @tdopin = nil
29
+ @tmspin = nil
30
+ @tckpin = nil
31
+ @pins.each_value(&:destroy)
32
+ end
33
+
34
+ def do_cycle(tdival, tmsval, capturetdo = false)
35
+ @tdipin.out(tdival)
36
+ @tmspin.out(tmsval)
37
+
38
+ @tckpin.out(1)
39
+
40
+ if capturetdo
41
+ @tdostr = @tdopin.in + @tdostr
42
+ end
43
+ @tckpin.out(0)
44
+ end
45
+
46
+ def do_tlr
47
+ 8.times { do_cycle(0, 1) }
48
+ do_cycle(0, 0)
49
+ end
50
+
51
+ def do_shift(numbits, value, capturetdo = false, suppresscomments = false, tdocompare = '')
52
+ @tdoval = 0
53
+ @tdostr = ''
54
+ (numbits - 1).times do |bit|
55
+ do_cycle(value[bit], 0, capturetdo)
56
+ end
57
+ do_cycle(value[numbits - 1], 1, capturetdo)
58
+
59
+ @tdoval = @tdostr.to_i(2) if capturetdo
60
+
61
+ if !(suppresscomments) && @verbose_enable && capturetdo
62
+ puts 'TDO output = 0x' + @tdoval.to_s(16)
63
+ end
64
+
65
+ if capturetdo && tdocompare != ''
66
+ thiscomparefail = false
67
+ numbits.times do |bit|
68
+ if tdocompare[numbits - 1 - bit] == 'H'
69
+ compareval = 1
70
+ elsif tdocompare[numbits - 1 - bit] == 'L'
71
+ compareval = 0
72
+ else
73
+ compareval = @tdoval[bit]
74
+ end
75
+
76
+ if @tdoval[bit] != compareval
77
+ @anytdofail = true
78
+ thiscomparefail = true
79
+ end
80
+ end
81
+
82
+ tdovalstr = @tdoval.to_s(2)
83
+ tdovalstr = '0' * (numbits - tdovalstr.length) + tdovalstr
84
+ end
85
+ end
86
+
87
+ def do_ir(numbits, value, options = {})
88
+ defaults = {
89
+ capturetdo: false,
90
+ suppresscomments: false,
91
+ tdocompare: ''
92
+ }
93
+ options = defaults.merge(options)
94
+
95
+ if options[:tdocompare] != ''
96
+ capturetdo = true
97
+ else
98
+ capturetdo = options[:capturetdo]
99
+ end
100
+
101
+ # Assume starting from run test idle
102
+ # Advance to shift IR
103
+ do_cycle(0, 1)
104
+ do_cycle(0, 1)
105
+ do_cycle(0, 0)
106
+ do_cycle(0, 0)
107
+
108
+ do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])
109
+
110
+ # Return to run test idle
111
+ do_cycle(0, 1)
112
+ do_cycle(0, 0)
113
+ end
114
+
115
+ def do_dr(numbits, value, options = {})
116
+ defaults = {
117
+ capturetdo: true,
118
+ suppresscomments: false,
119
+ tdocompare: ''
120
+ }
121
+ options = defaults.merge(options)
122
+
123
+ if options[:tdocompare] != ''
124
+ capturetdo = true
125
+ else
126
+ capturetdo = options[:tdocompare]
127
+ end
128
+
129
+ # Assume starting from run test idle
130
+ # Advance to shift DR
131
+ do_cycle(0, 1)
132
+ do_cycle(0, 0)
133
+ do_cycle(0, 0)
134
+
135
+ do_shift(numbits, value, capturetdo, options[:suppresscomments], options[:tdocompare])
136
+
137
+ # Return to run test idle
138
+ do_cycle(0, 1)
139
+ do_cycle(0, 0)
140
+ end
141
+
142
+ def pause_dr
143
+ do_cycle(0, 1)
144
+ do_cycle(0, 0)
145
+ do_cycle(0, 0)
146
+ do_cycle(0, 1)
147
+ do_cycle(0, 0)
148
+ do_cycle(0, 1)
149
+ do_cycle(0, 1)
150
+ do_cycle(0, 0)
151
+ end
152
+
153
+ def pause_ir
154
+ do_cycle(0, 1)
155
+ pause_dr
156
+ end
157
+
158
+ def read_adc(csl)
159
+ channel_list = csl.split(',')
160
+ response = ''
161
+ channel_list.each do |channel|
162
+ file_name = '/sys/bus/iio/devices/'
163
+ case channel
164
+ when 'A0'
165
+ file_name = file_name + 'iio:device0/in_voltage0_raw'
166
+ when 'A1'
167
+ file_name = file_name + 'iio:device0/in_voltage1_raw'
168
+ when 'A2'
169
+ file_name = file_name + 'iio:device0/in_voltage2_raw'
170
+ when 'A3'
171
+ file_name = file_name + 'iio:device0/in_voltage3_raw'
172
+ when 'A4'
173
+ file_name = file_name + 'iio:device1/in_voltage0_raw'
174
+ when 'A5'
175
+ file_name = file_name + 'iio:device1/in_voltage1_raw'
176
+ end
177
+ response = response + ',' unless response.size == 0
178
+ if File.exist?(file_name)
179
+ File.open(file_name, 'r') do |file|
180
+ reading = file.gets
181
+ response = response + reading.strip
182
+ end
183
+ else
184
+ response = response + '-1'
185
+ end
186
+ end
187
+ response
188
+ end
189
+
190
+ def processmessage(message)
191
+ message.strip!
192
+ split_message = message.split(':')
193
+ response = ''
194
+ case split_message[0]
195
+ when 'jtag_ir'
196
+ args = split_message[1].split(',')
197
+ do_ir(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
198
+ response = @tdoval.to_s(16)
199
+ when 'jtag_dr'
200
+ args = split_message[1].split(',')
201
+ do_dr(args[2].to_i, string_to_val(args[0], args[1]), capturetdo: true, suppresscomments: true)
202
+ response = @tdoval.to_s(16)
203
+ when 'jtag_pause_dr'
204
+ pause_dr
205
+ response = 'done'
206
+ when 'jtag_pause_ir'
207
+ pause_ir
208
+ response = 'done'
209
+ when 'jtag_reset'
210
+ do_tlr
211
+ response = 'done'
212
+ when 'jtag_pin_set'
213
+ pinlist = split_message[1].split(',')
214
+ pinlist.each do |pin|
215
+ @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
216
+ @pins[pin].out(1)
217
+ end
218
+ response = 'done'
219
+ when 'jtag_pin_clear'
220
+ pinlist = split_message[1].split(',')
221
+ pinlist.each do |pin|
222
+ @pins[pin] = Pin.new(pin, :out) unless @pins.key?(pin)
223
+ @pins[pin].out(0)
224
+ end
225
+ response = 'done'
226
+ when 'jtag_pin_read'
227
+ pinlist = split_message[1].split(',')
228
+ pinlist.each do |pin|
229
+ @pins[pin] = Pin.new(pin, :in) unless @pins.key?(pin)
230
+ response = response + @pins[pin].in
231
+ end
232
+ response
233
+ when 'jtag_adc_read'
234
+ response = read_adc(split_message[1])
235
+ response
236
+ end
237
+ end
238
+
239
+ def string_to_val(base_indicator, numstr)
240
+ case base_indicator
241
+ when 'h'
242
+ numstr.to_i(16)
243
+ when 'd'
244
+ numstr.to_i(10)
245
+ when 'b'
246
+ numstr.to_i(2)
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end