1 /**
2  * @file    htmr.h
3  * @brief   High speed timer (HTMR) functions and prototypes.
4  */
5 
6 /******************************************************************************
7  *
8  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
9  * Analog Devices, Inc.),
10  * Copyright (C) 2023-2024 Analog Devices, Inc.
11  *
12  * Licensed under the Apache License, Version 2.0 (the "License");
13  * you may not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  *     http://www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an "AS IS" BASIS,
20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  *
24  ******************************************************************************/
25 
26 /* Define to prevent redundant inclusion */
27 #ifndef LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_HTMR_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_HTMR_H_
29 
30 /* **** Includes **** */
31 #include <stdint.h>
32 #include "mxc_device.h"
33 #include "htmr_regs.h"
34 #include "mxc_sys.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /**
41  * @defgroup htmr HTMR
42  * @ingroup periphlibs
43  * @{
44  */
45 
46 /* **** Definitions **** */
47 #define IBRO_FREQ HIRC8_FREQ
48 
49 /**
50  * @brief   Bitmasks for each of the HTimer's interrupt enables.
51  */
52 typedef enum {
53     MXC_HTMR_INT_EN_LONG = MXC_F_HTMR_CTRL_ADE, ///< Long-interval alarm interrupt enable
54     MXC_HTMR_INT_EN_SHORT = MXC_F_HTMR_CTRL_ASE, ///< Short-interval alarm interrupt enable
55     MXC_HTMR_INT_EN_READY = MXC_F_HTMR_CTRL_RDYE, ///< Timer ready interrupt enable
56 } mxc_htmr_int_en_t;
57 
58 /**
59  * @brief   Bitmasks for each of the HTimer's interrupt flags.
60  */
61 typedef enum {
62     MXC_HTMR_INT_FL_LONG = MXC_F_HTMR_CTRL_ALDF, ///< Long-interval alarm interrupt flag
63     MXC_HTMR_INT_FL_SHORT = MXC_F_HTMR_CTRL_ALSF, ///< Short-interval alarm interrupt flag
64     MXC_HTMR_INT_FL_READY = MXC_F_HTMR_CTRL_RDY, ///< Timer ready interrupt flag
65 } mxc_htmr_int_fl_t;
66 
67 /**
68  * @brief     Enable Interurpts
69  * @param     htmr   pointer to the htmr register structure
70  * @param     mask   The bitwise OR of interrupts to enable.
71  *                   See #mxc_htmr_int_en_t for available choices.
72  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
73  */
74 int MXC_HTMR_EnableInt(mxc_htmr_regs_t *htmr, uint32_t mask);
75 
76 /**
77  * @brief     Disable Interurpts
78  * @param     htmr   pointer to the htmr register structure
79  * @param     mask   The mask of interrupts to disable.
80  *                   See #mxc_htmr_int_en_t for available choices.
81  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
82  */
83 int MXC_HTMR_DisableInt(mxc_htmr_regs_t *htmr, uint32_t mask);
84 
85 /**
86  * @brief     Set Long Interval alarm value and enable Interrupt
87  * @param     htmr    pointer to the htmr register structure
88  * @param     interval    20-bit value 0-0xFFFFF
89  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
90  */
91 int MXC_HTMR_SetLongAlarm(mxc_htmr_regs_t *htmr, uint32_t interval);
92 
93 /**
94  * @brief     Set Short Interval alarm value and enable interrupt,
95  * @param     htmr    pointer to the htmr register structure
96  * @param     interval   32-bit value 0-0xFFFFFFFF
97  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
98  */
99 int MXC_HTMR_SetShortAlarm(mxc_htmr_regs_t *htmr, uint32_t interval);
100 
101 /**
102  * @brief     Enable/Start the High Speed Timer
103  * @param     htmr    pointer to the htmr register structure
104  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
105  */
106 int MXC_HTMR_Start(mxc_htmr_regs_t *htmr);
107 
108 /**
109  * @brief     Disable/Stop the High Speed Timer
110  * @param     htmr    pointer to the htmr register structure
111  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
112  */
113 int MXC_HTMR_Stop(mxc_htmr_regs_t *htmr);
114 
115 /**
116  * @brief     Initialize the longInterval and shortInterval registers and enable MXC_HTMR
117  * @param     htmr   pointer to the htmr register structure
118  * @param     longInterval    set the MXC_HTMR long counter (32-bit)
119  * @param     shortInterval   set the MXC_HTMR short counter (8-bit)
120  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
121  */
122 int MXC_HTMR_Init(mxc_htmr_regs_t *htmr, uint32_t longInterval, uint8_t shortInterval);
123 
124 /**
125  * @brief     Check if BUSY bit is 0.
126  * @param     htmr   pointer to the htmr register structure
127  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
128  */
129 int MXC_HTMR_CheckBusy(mxc_htmr_regs_t *htmr);
130 
131 /**
132  * @brief     Get interrupt flags.
133  * @param     htmr   pointer to the htmr register structure
134  * @return    The bitwise OR of any interrupts flags that are
135  *            currently set. See #mxc_htmr_int_fl_t for the list
136  *            of possible flags.
137  */
138 int MXC_HTMR_GetFlags(mxc_htmr_regs_t *htmr);
139 
140 /**
141  * @brief     Clear interrupt flags.
142  * @param     htmr   pointer to the htmr register structure
143  * @param     flags The bitwise OR of the interrupts flags to cleear.
144  *            See #mxc_htmr_int_fl_t for the list of possible flags.
145  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
146  */
147 int MXC_HTMR_ClearFlags(mxc_htmr_regs_t *htmr, int flags);
148 
149 /**
150  * @brief     Get value in short interval register
151  * @param     htmr   pointer to the htmr register structure
152  * @return    Returns short count value
153  */
154 int MXC_HTMR_GetShortCount(mxc_htmr_regs_t *htmr);
155 
156 /**
157  * @brief     Get value in long interval register
158  * @param     htmr   pointer to the htmr register structure
159  * @return    returns long count value
160  */
161 int MXC_HTMR_GetLongCount(mxc_htmr_regs_t *htmr);
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 /**@} end of group htmr */
168 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32665_HTMR_H_
169