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);
108 void delay_us(uint32_t number_of_us);
142 #define HAL_TIMEOUT_INIT() \
143 uint32_t _demcr_initial = CoreDebug->DEMCR; \
144 uint32_t _dwt_ctrl_initial = DWT->CTRL; \
146 hal_dwt_enable(_demcr_initial, _dwt_ctrl_initial); \
153 #define HAL_TIMEOUT_DEINIT() \
155 hal_dwt_disable(_demcr_initial, _dwt_ctrl_initial); \
172 const uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
173 uint32_t cycles = number_of_us * (clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL]);
175 if (number_of_us == 0)
183 uint32_t cyccnt_initial = DWT->CYCCNT;
186 while ((DWT->CYCCNT - cyccnt_initial) < cycles)
196 #if defined ( __CC_ARM )
213 uint32_t pc = (
unsigned int)__current_pc();
214 uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
216 if (number_of_us == 0)
221 static const uint16_t delay_ramcode[] = {
227 const delay_func_t delay_ram_cycles = (delay_func_t)((((uint32_t)delay_ramcode) | 1));
229 static const uint16_t delay_flashcode[] = {
235 const delay_func_t delay_flash_cycles = (delay_func_t)((((uint32_t)delay_flashcode) | 1));
237 static const uint16_t delay_aliascode[] = {
243 const delay_func_t delay_alias_cycles = (delay_func_t)((((uint32_t)delay_aliascode) | 1));
245 uint32_t cycles = number_of_us * (clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL]);
247 if(pc & GR55XX_RAM_ADDRESS)
248 delay_ram_cycles(cycles);
249 else if(pc & GR55XX_FLASH_ADDRESS)
250 delay_flash_cycles(cycles);
251 else if(pc & GR55XX_ALIAS_ADDRESS)
252 delay_alias_cycles(cycles);
267 #elif defined ( _WIN32 ) || defined ( __unix ) || defined ( __APPLE__ )
269 #ifndef CUSTOM_DELAY_US
282 #elif defined ( __GNUC__ ) || ( __ICCARM__ )
292 uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
297 cycles = number_of_us*(clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL])/6;
298 __asm__
volatile (
"1:\n"
302 "SUBS %[cycles], %[cycles], #1\n"
304 : [cycles]
"=r" (cycles)
305 :
"[cycles]" "r" (cycles)
331 #if defined(GR5515_E)
332 void delay_ms(uint32_t number_of_ms);