hpm_mono_drv.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MONO_DRV_H
  8. #define HPM_MONO_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_mono_regs.h"
  11. /**
  12. *
  13. * @brief MONO driver APIs
  14. * @defgroup mono_interface MONO driver APIs
  15. * @ingroup io_interfaces
  16. * @{
  17. */
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief Get counter high
  23. *
  24. * @param[in] ptr MONO base address
  25. *
  26. * @return counter value high 16 bits
  27. */
  28. static inline uint16_t mono_get_counter_high(MONO_Type *ptr)
  29. {
  30. return MONO_MONOH_COUNTER_GET(ptr->MONOH);
  31. }
  32. /**
  33. * @brief Get counter low
  34. *
  35. * @param[in] ptr MONO base address
  36. *
  37. * @return counter value low 32 bits
  38. */
  39. static inline uint32_t mono_get_counter_low(MONO_Type *ptr)
  40. {
  41. return MONO_MONOL_COUNTER_GET(ptr->MONOL);
  42. }
  43. /**
  44. * @brief Get counter
  45. *
  46. * @param[in] ptr MONO base address
  47. *
  48. * @return 48 bits counter value
  49. */
  50. static inline uint64_t mono_get_counter(MONO_Type *ptr)
  51. {
  52. return (uint64_t)((uint64_t)mono_get_counter_high(ptr) << 32)
  53. | (uint64_t)mono_get_counter_low(ptr);
  54. }
  55. /**
  56. * @brief Get epoch
  57. *
  58. * @param[in] ptr MONO Base address
  59. *
  60. * @return epoch value 16 bits
  61. */
  62. static inline uint32_t mono_get_epoch(MONO_Type *ptr)
  63. {
  64. return MONO_MONOH_EPOCH_GET(ptr->MONOH);
  65. }
  66. /**
  67. * @brief Update MONO counter by 1
  68. *
  69. * @param[in] ptr MONO base
  70. */
  71. static inline void mono_update(MONO_Type *ptr)
  72. {
  73. ptr->MONOL = 1;
  74. }
  75. #ifdef __cplusplus
  76. }
  77. #endif
  78. /**
  79. * @}
  80. */
  81. #endif /* HPM_MONO_DRV_H */