origen_swd 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84a8d00eb4a930a2237960e03ce260a28bc06e62
4
- data.tar.gz: 7975842c9f9a94a54f7cb8840479e068ac479bdb
3
+ metadata.gz: e19e934c3c7bbb7092cad11d2d69b97be46ee52e
4
+ data.tar.gz: 07ff3368c8d0e9ed1904a81602d8d0a52c7a1399
5
5
  SHA512:
6
- metadata.gz: acfb25bc69ef384ad2fecbdb181a149f98142903bf96e2c9c2f5785072def6870854706cdf57cb3d388b0478f3a62c1e62ece59e269885646590811eb851b8c4
7
- data.tar.gz: f9043b7195cb7505fbd2dc1a9743a1e1f4ae8c0ce4e15212ea75c2728865c67e1f7a1268920c3c2266d68f1ddd71ad54d17bf056336a72b22a2ea07fb6ed9ce8
6
+ metadata.gz: a4f9830d179fdaf7fe1f0cb51edf3b9408a2d2d848c8fa695a02de307f50d7504a28bac50dad2006585d99e7a9a1137044e12fe8ce0e54007d7b976406d58eff
7
+ data.tar.gz: 5460db3c0c1388a17f0f5eb1e049f898330c2d56fb7f5c97a151d351580ab41d5d88277cfa2ee96df16abe19ea07e3a887e89ff6e1067a7d1a63c44fd94cd888
data/config/commands.rb CHANGED
@@ -24,6 +24,10 @@ when "examples"
24
24
  # Pattern generator tests
25
25
  ARGV = %w(example -t debug -r approved)
26
26
  load "#{Origen.top}/lib/origen/commands/generate.rb"
27
+ ARGV = %w(example_api -t debug -r approved)
28
+ load "#{Origen.top}/lib/origen/commands/generate.rb"
29
+ ARGV = %w(example_reg -t debug -r approved)
30
+ load "#{Origen.top}/lib/origen/commands/generate.rb"
27
31
 
28
32
  if Origen.app.stats.changed_files == 0 &&
29
33
  Origen.app.stats.new_files == 0 &&
data/config/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module OrigenSWD
2
2
  MAJOR = 0
3
- MINOR = 4
3
+ MINOR = 5
4
4
  BUGFIX = 0
5
5
  DEV = nil
6
6
 
@@ -4,74 +4,305 @@ module OrigenSWD
4
4
  # :swd_dio
5
5
  #
6
6
  class Driver
7
+ REQUIRED_PINS = [:swd_clk, :swd_dio]
8
+
9
+ include Origen::Registers
10
+
7
11
  # Returns the parent object that instantiated the driver, could be
8
12
  # either a DUT object or a protocol abstraction
9
13
  attr_reader :owner
14
+ attr_accessor :trn
10
15
 
11
16
  # Initialize class variables
12
- # owner - parent object
13
- # options - any miscellaneous custom arguments
14
- # Returns nothing.
15
17
  #
16
- # Examples
18
+ # @param [Object] owner Parent object
19
+ # @param [Hash] options Options to customize the operation
17
20
  #
21
+ # @example
22
+ # # Create new SWD::Driver object
18
23
  # DUT.new.swd
19
24
  #
20
25
  def initialize(owner, options = {})
21
26
  @owner = owner
27
+ # validate_pins
28
+
22
29
  @current_apaddr = 0
23
30
  @orundetect = 0
