Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/rp2_common/pico_platform/include/pico/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,29 @@ uint __get_current_exception(void);
}
#endif

/*! \brief Helper method to busy-wait for at least the given number of cycles
* \ingroup pico_platform
*
* This method is useful for introducing very short delays.
*
* This method busy-waits in a tight loop for the give number of system clock cycles. The total wait time is only accurate to within 2 cycles,
* and this method uses a loop counter rather than a hardware timer, so the method will always take longer than expected if an
* interrupt is handled on the calling core when during the busy-wait; you can of course disable interrupts to prevent this.
*
* You can use \ref clock_get_hz(clk_sys) to determine the number of clock cycles per second if you want to convert to cycles
* from an actual time duration.
*
* \param minimum_cycles the minimum number of system clock cycles to delay for
*/
static inline void busy_wait_at_least_cycles(uint32_t minimum_cycles) {
__asm volatile (
".syntax unified\n"
"1: subs %0, #3\n"
"bcs 1b\n"
: "+r" (minimum_cycles) : : "memory"
);
}

#else // __ASSEMBLER__

#define WRAPPER_FUNC_NAME(x) __wrap_##x
Expand Down