all cable: always display real used frequency
This commit is contained in:
parent
3d29fb79fe
commit
5c49b1465a
|
|
@ -83,10 +83,6 @@ AnlogicCable::AnlogicCable(uint32_t clkHZ, bool verbose):
|
|||
throw std::exception();
|
||||
}
|
||||
|
||||
if (clkHZ > 6000000) {
|
||||
printInfo("Anlogic JTAG probe limited to 6MHz");
|
||||
clkHZ = 6000000;
|
||||
}
|
||||
if (setClkFreq(clkHZ) < 0) {
|
||||
cerr << "Fail to set frequency" << endl;
|
||||
throw std::exception();
|
||||
|
|
@ -104,24 +100,41 @@ AnlogicCable::~AnlogicCable()
|
|||
int AnlogicCable::setClkFreq(uint32_t clkHZ)
|
||||
{
|
||||
int actual_length;
|
||||
int ret;
|
||||
int ret, req_freq = clkHZ;
|
||||
|
||||
uint8_t buf[] = {ANLOGICCABLE_FREQ_CMD, 0};
|
||||
if (clkHZ >= 6000000)
|
||||
|
||||
if (clkHZ > 6000000) {
|
||||
printWarn("Anlogic JTAG probe limited to 6MHz");
|
||||
clkHZ = 6000000;
|
||||
}
|
||||
|
||||
if (clkHZ >= 6000000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_6M;
|
||||
else if (clkHZ >= 3000000)
|
||||
clkHZ = 6000000;
|
||||
} else if (clkHZ >= 3000000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_3M;
|
||||
else if (clkHZ >= 1000000)
|
||||
clkHZ = 3000000;
|
||||
} else if (clkHZ >= 1000000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_1M;
|
||||
else if (clkHZ >= 600000)
|
||||
clkHZ = 1000000;
|
||||
} else if (clkHZ >= 600000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_600K;
|
||||
else if (clkHZ >= 400000)
|
||||
clkHZ = 600000;
|
||||
} else if (clkHZ >= 400000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_400K;
|
||||
else if (clkHZ >= 200000)
|
||||
clkHZ = 400000;
|
||||
} else if (clkHZ >= 200000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_200K;
|
||||
else if (clkHZ >= 100000)
|
||||
clkHZ = 200000;
|
||||
} else if (clkHZ >= 100000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_100K;
|
||||
else if (clkHZ >= 90000)
|
||||
clkHZ = 100000;
|
||||
} else if (clkHZ >= 90000) {
|
||||
buf[1] = ANLOGICCABLE_FREQ_90K;
|
||||
clkHZ = 90000;
|
||||
}
|
||||
|
||||
ret = libusb_bulk_transfer(dev_handle, ANLOGICCABLE_CONF_EP,
|
||||
buf, 2, &actual_length, 1000);
|
||||
if (ret < 0) {
|
||||
|
|
@ -129,6 +142,9 @@ int AnlogicCable::setClkFreq(uint32_t clkHZ)
|
|||
return -EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printWarn("Jtag frequency : requested " + std::to_string(req_freq) +
|
||||
"Hz -> real " + std::to_string(clkHZ) + "Hz");
|
||||
|
||||
return clkHZ;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,10 +79,6 @@ DirtyJtag::DirtyJtag(uint32_t clkHZ, bool verbose):
|
|||
throw std::exception();
|
||||
}
|
||||
|
||||
if (clkHZ > 600000) {
|
||||
printInfo("DirtyJTAG probe limited to 600kHz");
|
||||
clkHZ = 600000;
|
||||
}
|
||||
if (setClkFreq(clkHZ) < 0) {
|
||||
cerr << "Fail to set frequency" << endl;
|
||||
throw std::exception();
|
||||
|
|
@ -100,7 +96,16 @@ DirtyJtag::~DirtyJtag()
|
|||
int DirtyJtag::setClkFreq(uint32_t clkHZ)
|
||||
{
|
||||
int actual_length;
|
||||
int ret;
|
||||
int ret, req_freq = clkHZ;
|
||||
|
||||
if (clkHZ > 600000) {
|
||||
printWarn("DirtyJTAG probe limited to 600kHz");
|
||||
clkHZ = 600000;
|
||||
}
|
||||
|
||||
printInfo("Jtag frequency : requested " + std::to_string(req_freq) +
|
||||
"Hz -> real " + std::to_string(clkHZ) + "Hz");
|
||||
|
||||
uint8_t buf[] = {CMD_FREQ,
|
||||
static_cast<uint8_t>(0xff & ((clkHZ / 1000) >> 8)),
|
||||
static_cast<uint8_t>(0xff & ((clkHZ / 1000) )),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "display.hpp"
|
||||
#include "ftdiJtagBitbang.hpp"
|
||||
#include "ftdipp_mpsse.hpp"
|
||||
|
||||
|
|
@ -87,8 +88,13 @@ FtdiJtagBitBang::~FtdiJtagBitBang()
|
|||
|
||||
int FtdiJtagBitBang::setClkFreq(uint32_t clkHZ)
|
||||
{
|
||||
if (clkHZ > 3000000)
|
||||
uint32_t user_clk = clkHZ;
|
||||
if (clkHZ > 3000000) {
|
||||
printWarn("Jtag probe limited to 3MHz");
|
||||
clkHZ = 3000000;
|
||||
}
|
||||
printInfo("Jtag frequency : requested " + std::to_string(user_clk) +
|
||||
"Hz -> real " + std::to_string(clkHZ) + "Hz");
|
||||
int ret = ftdi_set_baudrate(_ftdi, clkHZ);
|
||||
printf("ret %d\n", ret);
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@
|
|||
#endif
|
||||
#include <libusb.h>
|
||||
|
||||
#include "display.hpp"
|
||||
#include "ftdipp_mpsse.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
|
@ -222,31 +223,40 @@ int FTDIpp_MPSSE::setClkFreq(uint32_t clkHZ, char use_divide_by_5)
|
|||
use_divide_by_5 = false;
|
||||
}
|
||||
|
||||
if ((use_divide_by_5 && _clkHZ > 6000000) || _clkHZ > 30000000) {
|
||||
fprintf(stderr, "Error: too fast frequency\n");
|
||||
return -1;
|
||||
}
|
||||
if (use_divide_by_5) {
|
||||
if (_clkHZ > 6000000) {
|
||||
printWarn("Jtag probe limited to 60MHz");
|
||||
_clkHZ = 6000000;
|
||||
}
|
||||
} else {
|
||||
if (_clkHZ > 30000000) {
|
||||
printWarn("Jtag probe limited to 30MHz");
|
||||
_clkHZ = 3000000;
|
||||
}
|
||||
}
|
||||
|
||||
presc = (base_freq /(_clkHZ * 2)) -1;
|
||||
real_freq = base_freq / ((1+presc)*2);
|
||||
if (real_freq > clkHZ)
|
||||
presc = (base_freq /(_clkHZ * 2)) -1;
|
||||
real_freq = base_freq / ((1+presc)*2);
|
||||
if (real_freq > _clkHZ)
|
||||
presc ++;
|
||||
real_freq = base_freq / ((1+presc)*2);
|
||||
display("presc : %d input freq : %d requested freq : %d real freq : %d\n",
|
||||
real_freq = base_freq / ((1+presc)*2);
|
||||
printInfo("Jtag frequency : requested " + std::to_string(clkHZ) +
|
||||
"Hz -> real " + std::to_string(real_freq) + "Hz");
|
||||
display("presc : %d input freq : %d requested freq : %d real freq : %d\n",
|
||||
presc, base_freq, _clkHZ, real_freq);
|
||||
buffer[1] = presc & 0xff;
|
||||
buffer[2] = (presc >> 8) & 0xff;
|
||||
buffer[1] = presc & 0xff;
|
||||
buffer[2] = (presc >> 8) & 0xff;
|
||||
|
||||
mpsse_store(buffer, 3);
|
||||
ret = mpsse_write();
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Error: write for frequency return %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
if (ret < 0) {
|
||||
fprintf(stderr, "Error: write for frequency return %d\n", ret);
|
||||
return -1;
|
||||
}
|
||||
ret = ftdi_read_data(_ftdi, buffer, 4);
|
||||
ftdi_usb_purge_buffers(_ftdi);
|
||||
|
||||
return real_freq;
|
||||
return real_freq;
|
||||
}
|
||||
|
||||
int FTDIpp_MPSSE::mpsse_store(unsigned char c)
|
||||
|
|
@ -622,11 +632,11 @@ bool FTDIpp_MPSSE::search_with_dev(const string &device)
|
|||
|
||||
/* Get closest usb device parent (we need VIP/PID) */
|
||||
usbdeviceparent =
|
||||
udev_device_get_parent_with_subsystem_devtype(dev, "usb",
|
||||
udev_device_get_parent_with_subsystem_devtype(dev, "usb",
|
||||
"usb_device");
|
||||
if (!usbdeviceparent) {
|
||||
printf
|
||||
("Unable to find parent usb device! Is this actually an USB device ?\n");
|
||||
("Unable to find parent usb device! Is this actually an USB device ?\n");
|
||||
udev_device_unref(dev);
|
||||
udev_unref(udev);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class FTDIpp_MPSSE {
|
|||
/* gpio */
|
||||
bool __gpio_write(bool low_pins);
|
||||
protected:
|
||||
int _clkHZ;
|
||||
uint32_t _clkHZ;
|
||||
struct ftdi_context *_ftdi;
|
||||
int _buffer_size;
|
||||
int _num;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@ void UsbBlaster::init_internal()
|
|||
int UsbBlaster::setClkFreq(uint32_t clkHZ)
|
||||
{
|
||||
(void) clkHZ;
|
||||
printWarn("USB-Blaster has a 24MHz fixed frequency");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue