X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fft2232.c;h=6fdb546e62786b8934e45c144c2fd32868afd403;hp=20824bbbd51e1675f25d3ed3c8bc3cbbfffae125;hb=68c598e88d5e09728ea845a81ab279c615bbaf0f;hpb=afe5371bc8bde3fc1a833c3d7e459920711a9584 diff --git a/src/jtag/ft2232.c b/src/jtag/ft2232.c index 20824bbbd5..6fdb546e62 100644 --- a/src/jtag/ft2232.c +++ b/src/jtag/ft2232.c @@ -2,6 +2,9 @@ * Copyright (C) 2004, 2006 by Dominic Rath * * Dominic.Rath@gmx.de * * * + * Copyright (C) 2008 by Spencer Oliver * + * spen@spen-soft.co.uk * + * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * @@ -46,9 +49,6 @@ #include #endif -#include -#include - /* enable this to debug io latency */ #if 0 @@ -64,6 +64,8 @@ int ft2232_execute_queue(void); int ft2232_speed(int speed); +int ft2232_speed_div(int speed, int *khz); +int ft2232_khz(int khz, int *jtag_speed); int ft2232_register_commands(struct command_context_s *cmd_ctx); int ft2232_init(void); int ft2232_quit(void); @@ -154,12 +156,11 @@ static int ft2232_expect_read = 0; jtag_interface_t ft2232_interface = { - .name = "ft2232", - .execute_queue = ft2232_execute_queue, - .speed = ft2232_speed, + .speed_div = ft2232_speed_div, + .khz = ft2232_khz, .register_commands = ft2232_register_commands, .init = ft2232_init, .quit = ft2232_quit, @@ -259,7 +260,55 @@ int ft2232_speed(int speed) return retval; } - jtag_speed = speed; + return ERROR_OK; +} + +int ft2232_speed_div(int speed, int *khz) +{ + /* Take a look in the FT2232 manual, + * AN2232C-01 Command Processor for + * MPSSE and MCU Host Bus. Chapter 3.8 */ + + *khz = 6000 / (1+speed); + + return ERROR_OK; +} + +int ft2232_khz(int khz, int *jtag_speed) +{ + if (khz==0) + { + LOG_ERROR("RCLK not supported"); + return ERROR_FAIL; + } + /* Take a look in the FT2232 manual, + * AN2232C-01 Command Processor for + * MPSSE and MCU Host Bus. Chapter 3.8 + * + * We will calc here with a multiplier + * of 10 for better rounding later. */ + + /* Calc speed, (6000 / khz) - 1 */ + /* Use 65000 for better rounding */ + *jtag_speed = (60000 / khz) - 10; + + /* Add 0.9 for rounding */ + *jtag_speed += 9; + + /* Calc real speed */ + *jtag_speed = *jtag_speed / 10; + + /* Check if speed is greater than 0 */ + if (*jtag_speed < 0) + { + *jtag_speed = 0; + } + + /* Check max value */ + if (*jtag_speed > 0xFFFF) + { + *jtag_speed = 0xFFFF; + } return ERROR_OK; } @@ -455,11 +504,11 @@ void ft2232_add_pathmove(pathmove_command_t *cmd) state_count = 0; while (num_states) { - tms_byte = 0x0; int bit_count = 0; int num_states_batch = num_states > 7 ? 7 : num_states; + tms_byte = 0x0; /* command "Clock Data to TMS/CS Pin (no Read)" */ BUFFER_ADD = 0x4b; /* number of states remaining */ @@ -980,20 +1029,20 @@ void olimex_jtag_reset(int trst, int srst) high_output |= nTRST; } - if (srst == 1) - { - high_output |= nSRST; - } - else if (srst == 0) - { - high_output &= ~nSRST; - } - - /* command "set data bits high byte" */ - BUFFER_ADD = 0x82; - BUFFER_ADD = high_output; - BUFFER_ADD = high_direction; - LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction); + if (srst == 1) + { + high_output |= nSRST; + } + else if (srst == 0) + { + high_output &= ~nSRST; + } + + /* command "set data bits high byte" */ + BUFFER_ADD = 0x82; + BUFFER_ADD = high_output; + BUFFER_ADD = high_direction; + LOG_DEBUG("trst: %i, srst: %i, high_output: 0x%2.2x, high_direction: 0x%2.2x", trst, srst, high_output, high_direction); } void flyswatter_reset(int trst, int srst) @@ -1007,20 +1056,20 @@ void flyswatter_reset(int trst, int srst) low_output |= nTRST; } - if (srst == 1) - { - low_output |= nSRST; - } - else if (srst == 0) - { - low_output &= ~nSRST; - } - - /* command "set data bits low byte" */ - BUFFER_ADD = 0x80; - BUFFER_ADD = low_output; - BUFFER_ADD = low_direction; - LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction); + if (srst == 1) + { + low_output |= nSRST; + } + else if (srst == 0) + { + low_output &= ~nSRST; + } + + /* command "set data bits low byte" */ + BUFFER_ADD = 0x80; + BUFFER_ADD = low_output; + BUFFER_ADD = low_direction; + LOG_DEBUG("trst: %i, srst: %i, low_output: 0x%2.2x, low_direction: 0x%2.2x", trst, srst, low_output, low_direction); } void turtle_reset(int trst, int srst) @@ -1054,14 +1103,14 @@ void comstick_reset(int trst, int srst) high_output |= nTRST; } - if (srst == 1) - { - high_output &= ~nSRST; - } - else if (srst == 0) - { - high_output |= nSRST; - } + if (srst == 1) + { + high_output &= ~nSRST; + } + else if (srst == 0) + { + high_output |= nSRST; + } /* command "set data bits high byte" */ BUFFER_ADD = 0x82; @@ -1081,14 +1130,14 @@ void stm32stick_reset(int trst, int srst) high_output |= nTRST; } - if (srst == 1) - { - low_output &= ~nSRST; - } - else if (srst == 0) - { - low_output |= nSRST; - } + if (srst == 1) + { + low_output &= ~nSRST; + } + else if (srst == 0) + { + low_output |= nSRST; + } /* command "set data bits low byte" */ BUFFER_ADD = 0x80; @@ -1457,17 +1506,17 @@ static int ft2232_init_libftdi(u16 vid, u16 pid, int more, int *try_more) u8 latency_timer; LOG_DEBUG("'ft2232' interface using libftdi with '%s' layout (%4.4x:%4.4x)", - ft2232_layout, vid, pid); + ft2232_layout, vid, pid); if (ftdi_init(&ftdic) < 0) return ERROR_JTAG_INIT_FAILED; /* context, vendor id, product id */ if (ftdi_usb_open_desc(&ftdic, vid, pid, ft2232_device_desc, - ft2232_serial) < 0) { + ft2232_serial) < 0) { if (more) LOG_WARNING("unable to open ftdi device (trying more): %s", - ftdic.error_str); + ftdic.error_str); else LOG_ERROR("unable to open ftdi device: %s", ftdic.error_str); *try_more = 1; @@ -1564,10 +1613,10 @@ int ft2232_init(void) #if BUILD_FT2232_FTD2XX == 1 retval = ft2232_init_ftd2xx(ft2232_vid[i], ft2232_pid[i], - more, &try_more); + more, &try_more); #elif BUILD_FT2232_LIBFTDI == 1 retval = ft2232_init_libftdi(ft2232_vid[i], ft2232_pid[i], - more, &try_more); + more, &try_more); #endif if (retval >= 0) break; @@ -2032,7 +2081,6 @@ void turtle_jtag_blink(void) BUFFER_ADD = high_direction; } - int ft2232_quit(void) { #if BUILD_FT2232_FTD2XX == 1 @@ -2098,7 +2146,7 @@ int ft2232_handle_vid_pid_command(struct command_context_s *cmd_ctx, char *cmd, if (argc > MAX_USB_IDS*2) { LOG_WARNING("ignoring extra IDs in ft2232_vid_pid " - "(maximum is %d pairs)", MAX_USB_IDS); + "(maximum is %d pairs)", MAX_USB_IDS); argc = MAX_USB_IDS*2; } if (argc < 2 || (argc & 1)) @@ -2134,5 +2182,3 @@ int ft2232_handle_latency_command(struct command_context_s *cmd_ctx, char *cmd, return ERROR_OK; } - -