38 #ifndef __GR55xx_DELAY_H__
39 #define __GR55xx_DELAY_H__
64 #if defined ( __CC_ARM )
66 #ifndef __STATIC_FORCEINLINE
67 #define __STATIC_FORCEINLINE static __forceinline
70 #elif defined ( __GNUC__ )
72 #ifndef __STATIC_FORCEINLINE
73 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
78 #ifndef __STATIC_FORCEINLINE
79 #define __STATIC_FORCEINLINE __STATIC_INLINE
92 typedef void (* delay_func_t)(uint32_t);
124 #define HAL_TIMEOUT_INIT() hal_dwt_enable()
130 #define HAL_TIMEOUT_DEINIT() hal_dwt_disable()
146 const uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
147 uint32_t cycles = number_of_us * (clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL]);
149 if (number_of_us == 0)
157 uint32_t cyccnt_initial = DWT->CYCCNT;
160 while ((DWT->CYCCNT - cyccnt_initial) < cycles)
170 #if defined ( __CC_ARM )
187 uint32_t pc = (
unsigned int)__current_pc();
188 uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
190 if (number_of_us == 0)
195 static const uint16_t delay_ramcode[] = {
201 const delay_func_t delay_ram_cycles = (delay_func_t)((((uint32_t)delay_ramcode) | 1));
203 static const uint16_t delay_flashcode[] = {
209 const delay_func_t delay_flash_cycles = (delay_func_t)((((uint32_t)delay_flashcode) | 1));
211 static const uint16_t delay_aliascode[] = {
217 const delay_func_t delay_alias_cycles = (delay_func_t)((((uint32_t)delay_aliascode) | 1));
219 uint32_t cycles = number_of_us * (clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL]);
221 if(pc & GR55XX_RAM_ADDRESS)
222 delay_ram_cycles(cycles);
223 else if(pc & GR55XX_FLASH_ADDRESS)
224 delay_flash_cycles(cycles);
225 else if(pc & GR55XX_ALIAS_ADDRESS)
226 delay_alias_cycles(cycles);
241 #elif defined ( _WIN32 ) || defined ( __unix ) || defined ( __APPLE__ )
243 #ifndef CUSTOM_DELAY_US
256 #elif defined ( __GNUC__ ) || ( __ICCARM__ )
266 uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
271 cycles = number_of_us*(clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL])/6;
272 __asm__
volatile (
"1:\n"
276 "SUBS %[cycles], %[cycles], #1\n"
278 : [cycles]
"=r" (cycles)
279 :
"[cycles]" "r" (cycles)