hpm_bacc_drv.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_BACC_DRV_H
  8. #define HPM_BACC_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_bacc_regs.h"
  11. /**
  12. *
  13. * @brief BACC driver APIs
  14. * @defgroup bacc_interface BACC driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. /* @brief Timing gap ratios */
  19. typedef enum {
  20. bacc_ratio_0 = 0,
  21. bacc_ratio_1_32768 = 1,
  22. bacc_ratio_1_16384 = 2,
  23. bacc_ratio_1_8192 = 3,
  24. bacc_ratio_1_4096 = 4,
  25. bacc_ratio_1_2048 = 5,
  26. bacc_ratio_1_1024 = 6,
  27. bacc_ratio_1_512 = 7,
  28. bacc_ratio_1_256 = 8,
  29. bacc_ratio_1_128 = 9,
  30. bacc_ratio_1_64 = 10,
  31. bacc_ratio_1_32 = 11,
  32. bacc_ratio_1_16 = 12,
  33. bacc_ratio_1_8 = 13,
  34. bacc_ratio_1_4 = 14,
  35. bacc_ratio_1_2 = 15,
  36. } bacc_ratio_t;
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*
  41. * brief set timing gap after rising edge
  42. *
  43. * @param[in] ptr BACC base address
  44. * @param[in] ratio Ratio of guard band after rising edge
  45. * @param[in] offset Guard band after rising edge (16 bits)
  46. */
  47. static inline void bacc_timing_gap_post(BACC_Type *ptr, bacc_ratio_t ratio, uint16_t offset)
  48. {
  49. ptr->PRE_TIME = BACC_PRE_TIME_POST_RATIO_SET(ratio)
  50. | BACC_PRE_TIME_POST_OFFSET_SET(offset);
  51. }
  52. /*
  53. * brief set timing gap before rising edge
  54. *
  55. * @param[in] ptr BACC base address
  56. * @param[in] ratio Ratio of guard band before rising edge
  57. * @param[in] offset Guard band before rising edge (16 bits)
  58. */
  59. static inline void bacc_timing_gap_pre(BACC_Type *ptr, bacc_ratio_t ratio, uint16_t offset)
  60. {
  61. ptr->PRE_TIME = BACC_PRE_TIME_PRE_RATIO_SET(ratio)
  62. | BACC_PRE_TIME_PRE_OFFSET_SET(offset);
  63. }
  64. /*
  65. * brief disable fast read
  66. *
  67. * @param[in] ptr BACC base address
  68. */
  69. static inline void bacc_disable_fast_read(BACC_Type *ptr)
  70. {
  71. ptr->CONFIG &= ~BACC_CONFIG_FAST_READ_MASK;
  72. }
  73. /*
  74. * brief enable fast read
  75. *
  76. * @param[in] ptr BACC base address
  77. */
  78. static inline void bacc_enable_fast_read(BACC_Type *ptr)
  79. {
  80. ptr->CONFIG |= BACC_CONFIG_FAST_READ_MASK;
  81. }
  82. /*
  83. * brief disable fast wirte
  84. *
  85. * @param[in] ptr BACC base address
  86. */
  87. static inline void bacc_disable_fast_write(BACC_Type *ptr)
  88. {
  89. ptr->CONFIG &= ~BACC_CONFIG_FAST_WRITE_MASK;
  90. }
  91. /*
  92. * brief enable fast wirte
  93. *
  94. * @param[in] ptr BACC base address
  95. */
  96. static inline void bacc_enable_fast_write(BACC_Type *ptr)
  97. {
  98. ptr->CONFIG |= BACC_CONFIG_FAST_WRITE_MASK;
  99. }
  100. /*
  101. * brief set timing of access
  102. *
  103. * @param[in] ptr BACC base address
  104. * @param[in] timing Time in APB clock cycles (16 bits)
  105. */
  106. static inline void bacc_set_timing(BACC_Type *ptr, uint16_t timing)
  107. {
  108. ptr->CONFIG = (ptr->CONFIG & ~(BACC_CONFIG_TIMING_MASK))
  109. | BACC_CONFIG_TIMING_SET(timing);
  110. }
  111. #ifdef __cplusplus
  112. }
  113. #endif
  114. /**
  115. * @}
  116. */
  117. #endif /* HPM_BACC_DRV_H */