From 9a8dbdeff7b9bac70719ddb51a6f83a1266a2d44 Mon Sep 17 00:00:00 2001 From: Gareth McMullin Date: Mon, 2 Mar 2015 23:27:42 -0800 Subject: [PATCH] Fix errors when building for non-native platforms. --- src/platforms/f4discovery/platform.h | 1 + src/platforms/launchpad-icdi/platform.c | 14 ++++++++++++-- src/platforms/launchpad-icdi/platform.h | 2 ++ src/platforms/libftdi/platform.c | 19 +++++++++++++++++++ src/platforms/stlink/platform.h | 1 + src/platforms/swlink/platform.h | 1 + 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/platforms/f4discovery/platform.h b/src/platforms/f4discovery/platform.h index 3c5c582d..68027ee0 100644 --- a/src/platforms/f4discovery/platform.h +++ b/src/platforms/f4discovery/platform.h @@ -28,6 +28,7 @@ #include "gpio.h" #include "morse.h" #include "timing.h" +#include "target.h" #include diff --git a/src/platforms/launchpad-icdi/platform.c b/src/platforms/launchpad-icdi/platform.c index e689f0cb..1a3598a0 100644 --- a/src/platforms/launchpad-icdi/platform.c +++ b/src/platforms/launchpad-icdi/platform.c @@ -86,10 +86,20 @@ platform_init(void) cdcacm_init(); } +void platform_timeout_set(uint32_t ms) +{ + timeout_counter = ms / 10; +} + +bool platform_timeout_is_expired(void) +{ + return timeout_counter == 0; +} + void platform_delay(uint32_t delay) { - timeout_counter = delay * 10; - while(timeout_counter); + platform_timeout_set(delay); + while (platform_timeout_is_expired()); } const char *platform_target_voltage(void) diff --git a/src/platforms/launchpad-icdi/platform.h b/src/platforms/launchpad-icdi/platform.h index eb3ac6e4..ddc20353 100644 --- a/src/platforms/launchpad-icdi/platform.h +++ b/src/platforms/launchpad-icdi/platform.h @@ -18,6 +18,8 @@ #define __PLATFORM_H #include "gdb_packet.h" +#include "target.h" +#include "morse.h" #include diff --git a/src/platforms/libftdi/platform.c b/src/platforms/libftdi/platform.c index 634090df..3062698e 100644 --- a/src/platforms/libftdi/platform.c +++ b/src/platforms/libftdi/platform.c @@ -21,6 +21,7 @@ #include "gdb_if.h" #include +#include struct ftdi_context *ftdic; @@ -258,3 +259,21 @@ void platform_delay(uint32_t delay) usleep(delay * 100000); } +static uint32_t timeout_time; +static uint32_t time_ms(void) +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return (tv.tv_sec * 1000) + (tv.tv_usec / 1000); +} + +void platform_timeout_set(uint32_t ms) +{ + timeout_time = time_ms() + ms; +} + +bool platform_timeout_is_expired(void) +{ + return time_ms() > timeout_time; +} + diff --git a/src/platforms/stlink/platform.h b/src/platforms/stlink/platform.h index f026db33..549b6d6d 100644 --- a/src/platforms/stlink/platform.h +++ b/src/platforms/stlink/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "target.h" #include #include diff --git a/src/platforms/swlink/platform.h b/src/platforms/swlink/platform.h index 27cc299d..e82124af 100644 --- a/src/platforms/swlink/platform.h +++ b/src/platforms/swlink/platform.h @@ -27,6 +27,7 @@ #include "gdb_packet.h" #include "gpio.h" #include "timing.h" +#include "target.h" #include