• 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: CLOCK CALIBRATION DRIVER.
15  *
16  * Create: 2024-02-26
17  */
18 
19 #include "clock_calibration.h"
20 #include "app_init.h"
21 #include "nv.h"
22 #include "nv_upg.h"
23 #include "pmu.h"
24 
25 #define CLOCK_TASK_PRIO          24
26 #define CLOCK_TASK_STACK_SIZE    0x1000
27 #define CLOCK_CTRIM_INCREASE     1
28 #define CLOCK_CTRIM_DECREASE     0
29 
clocks_task(void)30 static void clocks_task(void)
31 {
32     uint8_t xo_ctrim_value = 0;
33 
34     // 从flash中加载校准值到ctrim 寄存器
35     calibration_xo_core_ctrim_flash_init();
36     calibration_get_xo_core_ctrim_reg(&xo_ctrim_value);
37     osal_printk("[clock]Current ctrim value = %x", xo_ctrim_value);
38 
39     // 调整频偏寄存器码字,范围Decimal[0, 255]
40     calibration_xo_core_ctrim_algorithm(CLOCK_CTRIM_INCREASE, 0x10);
41     calibration_xo_core_ctrim_algorithm(CLOCK_CTRIM_DECREASE, 0x5);
42     // 获取调整后的频偏寄存器值
43     calibration_get_xo_core_ctrim_reg(&xo_ctrim_value);
44     // 调整后,校准码字存回flash
45     calibration_xo_core_ctrim_save_flash(xo_ctrim_value);
46     osal_printk("[clock]After calibration, ctrim value = %x", xo_ctrim_value);
47 }
48 
49 
50 /* Run the clock_task. */
51 app_run(clocks_task);