You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

117 lines
3.4 KiB

  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, write to the *
  16. * Free Software Foundation, Inc., *
  17. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
  18. ***************************************************************************/
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "target.h"
  23. #include "jtag/jtag.h"
  24. #include "avr32_jtag.h"
  25. #include "avr32_regs.h"
  26. static int avr32_jtag_read_reg(struct avr32_jtag *jtag_info, int reg,
  27. uint32_t *val)
  28. {
  29. int retval;
  30. uint32_t dcsr;
  31. retval = avr32_jtag_exec(jtag_info, MTDR(AVR32_OCDREG_DCCPU, reg));
  32. if (retval != ERROR_OK)
  33. return retval;
  34. do {
  35. retval = avr32_jtag_nexus_read(jtag_info,
  36. AVR32_OCDREG_DCSR, &dcsr);
  37. if (retval != ERROR_OK)
  38. return retval;
  39. } while (!(dcsr & OCDREG_DCSR_CPUD));
  40. retval = avr32_jtag_nexus_read(jtag_info,
  41. AVR32_OCDREG_DCCPU, val);
  42. return retval;
  43. }
  44. static int avr32_jtag_write_reg(struct avr32_jtag *jtag_info, int reg,
  45. uint32_t val)
  46. {
  47. int retval;
  48. uint32_t dcsr;
  49. /* Restore Status reg */
  50. retval = avr32_jtag_nexus_write(jtag_info,
  51. AVR32_OCDREG_DCEMU, val);
  52. if (retval != ERROR_OK)
  53. return retval;
  54. retval = avr32_jtag_exec(jtag_info, MFDR(reg, AVR32_OCDREG_DCEMU));
  55. if (retval != ERROR_OK)
  56. return retval;
  57. do {
  58. retval = avr32_jtag_nexus_read(jtag_info,
  59. AVR32_OCDREG_DCSR, &dcsr);
  60. } while (!(dcsr & OCDREG_DCSR_EMUD) && (retval == ERROR_OK));
  61. return retval;
  62. }
  63. int avr32_jtag_read_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
  64. {
  65. int i, retval;
  66. /* read core registers */
  67. for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
  68. avr32_jtag_read_reg(jtag_info, i, regs + i);
  69. /* read status register */
  70. retval = avr32_jtag_exec(jtag_info, MFSR(0, 0));
  71. if (retval != ERROR_OK)
  72. return retval;
  73. retval = avr32_jtag_read_reg(jtag_info, 0, regs + AVR32_REG_SR);
  74. return retval;
  75. }
  76. int avr32_jtag_write_regs(struct avr32_jtag *jtag_info, uint32_t *regs)
  77. {
  78. int i, retval;
  79. retval = avr32_jtag_write_reg(jtag_info, 0, regs[AVR32_REG_SR]);
  80. if (retval != ERROR_OK)
  81. return retval;
  82. /* Restore Status reg */
  83. retval = avr32_jtag_exec(jtag_info, MTSR(0, 0));
  84. if (retval != ERROR_OK)
  85. return retval;
  86. /*
  87. * And now the rest of registers
  88. */
  89. for (i = 0; i < AVR32NUMCOREREGS - 1; i++)
  90. avr32_jtag_write_reg(jtag_info, i, regs[i]);
  91. return ERROR_OK;
  92. }