The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
AnnaBridge
Date:
Wed Feb 20 20:53:29 2019 +0000
Revision:
172:65be27845400
Parent:
171:3a7713b1edbc
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 171:3a7713b1edbc 1 /*
AnnaBridge 171:3a7713b1edbc 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 171:3a7713b1edbc 3 * All rights reserved.
AnnaBridge 171:3a7713b1edbc 4 *
AnnaBridge 171:3a7713b1edbc 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 171:3a7713b1edbc 6 * are permitted provided that the following conditions are met:
AnnaBridge 171:3a7713b1edbc 7 *
AnnaBridge 171:3a7713b1edbc 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 171:3a7713b1edbc 9 * of conditions and the following disclaimer.
AnnaBridge 171:3a7713b1edbc 10 *
AnnaBridge 171:3a7713b1edbc 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 171:3a7713b1edbc 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 171:3a7713b1edbc 13 * other materials provided with the distribution.
AnnaBridge 171:3a7713b1edbc 14 *
AnnaBridge 171:3a7713b1edbc 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
AnnaBridge 171:3a7713b1edbc 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 171:3a7713b1edbc 17 * software without specific prior written permission.
AnnaBridge 171:3a7713b1edbc 18 *
AnnaBridge 171:3a7713b1edbc 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 171:3a7713b1edbc 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 171:3a7713b1edbc 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 171:3a7713b1edbc 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 171:3a7713b1edbc 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 171:3a7713b1edbc 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 171:3a7713b1edbc 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 171:3a7713b1edbc 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 171:3a7713b1edbc 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 171:3a7713b1edbc 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 171:3a7713b1edbc 29 */
AnnaBridge 171:3a7713b1edbc 30 #ifndef _FSL_PIT_H_
AnnaBridge 171:3a7713b1edbc 31 #define _FSL_PIT_H_
AnnaBridge 171:3a7713b1edbc 32
AnnaBridge 171:3a7713b1edbc 33 #include "fsl_common.h"
AnnaBridge 171:3a7713b1edbc 34
AnnaBridge 171:3a7713b1edbc 35 /*!
AnnaBridge 171:3a7713b1edbc 36 * @addtogroup pit_driver
AnnaBridge 171:3a7713b1edbc 37 * @{
AnnaBridge 171:3a7713b1edbc 38 */
AnnaBridge 171:3a7713b1edbc 39
AnnaBridge 171:3a7713b1edbc 40 /*! @file */
AnnaBridge 171:3a7713b1edbc 41
AnnaBridge 171:3a7713b1edbc 42 /*******************************************************************************
AnnaBridge 171:3a7713b1edbc 43 * Definitions
AnnaBridge 171:3a7713b1edbc 44 ******************************************************************************/
AnnaBridge 171:3a7713b1edbc 45
AnnaBridge 171:3a7713b1edbc 46 /*! @name Driver version */
AnnaBridge 171:3a7713b1edbc 47 /*@{*/
AnnaBridge 171:3a7713b1edbc 48 #define FSL_PIT_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
AnnaBridge 171:3a7713b1edbc 49 /*@}*/
AnnaBridge 171:3a7713b1edbc 50
AnnaBridge 171:3a7713b1edbc 51 /*!
AnnaBridge 171:3a7713b1edbc 52 * @brief List of PIT channels
AnnaBridge 171:3a7713b1edbc 53 * @note Actual number of available channels is SoC dependent
AnnaBridge 171:3a7713b1edbc 54 */
AnnaBridge 171:3a7713b1edbc 55 typedef enum _pit_chnl
AnnaBridge 171:3a7713b1edbc 56 {
AnnaBridge 171:3a7713b1edbc 57 kPIT_Chnl_0 = 0U, /*!< PIT channel number 0*/
AnnaBridge 171:3a7713b1edbc 58 kPIT_Chnl_1, /*!< PIT channel number 1 */
AnnaBridge 171:3a7713b1edbc 59 kPIT_Chnl_2, /*!< PIT channel number 2 */
AnnaBridge 171:3a7713b1edbc 60 kPIT_Chnl_3, /*!< PIT channel number 3 */
AnnaBridge 171:3a7713b1edbc 61 } pit_chnl_t;
AnnaBridge 171:3a7713b1edbc 62
AnnaBridge 171:3a7713b1edbc 63 /*! @brief List of PIT interrupts */
AnnaBridge 171:3a7713b1edbc 64 typedef enum _pit_interrupt_enable
AnnaBridge 171:3a7713b1edbc 65 {
AnnaBridge 171:3a7713b1edbc 66 kPIT_TimerInterruptEnable = PIT_TCTRL_TIE_MASK, /*!< Timer interrupt enable*/
AnnaBridge 171:3a7713b1edbc 67 } pit_interrupt_enable_t;
AnnaBridge 171:3a7713b1edbc 68
AnnaBridge 171:3a7713b1edbc 69 /*! @brief List of PIT status flags */
AnnaBridge 171:3a7713b1edbc 70 typedef enum _pit_status_flags
AnnaBridge 171:3a7713b1edbc 71 {
AnnaBridge 171:3a7713b1edbc 72 kPIT_TimerFlag = PIT_TFLG_TIF_MASK, /*!< Timer flag */
AnnaBridge 171:3a7713b1edbc 73 } pit_status_flags_t;
AnnaBridge 171:3a7713b1edbc 74
AnnaBridge 171:3a7713b1edbc 75 /*!
AnnaBridge 171:3a7713b1edbc 76 * @brief PIT config structure
AnnaBridge 171:3a7713b1edbc 77 *
AnnaBridge 171:3a7713b1edbc 78 * This structure holds the configuration settings for the PIT peripheral. To initialize this
AnnaBridge 171:3a7713b1edbc 79 * structure to reasonable defaults, call the PIT_GetDefaultConfig() function and pass a
AnnaBridge 171:3a7713b1edbc 80 * pointer to your config structure instance.
AnnaBridge 171:3a7713b1edbc 81 *
AnnaBridge 171:3a7713b1edbc 82 * The config struct can be made const so it resides in flash
AnnaBridge 171:3a7713b1edbc 83 */
AnnaBridge 171:3a7713b1edbc 84 typedef struct _pit_config
AnnaBridge 171:3a7713b1edbc 85 {
AnnaBridge 171:3a7713b1edbc 86 bool enableRunInDebug; /*!< true: Timers run in debug mode; false: Timers stop in debug mode */
AnnaBridge 171:3a7713b1edbc 87 } pit_config_t;
AnnaBridge 171:3a7713b1edbc 88
AnnaBridge 171:3a7713b1edbc 89 /*******************************************************************************
AnnaBridge 171:3a7713b1edbc 90 * API
AnnaBridge 171:3a7713b1edbc 91 ******************************************************************************/
AnnaBridge 171:3a7713b1edbc 92
AnnaBridge 171:3a7713b1edbc 93 #if defined(__cplusplus)
AnnaBridge 171:3a7713b1edbc 94 extern "C" {
AnnaBridge 171:3a7713b1edbc 95 #endif
AnnaBridge 171:3a7713b1edbc 96
AnnaBridge 171:3a7713b1edbc 97 /*!
AnnaBridge 171:3a7713b1edbc 98 * @name Initialization and deinitialization
AnnaBridge 171:3a7713b1edbc 99 * @{
AnnaBridge 171:3a7713b1edbc 100 */
AnnaBridge 171:3a7713b1edbc 101
AnnaBridge 171:3a7713b1edbc 102 /*!
AnnaBridge 171:3a7713b1edbc 103 * @brief Ungates the PIT clock, enables the PIT module and configures the peripheral for basic operation.
AnnaBridge 171:3a7713b1edbc 104 *
AnnaBridge 171:3a7713b1edbc 105 * @note This API should be called at the beginning of the application using the PIT driver.
AnnaBridge 171:3a7713b1edbc 106 *
AnnaBridge 171:3a7713b1edbc 107 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 108 * @param config Pointer to user's PIT config structure
AnnaBridge 171:3a7713b1edbc 109 */
AnnaBridge 171:3a7713b1edbc 110 void PIT_Init(PIT_Type *base, const pit_config_t *config);
AnnaBridge 171:3a7713b1edbc 111
AnnaBridge 171:3a7713b1edbc 112 /*!
AnnaBridge 171:3a7713b1edbc 113 * @brief Gate the PIT clock and disable the PIT module
AnnaBridge 171:3a7713b1edbc 114 *
AnnaBridge 171:3a7713b1edbc 115 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 116 */
AnnaBridge 171:3a7713b1edbc 117 void PIT_Deinit(PIT_Type *base);
AnnaBridge 171:3a7713b1edbc 118
AnnaBridge 171:3a7713b1edbc 119 /*!
AnnaBridge 171:3a7713b1edbc 120 * @brief Fill in the PIT config struct with the default settings
AnnaBridge 171:3a7713b1edbc 121 *
AnnaBridge 171:3a7713b1edbc 122 * The default values are:
AnnaBridge 171:3a7713b1edbc 123 * @code
AnnaBridge 171:3a7713b1edbc 124 * config->enableRunInDebug = false;
AnnaBridge 171:3a7713b1edbc 125 * @endcode
AnnaBridge 171:3a7713b1edbc 126 * @param config Pointer to user's PIT config structure.
AnnaBridge 171:3a7713b1edbc 127 */
AnnaBridge 171:3a7713b1edbc 128 static inline void PIT_GetDefaultConfig(pit_config_t *config)
AnnaBridge 171:3a7713b1edbc 129 {
AnnaBridge 171:3a7713b1edbc 130 assert(config);
AnnaBridge 171:3a7713b1edbc 131
AnnaBridge 171:3a7713b1edbc 132 /* Timers are stopped in Debug mode */
AnnaBridge 171:3a7713b1edbc 133 config->enableRunInDebug = false;
AnnaBridge 171:3a7713b1edbc 134 }
AnnaBridge 171:3a7713b1edbc 135
AnnaBridge 171:3a7713b1edbc 136 #if defined(FSL_FEATURE_PIT_HAS_CHAIN_MODE) && FSL_FEATURE_PIT_HAS_CHAIN_MODE
AnnaBridge 171:3a7713b1edbc 137
AnnaBridge 171:3a7713b1edbc 138 /*!
AnnaBridge 171:3a7713b1edbc 139 * @brief Enables or disables chaining a timer with the previous timer.
AnnaBridge 171:3a7713b1edbc 140 *
AnnaBridge 171:3a7713b1edbc 141 * When a timer has a chain mode enabled, it only counts after the previous
AnnaBridge 171:3a7713b1edbc 142 * timer has expired. If the timer n-1 has counted down to 0, counter n
AnnaBridge 171:3a7713b1edbc 143 * decrements the value by one. Each timer is 32-bits, this allows the developers
AnnaBridge 171:3a7713b1edbc 144 * to chain timers together and form a longer timer (64-bits and larger). The first timer
AnnaBridge 171:3a7713b1edbc 145 * (timer 0) cannot be chained to any other timer.
AnnaBridge 171:3a7713b1edbc 146 *
AnnaBridge 171:3a7713b1edbc 147 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 148 * @param channel Timer channel number which is chained with the previous timer
AnnaBridge 171:3a7713b1edbc 149 * @param enable Enable or disable chain.
AnnaBridge 171:3a7713b1edbc 150 * true: Current timer is chained with the previous timer.
AnnaBridge 171:3a7713b1edbc 151 * false: Timer doesn't chain with other timers.
AnnaBridge 171:3a7713b1edbc 152 */
AnnaBridge 171:3a7713b1edbc 153 static inline void PIT_SetTimerChainMode(PIT_Type *base, pit_chnl_t channel, bool enable)
AnnaBridge 171:3a7713b1edbc 154 {
AnnaBridge 171:3a7713b1edbc 155 if (enable)
AnnaBridge 171:3a7713b1edbc 156 {
AnnaBridge 171:3a7713b1edbc 157 base->CHANNEL[channel].TCTRL |= PIT_TCTRL_CHN_MASK;
AnnaBridge 171:3a7713b1edbc 158 }
AnnaBridge 171:3a7713b1edbc 159 else
AnnaBridge 171:3a7713b1edbc 160 {
AnnaBridge 171:3a7713b1edbc 161 base->CHANNEL[channel].TCTRL &= ~PIT_TCTRL_CHN_MASK;
AnnaBridge 171:3a7713b1edbc 162 }
AnnaBridge 171:3a7713b1edbc 163 }
AnnaBridge 171:3a7713b1edbc 164
AnnaBridge 171:3a7713b1edbc 165 #endif /* FSL_FEATURE_PIT_HAS_CHAIN_MODE */
AnnaBridge 171:3a7713b1edbc 166
AnnaBridge 171:3a7713b1edbc 167 /*! @}*/
AnnaBridge 171:3a7713b1edbc 168
AnnaBridge 171:3a7713b1edbc 169 /*!
AnnaBridge 171:3a7713b1edbc 170 * @name Interrupt Interface
AnnaBridge 171:3a7713b1edbc 171 * @{
AnnaBridge 171:3a7713b1edbc 172 */
AnnaBridge 171:3a7713b1edbc 173
AnnaBridge 171:3a7713b1edbc 174 /*!
AnnaBridge 171:3a7713b1edbc 175 * @brief Enables the selected PIT interrupts.
AnnaBridge 171:3a7713b1edbc 176 *
AnnaBridge 171:3a7713b1edbc 177 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 178 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 179 * @param mask The interrupts to enable. This is a logical OR of members of the
AnnaBridge 171:3a7713b1edbc 180 * enumeration ::pit_interrupt_enable_t
AnnaBridge 171:3a7713b1edbc 181 */
AnnaBridge 171:3a7713b1edbc 182 static inline void PIT_EnableInterrupts(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
AnnaBridge 171:3a7713b1edbc 183 {
AnnaBridge 171:3a7713b1edbc 184 base->CHANNEL[channel].TCTRL |= mask;
AnnaBridge 171:3a7713b1edbc 185 }
AnnaBridge 171:3a7713b1edbc 186
AnnaBridge 171:3a7713b1edbc 187 /*!
AnnaBridge 171:3a7713b1edbc 188 * @brief Disables the selected PIT interrupts.
AnnaBridge 171:3a7713b1edbc 189 *
AnnaBridge 171:3a7713b1edbc 190 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 191 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 192 * @param mask The interrupts to disable. This is a logical OR of members of the
AnnaBridge 171:3a7713b1edbc 193 * enumeration ::pit_interrupt_enable_t
AnnaBridge 171:3a7713b1edbc 194 */
AnnaBridge 171:3a7713b1edbc 195 static inline void PIT_DisableInterrupts(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
AnnaBridge 171:3a7713b1edbc 196 {
AnnaBridge 171:3a7713b1edbc 197 base->CHANNEL[channel].TCTRL &= ~mask;
AnnaBridge 171:3a7713b1edbc 198 }
AnnaBridge 171:3a7713b1edbc 199
AnnaBridge 171:3a7713b1edbc 200 /*!
AnnaBridge 171:3a7713b1edbc 201 * @brief Gets the enabled PIT interrupts.
AnnaBridge 171:3a7713b1edbc 202 *
AnnaBridge 171:3a7713b1edbc 203 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 204 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 205 *
AnnaBridge 171:3a7713b1edbc 206 * @return The enabled interrupts. This is the logical OR of members of the
AnnaBridge 171:3a7713b1edbc 207 * enumeration ::pit_interrupt_enable_t
AnnaBridge 171:3a7713b1edbc 208 */
AnnaBridge 171:3a7713b1edbc 209 static inline uint32_t PIT_GetEnabledInterrupts(PIT_Type *base, pit_chnl_t channel)
AnnaBridge 171:3a7713b1edbc 210 {
AnnaBridge 171:3a7713b1edbc 211 return (base->CHANNEL[channel].TCTRL & PIT_TCTRL_TIE_MASK);
AnnaBridge 171:3a7713b1edbc 212 }
AnnaBridge 171:3a7713b1edbc 213
AnnaBridge 171:3a7713b1edbc 214 /*! @}*/
AnnaBridge 171:3a7713b1edbc 215
AnnaBridge 171:3a7713b1edbc 216 /*!
AnnaBridge 171:3a7713b1edbc 217 * @name Status Interface
AnnaBridge 171:3a7713b1edbc 218 * @{
AnnaBridge 171:3a7713b1edbc 219 */
AnnaBridge 171:3a7713b1edbc 220
AnnaBridge 171:3a7713b1edbc 221 /*!
AnnaBridge 171:3a7713b1edbc 222 * @brief Gets the PIT status flags
AnnaBridge 171:3a7713b1edbc 223 *
AnnaBridge 171:3a7713b1edbc 224 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 225 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 226 *
AnnaBridge 171:3a7713b1edbc 227 * @return The status flags. This is the logical OR of members of the
AnnaBridge 171:3a7713b1edbc 228 * enumeration ::pit_status_flags_t
AnnaBridge 171:3a7713b1edbc 229 */
AnnaBridge 171:3a7713b1edbc 230 static inline uint32_t PIT_GetStatusFlags(PIT_Type *base, pit_chnl_t channel)
AnnaBridge 171:3a7713b1edbc 231 {
AnnaBridge 171:3a7713b1edbc 232 return (base->CHANNEL[channel].TFLG & PIT_TFLG_TIF_MASK);
AnnaBridge 171:3a7713b1edbc 233 }
AnnaBridge 171:3a7713b1edbc 234
AnnaBridge 171:3a7713b1edbc 235 /*!
AnnaBridge 171:3a7713b1edbc 236 * @brief Clears the PIT status flags.
AnnaBridge 171:3a7713b1edbc 237 *
AnnaBridge 171:3a7713b1edbc 238 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 239 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 240 * @param mask The status flags to clear. This is a logical OR of members of the
AnnaBridge 171:3a7713b1edbc 241 * enumeration ::pit_status_flags_t
AnnaBridge 171:3a7713b1edbc 242 */
AnnaBridge 171:3a7713b1edbc 243 static inline void PIT_ClearStatusFlags(PIT_Type *base, pit_chnl_t channel, uint32_t mask)
AnnaBridge 171:3a7713b1edbc 244 {
AnnaBridge 171:3a7713b1edbc 245 base->CHANNEL[channel].TFLG = mask;
AnnaBridge 171:3a7713b1edbc 246 }
AnnaBridge 171:3a7713b1edbc 247
AnnaBridge 171:3a7713b1edbc 248 /*! @}*/
AnnaBridge 171:3a7713b1edbc 249
AnnaBridge 171:3a7713b1edbc 250 /*!
AnnaBridge 171:3a7713b1edbc 251 * @name Read and Write the timer period
AnnaBridge 171:3a7713b1edbc 252 * @{
AnnaBridge 171:3a7713b1edbc 253 */
AnnaBridge 171:3a7713b1edbc 254
AnnaBridge 171:3a7713b1edbc 255 /*!
AnnaBridge 171:3a7713b1edbc 256 * @brief Sets the timer period in units of count.
AnnaBridge 171:3a7713b1edbc 257 *
AnnaBridge 171:3a7713b1edbc 258 * Timers begin counting from the value set by this function until it reaches 0,
AnnaBridge 171:3a7713b1edbc 259 * then it will generate an interrupt and load this regiter value again.
AnnaBridge 171:3a7713b1edbc 260 * Writing a new value to this register will not restart the timer; instead the value
AnnaBridge 171:3a7713b1edbc 261 * will be loaded after the timer expires.
AnnaBridge 171:3a7713b1edbc 262 *
AnnaBridge 171:3a7713b1edbc 263 * @note User can call the utility macros provided in fsl_common.h to convert to ticks
AnnaBridge 171:3a7713b1edbc 264 *
AnnaBridge 171:3a7713b1edbc 265 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 266 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 267 * @param count Timer period in units of ticks
AnnaBridge 171:3a7713b1edbc 268 */
AnnaBridge 171:3a7713b1edbc 269 static inline void PIT_SetTimerPeriod(PIT_Type *base, pit_chnl_t channel, uint32_t count)
AnnaBridge 171:3a7713b1edbc 270 {
AnnaBridge 171:3a7713b1edbc 271 base->CHANNEL[channel].LDVAL = count;
AnnaBridge 171:3a7713b1edbc 272 }
AnnaBridge 171:3a7713b1edbc 273
AnnaBridge 171:3a7713b1edbc 274 /*!
AnnaBridge 171:3a7713b1edbc 275 * @brief Reads the current timer counting value.
AnnaBridge 171:3a7713b1edbc 276 *
AnnaBridge 171:3a7713b1edbc 277 * This function returns the real-time timer counting value, in a range from 0 to a
AnnaBridge 171:3a7713b1edbc 278 * timer period.
AnnaBridge 171:3a7713b1edbc 279 *
AnnaBridge 171:3a7713b1edbc 280 * @note User can call the utility macros provided in fsl_common.h to convert ticks to usec or msec
AnnaBridge 171:3a7713b1edbc 281 *
AnnaBridge 171:3a7713b1edbc 282 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 283 * @param channel Timer channel number
AnnaBridge 171:3a7713b1edbc 284 *
AnnaBridge 171:3a7713b1edbc 285 * @return Current timer counting value in ticks
AnnaBridge 171:3a7713b1edbc 286 */
AnnaBridge 171:3a7713b1edbc 287 static inline uint32_t PIT_GetCurrentTimerCount(PIT_Type *base, pit_chnl_t channel)
AnnaBridge 171:3a7713b1edbc 288 {
AnnaBridge 171:3a7713b1edbc 289 return base->CHANNEL[channel].CVAL;
AnnaBridge 171:3a7713b1edbc 290 }
AnnaBridge 171:3a7713b1edbc 291
AnnaBridge 171:3a7713b1edbc 292 /*! @}*/
AnnaBridge 171:3a7713b1edbc 293
AnnaBridge 171:3a7713b1edbc 294 /*!
AnnaBridge 171:3a7713b1edbc 295 * @name Timer Start and Stop
AnnaBridge 171:3a7713b1edbc 296 * @{
AnnaBridge 171:3a7713b1edbc 297 */
AnnaBridge 171:3a7713b1edbc 298
AnnaBridge 171:3a7713b1edbc 299 /*!
AnnaBridge 171:3a7713b1edbc 300 * @brief Starts the timer counting.
AnnaBridge 171:3a7713b1edbc 301 *
AnnaBridge 171:3a7713b1edbc 302 * After calling this function, timers load period value, count down to 0 and
AnnaBridge 171:3a7713b1edbc 303 * then load the respective start value again. Each time a timer reaches 0,
AnnaBridge 171:3a7713b1edbc 304 * it generates a trigger pulse and sets the timeout interrupt flag.
AnnaBridge 171:3a7713b1edbc 305 *
AnnaBridge 171:3a7713b1edbc 306 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 307 * @param channel Timer channel number.
AnnaBridge 171:3a7713b1edbc 308 */
AnnaBridge 171:3a7713b1edbc 309 static inline void PIT_StartTimer(PIT_Type *base, pit_chnl_t channel)
AnnaBridge 171:3a7713b1edbc 310 {
AnnaBridge 171:3a7713b1edbc 311 base->CHANNEL[channel].TCTRL |= PIT_TCTRL_TEN_MASK;
AnnaBridge 171:3a7713b1edbc 312 }
AnnaBridge 171:3a7713b1edbc 313
AnnaBridge 171:3a7713b1edbc 314 /*!
AnnaBridge 171:3a7713b1edbc 315 * @brief Stops the timer counting.
AnnaBridge 171:3a7713b1edbc 316 *
AnnaBridge 171:3a7713b1edbc 317 * This function stops every timer counting. Timers reload their periods
AnnaBridge 171:3a7713b1edbc 318 * respectively after the next time they call the PIT_DRV_StartTimer.
AnnaBridge 171:3a7713b1edbc 319 *
AnnaBridge 171:3a7713b1edbc 320 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 321 * @param channel Timer channel number.
AnnaBridge 171:3a7713b1edbc 322 */
AnnaBridge 171:3a7713b1edbc 323 static inline void PIT_StopTimer(PIT_Type *base, pit_chnl_t channel)
AnnaBridge 171:3a7713b1edbc 324 {
AnnaBridge 171:3a7713b1edbc 325 base->CHANNEL[channel].TCTRL &= ~PIT_TCTRL_TEN_MASK;
AnnaBridge 171:3a7713b1edbc 326 }
AnnaBridge 171:3a7713b1edbc 327
AnnaBridge 171:3a7713b1edbc 328 /*! @}*/
AnnaBridge 171:3a7713b1edbc 329
AnnaBridge 171:3a7713b1edbc 330 #if defined(FSL_FEATURE_PIT_HAS_LIFETIME_TIMER) && FSL_FEATURE_PIT_HAS_LIFETIME_TIMER
AnnaBridge 171:3a7713b1edbc 331
AnnaBridge 171:3a7713b1edbc 332 /*!
AnnaBridge 171:3a7713b1edbc 333 * @brief Reads the current lifetime counter value.
AnnaBridge 171:3a7713b1edbc 334 *
AnnaBridge 171:3a7713b1edbc 335 * The lifetime timer is a 64-bit timer which chains timer 0 and timer 1 together.
AnnaBridge 171:3a7713b1edbc 336 * Timer 0 and 1 are chained by calling the PIT_SetTimerChainMode before using this timer.
AnnaBridge 171:3a7713b1edbc 337 * The period of lifetime timer is equal to the "period of timer 0 * period of timer 1".
AnnaBridge 171:3a7713b1edbc 338 * For the 64-bit value, the higher 32-bit has the value of timer 1, and the lower 32-bit
AnnaBridge 171:3a7713b1edbc 339 * has the value of timer 0.
AnnaBridge 171:3a7713b1edbc 340 *
AnnaBridge 171:3a7713b1edbc 341 * @param base PIT peripheral base address
AnnaBridge 171:3a7713b1edbc 342 *
AnnaBridge 171:3a7713b1edbc 343 * @return Current lifetime timer value
AnnaBridge 171:3a7713b1edbc 344 */
AnnaBridge 171:3a7713b1edbc 345 uint64_t PIT_GetLifetimeTimerCount(PIT_Type *base);
AnnaBridge 171:3a7713b1edbc 346
AnnaBridge 171:3a7713b1edbc 347 #endif /* FSL_FEATURE_PIT_HAS_LIFETIME_TIMER */
AnnaBridge 171:3a7713b1edbc 348
AnnaBridge 171:3a7713b1edbc 349 #if defined(__cplusplus)
AnnaBridge 171:3a7713b1edbc 350 }
AnnaBridge 171:3a7713b1edbc 351 #endif
AnnaBridge 171:3a7713b1edbc 352
AnnaBridge 171:3a7713b1edbc 353 /*! @}*/
AnnaBridge 171:3a7713b1edbc 354
AnnaBridge 171:3a7713b1edbc 355 #endif /* _FSL_PIT_H_ */