Autodiscovery of data rate during auto-tune.
[goodfet] / client / GoodFETXSCALE.py
1 #!/usr/bin/env python
2 # GoodFET Client Library
3
4 #
5 # Good luck with alpha / beta code.
6 # Contributions and bug reports welcome.
7 #
8 # NOTE: this is just a hacked up copy of the GoodFETARM.py file
9
10 import sys, binascii, struct
11
12 # Standard verbs
13 READ  = 0x00
14 WRITE = 0x01
15 PEEK  = 0x02
16 POKE  = 0x03
17 SETUP = 0x10
18 START = 0x20
19 STOP  = 0x21
20 CALL  = 0x30
21 EXEC  = 0x31
22 NOK   = 0x7E
23 OK    = 0x7F
24
25 # XSCALE JTAG verbs
26 GET_CHIP_ID         = 0xF1
27
28 from GoodFET import GoodFET
29 from intelhex import IntelHex
30
31 class GoodFETXSCALE(GoodFET):
32
33     """A GoodFET variant for use with XScale processors."""
34
35     XSCALEAPP=0x13;
36     APP=XSCALEAPP;
37  
38     def setup(self):
39         """Move the FET into the JTAG ARM application."""
40         print "Initializing XScale..."
41         self.writecmd(self.APP, SETUP, 0, self.data)
42
43     def start(self):
44         """Start debugging."""
45         print "Staring debug..."
46         self.writecmd(self.APP, START, 0, self.data)
47
48     def stop(self):
49         """Stop debugging."""
50         print "Stopping debug..."
51         self.writecmd(self.APP, STOP, 0, self.data)
52
53     def get_id(self):
54         """Get the Chip ID."""
55         
56         # send the get chip ID command
57         self.writecmd(self.APP, GET_CHIP_ID, 0, [])
58
59         # get the response
60         ident = struct.unpack("<L", "".join(self.data[0:4]))[0]
61
62         version = ident >> 28
63         part_number = (ident >> 12) & 0x10
64         manufacturer = ident & 0xFFF
65
66         print "XScale ID --\n\tmfg: %x\n\tpart: %x\n\tver: %x\n\t(%x)" % (version, part_number, manufacturer, ident)
67
68         return ident
69     
70