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 #if defined(SYNT_SOC_HAS_TIMESTAMP) && SYNT_SOC_HAS_TIMESTAMP
50
synt_enable_timestamp(SYNT_Type * ptr,bool enable)51 static inline void synt_enable_timestamp(SYNT_Type *ptr, bool enable)
52 {
53 ptr->GCR = (ptr->GCR & ~(SYNT_GCR_TIMESTAMP_ENABLE_MASK)) | SYNT_GCR_TIMESTAMP_ENABLE_SET(enable);
54 }
55
synt_enable_timestamp_debug_stop(SYNT_Type * ptr,bool enable)56 static inline void synt_enable_timestamp_debug_stop(SYNT_Type *ptr, bool enable)
57 {
58 ptr->GCR = (ptr->GCR & ~(SYNT_GCR_TIMESTAMP_DEBUG_EN_MASK)) | SYNT_GCR_TIMESTAMP_DEBUG_EN_SET(enable);
59 }
60
synt_reset_timestamp(SYNT_Type * ptr)61 static inline void synt_reset_timestamp(SYNT_Type *ptr)
62 {
63 ptr->GCR |= SYNT_GCR_TIMESTAMP_RESET_MASK;
64 }
65
synt_update_timestamp_new(SYNT_Type * ptr)66 static inline void synt_update_timestamp_new(SYNT_Type *ptr)
67 {
68 ptr->GCR |= SYNT_GCR_TIMESTAMP_SET_NEW_MASK;
69 }
70
synt_update_timestamp_dec(SYNT_Type * ptr)71 static inline void synt_update_timestamp_dec(SYNT_Type *ptr)
72 {
73 ptr->GCR |= SYNT_GCR_TIMESTAMP_DEC_NEW_MASK;
74 }
75
synt_update_timestamp_inc(SYNT_Type * ptr)76 static inline void synt_update_timestamp_inc(SYNT_Type *ptr)
77 {
78 ptr->GCR |= SYNT_GCR_TIMESTAMP_INC_NEW_MASK;
79 }
80
synt_set_timestamp_new_value(SYNT_Type * ptr,uint32_t new_value)81 static inline void synt_set_timestamp_new_value(SYNT_Type *ptr, uint32_t new_value)
82 {
83 ptr->TIMESTAMP_NEW = SYNT_TIMESTAMP_NEW_VALUE_SET(new_value);
84 }
85
synt_get_timestamp_save_value(SYNT_Type * ptr)86 static inline uint32_t synt_get_timestamp_save_value(SYNT_Type *ptr)
87 {
88 return SYNT_TIMESTAMP_SAV_VALUE_GET(ptr->TIMESTAMP_SAV);
89 }
90
synt_get_timestamp_current_value(SYNT_Type * ptr)91 static inline uint32_t synt_get_timestamp_current_value(SYNT_Type *ptr)
92 {
93 return SYNT_TIMESTAMP_CUR_VALUE_GET(ptr->TIMESTAMP_CUR);
94 }
95
96 #endif
97
98 #ifdef __cplusplus
99 }
100 #endif
101
102 #endif /* HPM_SYNT_DRV_H */
103