X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fjlink.c;h=23ebc62d2a6431dbfc383500e336a7cacda94ed6;hp=78efc5ef0bf66d4b494bd5c7521679763e55d5dd;hb=0535a9245632e2cf12d8eaae8c4a9b1cc0bc66c6;hpb=4bc155398e88c9cc4393e4113496d088b7ff7ab0 diff --git a/src/jtag/jlink.c b/src/jtag/jlink.c index 78efc5ef0b..23ebc62d2a 100644 --- a/src/jtag/jlink.c +++ b/src/jtag/jlink.c @@ -87,20 +87,16 @@ 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); static void jlink_path_move(int num_states, tap_state_t *path); static void jlink_runtest(int num_cycles); -static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, scan_command_t *command); +static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command); static void jlink_reset(int trst, int srst); static void jlink_simple_command(uint8_t command); static int jlink_get_status(void); @@ -110,7 +106,7 @@ static void jlink_tap_init(void); static int jlink_tap_execute(void); static void jlink_tap_ensure_space(int scans, int bits); static void jlink_tap_append_step(int tms, int tdi); -static void jlink_tap_append_scan(int length, uint8_t *buffer, scan_command_t *command); +static void jlink_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command); /* Jlink lowlevel functions */ struct jlink { @@ -150,7 +146,7 @@ struct jtag_interface jlink_interface = .quit = jlink_quit }; -static void jlink_execute_runtest(jtag_command_t *cmd) +static void jlink_execute_runtest(struct jtag_command *cmd) { DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, @@ -161,7 +157,7 @@ static void jlink_execute_runtest(jtag_command_t *cmd) jlink_runtest(cmd->cmd.runtest->num_cycles); } -static void jlink_execute_statemove(jtag_command_t *cmd) +static void jlink_execute_statemove(struct jtag_command *cmd) { DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); @@ -169,7 +165,7 @@ static void jlink_execute_statemove(jtag_command_t *cmd) jlink_state_move(); } -static void jlink_execute_pathmove(jtag_command_t *cmd) +static void jlink_execute_pathmove(struct jtag_command *cmd) { DEBUG_JTAG_IO("pathmove: %i states, end in %i", cmd->cmd.pathmove->num_states, @@ -179,7 +175,7 @@ static void jlink_execute_pathmove(jtag_command_t *cmd) cmd->cmd.pathmove->path); } -static void jlink_execute_scan(jtag_command_t *cmd) +static void jlink_execute_scan(struct jtag_command *cmd) { int scan_size; enum scan_type type; @@ -200,7 +196,7 @@ static void jlink_execute_scan(jtag_command_t *cmd) type, buffer, scan_size, cmd->cmd.scan); } -static void jlink_execute_reset(jtag_command_t *cmd) +static void jlink_execute_reset(struct jtag_command *cmd) { DEBUG_JTAG_IO("reset trst: %i srst %i", cmd->cmd.reset->trst, cmd->cmd.reset->srst); @@ -210,14 +206,14 @@ static void jlink_execute_reset(jtag_command_t *cmd) jlink_tap_execute(); } -static void jlink_execute_sleep(jtag_command_t *cmd) +static void jlink_execute_sleep(struct jtag_command *cmd) { DEBUG_JTAG_IO("sleep %i", cmd->cmd.sleep->us); jlink_tap_execute(); jtag_sleep(cmd->cmd.sleep->us); } -static void jlink_execute_command(jtag_command_t *cmd) +static void jlink_execute_command(struct jtag_command *cmd) { switch (cmd->type) { @@ -235,7 +231,7 @@ static void jlink_execute_command(jtag_command_t *cmd) static int jlink_execute_queue(void) { - jtag_command_t *cmd = jtag_command_queue; + struct jtag_command *cmd = jtag_command_queue; while (cmd != NULL) { @@ -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; @@ -449,7 +433,7 @@ static void jlink_runtest(int num_cycles) } } -static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, scan_command_t *command) +static void jlink_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, struct scan_command *command) { tap_state_t saved_end_state; @@ -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,7 +625,7 @@ 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) { case 0: @@ -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 */ @@ -677,7 +673,7 @@ static uint8_t tdo_buffer[JLINK_TAP_BUFFER_SIZE]; struct pending_scan_result { int first; /* First bit position in tdo_buffer to read */ int length; /* Number of bits to read */ - scan_command_t *command; /* Corresponding scan command */ + struct scan_command *command; /* Corresponding scan command */ uint8_t *buffer; }; @@ -736,7 +732,7 @@ static void jlink_tap_append_step(int tms, int tdi) tap_length++; } -static void jlink_tap_append_scan(int length, uint8_t *buffer, scan_command_t *command) +static void jlink_tap_append_scan(int length, uint8_t *buffer, struct scan_command *command) { struct pending_scan_result *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length]; @@ -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; @@ -804,7 +801,7 @@ static int jlink_tap_execute(void) uint8_t *buffer = pending_scan_result->buffer; int length = pending_scan_result->length; int first = pending_scan_result->first; - scan_command_t *command = pending_scan_result->command; + struct scan_command *command = pending_scan_result->command; /* Copy to buffer */ buf_set_buf(tdo_buffer, first, buffer, 0, length); @@ -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)