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.
 
 
 
 
 
 

242 lines
6.5 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. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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, int handle_breakpoints, int debug_execution);
  34. static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints);
  35. static int avr_assert_reset(struct target *target);
  36. static int avr_deassert_reset(struct target *target);
  37. static int avr_soft_reset_halt(struct target *target);
  38. /* IR and DR functions */
  39. static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out, int ir_len, int rti);
  40. static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out, int dr_len, int rti);
  41. static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out, int ir_len, int rti);
  42. static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *ir_in, uint32_t ir_out, int dr_len, int rti);
  43. struct target_type avr_target =
  44. {
  45. .name = "avr",
  46. .poll = avr_poll,
  47. .arch_state = avr_arch_state,
  48. .target_request_data = NULL,
  49. .halt = avr_halt,
  50. .resume = avr_resume,
  51. .step = avr_step,
  52. .assert_reset = avr_assert_reset,
  53. .deassert_reset = avr_deassert_reset,
  54. .soft_reset_halt = avr_soft_reset_halt,
  55. /*
  56. .get_gdb_reg_list = avr_get_gdb_reg_list,
  57. .read_memory = avr_read_memory,
  58. .write_memory = avr_write_memory,
  59. .bulk_write_memory = avr_bulk_write_memory,
  60. .checksum_memory = avr_checksum_memory,
  61. .blank_check_memory = avr_blank_check_memory,
  62. .run_algorithm = avr_run_algorithm,
  63. .add_breakpoint = avr_add_breakpoint,
  64. .remove_breakpoint = avr_remove_breakpoint,
  65. .add_watchpoint = avr_add_watchpoint,
  66. .remove_watchpoint = avr_remove_watchpoint,
  67. */
  68. .target_create = avr_target_create,
  69. .init_target = avr_init_target,
  70. };
  71. static int avr_target_create(struct target *target, Jim_Interp *interp)
  72. {
  73. struct avr_common *avr = calloc(1, sizeof(struct avr_common));
  74. avr->jtag_info.tap = target->tap;
  75. target->arch_info = avr;
  76. return ERROR_OK;
  77. }
  78. static int avr_init_target(struct command_context *cmd_ctx, struct target *target)
  79. {
  80. LOG_DEBUG("%s", __FUNCTION__);
  81. return ERROR_OK;
  82. }
  83. static int avr_arch_state(struct target *target)
  84. {
  85. LOG_DEBUG("%s", __FUNCTION__);
  86. return ERROR_OK;
  87. }
  88. static int avr_poll(struct target *target)
  89. {
  90. if ((target->state == TARGET_RUNNING) || (target->state == TARGET_DEBUG_RUNNING))
  91. {
  92. target->state = TARGET_HALTED;
  93. }
  94. LOG_DEBUG("%s", __FUNCTION__);
  95. return ERROR_OK;
  96. }
  97. static int avr_halt(struct target *target)
  98. {
  99. LOG_DEBUG("%s", __FUNCTION__);
  100. return ERROR_OK;
  101. }
  102. static int avr_resume(struct target *target, int current, uint32_t address,
  103. int handle_breakpoints, int debug_execution)
  104. {
  105. LOG_DEBUG("%s", __FUNCTION__);
  106. return ERROR_OK;
  107. }
  108. static int avr_step(struct target *target, int current, uint32_t address, int handle_breakpoints)
  109. {
  110. LOG_DEBUG("%s", __FUNCTION__);
  111. return ERROR_OK;
  112. }
  113. static int avr_assert_reset(struct target *target)
  114. {
  115. target->state = TARGET_RESET;
  116. LOG_DEBUG("%s", __FUNCTION__);
  117. return ERROR_OK;
  118. }
  119. static int avr_deassert_reset(struct target *target)
  120. {
  121. target->state = TARGET_RUNNING;
  122. LOG_DEBUG("%s", __FUNCTION__);
  123. return ERROR_OK;
  124. }
  125. static int avr_soft_reset_halt(struct target *target)
  126. {
  127. LOG_DEBUG("%s", __FUNCTION__);
  128. return ERROR_OK;
  129. }
  130. int avr_jtag_senddat(struct jtag_tap *tap, uint32_t* dr_in, uint32_t dr_out,
  131. int len)
  132. {
  133. return mcu_write_dr_u32(tap, dr_in, dr_out, len, 1);
  134. }
  135. int avr_jtag_sendinstr(struct jtag_tap *tap, uint8_t *ir_in, uint8_t ir_out)
  136. {
  137. return mcu_write_ir_u8(tap, ir_in, ir_out, AVR_JTAG_INS_LEN, 1);
  138. }
  139. /* IR and DR functions */
  140. static int mcu_write_ir(struct jtag_tap *tap, uint8_t *ir_in, uint8_t *ir_out,
  141. int ir_len, int rti)
  142. {
  143. if (NULL == tap)
  144. {
  145. LOG_ERROR("invalid tap");
  146. return ERROR_FAIL;
  147. }
  148. if (ir_len != tap->ir_length)
  149. {
  150. LOG_ERROR("invalid ir_len");
  151. return ERROR_FAIL;
  152. }
  153. {
  154. jtag_add_plain_ir_scan(tap->ir_length, ir_out, ir_in, TAP_IDLE);
  155. }
  156. return ERROR_OK;
  157. }
  158. static int mcu_write_dr(struct jtag_tap *tap, uint8_t *dr_in, uint8_t *dr_out,
  159. int dr_len, int rti)
  160. {
  161. if (NULL == tap)
  162. {
  163. LOG_ERROR("invalid tap");
  164. return ERROR_FAIL;
  165. }
  166. {
  167. jtag_add_plain_dr_scan(dr_len, dr_out, dr_in, TAP_IDLE);
  168. }
  169. return ERROR_OK;
  170. }
  171. static int mcu_write_ir_u8(struct jtag_tap *tap, uint8_t *ir_in,
  172. uint8_t ir_out, int ir_len, int rti)
  173. {
  174. if (ir_len > 8)
  175. {
  176. LOG_ERROR("ir_len overflow, maxium is 8");
  177. return ERROR_FAIL;
  178. }
  179. mcu_write_ir(tap, ir_in, &ir_out, ir_len, rti);
  180. return ERROR_OK;
  181. }
  182. static int mcu_write_dr_u32(struct jtag_tap *tap, uint32_t *dr_in,
  183. uint32_t dr_out, int dr_len, int rti)
  184. {
  185. if (dr_len > 32)
  186. {
  187. LOG_ERROR("dr_len overflow, maxium is 32");
  188. return ERROR_FAIL;
  189. }
  190. mcu_write_dr(tap, (uint8_t*)dr_in, (uint8_t*)&dr_out, dr_len, rti);
  191. return ERROR_OK;
  192. }
  193. int mcu_execute_queue(void)
  194. {
  195. return jtag_execute_queue();
  196. }