The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_TY51822R3/TARGET_NORDIC/TARGET_NRF5x/TARGET_SDK_11/drivers_nrf/delay/nrf_delay.h@169:a7c7b631e539
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 156:ff21514d8981 1 #ifndef _NRF_DELAY_H
AnnaBridge 156:ff21514d8981 2 #define _NRF_DELAY_H
AnnaBridge 156:ff21514d8981 3
AnnaBridge 156:ff21514d8981 4 #include "nrf.h"
AnnaBridge 156:ff21514d8981 5
AnnaBridge 156:ff21514d8981 6 /**
AnnaBridge 156:ff21514d8981 7 * @brief Function for delaying execution for number of microseconds.
AnnaBridge 156:ff21514d8981 8 *
AnnaBridge 156:ff21514d8981 9 * @note NRF52 has instruction cache and because of that delay is not precise.
AnnaBridge 156:ff21514d8981 10 *
AnnaBridge 156:ff21514d8981 11 * @param number_of_ms
AnnaBridge 156:ff21514d8981 12 */
AnnaBridge 156:ff21514d8981 13 /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */
AnnaBridge 156:ff21514d8981 14 #if defined ( __CC_ARM )
AnnaBridge 156:ff21514d8981 15
AnnaBridge 156:ff21514d8981 16 static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
AnnaBridge 156:ff21514d8981 17 {
AnnaBridge 156:ff21514d8981 18 loop
AnnaBridge 156:ff21514d8981 19 SUBS R0, R0, #1
AnnaBridge 156:ff21514d8981 20 NOP
AnnaBridge 156:ff21514d8981 21 NOP
AnnaBridge 156:ff21514d8981 22 NOP
AnnaBridge 156:ff21514d8981 23 NOP
AnnaBridge 156:ff21514d8981 24 NOP
AnnaBridge 156:ff21514d8981 25 NOP
AnnaBridge 156:ff21514d8981 26 NOP
AnnaBridge 156:ff21514d8981 27 NOP
AnnaBridge 156:ff21514d8981 28 NOP
AnnaBridge 156:ff21514d8981 29 NOP
AnnaBridge 156:ff21514d8981 30 NOP
AnnaBridge 156:ff21514d8981 31 NOP
AnnaBridge 156:ff21514d8981 32 #ifdef NRF52
AnnaBridge 156:ff21514d8981 33 NOP
AnnaBridge 156:ff21514d8981 34 NOP
AnnaBridge 156:ff21514d8981 35 NOP
AnnaBridge 156:ff21514d8981 36 NOP
AnnaBridge 156:ff21514d8981 37 NOP
AnnaBridge 156:ff21514d8981 38 NOP
AnnaBridge 156:ff21514d8981 39 NOP
AnnaBridge 156:ff21514d8981 40 NOP
AnnaBridge 156:ff21514d8981 41 NOP
AnnaBridge 156:ff21514d8981 42 NOP
AnnaBridge 156:ff21514d8981 43 NOP
AnnaBridge 156:ff21514d8981 44 NOP
AnnaBridge 156:ff21514d8981 45 NOP
AnnaBridge 156:ff21514d8981 46 NOP
AnnaBridge 156:ff21514d8981 47 NOP
AnnaBridge 156:ff21514d8981 48 NOP
AnnaBridge 156:ff21514d8981 49 NOP
AnnaBridge 156:ff21514d8981 50 NOP
AnnaBridge 156:ff21514d8981 51 NOP
AnnaBridge 156:ff21514d8981 52 NOP
AnnaBridge 156:ff21514d8981 53 NOP
AnnaBridge 156:ff21514d8981 54 NOP
AnnaBridge 156:ff21514d8981 55 NOP
AnnaBridge 156:ff21514d8981 56 NOP
AnnaBridge 156:ff21514d8981 57 NOP
AnnaBridge 156:ff21514d8981 58 NOP
AnnaBridge 156:ff21514d8981 59 NOP
AnnaBridge 156:ff21514d8981 60 NOP
AnnaBridge 156:ff21514d8981 61 NOP
AnnaBridge 156:ff21514d8981 62 NOP
AnnaBridge 156:ff21514d8981 63 NOP
AnnaBridge 156:ff21514d8981 64 NOP
AnnaBridge 156:ff21514d8981 65 NOP
AnnaBridge 156:ff21514d8981 66 NOP
AnnaBridge 156:ff21514d8981 67 NOP
AnnaBridge 156:ff21514d8981 68 NOP
AnnaBridge 156:ff21514d8981 69 NOP
AnnaBridge 156:ff21514d8981 70 NOP
AnnaBridge 156:ff21514d8981 71 NOP
AnnaBridge 156:ff21514d8981 72 NOP
AnnaBridge 156:ff21514d8981 73 NOP
AnnaBridge 156:ff21514d8981 74 NOP
AnnaBridge 156:ff21514d8981 75 NOP
AnnaBridge 156:ff21514d8981 76 NOP
AnnaBridge 156:ff21514d8981 77 #endif
AnnaBridge 156:ff21514d8981 78 BNE loop
AnnaBridge 156:ff21514d8981 79 BX LR
AnnaBridge 156:ff21514d8981 80 }
AnnaBridge 156:ff21514d8981 81
AnnaBridge 156:ff21514d8981 82 #elif defined ( __ICCARM__ )
AnnaBridge 156:ff21514d8981 83
AnnaBridge 156:ff21514d8981 84 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
AnnaBridge 156:ff21514d8981 85 {
AnnaBridge 156:ff21514d8981 86 __ASM (
AnnaBridge 156:ff21514d8981 87 "loop:\n\t"
AnnaBridge 156:ff21514d8981 88 " SUBS R0, R0, #1\n\t"
AnnaBridge 156:ff21514d8981 89 " NOP\n\t"
AnnaBridge 156:ff21514d8981 90 " NOP\n\t"
AnnaBridge 156:ff21514d8981 91 " NOP\n\t"
AnnaBridge 156:ff21514d8981 92 " NOP\n\t"
AnnaBridge 156:ff21514d8981 93 " NOP\n\t"
AnnaBridge 156:ff21514d8981 94 " NOP\n\t"
AnnaBridge 156:ff21514d8981 95 " NOP\n\t"
AnnaBridge 156:ff21514d8981 96 " NOP\n\t"
AnnaBridge 156:ff21514d8981 97 " NOP\n\t"
AnnaBridge 156:ff21514d8981 98 " NOP\n\t"
AnnaBridge 156:ff21514d8981 99 " NOP\n\t"
AnnaBridge 156:ff21514d8981 100 " NOP\n\t"
AnnaBridge 156:ff21514d8981 101 #ifdef NRF52
AnnaBridge 156:ff21514d8981 102 " NOP\n\t"
AnnaBridge 156:ff21514d8981 103 " NOP\n\t"
AnnaBridge 156:ff21514d8981 104 " NOP\n\t"
AnnaBridge 156:ff21514d8981 105 " NOP\n\t"
AnnaBridge 156:ff21514d8981 106 " NOP\n\t"
AnnaBridge 156:ff21514d8981 107 " NOP\n\t"
AnnaBridge 156:ff21514d8981 108 " NOP\n\t"
AnnaBridge 156:ff21514d8981 109 " NOP\n\t"
AnnaBridge 156:ff21514d8981 110 " NOP\n\t"
AnnaBridge 156:ff21514d8981 111 " NOP\n\t"
AnnaBridge 156:ff21514d8981 112 " NOP\n\t"
AnnaBridge 156:ff21514d8981 113 " NOP\n\t"
AnnaBridge 156:ff21514d8981 114 " NOP\n\t"
AnnaBridge 156:ff21514d8981 115 " NOP\n\t"
AnnaBridge 156:ff21514d8981 116 " NOP\n\t"
AnnaBridge 156:ff21514d8981 117 " NOP\n\t"
AnnaBridge 156:ff21514d8981 118 " NOP\n\t"
AnnaBridge 156:ff21514d8981 119 " NOP\n\t"
AnnaBridge 156:ff21514d8981 120 " NOP\n\t"
AnnaBridge 156:ff21514d8981 121 " NOP\n\t"
AnnaBridge 156:ff21514d8981 122 " NOP\n\t"
AnnaBridge 156:ff21514d8981 123 " NOP\n\t"
AnnaBridge 156:ff21514d8981 124 " NOP\n\t"
AnnaBridge 156:ff21514d8981 125 " NOP\n\t"
AnnaBridge 156:ff21514d8981 126 " NOP\n\t"
AnnaBridge 156:ff21514d8981 127 " NOP\n\t"
AnnaBridge 156:ff21514d8981 128 " NOP\n\t"
AnnaBridge 156:ff21514d8981 129 " NOP\n\t"
AnnaBridge 156:ff21514d8981 130 " NOP\n\t"
AnnaBridge 156:ff21514d8981 131 " NOP\n\t"
AnnaBridge 156:ff21514d8981 132 " NOP\n\t"
AnnaBridge 156:ff21514d8981 133 " NOP\n\t"
AnnaBridge 156:ff21514d8981 134 " NOP\n\t"
AnnaBridge 156:ff21514d8981 135 " NOP\n\t"
AnnaBridge 156:ff21514d8981 136 " NOP\n\t"
AnnaBridge 156:ff21514d8981 137 " NOP\n\t"
AnnaBridge 156:ff21514d8981 138 " NOP\n\t"
AnnaBridge 156:ff21514d8981 139 " NOP\n\t"
AnnaBridge 156:ff21514d8981 140 " NOP\n\t"
AnnaBridge 156:ff21514d8981 141 " NOP\n\t"
AnnaBridge 156:ff21514d8981 142 " NOP\n\t"
AnnaBridge 156:ff21514d8981 143 " NOP\n\t"
AnnaBridge 156:ff21514d8981 144 " NOP\n\t"
AnnaBridge 156:ff21514d8981 145 " NOP\n\t"
AnnaBridge 156:ff21514d8981 146 " NOP\n\t"
AnnaBridge 156:ff21514d8981 147 #endif
AnnaBridge 156:ff21514d8981 148 " BNE.n loop\n\t");
AnnaBridge 156:ff21514d8981 149 }
AnnaBridge 156:ff21514d8981 150
AnnaBridge 156:ff21514d8981 151 #elif defined ( _WIN32 ) || defined ( __unix ) || defined( __APPLE__ )
AnnaBridge 156:ff21514d8981 152
AnnaBridge 156:ff21514d8981 153 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us);
AnnaBridge 156:ff21514d8981 154
AnnaBridge 156:ff21514d8981 155 #ifndef CUSTOM_NRF_DELAY_US
AnnaBridge 156:ff21514d8981 156 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us)
AnnaBridge 156:ff21514d8981 157 {}
AnnaBridge 156:ff21514d8981 158 #endif
AnnaBridge 156:ff21514d8981 159
AnnaBridge 156:ff21514d8981 160 #elif defined ( __GNUC__ )
AnnaBridge 156:ff21514d8981 161
AnnaBridge 156:ff21514d8981 162 static __INLINE void nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline));
AnnaBridge 156:ff21514d8981 163 static __INLINE void nrf_delay_us(uint32_t volatile number_of_us)
AnnaBridge 156:ff21514d8981 164 {
AnnaBridge 156:ff21514d8981 165 register uint32_t delay __ASM ("r0") = number_of_us;
AnnaBridge 156:ff21514d8981 166 __ASM volatile (
AnnaBridge 156:ff21514d8981 167 #if defined(NRF51) && !defined(__ARMCC_VERSION)
AnnaBridge 156:ff21514d8981 168 ".syntax unified\n"
AnnaBridge 156:ff21514d8981 169 #endif
AnnaBridge 156:ff21514d8981 170 "1:\n"
AnnaBridge 156:ff21514d8981 171 " SUBS %0, %0, #1\n"
AnnaBridge 156:ff21514d8981 172 " NOP\n"
AnnaBridge 156:ff21514d8981 173 " NOP\n"
AnnaBridge 156:ff21514d8981 174 " NOP\n"
AnnaBridge 156:ff21514d8981 175 " NOP\n"
AnnaBridge 156:ff21514d8981 176 " NOP\n"
AnnaBridge 156:ff21514d8981 177 " NOP\n"
AnnaBridge 156:ff21514d8981 178 " NOP\n"
AnnaBridge 156:ff21514d8981 179 " NOP\n"
AnnaBridge 156:ff21514d8981 180 " NOP\n"
AnnaBridge 156:ff21514d8981 181 " NOP\n"
AnnaBridge 156:ff21514d8981 182 " NOP\n"
AnnaBridge 156:ff21514d8981 183 " NOP\n"
AnnaBridge 156:ff21514d8981 184 #ifdef NRF52
AnnaBridge 156:ff21514d8981 185 " NOP\n"
AnnaBridge 156:ff21514d8981 186 " NOP\n"
AnnaBridge 156:ff21514d8981 187 " NOP\n"
AnnaBridge 156:ff21514d8981 188 " NOP\n"
AnnaBridge 156:ff21514d8981 189 " NOP\n"
AnnaBridge 156:ff21514d8981 190 " NOP\n"
AnnaBridge 156:ff21514d8981 191 " NOP\n"
AnnaBridge 156:ff21514d8981 192 " NOP\n"
AnnaBridge 156:ff21514d8981 193 " NOP\n"
AnnaBridge 156:ff21514d8981 194 " NOP\n"
AnnaBridge 156:ff21514d8981 195 " NOP\n"
AnnaBridge 156:ff21514d8981 196 " NOP\n"
AnnaBridge 156:ff21514d8981 197 " NOP\n"
AnnaBridge 156:ff21514d8981 198 " NOP\n"
AnnaBridge 156:ff21514d8981 199 " NOP\n"
AnnaBridge 156:ff21514d8981 200 " NOP\n"
AnnaBridge 156:ff21514d8981 201 " NOP\n"
AnnaBridge 156:ff21514d8981 202 " NOP\n"
AnnaBridge 156:ff21514d8981 203 " NOP\n"
AnnaBridge 156:ff21514d8981 204 " NOP\n"
AnnaBridge 156:ff21514d8981 205 " NOP\n"
AnnaBridge 156:ff21514d8981 206 " NOP\n"
AnnaBridge 156:ff21514d8981 207 " NOP\n"
AnnaBridge 156:ff21514d8981 208 " NOP\n"
AnnaBridge 156:ff21514d8981 209 " NOP\n"
AnnaBridge 156:ff21514d8981 210 " NOP\n"
AnnaBridge 156:ff21514d8981 211 " NOP\n"
AnnaBridge 156:ff21514d8981 212 " NOP\n"
AnnaBridge 156:ff21514d8981 213 " NOP\n"
AnnaBridge 156:ff21514d8981 214 " NOP\n"
AnnaBridge 156:ff21514d8981 215 " NOP\n"
AnnaBridge 156:ff21514d8981 216 " NOP\n"
AnnaBridge 156:ff21514d8981 217 " NOP\n"
AnnaBridge 156:ff21514d8981 218 " NOP\n"
AnnaBridge 156:ff21514d8981 219 " NOP\n"
AnnaBridge 156:ff21514d8981 220 " NOP\n"
AnnaBridge 156:ff21514d8981 221 " NOP\n"
AnnaBridge 156:ff21514d8981 222 " NOP\n"
AnnaBridge 156:ff21514d8981 223 " NOP\n"
AnnaBridge 156:ff21514d8981 224 " NOP\n"
AnnaBridge 156:ff21514d8981 225 " NOP\n"
AnnaBridge 156:ff21514d8981 226 " NOP\n"
AnnaBridge 156:ff21514d8981 227 " NOP\n"
AnnaBridge 156:ff21514d8981 228 " NOP\n"
AnnaBridge 156:ff21514d8981 229 " NOP\n"
AnnaBridge 156:ff21514d8981 230 " NOP\n"
AnnaBridge 156:ff21514d8981 231 #endif
AnnaBridge 156:ff21514d8981 232 " BNE 1b\n"
AnnaBridge 156:ff21514d8981 233 #if defined(NRF51) && !defined(__ARMCC_VERSION)
AnnaBridge 156:ff21514d8981 234 ".syntax divided\n"
AnnaBridge 156:ff21514d8981 235 #endif
AnnaBridge 156:ff21514d8981 236 : "+r" (delay));
AnnaBridge 156:ff21514d8981 237 }
AnnaBridge 156:ff21514d8981 238 #endif
AnnaBridge 156:ff21514d8981 239
AnnaBridge 156:ff21514d8981 240 void nrf_delay_ms(uint32_t volatile number_of_ms);
AnnaBridge 156:ff21514d8981 241
AnnaBridge 156:ff21514d8981 242 #endif