Skip to content

Commit

Permalink
jtagtap, swdptap, timing: fixup! Update the delay_busy, for-loop form
Browse files Browse the repository at this point in the history
  • Loading branch information
ALTracer committed Dec 2, 2023
1 parent 2721f24 commit 162e8f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
11 changes: 2 additions & 9 deletions src/platforms/common/jtagtap.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,8 @@ static void jtagtap_reset(void)
/* Busy-looping delay snippet for GPIO bitbanging (rely on inlining) */
static inline void platform_delay_busy(const uint32_t loops)
{
#if 1
register uint32_t i = loops;
do {
__asm__("nop");
} while (--i > 0U);
#else
for (register uint32_t counter = loops; --counter > 0;)
__asm__("nop");
#endif
for (register uint32_t counter = loops; --counter > 0U;)
__asm__("");
}

static bool jtagtap_next_clk_delay()
Expand Down
10 changes: 10 additions & 0 deletions src/platforms/common/stm32/timing_stm32.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ uint32_t platform_max_frequency_get(void)
void platform_delay_busy(const uint32_t loops)
{
/* Avoid using `volatile` variables which incur stack accesses */
#if 0
register uint32_t i = loops;
do {
/*
Expand All @@ -226,4 +227,13 @@ void platform_delay_busy(const uint32_t loops)
*/
__asm__("nop");
} while (--i > 0U);
#else
/*
* Another version which still assembles to SUBS+BNE.N; the NOP can be eliminated
* in favor of an empty inline asm/volatile block if it's enough to suppress DCE.
* Note that the predecrement has to be merged into the condition expression.
*/
for (register uint32_t i = loops; --i > 0U;)
__asm__("");
#endif
}
11 changes: 2 additions & 9 deletions src/platforms/common/swdptap.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,8 @@ void swdptap_init(void)
/* Busy-looping delay snippet for GPIO bitbanging (rely on inlining) */
static inline void platform_delay_busy(const uint32_t loops)
{
#if 1
register uint32_t i = loops;
do {
__asm__("nop");
} while (--i > 0U);
#else
for (register uint32_t counter = loops; counter > 0; --counter)
__asm__("nop");
#endif
for (register uint32_t counter = loops; --counter > 0U;)
__asm__("");
}

static void swdptap_turnaround(const swdio_status_t dir)
Expand Down

0 comments on commit 162e8f6

Please sign in to comment.