1 /***************************************************************************
2 * Copyright (C) 2010 by Oleksandr Tymoshenko <gonzo@bluezbox.com> *
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. *
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. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
24 #include "jtag/jtag.h"
25 #include "avr32_jtag.h"
26 #include "avr32_regs.h"
28 static int avr32_jtag_read_reg(struct avr32_jtag *jtag_info, int reg,
34 retval = avr32_jtag_exec(jtag_info, MTDR(AVR32_OCDREG_DCCPU, reg));
35 if (retval != ERROR_OK)
39 retval = avr32_jtag_nexus_read(jtag_info,
40 AVR32_OCDREG_DCSR, &dcsr);
42 if (retval != ERROR_OK)
44 } while (!(dcsr & OCDREG_DCSR_CPUD));
46 retval = avr32_jtag_nexus_read(jtag_info,
47 AVR32_OCDREG_DCCPU, val);
52 static int avr32_jtag_write_reg(struct avr32_jtag *jtag_info, int reg,
58 /* Restore Status reg */
59 retval = avr32_jtag_nexus_write(jtag_info,
60 AVR32_OCDREG_DCEMU, val);
61 if (retval != ERROR_OK)
64 retval = avr32_jtag_exec(jtag_info, MFDR(reg, AVR32_OCDREG_DCEMU));
65 if (retval != ERROR_OK)
68 retval = avr32_jtag_nexus_read(jtag_info,
69 AVR32_OCDREG_DCSR, &dcsr);
70 } while (!(dcsr & OCDREG_DCSR_EMUD) && (retval == ERROR_OK));
77 int avr32_jtag_read_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
81 /* read core registers */
82 for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
83 avr32_jtag_read_reg(jtag_info, i, regs + i);
85 /* read status register */
86 retval = avr32_jtag_exec(jtag_info, MFSR(0, 0));
87 if (retval != ERROR_OK)
90 retval = avr32_jtag_read_reg(jtag_info, 0, regs + AVR32_REG_SR);
95 int avr32_jtag_write_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
99 retval = avr32_jtag_write_reg(jtag_info, 0, regs[AVR32_REG_SR]);
100 /* Restore Status reg */
101 retval = avr32_jtag_exec(jtag_info, MTSR(0, 0));
102 if (retval != ERROR_OK)
106 * And now the rest of registers
108 for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
109 avr32_jtag_write_reg(jtag_info, i, regs[i]);