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.
 
 
 
 
 
 

226 lines
6.2 KiB

  1. /***************************************************************************
  2. * Copyright (C) 2009 by Simon Qian *
  3. * SimonQian@SimonQian.com *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. *
  19. ***************************************************************************/
  20. #ifdef HAVE_CONFIG_H
  21. #include "config.h"
  22. #endif
  23. #include "avrt.h"
  24. #include "target.h"
  25. #include "target_type.h"
  26. #define AVR_JTAG_INS_LEN 4
  27. /* forward declarations */
  28. static int avr_target_create(struct target *target, Jim_Interp *interp);
  29. static int avr_init_target(struct command_context *cmd_ctx, struct target *target);
  30. static int avr_arch_state(struct target *target);
  31. static int avr_poll(struct target *target);
  32. static int avr_halt(struct target *target);
  33. static int avr_resume(struct target *target, int current, uint32_t address,
  34. int handle_breakpoints, int debug_execution);
  35. static int avr_step(struct target *target, int current, uint32_t address,
  36. int handle_breakpoints);
  37. static int avr_assert_reset(struct target *target);
  38. static int avr_deassert_reset(struct target *target);
  39. /* IR and DR functions */
  40. static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
  41. static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
  42. static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
  43. static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
  44. struct target_type avr_target = {
  45. .name = "avr",
  46. .poll = avr_poll,
  47. .arch_state = avr_arch_state,
  48. .halt = avr_halt,
  49. .resume = avr_resume,
  50. .step = avr_step,
  51. .assert_reset = avr_assert_reset,
  52. .deassert_reset = avr_deassert_reset,
  53. /*
  54. .get_gdb_reg_list = avr_get_gdb_reg_list,
  55. .read_memory = avr_read_memory,
  56. .write_memory = avr_write_memory,
  57. .bulk_write_memory = avr_bulk_write_memory,
  58. .checksum_memory = avr_checksum_memory,
  59. .blank_check_memory = avr_blank_check_memory,
  60. .run_algorithm = avr_run_algorithm,
  61. .add_breakpoint = avr_add_breakpoint,
  62. .remove_breakpoint = avr_remove_breakpoint,
  63. .add_watchpoint = avr_add_watchpoint,
  64. .remove_watchpoint = avr_remove_watchpoint,
  65. */
  66. .target_create = avr_target_create,
  67. .init_target = avr_init_target,
  68. };
  69. static int avr_target_create(struct target *target, Jim_Interp *interp)
  70. {
  71. struct avr_common *avr = calloc(1, sizeof(struct avr_common));
  72. avr->jtag_info.tap = target->tap;
  73. target->arch_info = avr;
  74. return ERROR_OK;
  75. }
  76. static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
  77. {
  78. LOG_DEBUG("%s", __func__);
  79. return ERROR_OK;
  80. }
  81. static int avr_arch_state(struct target *target)
  82. {
  83. LOG_DEBUG("%s", __func__);
  84. return ERROR_OK;
  85. }
  86. static int avr_poll(struct target *target)
  87. {
  88. if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
  89. target->state = TARGET_HALTED;
  90. LOG_DEBUG("%s", __func__);
  91. return ERROR_OK;
  92. }
  93. static int avr_halt(struct target *target)
  94. {
  95. LOG_DEBUG("%s", __func__);
  96. return ERROR_OK;
  97. }
  98. static int avr_resume(struct target *target, int current, uint32_t address,
  99. int handle_breakpoints, int debug_execution)
  100. {
  101. LOG_DEBUG("%s", __func__);
  102. return ERROR_OK;
  103. }
  104. static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
  105. {
  106. LOG_DEBUG("%s", __func__);
  107. return ERROR_OK;
  108. }
  109. static int avr_assert_reset(struct target *target)
  110. {
  111. target->state = TARGET_RESET;
  112. LOG_DEBUG("%s", __func__);
  113. return ERROR_OK;
  114. }
  115. static int avr_deassert_reset(struct target *target)
  116. {
  117. target->state = TARGET_RUNNING;
  118. LOG_DEBUG("%s", __func__);
  119. return ERROR_OK;
  120. }
  121. int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out,
  122. int len)
  123. {
  124. return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
  125. }
  126. int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
  127. {
  128. return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
  129. }
  130. /* IR and DR functions */
  131. static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
  132. int ir_len, int rti)
  133. {
  134. if (NULL == tap) {
  135. LOG_ERROR("invalid tap");
  136. return ERROR_FAIL;
  137. }
  138. if (ir_len != tap->ir_length) {
  139. LOG_ERROR("invalid ir_len");
  140. return ERROR_FAIL;
  141. }
  142. {
  143. jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
  144. }
  145. return ERROR_OK;
  146. }
  147. static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
  148. int dr_len, int rti)
  149. {
  150. if (NULL == tap) {
  151. LOG_ERROR("invalid tap");
  152. return ERROR_FAIL;
  153. }
  154. {
  155. jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
  156. }
  157. return ERROR_OK;
  158. }
  159. static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
  160. uint8_t ir_out, int ir_len, int rti)
  161. {
  162. if (ir_len > 8) {
  163. LOG_ERROR("ir_len overflow, maxium is 8");
  164. return ERROR_FAIL;
  165. }
  166. mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
  167. return ERROR_OK;
  168. }
  169. static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
  170. uint32_t dr_out, int dr_len, int rti)
  171. {
  172. if (dr_len > 32) {
  173. LOG_ERROR("dr_len overflow, maxium is 32");
  174. return ERROR_FAIL;
  175. }
  176. mcu_write_dr(tap, (uint8_t *)dr_in, (uint8_t *)&dr_out, dr_len, rti);
  177. return ERROR_OK;
  178. }
  179. int mcu_execute_queue(void)
  180. {
  181. return jtag_execute_queue();
  182. }