1 /* swd.h
2  *
3  * Copyright 2011 Brian Swetland <swetland@frotz.net>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _SWDP_H_
19 #define _SWDP_H_
20 
21 void swd_init(void);
22 void swd_reset(unsigned kind);
23 int swd_write(unsigned reg, unsigned val);
24 int swd_read(unsigned reg, unsigned *val);
25 
26 unsigned swd_set_clock(unsigned khz);
27 unsigned swo_set_clock(unsigned khz);
28 void swd_hw_reset(int assert);
29 
30 void jtag_init(void);
31 int jtag_io(unsigned count, unsigned tms, unsigned tdi, unsigned *tdo);
32 
33 // swdp_read/write() register codes
34 
35 // Park Stop Parity Addr3 Addr2 RnW APnDP Start
36 
37 #define RD_IDCODE   0b10100101
38 #define RD_DPCTRL   0b10001101
39 #define RD_RESEND   0b10010101
40 #define RD_BUFFER   0b10111101
41 
42 #define WR_ABORT    0b10000001
43 #define WR_DPCTRL   0b10101001
44 #define WR_SELECT   0b10110001
45 #define WR_BUFFER   0b10011001
46 
47 #define RD_AP0      0b10000111
48 #define RD_AP1      0b10101111
49 #define RD_AP2      0b10110111
50 #define RD_AP3      0b10011111
51 
52 #define WR_AP0      0b10100011
53 #define WR_AP1      0b10001011
54 #define WR_AP2      0b10010011
55 #define WR_AP3      0b10111011
56 
57 #endif
58 
59