31
+ @trn = 0
32
+ end
33
+
34
+ # Read data from Debug Port or Access Port
35
+ #
36
+ # @param [Integer] ap_dp A single bit indicating whether the Debug Port or the Access Port
37
+ # Register is to be accessed. This bit is 0 for an DPACC access, or 1 for a APACC access
38
+ # @param [Integer, Origen::Register::Reg, Origen::Register::BitCollection, Origen::Register::Bit] reg_or_val
39
+ # Value to be shifted. If a reg/bit collection is supplied this can be pre-marked for
40
+ # read, store or overlay and which will result in the requested action being applied to
41
+ # the cycles corresponding to those bits only (don't care cycles will be generated for the others).
42
+ # @param [Hash] options Options to customize the operation
43
+ def read(ap_dp, reg_or_val, options = {})
44
+ addr = reg_or_val.respond_to?(:address) ? reg_or_val.address : reg_or_val
45
+ send_header(ap_dp, 1, addr) # send read-specific header (rnw = 1)
46
+ receive_acknowledgement
47
+ receive_payload(reg_or_val, options)
48
+ end
49
+
50
+ # Write data to Debug Port or Access Port
51
+ #
52
+ # @param [Integer] ap_dp A single bit indicating whether the Debug Port or the Access Port Register
53
+ # is to be accessed. This bit is 0 for an DPACC access, or 1 for a APACC access
54
+ # @param [Integer, Origen::Register::Reg, Origen::Register::BitCollection, Origen::Register::Bit] reg_or_val
55
+ # Value to be shifted. If a reg/bit collection is supplied this can be pre-marked for
56
+ # read, store or overlay and which will result in the requested action being applied to
57
+ # the cycles corresponding to those bits only (don't care cycles will be generated for the others).
58
+ # @param [Integer] wdata Data to be written
59
+ # @param [Hash] options Options to customize the operation
60
+ def write(ap_dp, reg_or_val, wdata, options = {})
61
+ addr = reg_or_val.respond_to?(:address) ? reg_or_val.address : reg_or_val
62
+ send_header(ap_dp, 0, addr) # send write-specific header (rnw = 0)
63
+ receive_acknowledgement
64
+
65
+ if reg_or_val.respond_to?(:data)
66
+ reg_or_val.data = wdata
67
+ else
68
+ reg_or_val = wdata
69
+ end
70
+ send_payload(reg_or_val, options)
24
71
  end
25
72
 
26
73
  # Sends data stream with SWD protocol
27
- # data - data to be sent
28
- # size - the length of data
29
- # options - any miscellaneous custom arguments
30
- # options[:overlay] - string for pattern label to facilitate pattern overlay
31
- # Returns nothing.
74
+ #
75
+ # @param [Integer] data Data to be sent
76
+ # @param [Integer] size The length of data
77
+ # @param [Hash] options Options to customize the operation
78
+ # @option options [String] :overlay String for pattern label to
79
+ # facilitate pattern overlay
32
80
  def send_data(data, size, options = {})
81
+ # Warn caller that this method is being deprecated
82
+ msg = 'Use swd.write(ap_dp, reg_or_val, wdata, options = {}) instead of send_data(data, size, options = {})'
83
+ Origen.deprecate msg
33
84
  if options.key?(:overlay)
34
85
  $tester.label(options[:overlay])
35
86
  size.times do |bit|
36
- owner.pin(:swd_clk).drive(1)
87
+ swd_clk.drive(1)
37
88
  $tester.label("// SWD Data Pin #{bit}")
38
- owner.pin(:swd_dio).drive(data[bit])
89
+ swd_dio.drive(data[bit])
39
90
  $tester.cycle
40
91
  end
41
- owner.pin(:swd_dio).dont_care
92
+ swd_dio.dont_care
42
93
  else
43
94
  size.times do |bit|
44
- owner.pin(:swd_clk).drive(1)
45
- owner.pin(:swd_dio).drive(data[bit])
95
+ swd_clk.drive(1)
96
+ swd_dio.drive(data[bit])
46
97
  $tester.cycle
47
98
  end
48
- owner.pin(:swd_dio).dont_care
99
+ swd_dio.dont_care
49
100
  end
50
101
  end
51
102
 
52
103
  # Recieves data stream with SWD protocol
