hpm_mchtmr_drv.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_MCHTMR_DRV_H
  8. #define HPM_MCHTMR_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_mchtmr_regs.h"
  11. /**
  12. * @brief MCHTMR driver APIs
  13. * @defgroup mchtmr_interface MCHTMR driver APIs
  14. * @ingroup io_interfaces
  15. * @{
  16. */
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief mchtmr get counter value
  22. *
  23. * @param [in] ptr MCHTMR base address
  24. */
  25. static inline uint64_t mchtmr_get_count(MCHTMR_Type *ptr)
  26. {
  27. return (ptr->MTIME & MCHTMR_MTIME_MTIME_MASK) >> MCHTMR_MTIME_MTIME_SHIFT;
  28. }
  29. /**
  30. * @brief mchtmr set comparator value
  31. *
  32. * @param [in] ptr MCHTMR base address
  33. * @param [in] target comparator target value
  34. */
  35. static inline void mchtmr_set_compare_value(MCHTMR_Type *ptr, uint64_t target)
  36. {
  37. ptr->MTIMECMP = MCHTMR_MTIMECMP_MTIMECMP_SET(target);
  38. }
  39. /**
  40. * @brief mchtmr set delay value
  41. *
  42. * @param [in] ptr MCHTMR base address
  43. * @param [in] delay delay cycles
  44. */
  45. static inline void mchtmr_delay(MCHTMR_Type *ptr, uint64_t delay)
  46. {
  47. mchtmr_set_compare_value(ptr, mchtmr_get_count(ptr) + delay);
  48. }
  49. /**
  50. * @brief initialize mchtmr counter
  51. *
  52. * @param [in] ptr MCHTMR base address
  53. * @param [in] v value to be set
  54. */
  55. void mchtmr_init_counter(MCHTMR_Type *ptr, uint64_t v);
  56. /**
  57. * @}
  58. */
  59. #ifdef __cplusplus
  60. }
  61. #endif
  62. #endif /* HPM_MCHTMR_DRV_H */