annotate python/utils/adi.py @ 392:bb4289c84907

Added some sort of drop event test
author Windel Bouwman
date Fri, 16 May 2014 13:05:10 +0200
parents 534b94b40aa8
children
rev   line source
144
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
1
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
2 # Implementation of the ADI (ARM Debug Interface) v5 interface.
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
3
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
4 COMPONENT_CLASSES = {0x1: 'ROM table'}
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
5
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
6 class Adi:
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
7 def __init__(self, iface):
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
8 self.iface = iface
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
9 def r32(self, address):
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
10 return self.iface.read_debug32(address)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
11 def w32(self, address, value):
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
12 self.iface.write_debug32(address, value)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
13 def getId(self, offset):
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
14 print('reading id from {0:X}'.format(offset))
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
15 pid4 = self.r32(offset + 0xFD0)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
16 #print('pid4', pid4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
17 pid5 = self.r32(offset + 0xFD4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
18 pid6 = self.r32(offset + 0xFD8)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
19 pid7 = self.r32(offset + 0xFDC)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
20 pid0 = self.r32(offset + 0xFE0)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
21 pid1 = self.r32(offset + 0xFE4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
22 pid2 = self.r32(offset + 0xFE8)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
23 pid3 = self.r32(offset + 0xFEC)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
24 cid0 = self.r32(offset + 0xFF0)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
25 cid1 = self.r32(offset + 0xFF4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
26 cid2 = self.r32(offset + 0xFF8)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
27 cid3 = self.r32(offset + 0xFFC)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
28 pids = [pid0, pid1, pid2, pid3, pid4, pid5, pid6, pid7]
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
29 cids = [cid0, cid1, cid2, cid3]
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
30 print('cids:', [hex(x) for x in cids], 'pids', [hex(x) for x in pids])
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
31 valid = cid0 == 0xD and (cid1 & 0xF) == 0x0 and cid2 == 0x5 and cid3 == 0xB1
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
32 if valid:
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
33 component_class = cid1 >> 4
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
34 else:
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
35 print('invalid class')
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
36 component_class = 0
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
37 # TODO: use pids
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
38 return component_class, pids
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
39
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
40 def parseRomTable(self, offset):
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
41 assert (offset & 0xFFF) == 0
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
42 component_class, pid = self.getId(offset)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
43 assert component_class == 1
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
44 print('Component class:', COMPONENT_CLASSES[component_class])
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
45 print('memory also on this bus:', self.r32(offset + 0xFCC))
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
46 idx = 0
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
47 entry = self.r32(offset + idx * 4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
48 while entry != 0:
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
49 #print('Entry: {0:X}'.format(entry))
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
50 entryOffset = entry & 0xFFFFF000
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
51 cls, pids = self.getId((offset + entryOffset) & 0xFFFFFFFF)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
52 print('class:', cls)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
53 if cls == 9:
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
54 print('Debug block found!')
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
55
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
56 idx += 1
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
57 entry = self.r32(offset + idx * 4)
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
58
59a9a499e518 Added adi class
Windel Bouwman
parents:
diff changeset
59