1 /** 2 * @file wdt.h 3 * @brief Watchdog timer (WDT) function prototypes and data types. 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_MAX32675_WDT_H_ 28 #define LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_WDT_H_ 29 30 #ifdef __CC_ARM 31 #pragma diag_suppress 66 // enumeration value is out of int range 32 #endif 33 34 /* **** Includes **** */ 35 #include <stdint.h> 36 #include "mxc_device.h" 37 #include "wdt_regs.h" 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** 44 * @defgroup wdt WDT 45 * @ingroup periphlibs 46 * @{ 47 */ 48 49 /* **** Definitions **** */ 50 51 /** @brief Watchdog upper limit period enumeration. 52 Used to configure the period of the watchdog interrupt */ 53 typedef enum { 54 MXC_WDT_PERIOD_2_31 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW31, ///< Period 2^31 55 MXC_WDT_PERIOD_2_30 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW30, ///< Period 2^30 56 MXC_WDT_PERIOD_2_29 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW29, ///< Period 2^29 57 MXC_WDT_PERIOD_2_28 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW28, ///< Period 2^28 58 MXC_WDT_PERIOD_2_27 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW27, ///< Period 2^27 59 MXC_WDT_PERIOD_2_26 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW26, ///< Period 2^26 60 MXC_WDT_PERIOD_2_25 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW25, ///< Period 2^25 61 MXC_WDT_PERIOD_2_24 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW24, ///< Period 2^24 62 MXC_WDT_PERIOD_2_23 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW23, ///< Period 2^23 63 MXC_WDT_PERIOD_2_22 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW22, ///< Period 2^22 64 MXC_WDT_PERIOD_2_21 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW21, ///< Period 2^21 65 MXC_WDT_PERIOD_2_20 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW20, ///< Period 2^20 66 MXC_WDT_PERIOD_2_19 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW19, ///< Period 2^19 67 MXC_WDT_PERIOD_2_18 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW18, ///< Period 2^18 68 MXC_WDT_PERIOD_2_17 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW17, ///< Period 2^17 69 MXC_WDT_PERIOD_2_16 = MXC_S_WDT_CTRL_INT_LATE_VAL_WDT2POW16, ///< Period 2^16 70 } mxc_wdt_period_t; 71 72 /** 73 * @brief Watchdog interrupt flag enumeration 74 */ 75 typedef enum { 76 MXC_WDT_INT_TOO_LATE = MXC_F_WDT_CTRL_INT_LATE, 77 MXC_WDT_INT_TOO_SOON = MXC_F_WDT_CTRL_INT_EARLY, 78 } mxc_wdt_int_t; 79 80 /** 81 * @brief Watchdog reset flag enumeration 82 */ 83 typedef enum { 84 MXC_WDT_RST_TOO_LATE = MXC_F_WDT_CTRL_RST_LATE, 85 MXC_WDT_RST_TOO_SOON = MXC_F_WDT_CTRL_RST_EARLY, 86 } mxc_wdt_rst_t; 87 88 /** 89 * @brief Watchdog mode enumeration 90 */ 91 typedef enum { 92 MXC_WDT_COMPATIBILITY = 0, 93 MXC_WDT_WINDOWED = 1, 94 } mxc_wdt_mode_t; 95 96 /** 97 * @brief Peripheral Clock settings 98 */ 99 typedef enum { 100 MXC_WDT_PCLK = 0, 101 MXC_WDT_IPO_CLK, 102 MXC_WDT_IBRO_CLK, 103 MXC_WDT_INRO_CLK 104 } mxc_wdt_clock_t; 105 106 /** 107 * @brief Timer Configuration 108 */ 109 typedef struct { 110 mxc_wdt_mode_t mode; ///< WDT mode 111 mxc_wdt_period_t upperResetPeriod; ///< Reset upper limit 112 mxc_wdt_period_t lowerResetPeriod; ///< Reset lower limit 113 mxc_wdt_period_t upperIntPeriod; ///< Interrupt upper limit 114 mxc_wdt_period_t lowerIntPeriod; ///< Interrupt lower limit 115 } mxc_wdt_cfg_t; 116 /* **** Function Prototypes **** */ 117 118 /** 119 * @brief Initialize the Watchdog Timer 120 * @note On default this function enables WDT peripheral clock. 121 * if you wish to manage clock and gpio related things in upper level instead of here. 122 * Define MSDK_NO_GPIO_CLK_INIT flag in project.mk file. 123 * By this flag this function will remove clock and gpio related codes from file. 124 * 125 * @param wdt Pointer to the watchdog registers 126 * @param cfg watchdog configuration 127 * @return See \ref MXC_Error_Codes for the list of error codes. 128 */ 129 int MXC_WDT_Init(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg); 130 131 /** 132 * @brief Shutdown the Watchdog Timer 133 * @param wdt Pointer to the watchdog registers 134 * @return See \ref MXC_Error_Codes for the list of error codes. 135 */ 136 int MXC_WDT_Shutdown(mxc_wdt_regs_t *wdt); 137 138 /** 139 * @brief Set the period of the watchdog interrupt. 140 * @param wdt Pointer to watchdog registers. 141 * @param cfg watchdog configuration. 142 */ 143 void MXC_WDT_SetIntPeriod(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg); 144 145 /** 146 * @brief Set the period of the watchdog reset. 147 * @param wdt Pointer to watchdog registers. 148 * @param cfg watchdog configuration. 149 */ 150 void MXC_WDT_SetResetPeriod(mxc_wdt_regs_t *wdt, mxc_wdt_cfg_t *cfg); 151 152 /** 153 * @brief Enable the watchdog timer. 154 * @param wdt Pointer to watchdog registers. 155 */ 156 void MXC_WDT_Enable(mxc_wdt_regs_t *wdt); 157 158 /** 159 * @brief Disable the watchdog timer. 160 * @param wdt Pointer to watchdog registers. 161 */ 162 void MXC_WDT_Disable(mxc_wdt_regs_t *wdt); 163 164 /** 165 * @brief Enable the watchdog interrupt. 166 * @param wdt Pointer to watchdog registers. 167 */ 168 void MXC_WDT_EnableInt(mxc_wdt_regs_t *wdt); 169 170 /** 171 * @brief Disable the watchdog interrupt. 172 * @param wdt Pointer to watchdog registers. 173 */ 174 void MXC_WDT_DisableInt(mxc_wdt_regs_t *wdt); 175 176 /** 177 * @brief Enable the watchdog reset. 178 * @param wdt Pointer to watchdog registers. 179 */ 180 void MXC_WDT_EnableReset(mxc_wdt_regs_t *wdt); 181 182 /** 183 * @brief Disable the watchdog reset. 184 * @param wdt Pointer to watchdog registers. 185 */ 186 void MXC_WDT_DisableReset(mxc_wdt_regs_t *wdt); 187 188 /** 189 * @brief Reset the watchdog timer. 190 * @param wdt Pointer to watchdog registers. 191 */ 192 void MXC_WDT_ResetTimer(mxc_wdt_regs_t *wdt); 193 194 /** 195 * @brief Get the status of the reset flag. 196 * @param wdt Pointer to watchdog registers. 197 * @returns 1 if the previous reset was caused by the watchdog, 0 otherwise. 198 */ 199 int MXC_WDT_GetResetFlag(mxc_wdt_regs_t *wdt); 200 201 /** 202 * @brief Clears the reset flag. 203 * @param wdt Pointer to watchdog registers. 204 */ 205 void MXC_WDT_ClearResetFlag(mxc_wdt_regs_t *wdt); 206 207 /** 208 * @brief Get the status of the interrupt flag. 209 * @param wdt Pointer to watchdog registers. 210 * @returns 1 if the interrupt is pending, 0 otherwise. 211 */ 212 int MXC_WDT_GetIntFlag(mxc_wdt_regs_t *wdt); 213 214 /** 215 * @brief Clears the interrupt flag. 216 * @param wdt Pointer to watchdog registers. 217 */ 218 void MXC_WDT_ClearIntFlag(mxc_wdt_regs_t *wdt); 219 220 /** 221 * @brief Sets clock source. 222 * @param wdt Pointer to watchdog registers. 223 * @param clock_source Clock source. 224 */ 225 int MXC_WDT_SetClockSource(mxc_wdt_regs_t *wdt, mxc_wdt_clock_t clock_source); 226 227 /**@} end of group wdt */ 228 229 #ifdef __cplusplus 230 } 231 #endif 232 233 #endif // LIBRARIES_PERIPHDRIVERS_INCLUDE_MAX32675_WDT_H_ 234