53
- # size - the length of data
54
- # options - any miscellaneous custom arguments
55
- # options[:compare_data] - data to be compared, only compared if options is set
56
- # Returns nothing.
104
+ #
105
+ # @param [Integer] size The length of data
106
+ # @param [Hash] options Options to customize the operation
107
+ # @option options [String] :compare_data Data to be compared, only compared
108
+ # if options is set
57
109
  def get_data(size, options = {})
58
- should_store = $dut.pin(:swd_dio).is_to_be_stored?
59
- owner.pin(:swd_dio).dont_care
110
+ # Warn caller that this method is being deprecated
111
+ msg = 'Use swd.read(ap_dp, reg_or_val, options = {}) instead of get_data(size, options = {})'
112
+ Origen.deprecate msg
113
+ should_store = swd_dio.is_to_be_stored?
114
+ swd_dio.dont_care
60
115
  size.times do |bit|
61
116
  $tester.store_next_cycle($dut.pin(:swd_dio)) if should_store
62
- $dut.pin(:swd_dio).assert(options[:compare_data][bit]) if options.key?(:compare_data)
117
+ swd_dio.assert(options[:compare_data][bit]) if options.key?(:compare_data)
63
118
  $tester.cycle
64
119
  end
65
120
  end
66
121
 
67
122
  # Sends specified number of '0' bits
68
- # size - the length of data
69
- # Returns nothing.
123
+ #
124
+ # @param [Integer] size The length of data
70
125
  def swd_dio_to_0(size)
71
- owner.pin(:swd_dio).drive(0)
126
+ swd_dio.drive(0)
72
127
  size.times do |bit|
73
128
  $tester.cycle
74
129
  end
75
130
  end
