Skip to content

Commit

Permalink
correct loop remaining evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Paciente8159 committed Jan 14, 2025
1 parent 9d380da commit 6e7ee85
Showing 1 changed file with 54 additions and 39 deletions.
93 changes: 54 additions & 39 deletions uCNC/src/hal/mcus/mcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -344,45 +344,60 @@ extern "C"
#error "MCU_CYCLES_PER_LOOP_OVERHEAD not defined for this MCU"
#endif

#define mcu_delay_cycles(X) \
do \
{ \
if ((X) / MCU_CYCLES_PER_LOOP) \
{ \
mcu_delay_loop(((X) / MCU_CYCLES_PER_LOOP)); \
} \
switch (((X) % MCU_CYCLES_PER_LOOP)) \
{ \
case 10: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 9: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 8: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 7: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 6: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 5: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 4: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 3: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 2: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 1: \
asm volatile("nop"); \
} \
#define mcu_delay_cycles(X) \
do \
{ \
if (((X - MCU_CYCLES_PER_LOOP_OVERHEAD) / MCU_CYCLES_PER_LOOP) > 0) \
{ \
mcu_delay_loop((uint16_t)((X - MCU_CYCLES_PER_LOOP_OVERHEAD) / MCU_CYCLES_PER_LOOP)); \
} \
switch ((((X - MCU_CYCLES_PER_LOOP_OVERHEAD - MCU_CYCLES_PER_LOOP) >= 0) ? ((X - MCU_CYCLES_PER_LOOP_OVERHEAD) % MCU_CYCLES_PER_LOOP) : (X))) \
{ \
case 15: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 14: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 13: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 12: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 11: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 10: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 9: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 8: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 7: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 6: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 5: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 4: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 3: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 2: \
asm volatile("nop"); \
__FALL_THROUGH__ \
case 1: \
asm volatile("nop"); \
} \
} while (0)
#endif

Expand Down

0 comments on commit 6e7ee85

Please sign in to comment.