test
Fork of nrf51-sdk by
Embed:
(wiki syntax)
Show/hide line numbers
nrf_delay.h
00001 /* 00002 * Copyright (c) Nordic Semiconductor ASA 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without modification, 00006 * are permitted provided that the following conditions are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright notice, this 00009 * list of conditions and the following disclaimer. 00010 * 00011 * 2. Redistributions in binary form must reproduce the above copyright notice, this 00012 * list of conditions and the following disclaimer in the documentation and/or 00013 * other materials provided with the distribution. 00014 * 00015 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other 00016 * contributors to this software may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00021 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00022 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00023 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 00024 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00025 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00026 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00027 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00028 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 * 00031 */ 00032 00033 #ifndef _NRF_DELAY_H 00034 #define _NRF_DELAY_H 00035 00036 #include "nrf.h" 00037 00038 /** 00039 * @brief Function for delaying execution for number of microseconds. 00040 * 00041 * @note NRF52 has instruction cache and because of that delay is not precise. 00042 * 00043 * @param number_of_ms 00044 */ 00045 /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */ 00046 #if defined ( __CC_ARM ) 00047 00048 static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 00049 { 00050 loop 00051 SUBS R0, R0, #1 00052 NOP 00053 NOP 00054 NOP 00055 NOP 00056 NOP 00057 NOP 00058 NOP 00059 NOP 00060 NOP 00061 NOP 00062 NOP 00063 NOP 00064 #ifdef NRF52 00065 NOP 00066 NOP 00067 NOP 00068 NOP 00069 NOP 00070 NOP 00071 NOP 00072 NOP 00073 NOP 00074 NOP 00075 NOP 00076 NOP 00077 NOP 00078 NOP 00079 NOP 00080 NOP 00081 NOP 00082 NOP 00083 NOP 00084 NOP 00085 NOP 00086 NOP 00087 NOP 00088 NOP 00089 NOP 00090 NOP 00091 NOP 00092 NOP 00093 NOP 00094 NOP 00095 NOP 00096 NOP 00097 NOP 00098 NOP 00099 NOP 00100 NOP 00101 NOP 00102 NOP 00103 NOP 00104 NOP 00105 NOP 00106 NOP 00107 NOP 00108 NOP 00109 #endif 00110 BNE loop 00111 BX LR 00112 } 00113 00114 #elif defined ( __ICCARM__ ) 00115 00116 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 00117 { 00118 __ASM ( 00119 "loop:\n\t" 00120 " SUBS R0, R0, #1\n\t" 00121 " NOP\n\t" 00122 " NOP\n\t" 00123 " NOP\n\t" 00124 " NOP\n\t" 00125 " NOP\n\t" 00126 " NOP\n\t" 00127 " NOP\n\t" 00128 " NOP\n\t" 00129 " NOP\n\t" 00130 " NOP\n\t" 00131 " NOP\n\t" 00132 " NOP\n\t" 00133 #ifdef NRF52 00134 " NOP\n\t" 00135 " NOP\n\t" 00136 " NOP\n\t" 00137 " NOP\n\t" 00138 " NOP\n\t" 00139 " NOP\n\t" 00140 " NOP\n\t" 00141 " NOP\n\t" 00142 " NOP\n\t" 00143 " NOP\n\t" 00144 " NOP\n\t" 00145 " NOP\n\t" 00146 " NOP\n\t" 00147 " NOP\n\t" 00148 " NOP\n\t" 00149 " NOP\n\t" 00150 " NOP\n\t" 00151 " NOP\n\t" 00152 " NOP\n\t" 00153 " NOP\n\t" 00154 " NOP\n\t" 00155 " NOP\n\t" 00156 " NOP\n\t" 00157 " NOP\n\t" 00158 " NOP\n\t" 00159 " NOP\n\t" 00160 " NOP\n\t" 00161 " NOP\n\t" 00162 " NOP\n\t" 00163 " NOP\n\t" 00164 " NOP\n\t" 00165 " NOP\n\t" 00166 " NOP\n\t" 00167 " NOP\n\t" 00168 " NOP\n\t" 00169 " NOP\n\t" 00170 " NOP\n\t" 00171 " NOP\n\t" 00172 " NOP\n\t" 00173 " NOP\n\t" 00174 " NOP\n\t" 00175 " NOP\n\t" 00176 " NOP\n\t" 00177 " NOP\n\t" 00178 " NOP\n\t" 00179 #endif 00180 " BNE.n loop\n\t"); 00181 } 00182 00183 #elif defined ( _WIN32 ) || defined ( __unix ) || defined( __APPLE__ ) 00184 00185 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us); 00186 00187 #ifndef CUSTOM_NRF_DELAY_US 00188 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us) 00189 {} 00190 #endif 00191 00192 #elif defined ( __GNUC__ ) 00193 00194 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline)); 00195 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 00196 { 00197 register uint32_t delay __ASM ("r0") = number_of_us; 00198 __ASM volatile ( 00199 #ifdef NRF51 00200 ".syntax unified\n" 00201 #endif 00202 "1:\n" 00203 " SUBS %0, %0, #1\n" 00204 " NOP\n" 00205 " NOP\n" 00206 " NOP\n" 00207 " NOP\n" 00208 " NOP\n" 00209 " NOP\n" 00210 " NOP\n" 00211 " NOP\n" 00212 " NOP\n" 00213 " NOP\n" 00214 " NOP\n" 00215 " NOP\n" 00216 #ifdef NRF52 00217 " NOP\n" 00218 " NOP\n" 00219 " NOP\n" 00220 " NOP\n" 00221 " NOP\n" 00222 " NOP\n" 00223 " NOP\n" 00224 " NOP\n" 00225 " NOP\n" 00226 " NOP\n" 00227 " NOP\n" 00228 " NOP\n" 00229 " NOP\n" 00230 " NOP\n" 00231 " NOP\n" 00232 " NOP\n" 00233 " NOP\n" 00234 " NOP\n" 00235 " NOP\n" 00236 " NOP\n" 00237 " NOP\n" 00238 " NOP\n" 00239 " NOP\n" 00240 " NOP\n" 00241 " NOP\n" 00242 " NOP\n" 00243 " NOP\n" 00244 " NOP\n" 00245 " NOP\n" 00246 " NOP\n" 00247 " NOP\n" 00248 " NOP\n" 00249 " NOP\n" 00250 " NOP\n" 00251 " NOP\n" 00252 " NOP\n" 00253 " NOP\n" 00254 " NOP\n" 00255 " NOP\n" 00256 " NOP\n" 00257 " NOP\n" 00258 " NOP\n" 00259 " NOP\n" 00260 " NOP\n" 00261 " NOP\n" 00262 " NOP\n" 00263 #endif 00264 " BNE 1b\n" 00265 #ifdef NRF51 00266 ".syntax divided\n" 00267 #endif 00268 : "+r" (delay)); 00269 } 00270 #endif 00271 00272 void nrf_delay_ms(uint32_t volatile number_of_ms); 00273 00274 #endif
Generated on Tue Jul 12 2022 15:51:26 by 1.7.2