File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
src/rp2_common/pico_platform/include/pico Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -400,6 +400,29 @@ uint __get_current_exception(void);
400
400
}
401
401
#endif
402
402
403
+ /*! \brief Helper method to busy-wait for at least the given number of cycles
404
+ * \ingroup pico_platform
405
+ *
406
+ * This method is useful for introducing very short delays.
407
+ *
408
+ * 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,
409
+ * and this method uses a loop counter rather than a hardware timer, so the method will always take longer than expected if an
410
+ * interrupt is handled on the calling core when during the busy-wait; you can of course disable interrupts to prevent this.
411
+ *
412
+ * 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
413
+ * from an actual time duration.
414
+ *
415
+ * \param minimum_cycles the minimum number of system clock cycles to delay for
416
+ */
417
+ static inline void busy_wait_at_least_cycles (uint32_t minimum_cycles ) {
418
+ __asm volatile (
419
+ ".syntax unified\n"
420
+ "1: subs %0, #3\n"
421
+ "bcs 1b\n"
422
+ : "+r" (minimum_cycles ) : : "memory"
423
+ );
424
+ }
425
+
403
426
#else // __ASSEMBLER__
404
427
405
428
#define WRAPPER_FUNC_NAME (x ) __wrap_##x
You can’t perform that action at this time.
0 commit comments