-
Notifications
You must be signed in to change notification settings - Fork 11
/
adiv5.rb
80 lines (67 loc) · 1.65 KB
/
adiv5.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
require 'log'
require 'adiv5-swd'
require 'adiv5-dp'
require 'adiv5-ap'
class Adiv5
class Wait < StandardError
end
class Fault < StandardError
end
def initialize(drv)
@dp = DP.new(drv)
# power up syste + debug
@dp.CTRLSTAT.transact do |dp|
dp.zero!
dp.CDBGPWRUPREQ = true
dp.CSYSPWRUPREQ = true
end
while true
ctrlstat = @dp.CTRLSTAT.dup
break if ctrlstat.CDBGPWRUPACK && ctrlstat.CSYSPWRUPACK
sleep 0.01
end
# don't reset debug, not supposed to be used automatically:
# http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka14761.html
# # reset debug
# @dp.write(:dp, DP::CTRLSTAT, @dp.read(:dp, DP::CTRLSTAT) | DP::CDBGRSTREQ)
# waitflags = DP::CDBGRSTACK
# while @dp.read(:dp, DP::CTRLSTAT) & waitflags != waitflags
# sleep 0.01
# end
# # clear reset
# @dp.write(:dp, DP::CTRLSTAT, @dp.read(:dp, DP::CTRLSTAT) & ~DP::CDBGRSTREQ)
# while @dp.read(:dp, DP::CTRLSTAT) & waitflags == waitflags
# sleep 0.01
# end
Log(:ap, 1){ "all systems up" }
end
def ap(idx)
ap = AP.probe(@dp, idx)
end
def dap
return @dap if @dap
256.times do |apsel|
ap = self.ap(apsel)
if ap
Log(:ap, 1){ "found AP #{apsel}, #{ap.IDR}, mem: #{ap.mem?}" }
if !@dap && ap.mem?
@dap = ap
break;
end
else
Log(:ap, 1){ "no AP on #{apsel}, stopping probe" }
break
end
end
@dap
end
def idcode
return @dp.IDCODE
end
end
if $0 == __FILE__
require 'backend-driver'
p = Adiv5.new(BackendDriver.from_string(ARGV[0]))
require 'pp'
pp p.dap.devs
end