diff --git a/src/platforms/libftdi/Makefile.inc b/src/platforms/libftdi/Makefile.inc index 9686050..12c4696 100644 --- a/src/platforms/libftdi/Makefile.inc +++ b/src/platforms/libftdi/Makefile.inc @@ -8,5 +8,5 @@ else ifneq (, $(findstring cygwin, $(SYS))) LDFLAGS += -lusb-1.0 -lws2_32 endif VPATH += platforms/pc -SRC += timing.c cl_utils.c +SRC += timing.c cl_utils.c utils.c CFLAGS +=-I ./target -I./platforms/pc diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 643304c..8fad4cc 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -290,34 +290,7 @@ int platform_buffer_read(uint8_t *data, int size) return size; } -#if defined(_WIN32) && !defined(__MINGW32__) -#warning "This vasprintf() is dubious!" -int vasprintf(char **strp, const char *fmt, va_list ap) -{ - int size = 128, ret = 0; - - *strp = malloc(size); - while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) - *strp = realloc(*strp, size <<= 1); - - return ret; -} -#endif - const char *platform_target_voltage(void) { return "not supported"; } - -void platform_delay(uint32_t ms) -{ - usleep(ms * 1000); -} - -uint32_t platform_time_ms(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); -} - diff --git a/src/platforms/pc-hosted/Makefile.inc b/src/platforms/pc-hosted/Makefile.inc index 8a35408..2ddb9fb 100644 --- a/src/platforms/pc-hosted/Makefile.inc +++ b/src/platforms/pc-hosted/Makefile.inc @@ -11,4 +11,4 @@ else ifneq (, $(findstring cygwin, $(SYS))) LDFLAGS += -lusb-1.0 -lws2_32 endif VPATH += platforms/pc -SRC += cl_utils.c timing.c +SRC += cl_utils.c timing.c utils.c diff --git a/src/platforms/pc-hosted/platform.c b/src/platforms/pc-hosted/platform.c index d543cfb..f95859e 100644 --- a/src/platforms/pc-hosted/platform.c +++ b/src/platforms/pc-hosted/platform.c @@ -307,20 +307,6 @@ int platform_buffer_read(uint8_t *data, int maxsize) return 0; } -#if defined(_WIN32) && !defined(__MINGW32__) -#warning "This vasprintf() is dubious!" -int vasprintf(char **strp, const char *fmt, va_list ap) -{ - int size = 128, ret = 0; - - *strp = malloc(size); - while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) - *strp = realloc(*strp, size <<= 1); - - return ret; -} -#endif - const char *platform_target_voltage(void) { @@ -340,15 +326,3 @@ const char *platform_target_voltage(void) return (char *)&construct[1]; } - -void platform_delay(uint32_t ms) -{ - usleep(ms * 1000); -} - -uint32_t platform_time_ms(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); -} diff --git a/src/platforms/pc-stlinkv2/Makefile.inc b/src/platforms/pc-stlinkv2/Makefile.inc index 1777474..299a815 100644 --- a/src/platforms/pc-stlinkv2/Makefile.inc +++ b/src/platforms/pc-stlinkv2/Makefile.inc @@ -9,5 +9,5 @@ else ifneq (, $(findstring cygwin, $(SYS))) LDFLAGS += -lws2_32 endif VPATH += platforms/pc -SRC += timing.c stlinkv2.c cl_utils.c +SRC += timing.c stlinkv2.c cl_utils.c utils.c OWN_HL = 1 diff --git a/src/platforms/pc-stlinkv2/platform.c b/src/platforms/pc-stlinkv2/platform.c index 61e1796..e3f0a1f 100644 --- a/src/platforms/pc-stlinkv2/platform.c +++ b/src/platforms/pc-stlinkv2/platform.c @@ -69,29 +69,3 @@ int platform_buffer_read(uint8_t *data, int size) (void) data; return size; } - -#if defined(_WIN32) && !defined(__MINGW32__) -#warning "This vasprintf() is dubious!" -int vasprintf(char **strp, const char *fmt, va_list ap) -{ - int size = 128, ret = 0; - - *strp = malloc(size); - while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) - *strp = realloc(*strp, size <<= 1); - - return ret; -} -#endif - -void platform_delay(uint32_t ms) -{ - usleep(ms * 1000); -} - -uint32_t platform_time_ms(void) -{ - struct timeval tv; - gettimeofday(&tv, NULL); - return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); -} diff --git a/src/platforms/pc/utils.c b/src/platforms/pc/utils.c new file mode 100644 index 0000000..b74c8ae --- /dev/null +++ b/src/platforms/pc/utils.c @@ -0,0 +1,55 @@ +/* + * This file is part of the Black Magic Debug project. + * + * Copyright (C) 2020 Uwe Bonnes (bon@elektron.ikp.physik.tu-darmstadt.de) + * Base on code: + * Copyright (C) 2011 Black Sphere Technologies Ltd. + * Written by Gareth McMullin + * and others. + * + * 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 3 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 . + */ + +/* This file deduplicates codes used in several pc-hosted platforms + */ + +#include +#include +#include + +#if defined(_WIN32) && !defined(__MINGW32__) +#warning "This vasprintf() is dubious!" +int vasprintf(char **strp, const char *fmt, va_list ap) +{ + int size = 128, ret = 0; + + *strp = malloc(size); + while(*strp && ((ret = vsnprintf(*strp, size, fmt, ap)) == size)) + *strp = realloc(*strp, size <<= 1); + + return ret; +} +#endif + +void platform_delay(uint32_t ms) +{ + usleep(ms * 1000); +} + +uint32_t platform_time_ms(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +}