diff --git a/ch32v003fun/ch32v003fun.h b/ch32v003fun/ch32v003fun.h index 959177af123b90e81c7e9f248a7fa9be3adce9ef..ea0aa40f6e624ac4502a91f730752c6f650a538c 100644 --- a/ch32v003fun/ch32v003fun.h +++ b/ch32v003fun/ch32v003fun.h @@ -5099,7 +5099,19 @@ extern "C" { #define Ticks_from_Us(n) (n * DELAY_US_TIME) #define Ticks_from_Ms(n) (n * DELAY_MS_TIME) +// Depending on a LOT of factors, it's about 6 cycles per n. +// **DO NOT send it zero or less.** +static inline void Delay_Tiny( int n ) { + asm volatile( "\ + mv a5, %[n]\n\ + 1: \ + c.addi a5, -1\n\ + c.bnez a5, 1b" : : [n]"r"(n) : "a5" ); +} +// Add a certain number of nops. Note: These are usually executed in pairs +// and take two cycles, so you typically would use 0, 2, 4, etc. +#define ADD_N_NOPS( n ) asm volatile( ".rept " #n "\nc.nop\n.endr" ); #if defined(__riscv) || defined(__riscv__) || defined( CH32V003FUN_BASE )