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_MAX32570_HTMR_H_
28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_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 
48 /**
49  * @brief   Bitmasks for each of the HTimer's interrupt enables.
50  */
51 typedef enum {
52     MXC_HTMR_INT_EN_LONG = MXC_F_HTMR_CTRL_ADE, ///< Long-interval alarm interrupt enable
53     MXC_HTMR_INT_EN_SHORT = MXC_F_HTMR_CTRL_ASE, ///< Short-interval alarm interrupt enable
54     MXC_HTMR_INT_EN_READY = MXC_F_HTMR_CTRL_RDYE, ///< Timer ready interrupt enable
55 } mxc_htmr_int_en_t;
56 
57 /**
58  * @brief   Bitmasks for each of the HTimer's interrupt flags.
59  */
60 typedef enum {
61     MXC_HTMR_INT_FL_LONG = MXC_F_HTMR_CTRL_ALDF, ///< Long-interval alarm interrupt flag
62     MXC_HTMR_INT_FL_SHORT = MXC_F_HTMR_CTRL_ALSF, ///< Short-interval alarm interrupt flag
63     MXC_HTMR_INT_FL_READY = MXC_F_HTMR_CTRL_RDY, ///< Timer ready interrupt flag
64 } mxc_htmr_int_fl_t;
65 
66 /**
67  * @brief     Enable Interurpts
68  * @param     htmr   pointer to the htmr register structure
69  * @param     mask   The bitwise OR of interrupts to enable.
70  *                   See #mxc_htmr_int_en_t for available choices.
71  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
72  */
73 int MXC_HTMR_EnableInt(mxc_htmr_regs_t *htmr, uint32_t mask);
74 
75 /**
76  * @brief     Disable Interurpts
77  * @param     htmr   pointer to the htmr register structure
78  * @param     mask   The mask of interrupts to disable.
79  *                   See #mxc_htmr_int_en_t for available choices.
80  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
81  */
82 int MXC_HTMR_DisableInt(mxc_htmr_regs_t *htmr, uint32_t mask);
83 
84 /**
85  * @brief     Set Long Interval alarm value and enable Interrupt
86  * @param     htmr    pointer to the htmr register structure
87  * @param     interval    20-bit value 0-0xFFFFF
88  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
89  */
90 int MXC_HTMR_SetLongAlarm(mxc_htmr_regs_t *htmr, uint32_t interval);
91 
92 /**
93  * @brief     Set Short Interval alarm value and enable interrupt,
94  * @param     htmr    pointer to the htmr register structure
95  * @param     interval   32-bit value 0-0xFFFFFFFF
96  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
97  */
98 int MXC_HTMR_SetShortAlarm(mxc_htmr_regs_t *htmr, uint32_t interval);
99 
100 /**
101  * @brief     Enable/Start the High Speed Timer
102  * @param     htmr    pointer to the htmr register structure
103  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
104  */
105 int MXC_HTMR_Start(mxc_htmr_regs_t *htmr);
106 
107 /**
108  * @brief     Disable/Stop the High Speed Timer
109  * @param     htmr    pointer to the htmr register structure
110  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
111  */
112 int MXC_HTMR_Stop(mxc_htmr_regs_t *htmr);
113 
114 /**
115  * @brief     Initialize the longInterval and shortInterval registers and enable MXC_HTMR
116  * @param     htmr   pointer to the htmr register structure
117  * @param     longInterval    set the MXC_HTMR long counter (32-bit)
118  * @param     shortInterval   set the MXC_HTMR short counter (8-bit)
119  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
120  */
121 int MXC_HTMR_Init(mxc_htmr_regs_t *htmr, uint32_t longInterval, uint8_t shortInterval);
122 
123 /**
124  * @brief     Check if BUSY bit is 0.
125  * @param     htmr   pointer to the htmr register structure
126  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
127  */
128 int MXC_HTMR_CheckBusy(mxc_htmr_regs_t *htmr);
129 
130 /**
131  * @brief     Get interrupt flags.
132  * @param     htmr   pointer to the htmr register structure
133  * @return    The bitwise OR of any interrupts flags that are
134  *            currently set. See #mxc_htmr_int_fl_t for the list
135  *            of possible flags.
136  */
137 int MXC_HTMR_GetFlags(mxc_htmr_regs_t *htmr);
138 
139 /**
140  * @brief     Clear interrupt flags.
141  * @param     htmr   pointer to the htmr register structure
142  * @param     flags The bitwise OR of the interrupts flags to cleear.
143  *            See #mxc_htmr_int_fl_t for the list of possible flags.
144  * @retval    returns Success or Fail, see \ref MXC_ERROR_CODES
145  */
146 int MXC_HTMR_ClearFlags(mxc_htmr_regs_t *htmr, int flags);
147 
148 /**
149  * @brief     Get value in short interval register
150  * @param     htmr   pointer to the htmr register structure
151  * @return    Returns short count value
152  */
153 int MXC_HTMR_GetShortCount(mxc_htmr_regs_t *htmr);
154 
155 /**
156  * @brief     Get value in long interval register
157  * @param     htmr   pointer to the htmr register structure
158  * @return    returns long count value
159  */
160 int MXC_HTMR_GetLongCount(mxc_htmr_regs_t *htmr);
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 /**@} end of group htmr */
167 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32570_HTMR_H_
168