gr55xx_delay.h
Go to the documentation of this file.
1
38 #ifndef __GR55xx_DELAY_H__
39 #define __GR55xx_DELAY_H__
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 #include "gr55xx.h"
46
47
48 #if defined ( __CC_ARM )
49
50 #ifndef __STATIC_FORCEINLINE
51 #define __STATIC_FORCEINLINE static __forceinline
52 #endif
53
54 #elif defined ( __GNUC__ )
55
56 #ifndef __STATIC_FORCEINLINE
57 #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline
58 #endif
59
60 #else
61
62 #ifndef __STATIC_FORCEINLINE
63 #define __STATIC_FORCEINLINE __STATIC_INLINE
64 #endif
65
66 #endif
67
77 #if defined(GR5515_E)
78 void delay_us(uint32_t number_of_us);
79 #else
80 __STATIC_FORCEINLINE void delay_us(uint32_t number_of_us)
81 {
82 const uint8_t clocks[] = {64, 48, 16, 24, 16, 32};
83 uint32_t cycles = number_of_us * (clocks[AON->PWR_RET01 & AON_PWR_REG01_SYS_CLK_SEL]);
84
85 if (number_of_us == 0)
86 {
87 return;
88 }
89
90 // Save the DEMCR register value which is used to restore it
91 uint32_t core_debug_initial = CoreDebug->DEMCR;
92 // Enable DWT
93 CoreDebug->DEMCR = core_debug_initial | CoreDebug_DEMCR_TRCENA_Msk;
94
95 // Save the CTRL register value which is used to restore it
96 uint32_t dwt_ctrl_initial = DWT->CTRL;
97 // Enable cycle counter
98 DWT->CTRL = dwt_ctrl_initial | DWT_CTRL_CYCCNTENA_Msk;
99
100 // Get start value of the cycle counter.
101 uint32_t cyccnt_initial = DWT->CYCCNT;
102
103 // Wait time end
104 while ((DWT->CYCCNT - cyccnt_initial) < cycles)
105 {}
106
107 // Restore registers.
108 DWT->CTRL = dwt_ctrl_initial;
109 CoreDebug->DEMCR = core_debug_initial;
110 }
111 #endif
112
125 #if defined(GR5515_E)
126 void delay_ms(uint32_t number_of_ms);
127 #else
128 __STATIC_FORCEINLINE void delay_ms(uint32_t number_of_ms)
129 {
130 delay_us(1000 * number_of_ms);
131 return;
132 }
133 #endif
134
135 #ifdef __cplusplus
136 }
137 #endif
138
139 #endif /* __GR55xx_DELAY_H__ */
delay_us
__STATIC_FORCEINLINE void delay_us(uint32_t number_of_us)
Function for delaying execution for number of microseconds.
Definition: gr55xx_delay.h:80
__STATIC_FORCEINLINE
#define __STATIC_FORCEINLINE
Definition: gr55xx_delay.h:63
delay_ms
__STATIC_FORCEINLINE void delay_ms(uint32_t number_of_ms)
Function for delaying execution for number of milliseconds.
Definition: gr55xx_delay.h:128