From d0955aa6e07d4ece79012336552b886ff0b13bc9 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Sun, 23 Nov 2014 21:49:56 +0000 Subject: [PATCH] Allow the -B option argument to be suffixed with Hz, kHz, or MHz, in order to specify a bitclock frequency rather than period. git-svn-id: svn://svn.savannah.nongnu.org/avrdude/trunk/avrdude@1347 81a1dc3b-b13d-400b-aceb-764788c761c2 --- ChangeLog | 8 ++++++++ NEWS | 3 +++ avrdude.1 | 4 +++- doc/avrdude.texi | 2 ++ main.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 10e5eebe..d9b1d828 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2014-11-23 Joerg Wunsch + + * main.c: Allow the -B option argument to be suffixed with Hz, + kHz, or MHz, in order to specify a bitclock frequency rather than + period. + * avrdude.1: Document the -B option changes. + * doc/avrdude.texi: (Dito.) + 2014-11-23 Joerg Wunsch bug #40870: config nitpick: ATtiny25/45/85 have 1 calibration byte not 2 diff --git a/NEWS b/NEWS index ecf411a1..5a80dc59 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ Current: used by all the more modern Atmel tools (AVRISPmkII, JTAGICEmkII in ISP mode, STK600 in ISP mode). + - The -B option can be suffixed with "Hz", "kHz", or "MHz", in + order to specify a bitclock frequency rather than period. + * New programmers supported: - ... diff --git a/avrdude.1 b/avrdude.1 index 5efa49d8..906f375f 100644 --- a/avrdude.1 +++ b/avrdude.1 @@ -18,7 +18,7 @@ .\" .\" $Id$ .\" -.Dd DATE January 17, 2014 +.Dd DATE November 23, 2014 .Os .Dt AVRDUDE 1 .Sh NAME @@ -257,6 +257,8 @@ programmer's entry of the configuration file. .It Fl B Ar bitclock Specify the bit clock period for the JTAG interface or the ISP clock (JTAG ICE only). The value is a floating-point number in microseconds. +Alternatively, the value might be suffixed with "Hz", "kHz", or "MHz", +in order to specify the bit clock frequency, rather than a period. The default value of the JTAG ICE results in about 1 microsecond bit clock period, suitable for target MCUs running at 4 MHz clock and above. diff --git a/doc/avrdude.texi b/doc/avrdude.texi index a3012050..240dd206 100644 --- a/doc/avrdude.texi +++ b/doc/avrdude.texi @@ -354,6 +354,8 @@ programmer's entry of the configuration file. @item -B @var{bitclock} Specify the bit clock period for the JTAG interface or the ISP clock (JTAG ICE only). The value is a floating-point number in microseconds. +Alternatively, the value might be suffixed with "Hz", "kHz", or "MHz", +in order to specify the bit clock frequency, rather than a period. The default value of the JTAG ICE results in about 1 microsecond bit clock period, suitable for target MCUs running at 4 MHz clock and above. diff --git a/main.c b/main.c index bfe2b596..7232e4f2 100644 --- a/main.c +++ b/main.c @@ -476,7 +476,48 @@ int main(int argc, char * argv []) case 'B': /* specify JTAG ICE bit clock period */ bitclock = strtod(optarg, &e); - if ((e == optarg) || (*e != 0) || bitclock == 0.0) { + if (*e != 0) { + /* trailing unit of measure present */ + int suffixlen = strlen(e); + switch (suffixlen) { + case 2: + if ((e[0] != 'h' && e[0] != 'H') || e[1] != 'z') + bitclock = 0.0; + else + /* convert from Hz to microseconds */ + bitclock = 1E6 / bitclock; + break; + + case 3: + if ((e[1] != 'h' && e[1] != 'H') || e[2] != 'z') + bitclock = 0.0; + else { + switch (e[0]) { + case 'M': + case 'm': /* no Millihertz here :) */ + bitclock = 1.0 / bitclock; + break; + + case 'k': + bitclock = 1E3 / bitclock; + break; + + default: + bitclock = 0.0; + break; + } + } + break; + + default: + bitclock = 0.0; + break; + } + if (bitclock == 0.0) + avrdude_message(MSG_INFO, "%s: invalid bit clock unit of measure '%s'\n", + progname, e); + } + if ((e == optarg) || bitclock == 0.0) { avrdude_message(MSG_INFO, "%s: invalid bit clock period specified '%s'\n", progname, optarg); exit(1);