• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #if defined(__cplusplus)
16 extern "C" {
17 #endif /* __cplusplus */
18 
19 /**
20  * @brief   read BGPR value
21  *
22  * @note the bgpr_index range is 0 ~ (GPR count of BGPR - 1)
23  *
24  * @param ptr BGPR base address
25  * @param bgpr_index BGPR GPR index
26  * @param bgpr_val  the BGPR GPR value pointer
27  *
28  * @return hpm_stat_t status_success if read bgpr without any error
29  */
bgpr_read32(BGPR_Type * ptr,uint8_t bgpr_index,uint32_t * bgpr_val)30 static inline hpm_stat_t bgpr_read32(BGPR_Type *ptr, uint8_t bgpr_index, uint32_t *bgpr_val)
31 {
32     hpm_stat_t stat = status_invalid_argument;
33     uint8_t gpr_count = sizeof(ptr->GPR) / sizeof(uint32_t);
34     if (bgpr_index < gpr_count) {
35         (*bgpr_val) = ptr->GPR[bgpr_index];
36         stat = status_success;
37     }
38     return stat;
39 }
40 
41 /**
42  * @brief   write BGPR value
43  *
44  * @note the bgpr_index range is 0 ~ (GPR count of BGPR - 1)
45  *
46  * @param ptr BGPR base address
47  * @param bgpr_index BGPR GPR index
48  * @param bgpr_val  the BGPR GPR value
49  *
50  * @return hpm_stat_t status_success if write bgpr without any error
51  */
bgpr_write32(BGPR_Type * ptr,uint8_t bgpr_index,uint32_t bgpr_val)52 static inline hpm_stat_t bgpr_write32(BGPR_Type *ptr, uint8_t bgpr_index, uint32_t bgpr_val)
53 {
54     hpm_stat_t stat = status_invalid_argument;
55     uint8_t gpr_count = sizeof(ptr->GPR) / sizeof(uint32_t);
56     if (bgpr_index < gpr_count) {
57         ptr->GPR[bgpr_index] = bgpr_val;
58         stat = status_success;
59     }
60     return stat;
61 }
62 
63 /**
64  * @}
65  */
66 
67 #if defined(__cplusplus)
68 }
69 #endif /* __cplusplus */
70 #endif
71