From caaf7837a55bd8c4fca1a6e0c8f929334abf9305 Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 16 Jul 2022 02:45:25 +0100 Subject: [PATCH] swdptap: Made the cycle code a little easier to reason about This doesn't actually change the resulting binary size, so worth doing --- src/platforms/common/swdptap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platforms/common/swdptap.c b/src/platforms/common/swdptap.c index 7fa4fe2..82381cf 100644 --- a/src/platforms/common/swdptap.c +++ b/src/platforms/common/swdptap.c @@ -59,12 +59,12 @@ static void swdptap_turnaround(const swdio_status_t dir) SWDIO_MODE_DRIVE(); } -static uint32_t swdptap_seq_in_swd_delay(size_t clock_cycles) __attribute__((optimize(3))); -static uint32_t swdptap_seq_in_swd_delay(size_t clock_cycles) +static uint32_t swdptap_seq_in_swd_delay(const size_t clock_cycles) __attribute__((optimize(3))); +static uint32_t swdptap_seq_in_swd_delay(const size_t clock_cycles) { size_t index = 0; uint32_t value = 0; - while (clock_cycles--) { + for (size_t cycle = 0; cycle < clock_cycles; ++cycle) { if (gpio_get(SWDIO_PORT, SWDIO_PIN)) value |= (1U << index); gpio_set(SWCLK_PORT, SWCLK_PIN); @@ -78,12 +78,12 @@ static uint32_t swdptap_seq_in_swd_delay(size_t clock_cycles) return value; } -static uint32_t swdptap_seq_in_no_delay(size_t clock_cycles) __attribute__((optimize(3))); -static uint32_t swdptap_seq_in_no_delay(size_t clock_cycles) +static uint32_t swdptap_seq_in_no_delay(const size_t clock_cycles) __attribute__((optimize(3))); +static uint32_t swdptap_seq_in_no_delay(const size_t clock_cycles) { size_t index = 0; uint32_t value = 0; - while (clock_cycles--) { + for (size_t cycle = 0; cycle < clock_cycles; ++cycle) { if (gpio_get(SWDIO_PORT, SWDIO_PIN)) value |= (1U << index); gpio_set(SWCLK_PORT, SWCLK_PIN);