Skip to content

Commit be2d25e

Browse files
borneoatom-van
authored andcommitted
arm_adi_v5: add API send_sequence() and use it
The method to send an arbitrary sequence to DAP depends on the transport and is thus different on JTAG and SWD. This is already coded in dap_to_jtag() and dap_to_swd(). Add a new API send_sequence() in struct dap_ops. Add the implementations of send_sequence() in adi_v5_jtag.c and adi_v5_swd.c Rewrite dap_to_jtag() and dap_to_swd() using the new API. Move the enum swd_special_seq in arm_adi_v5.h to solve a circular dependencies among swd.h and arm_adi_v5.h Change-Id: I9db13a00f129761eab283783c094cfff2dd92610 Signed-off-by: Antonio Borneo <[email protected]> Reviewed-on: http://openocd.zylin.com/4902 Tested-by: jenkins Reviewed-by: Tomas Vanek <[email protected]>
1 parent 5d08bcb commit be2d25e

File tree

5 files changed

+63
-44
lines changed

5 files changed

+63
-44
lines changed

src/jtag/swd.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,6 @@ static const uint8_t swd_seq_dormant_to_jtag[] = {
213213
};
214214
static const unsigned swd_seq_dormant_to_jtag_len = 160;
215215

216-
enum swd_special_seq {
217-
LINE_RESET,
218-
JTAG_TO_SWD,
219-
SWD_TO_JTAG,
220-
SWD_TO_DORMANT,
221-
DORMANT_TO_SWD,
222-
};
223-
224216
struct swd_driver {
225217
/**
226218
* Initialize the debug link so it can perform SWD operations.

src/target/adi_v5_jtag.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "arm_adi_v5.h"
3939
#include <helper/time_support.h>
4040
#include <helper/list.h>
41+
#include <jtag/swd.h>
4142

4243
/*#define DEBUG_WAIT*/
4344

@@ -663,6 +664,28 @@ static int jtag_check_reconnect(struct adiv5_dap *dap)
663664
return ERROR_OK;
664665
}
665666

