/TARGET_K64F/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/adc/fsl_adc_hal.h substitute line 894 extern } by }

Fork of mbed by mbed official

Committer:
bogdanm
Date:
Mon Apr 07 18:28:36 2014 +0100
Revision:
82:6473597d706e
Release 82 of the mbed library

Main changes:

- support for K64F
- Revisited Nordic code structure
- Test infrastructure improvements
- various bug fixes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bogdanm 82:6473597d706e 1 /*
bogdanm 82:6473597d706e 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
bogdanm 82:6473597d706e 3 * All rights reserved.
bogdanm 82:6473597d706e 4 *
bogdanm 82:6473597d706e 5 * Redistribution and use in source and binary forms, with or without modification,
bogdanm 82:6473597d706e 6 * are permitted provided that the following conditions are met:
bogdanm 82:6473597d706e 7 *
bogdanm 82:6473597d706e 8 * o Redistributions of source code must retain the above copyright notice, this list
bogdanm 82:6473597d706e 9 * of conditions and the following disclaimer.
bogdanm 82:6473597d706e 10 *
bogdanm 82:6473597d706e 11 * o Redistributions in binary form must reproduce the above copyright notice, this
bogdanm 82:6473597d706e 12 * list of conditions and the following disclaimer in the documentation and/or
bogdanm 82:6473597d706e 13 * other materials provided with the distribution.
bogdanm 82:6473597d706e 14 *
bogdanm 82:6473597d706e 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
bogdanm 82:6473597d706e 16 * contributors may be used to endorse or promote products derived from this
bogdanm 82:6473597d706e 17 * software without specific prior written permission.
bogdanm 82:6473597d706e 18 *
bogdanm 82:6473597d706e 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
bogdanm 82:6473597d706e 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
bogdanm 82:6473597d706e 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
bogdanm 82:6473597d706e 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
bogdanm 82:6473597d706e 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
bogdanm 82:6473597d706e 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
bogdanm 82:6473597d706e 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
bogdanm 82:6473597d706e 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
bogdanm 82:6473597d706e 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
bogdanm 82:6473597d706e 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
bogdanm 82:6473597d706e 29 */
bogdanm 82:6473597d706e 30 #if !defined(__FSL_RTC_HAL_MONOTONIC_H__)
bogdanm 82:6473597d706e 31 #define __FSL_RTC_HAL_MONOTONIC_H__
bogdanm 82:6473597d706e 32
bogdanm 82:6473597d706e 33
bogdanm 82:6473597d706e 34 #include "fsl_rtc_features.h"
bogdanm 82:6473597d706e 35 #include "device/fsl_device_registers.h"
bogdanm 82:6473597d706e 36 #include <stdint.h>
bogdanm 82:6473597d706e 37 #include <stdbool.h>
bogdanm 82:6473597d706e 38
bogdanm 82:6473597d706e 39
bogdanm 82:6473597d706e 40
bogdanm 82:6473597d706e 41 /*! @addtogroup rtc_hal*/
bogdanm 82:6473597d706e 42 /*! @{*/
bogdanm 82:6473597d706e 43
bogdanm 82:6473597d706e 44
bogdanm 82:6473597d706e 45 /*******************************************************************************
bogdanm 82:6473597d706e 46 * Definitions
bogdanm 82:6473597d706e 47 ******************************************************************************/
bogdanm 82:6473597d706e 48
bogdanm 82:6473597d706e 49
bogdanm 82:6473597d706e 50
bogdanm 82:6473597d706e 51 /*******************************************************************************
bogdanm 82:6473597d706e 52 * API
bogdanm 82:6473597d706e 53 ******************************************************************************/
bogdanm 82:6473597d706e 54
bogdanm 82:6473597d706e 55 #if FSL_FEATURE_RTC_HAS_MONOTONIC
bogdanm 82:6473597d706e 56
bogdanm 82:6473597d706e 57 #if defined(__cplusplus)
bogdanm 82:6473597d706e 58 extern "C" {
bogdanm 82:6473597d706e 59 #endif
bogdanm 82:6473597d706e 60
bogdanm 82:6473597d706e 61
bogdanm 82:6473597d706e 62 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 63 /* RTC Monotonic Counter Register Reset Functions*/
bogdanm 82:6473597d706e 64 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 65
bogdanm 82:6473597d706e 66 /*! @brief Resets the RTC Monotonic Enable Register (RTC_MER).*/
bogdanm 82:6473597d706e 67 static inline void rtc_hal_reset_reg_MER(void)
bogdanm 82:6473597d706e 68 {
bogdanm 82:6473597d706e 69 HW_RTC_MER_WR((uint32_t)0x00000000U);
bogdanm 82:6473597d706e 70 }
bogdanm 82:6473597d706e 71
bogdanm 82:6473597d706e 72 /*! @brief Resets the RTC Monotonic Counter Low Register (RTC_MCLR).*/
bogdanm 82:6473597d706e 73 static inline void rtc_hal_reset_reg_MCLR(void)
bogdanm 82:6473597d706e 74 {
bogdanm 82:6473597d706e 75 HW_RTC_MCLR_WR((uint32_t)0x00000000U);
bogdanm 82:6473597d706e 76 }
bogdanm 82:6473597d706e 77
bogdanm 82:6473597d706e 78 /*! @brief Resets the RTC Monotonic Counter High Register (RTC_MCHR).*/
bogdanm 82:6473597d706e 79 static inline void rtc_hal_reset_reg_MCHR(void)
bogdanm 82:6473597d706e 80 {
bogdanm 82:6473597d706e 81 HW_RTC_MCHR_WR((uint32_t)0x00000000U);
bogdanm 82:6473597d706e 82 }
bogdanm 82:6473597d706e 83
bogdanm 82:6473597d706e 84 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 85 /* RTC Monotonic Enable*/
bogdanm 82:6473597d706e 86 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 87
bogdanm 82:6473597d706e 88 /*! @brief For the monotonic counter reads the mode writing.
bogdanm 82:6473597d706e 89 * @return true: Enables writing to the monotonic counter increment the counter.
bogdanm 82:6473597d706e 90 * false: Enables writing to the monotonic counter load the counter with the
bogdanm 82:6473597d706e 91 * value written.
bogdanm 82:6473597d706e 92 */
bogdanm 82:6473597d706e 93 static inline bool rtc_hal_read_monotonic_enable(void)
bogdanm 82:6473597d706e 94 {
bogdanm 82:6473597d706e 95 /* reads the value of the RTC Monotonic Enable Register (RTC_MER), field
bogdanm 82:6473597d706e 96 * Monotonic Counter Enable (MCE). */
bogdanm 82:6473597d706e 97 return (bool)BR_RTC_MER_MCE;
bogdanm 82:6473597d706e 98 }
bogdanm 82:6473597d706e 99
bogdanm 82:6473597d706e 100 /*! @brief Changes the state of the Monotonic Counter Enable.
bogdanm 82:6473597d706e 101 * @param enable true: Writes to the monotonic counter increment the counter.
bogdanm 82:6473597d706e 102 * false: Writes to the monotonic counter load the counter with the
bogdanm 82:6473597d706e 103 * value written.
bogdanm 82:6473597d706e 104 */
bogdanm 82:6473597d706e 105 static inline void rtc_hal_config_monotonic_enable(bool enable)
bogdanm 82:6473597d706e 106 {
bogdanm 82:6473597d706e 107 /* writes to the RTC Monotonic Enable Register (RTC_MER), field Monotonic
bogdanm 82:6473597d706e 108 * Counter Enable (MCE).*/
bogdanm 82:6473597d706e 109 BW_RTC_MER_MCE((uint32_t) enable);
bogdanm 82:6473597d706e 110 }
bogdanm 82:6473597d706e 111
bogdanm 82:6473597d706e 112 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 113 /* RTC Monotonic Counter*/
bogdanm 82:6473597d706e 114 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 115
bogdanm 82:6473597d706e 116 /*! @brief Reads the values of the Monotonic Counter High and the Monotonic Counter
bogdanm 82:6473597d706e 117 * Low and returns them into a single value.
bogdanm 82:6473597d706e 118 * @param counter [out] pointer to variable where the value is stored.
bogdanm 82:6473597d706e 119 */
bogdanm 82:6473597d706e 120 static inline void rtc_hal_get_monotonic_counter(uint64_t * counter)
bogdanm 82:6473597d706e 121 {
bogdanm 82:6473597d706e 122 /* check for null pointer*/
bogdanm 82:6473597d706e 123 if(NULL == counter)
bogdanm 82:6473597d706e 124 {
bogdanm 82:6473597d706e 125 return;
bogdanm 82:6473597d706e 126 }
bogdanm 82:6473597d706e 127
bogdanm 82:6473597d706e 128 uint64_t tmpCountHigh = 0;
bogdanm 82:6473597d706e 129
bogdanm 82:6473597d706e 130 /* store in temporal variable to avoid compile warning*/
bogdanm 82:6473597d706e 131 tmpCountHigh = BR_RTC_MCHR_MCH;
bogdanm 82:6473597d706e 132
bogdanm 82:6473597d706e 133 *counter = (((uint64_t)(tmpCountHigh) << 32) | ((uint64_t)(BR_RTC_MCLR_MCL)));
bogdanm 82:6473597d706e 134 }
bogdanm 82:6473597d706e 135
bogdanm 82:6473597d706e 136 /*! @brief Writes values Monotonic Counter High and Monotonic Counter Low
bogdanm 82:6473597d706e 137 * by decomposing the given single value.
bogdanm 82:6473597d706e 138 * @param counter [in] pointer to the variable where the value is stored.
bogdanm 82:6473597d706e 139 */
bogdanm 82:6473597d706e 140 static inline void rtc_hal_set_monotonic_counter(const uint64_t * counter)
bogdanm 82:6473597d706e 141 {
bogdanm 82:6473597d706e 142 /* check for null pointer*/
bogdanm 82:6473597d706e 143 if(NULL == counter)
bogdanm 82:6473597d706e 144 {
bogdanm 82:6473597d706e 145 return;
bogdanm 82:6473597d706e 146 }
bogdanm 82:6473597d706e 147
bogdanm 82:6473597d706e 148 /* enable writing to the counter*/
bogdanm 82:6473597d706e 149 BW_RTC_MER_MCE(0U);
bogdanm 82:6473597d706e 150
bogdanm 82:6473597d706e 151 BW_RTC_MCLR_MCL((uint32_t)(*counter));
bogdanm 82:6473597d706e 152
bogdanm 82:6473597d706e 153 /* enable writing to the counter*/
bogdanm 82:6473597d706e 154 BW_RTC_MER_MCE(0U);
bogdanm 82:6473597d706e 155
bogdanm 82:6473597d706e 156 BW_RTC_MCHR_MCH((uint32_t)((*counter) >> 32));
bogdanm 82:6473597d706e 157 }
bogdanm 82:6473597d706e 158
bogdanm 82:6473597d706e 159 /*! @brief Increments one to the Monotonic Counter.*/
bogdanm 82:6473597d706e 160 /*! @return true: success; false: error, time invalid flag found.*/
bogdanm 82:6473597d706e 161 static inline bool rtc_hal_monotonic_counter_increment(void)
bogdanm 82:6473597d706e 162 {
bogdanm 82:6473597d706e 163 bool result = false;
bogdanm 82:6473597d706e 164
bogdanm 82:6473597d706e 165 /* Increments the Monotonic Counter (registers RTC_MCLR and RTC_MCHR
bogdanm 82:6473597d706e 166 * accordingly); by setting the monotonic counter enable (MER[MCE]) and then
bogdanm 82:6473597d706e 167 * writing to RTC_MCLR register. A write to monotonic counter low that causes
bogdanm 82:6473597d706e 168 * it to overflow also increments the monotonic counter high. */
bogdanm 82:6473597d706e 169
bogdanm 82:6473597d706e 170 if((!(BR_RTC_SR_TIF)) && (!(BR_RTC_SR_MOF)))
bogdanm 82:6473597d706e 171 {
bogdanm 82:6473597d706e 172 /* prepare for incrementing after write*/
bogdanm 82:6473597d706e 173 BW_RTC_MER_MCE(1U);
bogdanm 82:6473597d706e 174
bogdanm 82:6473597d706e 175 /* write anything so the counter increments*/
bogdanm 82:6473597d706e 176 BW_RTC_MCLR_MCL(1U);
bogdanm 82:6473597d706e 177
bogdanm 82:6473597d706e 178 result = true;
bogdanm 82:6473597d706e 179 }
bogdanm 82:6473597d706e 180
bogdanm 82:6473597d706e 181 return result;
bogdanm 82:6473597d706e 182 }
bogdanm 82:6473597d706e 183
bogdanm 82:6473597d706e 184 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 185 /* RTC Status*/
bogdanm 82:6473597d706e 186 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 187
bogdanm 82:6473597d706e 188 /*! @brief Reads the value of the Monotonic Overflow Flag (MOF). This flag is
bogdanm 82:6473597d706e 189 * set when the monotonic counter is enabled and the monotonic
bogdanm 82:6473597d706e 190 * counter high overflows. The monotonic counter does not increment
bogdanm 82:6473597d706e 191 * and reads as zero when this bit is set. This bit is cleared
bogdanm 82:6473597d706e 192 * by writing the monotonic counter high register when the monotonic
bogdanm 82:6473597d706e 193 * counter is disabled.
bogdanm 82:6473597d706e 194 * @return true: monotonic counter overflow has occurred and monotonic
bogdanm 82:6473597d706e 195 counter is read as zero.
bogdanm 82:6473597d706e 196 * false: NO monotonic counter overflow has occurred.
bogdanm 82:6473597d706e 197 */
bogdanm 82:6473597d706e 198 static inline bool rtc_hal_is_monotonic_counter_overflow(void)
bogdanm 82:6473597d706e 199 {
bogdanm 82:6473597d706e 200 return (bool)BR_RTC_SR_MOF;
bogdanm 82:6473597d706e 201 }
bogdanm 82:6473597d706e 202
bogdanm 82:6473597d706e 203 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 204 /* RTC Lock*/
bogdanm 82:6473597d706e 205 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 206
bogdanm 82:6473597d706e 207 /*! @brief Reads the value of the Monotonic Counter High Lock.
bogdanm 82:6473597d706e 208 * @return true: Monotonic counter high register is not locked and writes
bogdanm 82:6473597d706e 209 * complete normally.
bogdanm 82:6473597d706e 210 * false: Monotonic counter high register is locked and writes are
bogdanm 82:6473597d706e 211 * ignored.
bogdanm 82:6473597d706e 212 */
bogdanm 82:6473597d706e 213 static inline bool rtc_hal_read_monotonic_hcounter_lock(void)
bogdanm 82:6473597d706e 214 {
bogdanm 82:6473597d706e 215 /* Reads the RTC Lock Register (RTC_LR), field Monotonic Counter High Lock
bogdanm 82:6473597d706e 216 * (MCHL). */
bogdanm 82:6473597d706e 217 return (bool)BR_RTC_LR_MCHL;
bogdanm 82:6473597d706e 218 }
bogdanm 82:6473597d706e 219
bogdanm 82:6473597d706e 220 /*! @brief Clears the Monotonic Counter High Lock. Once done, this
bogdanm 82:6473597d706e 221 * flag can only be set by VBAT POR orthe software reset.
bogdanm 82:6473597d706e 222 */
bogdanm 82:6473597d706e 223 static inline void rtc_hal_clear_monotonic_hcounter_lock(void)
bogdanm 82:6473597d706e 224 {
bogdanm 82:6473597d706e 225 /* Writes 0 to the RTC Lock Register (RTC_LR), field Monotonic Counter High Lock
bogdanm 82:6473597d706e 226 * (MCHL). Once cleared, this flag can only be set by VBAT POR or software
bogdanm 82:6473597d706e 227 * reset. */
bogdanm 82:6473597d706e 228 BW_RTC_LR_MCHL(0U);
bogdanm 82:6473597d706e 229 }
bogdanm 82:6473597d706e 230
bogdanm 82:6473597d706e 231 /*! @brief Reads the value of the Monotonic Counter Low Lock.
bogdanm 82:6473597d706e 232 * @return true: Monotonic counter low register is not locked and writes
bogdanm 82:6473597d706e 233 * complete normally.
bogdanm 82:6473597d706e 234 * false: Monotonic counter low register is locked and writes are
bogdanm 82:6473597d706e 235 * ignored.
bogdanm 82:6473597d706e 236 */
bogdanm 82:6473597d706e 237 static inline bool rtc_hal_read_lcounter_lock(void)
bogdanm 82:6473597d706e 238 {
bogdanm 82:6473597d706e 239 /* Reads the value of the RTC Lock Register (RTC_LR), field Monotonic Counter
bogdanm 82:6473597d706e 240 * Low Lock (MCLL). */
bogdanm 82:6473597d706e 241 return (bool)BR_RTC_LR_MCLL;
bogdanm 82:6473597d706e 242 }
bogdanm 82:6473597d706e 243
bogdanm 82:6473597d706e 244 /*! @brief Clears the Monotonic Counter Low Lock. Once done, this flag
bogdanm 82:6473597d706e 245 * can only be set by the VBAT POR or the software reset.
bogdanm 82:6473597d706e 246 */
bogdanm 82:6473597d706e 247 static inline void rtc_hal_clear_lcounter_lock(bool set_to)
bogdanm 82:6473597d706e 248 {
bogdanm 82:6473597d706e 249 BW_RTC_LR_MCLL(0U);
bogdanm 82:6473597d706e 250 }
bogdanm 82:6473597d706e 251
bogdanm 82:6473597d706e 252 /*! @brief Reads the value of the Monotonic Enable Lock.
bogdanm 82:6473597d706e 253 * @return true: Monotonic enable register is not locked and writes
bogdanm 82:6473597d706e 254 * complete normally.
bogdanm 82:6473597d706e 255 * false: Monotonic enable register is locked and writes are
bogdanm 82:6473597d706e 256 * ignored.
bogdanm 82:6473597d706e 257 */
bogdanm 82:6473597d706e 258 static inline bool rtc_hal_read_monotonic_enable_lock(void)
bogdanm 82:6473597d706e 259 {
bogdanm 82:6473597d706e 260 /* Reads the value of the RTC Lock Register (RTC_LR), field Monotonic Enable
bogdanm 82:6473597d706e 261 * Lock (MEL). Once cleared, this flag can only be set by the VBAT POR or the software
bogdanm 82:6473597d706e 262 * reset. */
bogdanm 82:6473597d706e 263 return (bool)BR_RTC_LR_MEL;
bogdanm 82:6473597d706e 264 }
bogdanm 82:6473597d706e 265
bogdanm 82:6473597d706e 266 /*! @brief Clears the Monotonic Enable Lock. Once done, this flag can
bogdanm 82:6473597d706e 267 * only be set by the VBAT POR or the software reset.
bogdanm 82:6473597d706e 268 */
bogdanm 82:6473597d706e 269 static inline void rtc_hal_clear_monotonic_enable_lock(void)
bogdanm 82:6473597d706e 270 {
bogdanm 82:6473597d706e 271 /* Writes to the RTC Lock Register (RTC_LR), field Monotonic Enable Lock (MEL).
bogdanm 82:6473597d706e 272 * Once cleared, this flag can only be set by the VBAT POR or the software reset. */
bogdanm 82:6473597d706e 273 BW_RTC_LR_MEL(0U);
bogdanm 82:6473597d706e 274 }
bogdanm 82:6473597d706e 275
bogdanm 82:6473597d706e 276 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 277 /* RTC Interrupt Enable*/
bogdanm 82:6473597d706e 278 /*-------------------------------------------------------------------------------------------*/
bogdanm 82:6473597d706e 279
bogdanm 82:6473597d706e 280 /*! @brief Checks whether the Monotonic Overflow Interrupt is enabled/disabled.
bogdanm 82:6473597d706e 281 * @return true: Monotonic overflow flag generates an interrupt.
bogdanm 82:6473597d706e 282 * false: Monotonic overflow flag does not generate an interrupt.
bogdanm 82:6473597d706e 283 */
bogdanm 82:6473597d706e 284 static inline bool rtc_hal_read_monot_overflow_int_enable(void)
bogdanm 82:6473597d706e 285 {
bogdanm 82:6473597d706e 286 /* Reads the value of the RTC Interrupt Enable Register (RTC_IER), field
bogdanm 82:6473597d706e 287 * Monotonic Overflow Interrupt Enable (MOIE). */
bogdanm 82:6473597d706e 288 return (bool)BR_RTC_IER_MOIE;
bogdanm 82:6473597d706e 289 }
bogdanm 82:6473597d706e 290
bogdanm 82:6473597d706e 291 /*! @brief Enables/disables the Monotonic Overflow Interrupt Enable.
bogdanm 82:6473597d706e 292 * @param enable true: Monotonic overflow flag generates an interrupt.
bogdanm 82:6473597d706e 293 * false: Monotonic overflow flag does not generate an interrupt.
bogdanm 82:6473597d706e 294 */
bogdanm 82:6473597d706e 295 static inline void rtc_hal_config_monot_overflow_int_enable(bool enable)
bogdanm 82:6473597d706e 296 {
bogdanm 82:6473597d706e 297 BW_RTC_IER_MOIE((uint32_t) enable);
bogdanm 82:6473597d706e 298 }
bogdanm 82:6473597d706e 299
bogdanm 82:6473597d706e 300
bogdanm 82:6473597d706e 301 #if defined(__cplusplus)
bogdanm 82:6473597d706e 302 }
bogdanm 82:6473597d706e 303 #endif
bogdanm 82:6473597d706e 304
bogdanm 82:6473597d706e 305 #endif
bogdanm 82:6473597d706e 306
bogdanm 82:6473597d706e 307 /*! @}*/
bogdanm 82:6473597d706e 308
bogdanm 82:6473597d706e 309 #endif /* __FSL_RTC_HAL_MONOTONIC_H__*/
bogdanm 82:6473597d706e 310
bogdanm 82:6473597d706e 311 /*******************************************************************************
bogdanm 82:6473597d706e 312 * EOF
bogdanm 82:6473597d706e 313 ******************************************************************************/