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