131
+
132
+ private
133
+
134
+ # Send SWD Packet header
135
+ # ------------------------------------------------------------------------
136
+ # | Start | APnDP | 1 | ADDR[2] | ADDR[3] | Parity | Stop | Park |
137
+ # ------------------------------------------------------------------------
138
+ #
139
+ # @param [Integer] apndp A single bit indicating whether the Debug Port or the Access Port
140
+ # Register is to be accessed. This bit is 0 for an DPACC access, or 1 for a APACC access
141
+ # @param [Integer] rnw A single bit, indicating whether the access is a read or a write.
142
+ # This bit is 0 for a write access, or 1 for a read access.
143
+ # @param [Integer] address Address of register that is being accessed
144
+ def send_header(apndp, rnw, address)
145
+ addr = address >> 2
146
+ parity = apndp ^ rnw ^ (addr >> 3) ^ (addr >> 2) & (0x01) ^ (addr >> 1) & (0x01) ^ addr & 0x01
147
+
148
+ cc 'Header phase'
149
+ swd_clk.drive(1)
150
+ cc 'Send Start Bit'
151
+ swd_dio.drive!(1) # send start bit (always 1)
152
+ cc 'Send APnDP Bit (DP or AP Access Register Bit)'
153
+ swd_dio.drive!(apndp) # send apndp bit
154
+ cc 'Send RnW Bit (read or write bit)'
155
+ swd_dio.drive!(rnw) # send rnw bit
156
+ cc 'Send Address Bits (2 bits)'
157
+ swd_dio.drive!(addr[0]) # send address[2] bit
158
+ swd_dio.drive!(addr[1]) # send address[3] bit
159
+ cc 'Send Parity Bit'
160
+ swd_dio.drive!(parity[0]) # send parity bit
161
+ cc 'Send Stop Bit'
162
+ swd_dio.drive!(0) # send stop bit
163
+ cc 'Send Park Bit'
164
+ swd_dio.drive!(1) # send park bit
165
+ swd_dio.dont_care
166
+ end
167
+
168
+ # Waits appropriate number of cycles for the acknowledgement phase
169
+ def receive_acknowledgement
170
+ cc 'Acknowledge Response phase'
171
+ wait_trn
172
+ swd_dio.dont_care
173
+ $tester.cycle(repeat: 3)
174
+ end
175
+
176
+ # Waits for TRN time delay
177
+ def wait_trn
178
+ swd_dio.drive(1)
179
+ $tester.cycle(repeat: trn + 1)
180
+ end
181
+
182
+ # Get (read) the data payload
183
+ #
184
+ # @param [Integer, Origen::Register::Reg, Origen::Register::BitCollection, Origen::Register::Bit] reg_or_val
185
+ # Value to be read. If a reg/bit collection is supplied this can be pre-marked for
186
+ # read, store or overlay and which will result in the requested action being applied to
187
+ # the cycles corresponding to those bits only (don't care cycles will be generated for the others).
188
+ # @option options [String] :overlay String for pattern label to
189
+ # facilitate pattern overlay
190
+ def receive_payload(reg_or_val, options)
191
+ cc 'Read Data Payload phase'
192
+
193
+ cc 'SWD 32-Bit Read Data Start'
194
+ options[:read] = true
195
+ shift_payload(reg_or_val, options)
196
+
197
+ cc 'SWD 32-Bit Read Data End'
198
+ cc 'Get Read Parity Bit'
199
+ swd_dio.dont_care
200
+ $tester.cycle
201
+ cc 'Send Read ACK bits'
202
+ wait_trn
203
+ end
204
+
205
+ # Send (write) the data payload
206
+ #
207
+ # @param [Integer, Origen::Register::Reg, Origen::Register::BitCollection, Origen::Register::Bit] reg_or_val
208
+ # Value to be written. If a reg/bit collection is supplied this can be pre-marked for
209
+ # read, store or overlay and which will result in the requested action being applied to
210
+ # the cycles corresponding to those bits only (don't care cycles will be generated for the others).
211
+ # @option options [String] :overlay String for pattern label to
212
+ # facilitate pattern overlay
213
+ def send_payload(reg_or_val, options)
214
+ cc 'Write Data Payload phase'
215
+ cc 'Send ACK Bits'
216
+ wait_trn
217
+
218
+ cc 'SWD 32-Bit Write Start'
219
+ options[:read] = false
220
+ shift_payload(reg_or_val, options)
221
+
222
+ cc 'Send Write Parity Bit'
223
+ wdata = reg_or_val.respond_to?(:data) ? reg_or_val.data : reg_or_val
224
+ parity_bit = swd_xor_calc(32, wdata)
225
+ swd_dio.drive!(parity_bit)
226
+ end
227
+
228
+ # Shift the data payload
229
+ #
230
+ # @param [Integer, Origen::Register::Reg, Origen::Register::BitCollection, Origen::Register::Bit] reg_or_val
231
+ # Value to be shifted. If a reg/bit collection is supplied this can be pre-marked for
232
+ # read, store or overlay and which will result in the requested action being applied to
233
+ # the cycles corresponding to those bits only (don't care cycles will be generated for the others).
234
+ # @option options [String] :overlay String for pattern label to
235
+ # facilitate pattern overlay
236
+ def shift_payload(reg_or_val, options)
237
+ cc options[:arm_debug_comment] if options.key?(:arm_debug_comment)
238
+ size = 32 # SWD only used to write to DP and AP registers of ARM Debugger (32 bits)
239
+ contains_bits = (contains_bits?(reg_or_val) || is_a_bit?(reg_or_val))
240
+ if options.key?(:arm_debug_overlay)
241
+ options[:overlay] = options[:arm_debug_overlay]
242
+ options[:overlay_label] = options[:arm_debug_overlay]
243
+ end
244
+ if options.key?(:overlay)
245
+ if options[:overlay_label].nil?
246
+ options[:overlay_label] = options[:overlay]
247
+ $tester.label(options[:overlay_label]) if options.key?(:overlay)
248
+ end
249
+ end
250
+ swd_clk.drive(1)
251
+ size.times do |i|
252
+ if options[:read]
253
+ # If it's a register support bit-wise reads
254
+ if contains_bits
255
+ if reg_or_val[i].is_to_be_stored?
256
+ Origen.tester.store_next_cycle(swd_dio)
257
+ swd_dio.dont_care if Origen.tester.j750?
258
+ elsif reg_or_val[i].has_overlay?
259
+ $tester.label(reg_or_val[i].overlay_str)
260
+ elsif reg_or_val[i].is_to_be_read?
261
+ swd_dio.assert(reg_or_val[i] ? reg_or_val[i] : 0)
262
+ elsif options.key?(:compare_data)
263
+ swd_dio.assert(reg_or_val[i] ? reg_or_val[i] : 0)
264
+ else
265
+ swd_dio.dont_care
266
+ end
267
+ else
268
+ if options.key?(:compare_data)
269
+ swd_dio.assert(reg_or_val[i] ? reg_or_val[i] : 0)
270
+ else
271
+ swd_dio.dont_care
272
+ end
273
+ end
274
+ $tester.cycle
275
+ else
276
+ $tester.label("// SWD Data Pin #{i}") if options.key?(:overlay) && !Origen.mode.simulation?
277
+ swd_dio.drive!(reg_or_val[i])
278
+ end
279
+ end
280
+ # Clear read and similar flags to reflect that the request has just
281
+ # been fulfilled
282
+ reg_or_val.clear_flags if reg_or_val.respond_to?(:clear_flags)
283
+ swd_dio.dont_care
284
+ end
285
+
286
+ # Calculate exclusive OR
287
+ #
288
+ # @param [Integer] size The number of bits in the number
289
+ # @param [Integer] number The number being operated on
290
+ def swd_xor_calc(size, number)
291
+ xor = 0
292
+ size.times do |bit|
293
+ xor ^= (number >> bit) & 0x01
294
+ end
295
+ xor
296
+ end
297
+
298
+ # Provided shortname access to top-level SWD clock pin
299
+ def swd_clk
300
+ owner.pin(:swd_clk)
301
+ end
302
+
303
+ # Provided shortname access to top-level SWD data I/P pin
304
+ def swd_dio
305
+ owner.pin(:swd_dio)
306
+ end
76
307
  end
