hpm_bgpr_drv.h 1.7 KB

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