hpm_synt_drv.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif /* HPM_SYNT_DRV_H */