diff --git a/README.md b/README.md index 8d408bc..a49d9b4 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,8 @@ openFPGALoader -- a program to flash FPGA -r, --reset reset FPGA after operations --spi SPI mode (only for FTDI in serial mode) -v, --verbose Produce verbose output + --verbose-level arg verbose level -1: quiet, 0: normal, 1:verbose, + 2:debug -h, --help Give this help list --verify Verify write operation (SPI Flash only) -V, --Version Print program version diff --git a/src/jtag.cpp b/src/jtag.cpp index 3707f4c..5435f87 100644 --- a/src/jtag.cpp +++ b/src/jtag.cpp @@ -29,7 +29,7 @@ using namespace std; #define DEBUG 0 -#ifdef DEBUG +#if DEBUG #define display(...) \ do { if (_verbose) fprintf(stdout, __VA_ARGS__);}while(0) #else @@ -59,9 +59,9 @@ using namespace std; */ Jtag::Jtag(cable_t &cable, const jtag_pins_conf_t *pin_conf, string dev, - const string &serial, uint32_t clkHZ, bool verbose, + const string &serial, uint32_t clkHZ, int8_t verbose, const string &firmware_path): - _verbose(verbose), + _verbose(verbose > 1), _state(RUN_TEST_IDLE), _tms_buffer_size(128), _num_tms(0), _board_name("nope"), device_index(0) diff --git a/src/jtag.hpp b/src/jtag.hpp index b7b7e3a..73ab548 100644 --- a/src/jtag.hpp +++ b/src/jtag.hpp @@ -18,7 +18,7 @@ class Jtag { public: Jtag(cable_t &cable, const jtag_pins_conf_t *pin_conf, std::string dev, - const std::string &serial, uint32_t clkHZ, bool verbose = false, + const std::string &serial, uint32_t clkHZ, int8_t verbose = 0, const std::string &firmware_path=""); ~Jtag(); @@ -90,13 +90,13 @@ class Jtag { const char *getStateName(tapState_t s); /* utilities */ - void setVerbose(bool verbose){_verbose = verbose;} + void setVerbose(int8_t verbose){_verbose = verbose;} private: void init_internal(cable_t &cable, const std::string &dev, const std::string &serial, const jtag_pins_conf_t *pin_conf, uint32_t clkHZ, const std::string &firmware_path); - bool _verbose; + int8_t _verbose; int _state; int _tms_buffer_size; int _num_tms; diff --git a/src/main.cpp b/src/main.cpp index 3663da3..6ac9c83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -299,7 +299,7 @@ int main(int argc, char **argv) Jtag *jtag; try { jtag = new Jtag(cable, &pins_config, args.device, args.ftdi_serial, - args.freq, false, args.probe_firmware); + args.freq, args.verbose, args.probe_firmware); } catch (std::exception &e) { printError("JTAG init failed with: " + string(e.what())); return EXIT_FAILURE; @@ -476,6 +476,7 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p string freqo; vector pins; bool verbose, quiet; + int8_t verbose_level = -2; try { cxxopts::Options options(argv[0], "openFPGALoader -- a program to flash FPGA", ""); @@ -534,6 +535,8 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p ("spi", "SPI mode (only for FTDI in serial mode)", cxxopts::value(args->spi)) ("v,verbose", "Produce verbose output", cxxopts::value(verbose)) + ("verbose-level", "verbose level -1: quiet, 0: normal, 1:verbose, 2:debug", + cxxopts::value(verbose_level)) ("h,help", "Give this help list") ("verify", "Verify write operation (SPI Flash only)", cxxopts::value(args->verify)) @@ -555,6 +558,15 @@ int parse_opt(int argc, char **argv, struct arguments *args, jtag_pins_conf_t *p args->verbose = 1; if (quiet) args->verbose = -1; + if (verbose_level != -2) { + if ((verbose && verbose_level != 1) || + (quiet && verbose_level != -1)) { + printError("Error: mismatch quiet/verbose and verbose-level\n"); + throw std::exception(); + } + + args->verbose = verbose_level; + } if (result.count("Version")) { cout << "openFPGALoader " << VERSION << endl;