Appiko
hal_nop_delay.h
1 
18 /*
19  * Licensed to the Apache Software Foundation (ASF) under one
20  * or more contributor license agreements. See the NOTICE file
21  * distributed with this work for additional information
22  * regarding copyright ownership. The ASF licenses this file
23  * to you under the Apache License, Version 2.0 (the
24  * "License"); you may not use this file except in compliance
25  * with the License. You may obtain a copy of the License at
26  *
27  * http://www.apache.org/licenses/LICENSE-2.0
28  *
29  * Unless required by applicable law or agreed to in writing,
30  * software distributed under the License is distributed on an
31  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
32  * KIND, either express or implied. See the License for the
33  * specific language governing permissions and limitations
34  * under the License.
35  */
36 
37 #ifndef CODEBASE_HAL_HAL_NOP_DELAY_H_
38 #define CODEBASE_HAL_HAL_NOP_DELAY_H_
39 
51 #include "stdint.h"
52 #include "nrf.h"
53 
58 static void hal_nop_delay_us(uint32_t number_of_us)
59 {
60 register uint32_t delay __ASM ("r0") = number_of_us;
61 __ASM volatile (
62 #ifdef NRF51
63  ".syntax unified\n"
64 #endif
65  "1:\n"
66  " SUBS %0, %0, #1\n"
67  " NOP\n"
68  " NOP\n"
69  " NOP\n"
70  " NOP\n"
71  " NOP\n"
72  " NOP\n"
73  " NOP\n"
74  " NOP\n"
75  " NOP\n"
76  " NOP\n"
77  " NOP\n"
78  " NOP\n"
79 #if defined NRF52 || defined NRF52832 || defined NRF52810
80  " NOP\n"
81  " NOP\n"
82  " NOP\n"
83  " NOP\n"
84  " NOP\n"
85  " NOP\n"
86  " NOP\n"
87  " NOP\n"
88  " NOP\n"
89  " NOP\n"
90  " NOP\n"
91  " NOP\n"
92  " NOP\n"
93  " NOP\n"
94  " NOP\n"
95  " NOP\n"
96  " NOP\n"
97  " NOP\n"
98  " NOP\n"
99  " NOP\n"
100  " NOP\n"
101  " NOP\n"
102  " NOP\n"
103  " NOP\n"
104  " NOP\n"
105  " NOP\n"
106  " NOP\n"
107  " NOP\n"
108  " NOP\n"
109  " NOP\n"
110  " NOP\n"
111  " NOP\n"
112  " NOP\n"
113  " NOP\n"
114  " NOP\n"
115  " NOP\n"
116  " NOP\n"
117  " NOP\n"
118  " NOP\n"
119  " NOP\n"
120  " NOP\n"
121  " NOP\n"
122  " NOP\n"
123  " NOP\n"
124  " NOP\n"
125  " NOP\n"
126 #endif
127  " BNE 1b\n"
128 #ifdef NRF51
129  ".syntax divided\n"
130 #endif
131  : "+r" (delay));
132 }
133 
138 static inline void hal_nop_delay_ms(uint32_t number_of_ms)
139 {
140  hal_nop_delay_us(1000*number_of_ms);
141 }
142 
143 #endif /* CODEBASE_HAL_HAL_NOP_DELAY_H_ */
144