Skip to content

Commit acb5928

Browse files
committed
Add delay loop implementation for M0 core.
1 parent afb6d13 commit acb5928

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

firmware/common/delay.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,23 @@ void delay(uint32_t duration)
3232

3333
void delay_us_at_mhz(uint32_t us, uint32_t mhz)
3434
{
35+
#if defined(LPC43XX_M4)
3536
// The loop below takes 3 cycles per iteration.
3637
uint32_t loop_iterations = (us * mhz) / 3;
3738
asm volatile("start%=:\n"
3839
" subs %[ITERATIONS], #1\n" // 1 cycle
3940
" bpl start%=\n" // 2 cycles
4041
:
4142
: [ITERATIONS] "r"(loop_iterations));
43+
#elif defined(LPC43XX_M0)
44+
// The loop below takes 4 cycles per iteration.
45+
uint32_t loop_iterations = (us * mhz) / 3;
46+
asm volatile("start%=:\n"
47+
" sub %[ITERATIONS], #1\n" // 1 cycle
48+
" bpl start%=\n" // 3 cycles
49+
:
50+
: [ITERATIONS] "r"(loop_iterations));
51+
#else
52+
#error "No delay loop implementation"
53+
#endif
4254
}

0 commit comments

Comments
 (0)