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