• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 #include <sys_timer.h>
13 #include <tee_log.h>
14 #include <tee_time_adapt.h>
15 #include <time.h>
16 #include <tee_time_event.h>
17 
18 #define MAX_SECONDS  0xFFFFFFFF
19 
delay_us(uint32_t microseconds)20 void delay_us(uint32_t microseconds)
21 {
22     uint64_t counts = 0;
23     uint64_t time_stamp;
24     uint64_t start_time;
25     uint64_t cur_time;
26 
27     if (microseconds > US_PER_SECONDS) {
28         tloge("The value of microseconds is extend the range\n");
29         return;
30     }
31 
32     struct timer_ops_t *time_ops = NULL;
33     time_ops = get_time_ops();
34     if (time_ops == NULL)
35         return;
36 
37     time_stamp = time_ops->read_time_stamp();
38     while (counts < microseconds) {
39         start_time = (uint64_t)UPPER_32_BITS(time_stamp) * US_PER_SECONDS + LOWER_32_BITS(time_stamp) / NS_PER_USEC;
40         time_stamp = time_ops->read_time_stamp();
41         cur_time = (uint64_t)UPPER_32_BITS(time_stamp) * US_PER_SECONDS + LOWER_32_BITS(time_stamp) / NS_PER_USEC;
42         counts += cur_time - start_time;
43     }
44 }
45 
delay_ms(uint32_t msec)46 void delay_ms(uint32_t msec)
47 {
48     delay_us(msec * US_PER_MSEC);
49 }
50 
tee_msleep(uint32_t msec)51 uint32_t tee_msleep(uint32_t msec)
52 {
53     if (msec > MS_PER_SECONDS) {
54         tloge("The value of microseconds is extend the range\n");
55         return TMR_ERR;
56     }
57 
58     delay_ms(msec);
59     return TMR_OK;
60 }
61