• 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_MONO_DRV_H
9 #define HPM_MONO_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_mono_regs.h"
13 
14 /**
15  *
16  * @brief MONO driver APIs
17  * @defgroup mono_interface MONO driver APIs
18  * @ingroup io_interfaces
19  * @{
20  */
21 
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /**
28  * @brief   Get counter high
29  *
30  * @param[in] ptr MONO base address
31  *
32  * @return counter value high 16 bits
33  */
mono_get_counter_high(MONO_Type * ptr)34 static inline uint16_t mono_get_counter_high(MONO_Type *ptr)
35 {
36     return MONO_MONOH_COUNTER_GET(ptr->MONOH);
37 }
38 
39 /**
40  * @brief   Get counter low
41  *
42  * @param[in] ptr MONO base address
43  *
44  * @return counter value low 32 bits
45  */
mono_get_counter_low(MONO_Type * ptr)46 static inline uint32_t mono_get_counter_low(MONO_Type *ptr)
47 {
48     return MONO_MONOL_COUNTER_GET(ptr->MONOL);
49 }
50 
51 /**
52  * @brief   Get counter
53  *
54  * @param[in] ptr MONO base address
55  *
56  * @return 48 bits counter value
57  */
mono_get_counter(MONO_Type * ptr)58 static inline uint64_t mono_get_counter(MONO_Type *ptr)
59 {
60     return (uint64_t)((uint64_t)mono_get_counter_high(ptr) << 32)
61         | (uint64_t)mono_get_counter_low(ptr);
62 }
63 
64 /**
65  * @brief   Get epoch
66  *
67  * @param[in] ptr MONO Base address
68  *
69  * @return epoch value 16 bits
70  */
mono_get_epoch(MONO_Type * ptr)71 static inline uint32_t mono_get_epoch(MONO_Type *ptr)
72 {
73     return MONO_MONOH_EPOCH_GET(ptr->MONOH);
74 }
75 
76 
77 /**
78  * @brief   Update MONO counter by 1
79  *
80  * @param[in] ptr MONO base
81  */
mono_update(MONO_Type * ptr)82 static inline void mono_update(MONO_Type *ptr)
83 {
84     ptr->MONOL = 1;
85 }
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 /**
91  * @}
92  */
93 #endif /* HPM_MONO_DRV_H */
94 
95