77
308
  end
@@ -11,23 +11,31 @@ module OrigenSWD
11
11
  include Origen::Pins
12
12
 
13
13
  # Initializes simple dut model with test register and required swd pins
14
- # options - any miscellaneous custom arguments
15
- # Returns nothing.
16
14
  #
17
- # Examples
15
+ # @param [Hash] options Options to customize the operation
18
16
  #
17
+ # @example
19
18
  # $dut = OrigenSWD::DUT.new
20
19
  #
21
20
  def initialize(options = {})
22
- add_reg :test, 0x0, 32, data: { pos: 0, bits: 32 },
23
- bit: { pos: 0 }
21
+ # Sample DPACC register
22
+ add_reg :test, 0x04, 32, data: { pos: 0, bits: 32 },
23
+ bit: { pos: 2 }
24
+
25
+ # Sample DPACC register
26
+ add_reg :select, 0x08, 32, data: { pos: 0, bits: 32 }
27
+
28
+ # Sample APACC register
29
+ add_reg :stat, 0x00, 32, data: { pos: 0, bits: 32 }
30
+ add_reg :control, 0x01, 32, data: { pos: 0, bits: 32 }
31
+
24
32
  add_pin :swd_clk
25
33
  add_pin :swd_dio
26
34
  end
27
35
 
28
36
  # Add any custom startup business here.
29
- # options - any miscellaneous custom arguments
30
- # Returns nothing.
37
+ #
38
+ # @param [Hash] options Options to customize the operation
31
39
  def startup(options = {})
32
40
  $tester.set_timeset('swd', 40)
33
41
  end
