* Wait for about n microseconds (at least!). */
| 194 | * Wait for about n microseconds (at least!). |
| 195 | */ |
| 196 | void |
| 197 | DELAY(int n) |
| 198 | { |
| 199 | uint32_t cur, last, delta, usecs; |
| 200 | |
| 201 | TSENTER(); |
| 202 | /* |
| 203 | * This works by polling the timer and counting the number of |
| 204 | * microseconds that go by. |
| 205 | */ |
| 206 | last = mips_rd_count(); |
| 207 | delta = usecs = 0; |
| 208 | |
| 209 | while (n > usecs) { |
| 210 | cur = mips_rd_count(); |
| 211 | |
| 212 | /* Check to see if the timer has wrapped around. */ |
| 213 | if (cur < last) |
| 214 | delta += cur + (0xffffffff - last) + 1; |
| 215 | else |
| 216 | delta += cur - last; |
| 217 | |
| 218 | last = cur; |
| 219 | |
| 220 | if (delta >= cycles_per_usec) { |
| 221 | usecs += delta / cycles_per_usec; |
| 222 | delta %= cycles_per_usec; |
| 223 | } |
| 224 | } |
| 225 | TSEXIT(); |
| 226 | } |
| 227 | |
| 228 | static int |
| 229 | clock_start(struct eventtimer *et, sbintime_t first, sbintime_t period) |
no outgoing calls
no test coverage detected