Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
Vincent Coubard
Date:
Wed Sep 14 14:39:43 2016 +0100
Revision:
640:c90ae1400bf2
Sync with bdab10dc0f90748b6989c8b577771bb403ca6bd8 from ARMmbed/mbed-os.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 640:c90ae1400bf2 1 /*
Vincent Coubard 640:c90ae1400bf2 2 * Copyright (c) Nordic Semiconductor ASA
Vincent Coubard 640:c90ae1400bf2 3 * All rights reserved.
Vincent Coubard 640:c90ae1400bf2 4 *
Vincent Coubard 640:c90ae1400bf2 5 * Redistribution and use in source and binary forms, with or without modification,
Vincent Coubard 640:c90ae1400bf2 6 * are permitted provided that the following conditions are met:
Vincent Coubard 640:c90ae1400bf2 7 *
Vincent Coubard 640:c90ae1400bf2 8 * 1. Redistributions of source code must retain the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 9 * list of conditions and the following disclaimer.
Vincent Coubard 640:c90ae1400bf2 10 *
Vincent Coubard 640:c90ae1400bf2 11 * 2. Redistributions in binary form must reproduce the above copyright notice, this
Vincent Coubard 640:c90ae1400bf2 12 * list of conditions and the following disclaimer in the documentation and/or
Vincent Coubard 640:c90ae1400bf2 13 * other materials provided with the distribution.
Vincent Coubard 640:c90ae1400bf2 14 *
Vincent Coubard 640:c90ae1400bf2 15 * 3. Neither the name of Nordic Semiconductor ASA nor the names of other
Vincent Coubard 640:c90ae1400bf2 16 * contributors to this software may be used to endorse or promote products
Vincent Coubard 640:c90ae1400bf2 17 * derived from this software without specific prior written permission.
Vincent Coubard 640:c90ae1400bf2 18 *
Vincent Coubard 640:c90ae1400bf2 19 *
Vincent Coubard 640:c90ae1400bf2 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Vincent Coubard 640:c90ae1400bf2 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Vincent Coubard 640:c90ae1400bf2 22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Vincent Coubard 640:c90ae1400bf2 23 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Vincent Coubard 640:c90ae1400bf2 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Vincent Coubard 640:c90ae1400bf2 25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Vincent Coubard 640:c90ae1400bf2 26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Vincent Coubard 640:c90ae1400bf2 27 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Vincent Coubard 640:c90ae1400bf2 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Vincent Coubard 640:c90ae1400bf2 29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Vincent Coubard 640:c90ae1400bf2 30 *
Vincent Coubard 640:c90ae1400bf2 31 */
Vincent Coubard 640:c90ae1400bf2 32
Vincent Coubard 640:c90ae1400bf2 33 #ifndef _NRF_DELAY_H
Vincent Coubard 640:c90ae1400bf2 34 #define _NRF_DELAY_H
Vincent Coubard 640:c90ae1400bf2 35
Vincent Coubard 640:c90ae1400bf2 36 #include "nrf.h"
Vincent Coubard 640:c90ae1400bf2 37
Vincent Coubard 640:c90ae1400bf2 38 /**
Vincent Coubard 640:c90ae1400bf2 39 * @brief Function for delaying execution for number of microseconds.
Vincent Coubard 640:c90ae1400bf2 40 *
Vincent Coubard 640:c90ae1400bf2 41 * @note NRF52 has instruction cache and because of that delay is not precise.
Vincent Coubard 640:c90ae1400bf2 42 *
Vincent Coubard 640:c90ae1400bf2 43 * @param number_of_ms
Vincent Coubard 640:c90ae1400bf2 44 */
Vincent Coubard 640:c90ae1400bf2 45 /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */
Vincent Coubard 640:c90ae1400bf2 46 #if defined ( __CC_ARM )
Vincent Coubard 640:c90ae1400bf2 47
Vincent Coubard 640:c90ae1400bf2 48 static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
Vincent Coubard 640:c90ae1400bf2 49 {
Vincent Coubard 640:c90ae1400bf2 50 loop
Vincent Coubard 640:c90ae1400bf2 51 SUBS R0, R0, #1
Vincent Coubard 640:c90ae1400bf2 52 NOP
Vincent Coubard 640:c90ae1400bf2 53 NOP
Vincent Coubard 640:c90ae1400bf2 54 NOP
Vincent Coubard 640:c90ae1400bf2 55 NOP
Vincent Coubard 640:c90ae1400bf2 56 NOP
Vincent Coubard 640:c90ae1400bf2 57 NOP
Vincent Coubard 640:c90ae1400bf2 58 NOP
Vincent Coubard 640:c90ae1400bf2 59 NOP
Vincent Coubard 640:c90ae1400bf2 60 NOP
Vincent Coubard 640:c90ae1400bf2 61 NOP
Vincent Coubard 640:c90ae1400bf2 62 NOP
Vincent Coubard 640:c90ae1400bf2 63 NOP
Vincent Coubard 640:c90ae1400bf2 64 #ifdef NRF52
Vincent Coubard 640:c90ae1400bf2 65 NOP
Vincent Coubard 640:c90ae1400bf2 66 NOP
Vincent Coubard 640:c90ae1400bf2 67 NOP
Vincent Coubard 640:c90ae1400bf2 68 NOP
Vincent Coubard 640:c90ae1400bf2 69 NOP
Vincent Coubard 640:c90ae1400bf2 70 NOP
Vincent Coubard 640:c90ae1400bf2 71 NOP
Vincent Coubard 640:c90ae1400bf2 72 NOP
Vincent Coubard 640:c90ae1400bf2 73 NOP
Vincent Coubard 640:c90ae1400bf2 74 NOP
Vincent Coubard 640:c90ae1400bf2 75 NOP
Vincent Coubard 640:c90ae1400bf2 76 NOP
Vincent Coubard 640:c90ae1400bf2 77 NOP
Vincent Coubard 640:c90ae1400bf2 78 NOP
Vincent Coubard 640:c90ae1400bf2 79 NOP
Vincent Coubard 640:c90ae1400bf2 80 NOP
Vincent Coubard 640:c90ae1400bf2 81 NOP
Vincent Coubard 640:c90ae1400bf2 82 NOP
Vincent Coubard 640:c90ae1400bf2 83 NOP
Vincent Coubard 640:c90ae1400bf2 84 NOP
Vincent Coubard 640:c90ae1400bf2 85 NOP
Vincent Coubard 640:c90ae1400bf2 86 NOP
Vincent Coubard 640:c90ae1400bf2 87 NOP
Vincent Coubard 640:c90ae1400bf2 88 NOP
Vincent Coubard 640:c90ae1400bf2 89 NOP
Vincent Coubard 640:c90ae1400bf2 90 NOP
Vincent Coubard 640:c90ae1400bf2 91 NOP
Vincent Coubard 640:c90ae1400bf2 92 NOP
Vincent Coubard 640:c90ae1400bf2 93 NOP
Vincent Coubard 640:c90ae1400bf2 94 NOP
Vincent Coubard 640:c90ae1400bf2 95 NOP
Vincent Coubard 640:c90ae1400bf2 96 NOP
Vincent Coubard 640:c90ae1400bf2 97 NOP
Vincent Coubard 640:c90ae1400bf2 98 NOP
Vincent Coubard 640:c90ae1400bf2 99 NOP
Vincent Coubard 640:c90ae1400bf2 100 NOP
Vincent Coubard 640:c90ae1400bf2 101 NOP
Vincent Coubard 640:c90ae1400bf2 102 NOP
Vincent Coubard 640:c90ae1400bf2 103 NOP
Vincent Coubard 640:c90ae1400bf2 104 NOP
Vincent Coubard 640:c90ae1400bf2 105 NOP
Vincent Coubard 640:c90ae1400bf2 106 NOP
Vincent Coubard 640:c90ae1400bf2 107 NOP
Vincent Coubard 640:c90ae1400bf2 108 NOP
Vincent Coubard 640:c90ae1400bf2 109 #endif
Vincent Coubard 640:c90ae1400bf2 110 BNE loop
Vincent Coubard 640:c90ae1400bf2 111 BX LR
Vincent Coubard 640:c90ae1400bf2 112 }
Vincent Coubard 640:c90ae1400bf2 113
Vincent Coubard 640:c90ae1400bf2 114 #elif defined ( __ICCARM__ )
Vincent Coubard 640:c90ae1400bf2 115
Vincent Coubard 640:c90ae1400bf2 116 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
Vincent Coubard 640:c90ae1400bf2 117 {
Vincent Coubard 640:c90ae1400bf2 118 __ASM (
Vincent Coubard 640:c90ae1400bf2 119 "loop:\n\t"
Vincent Coubard 640:c90ae1400bf2 120 " SUBS R0, R0, #1\n\t"
Vincent Coubard 640:c90ae1400bf2 121 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 122 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 123 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 124 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 125 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 126 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 127 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 128 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 129 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 130 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 131 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 132 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 133 #ifdef NRF52
Vincent Coubard 640:c90ae1400bf2 134 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 135 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 136 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 137 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 138 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 139 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 140 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 141 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 142 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 143 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 144 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 145 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 146 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 147 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 148 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 149 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 150 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 151 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 152 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 153 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 154 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 155 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 156 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 157 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 158 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 159 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 160 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 161 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 162 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 163 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 164 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 165 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 166 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 167 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 168 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 169 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 170 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 171 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 172 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 173 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 174 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 175 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 176 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 177 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 178 " NOP\n\t"
Vincent Coubard 640:c90ae1400bf2 179 #endif
Vincent Coubard 640:c90ae1400bf2 180 " BNE.n loop\n\t");
Vincent Coubard 640:c90ae1400bf2 181 }
Vincent Coubard 640:c90ae1400bf2 182
Vincent Coubard 640:c90ae1400bf2 183 #elif defined ( _WIN32 ) || defined ( __unix ) || defined( __APPLE__ )
Vincent Coubard 640:c90ae1400bf2 184
Vincent Coubard 640:c90ae1400bf2 185 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us);
Vincent Coubard 640:c90ae1400bf2 186
Vincent Coubard 640:c90ae1400bf2 187 #ifndef CUSTOM_NRF_DELAY_US
Vincent Coubard 640:c90ae1400bf2 188 __STATIC_INLINE void nrf_delay_us(uint32_t volatile number_of_us)
Vincent Coubard 640:c90ae1400bf2 189 {}
Vincent Coubard 640:c90ae1400bf2 190 #endif
Vincent Coubard 640:c90ae1400bf2 191
Vincent Coubard 640:c90ae1400bf2 192 #elif defined ( __GNUC__ )
Vincent Coubard 640:c90ae1400bf2 193
Vincent Coubard 640:c90ae1400bf2 194 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) __attribute__((always_inline));
Vincent Coubard 640:c90ae1400bf2 195 static void __INLINE nrf_delay_us(uint32_t volatile number_of_us)
Vincent Coubard 640:c90ae1400bf2 196 {
Vincent Coubard 640:c90ae1400bf2 197 register uint32_t delay __ASM ("r0") = number_of_us;
Vincent Coubard 640:c90ae1400bf2 198 __ASM volatile (
Vincent Coubard 640:c90ae1400bf2 199 #ifdef NRF51
Vincent Coubard 640:c90ae1400bf2 200 ".syntax unified\n"
Vincent Coubard 640:c90ae1400bf2 201 #endif
Vincent Coubard 640:c90ae1400bf2 202 "1:\n"
Vincent Coubard 640:c90ae1400bf2 203 " SUBS %0, %0, #1\n"
Vincent Coubard 640:c90ae1400bf2 204 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 205 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 206 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 207 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 208 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 209 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 210 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 211 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 212 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 213 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 214 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 215 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 216 #ifdef NRF52
Vincent Coubard 640:c90ae1400bf2 217 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 218 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 219 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 220 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 221 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 222 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 223 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 224 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 225 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 226 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 227 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 228 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 229 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 230 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 231 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 232 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 233 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 234 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 235 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 236 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 237 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 238 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 239 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 240 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 241 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 242 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 243 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 244 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 245 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 246 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 247 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 248 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 249 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 250 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 251 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 252 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 253 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 254 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 255 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 256 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 257 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 258 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 259 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 260 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 261 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 262 " NOP\n"
Vincent Coubard 640:c90ae1400bf2 263 #endif
Vincent Coubard 640:c90ae1400bf2 264 " BNE 1b\n"
Vincent Coubard 640:c90ae1400bf2 265 #ifdef NRF51
Vincent Coubard 640:c90ae1400bf2 266 ".syntax divided\n"
Vincent Coubard 640:c90ae1400bf2 267 #endif
Vincent Coubard 640:c90ae1400bf2 268 : "+r" (delay));
Vincent Coubard 640:c90ae1400bf2 269 }
Vincent Coubard 640:c90ae1400bf2 270 #endif
Vincent Coubard 640:c90ae1400bf2 271
Vincent Coubard 640:c90ae1400bf2 272 void nrf_delay_ms(uint32_t volatile number_of_ms);
Vincent Coubard 640:c90ae1400bf2 273
Vincent Coubard 640:c90ae1400bf2 274 #endif