1 /* 2 * Copyright (c) 2023 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef HPM_BGPR_DRV_H 9 #define HPM_BGPR_DRV_H 10 11 #include "hpm_common.h" 12 #include "hpm_soc_feature.h" 13 #include "hpm_bgpr_regs.h" 14 15 /** 16 * 17 * @brief BGPR driver APIs 18 * @defgroup bgpr_interfaces BGPR driver APIs 19 * @ingroup io_interfaces 20 * @{ 21 */ 22 23 #if defined(__cplusplus) 24 extern "C" { 25 #endif /* __cplusplus */ 26 27 /** 28 * @brief read BGPR value 29 * 30 * @note the bgpr_index range is 0 ~ (GPR count of BGPR - 1) 31 * 32 * @param ptr BGPR base address 33 * @param bgpr_index BGPR GPR index 34 * @param bgpr_val the BGPR GPR value pointer 35 * 36 * @return hpm_stat_t status_success if read bgpr without any error 37 */ bgpr_read32(BGPR_Type * ptr,uint8_t bgpr_index,uint32_t * bgpr_val)38static inline hpm_stat_t bgpr_read32(BGPR_Type *ptr, uint8_t bgpr_index, uint32_t *bgpr_val) 39 { 40 hpm_stat_t stat = status_invalid_argument; 41 uint8_t gpr_count = sizeof(ptr->GPR) / sizeof(uint32_t); 42 if (bgpr_index < gpr_count) { 43 (*bgpr_val) = ptr->GPR[bgpr_index]; 44 stat = status_success; 45 } 46 return stat; 47 } 48 49 /** 50 * @brief write BGPR value 51 * 52 * @note the bgpr_index range is 0 ~ (GPR count of BGPR - 1) 53 * 54 * @param ptr BGPR base address 55 * @param bgpr_index BGPR GPR index 56 * @param bgpr_val the BGPR GPR value 57 * 58 * @return hpm_stat_t status_success if write bgpr without any error 59 */ bgpr_write32(BGPR_Type * ptr,uint8_t bgpr_index,uint32_t bgpr_val)60static inline hpm_stat_t bgpr_write32(BGPR_Type *ptr, uint8_t bgpr_index, uint32_t bgpr_val) 61 { 62 hpm_stat_t stat = status_invalid_argument; 63 uint8_t gpr_count = sizeof(ptr->GPR) / sizeof(uint32_t); 64 if (bgpr_index < gpr_count) { 65 ptr->GPR[bgpr_index] = bgpr_val; 66 stat = status_success; 67 } 68 return stat; 69 } 70 71 /** 72 * @} 73 */ 74 75 #if defined(__cplusplus) 76 } 77 #endif /* __cplusplus */ 78 #endif 79