/* max speed 12MHz v5.0 jlink */
#define JLINK_MAX_SPEED 12000
-/* External interface functions */
-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_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);
/***************************************************************************/
/* External interface implementation */
-struct jtag_interface jlink_interface =
-{
- .name = "jlink",
- .execute_queue = jlink_execute_queue,
- .speed = jlink_speed,
- .speed_div = jlink_speed_div,
- .khz = jlink_khz,
- .register_commands = jlink_register_commands,
- .init = jlink_init,
- .quit = jlink_quit
-};
-
static void jlink_execute_runtest(struct jtag_command *cmd)
{
DEBUG_JTAG_IO("runtest %i cycles, end in %i",
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;
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)
{
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;
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;
+}
+
+struct jtag_interface jlink_interface = {
+ .name = "jlink",
+ .execute_queue = &jlink_execute_queue,
+ .speed = &jlink_speed,
+ .speed_div = &jlink_speed_div,
+ .khz = &jlink_khz,
+ .register_commands = &jlink_register_commands,
+ .init = &jlink_init,
+ .quit = &jlink_quit,
+ };
+
/***************************************************************************/
/* J-Link tap functions */
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;
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)
result->usb_handle = usb_open(dev);
- if (result->usb_handle)
- {
+ if (NULL == result->usb_handle)
+ return NULL;
- /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS AREA!!!!!!!!!!!
- * The behavior of libusb is not completely consistent across Windows, Linux, and Mac OS X platforms. The actions taken
- * in the following compiler conditionals may not agree with published documentation for libusb, but were found
- * to be necessary through trials and tribulations. Even little tweaks can break one or more platforms, so if you do make changes
- * test them carefully on all platforms before committing them!
- */
+ /* BE ***VERY CAREFUL*** ABOUT MAKING CHANGES IN THIS
+ * AREA!!!!!!!!!!! The behavior of libusb is not completely
+ * consistent across Windows, Linux, and Mac OS X platforms.
+ * The actions taken in the following compiler conditionals may
+ * not agree with published documentation for libusb, but were
+ * found to be necessary through trials and tribulations. Even
+ * little tweaks can break one or more platforms, so if you do
+ * make changes test them carefully on all platforms before
+ * committing them!
+ */
#if IS_WIN32 == 0
- usb_reset(result->usb_handle);
+ usb_reset(result->usb_handle);
#if IS_DARWIN == 0
- int timeout = 5;
+ int timeout = 5;
- /* reopen jlink after usb_reset
- * on win32 this may take a second or two to re-enumerate */
- while ((dev = find_jlink_device()) == NULL)
- {
- usleep(1000);
- timeout--;
- if (!timeout) {
- break;
- }
+ /* reopen jlink after usb_reset
+ * on win32 this may take a second or two to re-enumerate */
+ while ((dev = find_jlink_device()) == NULL)
+ {
+ usleep(1000);
+ timeout--;
+ if (!timeout) {
+ break;
}
+ }
- if (dev == NULL)
- {
- free(result);
- return NULL;
- }
+ if (dev == NULL)
+ {
+ free(result);
+ return NULL;
+ }
- result->usb_handle = usb_open(dev);
+ result->usb_handle = usb_open(dev);
#endif
#endif
- if (result->usb_handle)
- {
- /* usb_set_configuration required under win32 */
- usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue);
- usb_claim_interface(result->usb_handle, 0);
+ if (NULL == result->usb_handle)
+ {
+ free(result);
+ return NULL;
+ }
+
+ /* usb_set_configuration required under win32 */
+ usb_set_configuration(result->usb_handle, dev->config[0].bConfigurationValue);
+ usb_claim_interface(result->usb_handle, 0);
#if 0
- /*
- * This makes problems under Mac OS X. And is not needed
- * under Windows. Hopefully this will not break a linux build
- */
- usb_set_altinterface(result->usb_handle, 0);
+ /*
+ * This makes problems under Mac OS X. And is not needed
+ * under Windows. Hopefully this will not break a linux build
+ */
+ usb_set_altinterface(result->usb_handle, 0);
#endif
- struct usb_interface *iface = dev->config->interface;
- struct usb_interface_descriptor *desc = iface->altsetting;
- for (int i = 0; i < desc->bNumEndpoints; i++)
- {
- uint8_t epnum = desc->endpoint[i].bEndpointAddress;
- bool is_input = epnum & 0x80;
- LOG_DEBUG("usb ep %s %02x", is_input ? "in" : "out", epnum);
- if (is_input)
- jlink_read_ep = epnum;
- else
- jlink_write_ep = epnum;
- }
-
- return result;
- }
+ struct usb_interface *iface = dev->config->interface;
+ struct usb_interface_descriptor *desc = iface->altsetting;
+ for (int i = 0; i < desc->bNumEndpoints; i++)
+ {
+ uint8_t epnum = desc->endpoint[i].bEndpointAddress;
+ bool is_input = epnum & 0x80;
+ LOG_DEBUG("usb ep %s %02x", is_input ? "in" : "out", epnum);
+ if (is_input)
+ jlink_read_ep = epnum;
+ else
+ jlink_write_ep = epnum;
}
- free(result);
- return NULL;
+ return result;
}
static void jlink_usb_close(struct jlink *jlink)