MCPcopy Create free account
hub / github.com/F-Stack/f-stack / DELAY

Function DELAY

freebsd/mips/ingenic/jz4780_timer.c:271–332  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269 jz4780_timer_devclass, 0, 0, BUS_PASS_TIMER);
270
271void
272DELAY(int usec)
273{
274 uint32_t counter;
275 uint32_t delta, now, previous, remaining;
276
277 /* Timer has not yet been initialized */
278 if (jz4780_timer_sc == NULL) {
279 for (; usec > 0; usec--)
280 for (counter = 200; counter > 0; counter--) {
281 /* Prevent gcc from optimizing out the loop */
282 mips_rd_cause();
283 }
284 return;
285 }
286 TSENTER();
287
288 /*
289 * Some of the other timers in the source tree do this calculation as:
290 *
291 * usec * ((sc->tc.tc_frequency / 1000000) + 1)
292 *
293 * which gives a fairly pessimistic result when tc_frequency is an exact
294 * multiple of 1000000. Given the data type and typical values for
295 * tc_frequency adding 999999 shouldn't overflow.
296 */
297 remaining = usec * ((jz4780_timer_sc->tc.tc_frequency + 999999) /
298 1000000);
299
300 /*
301 * We add one since the first iteration may catch the counter just
302 * as it is changing.
303 */
304 remaining += 1;
305
306 previous = jz4780_get_timecount(&jz4780_timer_sc->tc);
307
308 for ( ; ; ) {
309 now = jz4780_get_timecount(&jz4780_timer_sc->tc);
310
311 /*
312 * If the timer has rolled over, then we have the case:
313 *
314 * if (previous > now) {
315 * delta = (0 - previous) + now
316 * }
317 *
318 * which is really no different then the normal case.
319 * Both cases are simply:
320 *
321 * delta = now - previous.
322 */
323 delta = now - previous;
324
325 if (delta >= remaining)
326 break;
327
328 previous = now;

Callers 10

jz4780_mmc_resetFunction · 0.70
jz4780_ehci_enableFunction · 0.70
jz4780_otg_enableFunction · 0.70
jzlcd_stopFunction · 0.70
codec_attachFunction · 0.70
jz4780_clk_gen_set_freqFunction · 0.70
jz4780_clk_pll_wait_lockFunction · 0.70
jzsmb_transfer_readFunction · 0.70
jzsmb_transfer_writeFunction · 0.70
jz4780_efuse_read_chunkFunction · 0.70

Calls 1

jz4780_get_timecountFunction · 0.85

Tested by

no test coverage detected