Add FTDI channel selection command line argument.

This commit is contained in:
Rony Kelner 2020-09-22 11:45:44 +03:00
parent a220226a9e
commit 48c747edd6
2 changed files with 29 additions and 1 deletions

View File

@ -22,6 +22,20 @@ typedef struct {
FTDIpp_MPSSE::mpsse_bit_config config;
} cable_t;
inline int ftdi_update_channel(cable_t &cable, unsigned int channel_num)
{
int mapping[] = {INTERFACE_A,INTERFACE_B, INTERFACE_C, INTERFACE_D};
if (cable.type != MODE_FTDI_SERIAL && cable.type != MODE_FTDI_BITBANG)
return -1;
if (channel_num > 3)
return -2;
cable.config.interface = mapping[channel_num];
return 0;
}
static std::map <std::string, cable_t> cable_list = {
// last 4 bytes are ADBUS7-0 value, ADBUS7-0 direction, ACBUS7-0 value, ACBUS7-0 direction
// some cables requires explicit values on some of the I/Os

View File

@ -44,6 +44,7 @@ struct arguments {
string bit_file;
string device;
string cable;
int ftdi_channel;
uint32_t freq;
string board;
bool pin_config;
@ -65,7 +66,7 @@ int main(int argc, char **argv)
jtag_pins_conf_t pins_config = {0, 0, 0, 0};
/* command line args. */
struct arguments args = {false, false, false, 0, "", "-", "-", 6000000, "-",
struct arguments args = {false, false, false, 0, "", "-", "-", -1, 6000000, "-",
false, false, false, false, false, true, false};
/* parse arguments */
try {
@ -114,6 +115,18 @@ int main(int argc, char **argv)
}
cable = select_cable->second;
if (args.ftdi_channel != -1) {
if (args.ftdi_channel < 0 or args.ftdi_channel > 3) {
printError("Error: valid FTDI channels are 0-3.");
return EXIT_FAILURE;
}
if (ftdi_update_channel(cable, args.ftdi_channel)) {
printError("Error: FTDI channel param is invalid. Is it a FTDI cable?");
return EXIT_FAILURE;
}
}
/* jtag base */
Jtag *jtag;
try {
@ -249,6 +262,7 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p
("b,board", "board name, may be used instead of cable",
cxxopts::value<string>(args->board))
("c,cable", "jtag interface", cxxopts::value<string>(args->cable))
("ftdi_channel", "FTDI chip channel number (channels 0-3 map to A-D)", cxxopts::value<int>(args->ftdi_channel))
#ifdef USE_UDEV
("d,device", "device to use (/dev/ttyUSBx)",
cxxopts::value<string>(args->device))