blob: 8a06f57bc7b14145a24d4b6047f5d788e1ead130 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Furquan Shaikh4208e0c2014-04-28 16:43:07 -07002
Furquan Shaikh4208e0c2014-04-28 16:43:07 -07003#include <timer.h>
4#include <delay.h>
5#include <thread.h>
6
Aaron Durbin64031672018-04-21 14:45:32 -06007__weak void init_timer(void) { /* do nothing */ }
Julius Werner44cf8702014-12-08 13:39:14 -08008
Lee Leahy75b85992017-03-08 16:34:12 -08009void udelay(unsigned int usec)
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070010{
Aaron Durbinb9894ef2014-09-23 16:33:21 -050011 struct stopwatch sw;
Aaron Durbin515bd132014-08-04 16:21:50 -050012
13 /*
Aaron Durbine5e36302014-09-25 10:05:15 -050014 * As the timer granularity is in microseconds pad the
Aaron Durbin515bd132014-08-04 16:21:50 -050015 * requested delay by one to get at least >= requested usec delay.
16 */
Aaron Durbinb9894ef2014-09-23 16:33:21 -050017 usec += 1;
18
19 if (!thread_yield_microseconds(usec))
20 return;
21
22 stopwatch_init_usecs_expire(&sw, usec);
Jonathan Neuschäferc9660752017-09-19 15:19:54 +020023 stopwatch_wait_until_expired(&sw);
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070024}