@@ -33,15 +33,16 @@ extern uint16_t delay_fcpu_MHz;
33
33
34
34
inline void modm_fastcode delay_ns(uint32_t ns)
35
35
{
36
- volatile uint32_t overhead_cycles ;
36
+ volatile uint32_t cycles ;
37
37
// ns_per_loop = nanoseconds per cycle times cycles per loop ({{loop}} cycles)
38
38
asm volatile (
39
- ".syntax unified" "\n\t"
40
- "muls.n %0, %0, %2" "\n\t" // multiply the overhead cycles with the ns per cycle: 1-2 cycles on cm3, up to 32 cycles on cm0
41
- "subs.n %1, %1, %0" "\n\t" // subtract the overhead in ns from the input: 1 cycle
42
- "1: subs.n %1, %1, %2" "\n\t" // subtract the ns per loop from the input: 1 cycle
43
- "bpl.n 1b" "\n\t" // keep doing that while result is still positive: 2 cycles (when taken)
44
- : "=r" (overhead_cycles) : "r" (ns), "r" (platform::delay_ns_per_loop), "0" ({{ (overhead / loop) | int}}));
39
+ ".syntax unified \n\t"
40
+ ".align 4 \n\t"
41
+ "muls.n %[cyc], %[cyc], %[dnpl] \n\t" // multiply the overhead cycles with the ns per cycle: 1-2 cycles on cm3, up to 32 cycles on cm0
42
+ "subs.n %[cyc], %[cyc], %[ovhd] \n\t" // subtract the overhead in ns from the input: 1 cycle
43
+ "1: subs.n %[cyc], %[cyc], %[dnpl] \n\t" // subtract the ns per loop from the input: 1 cycle
44
+ "bpl.n 1b" // keep doing that while result is still positive: 2 cycles (when taken)
45
+ : [cyc] "=l" (cycles) : "0" (ns), [dnpl] "l" (platform::delay_ns_per_loop), [ovhd] "l" ({{(overhead / loop) | int}}));
45
46
// => loop is {{loop}} cycles long
46
47
}
47
48
void delay_us(uint32_t us);
0 commit comments