2003-05-27 Theodore A. Roth * Makefile.am (avrdude_SOURCES): Add replace.[ch]. * configure.ac: AC_DEFINE usec_sleep to usleep except on windows. * replace.c: New file. * replace.h: New file. * avr.c: Change usleep() calls to usec_sleep() calls. * par.c: Ditto. * stk500.c: Ditto. Index: Makefile.am =================================================================== RCS file: /cvsroot/avrdude/avrdude/Makefile.am,v retrieving revision 1.16 diff -u -r1.16 Makefile.am --- Makefile.am 13 Mar 2003 03:52:18 -0000 1.16 +++ Makefile.am 27 May 2003 19:28:05 -0000 @@ -69,6 +69,8 @@ ppi.c \ ppi.h \ ppiwin.c \ + replace.c \ + replace.h \ serial.h \ ser_posix.c \ ser_win32.c \ Index: avr.c =================================================================== RCS file: /cvsroot/avrdude/avrdude/avr.c,v retrieving revision 1.55 diff -u -r1.55 avr.c --- avr.c 24 Mar 2003 07:09:15 -0000 1.55 +++ avr.c 27 May 2003 19:28:05 -0000 @@ -32,6 +32,7 @@ #include "lists.h" #include "pindefs.h" #include "ppi.h" +#include "replace.h" #define DEBUG 0 @@ -470,7 +471,7 @@ * since we don't know what voltage the target AVR is powered by, be * conservative and delay the max amount the spec says to wait */ - usleep(mem->max_write_delay); + usec_sleep(mem->max_write_delay); pgm->pgm_led(pgm, OFF); return 0; @@ -571,7 +572,7 @@ * read operation not supported for this memory type, just wait * the max programming time and then return */ - usleep(mem->max_write_delay); /* maximum write delay */ + usec_sleep(mem->max_write_delay); /* maximum write delay */ pgm->pgm_led(pgm, OFF); return 0; } @@ -579,7 +580,7 @@ tries = 0; ready = 0; while (!ready) { - usleep(mem->min_write_delay); + usec_sleep(mem->min_write_delay); rc = avr_read_byte(pgm, p, mem, addr, &r); if (rc != 0) { pgm->pgm_led(pgm, OFF); @@ -595,7 +596,7 @@ * doesn't work, and we need to delay the worst case write time * specified for the chip. */ - usleep(mem->max_write_delay); + usec_sleep(mem->max_write_delay); rc = avr_read_byte(pgm, p, mem, addr, &r); if (rc != 0) { pgm->pgm_led(pgm, OFF); @@ -615,7 +616,7 @@ * memory bits but not all. We only actually power-off the * device if the data read back does not match what we wrote. */ - usleep(mem->max_write_delay); /* maximum write delay */ + usec_sleep(mem->max_write_delay); /* maximum write delay */ pgm->pgm_led(pgm, OFF); fprintf(stderr, "%s: this device must be powered off and back on to continue\n", @@ -623,7 +624,7 @@ if (pgm->pinno[PPI_AVR_VCC]) { fprintf(stderr, "%s: attempting to do this now ...\n", progname); pgm->powerdown(pgm); - usleep(250000); + usec_sleep(250000); rc = pgm->initialize(pgm, p); if (rc < 0) { fprintf(stderr, "%s: initialization failed, rc=%d\n", progname, rc); Index: configure.ac =================================================================== RCS file: /cvsroot/avrdude/avrdude/configure.ac,v retrieving revision 1.12 diff -u -r1.12 configure.ac --- configure.ac 5 May 2003 02:29:28 -0000 1.12 +++ configure.ac 27 May 2003 19:28:05 -0000 @@ -118,12 +118,21 @@ AC_SUBST(DEFAULT_SER_PORT, $DEFAULT_SER_PORT) # See if we need to drop into the windows subdir. +# Also need to replace usleep(). case $target in *-*-mingw32* | *-*-cygwin* | *-*-windows*) WINDOWS_DIRS="windows" + ac_need_usleep_replacement="yes" ;; esac AC_SUBST(WINDOWS_DIRS,$WINDOWS_DIRS) + +if test "$ac_need_usleep_replacement" != "yes"; then + AC_DEFINE( + [usec_sleep], + [usleep], + [Use system usleep() instead of replacement.]) +fi AC_CONFIG_FILES([ doc/Makefile Index: par.c =================================================================== RCS file: /cvsroot/avrdude/avrdude/par.c,v retrieving revision 1.5 diff -u -r1.5 par.c --- par.c 22 Feb 2003 16:45:13 -0000 1.5 +++ par.c 27 May 2003 19:28:06 -0000 @@ -39,6 +39,7 @@ #include "pgm.h" #include "par.h" #include "ppi.h" +#include "replace.h" #define SLOW_TOGGLE 0 @@ -135,7 +136,7 @@ ppi_clr(fd, pins[pin].reg, pins[pin].bit); #if SLOW_TOGGLE - usleep(1000); + usec_sleep(1000); #endif return 0; @@ -174,13 +175,13 @@ ppi_toggle(fd, pins[pin].reg, pins[pin].bit); #if SLOW_TOGGLE - usleep(1000); + usec_sleep(1000); #endif ppi_toggle(fd, pins[pin].reg, pins[pin].bit); #if SLOW_TOGGLE - usleep(1000); + usec_sleep(1000); #endif return 0; @@ -347,7 +348,7 @@ avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd); pgm->cmd(pgm, cmd, res); - usleep(p->chip_erase_delay); + usec_sleep(p->chip_erase_delay); pgm->initialize(pgm, p); pgm->pgm_led(pgm, OFF); @@ -396,7 +397,7 @@ static void par_powerup(PROGRAMMER * pgm) { ppi_set(pgm->fd, PPIDATA, pgm->pinno[PPI_AVR_VCC]); /* power up */ - usleep(100000); + usec_sleep(100000); } @@ -418,15 +419,15 @@ int tries; pgm->powerup(pgm); - usleep(20000); + usec_sleep(20000); par_setpin(pgm->fd, pgm->pinno[PIN_AVR_SCK], 0); par_setpin(pgm->fd, pgm->pinno[PIN_AVR_RESET], 0); - usleep(20000); + usec_sleep(20000); par_pulsepin(pgm->fd, pgm->pinno[PIN_AVR_RESET]); - usleep(20000); /* 20 ms XXX should be a per-chip parameter */ + usec_sleep(20000); /* 20 ms XXX should be a per-chip parameter */ /* * Enable programming mode. If we are programming an AT90S1200, we @@ -501,7 +502,7 @@ */ par_setpin(pgm->fd, pgm->pinno[PIN_AVR_RESET], 0); - usleep(1); + usec_sleep(1); /* * enable the 74367 buffer, if connected; this signal is active low Index: replace.c =================================================================== RCS file: replace.c diff -N replace.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ replace.c 27 May 2003 19:28:06 -0000 @@ -0,0 +1,43 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2003 Theodore A. Roth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +/* Replacements for functions with portability problems. */ + +#include +#include +#include + +#include "replace.h" + +/* + * A portable usleep() implementation. + */ + +int usec_sleep (unsigned long usec) +{ + struct timeval tv; + + tv.tv_sec = 0; + tv.tv_usec = (long)usec; + + return select (0, NULL, NULL, NULL, &tv); +} + Index: replace.h =================================================================== RCS file: replace.h diff -N replace.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ replace.h 27 May 2003 19:28:06 -0000 @@ -0,0 +1,31 @@ +/* + * avrdude - A Downloader/Uploader for AVR device programmers + * Copyright (C) 2003 Theodore A. Roth + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* $Id$ */ + +/* Replacements for functions with portability problems. */ + +#ifndef __replace_h__ +#define __replace_h__ + +#if !defined (usec_sleep) +extern int usec_sleep (unsigned long usec); +#endif + +#endif /* __replace_h__ */ Index: stk500.c =================================================================== RCS file: /cvsroot/avrdude/avrdude/stk500.c,v retrieving revision 1.32 diff -u -r1.32 stk500.c --- stk500.c 7 Apr 2003 17:18:51 -0000 1.32 +++ stk500.c 27 May 2003 19:28:06 -0000 @@ -39,6 +39,7 @@ #include "pgm.h" #include "stk500_private.h" #include "serial.h" +#include "replace.h" extern int verbose; @@ -194,7 +195,7 @@ avr_set_bits(p->op[AVR_OP_CHIP_ERASE], cmd); pgm->cmd(pgm, cmd, res); - usleep(p->chip_erase_delay); + usec_sleep(p->chip_erase_delay); pgm->initialize(pgm, p); pgm->pgm_led(pgm, OFF);