-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathadiv5-dp.rb
More file actions
103 lines (91 loc) · 2.23 KB
/
adiv5-dp.rb
File metadata and controls
103 lines (91 loc) · 2.23 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'register'
require 'log'
class Adiv5
class DP
include Peripheral
register :ABORT, 0 do
bool :ORUNERRCLR, 4
bool :WDERRCLR, 3
bool :STKERRCLR, 2
bool :STKCMPCLR, 1
bool :DAPABORT, 0
end
register :IDCODE, 0 do
unsigned :VERSION, 31..28
unsigned :PARTNO, 27..12
unsigned :DESIGNER, 11..1
bool :SB1, 0
end
register :CTRLSTAT, 4 do
bool :CSYSPWRUPACK, 31
bool :CSYSPWRUPREQ, 30
bool :CDBGPWRUPACK, 29
bool :CDBGPWRUPREQ, 28
bool :CDBGRSTACK, 27
bool :CDBGRSTREQ, 26
unsigned :TRNCNT, 21..12
unsigned :MASKLANE, 11..8
bool :WDATAERR, 7
bool :READOK, 6
bool :STICKYERR, 5
bool :STICKYCMP, 4
unsigned :TRNMODE, 3..2
bool :STICKYORUN, 1
bool :ORUNDETECT, 0
end
register :SELECT, 8 do
unsigned :APSEL, 31..24
unsigned :APBANKSEL, 7..4
bool :CTRLSEL, 0
end
unsigned :RDBUF, 12
def initialize(dp_lower)
@lower = dp_lower
end
def ap_select(apsel, addr)
apbanksel = addr >> 4
return if @last_select == [apsel, apbanksel]
Log(:dp, 3){ "selecting %d:%x" % [apsel, apbanksel] }
self.SELECT.transact do |select|
select.zero!
select.APSEL = apsel
select.APBANKSEL = apbanksel
end
@last_select = [apsel, apbanksel]
end
def read(port, addr, opt={})
begin
v = @lower.read(port, addr, opt)
rescue Adiv5::Fault
Log(:dp, 3){ "fault" }
self.ABORT.transact do |a|
a.zero!
a.STKERRCLR = 1
end
raise
end
Log(:dp, 2){ "read %s %08x < %s" % [port, addr, Log.hexary(v)] }
v
end
def write(port, addr, val)
Log(:dp, 2){ "write %s %08x = %s" % [port, addr, Log.hexary(val)] }
begin
@lower.write(port, addr, val)
rescue Adiv5::Fault
Log(:dp, 3) { "fault" }
# XXX error might come from previous buffered write?
self.ABORT.transact do |a|
a.zero!
a.STKERRCLR = 1
end
raise
end
end
def get_backing(offset)
read(:dp, offset)
end
def set_backing(offset, val)
write(:dp, offset, val)
end
end
end