mbed library sources. Supersedes mbed-src. Edited target satm32f446 for user USART3 pins

Dependents:   IGLOO_board

Fork of mbed-dev by mbed official

Committer:
Anna Bridge
Date:
Fri Jun 22 16:45:37 2018 +0100
Revision:
186:707f6e361f3e
mbed-dev library. Release version 162

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anna Bridge 186:707f6e361f3e 1 /**
Anna Bridge 186:707f6e361f3e 2 * @file
Anna Bridge 186:707f6e361f3e 3 * @brief WDT2 peripheral module API.
Anna Bridge 186:707f6e361f3e 4 */
Anna Bridge 186:707f6e361f3e 5 /* ****************************************************************************
Anna Bridge 186:707f6e361f3e 6 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
Anna Bridge 186:707f6e361f3e 7 *
Anna Bridge 186:707f6e361f3e 8 * Permission is hereby granted, free of charge, to any person obtaining a
Anna Bridge 186:707f6e361f3e 9 * copy of this software and associated documentation files (the "Software"),
Anna Bridge 186:707f6e361f3e 10 * to deal in the Software without restriction, including without limitation
Anna Bridge 186:707f6e361f3e 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
Anna Bridge 186:707f6e361f3e 12 * and/or sell copies of the Software, and to permit persons to whom the
Anna Bridge 186:707f6e361f3e 13 * Software is furnished to do so, subject to the following conditions:
Anna Bridge 186:707f6e361f3e 14 *
Anna Bridge 186:707f6e361f3e 15 * The above copyright notice and this permission notice shall be included
Anna Bridge 186:707f6e361f3e 16 * in all copies or substantial portions of the Software.
Anna Bridge 186:707f6e361f3e 17 *
Anna Bridge 186:707f6e361f3e 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Anna Bridge 186:707f6e361f3e 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Anna Bridge 186:707f6e361f3e 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Anna Bridge 186:707f6e361f3e 21 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
Anna Bridge 186:707f6e361f3e 22 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Anna Bridge 186:707f6e361f3e 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Anna Bridge 186:707f6e361f3e 24 * OTHER DEALINGS IN THE SOFTWARE.
Anna Bridge 186:707f6e361f3e 25 *
Anna Bridge 186:707f6e361f3e 26 * Except as contained in this notice, the name of Maxim Integrated
Anna Bridge 186:707f6e361f3e 27 * Products, Inc. shall not be used except as stated in the Maxim Integrated
Anna Bridge 186:707f6e361f3e 28 * Products, Inc. Branding Policy.
Anna Bridge 186:707f6e361f3e 29 *
Anna Bridge 186:707f6e361f3e 30 * The mere transfer of this software does not imply any licenses
Anna Bridge 186:707f6e361f3e 31 * of trade secrets, proprietary technology, copyrights, patents,
Anna Bridge 186:707f6e361f3e 32 * trademarks, maskwork rights, or any other form of intellectual
Anna Bridge 186:707f6e361f3e 33 * property whatsoever. Maxim Integrated Products, Inc. retains all
Anna Bridge 186:707f6e361f3e 34 * ownership rights.
Anna Bridge 186:707f6e361f3e 35 *
Anna Bridge 186:707f6e361f3e 36 * $Date: 2017-02-16 15:06:56 -0600 (Thu, 16 Feb 2017) $
Anna Bridge 186:707f6e361f3e 37 * $Revision: 26491 $
Anna Bridge 186:707f6e361f3e 38 *
Anna Bridge 186:707f6e361f3e 39 **************************************************************************** */
Anna Bridge 186:707f6e361f3e 40
Anna Bridge 186:707f6e361f3e 41 /* Define to prevent redundant inclusion */
Anna Bridge 186:707f6e361f3e 42 #ifndef _WDT2_H
Anna Bridge 186:707f6e361f3e 43 #define _WDT2_H
Anna Bridge 186:707f6e361f3e 44
Anna Bridge 186:707f6e361f3e 45 /* **** Includes **** */
Anna Bridge 186:707f6e361f3e 46 #include "mxc_config.h"
Anna Bridge 186:707f6e361f3e 47 #include "wdt2_regs.h"
Anna Bridge 186:707f6e361f3e 48 #include "mxc_assert.h"
Anna Bridge 186:707f6e361f3e 49
Anna Bridge 186:707f6e361f3e 50 #ifdef __cplusplus
Anna Bridge 186:707f6e361f3e 51 extern "C" {
Anna Bridge 186:707f6e361f3e 52 #endif
Anna Bridge 186:707f6e361f3e 53
Anna Bridge 186:707f6e361f3e 54 /**
Anna Bridge 186:707f6e361f3e 55 * @ingroup wdttimers
Anna Bridge 186:707f6e361f3e 56 * @defgroup wdt2 Watch Dog Timer 2
Anna Bridge 186:707f6e361f3e 57 * @brief WDT2 configuration and control API.
Anna Bridge 186:707f6e361f3e 58 * @{
Anna Bridge 186:707f6e361f3e 59 */
Anna Bridge 186:707f6e361f3e 60
Anna Bridge 186:707f6e361f3e 61 /**
Anna Bridge 186:707f6e361f3e 62 * Definition to clear all WDT2 flags
Anna Bridge 186:707f6e361f3e 63 */
Anna Bridge 186:707f6e361f3e 64 #define WDT2_FLAGS_CLEAR_ALL (MXC_F_WDT2_FLAGS_TIMEOUT | MXC_F_WDT2_FLAGS_RESET_OUT)
Anna Bridge 186:707f6e361f3e 65 /**
Anna Bridge 186:707f6e361f3e 66 * Enumeration type to select the Watchdog Timer's Period
Anna Bridge 186:707f6e361f3e 67 */
Anna Bridge 186:707f6e361f3e 68 typedef enum {
Anna Bridge 186:707f6e361f3e 69 WDT2_PERIOD_2_25_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_25_NANO_CLKS, /**< \f$ 2^{25}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 70 WDT2_PERIOD_2_24_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_24_NANO_CLKS, /**< \f$ 2^{24}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 71 WDT2_PERIOD_2_23_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_23_NANO_CLKS, /**< \f$ 2^{23}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 72 WDT2_PERIOD_2_22_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_22_NANO_CLKS, /**< \f$ 2^{22}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 73 WDT2_PERIOD_2_21_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_21_NANO_CLKS, /**< \f$ 2^{21}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 74 WDT2_PERIOD_2_20_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_20_NANO_CLKS, /**< \f$ 2^{20}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 75 WDT2_PERIOD_2_19_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_19_NANO_CLKS, /**< \f$ 2^{19}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 76 WDT2_PERIOD_2_18_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_18_NANO_CLKS, /**< \f$ 2^{18}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 77 WDT2_PERIOD_2_17_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_17_NANO_CLKS, /**< \f$ 2^{17}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 78 WDT2_PERIOD_2_16_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_16_NANO_CLKS, /**< \f$ 2^{16}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 79 WDT2_PERIOD_2_15_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_15_NANO_CLKS, /**< \f$ 2^{15}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 80 WDT2_PERIOD_2_14_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_14_NANO_CLKS, /**< \f$ 2^{14}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 81 WDT2_PERIOD_2_13_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_13_NANO_CLKS, /**< \f$ 2^{13}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 82 WDT2_PERIOD_2_12_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_12_NANO_CLKS, /**< \f$ 2^{12}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 83 WDT2_PERIOD_2_11_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_11_NANO_CLKS, /**< \f$ 2^{11}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 84 WDT2_PERIOD_2_10_CLKS = MXC_V_WDT2_CTRL_INT_PERIOD_2_10_NANO_CLKS, /**< \f$ 2^{10}\f$ Nano Ring clocks. */
Anna Bridge 186:707f6e361f3e 85 WDT2_PERIOD_MAX /**< Maximum Period is Max - 1 */
Anna Bridge 186:707f6e361f3e 86 } wdt2_period_t;
Anna Bridge 186:707f6e361f3e 87
Anna Bridge 186:707f6e361f3e 88
Anna Bridge 186:707f6e361f3e 89 /**
Anna Bridge 186:707f6e361f3e 90 * @brief Initializes the NanoRing for the watchdog clock and sets watchdog
Anna Bridge 186:707f6e361f3e 91 * in a known disabled state
Anna Bridge 186:707f6e361f3e 92 * @param runInSleep If non-zero, the WDT2 operates in Sleep Modes for
Anna Bridge 186:707f6e361f3e 93 * the device, 0 disables the WDT2 during Sleep Modes.
Anna Bridge 186:707f6e361f3e 94 * @param unlock_key The WDT2 unlock key value, use
Anna Bridge 186:707f6e361f3e 95 * #MXC_V_WDT2_UNLOCK_KEY
Anna Bridge 186:707f6e361f3e 96 *
Anna Bridge 186:707f6e361f3e 97 * @retval #E_NO_ERROR Watchdog Timer initialized as requested
Anna Bridge 186:707f6e361f3e 98 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 99 */
Anna Bridge 186:707f6e361f3e 100 int WDT2_Init(uint8_t runInSleep, uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 101
Anna Bridge 186:707f6e361f3e 102 /**
Anna Bridge 186:707f6e361f3e 103 * @brief Configures and enables the wake-up timeout for the watchdog
Anna Bridge 186:707f6e361f3e 104 * specified.
Anna Bridge 186:707f6e361f3e 105 *
Anna Bridge 186:707f6e361f3e 106 * @param int_period Interrupt period.
Anna Bridge 186:707f6e361f3e 107 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 108 *
Anna Bridge 186:707f6e361f3e 109 * @retval #E_NO_ERROR WDT2 Interrupt period enabled with the int_period
Anna Bridge 186:707f6e361f3e 110 * time.
Anna Bridge 186:707f6e361f3e 111 * @retval #E_INVALID Requested Period is greater than the maximum
Anna Bridge 186:707f6e361f3e 112 * supported
Anna Bridge 186:707f6e361f3e 113 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 114 */
Anna Bridge 186:707f6e361f3e 115 int WDT2_EnableWakeUp(wdt2_period_t int_period, uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 116
Anna Bridge 186:707f6e361f3e 117 /**
Anna Bridge 186:707f6e361f3e 118 * @brief Disables the interrupt timeout for the watchdog specified.
Anna Bridge 186:707f6e361f3e 119 *
Anna Bridge 186:707f6e361f3e 120 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 121 *
Anna Bridge 186:707f6e361f3e 122 * @retval #E_NO_ERROR Wakeup disabled.
Anna Bridge 186:707f6e361f3e 123 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 124 */
Anna Bridge 186:707f6e361f3e 125 int WDT2_DisableWakeUp(uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 126
Anna Bridge 186:707f6e361f3e 127 /**
Anna Bridge 186:707f6e361f3e 128 * @brief Configures and enables the reset timeout for the watchdog
Anna Bridge 186:707f6e361f3e 129 * specified.
Anna Bridge 186:707f6e361f3e 130 *
Anna Bridge 186:707f6e361f3e 131 * @param rst_period Reset period.
Anna Bridge 186:707f6e361f3e 132 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 133 *
Anna Bridge 186:707f6e361f3e 134 * @retval #E_NO_ERROR Reset timeout enabled with the rst_period time.
Anna Bridge 186:707f6e361f3e 135 * @retval #E_INVALID Requested Period is greater than the maximum
Anna Bridge 186:707f6e361f3e 136 * supported
Anna Bridge 186:707f6e361f3e 137 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 138 */
Anna Bridge 186:707f6e361f3e 139 int WDT2_EnableReset(wdt2_period_t rst_period, uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 140
Anna Bridge 186:707f6e361f3e 141 /**
Anna Bridge 186:707f6e361f3e 142 * @brief Disables the reset timeout for the watchdog specified.
Anna Bridge 186:707f6e361f3e 143 *
Anna Bridge 186:707f6e361f3e 144 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 145 *
Anna Bridge 186:707f6e361f3e 146 * @retval #E_NO_ERROR Reset disabled.
Anna Bridge 186:707f6e361f3e 147 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 148 */
Anna Bridge 186:707f6e361f3e 149 int WDT2_DisableReset(uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 150
Anna Bridge 186:707f6e361f3e 151 /**
Anna Bridge 186:707f6e361f3e 152 * @brief Gets the watchdog flags
Anna Bridge 186:707f6e361f3e 153 *
Anna Bridge 186:707f6e361f3e 154 * @retval 0 No flags set.
Anna Bridge 186:707f6e361f3e 155 * @retval non-zero The WDT2 interrupt flags that are
Anna Bridge 186:707f6e361f3e 156 * set, see @ref WDT2_FLAGS_Register "WDT2_FLAGS
Anna Bridge 186:707f6e361f3e 157 * register".
Anna Bridge 186:707f6e361f3e 158 */
Anna Bridge 186:707f6e361f3e 159 __STATIC_INLINE uint32_t WDT2_GetFlags(void)
Anna Bridge 186:707f6e361f3e 160 {
Anna Bridge 186:707f6e361f3e 161 return (MXC_WDT2->flags);
Anna Bridge 186:707f6e361f3e 162 }
Anna Bridge 186:707f6e361f3e 163
Anna Bridge 186:707f6e361f3e 164 /**
Anna Bridge 186:707f6e361f3e 165 * @brief Clears the watchdog flags based on the @p mask.
Anna Bridge 186:707f6e361f3e 166 *
Anna Bridge 186:707f6e361f3e 167 * @param mask bits to clear
Anna Bridge 186:707f6e361f3e 168 */
Anna Bridge 186:707f6e361f3e 169 __STATIC_INLINE void WDT2_ClearFlags(uint32_t mask)
Anna Bridge 186:707f6e361f3e 170 {
Anna Bridge 186:707f6e361f3e 171 MXC_WDT2->flags = mask;
Anna Bridge 186:707f6e361f3e 172 }
Anna Bridge 186:707f6e361f3e 173
Anna Bridge 186:707f6e361f3e 174 /**
Anna Bridge 186:707f6e361f3e 175 * @brief Starts the watchdog specified.
Anna Bridge 186:707f6e361f3e 176 *
Anna Bridge 186:707f6e361f3e 177 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 178 *
Anna Bridge 186:707f6e361f3e 179 * @retval #E_NO_ERROR WDT2 started.
Anna Bridge 186:707f6e361f3e 180 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 181 */
Anna Bridge 186:707f6e361f3e 182 int WDT2_Start(uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 183
Anna Bridge 186:707f6e361f3e 184 /**
Anna Bridge 186:707f6e361f3e 185 * @brief Feeds the watchdog specified.
Anna Bridge 186:707f6e361f3e 186 *
Anna Bridge 186:707f6e361f3e 187 * @retval #E_NO_ERROR WDT2 reset successfully.
Anna Bridge 186:707f6e361f3e 188 */
Anna Bridge 186:707f6e361f3e 189 void WDT2_Reset(void);
Anna Bridge 186:707f6e361f3e 190
Anna Bridge 186:707f6e361f3e 191 /**
Anna Bridge 186:707f6e361f3e 192 * @brief Stops the WatchDog Timer 2.
Anna Bridge 186:707f6e361f3e 193 *
Anna Bridge 186:707f6e361f3e 194 * @param unlock_key Key to unlock watchdog.
Anna Bridge 186:707f6e361f3e 195 *
Anna Bridge 186:707f6e361f3e 196 * @retval #E_NO_ERROR WDT2 stopped.
Anna Bridge 186:707f6e361f3e 197 * @retval #E_BAD_STATE Invalid unlock_key, WDT2 failed to unlock.
Anna Bridge 186:707f6e361f3e 198 */
Anna Bridge 186:707f6e361f3e 199 int WDT2_Stop(uint8_t unlock_key);
Anna Bridge 186:707f6e361f3e 200
Anna Bridge 186:707f6e361f3e 201 /**
Anna Bridge 186:707f6e361f3e 202 * @brief Determines if the watchdog is running
Anna Bridge 186:707f6e361f3e 203 *
Anna Bridge 186:707f6e361f3e 204 * @retval 0 Inactive
Anna Bridge 186:707f6e361f3e 205 * @retval non-zero Active
Anna Bridge 186:707f6e361f3e 206 */
Anna Bridge 186:707f6e361f3e 207 __STATIC_INLINE int WDT2_IsActive(void)
Anna Bridge 186:707f6e361f3e 208 {
Anna Bridge 186:707f6e361f3e 209 return (!!(MXC_WDT2->ctrl & MXC_F_WDT2_CTRL_EN_TIMER));
Anna Bridge 186:707f6e361f3e 210 }
Anna Bridge 186:707f6e361f3e 211
Anna Bridge 186:707f6e361f3e 212 /**@} end of group wdt2*/
Anna Bridge 186:707f6e361f3e 213
Anna Bridge 186:707f6e361f3e 214 #ifdef __cplusplus
Anna Bridge 186:707f6e361f3e 215 }
Anna Bridge 186:707f6e361f3e 216 #endif
Anna Bridge 186:707f6e361f3e 217
Anna Bridge 186:707f6e361f3e 218 #endif /* _WDT_H */