X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Farm-jtag-ew.c;h=fa18ef0f59f8371eef027ce6113d3053b27ea152;hp=0c00cace76a44f5d5d5bff00fb17d81154923bbd;hb=c97caebccd07be7e5bae61d6d40921e01786ba06;hpb=231a71b7fba9277aaa7772a78788ebded3253b47 diff --git a/src/jtag/arm-jtag-ew.c b/src/jtag/arm-jtag-ew.c index 0c00cace76..fa18ef0f59 100644 --- a/src/jtag/arm-jtag-ew.c +++ b/src/jtag/arm-jtag-ew.c @@ -1,5 +1,3 @@ -// vim:ts=4 sw=4: - /*************************************************************************** * Copyright (C) 2009 by Dimitar Dimitrov * * based on Dominic Rath's and Benedikt Sauter's usbprog.c * @@ -24,7 +22,8 @@ #include "config.h" #endif -#include "jtag.h" +#include "interface.h" +#include "commands.h" #include @@ -53,8 +52,8 @@ #define CMD_TGPWR_SETUP 0x22 /* Global USB buffers */ -static u8 usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE]; -static u8 usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE]; +static uint8_t usb_in_buffer[ARMJTAGEW_IN_BUFFER_SIZE]; +static uint8_t usb_out_buffer[ARMJTAGEW_OUT_BUFFER_SIZE]; /* External interface functions */ static int armjtagew_execute_queue(void); @@ -72,9 +71,9 @@ static void armjtagew_end_state(tap_state_t state); static void armjtagew_state_move(void); static void armjtagew_path_move(int num_states, tap_state_t *path); static void armjtagew_runtest(int num_cycles); -static void armjtagew_scan(bool ir_scan, enum scan_type type, u8 *buffer, int scan_size, scan_command_t *command); +static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, scan_command_t *command); static void armjtagew_reset(int trst, int srst); -//static void armjtagew_simple_command(u8 command); +//static void armjtagew_simple_command(uint8_t command); static int armjtagew_get_status(void); /* tap buffer functions */ @@ -82,7 +81,7 @@ static void armjtagew_tap_init(void); static int armjtagew_tap_execute(void); static void armjtagew_tap_ensure_space(int scans, int bits); static void armjtagew_tap_append_step(int tms, int tdi); -static void armjtagew_tap_append_scan(int length, u8 *buffer, scan_command_t *command); +static void armjtagew_tap_append_scan(int length, uint8_t *buffer, scan_command_t *command); /* ARM-JTAG-EW lowlevel functions */ typedef struct armjtagew_jtag @@ -100,7 +99,7 @@ static int armjtagew_usb_read(armjtagew_jtag_t *armjtagew_jtag, int exp_in_lengt static int armjtagew_get_version_info(void); #ifdef _DEBUG_USB_COMMS_ -static void armjtagew_debug_buffer(u8 *buffer, int length); +static void armjtagew_debug_buffer(uint8_t *buffer, int length); #endif static armjtagew_jtag_t* armjtagew_jtag_handle; @@ -127,39 +126,24 @@ static int armjtagew_execute_queue(void) jtag_command_t *cmd = jtag_command_queue; int scan_size; enum scan_type type; - u8 *buffer; + uint8_t *buffer; while (cmd != NULL) { switch (cmd->type) { - case JTAG_END_STATE: - DEBUG_JTAG_IO("end_state: %i", cmd->cmd.end_state->end_state); - - if (cmd->cmd.end_state->end_state != TAP_INVALID) - { - armjtagew_end_state(cmd->cmd.end_state->end_state); - } - break; - case JTAG_RUNTEST: - DEBUG_JTAG_IO( "runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ + DEBUG_JTAG_IO("runtest %i cycles, end in %i", cmd->cmd.runtest->num_cycles, \ cmd->cmd.runtest->end_state); - if (cmd->cmd.runtest->end_state != TAP_INVALID) - { - armjtagew_end_state(cmd->cmd.runtest->end_state); - } + armjtagew_end_state(cmd->cmd.runtest->end_state); armjtagew_runtest(cmd->cmd.runtest->num_cycles); break; case JTAG_STATEMOVE: DEBUG_JTAG_IO("statemove end in %i", cmd->cmd.statemove->end_state); - if (cmd->cmd.statemove->end_state != TAP_INVALID) - { - armjtagew_end_state(cmd->cmd.statemove->end_state); - } + armjtagew_end_state(cmd->cmd.statemove->end_state); armjtagew_state_move(); break; @@ -174,10 +158,7 @@ static int armjtagew_execute_queue(void) case JTAG_SCAN: DEBUG_JTAG_IO("scan end in %i", cmd->cmd.scan->end_state); - if (cmd->cmd.scan->end_state != TAP_INVALID) - { - armjtagew_end_state(cmd->cmd.scan->end_state); - } + armjtagew_end_state(cmd->cmd.scan->end_state); scan_size = jtag_build_buffer(cmd->cmd.scan, &buffer); DEBUG_JTAG_IO("scan input, length = %d", scan_size); @@ -226,7 +207,7 @@ static int armjtagew_speed(int speed) usb_out_buffer[0] = CMD_SET_TCK_FREQUENCY; - buf_set_u32(usb_out_buffer+1, 0, 32, speed); + buf_set_u32(usb_out_buffer + 1, 0, 32, speed); result = armjtagew_usb_message(armjtagew_jtag_handle, 4, 4); @@ -239,14 +220,14 @@ static int armjtagew_speed(int speed) usb_out_buffer[0] = CMD_GET_TCK_FREQUENCY; result = armjtagew_usb_message(armjtagew_jtag_handle, 1, 4); speed_real = (int)buf_get_u32(usb_in_buffer,0,32); - if(result < 0) + if (result < 0) { LOG_ERROR("ARM-JTAG-EW getting speed failed (%d)", result); return ERROR_JTAG_DEVICE_ERROR; - } + } else { - LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real); + LOG_INFO("Requested speed %dkHz, emulator reported %dkHz.", speed, speed_real); } return ERROR_OK; @@ -332,9 +313,10 @@ static void armjtagew_state_move(void) { int i; int tms = 0; - u8 tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); + uint8_t tms_scan = tap_get_tms_path(tap_get_state(), tap_get_end_state()); + int tms_count = tap_get_tms_path_len(tap_get_state(), tap_get_end_state()); - for (i = 0; i < 7; i++) + for (i = 0; i < tms_count; i++) { tms = (tms_scan >> i) & 1; armjtagew_tap_append_step(tms, 0); @@ -350,7 +332,7 @@ static void armjtagew_path_move(int num_states, tap_state_t *path) for (i = 0; i < num_states; i++) { /* - * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode. + * TODO: The ARM-JTAG-EW hardware delays TDI with 3 TCK cycles when in RTCK mode. * Either handle that here, or update the documentation with examples * how to fix that in the configuration files. */ @@ -401,7 +383,7 @@ static void armjtagew_runtest(int num_cycles) } } -static void armjtagew_scan(bool ir_scan, enum scan_type type, u8 *buffer, int scan_size, scan_command_t *command) +static void armjtagew_scan(bool ir_scan, enum scan_type type, uint8_t *buffer, int scan_size, scan_command_t *command) { tap_state_t saved_end_state; @@ -431,11 +413,11 @@ static void armjtagew_scan(bool ir_scan, enum scan_type type, u8 *buffer, int sc static void armjtagew_reset(int trst, int srst) { - const u8 trst_mask = (1u<<5); - const u8 srst_mask = (1u<<6); - u8 val = 0; - u8 outp_en = 0; - u8 change_mask = 0; + const uint8_t trst_mask = (1u << 5); + const uint8_t srst_mask = (1u << 6); + uint8_t val = 0; + uint8_t outp_en = 0; + uint8_t change_mask = 0; int result; LOG_DEBUG("trst: %i, srst: %i", trst, srst); @@ -488,14 +470,14 @@ static int armjtagew_get_status(void) if (result == 0) { unsigned int u_tg = buf_get_u32(usb_in_buffer, 0, 16); - LOG_INFO("U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s\n", \ - buf_get_u32(usb_in_buffer + 0, 0, 16), \ - buf_get_u32(usb_in_buffer + 2, 0, 16), \ - buf_get_u32(usb_in_buffer + 4, 0, 16), \ - buf_get_u32(usb_in_buffer + 6, 0, 16), \ - usb_in_buffer[9], \ - usb_in_buffer[11] ? "OVERCURRENT" : "OK", \ - usb_in_buffer[10] ? "enabled" : "disabled"); + LOG_INFO("U_tg = %d mV, U_aux = %d mV, U_tgpwr = %d mV, I_tgpwr = %d mA, D1 = %d, Target power %s %s\n", + (int)(buf_get_u32(usb_in_buffer + 0, 0, 16)), + (int)(buf_get_u32(usb_in_buffer + 2, 0, 16)), + (int)(buf_get_u32(usb_in_buffer + 4, 0, 16)), + (int)(buf_get_u32(usb_in_buffer + 6, 0, 16)), + usb_in_buffer[9], + usb_in_buffer[11] ? "OVERCURRENT" : "OK", + usb_in_buffer[10] ? "enabled" : "disabled"); if (u_tg < 1500) { @@ -518,18 +500,18 @@ static int armjtagew_get_version_info(void) /* query hardware version */ usb_out_buffer[0] = CMD_GET_VERSION; - result = armjtagew_usb_message(armjtagew_jtag_handle, 1, 4+15+256); + result = armjtagew_usb_message(armjtagew_jtag_handle, 1, 4 + 15 + 256); - if (result != 0) + if (result != 0) { LOG_ERROR("ARM-JTAG-EW command CMD_GET_VERSION failed (%d)\n", result); return ERROR_JTAG_DEVICE_ERROR; } - memcpy(sn, usb_in_buffer+4, 15); + memcpy(sn, usb_in_buffer + 4, 15); sn[15] = '\0'; - memcpy(auxinfo, usb_in_buffer+4+15, 256); + memcpy(auxinfo, usb_in_buffer + 4+15, 256); auxinfo[256] = '\0'; LOG_INFO("ARM-JTAG-EW firmware version %d.%d, hardware revision %c, SN=%s, Additional info: %s", \ @@ -557,16 +539,16 @@ static int armjtagew_handle_armjtagew_info_command(struct command_context_s *cmd #define ARMJTAGEW_TAP_BUFFER_SIZE 2048 static int tap_length; -static u8 tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; -static u8 tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; -static u8 tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; +static uint8_t tms_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; +static uint8_t tdi_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; +static uint8_t tdo_buffer[ARMJTAGEW_TAP_BUFFER_SIZE]; typedef struct { int first; /* First bit position in tdo_buffer to read */ int length; /* Number of bits to read */ scan_command_t *command; /* Corresponding scan command */ - u8 *buffer; + uint8_t *buffer; } pending_scan_result_t; #define MAX_PENDING_SCAN_RESULTS 256 @@ -601,7 +583,7 @@ static void armjtagew_tap_append_step(int tms, int tdi) if (index < ARMJTAGEW_TAP_BUFFER_SIZE) { int bit_index = tap_length % 8; - u8 bit = 1 << bit_index; + uint8_t bit = 1 << bit_index; if (tms) { @@ -629,7 +611,7 @@ static void armjtagew_tap_append_step(int tms, int tdi) } } -void armjtagew_tap_append_scan(int length, u8 *buffer, scan_command_t *command) +void armjtagew_tap_append_scan(int length, uint8_t *buffer, scan_command_t *command) { pending_scan_result_t *pending_scan_result = &pending_scan_results_buffer[pending_scan_results_length]; int i; @@ -669,7 +651,7 @@ static int armjtagew_tap_execute(void) byte_length = tap_length / 8; usb_out_buffer[0] = CMD_TAP_SHIFT; - buf_set_u32(usb_out_buffer+1, 0, 16, byte_length); + buf_set_u32(usb_out_buffer + 1, 0, 16, byte_length); tms_offset = 3; for (i = 0; i < byte_length; i++) @@ -690,7 +672,7 @@ static int armjtagew_tap_execute(void) int stat; stat = (int)buf_get_u32(usb_in_buffer + byte_length, 0, 32); - if(stat) { + if (stat) { LOG_ERROR("armjtagew_tap_execute, emulator returned error code %d for a CMD_TAP_SHIFT command", stat); return ERROR_JTAG_QUEUE_FAILED; } @@ -703,7 +685,7 @@ static int armjtagew_tap_execute(void) for (i = 0; i < pending_scan_results_length; i++) { pending_scan_result_t *pending_scan_result = &pending_scan_results_buffer[i]; - u8 *buffer = pending_scan_result->buffer; + 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; @@ -807,7 +789,7 @@ static int armjtagew_usb_message(armjtagew_jtag_t *armjtagew_jtag, int out_lengt if (result == out_length) { result = armjtagew_usb_read(armjtagew_jtag, in_length); - if (result != in_length) + if (result != in_length) { LOG_ERROR("usb_bulk_read failed (requested=%d, result=%d)", in_length, result); return -1; @@ -861,7 +843,7 @@ static int armjtagew_usb_read(armjtagew_jtag_t *armjtagew_jtag, int exp_in_lengt #ifdef _DEBUG_USB_COMMS_ #define BYTES_PER_LINE 16 -static void armjtagew_debug_buffer(u8 *buffer, int length) +static void armjtagew_debug_buffer(uint8_t *buffer, int length) { char line[81]; char s[4];