aboutsummaryrefslogtreecommitdiff
path: root/src/include/jtagtap.h
blob: 9fe3e0dda8e07ff5e2db0b24c3f857caeba62246 (plain)
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
/*
 * This file is part of the Black Magic Debug project.
 *
 * Copyright (C) 2011  Black Sphere Technologies Ltd.
 * Written by Gareth McMullin <gareth@blacksphere.co.nz>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __JTAGTAP_H
#define __JTAGTAP_H

#include "general.h"

/* Note: Signal names are as for the device under test. */

int jtagtap_init(void);

void jtagtap_reset(void);

void jtagtap_srst(void);

uint8_t jtagtap_next(const uint8_t TMS, const uint8_t TDI);
/* tap_next executes one state transision in the JTAG TAP state machine:
 * - Ensure TCK is low
 * - Assert the values of TMS and TDI
 * - Assert TCK (TMS and TDO are latched on rising edge
 * - Caputure the value on TDO
 * - Release TCK.
 */

void jtagtap_tms_seq(uint32_t MS, int ticks);
void jtagtap_tdi_tdo_seq(uint8_t *DO, const uint8_t final_tms, const uint8_t *DI, int ticks);
void jtagtap_tdi_seq(const uint8_t final_tms, const uint8_t *DI, int ticks);
/* Shift out a sequence on MS and DI, capture data to DO.
 * - This is not endian safe: First byte will always be first shifted out. 
 * - DO may be NULL to ignore captured data. 
 * - DO may be point to the same address as DI. 
 */

/* generic soft reset: 1, 1, 1, 1, 1, 0 */
#define jtagtap_soft_reset()	\
	jtagtap_tms_seq(0x1F, 6)

/* Goto Shift-IR: 1, 1, 0, 0 */
#define jtagtap_shift_ir()		\
	jtagtap_tms_seq(0x03, 4)

/* Goto Shift-DR: 1, 0, 0 */
#define jtagtap_shift_dr()		\
	jtagtap_tms_seq(0x01, 3)

/* Goto Run-test/Idle: 1, 1, 0 */
#define jtagtap_return_idle()	\
	jtagtap_tms_seq(0x01, 2)

#endif