• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_SYNT_DRV_H
9 #define HPM_SYNT_DRV_H
10 #include "hpm_common.h"
11 #include "hpm_synt_regs.h"
12 
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16 
synt_enable_counter(SYNT_Type * ptr,bool enable)17 static inline void synt_enable_counter(SYNT_Type *ptr, bool enable)
18 {
19     ptr->GCR = (ptr->GCR & ~(SYNT_GCR_CEN_MASK)) | SYNT_GCR_CEN_SET(enable);
20 }
21 
synt_reset_counter(SYNT_Type * ptr)22 static inline void synt_reset_counter(SYNT_Type *ptr)
23 {
24     ptr->GCR |= SYNT_GCR_CRST_MASK;
25     ptr->GCR &= ~SYNT_GCR_CRST_MASK;
26 }
27 
synt_set_comparator(SYNT_Type * ptr,uint8_t cmp_index,uint32_t count)28 static inline hpm_stat_t synt_set_comparator(SYNT_Type *ptr,
29                                        uint8_t cmp_index,
30                                        uint32_t count)
31 {
32     if (cmp_index > SYNT_CMP_3) {
33         return status_invalid_argument;
34     }
35     ptr->CMP[cmp_index] = SYNT_CMP_CMP_SET(count);
36     return status_success;
37 }
38 
synt_set_reload(SYNT_Type * ptr,uint32_t reload_count)39 static inline void synt_set_reload(SYNT_Type *ptr, uint32_t reload_count)
40 {
41     ptr->RLD = SYNT_RLD_RLD_SET(reload_count);
42 }
43 
synt_get_current_count(SYNT_Type * ptr)44 static inline uint32_t synt_get_current_count(SYNT_Type *ptr)
45 {
46     return (ptr->CNT & SYNT_CNT_CNT_MASK) >> SYNT_CNT_CNT_SHIFT;
47 }
48 
49 #ifdef __cplusplus
50 }
51 #endif
52 
53 #endif /* HPM_SYNT_DRV_H */
54