• 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_MCHTMR_DRV_H
9 #define HPM_MCHTMR_DRV_H
10 #include "hpm_common.h"
11 #include "hpm_mchtmr_regs.h"
12 
13 /**
14  * @brief MCHTMR driver APIs
15  * @defgroup mchtmr_interface MCHTMR driver APIs
16  * @ingroup io_interfaces
17  * @{
18  */
19 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 /**
25  * @brief mchtmr get counter value
26  *
27  * @param [in] ptr MCHTMR base address
28  */
mchtmr_get_count(MCHTMR_Type * ptr)29 static inline uint64_t mchtmr_get_count(MCHTMR_Type *ptr)
30 {
31     return (ptr->MTIME & MCHTMR_MTIME_MTIME_MASK) >> MCHTMR_MTIME_MTIME_SHIFT;
32 }
33 
34 /**
35  * @brief mchtmr set comparator value
36  *
37  * @param [in] ptr MCHTMR base address
38  * @param [in] target comparator target value
39  */
mchtmr_set_compare_value(MCHTMR_Type * ptr,uint64_t target)40 static inline void mchtmr_set_compare_value(MCHTMR_Type *ptr, uint64_t target)
41 {
42     ptr->MTIMECMP = MCHTMR_MTIMECMP_MTIMECMP_SET(target);
43 }
44 
45 /**
46  * @brief mchtmr set delay value
47  *
48  * @param [in] ptr MCHTMR base address
49  * @param [in] delay delay cycles
50  */
mchtmr_delay(MCHTMR_Type * ptr,uint64_t delay)51 static inline void mchtmr_delay(MCHTMR_Type *ptr, uint64_t delay)
52 {
53     mchtmr_set_compare_value(ptr, mchtmr_get_count(ptr) + delay);
54 }
55 
56 /**
57  * @brief initialize mchtmr counter
58  *
59  * @param [in] ptr MCHTMR base address
60  * @param [in] v value to be set
61  */
62 void mchtmr_init_counter(MCHTMR_Type *ptr, uint64_t v);
63 
64 /**
65  * @}
66  */
67 #ifdef __cplusplus
68 }
69 #endif
70 #endif /* HPM_MCHTMR_DRV_H */
71