cc y / mbed

Fork of mbed by mbed official

Committer:
kaoshen
Date:
Tue Jan 17 23:27:32 2017 +0000
Revision:
135:fce8a9387ed1
Parent:
129:0ab6a29f35bf
333 ADS1115 ADC1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 129:0ab6a29f35bf 1 /*******************************************************************************
<> 129:0ab6a29f35bf 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
<> 129:0ab6a29f35bf 3 *
<> 129:0ab6a29f35bf 4 * Permission is hereby granted, free of charge, to any person obtaining a
<> 129:0ab6a29f35bf 5 * copy of this software and associated documentation files (the "Software"),
<> 129:0ab6a29f35bf 6 * to deal in the Software without restriction, including without limitation
<> 129:0ab6a29f35bf 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
<> 129:0ab6a29f35bf 8 * and/or sell copies of the Software, and to permit persons to whom the
<> 129:0ab6a29f35bf 9 * Software is furnished to do so, subject to the following conditions:
<> 129:0ab6a29f35bf 10 *
<> 129:0ab6a29f35bf 11 * The above copyright notice and this permission notice shall be included
<> 129:0ab6a29f35bf 12 * in all copies or substantial portions of the Software.
<> 129:0ab6a29f35bf 13 *
<> 129:0ab6a29f35bf 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
<> 129:0ab6a29f35bf 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
<> 129:0ab6a29f35bf 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
<> 129:0ab6a29f35bf 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
<> 129:0ab6a29f35bf 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
<> 129:0ab6a29f35bf 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
<> 129:0ab6a29f35bf 20 * OTHER DEALINGS IN THE SOFTWARE.
<> 129:0ab6a29f35bf 21 *
<> 129:0ab6a29f35bf 22 * Except as contained in this notice, the name of Maxim Integrated
<> 129:0ab6a29f35bf 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
<> 129:0ab6a29f35bf 24 * Products, Inc. Branding Policy.
<> 129:0ab6a29f35bf 25 *
<> 129:0ab6a29f35bf 26 * The mere transfer of this software does not imply any licenses
<> 129:0ab6a29f35bf 27 * of trade secrets, proprietary technology, copyrights, patents,
<> 129:0ab6a29f35bf 28 * trademarks, maskwork rights, or any other form of intellectual
<> 129:0ab6a29f35bf 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
<> 129:0ab6a29f35bf 30 * ownership rights.
<> 129:0ab6a29f35bf 31 *
<> 129:0ab6a29f35bf 32 * $Date: 2016-03-21 15:44:11 -0500 (Mon, 21 Mar 2016) $
<> 129:0ab6a29f35bf 33 * $Revision: 22024 $
<> 129:0ab6a29f35bf 34 *
<> 129:0ab6a29f35bf 35 ******************************************************************************/
<> 129:0ab6a29f35bf 36
<> 129:0ab6a29f35bf 37 /**
<> 129:0ab6a29f35bf 38 * @file wdt.h
<> 129:0ab6a29f35bf 39 * @addtogroup wdt WDT
<> 129:0ab6a29f35bf 40 * @{
<> 129:0ab6a29f35bf 41 * @brief This is the high level API for the watchdog timer interface module
<> 129:0ab6a29f35bf 42 *
<> 129:0ab6a29f35bf 43 */
<> 129:0ab6a29f35bf 44
<> 129:0ab6a29f35bf 45 #ifndef _WDT_H
<> 129:0ab6a29f35bf 46 #define _WDT_H
<> 129:0ab6a29f35bf 47
<> 129:0ab6a29f35bf 48 #include "mxc_config.h"
<> 129:0ab6a29f35bf 49 #include "wdt_regs.h"
<> 129:0ab6a29f35bf 50 #include "mxc_assert.h"
<> 129:0ab6a29f35bf 51 #include "mxc_sys.h"
<> 129:0ab6a29f35bf 52
<> 129:0ab6a29f35bf 53 #ifdef __cplusplus
<> 129:0ab6a29f35bf 54 extern "C" {
<> 129:0ab6a29f35bf 55 #endif
<> 129:0ab6a29f35bf 56
<> 129:0ab6a29f35bf 57 #define WDT_FLAGS_CLEAR_ALL (MXC_F_WDT_FLAGS_TIMEOUT| \
<> 129:0ab6a29f35bf 58 MXC_F_WDT_FLAGS_PRE_WIN | \
<> 129:0ab6a29f35bf 59 MXC_F_WDT_FLAGS_RESET_OUT)
<> 129:0ab6a29f35bf 60 /** @enum wdt_period_t */
<> 129:0ab6a29f35bf 61 /** @brief Enumeration for the Watchdog Timer Period */
<> 129:0ab6a29f35bf 62 typedef enum {
<> 129:0ab6a29f35bf 63 WDT_PERIOD_2_31_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_31_CLKS, /**< 2^31 WDT clocks. */
<> 129:0ab6a29f35bf 64 WDT_PERIOD_2_30_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_30_CLKS, /**< 2^30 WDT clocks. */
<> 129:0ab6a29f35bf 65 WDT_PERIOD_2_29_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_29_CLKS, /**< 2^29 WDT clocks. */
<> 129:0ab6a29f35bf 66 WDT_PERIOD_2_28_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_28_CLKS, /**< 2^28 WDT clocks. */
<> 129:0ab6a29f35bf 67 WDT_PERIOD_2_27_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_27_CLKS, /**< 2^27 WDT clocks. */
<> 129:0ab6a29f35bf 68 WDT_PERIOD_2_26_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_26_CLKS, /**< 2^26 WDT clocks. */
<> 129:0ab6a29f35bf 69 WDT_PERIOD_2_25_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_25_CLKS, /**< 2^25 WDT clocks. */
<> 129:0ab6a29f35bf 70 WDT_PERIOD_2_24_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_24_CLKS, /**< 2^24 WDT clocks. */
<> 129:0ab6a29f35bf 71 WDT_PERIOD_2_23_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_23_CLKS, /**< 2^23 WDT clocks. */
<> 129:0ab6a29f35bf 72 WDT_PERIOD_2_22_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_22_CLKS, /**< 2^22 WDT clocks. */
<> 129:0ab6a29f35bf 73 WDT_PERIOD_2_21_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_21_CLKS, /**< 2^21 WDT clocks. */
<> 129:0ab6a29f35bf 74 WDT_PERIOD_2_20_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_20_CLKS, /**< 2^20 WDT clocks. */
<> 129:0ab6a29f35bf 75 WDT_PERIOD_2_19_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_19_CLKS, /**< 2^19 WDT clocks. */
<> 129:0ab6a29f35bf 76 WDT_PERIOD_2_18_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_18_CLKS, /**< 2^18 WDT clocks. */
<> 129:0ab6a29f35bf 77 WDT_PERIOD_2_17_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_17_CLKS, /**< 2^17 WDT clocks. */
<> 129:0ab6a29f35bf 78 WDT_PERIOD_2_16_CLKS = MXC_V_WDT_CTRL_INT_PERIOD_2_16_CLKS, /**< 2^16 WDT clocks. */
<> 129:0ab6a29f35bf 79 WDT_PERIOD_MAX /**< Maximum Period is Max - 1 */
<> 129:0ab6a29f35bf 80 } wdt_period_t;
<> 129:0ab6a29f35bf 81
<> 129:0ab6a29f35bf 82 /**
<> 129:0ab6a29f35bf 83 * @brief Initializes system level clocks and sets watchdog in a known disabled state
<> 129:0ab6a29f35bf 84 * @note The clk_scale in cfg is only used if the system clock is selected for clk.
<> 129:0ab6a29f35bf 85 *
<> 129:0ab6a29f35bf 86 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 87 * @param cfg Watchdog system configuration, see sys_cfg_wdt_t.
<> 129:0ab6a29f35bf 88 * @param unlock_key Watchdog unlock key
<> 129:0ab6a29f35bf 89 *
<> 129:0ab6a29f35bf 90 * @retval E_NO_ERROR Watchdog Timer initialized as requested
<> 129:0ab6a29f35bf 91 * @retval E_NULL_PTR NULL pointer for Watchdog Timer Instance or Configuration parameters.
<> 129:0ab6a29f35bf 92 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 93 */
<> 129:0ab6a29f35bf 94 int WDT_Init(mxc_wdt_regs_t *wdt, const sys_cfg_wdt_t *cfg, uint8_t unlock_key);
<> 129:0ab6a29f35bf 95
<> 129:0ab6a29f35bf 96 /**
<> 129:0ab6a29f35bf 97 * @brief Configures and enables the interrupt timeout for the watchdog specified.
<> 129:0ab6a29f35bf 98 *
<> 129:0ab6a29f35bf 99 * @param wdt Watchdog module to operate on
<> 129:0ab6a29f35bf 100 * @param int_period Interrupt period as defined by wdt_period_t.
<> 129:0ab6a29f35bf 101 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 102 *
<> 129:0ab6a29f35bf 103 * @retval E_NO_ERROR Interrupt enabled
<> 129:0ab6a29f35bf 104 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 105 */
<> 129:0ab6a29f35bf 106 int WDT_EnableInt(mxc_wdt_regs_t *wdt, wdt_period_t int_period, uint8_t unlock_key);
<> 129:0ab6a29f35bf 107
<> 129:0ab6a29f35bf 108 /**
<> 129:0ab6a29f35bf 109 * @brief Disables the interrupt timeout for the watchdog specified.
<> 129:0ab6a29f35bf 110 *
<> 129:0ab6a29f35bf 111 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 112 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 113 *
<> 129:0ab6a29f35bf 114 * @retval E_NO_ERROR Interrupt disabled.
<> 129:0ab6a29f35bf 115 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 116 */
<> 129:0ab6a29f35bf 117 int WDT_DisableInt(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
<> 129:0ab6a29f35bf 118
<> 129:0ab6a29f35bf 119 /**
<> 129:0ab6a29f35bf 120 * @brief Configures and enables the pre-window timeout for the watchdog specified.
<> 129:0ab6a29f35bf 121 *
<> 129:0ab6a29f35bf 122 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 123 * @param wait_period Pre-window period, see wdt_period_t for accepted values.
<> 129:0ab6a29f35bf 124 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 125 *
<> 129:0ab6a29f35bf 126 * @retval E_NO_ERROR Pre-window timeout set to wait_period
<> 129:0ab6a29f35bf 127 * @retval E_BAD_STATE WDT unable to be unlocked
<> 129:0ab6a29f35bf 128 * @retval E_INVALID Requested Period is greater than the maximum supported
<> 129:0ab6a29f35bf 129 */
<> 129:0ab6a29f35bf 130 int WDT_EnableWait(mxc_wdt_regs_t *wdt, wdt_period_t wait_period, uint8_t unlock_key);
<> 129:0ab6a29f35bf 131
<> 129:0ab6a29f35bf 132 /**
<> 129:0ab6a29f35bf 133 * @brief Disables the pre-window timeout for the watchdog specified.
<> 129:0ab6a29f35bf 134 *
<> 129:0ab6a29f35bf 135 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 136 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 137 *
<> 129:0ab6a29f35bf 138 * @retval E_NO_ERROR Wait disabled.
<> 129:0ab6a29f35bf 139 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 140 */
<> 129:0ab6a29f35bf 141 int WDT_DisableWait(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
<> 129:0ab6a29f35bf 142
<> 129:0ab6a29f35bf 143 /**
<> 129:0ab6a29f35bf 144 * @brief Configures and enables the reset timeout for the watchdog specified.
<> 129:0ab6a29f35bf 145 *
<> 129:0ab6a29f35bf 146 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 147 * @param rst_period Reset period, see wdt_period_t for accepted values.
<> 129:0ab6a29f35bf 148 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 149 *
<> 129:0ab6a29f35bf 150 * @retval E_NO_ERROR Watchdog Timer Reset enabled with the rst_period time.
<> 129:0ab6a29f35bf 151 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 152 * @retval E_INVALID Requested Period is greater than the maximum supported
<> 129:0ab6a29f35bf 153 */
<> 129:0ab6a29f35bf 154 int WDT_EnableReset(mxc_wdt_regs_t *wdt, wdt_period_t rst_period, uint8_t unlock_key);
<> 129:0ab6a29f35bf 155
<> 129:0ab6a29f35bf 156 /**
<> 129:0ab6a29f35bf 157 * @brief Disables the reset timeout for the watchdog specified.
<> 129:0ab6a29f35bf 158 *
<> 129:0ab6a29f35bf 159 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 160 * @param unlock_key Key to unlock watchdog. See MXC_WDT_UNLOCK_KEY.
<> 129:0ab6a29f35bf 161 *
<> 129:0ab6a29f35bf 162 * @retval E_NO_ERROR Reset disabled.
<> 129:0ab6a29f35bf 163 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 164 */
<> 129:0ab6a29f35bf 165 int WDT_DisableReset(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
<> 129:0ab6a29f35bf 166
<> 129:0ab6a29f35bf 167 /**
<> 129:0ab6a29f35bf 168 * @brief Gets the watchdog interrupt flags
<> 129:0ab6a29f35bf 169 *
<> 129:0ab6a29f35bf 170 * @param wdt Pointer to the Watchdog Timer Instance.
<> 129:0ab6a29f35bf 171 *
<> 129:0ab6a29f35bf 172 * @retval uint32_t Value of the Watchdog Timer Flags.
<> 129:0ab6a29f35bf 173 *
<> 129:0ab6a29f35bf 174 */
<> 129:0ab6a29f35bf 175 __STATIC_INLINE uint32_t WDT_GetFlags(mxc_wdt_regs_t *wdt)
<> 129:0ab6a29f35bf 176 {
<> 129:0ab6a29f35bf 177 return (wdt->flags);
<> 129:0ab6a29f35bf 178 }
<> 129:0ab6a29f35bf 179
<> 129:0ab6a29f35bf 180 /**
<> 129:0ab6a29f35bf 181 * @brief Clears the watchdog interrupt flags based on the mask
<> 129:0ab6a29f35bf 182 *
<> 129:0ab6a29f35bf 183 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 184 * @param mask Watchdog Flags to clear
<> 129:0ab6a29f35bf 185 *
<> 129:0ab6a29f35bf 186 */
<> 129:0ab6a29f35bf 187 __STATIC_INLINE void WDT_ClearFlags(mxc_wdt_regs_t *wdt, uint32_t mask)
<> 129:0ab6a29f35bf 188 {
<> 129:0ab6a29f35bf 189 wdt->flags = mask;
<> 129:0ab6a29f35bf 190 }
<> 129:0ab6a29f35bf 191
<> 129:0ab6a29f35bf 192 /**
<> 129:0ab6a29f35bf 193 * @brief Starts the specified Watchdog Timer instance.
<> 129:0ab6a29f35bf 194 *
<> 129:0ab6a29f35bf 195 * @param wdt Pointer to the Watchdog Timer instance
<> 129:0ab6a29f35bf 196 * @param unlock_key Key to unlock watchdog.
<> 129:0ab6a29f35bf 197 *
<> 129:0ab6a29f35bf 198 * @retval E_NO_ERROR Interrupt enabled.
<> 129:0ab6a29f35bf 199 * @retval E_BAD_STATE WDT2 Already Running
<> 129:0ab6a29f35bf 200 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 201 *
<> 129:0ab6a29f35bf 202 */
<> 129:0ab6a29f35bf 203 int WDT_Start(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
<> 129:0ab6a29f35bf 204
<> 129:0ab6a29f35bf 205 /**
<> 129:0ab6a29f35bf 206 * @brief Feeds the watchdog specified.
<> 129:0ab6a29f35bf 207 *
<> 129:0ab6a29f35bf 208 * @param wdt Watchdog module to operate on
<> 129:0ab6a29f35bf 209 *
<> 129:0ab6a29f35bf 210 */
<> 129:0ab6a29f35bf 211 void WDT_Reset(mxc_wdt_regs_t *wdt);
<> 129:0ab6a29f35bf 212
<> 129:0ab6a29f35bf 213 /**
<> 129:0ab6a29f35bf 214 * @brief Stops the watchdog specified.
<> 129:0ab6a29f35bf 215 *
<> 129:0ab6a29f35bf 216 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 217 * @param unlock_key Key to unlock watchdog.
<> 129:0ab6a29f35bf 218 *
<> 129:0ab6a29f35bf 219 * @retval E_NO_ERROR Interrupt enabled.
<> 129:0ab6a29f35bf 220 * @retval E_BAD_STATE Invalid unlock_key, WDT failed to unlock.
<> 129:0ab6a29f35bf 221 */
<> 129:0ab6a29f35bf 222 int WDT_Stop(mxc_wdt_regs_t *wdt, uint8_t unlock_key);
<> 129:0ab6a29f35bf 223
<> 129:0ab6a29f35bf 224 /**
<> 129:0ab6a29f35bf 225 * @brief Determines if the watchdog is running
<> 129:0ab6a29f35bf 226 *
<> 129:0ab6a29f35bf 227 * @param wdt Pointer to the Watchdog Timer Instance
<> 129:0ab6a29f35bf 228 *
<> 129:0ab6a29f35bf 229 * @retval 0 Watchdog timer is Disabled.
<> 129:0ab6a29f35bf 230 * @retval non-zero Watchdog timer is Active
<> 129:0ab6a29f35bf 231 */
<> 129:0ab6a29f35bf 232 __STATIC_INLINE int WDT_IsActive(mxc_wdt_regs_t *wdt)
<> 129:0ab6a29f35bf 233 {
<> 129:0ab6a29f35bf 234 return (!!(wdt->ctrl & MXC_F_WDT_CTRL_EN_TIMER));
<> 129:0ab6a29f35bf 235 }
<> 129:0ab6a29f35bf 236
<> 129:0ab6a29f35bf 237 /**
<> 129:0ab6a29f35bf 238 * @}
<> 129:0ab6a29f35bf 239 */
<> 129:0ab6a29f35bf 240
<> 129:0ab6a29f35bf 241 #ifdef __cplusplus
<> 129:0ab6a29f35bf 242 }
<> 129:0ab6a29f35bf 243 #endif
<> 129:0ab6a29f35bf 244
<> 129:0ab6a29f35bf 245 #endif /* _WDT_H */