This patch adds two new source files that will deal with code related to progress callbacks and display. I have decided to keep those 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 | 9 +-------- progress.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ progress.h | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+), 9 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 e9f6450..e4e0170 100644 --- a/fel.c +++ b/fel.c @@ -36,6 +36,7 @@ #include <sys/time.h> #include "endian_compat.h" +#include "progress.h" struct aw_usb_request { char signature[8]; @@ -1044,14 +1045,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 uboot_autostart = 0; /* flag for "uboot" command = U-Boot autostart */ diff --git a/progress.c b/progress.c new file mode 100644 index 0000000..85d23a0 --- /dev/null +++ b/progress.c @@ -0,0 +1,46 @@ +/* + * 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. + * "quick" is an opaque flag that can indicate "small", frequent or + * insignificant updates. It normally gets passed through to the callback + * function, where it might possibly get consideration / special treatment. + * If you have no use for that, simply always pass 'false'. + */ +void progress_update(size_t UNUSED(total), size_t UNUSED(done), bool UNUSED(quick)) +{ + /* + * 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..27e22c5 --- /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, bool quick); + +/* conversion helper macros */ +#define kilo(value) ((double)value / 1000.) /* SI prefix "k" */ +#define kibi(value) ((double)value / 1024.) /* binary prefix "Ki", "K" */ + +double gettime(void); + +void progress_update(size_t total, size_t done, bool quick); + +#endif /* _SUNXI_TOOLS_PROGRESS_H */ -- 2.4.6 -- 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.
