1 // Copyright (C) 2022 Beken Corporation 2 // 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 #pragma once 16 17 #include <soc/soc.h> 18 #include "hal_port.h" 19 #include "efuse_hw.h" 20 #include <driver/hal/hal_efuse_types.h> 21 #include "sys_ctrl.h" 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 #define EFUSE_LL_REG_BASE(_efuse_unit_id) (SOC_EFUSE_REG_BASE) 28 efuse_ll_reset_config_to_default(efuse_hw_t * hw)29static inline void efuse_ll_reset_config_to_default(efuse_hw_t *hw) 30 { 31 hw->ctrl.addr = 0; 32 hw->ctrl.wr_data = 0; 33 34 hw->optr.rd_data = 0; 35 hw->optr.rd_data_valid = 0; 36 } 37 efuse_ll_init(efuse_hw_t * hw)38static inline void efuse_ll_init(efuse_hw_t *hw) 39 { 40 efuse_ll_reset_config_to_default(hw); 41 } 42 efuse_ll_enable(efuse_hw_t * hw)43static inline void efuse_ll_enable(efuse_hw_t *hw) 44 { 45 hw->ctrl.en = 1; 46 } 47 efuse_ll_disable(efuse_hw_t * hw)48static inline void efuse_ll_disable(efuse_hw_t *hw) 49 { 50 hw->ctrl.en = 0; 51 } 52 efuse_ll_is_operate_finished(efuse_hw_t * hw)53static inline bool efuse_ll_is_operate_finished(efuse_hw_t *hw) 54 { 55 return !REG_GET_BIT(EFUSE_R_CTRL, BIT(0)); 56 } 57 efuse_ll_set_direction_write(efuse_hw_t * hw)58static inline void efuse_ll_set_direction_write(efuse_hw_t *hw) 59 { 60 hw->ctrl.dir = 0x1; 61 } 62 efuse_ll_set_direction_read(efuse_hw_t * hw)63static inline void efuse_ll_set_direction_read(efuse_hw_t *hw) 64 { 65 hw->ctrl.dir = 0x0; 66 } 67 efuse_ll_set_addr(efuse_hw_t * hw,uint8_t addr)68static inline void efuse_ll_set_addr(efuse_hw_t *hw, uint8_t addr) 69 { 70 hw->ctrl.addr = addr & EFUSE_F_ADDR_M; 71 } 72 efuse_ll_set_wr_data(efuse_hw_t * hw,uint8_t data)73static inline void efuse_ll_set_wr_data(efuse_hw_t *hw, uint8_t data) 74 { 75 hw->ctrl.v &= (~(EFUSE_F_WR_DATA_M << EFUSE_F_WR_DATA_S)); 76 hw->ctrl.v |= ((data & EFUSE_F_WR_DATA_M) << EFUSE_F_WR_DATA_S); 77 } 78 efuse_ll_is_rd_data_valid(efuse_hw_t * hw)79static inline bool efuse_ll_is_rd_data_valid(efuse_hw_t *hw) 80 { 81 return !!(hw->optr.rd_data_valid); 82 } 83 efuse_ll_get_rd_data(efuse_hw_t * hw)84static inline uint8_t efuse_ll_get_rd_data(efuse_hw_t *hw) 85 { 86 return hw->optr.rd_data & EFUSE_F_RD_DATA_M; 87 } 88 efuse_ll_enable_vdd25(efuse_hw_t * hw)89static inline void efuse_ll_enable_vdd25(efuse_hw_t *hw) 90 { 91 hw->ctrl.vdd25_en = 1; 92 } 93 efuse_ll_disable_vdd25(efuse_hw_t * hw)94static inline void efuse_ll_disable_vdd25(efuse_hw_t *hw) 95 { 96 hw->ctrl.vdd25_en = 0; 97 } 98 99 #ifdef __cplusplus 100 } 101 #endif 102 103 104