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, see <http://www.gnu.org/licenses/>. *
16 ***************************************************************************/
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
,
33 retval
= avr32_jtag_exec(jtag_info
, MTDR(AVR32_OCDREG_DCCPU
, reg
));
34 if (retval
!= ERROR_OK
)
38 retval
= avr32_jtag_nexus_read(jtag_info
,
39 AVR32_OCDREG_DCSR
, &dcsr
);
41 if (retval
!= ERROR_OK
)
43 } while (!(dcsr
& OCDREG_DCSR_CPUD
));
45 retval
= avr32_jtag_nexus_read(jtag_info
,
46 AVR32_OCDREG_DCCPU
, val
);
51 static int avr32_jtag_write_reg(struct avr32_jtag
*jtag_info
, int reg
,
57 /* Restore Status reg */
58 retval
= avr32_jtag_nexus_write(jtag_info
,
59 AVR32_OCDREG_DCEMU
, val
);
60 if (retval
!= ERROR_OK
)
63 retval
= avr32_jtag_exec(jtag_info
, MFDR(reg
, AVR32_OCDREG_DCEMU
));
64 if (retval
!= ERROR_OK
)
67 retval
= avr32_jtag_nexus_read(jtag_info
,
68 AVR32_OCDREG_DCSR
, &dcsr
);
69 } while (!(dcsr
& OCDREG_DCSR_EMUD
) && (retval
== ERROR_OK
));
76 int avr32_jtag_read_regs(struct avr32_jtag
*jtag_info
, uint32_t *regs
)
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
)
89 retval
= avr32_jtag_read_reg(jtag_info
, 0, regs
+ AVR32_REG_SR
);
94 int avr32_jtag_write_regs(struct avr32_jtag
*jtag_info
, uint32_t *regs
)
98 retval
= avr32_jtag_write_reg(jtag_info
, 0, regs
[AVR32_REG_SR
]);
99 if (retval
!= ERROR_OK
)
102 /* Restore Status reg */
103 retval
= avr32_jtag_exec(jtag_info
, MTSR(0, 0));
104 if (retval
!= ERROR_OK
)
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
]);