Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 3 | #include <timer.h> |
| 4 | #include <delay.h> |
| 5 | #include <thread.h> |
| 6 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 7 | __weak void init_timer(void) { /* do nothing */ } |
Julius Werner | 44cf870 | 2014-12-08 13:39:14 -0800 | [diff] [blame] | 8 | |
Lee Leahy | 75b8599 | 2017-03-08 16:34:12 -0800 | [diff] [blame] | 9 | void udelay(unsigned int usec) |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 10 | { |
Aaron Durbin | b9894ef | 2014-09-23 16:33:21 -0500 | [diff] [blame] | 11 | struct stopwatch sw; |
Aaron Durbin | 515bd13 | 2014-08-04 16:21:50 -0500 | [diff] [blame] | 12 | |
| 13 | /* |
Aaron Durbin | e5e3630 | 2014-09-25 10:05:15 -0500 | [diff] [blame] | 14 | * As the timer granularity is in microseconds pad the |
Aaron Durbin | 515bd13 | 2014-08-04 16:21:50 -0500 | [diff] [blame] | 15 | * requested delay by one to get at least >= requested usec delay. |
| 16 | */ |
Aaron Durbin | b9894ef | 2014-09-23 16:33:21 -0500 | [diff] [blame] | 17 | usec += 1; |
| 18 | |
| 19 | if (!thread_yield_microseconds(usec)) |
| 20 | return; |
| 21 | |
| 22 | stopwatch_init_usecs_expire(&sw, usec); |
Jonathan Neuschäfer | c966075 | 2017-09-19 15:19:54 +0200 | [diff] [blame] | 23 | stopwatch_wait_until_expired(&sw); |
Furquan Shaikh | 4208e0c | 2014-04-28 16:43:07 -0700 | [diff] [blame] | 24 | } |