Merge pull request #36 from martin2250/master
add jtag frequency option
This commit is contained in:
commit
9b1c0d42e1
|
|
@ -95,6 +95,7 @@ openFPGALoader -- a program to flash cyclone10 LP FPGA
|
||||||
-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)
|
||||||
--detect detect FPGA
|
--detect detect FPGA
|
||||||
|
--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
|
||||||
Gowin and ECP5 devices)
|
Gowin and ECP5 devices)
|
||||||
--list-boards list all supported boards
|
--list-boards list all supported boards
|
||||||
|
|
|
||||||
50
src/main.cpp
50
src/main.cpp
|
|
@ -43,6 +43,7 @@ struct arguments {
|
||||||
string bit_file;
|
string bit_file;
|
||||||
string device;
|
string device;
|
||||||
string cable;
|
string cable;
|
||||||
|
uint32_t freq;
|
||||||
string board;
|
string board;
|
||||||
bool list_cables;
|
bool list_cables;
|
||||||
bool list_boards;
|
bool list_boards;
|
||||||
|
|
@ -56,6 +57,7 @@ struct arguments {
|
||||||
#define LIST_BOARD 2
|
#define LIST_BOARD 2
|
||||||
#define LIST_FPGA 3
|
#define LIST_FPGA 3
|
||||||
#define DETECT 4
|
#define DETECT 4
|
||||||
|
#define FREQUENCY 5
|
||||||
|
|
||||||
const char *argp_program_version = "openFPGALoader 1.0";
|
const char *argp_program_version = "openFPGALoader 1.0";
|
||||||
const char *argp_program_bug_address = "<gwenhael.goavec-merou@trabucayre.com>";
|
const char *argp_program_bug_address = "<gwenhael.goavec-merou@trabucayre.com>";
|
||||||
|
|
@ -64,6 +66,7 @@ static char args_doc[] = "BIT_FILE";
|
||||||
static error_t parse_opt(int key, char *arg, struct argp_state *state);
|
static error_t parse_opt(int key, char *arg, struct argp_state *state);
|
||||||
static struct argp_option options[] = {
|
static struct argp_option options[] = {
|
||||||
{"cable", 'c', "CABLE", 0, "jtag interface"},
|
{"cable", 'c', "CABLE", 0, "jtag interface"},
|
||||||
|
{"freq", FREQUENCY, "FREQ", 0, "jtag frequency (Hz)"},
|
||||||
{"list-cables", LIST_CABLE, 0, 0, "list all supported cables"},
|
{"list-cables", LIST_CABLE, 0, 0, "list all supported cables"},
|
||||||
{"board", 'b', "BOARD", 0, "board name, may be used instead of cable"},
|
{"board", 'b', "BOARD", 0, "board name, may be used instead of cable"},
|
||||||
{"list-boards", LIST_BOARD, 0, 0, "list all supported boards"},
|
{"list-boards", LIST_BOARD, 0, 0, "list all supported boards"},
|
||||||
|
|
@ -91,7 +94,7 @@ int main(int argc, char **argv)
|
||||||
jtag_pins_conf_t *pins_config = NULL;
|
jtag_pins_conf_t *pins_config = NULL;
|
||||||
|
|
||||||
/* command line args. */
|
/* command line args. */
|
||||||
struct arguments args = {false, false, false, 0, "", "-", "-", "-",
|
struct arguments args = {false, false, false, 0, "", "-", "-", 6000000, "-",
|
||||||
false, false, false, false, true, false};
|
false, false, false, false, true, false};
|
||||||
/* parse arguments */
|
/* parse arguments */
|
||||||
argp_parse(&argp, argc, argv, 0, 0, &args);
|
argp_parse(&argp, argc, argv, 0, 0, &args);
|
||||||
|
|
@ -130,9 +133,9 @@ int main(int argc, char **argv)
|
||||||
/* jtag base */
|
/* jtag base */
|
||||||
Jtag *jtag;
|
Jtag *jtag;
|
||||||
if (args.device == "-")
|
if (args.device == "-")
|
||||||
jtag = new Jtag(cable, pins_config, 6000000, false);
|
jtag = new Jtag(cable, pins_config, args.freq, false);
|
||||||
else
|
else
|
||||||
jtag = new Jtag(cable, pins_config, args.device, 6000000, false);
|
jtag = new Jtag(cable, pins_config, args.device, args.freq, false);
|
||||||
|
|
||||||
/* chain detection */
|
/* chain detection */
|
||||||
vector<int> listDev;
|
vector<int> listDev;
|
||||||
|
|
@ -202,6 +205,35 @@ int main(int argc, char **argv)
|
||||||
delete(jtag);
|
delete(jtag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// parse double from string in enginerring notation
|
||||||
|
// can deal with postfixes k and m, add more when required
|
||||||
|
static error_t parse_eng(string arg, double *dst) {
|
||||||
|
try {
|
||||||
|
size_t end;
|
||||||
|
double base = stod(arg, &end);
|
||||||
|
if (end == arg.size()) {
|
||||||
|
*dst = base;
|
||||||
|
return 0;
|
||||||
|
} else if (end == (arg.size() - 1)) {
|
||||||
|
switch (arg.back()) {
|
||||||
|
case 'k': case 'K':
|
||||||
|
*dst = (uint32_t)(1e3 * base);
|
||||||
|
return 0;
|
||||||
|
case 'm': case 'M':
|
||||||
|
*dst = (uint32_t)(1e6 * base);
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
} catch (...) {
|
||||||
|
cerr << "error : speed: invaild format" << endl;
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* arguments parser */
|
/* arguments parser */
|
||||||
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||||
{
|
{
|
||||||
|
|
@ -235,6 +267,18 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
|
||||||
case 'b':
|
case 'b':
|
||||||
arguments->board = arg;
|
arguments->board = arg;
|
||||||
break;
|
break;
|
||||||
|
case FREQUENCY:
|
||||||
|
double freq;
|
||||||
|
if (parse_eng(string(arg), &freq)) {
|
||||||
|
cerr << "Error: invalid format for --freq" << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
if (freq < 1) {
|
||||||
|
cerr << "Error: --freq must be positive" << endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
arguments->freq = freq;
|
||||||
|
break;
|
||||||
case ARGP_KEY_ARG:
|
case ARGP_KEY_ARG:
|
||||||
arguments->bit_file = arg;
|
arguments->bit_file = arg;
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue