Firmware compiles in Ubuntu 11.10.
[goodfet] / firmware / apps / jtag / jtagxscale.c
1 /*! 
2   \file jtagxscale.c
3   \author Dave Huseby <dave@linuxprogrammer.org>
4   \brief Intel XScale JTAG
5 */
6
7 #include "platform.h"
8 #include "command.h"
9 #include "jtag.h"
10 #include "jtagxscale.h"
11
12 #define JTAGXSCALE_APP
13
14 /* Handles XScale JTAG commands.  Forwards others to JTAG. */
15 void jtag_xscale_handle_fn( uint8_t const app,
16                                                         uint8_t const verb,
17                                                         uint32_t const len);
18
19 // define the jtag xscale app's app_t
20 app_t const jtagxscale_app = {
21
22         /* app number */
23         JTAGXSCALE,
24
25         /* handle fn */
26         jtag_xscale_handle_fn,
27
28         /* name */
29         "JTAG XScale",
30
31         /* desc */
32         "\tThe JTAG Xscale app extends the JTAG app adding support\n"
33         "\tfor JTAG'ing Intel XScale devices.\n"
34 };
35
36
37 /* From the Intel XScale Core Developer's Manual:
38  *
39  * The Intel XScale® core provides test features compatible with IEEE Standard
40  * Test Access Port and Boundary Scan Architecture (IEEE Std. 1149.1). These 
41  * features include a TAP controller, a 5 or 7 bit instruction register, and 
42  * test data registers to support software debug. The size of the instruction 
43  * register depends on which variant of the Intel XScale® core is being used.
44  * This can be found out by examining the CoreGen field of Coprocessor 15, ID 
45  * Register (bits 15:13). (See Table 7-4, "ID Register" on page 7-81 for more 
46  * details.) A CoreGen value of 0x1 means the JTAG instruction register size 
47  * is 5 bits and a CoreGen value of 0x2 means the JTAG instruction register 
48  * size is 7 bits.
49  *
50  */
51
52 /* NOTE: I heavily cribbed from the ARM7TDMI jtag implementation. Credit where
53  * credit is due. */
54
55 void jtag_xscale_reset_cpu(void)
56 {
57         SETRST;
58         msdelay(100);
59         CLRRST;
60         msdelay(100);
61         SETRST;
62         msdelay(100);
63 }
64
65 /* Handles XScale JTAG commands.  Forwards others to JTAG. */
66 void jtag_xscale_handle_fn( uint8_t const app,
67                                                         uint8_t const verb,
68                                                         uint32_t const len)
69 {        
70         switch(verb) 
71         {
72         case SETUP:
73                 /* set up the pin I/O for JTAG */
74                 jtag_setup();
75                 /* reset to run-test-idle state */
76                 jtag_reset_tap();
77                 /* send back OK */
78                 txdata(app, verb, 0);
79                 break;
80
81         case START:
82                 txdata(app, verb, 0);
83                 break;
84
85         case STOP:
86                 txdata(app, verb, 0);
87                 break;
88
89         case PEEK:
90         case POKE:
91         case READ:
92         case WRITE:
93                 /* send back OK */
94                 txdata(app, verb, 0);
95                 break;
96
97         case JTAG_RESET_TARGET:
98                 jtag_xscale_reset_cpu();
99                 txdata(app, verb, 0);
100                 break;
101
102         default:
103                 (*(jtag_app.handle))(app,verb,len);
104                 break;
105         }
106 }