aboutsummaryrefslogtreecommitdiff
path: root/src/include/adiv5.h
blob: a9cacf11508b75d52112dc43c7596dd57cdd9420 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
 * 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 __ADIV5_H
#define __ADIV5_H

#include "general.h"
#include "jtag_scan.h"
#include "target.h"

#define DP_ABORT	0x0
#define DP_CTRLSTAT	0x4
#define DP_SELECT	0x8
#define DP_RDBUFF	0xC


/* Try to keep this somewhat absract for later adding SW-DP */
typedef struct ADIv5_DP_s {
	struct ADIv5_DP_s *next;
	uint32_t idcode;

	void (*dp_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value);
	uint32_t (*dp_read)(struct ADIv5_DP_s *dp, uint8_t addr);

	void (*ap_write)(struct ADIv5_DP_s *dp, uint8_t addr, uint32_t value);
	uint32_t (*ap_read)(struct ADIv5_DP_s *dp, uint8_t addr);

	uint32_t (*error)(struct ADIv5_DP_s *dp);

	uint32_t (*low_access)(struct ADIv5_DP_s *dp, uint8_t APnDP, uint8_t RnW, 
			uint8_t addr, uint32_t value);

	union {
		jtag_dev_t *dev;
		uint8_t fault;
	};
} ADIv5_DP_t;

static inline void adiv5_dp_write(ADIv5_DP_t *dp, uint8_t addr, uint32_t value)
{
	dp->dp_write(dp, addr, value);
}

static inline uint32_t adiv5_dp_read(ADIv5_DP_t *dp, uint8_t addr)
{
	return dp->dp_read(dp, addr);
}

static inline void adiv5_dp_write_ap(ADIv5_DP_t *dp, uint8_t addr, uint32_t value)
{
	dp->ap_write(dp, addr, value);
}

static inline uint32_t adiv5_dp_read_ap(ADIv5_DP_t *dp, uint8_t addr)
{
	return dp->ap_read(dp, addr);
}

static inline uint32_t adiv5_dp_error(ADIv5_DP_t *dp)
{
	return dp->error(dp);
}

static inline uint32_t adiv5_dp_low_access(struct ADIv5_DP_s *dp, uint8_t APnDP, 
					uint8_t RnW, uint8_t addr, uint32_t value)
{
	return dp->low_access(dp, APnDP, RnW, addr, value);
}

extern ADIv5_DP_t *adiv5_dp_list;

typedef struct ADIv5_AP_s {
	ADIv5_DP_t *dp;
	uint8_t apsel;

	uint32_t idr;
	uint32_t cfg;
	uint32_t base;
} ADIv5_AP_t;

struct target_ap_s {
	target t;
	ADIv5_AP_t *ap;
};

extern ADIv5_AP_t adiv5_aps[5];
extern int adiv5_ap_count;

void adiv5_free_all(void);
void adiv5_dp_init(ADIv5_DP_t *dp);

uint32_t adiv5_ap_mem_read(ADIv5_AP_t *ap, uint32_t addr);
void adiv5_ap_mem_write(ADIv5_AP_t *ap, uint32_t addr, uint32_t value);

void adiv5_ap_write(ADIv5_AP_t *ap, uint8_t addr, uint32_t value);
uint32_t adiv5_ap_read(ADIv5_AP_t *ap, uint8_t addr);

void adiv5_jtag_dp_handler(jtag_dev_t *dev);
int adiv5_swdp_scan(void);

#endif