Remove FSF address from GPL notices
[openocd.git] / src / target / avr32_regs.c
blob7273822c2f027e4abb9c9985572e97f5ffb213b2
1 /***************************************************************************
2 * Copyright (C) 2010 by Oleksandr Tymoshenko <gonzo@bluezbox.com> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 * *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
22 #include "target.h"
23 #include "jtag/jtag.h"
24 #include "avr32_jtag.h"
25 #include "avr32_regs.h"
27 static int avr32_jtag_read_reg(struct avr32_jtag *jtag_info, int reg,
28 uint32_t *val)
30 int retval;
31 uint32_t dcsr;
33 retval = avr32_jtag_exec(jtag_info, MTDR(AVR32_OCDREG_DCCPU, reg));
34 if (retval != ERROR_OK)
35 return retval;
37 do {
38 retval = avr32_jtag_nexus_read(jtag_info,
39 AVR32_OCDREG_DCSR, &dcsr);
41 if (retval != ERROR_OK)
42 return retval;
43 } while (!(dcsr & OCDREG_DCSR_CPUD));
45 retval = avr32_jtag_nexus_read(jtag_info,
46 AVR32_OCDREG_DCCPU, val);
48 return retval;
51 static int avr32_jtag_write_reg(struct avr32_jtag *jtag_info, int reg,
52 uint32_t val)
54 int retval;
55 uint32_t dcsr;
57 /* Restore Status reg */
58 retval = avr32_jtag_nexus_write(jtag_info,
59 AVR32_OCDREG_DCEMU, val);
60 if (retval != ERROR_OK)
61 return retval;
63 retval = avr32_jtag_exec(jtag_info, MFDR(reg, AVR32_OCDREG_DCEMU));
64 if (retval != ERROR_OK)
65 return retval;
66 do {
67 retval = avr32_jtag_nexus_read(jtag_info,
68 AVR32_OCDREG_DCSR, &dcsr);
69 } while (!(dcsr & OCDREG_DCSR_EMUD) && (retval == ERROR_OK));
71 return retval;
76 int avr32_jtag_read_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
78 int i, retval;
80 /* read core registers */
81 for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
82 avr32_jtag_read_reg(jtag_info, i, regs + i);
84 /* read status register */
85 retval = avr32_jtag_exec(jtag_info, MFSR(0, 0));
86 if (retval != ERROR_OK)
87 return retval;
89 retval = avr32_jtag_read_reg(jtag_info, 0, regs + AVR32_REG_SR);
91 return retval;
94 int avr32_jtag_write_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
96 int i, retval;
98 retval = avr32_jtag_write_reg(jtag_info, 0, regs[AVR32_REG_SR]);
99 if (retval != ERROR_OK)
100 return retval;
102 /* Restore Status reg */
103 retval = avr32_jtag_exec(jtag_info, MTSR(0, 0));
104 if (retval != ERROR_OK)
105 return retval;
108 * And now the rest of registers
110 for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
111 avr32_jtag_write_reg(jtag_info, i, regs[i]);
113 return ERROR_OK;