667+
static int jtag_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
668+
{
669+
int retval;
670+
671+
switch (seq) {
672+
case JTAG_TO_SWD:
673+
retval = jtag_add_tms_seq(swd_seq_jtag_to_swd_len,
674+
swd_seq_jtag_to_swd, TAP_INVALID);
675+
break;
676+
case SWD_TO_JTAG:
677+
retval = jtag_add_tms_seq(swd_seq_swd_to_jtag_len,
678+
swd_seq_swd_to_jtag, TAP_RESET);
679+
break;
680+
default:
681+
LOG_ERROR("Sequence %d not supported", seq);
682+
return ERROR_FAIL;
683+
}
684+
if (retval == ERROR_OK)
685+
retval = jtag_execute_queue();
686+
return retval;
687+
}
688+
666689
static int jtag_dp_q_read(struct adiv5_dap *dap, unsigned reg,
667690
uint32_t *data)
668691
{
@@ -782,6 +805,7 @@ static int jtag_dp_sync(struct adiv5_dap *dap)
782805
*/
783806
const struct dap_ops jtag_dp_ops = {
784807
.connect = jtag_connect,
808+
.send_sequence = jtag_send_sequence,
785809
.queue_dp_read = jtag_dp_q_read,
786810
.queue_dp_write = jtag_dp_q_write,
787811
.queue_ap_read = jtag_ap_q_read,

src/target/adi_v5_swd.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ static int swd_connect(struct adiv5_dap *dap)
142142
return status;
143143
}
144144

145+
static int swd_send_sequence(struct adiv5_dap *dap, enum swd_special_seq seq)
146+
{
147+
const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
148+
assert(swd);
149+
150+
return swd->switch_seq(seq);
151+
}
152+
145153
static inline int check_sync(struct adiv5_dap *dap)
146154
{
147155
return do_sync ? swd_run_inner(dap) : ERROR_OK;
@@ -320,6 +328,7 @@ static void swd_quit(struct adiv5_dap *dap)
320328

321329
const struct dap_ops swd_dap_ops = {
322330
.connect = swd_connect,
331+
.send_sequence = swd_send_sequence,
323332
.queue_dp_read = swd_queue_dp_read,
324333
.queue_dp_write = swd_queue_dp_write,
325334
.queue_ap_read = swd_queue_ap_read,

src/target/arm_adi_v5.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -804,26 +804,9 @@ int mem_ap_init(struct adiv5_ap *ap)
804804
*/
805805
int dap_to_swd(struct adiv5_dap *dap)
806806
{
807-
int retval;
808-
809807
LOG_DEBUG("Enter SWD mode");
810808

811-
if (transport_is_jtag()) {
812-
retval = jtag_add_tms_seq(swd_seq_jtag_to_swd_len,
813-
swd_seq_jtag_to_swd, TAP_INVALID);
814-
if (retval == ERROR_OK)
815-
retval = jtag_execute_queue();
816-
return retval;
817-
}
818-
819-
if (transport_is_swd()) {
820-
const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
821-
822-
return swd->switch_seq(JTAG_TO_SWD);
823-
}
824-
825-
LOG_ERROR("Nor JTAG nor SWD transport");
826-
return ERROR_FAIL;
809+
return dap_send_sequence(dap, JTAG_TO_SWD);
827810
}
828811

829812
/**
@@ -839,26 +822,9 @@ int dap_to_swd(struct adiv5_dap *dap)
839822
*/
840823
int dap_to_jtag(struct adiv5_dap *dap)
841824
{
842-
int retval;
843-
844825
LOG_DEBUG("Enter JTAG mode");
845826

846-
if (transport_is_jtag()) {
847-
retval = jtag_add_tms_seq(swd_seq_swd_to_jtag_len,
848-
swd_seq_swd_to_jtag, TAP_RESET);
849-
if (retval == ERROR_OK)
850-
retval = jtag_execute_queue();
851-
return retval;
852-
}
853-
854-
if (transport_is_swd()) {
855-
const struct swd_driver *swd = adiv5_dap_swd_driver(dap);
856-
857-
return swd->switch_seq(SWD_TO_JTAG);
858-
}
859-
860-
LOG_ERROR("Nor JTAG nor SWD transport");
861-
return ERROR_FAIL;
827+
return dap_send_sequence(dap, SWD_TO_JTAG);
862828
}
863829

864830
/* CID interpretation -- see ARM IHI 0029B section 3

src/target/arm_adi_v5.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@
158158
#define DP_APSEL_MAX (255)
159159
#define DP_APSEL_INVALID (-1)
160160

161+
/* FIXME: not SWD specific; should be renamed, e.g. adiv5_special_seq */
162+
enum swd_special_seq {
163+
LINE_RESET,
164+
JTAG_TO_SWD,
165+
SWD_TO_JTAG,
166+
SWD_TO_DORMANT,
167+
DORMANT_TO_SWD,
168+
};
169+
161170
/**
162171
* This represents an ARM Debug Interface (v5) Access Port (AP).
163172
* Most common is a MEM-AP, for memory access.
@@ -291,6 +300,10 @@ struct adiv5_dap {
291300
struct dap_ops {
292301
/** connect operation for SWD */
293302
int (*connect)(struct adiv5_dap *dap);
303+
304+
/** send a sequence to the DAP */
305+
int (*send_sequence)(struct adiv5_dap *dap, enum swd_special_seq seq);
306+
294307
/** DP register read. */
295308
int (*queue_dp_read)(struct adiv5_dap *dap, unsigned reg,
296309
uint32_t *data);
@@ -338,6 +351,21 @@ enum ap_type {
338351
AP_TYPE_AHB5_AP = 0x5, /* AHB5 Memory-AP. */
339352
};
340353

354+
/**
355+
* Send an adi-v5 sequence to the DAP.
356+
*
357+
* @param dap The DAP used for reading.
358+
* @param seq The sequence to send.
359+
*
360+
* @return ERROR_OK for success, else a fault code.
361+
*/
362+
static inline int dap_send_sequence(struct adiv5_dap *dap,
363+
enum swd_special_seq seq)
364+
{
365+
assert(dap->ops != NULL);
366+
return dap->ops->send_sequence(dap, seq);
367+
}
368+
341369
/**
342370
* Queue a DP register read.
343371
* Note that not all DP registers are readable; also, that JTAG and SWD

0 commit comments

Comments
 (0)