+\r
+/*!\r
+ * @brief Delay function bases on while loop, every loop includes three instructions.\r
+ *\r
+ * @param count Counts of loop needed for dalay.\r
+ */\r
+#ifndef __XCC__\r
+#if defined(__CC_ARM) /* This macro is arm v5 specific */\r
+/* clang-format off */\r
+__ASM static void DelayLoop(uint32_t count)\r
+{\r
+loop\r
+ SUBS R0, R0, #1\r
+ CMP R0, #0\r
+ BNE loop\r
+ BX LR\r
+}\r
+/* clang-format on */\r
+#elif defined(__ARMCC_VERSION) || defined(__ICCARM__) || defined(__GNUC__)\r
+/* Cortex-M0 has a smaller instruction set, SUBS isn't supported in thumb-16 mode reported from __GNUC__ compiler,\r
+ * use SUB and CMP here for compatibility */\r
+static void DelayLoop(uint32_t count)\r
+{\r
+ __ASM volatile(" MOV R0, %0" : : "r"(count));\r
+ __ASM volatile(\r
+ "loop: \n"\r
+#if defined(__GNUC__) && !defined(__ARMCC_VERSION)\r
+ " SUB R0, R0, #1 \n"\r
+#else\r
+ " SUBS R0, R0, #1 \n"\r
+#endif\r
+ " CMP R0, #0 \n"\r
+\r
+ " BNE loop \n");\r
+}\r
+#endif /* defined(__CC_ARM) */\r
+\r
+/*!\r
+ * @brief Delay at least for some time.\r
+ * Please note that, this API uses while loop for delay, different run-time environments make the time not precise,\r
+ * if precise delay count was needed, please implement a new delay function with hardware timer.\r
+ *\r
+ * @param delay_us Delay time in unit of microsecond.\r
+ * @param coreClock_Hz Core clock frequency with Hz.\r
+ */\r
+void SDK_DelayAtLeastUs(uint32_t delay_us, uint32_t coreClock_Hz)\r
+{\r
+ assert(0U != delay_us);\r
+ uint64_t count = USEC_TO_COUNT(delay_us, coreClock_Hz);\r
+ assert(count <= UINT32_MAX);\r
+\r
+ /* Divide value may be different in various environment to ensure delay is precise.\r
+ * Every loop count includes three instructions, due to Cortex-M7 sometimes executes\r
+ * two instructions in one period, through test here set divide 2. Other M cores use\r
+ * divide 4. By the way, divide 2 or 4 could let odd count lost precision, but it does\r
+ * not matter because other instructions outside while loop is enough to fill the time.\r
+ */\r
+#if (__CORTEX_M == 7)\r
+ count = count / 2U;\r
+#else\r
+ count = count / 4U;\r
+#endif\r
+ DelayLoop((uint32_t)count);\r
+}\r
+#endif\r