hpm_synt_drv.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (c) 2021 HPMicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_SYNT_DRV_H
  8. #define HPM_SYNT_DRV_H
  9. #include "hpm_common.h"
  10. #include "hpm_synt_regs.h"
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14. static inline void synt_enable_counter(SYNT_Type *ptr, bool enable)
  15. {
  16. ptr->GCR = (ptr->GCR & ~(SYNT_GCR_CEN_MASK)) | SYNT_GCR_CEN_SET(enable);
  17. }
  18. static inline void synt_reset_counter(SYNT_Type *ptr)
  19. {
  20. ptr->GCR |= SYNT_GCR_CRST_MASK;
  21. ptr->GCR &= ~SYNT_GCR_CRST_MASK;
  22. }
  23. static inline hpm_stat_t synt_set_comparator(SYNT_Type *ptr,
  24. uint8_t cmp_index,
  25. uint32_t count)
  26. {
  27. if (cmp_index > SYNT_CMP_3) {
  28. return status_invalid_argument;
  29. }
  30. ptr->CMP[cmp_index] = SYNT_CMP_CMP_SET(count);
  31. return status_success;
  32. }
  33. static inline void synt_set_reload(SYNT_Type *ptr, uint32_t reload_count)
  34. {
  35. ptr->RLD = SYNT_RLD_RLD_SET(reload_count);
  36. }
  37. static inline uint32_t synt_get_current_count(SYNT_Type *ptr)
  38. {
  39. return (ptr->CNT & SYNT_CNT_CNT_MASK) >> SYNT_CNT_CNT_SHIFT;
  40. }
  41. #if defined(SYNT_SOC_HAS_TIMESTAMP) && SYNT_SOC_HAS_TIMESTAMP
  42. static inline void synt_enable_timestamp(SYNT_Type *ptr, bool enable)
  43. {
  44. ptr->GCR = (ptr->GCR & ~(SYNT_GCR_TIMESTAMP_ENABLE_MASK)) | SYNT_GCR_TIMESTAMP_ENABLE_SET(enable);
  45. }
  46. static inline void synt_enable_timestamp_debug_stop(SYNT_Type *ptr, bool enable)
  47. {
  48. ptr->GCR = (ptr->GCR & ~(SYNT_GCR_TIMESTAMP_DEBUG_EN_MASK)) | SYNT_GCR_TIMESTAMP_DEBUG_EN_SET(enable);
  49. }
  50. static inline void synt_reset_timestamp(SYNT_Type *ptr)
  51. {
  52. ptr->GCR |= SYNT_GCR_TIMESTAMP_RESET_MASK;
  53. }
  54. static inline void synt_update_timestamp_new(SYNT_Type *ptr)
  55. {
  56. ptr->GCR |= SYNT_GCR_TIMESTAMP_SET_NEW_MASK;
  57. }
  58. static inline void synt_update_timestamp_dec(SYNT_Type *ptr)
  59. {
  60. ptr->GCR |= SYNT_GCR_TIMESTAMP_DEC_NEW_MASK;
  61. }
  62. static inline void synt_update_timestamp_inc(SYNT_Type *ptr)
  63. {
  64. ptr->GCR |= SYNT_GCR_TIMESTAMP_INC_NEW_MASK;
  65. }
  66. static inline void synt_set_timestamp_new_value(SYNT_Type *ptr, uint32_t new_value)
  67. {
  68. ptr->TIMESTAMP_NEW = SYNT_TIMESTAMP_NEW_VALUE_SET(new_value);
  69. }
  70. static inline uint32_t synt_get_timestamp_save_value(SYNT_Type *ptr)
  71. {
  72. return SYNT_TIMESTAMP_SAV_VALUE_GET(ptr->TIMESTAMP_SAV);
  73. }
  74. static inline uint32_t synt_get_timestamp_current_value(SYNT_Type *ptr)
  75. {
  76. return SYNT_TIMESTAMP_CUR_VALUE_GET(ptr->TIMESTAMP_CUR);
  77. }
  78. #endif
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif /* HPM_SYNT_DRV_H */