OpenOCD
avr32_regs.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2010 by Oleksandr Tymoshenko <gonzo@bluezbox.com> *
5  ***************************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "target.h"
12 #include "jtag/jtag.h"
13 #include "avr32_jtag.h"
14 #include "avr32_regs.h"
15 
16 static int avr32_jtag_read_reg(struct avr32_jtag *jtag_info, int reg,
17  uint32_t *val)
18 {
19  int retval;
20  uint32_t dcsr;
21 
22  retval = avr32_jtag_exec(jtag_info, MTDR(AVR32_OCDREG_DCCPU, reg));
23  if (retval != ERROR_OK)
24  return retval;
25 
26  do {
27  retval = avr32_jtag_nexus_read(jtag_info,
28  AVR32_OCDREG_DCSR, &dcsr);
29 
30  if (retval != ERROR_OK)
31  return retval;
32  } while (!(dcsr & OCDREG_DCSR_CPUD));
33 
34  retval = avr32_jtag_nexus_read(jtag_info,
35  AVR32_OCDREG_DCCPU, val);
36 
37  return retval;
38 }
39 
40 static int avr32_jtag_write_reg(struct avr32_jtag *jtag_info, int reg,
41  uint32_t val)
42 {
43  int retval;
44  uint32_t dcsr;
45 
46  /* Restore Status reg */
47  retval = avr32_jtag_nexus_write(jtag_info,
48  AVR32_OCDREG_DCEMU, val);
49  if (retval != ERROR_OK)
50  return retval;
51 
52  retval = avr32_jtag_exec(jtag_info, MFDR(reg, AVR32_OCDREG_DCEMU));
53  if (retval != ERROR_OK)
54  return retval;
55  do {
56  retval = avr32_jtag_nexus_read(jtag_info,
57  AVR32_OCDREG_DCSR, &dcsr);
58  } while (!(dcsr & OCDREG_DCSR_EMUD) && (retval == ERROR_OK));
59 
60  return retval;
61 }
62 
63 
64 
65 int avr32_jtag_read_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
66 {
67  int i, retval;
68 
69  /* read core registers */
70  for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
71  avr32_jtag_read_reg(jtag_info, i, regs + i);
72 
73  /* read status register */
74  retval = avr32_jtag_exec(jtag_info, MFSR(0, 0));
75  if (retval != ERROR_OK)
76  return retval;
77 
78  retval = avr32_jtag_read_reg(jtag_info, 0, regs + AVR32_REG_SR);
79 
80  return retval;
81 }
82 
83 int avr32_jtag_write_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
84 {
85  int i, retval;
86 
87  retval = avr32_jtag_write_reg(jtag_info, 0, regs[AVR32_REG_SR]);
88  if (retval != ERROR_OK)
89  return retval;
90 
91  /* Restore Status reg */
92  retval = avr32_jtag_exec(jtag_info, MTSR(0, 0));
93  if (retval != ERROR_OK)
94  return retval;
95 
96  /*
97  * And now the rest of registers
98  */
99  for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
100  avr32_jtag_write_reg(jtag_info, i, regs[i]);
101 
102  return ERROR_OK;
103 }
int avr32_jtag_exec(struct avr32_jtag *jtag_info, uint32_t inst)
Definition: avr32_jtag.c:310
int avr32_jtag_nexus_write(struct avr32_jtag *jtag_info, uint32_t addr, uint32_t value)
Definition: avr32_jtag.c:168
int avr32_jtag_nexus_read(struct avr32_jtag *jtag_info, uint32_t addr, uint32_t *value)
Definition: avr32_jtag.c:160
#define OCDREG_DCSR_EMUD
Definition: avr32_jtag.h:54
#define MFDR(reg, dreg)
Definition: avr32_jtag.h:68
#define MTDR(dreg, reg)
Definition: avr32_jtag.h:67
#define MFSR(reg, sysreg)
Definition: avr32_jtag.h:70
#define AVR32_OCDREG_DCCPU
Definition: avr32_jtag.h:50
#define MTSR(sysreg, reg)
Definition: avr32_jtag.h:69
#define AVR32_OCDREG_DCSR
Definition: avr32_jtag.h:52
#define AVR32NUMCOREREGS
Definition: avr32_jtag.h:10
#define AVR32_OCDREG_DCEMU
Definition: avr32_jtag.h:51
#define OCDREG_DCSR_CPUD
Definition: avr32_jtag.h:53
static int avr32_jtag_write_reg(struct avr32_jtag *jtag_info, int reg, uint32_t val)
Definition: avr32_regs.c:40
static int avr32_jtag_read_reg(struct avr32_jtag *jtag_info, int reg, uint32_t *val)
Definition: avr32_regs.c:16
int avr32_jtag_read_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
Definition: avr32_regs.c:65
int avr32_jtag_write_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
Definition: avr32_regs.c:83
@ AVR32_REG_SR
Definition: avr32_regs.h:27
The JTAG interface can be implemented with a software or hardware fifo.
static const struct @101 regs[]
#define ERROR_OK
Definition: log.h:155
Definition: register.h:111