version_2.0

Dependents:   cc3000_ping_demo_try_2

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 #ifndef __FSL_PIT_HAL_H__
bogdanm 82:6473597d706e 31 #define __FSL_PIT_HAL_H__
bogdanm 82:6473597d706e 32
bogdanm 82:6473597d706e 33 #include <assert.h>
bogdanm 82:6473597d706e 34 #include <stdint.h>
bogdanm 82:6473597d706e 35 #include <stdbool.h>
bogdanm 82:6473597d706e 36 #include "fsl_pit_features.h"
bogdanm 82:6473597d706e 37 #include "fsl_device_registers.h"
bogdanm 82:6473597d706e 38
bogdanm 82:6473597d706e 39 /*!
bogdanm 82:6473597d706e 40 * @addtogroup pit_hal
bogdanm 82:6473597d706e 41 * @{
bogdanm 82:6473597d706e 42 */
bogdanm 82:6473597d706e 43
bogdanm 82:6473597d706e 44 /*******************************************************************************
bogdanm 82:6473597d706e 45 * API
bogdanm 82:6473597d706e 46 ******************************************************************************/
bogdanm 82:6473597d706e 47
bogdanm 82:6473597d706e 48 #if defined(__cplusplus)
bogdanm 82:6473597d706e 49 extern "C" {
bogdanm 82:6473597d706e 50 #endif
bogdanm 82:6473597d706e 51
bogdanm 82:6473597d706e 52 /*!
bogdanm 82:6473597d706e 53 * @name Initialization
bogdanm 82:6473597d706e 54 * @{
bogdanm 82:6473597d706e 55 */
bogdanm 82:6473597d706e 56
bogdanm 82:6473597d706e 57 /*!
bogdanm 82:6473597d706e 58 * @brief Enables the PIT module.
bogdanm 82:6473597d706e 59 *
bogdanm 82:6473597d706e 60 * This function enables the PIT timer clock (Note: this function does not un-gate
bogdanm 82:6473597d706e 61 * the system clock gating control). It should be called before any other timer
bogdanm 82:6473597d706e 62 * related setup.
bogdanm 82:6473597d706e 63 */
bogdanm 82:6473597d706e 64 static inline void pit_hal_enable(void)
bogdanm 82:6473597d706e 65 {
bogdanm 82:6473597d706e 66 BW_PIT_MCR_MDIS(0U);
bogdanm 82:6473597d706e 67 }
bogdanm 82:6473597d706e 68
bogdanm 82:6473597d706e 69 /*!
bogdanm 82:6473597d706e 70 * @brief Disables the PIT module.
bogdanm 82:6473597d706e 71 *
bogdanm 82:6473597d706e 72 * This function disables all PIT timer clocks(Note: it does not affect the
bogdanm 82:6473597d706e 73 * SIM clock gating control).
bogdanm 82:6473597d706e 74 */
bogdanm 82:6473597d706e 75 static inline void pit_hal_disable(void)
bogdanm 82:6473597d706e 76 {
bogdanm 82:6473597d706e 77 BW_PIT_MCR_MDIS(1U);
bogdanm 82:6473597d706e 78 }
bogdanm 82:6473597d706e 79
bogdanm 82:6473597d706e 80 /*!
bogdanm 82:6473597d706e 81 * @brief Configures the timers to continue running or stop in debug mode.
bogdanm 82:6473597d706e 82 *
bogdanm 82:6473597d706e 83 * In debug mode, the timers may or may not be frozen, based on the configuration of
bogdanm 82:6473597d706e 84 * this function. This is intended to aid software development, allowing the developer
bogdanm 82:6473597d706e 85 * to halt the processor, investigate the current state of the system (for example,
bogdanm 82:6473597d706e 86 * the timer values), and continue the operation.
bogdanm 82:6473597d706e 87 *
bogdanm 82:6473597d706e 88 * @param timerRun Timers run or stop in debug mode.
bogdanm 82:6473597d706e 89 * - true: Timers continue to run in debug mode.
bogdanm 82:6473597d706e 90 * - false: Timers stop in debug mode.
bogdanm 82:6473597d706e 91 */
bogdanm 82:6473597d706e 92 static inline void pit_hal_configure_timer_run_in_debug(bool timerRun)
bogdanm 82:6473597d706e 93 {
bogdanm 82:6473597d706e 94 BW_PIT_MCR_FRZ(!timerRun);
bogdanm 82:6473597d706e 95 }
bogdanm 82:6473597d706e 96
bogdanm 82:6473597d706e 97 #if FSL_FEATURE_PIT_HAS_CHAIN_MODE
bogdanm 82:6473597d706e 98 /*!
bogdanm 82:6473597d706e 99 * @brief Enables or disables the timer chain with the previous timer.
bogdanm 82:6473597d706e 100 *
bogdanm 82:6473597d706e 101 * When a timer has a chain mode enabled, it only counts after the previous
bogdanm 82:6473597d706e 102 * timer has expired. If the timer n-1 has counted down to 0, counter n
bogdanm 82:6473597d706e 103 * decrements the value by one. This allows the developers to chain timers together
bogdanm 82:6473597d706e 104 * and form a longer timer. The first timer (timer 0) cannot be chained to any
bogdanm 82:6473597d706e 105 * other timer.
bogdanm 82:6473597d706e 106 *
bogdanm 82:6473597d706e 107 * @param timer Timer channel number which is chained with the previous timer.
bogdanm 82:6473597d706e 108 * @param enable Enable or disable chain.
bogdanm 82:6473597d706e 109 * - true: Current timer is chained with the previous timer.
bogdanm 82:6473597d706e 110 * - false: Timer doesn't chain with other timers.
bogdanm 82:6473597d706e 111 */
bogdanm 82:6473597d706e 112 static inline void pit_hal_configure_timer_chain(uint32_t timer, bool enable)
bogdanm 82:6473597d706e 113 {
bogdanm 82:6473597d706e 114 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 115 BW_PIT_TCTRLn_CHN(timer, enable);
bogdanm 82:6473597d706e 116 }
bogdanm 82:6473597d706e 117
bogdanm 82:6473597d706e 118 #endif /* FSL_FEATURE_PIT_HAS_CHAIN_MODE*/
bogdanm 82:6473597d706e 119
bogdanm 82:6473597d706e 120 /* @} */
bogdanm 82:6473597d706e 121
bogdanm 82:6473597d706e 122 /*!
bogdanm 82:6473597d706e 123 * @name Timer Start and Stop
bogdanm 82:6473597d706e 124 * @{
bogdanm 82:6473597d706e 125 */
bogdanm 82:6473597d706e 126
bogdanm 82:6473597d706e 127 /*!
bogdanm 82:6473597d706e 128 * @brief Starts the timer counting.
bogdanm 82:6473597d706e 129 *
bogdanm 82:6473597d706e 130 * After calling this function, timers load the start value as specified by the function
bogdanm 82:6473597d706e 131 * pit_hal_set_timer_period_count(uint32_t timer, uint32_t count), count down to
bogdanm 82:6473597d706e 132 * 0, and load the respective start value again. Each time a timer reaches 0,
bogdanm 82:6473597d706e 133 * it generates a trigger pulse and sets the time-out interrupt flag.
bogdanm 82:6473597d706e 134 *
bogdanm 82:6473597d706e 135 * @param timer Timer channel number
bogdanm 82:6473597d706e 136 */
bogdanm 82:6473597d706e 137 static inline void pit_hal_timer_start(uint32_t timer)
bogdanm 82:6473597d706e 138 {
bogdanm 82:6473597d706e 139 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 140 BW_PIT_TCTRLn_TEN(timer, 1U);
bogdanm 82:6473597d706e 141 }
bogdanm 82:6473597d706e 142
bogdanm 82:6473597d706e 143 /*!
bogdanm 82:6473597d706e 144 * @brief Stops the timer from counting.
bogdanm 82:6473597d706e 145 *
bogdanm 82:6473597d706e 146 * This function stops every timer from counting. Timers reload their periods
bogdanm 82:6473597d706e 147 * respectively after they call the pit_hal_timer_start the next time.
bogdanm 82:6473597d706e 148 *
bogdanm 82:6473597d706e 149 * @param timer Timer channel number
bogdanm 82:6473597d706e 150 */
bogdanm 82:6473597d706e 151 static inline void pit_hal_timer_stop(uint32_t timer)
bogdanm 82:6473597d706e 152 {
bogdanm 82:6473597d706e 153 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 154 BW_PIT_TCTRLn_TEN(timer, 0U);
bogdanm 82:6473597d706e 155 }
bogdanm 82:6473597d706e 156
bogdanm 82:6473597d706e 157 /*!
bogdanm 82:6473597d706e 158 * @brief Checks to see whether the current timer is started or not.
bogdanm 82:6473597d706e 159 *
bogdanm 82:6473597d706e 160 * @param timer Timer channel number
bogdanm 82:6473597d706e 161 * @return Current timer running status
bogdanm 82:6473597d706e 162 * -true: Current timer is running.
bogdanm 82:6473597d706e 163 * -false: Current timer has stopped.
bogdanm 82:6473597d706e 164 */
bogdanm 82:6473597d706e 165 static inline bool pit_hal_is_timer_started(uint32_t timer)
bogdanm 82:6473597d706e 166 {
bogdanm 82:6473597d706e 167 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 168 return BR_PIT_TCTRLn_TEN(timer);
bogdanm 82:6473597d706e 169 }
bogdanm 82:6473597d706e 170
bogdanm 82:6473597d706e 171 /* @} */
bogdanm 82:6473597d706e 172
bogdanm 82:6473597d706e 173 /*!
bogdanm 82:6473597d706e 174 * @name Timer Period
bogdanm 82:6473597d706e 175 * @{
bogdanm 82:6473597d706e 176 */
bogdanm 82:6473597d706e 177
bogdanm 82:6473597d706e 178 /*!
bogdanm 82:6473597d706e 179 * @brief Sets the timer period in units of count.
bogdanm 82:6473597d706e 180 *
bogdanm 82:6473597d706e 181 * Timers begin counting from the value set by this function.
bogdanm 82:6473597d706e 182 * The counter period of a running timer can be modified by first stopping
bogdanm 82:6473597d706e 183 * the timer, setting a new load value, and starting the timer again. If
bogdanm 82:6473597d706e 184 * timers are not restarted, the new value is loaded after the next trigger
bogdanm 82:6473597d706e 185 * event.
bogdanm 82:6473597d706e 186 *
bogdanm 82:6473597d706e 187 * @param timer Timer channel number
bogdanm 82:6473597d706e 188 * @param count Timer period in units of count
bogdanm 82:6473597d706e 189 */
bogdanm 82:6473597d706e 190 static inline void pit_hal_set_timer_period_count(uint32_t timer, uint32_t count)
bogdanm 82:6473597d706e 191 {
bogdanm 82:6473597d706e 192 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 193 HW_PIT_LDVALn_WR(timer, count);
bogdanm 82:6473597d706e 194 }
bogdanm 82:6473597d706e 195
bogdanm 82:6473597d706e 196 /*!
bogdanm 82:6473597d706e 197 * @brief Returns the current timer period in units of count.
bogdanm 82:6473597d706e 198 *
bogdanm 82:6473597d706e 199 * @param timer Timer channel number
bogdanm 82:6473597d706e 200 * @return Timer period in units of count
bogdanm 82:6473597d706e 201 */
bogdanm 82:6473597d706e 202 static inline uint32_t pit_hal_read_timer_period_count(uint32_t timer)
bogdanm 82:6473597d706e 203 {
bogdanm 82:6473597d706e 204 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 205 return HW_PIT_LDVALn_RD(timer);
bogdanm 82:6473597d706e 206 }
bogdanm 82:6473597d706e 207
bogdanm 82:6473597d706e 208 /*!
bogdanm 82:6473597d706e 209 * @brief Reads the current timer counting value.
bogdanm 82:6473597d706e 210 *
bogdanm 82:6473597d706e 211 * This function returns the real-time timer counting value, in a range from 0 to a
bogdanm 82:6473597d706e 212 * timer period.
bogdanm 82:6473597d706e 213 *
bogdanm 82:6473597d706e 214 * @param timer Timer channel number
bogdanm 82:6473597d706e 215 * @return Current timer counting value
bogdanm 82:6473597d706e 216 */
bogdanm 82:6473597d706e 217 static inline uint32_t pit_hal_read_timer_count(uint32_t timer)
bogdanm 82:6473597d706e 218 {
bogdanm 82:6473597d706e 219 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 220 return HW_PIT_CVALn_RD(timer);
bogdanm 82:6473597d706e 221 }
bogdanm 82:6473597d706e 222
bogdanm 82:6473597d706e 223 #if FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
bogdanm 82:6473597d706e 224 /*!
bogdanm 82:6473597d706e 225 * @brief Reads the current lifetime counter value.
bogdanm 82:6473597d706e 226 *
bogdanm 82:6473597d706e 227 * The lifetime timer is a 64-bit timer which chains timer 0 and timer 1 together.
bogdanm 82:6473597d706e 228 * Timer 0 and 1 are chained by calling the pit_hal_configure_timer_chain
bogdanm 82:6473597d706e 229 * before using this timer. The period of lifetime timer is equal to the "period of
bogdanm 82:6473597d706e 230 * timer 0 * period of timer 1". For the 64-bit value, the higher 32-bit has
bogdanm 82:6473597d706e 231 * the value of timer 1, and the lower 32-bit has the value of timer 0.
bogdanm 82:6473597d706e 232 *
bogdanm 82:6473597d706e 233 * @return Current lifetime timer value
bogdanm 82:6473597d706e 234 */
bogdanm 82:6473597d706e 235 uint64_t pit_hal_read_lifetime_timer_count(void);
bogdanm 82:6473597d706e 236 #endif /*FSL_FEATURE_PIT_HAS_LIFETIME_TIMER*/
bogdanm 82:6473597d706e 237
bogdanm 82:6473597d706e 238 /* @} */
bogdanm 82:6473597d706e 239
bogdanm 82:6473597d706e 240 /*!
bogdanm 82:6473597d706e 241 * @name Interrupt
bogdanm 82:6473597d706e 242 * @{
bogdanm 82:6473597d706e 243 */
bogdanm 82:6473597d706e 244
bogdanm 82:6473597d706e 245 /*!
bogdanm 82:6473597d706e 246 * @brief Enables or disables the timer interrupt.
bogdanm 82:6473597d706e 247 *
bogdanm 82:6473597d706e 248 * If enabled, an interrupt happens when a timeout event occurs
bogdanm 82:6473597d706e 249 * (Note: NVIC should be called to enable pit interrupt in system level).
bogdanm 82:6473597d706e 250 *
bogdanm 82:6473597d706e 251 * @param timer Timer channel number
bogdanm 82:6473597d706e 252 * @param enable Enable or disable interrupt.
bogdanm 82:6473597d706e 253 * - true: Generate interrupt when timer counts to 0.
bogdanm 82:6473597d706e 254 * - false: No interrupt is generated.
bogdanm 82:6473597d706e 255 */
bogdanm 82:6473597d706e 256 static inline void pit_hal_configure_interrupt(uint32_t timer, bool enable)
bogdanm 82:6473597d706e 257 {
bogdanm 82:6473597d706e 258 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 259 BW_PIT_TCTRLn_TIE(timer, enable);
bogdanm 82:6473597d706e 260 }
bogdanm 82:6473597d706e 261
bogdanm 82:6473597d706e 262 /*!
bogdanm 82:6473597d706e 263 * @brief Checks whether the timer interrupt is enabled or not.
bogdanm 82:6473597d706e 264 *
bogdanm 82:6473597d706e 265 * @param timer Timer channel number
bogdanm 82:6473597d706e 266 * @return Status of enabled or disabled interrupt
bogdanm 82:6473597d706e 267 * - true: Interrupt is enabled.
bogdanm 82:6473597d706e 268 * - false: Interrupt is disabled.
bogdanm 82:6473597d706e 269 */
bogdanm 82:6473597d706e 270 static inline bool pit_hal_is_interrupt_enabled(uint32_t timer)
bogdanm 82:6473597d706e 271 {
bogdanm 82:6473597d706e 272 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 273 return BR_PIT_TCTRLn_TIE(timer);
bogdanm 82:6473597d706e 274 }
bogdanm 82:6473597d706e 275
bogdanm 82:6473597d706e 276 /*!
bogdanm 82:6473597d706e 277 * @brief Clears the timer interrupt flag.
bogdanm 82:6473597d706e 278 *
bogdanm 82:6473597d706e 279 * This function clears the timer interrupt flag after a timeout event
bogdanm 82:6473597d706e 280 * occurs.
bogdanm 82:6473597d706e 281 *
bogdanm 82:6473597d706e 282 * @param timer Timer channel number
bogdanm 82:6473597d706e 283 */
bogdanm 82:6473597d706e 284 static inline void pit_hal_clear_interrupt_flag(uint32_t timer)
bogdanm 82:6473597d706e 285 {
bogdanm 82:6473597d706e 286 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 287 /* Write 1 will clear the flag. */
bogdanm 82:6473597d706e 288 HW_PIT_TFLGn_WR(timer, 1U);
bogdanm 82:6473597d706e 289 }
bogdanm 82:6473597d706e 290
bogdanm 82:6473597d706e 291 /*!
bogdanm 82:6473597d706e 292 * @brief Reads the current timer timeout flag.
bogdanm 82:6473597d706e 293 *
bogdanm 82:6473597d706e 294 * Every time the timer counts to 0, this flag is set.
bogdanm 82:6473597d706e 295 *
bogdanm 82:6473597d706e 296 * @param timer Timer channel number
bogdanm 82:6473597d706e 297 * @return Current status of the timeout flag
bogdanm 82:6473597d706e 298 * - true: Timeout has occurred.
bogdanm 82:6473597d706e 299 * - false: Timeout has not yet occurred.
bogdanm 82:6473597d706e 300 */
bogdanm 82:6473597d706e 301 static inline bool pit_hal_is_timeout_occurred(uint32_t timer)
bogdanm 82:6473597d706e 302 {
bogdanm 82:6473597d706e 303 assert(timer < FSL_FEATURE_PIT_TIMER_COUNT);
bogdanm 82:6473597d706e 304 return HW_PIT_TFLGn_RD(timer);
bogdanm 82:6473597d706e 305 }
bogdanm 82:6473597d706e 306
bogdanm 82:6473597d706e 307 /* @} */
bogdanm 82:6473597d706e 308
bogdanm 82:6473597d706e 309 #if defined(__cplusplus)
bogdanm 82:6473597d706e 310 }
bogdanm 82:6473597d706e 311 #endif
bogdanm 82:6473597d706e 312
bogdanm 82:6473597d706e 313 /*! @}*/
bogdanm 82:6473597d706e 314
bogdanm 82:6473597d706e 315 #endif /* __FSL_PIT_HAL_H__*/
bogdanm 82:6473597d706e 316 /*******************************************************************************
bogdanm 82:6473597d706e 317 * EOF
bogdanm 82:6473597d706e 318 *******************************************************************************/
bogdanm 82:6473597d706e 319