-
Notifications
You must be signed in to change notification settings - Fork 350
Expand file tree
/
Copy pathwait.c
More file actions
75 lines (62 loc) · 1.6 KB
/
wait.c
File metadata and controls
75 lines (62 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2016 Intel Corporation. All rights reserved.
//
// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
/*
* Simple wait for event completion and signaling with timeouts.
*/
#include <rtos/clk.h>
#include <sof/lib/io.h>
#include <sof/lib/uuid.h>
#include <rtos/wait.h>
#include <sof/platform.h>
#include <sof/schedule/schedule.h>
#include <sof/trace/trace.h>
#include <user/trace.h>
#include <errno.h>
#include <stdint.h>
#include <inttypes.h>
LOG_MODULE_REGISTER(wait, CONFIG_SOF_LOG_LEVEL);
SOF_DEFINE_REG_UUID(wait);
DECLARE_TR_CTX(wait_tr, SOF_UUID(wait_uuid), LOG_LEVEL_INFO);
#define DEFAULT_TRY_TIMES 8
int poll_for_register_delay(uint32_t reg, uint32_t mask,
uint32_t val, uint64_t us)
{
uint64_t tick = k_us_to_cyc_ceil64(us);
uint32_t tries = DEFAULT_TRY_TIMES;
uint64_t delta = tick / tries;
if (!delta) {
/*
* If we want to wait for less than DEFAULT_TRY_TIMES ticks then
* delta has to be set to 1 and number of tries to that of number
* of ticks.
*/
delta = 1;
tries = tick;
}
while ((io_reg_read(reg) & mask) != val) {
if (!tries--) {
tr_err(&wait_tr, "poll timeout reg %u mask %u val %u us %u",
reg, mask, val, (uint32_t)us);
return -EIO;
}
wait_delay(delta);
}
return 0;
}
void wait_delay(uint64_t number_of_clks)
{
uint64_t timeout = sof_cycle_get_64() + number_of_clks;
while (sof_cycle_get_64() < timeout)
idelay(PLATFORM_DEFAULT_DELAY);
}
void wait_delay_ms(uint64_t ms)
{
wait_delay(k_ms_to_cyc_ceil64(ms));
}
void wait_delay_us(uint64_t us)
{
wait_delay(k_us_to_cyc_ceil64(us));
}