X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fjlink.c;h=dbbddb868a2fe83be82ff2850b4a89ea2baf2490;hp=9677f0e80d54ade44c075a45188a78e7c5081895;hb=2861877b32a7a2f4022a1c3d9b66c9b4879878ac;hpb=246068fd8985b293d7109058f83c57f6c22a4336 diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 9677f0e80d..dbbddb868a 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -87,14 +87,10 @@ static int jlink_execute_queue(void); static int jlink_speed(int speed); static int jlink_speed_div(int speed, int* khz); static int jlink_khz(int khz, int *jtag_speed); -static int jlink_register_commands(struct command_context_s *cmd_ctx); +static int jlink_register_commands(struct command_context *cmd_ctx); static int jlink_init(void); static int jlink_quit(void); -/* CLI command handler functions */ -static int jlink_handle_jlink_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); -static int jlink_handle_jlink_hw_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc); - /* Queue command functions */ static void jlink_end_state(tap_state_t state); static void jlink_state_move(void); @@ -290,18 +286,6 @@ static int jlink_khz(int khz, int *jtag_speed) return ERROR_OK; } -static int jlink_register_commands(struct command_context_s *cmd_ctx) -{ - - register_command(cmd_ctx, NULL, "jlink_info", - &jlink_handle_jlink_info_command, COMMAND_EXEC, - "query jlink info"); - register_command(cmd_ctx, NULL, "jlink_hw_jtag", - &jlink_handle_jlink_hw_jtag_command, COMMAND_EXEC, - "set/get jlink hw jtag command version [2 | 3]"); - return ERROR_OK; -} - static int jlink_init(void) { int i; @@ -630,7 +614,7 @@ static int jlink_get_version_info(void) return ERROR_OK; } -static int jlink_handle_jlink_info_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(jlink_handle_jlink_info_command) { if (jlink_get_version_info() == ERROR_OK) { @@ -641,14 +625,14 @@ static int jlink_handle_jlink_info_command(struct command_context_s *cmd_ctx, ch return ERROR_OK; } -static int jlink_handle_jlink_hw_jtag_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc) +COMMAND_HANDLER(jlink_handle_jlink_hw_jtag_command) { - switch (argc) { + switch (CMD_ARGC) { case 0: - command_print(cmd_ctx, "jlink hw jtag %i", jlink_hw_jtag_version); + command_print(CMD_CTX, "jlink hw jtag %i", jlink_hw_jtag_version); break; case 1: { - int request_version = atoi(args[0]); + int request_version = atoi(CMD_ARGV[0]); switch (request_version) { case 2: case 3: jlink_hw_jtag_version = request_version; @@ -665,6 +649,18 @@ static int jlink_handle_jlink_hw_jtag_command(struct command_context_s *cmd_ctx, return ERROR_OK; } +static int jlink_register_commands(struct command_context *cmd_ctx) +{ + + register_command(cmd_ctx, NULL, "jlink_info", + &jlink_handle_jlink_info_command, COMMAND_EXEC, + "query jlink info"); + register_command(cmd_ctx, NULL, "jlink_hw_jtag", + &jlink_handle_jlink_hw_jtag_command, COMMAND_EXEC, + "set/get jlink hw jtag command version [2 | 3]"); + return ERROR_OK; +} + /***************************************************************************/ /* J-Link tap functions */ @@ -767,15 +763,16 @@ static int jlink_tap_execute(void) if (!tap_length) return ERROR_OK; - /* JLink returns an extra NULL in packet when size of in message is a multiple of 64, creates problems with usb comms */ - /* WARNING This will interfere with tap state counting */ - while ((TAP_SCAN_BYTES(tap_length)%64) == 0) + /* JLink returns an extra NULL in packet when size of incoming + * message is a multiple of 64, creates problems with USB comms. + * WARNING: This will interfere with tap state counting. */ + while ((DIV_ROUND_UP(tap_length, 8) % 64) == 0) { jlink_tap_append_step((tap_get_state() == TAP_RESET)?1:0, 0); } // number of full bytes (plus one if some would be left over) - byte_length = TAP_SCAN_BYTES(tap_length); + byte_length = DIV_ROUND_UP(tap_length, 8); bool use_jtag3 = jlink_hw_jtag_version >= 3; usb_out_buffer[0] = use_jtag3 ? EMU_CMD_HW_JTAG3 : EMU_CMD_HW_JTAG2; @@ -812,7 +809,7 @@ static int jlink_tap_execute(void) DEBUG_JTAG_IO("pending scan result, length = %d", length); #ifdef _DEBUG_USB_COMMS_ - jlink_debug_buffer(buffer, TAP_SCAN_BYTES(length)); + jlink_debug_buffer(buffer, DIV_ROUND_UP(length, 8)); #endif if (jtag_read_buffer(buffer, command) != ERROR_OK)