review fixes: refactoring and readme update

This commit is contained in:
Rony Kelner 2020-09-22 19:22:51 +03:00
parent 48c747edd6
commit 41f1a7a61a
3 changed files with 13 additions and 21 deletions

View File

@ -111,6 +111,7 @@ openFPGALoader -- a program to flash cyclone10 LP FPGA
-b, --board=BOARD board name, may be used instead of cable -b, --board=BOARD board name, may be used instead of cable
-c, --cable=CABLE jtag interface -c, --cable=CABLE jtag interface
-d, --device=DEVICE device to use (/dev/ttyUSBx) -d, --device=DEVICE device to use (/dev/ttyUSBx)
--ftdi-channel=CHANNEL FTDI chip channel number (channels 0-3 map to A-D)
--detect detect FPGA --detect detect FPGA
--freq=FREQ jtag frequency (Hz) --freq=FREQ jtag frequency (Hz)
-f, --write-flash write bitstream in flash (default: false, only for -f, --write-flash write bitstream in flash (default: false, only for

View File

@ -22,20 +22,6 @@ typedef struct {
FTDIpp_MPSSE::mpsse_bit_config config; FTDIpp_MPSSE::mpsse_bit_config config;
} cable_t; } 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 = { 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 // 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 // some cables requires explicit values on some of the I/Os

View File

@ -116,15 +116,13 @@ int main(int argc, char **argv)
cable = select_cable->second; cable = select_cable->second;
if (args.ftdi_channel != -1) { if (args.ftdi_channel != -1) {
if (args.ftdi_channel < 0 or args.ftdi_channel > 3) { if (cable.type != MODE_FTDI_SERIAL && cable.type != MODE_FTDI_BITBANG){
printError("Error: valid FTDI channels are 0-3."); printError("Error: FTDI channel param is for FTDI cables.");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (ftdi_update_channel(cable, args.ftdi_channel)) { int mapping[] = {INTERFACE_A, INTERFACE_B, INTERFACE_C, INTERFACE_D};
printError("Error: FTDI channel param is invalid. Is it a FTDI cable?"); cable.config.interface = mapping[args.ftdi_channel];
return EXIT_FAILURE;
}
} }
/* jtag base */ /* jtag base */
@ -262,7 +260,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", ("b,board", "board name, may be used instead of cable",
cxxopts::value<string>(args->board)) cxxopts::value<string>(args->board))
("c,cable", "jtag interface", cxxopts::value<string>(args->cable)) ("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)) ("ftdi-channel", "FTDI chip channel number (channels 0-3 map to A-D)", cxxopts::value<int>(args->ftdi_channel))
#ifdef USE_UDEV #ifdef USE_UDEV
("d,device", "device to use (/dev/ttyUSBx)", ("d,device", "device to use (/dev/ttyUSBx)",
cxxopts::value<string>(args->device)) cxxopts::value<string>(args->device))
@ -331,6 +329,13 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p
args->freq = static_cast<uint32_t>(freq); args->freq = static_cast<uint32_t>(freq);
} }
if (result.count("ftdi-channel")) {
if (args->ftdi_channel < 0 || args->ftdi_channel > 3) {
printError("Error: valid FTDI channels are 0-3.");
throw std::exception();
}
}
if (result.count("pins")) { if (result.count("pins")) {
if (pins.size() != 4) { if (pins.size() != 4) {
printError("Error: pin_config need 4 pins"); printError("Error: pin_config need 4 pins");