@@ -0,0 +1,37 @@
1
+ Pattern.create do
2
+ DP = 0
3
+ AP = 1
4
+ ap_dp = 1
5
+ address = 0x00002020
6
+ wdata = 0xAAAA5555
7
+
8
+
9
+ $dut.swd.write(ap_dp, address, wdata, overlay: 'write_ovl')
10
+ cc 'SWD DIO to 0 for 10 cycles'
11
+ $dut.swd.swd_dio_to_0(10)
12
+ $dut.swd.read(ap_dp, address)
13
+ $dut.swd.swd_dio_to_0(10)
14
+ $dut.swd.read(ap_dp, address, compare_data: wdata)
15
+ $dut.swd.swd_dio_to_0(10)
16
+
17
+ #$dut.reg(:select).data = 0x01000000
18
+ $dut.swd.write(DP, $dut.reg(:select), 0x01000000, arm_debug_overlay: 'select_reg')
19
+ $dut.swd.swd_dio_to_0(10)
20
+ $dut.swd.read(DP, $dut.reg(:select))
21
+ $dut.swd.swd_dio_to_0(10)
22
+
23
+ $dut.swd.write(DP, $dut.reg(:stat), 0x00000032)
24
+ $dut.swd.swd_dio_to_0(10)
25
+ $dut.swd.write(DP, $dut.reg(:control), 0x00000010)
26
+ $dut.swd.swd_dio_to_0(10)
27
+ $dut.swd.read(DP, $dut.reg(:control), r_mask: 'store')
28
+ $dut.swd.swd_dio_to_0(10)
29
+ $dut.swd.read(DP, $dut.reg(:control), compare_data: 0x00000010)
30
+ $dut.swd.swd_dio_to_0(10)
31
+
32
+ $dut.swd.read(DP, $dut.reg(:control), compare_data: 0x00000010)
33
+ $dut.swd.swd_dio_to_0(10)
34
+ $dut.swd.read(DP, $dut.reg(:control), compare_data: 0x00000010)
35
+ $dut.swd.swd_dio_to_0(10)
36
+
37
+ end
@@ -0,0 +1,42 @@
1
+ Pattern.create do
2
+
3
+ swd = $dut.swd
4
+ reg = $dut.reg(:test)
5
+
6
+ def test(msg)
7
+ ss "Test - #{msg}"
8
+ end
9
+
10
+ test "Write to DR register"
11
+ reg.write(0xFF01FF01)
12
+ swd.write(0, reg, 0xFF01FF01)
13
+
14
+ test "Write to DR register with overlay"
15
+ reg.overlay("write_overlay")
16
+ swd.write(0, reg, 0xFF01FF01)
17
+
18
+ test "Write to DR register with single bit overlay"
19
+ reg.overlay(nil)
20
+ reg.bit(:bit).overlay("write_overlay")
21
+ swd.write(0, reg, 0xFF01FF01)
22
+
23
+
24
+ test "Read full DR register"
25
+ cc "Full register (32 bits)"
26
+ reg.read
27
+ swd.read(0, reg)
28
+
29
+ test "Read single bit out of DR register"
30
+ reg.bit(:bit).read
31
+ swd.read(0, reg)
32
+
33
+ test "Store full DR register"
34
+ cc "Full register (32 bits)"
35
+ reg.store
36
+ swd.read(0, reg)
37
+
38
+ test "Store single bit out of DR register"
39
+ reg.bit(:bit).store
40
+ swd.read(0, reg)
41
+
42
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: origen_swd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ronnie Lajaunie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-19 00:00:00.000000000 Z
11
+ date: 2015-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: origen
@@ -55,6 +55,8 @@ files:
55
55
  - lib/origen_swd/driver.rb
56
56
  - lib/origen_swd/dut.rb
57
57
  - pattern/example.rb
58
+ - pattern/example_api.rb
59
+ - pattern/example_reg.rb
58
60
  - templates/web/index.md.erb
59
61
  - templates/web/layouts/_basic.html.erb
60
62
  - templates/web/partials/_navbar.html.erb