1 /******************************************************************************
2  *
3  * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by
4  * Analog Devices, Inc.),
5  * Copyright (C) 2023-2024 Analog Devices, Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************************/
20 
21 #ifndef LIBRARIES_PERIPHDRIVERS_SOURCE_WUT_WUT_REVA_H_
22 #define LIBRARIES_PERIPHDRIVERS_SOURCE_WUT_WUT_REVA_H_
23 
24 /* **** Includes **** */
25 #include <stdint.h>
26 #include "mxc_device.h"
27 #include "mxc_assert.h"
28 #include "mxc_sys.h"
29 #include "wut.h"
30 #include "wut_reva_regs.h"
31 #include "gcr_regs.h"
32 
33 /**
34  * @brief Wakeup Timer prescaler values
35  */
36 typedef enum {
37     MXC_WUT_REVA_PRES_1 = MXC_S_WUT_REVA_CTRL_PRES_DIV1, /// Divide input clock by 1
38     MXC_WUT_REVA_PRES_2 = MXC_S_WUT_REVA_CTRL_PRES_DIV2, /// Divide input clock by 2
39     MXC_WUT_REVA_PRES_4 = MXC_S_WUT_REVA_CTRL_PRES_DIV4, /// Divide input clock by 4
40     MXC_WUT_REVA_PRES_8 = MXC_S_WUT_REVA_CTRL_PRES_DIV8, /// Divide input clock by 8
41     MXC_WUT_REVA_PRES_16 = MXC_S_WUT_REVA_CTRL_PRES_DIV16, /// Divide input clock by 16
42     MXC_WUT_REVA_PRES_32 = MXC_S_WUT_REVA_CTRL_PRES_DIV32, /// Divide input clock by 32
43     MXC_WUT_REVA_PRES_64 = MXC_S_WUT_REVA_CTRL_PRES_DIV64, /// Divide input clock by 64
44     MXC_WUT_REVA_PRES_128 = MXC_S_WUT_REVA_CTRL_PRES_DIV128, /// Divide input clock by 128
45     MXC_WUT_REVA_PRES_256 = MXC_F_WUT_REVA_CTRL_PRES3 |
46                             MXC_S_WUT_REVA_CTRL_PRES_DIV1, /// Divide input clock by 256
47     MXC_WUT_REVA_PRES_512 = MXC_F_WUT_REVA_CTRL_PRES3 |
48                             MXC_S_WUT_REVA_CTRL_PRES_DIV2, /// Divide input clock by 512
49     MXC_WUT_REVA_PRES_1024 = MXC_F_WUT_REVA_CTRL_PRES3 |
50                              MXC_S_WUT_REVA_CTRL_PRES_DIV4, /// Divide input clock by 1024
51     MXC_WUT_REVA_PRES_2048 = MXC_F_WUT_REVA_CTRL_PRES3 |
52                              MXC_S_WUT_REVA_CTRL_PRES_DIV8, /// Divide input clock by 2048
53     MXC_WUT_REVA_PRES_4096 = MXC_F_WUT_REVA_CTRL_PRES3 |
54                              MXC_S_WUT_REVA_CTRL_PRES_DIV16 /// Divide input clock by 4096
55 } mxc_wut_reva_pres_t;
56 
57 /**
58  * @brief Wakeup Timer modes
59  */
60 typedef enum {
61     MXC_WUT_REVA_MODE_ONESHOT = MXC_V_WUT_REVA_CTRL_TMODE_ONESHOT, /// Wakeup Timer Mode ONESHOT
62     MXC_WUT_REVA_MODE_CONTINUOUS =
63         MXC_V_WUT_REVA_CTRL_TMODE_CONTINUOUS, /// Wakeup Timer Mode CONTINUOUS
64 } mxc_wut_reva_mode_t;
65 
66 /**
67  * @brief Wakeup Timer units of time enumeration
68  */
69 typedef enum {
70     MXC_WUT_REVA_UNIT_NANOSEC = 0, /**< Nanosecond Unit Indicator. */
71     MXC_WUT_REVA_UNIT_MICROSEC, /**< Microsecond Unit Indicator. */
72     MXC_WUT_REVA_UNIT_MILLISEC, /**< Millisecond Unit Indicator. */
73     MXC_WUT_REVA_UNIT_SEC /**< Second Unit Indicator. */
74 } mxc_wut_reva_unit_t;
75 
76 /**
77  * @brief Wakeup Timer Configuration
78  */
79 typedef struct {
80     mxc_wut_reva_mode_t mode; /// Desired timer mode
81     uint32_t cmp_cnt; /// Compare register value in timer ticks
82 } mxc_wut_reva_cfg_t;
83 
84 /* **** Functions **** */
85 void MXC_WUT_RevA_Init(mxc_wut_reva_regs_t *wut, mxc_wut_reva_pres_t pres);
86 
87 void MXC_WUT_RevA_Shutdown(mxc_wut_reva_regs_t *wut);
88 
89 void MXC_WUT_RevA_Enable(mxc_wut_reva_regs_t *wut);
90 
91 void MXC_WUT_RevA_Disable(mxc_wut_reva_regs_t *wut);
92 
93 void MXC_WUT_RevA_Config(mxc_wut_reva_regs_t *wut, const mxc_wut_reva_cfg_t *cfg);
94 
95 uint32_t MXC_WUT_RevA_GetCompare(mxc_wut_reva_regs_t *wut);
96 
97 uint32_t MXC_WUT_RevA_GetCapture(mxc_wut_reva_regs_t *wut);
98 
99 uint32_t MXC_WUT_RevA_GetCount(mxc_wut_reva_regs_t *wut);
100 
101 void MXC_WUT_RevA_IntClear(mxc_wut_reva_regs_t *wut);
102 
103 uint32_t MXC_WUT_RevA_IntStatus(mxc_wut_reva_regs_t *wut);
104 
105 void MXC_WUT_RevA_SetCompare(mxc_wut_reva_regs_t *wut, uint32_t cmp_cnt);
106 
107 void MXC_WUT_RevA_SetCount(mxc_wut_reva_regs_t *wut, uint32_t cnt);
108 
109 int MXC_WUT_RevA_GetTicks(mxc_wut_reva_regs_t *wut, uint32_t timerClock, uint32_t time,
110                           mxc_wut_reva_unit_t units, uint32_t *ticks);
111 
112 int MXC_WUT_RevA_GetTime(mxc_wut_reva_regs_t *wut, uint32_t timerClock, uint32_t ticks,
113                          uint32_t *time, mxc_wut_reva_unit_t *units);
114 
115 void MXC_WUT_RevA_Edge(mxc_wut_reva_regs_t *wut);
116 
117 void MXC_WUT_RevA_Store(mxc_wut_reva_regs_t *wut);
118 
119 void MXC_WUT_RevA_RestoreBBClock(mxc_wut_reva_regs_t *wut, uint32_t dbbFreq, uint32_t timerClock);
120 
121 uint32_t MXC_WUT_RevA_GetSleepTicks(mxc_wut_reva_regs_t *wut);
122 
123 void MXC_WUT_RevA_Delay_MS(mxc_wut_reva_regs_t *wut, uint32_t waitMs, uint32_t timerClock);
124 
125 #endif // LIBRARIES_PERIPHDRIVERS_SOURCE_WUT_WUT_REVA_H_
126