• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description:  mips
15  */
16 
17 #include "mips.h"
18 #include "tcxo.h"
19 #include "hal_mips.h"
20 
21 static uint64_t g_platform_isr_count_start = 0;
22 static uint64_t g_platform_isr_count_end = 0;
23 static uint64_t g_platform_isr_run_time = 0;
24 static bool g_bt_thread_is_running = false;
25 static bool g_bt_isr_is_running = false;
26 
27 static uint64_t g_isr_time_statistics = 0;
28 static bool g_thread_running_status = false;
29 
global_thread_status_update(bool status)30 void global_thread_status_update(bool status)
31 {
32     g_thread_running_status = status;
33     g_isr_time_statistics = 0;
34 }
35 
global_thread_status_get(void)36 bool global_thread_status_get(void)
37 {
38     return g_thread_running_status;
39 }
40 
global_isr_time_statistics_update(uint64_t sys_time_start,uint64_t sys_time_end)41 void global_isr_time_statistics_update(uint64_t sys_time_start, uint64_t sys_time_end)
42 {
43     if (global_thread_status_get()) {
44         g_isr_time_statistics =  g_isr_time_statistics + (sys_time_end - sys_time_start);
45     }
46 }
47 
global_isr_time_statistics_get(void)48 uint64_t global_isr_time_statistics_get(void)
49 {
50     return g_isr_time_statistics;
51 }
52 
mips_compute_run_time_start(void)53 void mips_compute_run_time_start(void)
54 {
55     g_platform_isr_count_start = uapi_tcxo_get_us();
56 }
57 
mips_compute_run_time_stop(void)58 void mips_compute_run_time_stop(void)
59 {
60     g_platform_isr_count_end = uapi_tcxo_get_us();
61 
62     if (g_bt_thread_is_running || g_bt_isr_is_running) {
63         g_platform_isr_run_time += (uint32_t)(g_platform_isr_count_end - g_platform_isr_count_start);
64     }
65 }
66 
67 /* register mips callback function */
mips_init(void)68 void mips_init(void)
69 {
70     hal_register_mips_start_callback(mips_compute_run_time_start);
71     hal_register_mips_stop_callback(mips_compute_run_time_stop);
72 }
73 
74 /* get bt thread status when compute mips */
mips_get_bt_thread_status(void)75 bool mips_get_bt_thread_status(void)
76 {
77     return g_bt_thread_is_running;
78 }
79 
80 /* set bt thread status when compute mips */
mips_set_bt_thread_status(bool status)81 void mips_set_bt_thread_status(bool status)
82 {
83     g_bt_thread_is_running = status;
84 }
85 
86 /* get bt isr status when compute mips */
mips_get_bt_isr_status(void)87 bool mips_get_bt_isr_status(void)
88 {
89     return g_bt_isr_is_running;
90 }
91 
92 /* set bt isr status when compute mips */
mips_set_bt_isr_status(bool status)93 void mips_set_bt_isr_status(bool status)
94 {
95     g_bt_isr_is_running = status;
96 }
97 
98 /* get platfrom isr run time while bt thread and bt isr running */
mips_get_plt_isr_run_time(void)99 uint32_t mips_get_plt_isr_run_time(void)
100 {
101     return g_platform_isr_run_time;
102 }
103 
104 /* clear plt isr run time data */
mips_clear_plt_isr_run_time(void)105 void mips_clear_plt_isr_run_time(void)
106 {
107     g_platform_isr_run_time = 0;
108 }
109 
110