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 * 15 * Description: Provides V150 HAL tcxo \n 16 * 17 * History: \n 18 * 2022-08-16, Create file. \n 19 */ 20 21 #include <stdint.h> 22 #include <stdbool.h> 23 #include "common_def.h" 24 #include "tcxo_porting.h" 25 #include "hal_tcxo.h" 26 #include "hal_tcxo_v150.h" 27 28 #define HAL_TCXO_COUNT_VALUE_B_VALID_TRUE 1 29 hal_tcxo_init(void)30errcode_t hal_tcxo_init(void) 31 { 32 if (hal_tcxo_v150_regs_init() != ERRCODE_SUCC) { 33 return ERRCODE_TCXO_REG_ADDR_INVALID; 34 } 35 36 /* set the tcxo cnt enable */ 37 hal_tcxo_status_set_enable(); 38 /* clear the tcxo cnt */ 39 hal_tcxo_status_set_clear(); 40 return ERRCODE_SUCC; 41 } 42 hal_tcxo_deinit(void)43errcode_t hal_tcxo_deinit(void) 44 { 45 hal_tcxo_v150_regs_deinit(); 46 return ERRCODE_SUCC; 47 } 48 hal_tcxo_get(void)49uint64_t hal_tcxo_get(void) 50 { 51 bool f_cnt_val = false; 52 /* refresh the data to tcxo cnt value */ 53 hal_tcxo_status_set_refresh(); 54 55 for (uint32_t i = 0; i < TCXO_LOCK_GET_ATTE; i++) { 56 if (hal_tcxo_status_get_valid() == HAL_TCXO_COUNT_VALUE_B_VALID_TRUE) { 57 f_cnt_val = true; 58 break; /* wait until the value in tcxo cnt value is available */ 59 } 60 } 61 62 if (f_cnt_val == true) { 63 return hal_tcxo_reg_count_get(); 64 } else { 65 return 0; 66 } 67 }