On Fri, 27 Nov 2015 15:35:17 +0100 Bernhard Nortmann <[email protected]> wrote:
> This patch adds two new source files that will deal will code > related to progress callbacks and display. I have decided to > keep this separate, as there will be many smaller routines > involved, which otherwise would bloat fel.c unnecessarily. > > For starters, let's also move the gettime() function there. > > Signed-off-by: Bernhard Nortmann <[email protected]> > --- > Makefile | 2 +- > fel.c | 10 +--------- > progress.c | 40 ++++++++++++++++++++++++++++++++++++++++ > progress.h | 34 ++++++++++++++++++++++++++++++++++ > 4 files changed, 76 insertions(+), 10 deletions(-) > create mode 100644 progress.c > create mode 100644 progress.h > > diff --git a/Makefile b/Makefile > index 53d6a0d..7fb0931 100644 > --- a/Makefile > +++ b/Makefile > @@ -83,7 +83,7 @@ LIBUSB = libusb-1.0 > LIBUSB_CFLAGS = `pkg-config --cflags $(LIBUSB)` > LIBUSB_LIBS = `pkg-config --libs $(LIBUSB)` > > -sunxi-fel: fel.c fel-to-spl-thunk.h > +sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h > $(CC) $(CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) > $(LIBS) $(LIBUSB_LIBS) > > sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h > diff --git a/fel.c b/fel.c > index 3e4852f..aca8162 100644 > --- a/fel.c > +++ b/fel.c > @@ -32,9 +32,9 @@ > #include <stdarg.h> > #include <errno.h> > #include <unistd.h> > -#include <sys/time.h> > > #include "endian_compat.h" > +#include "progress.h" > > struct aw_usb_request { > char signature[8]; > @@ -1186,14 +1186,6 @@ static int aw_fel_get_endpoint(libusb_device_handle > *usb) > return 0; > } > > -/* Less reliable than clock_gettime, but does not require linking with -lrt > */ > -static double gettime(void) > -{ > - struct timeval tv; > - gettimeofday(&tv, NULL); > - return tv.tv_sec + (double)tv.tv_usec / 1000000.; > -} > - > int main(int argc, char **argv) > { > int rc; > diff --git a/progress.c b/progress.c > new file mode 100644 > index 0000000..9c2a7d4 > --- /dev/null > +++ b/progress.c > @@ -0,0 +1,40 @@ > +/* > + * Copyright (C) 2015 Bernhard Nortmann <[email protected]> > + * > + * 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, see <http://www.gnu.org/licenses/>. > + */ > +#include "progress.h" > + > +#include <stdio.h> > +#include <sys/time.h> > +#include <unistd.h> > + > +#include "common.h" > + > +/* Less reliable than clock_gettime, but does not require linking with -lrt > */ > +inline double gettime(void) > +{ > + struct timeval tv; > + gettimeofday(&tv, NULL); > + return tv.tv_sec + (double)tv.tv_usec / 1000000.; > +} > + > +/* Update progress status, passing information to the callback function. */ > +void progress_update(size_t UNUSED(bytes_done)) > +{ > + /* > + * This is a non-functional placeholder! > + * It will be replaced in a later patch. > + */ > +} > diff --git a/progress.h b/progress.h > new file mode 100644 > index 0000000..360988e > --- /dev/null > +++ b/progress.h > @@ -0,0 +1,34 @@ > +/* > + * Copyright (C) 2015 Bernhard Nortmann <[email protected]> > + * > + * 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, see <http://www.gnu.org/licenses/>. > + */ > +#ifndef _SUNXI_TOOLS_PROGRESS_H > +#define _SUNXI_TOOLS_PROGRESS_H > + > +#include <stdbool.h> > +#include <stddef.h> > + > +/* function pointer type for a progress callback / notification */ > +typedef void (*progress_cb_t)(size_t total, size_t done); > + > +/* conversion helper macros */ > +#define kilo(value) ((double)value / 1000.) /* SI prefix "k" */ > +#define kibi(value) ((double)value / 1024.) /* binary prefix "Ki", "K" */ Parentheses are needed around 'value'. This is necessary to correctly handle something like "kilo(2000 + 2000)" > +double gettime(void); > + > +void progress_update(size_t bytes_done); > + > +#endif /* _SUNXI_TOOLS_PROGRESS_H */ If the kilo/kibi macros are fixed (this can be done when pushing the patch, so no need to re-send it): Reviewed-by: Siarhei Siamashka <[email protected]> -- Best regards, Siarhei Siamashka -- You received this message because you are subscribed to the Google Groups "linux-sunxi" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
