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
Kojto 148:fd96258d940d 1 /*
Kojto 148:fd96258d940d 2 * Copyright (c) 2016, Freescale Semiconductor, Inc.
Kojto 148:fd96258d940d 3 * All rights reserved.
Kojto 148:fd96258d940d 4 *
Kojto 148:fd96258d940d 5 * Redistribution and use in source and binary forms, with or without modification,
Kojto 148:fd96258d940d 6 * are permitted provided that the following conditions are met:
Kojto 148:fd96258d940d 7 *
Kojto 148:fd96258d940d 8 * o Redistributions of source code must retain the above copyright notice, this list
Kojto 148:fd96258d940d 9 * of conditions and the following disclaimer.
Kojto 148:fd96258d940d 10 *
Kojto 148:fd96258d940d 11 * o Redistributions in binary form must reproduce the above copyright notice, this
Kojto 148:fd96258d940d 12 * list of conditions and the following disclaimer in the documentation and/or
Kojto 148:fd96258d940d 13 * other materials provided with the distribution.
Kojto 148:fd96258d940d 14 *
Kojto 148:fd96258d940d 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
Kojto 148:fd96258d940d 16 * contributors may be used to endorse or promote products derived from this
Kojto 148:fd96258d940d 17 * software without specific prior written permission.
Kojto 148:fd96258d940d 18 *
Kojto 148:fd96258d940d 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
Kojto 148:fd96258d940d 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
Kojto 148:fd96258d940d 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Kojto 148:fd96258d940d 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
Kojto 148:fd96258d940d 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
Kojto 148:fd96258d940d 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
Kojto 148:fd96258d940d 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
Kojto 148:fd96258d940d 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Kojto 148:fd96258d940d 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
Kojto 148:fd96258d940d 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Kojto 148:fd96258d940d 29 */
Kojto 148:fd96258d940d 30 #ifndef _FSL_CTIMER_H_
Kojto 148:fd96258d940d 31 #define _FSL_CTIMER_H_
Kojto 148:fd96258d940d 32
Kojto 148:fd96258d940d 33 #include "fsl_common.h"
Kojto 148:fd96258d940d 34
Kojto 148:fd96258d940d 35 /*!
Kojto 148:fd96258d940d 36 * @addtogroup ctimer
Kojto 148:fd96258d940d 37 * @{
Kojto 148:fd96258d940d 38 */
Kojto 148:fd96258d940d 39
Kojto 148:fd96258d940d 40 /*! @file */
Kojto 148:fd96258d940d 41
Kojto 148:fd96258d940d 42 /*******************************************************************************
Kojto 148:fd96258d940d 43 * Definitions
Kojto 148:fd96258d940d 44 ******************************************************************************/
Kojto 148:fd96258d940d 45
Kojto 148:fd96258d940d 46 /*! @name Driver version */
Kojto 148:fd96258d940d 47 /*@{*/
Kojto 148:fd96258d940d 48 #define FSL_CTIMER_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0 */
Kojto 148:fd96258d940d 49 /*@}*/
Kojto 148:fd96258d940d 50
Kojto 148:fd96258d940d 51 /*! @brief List of Timer capture channels */
Kojto 148:fd96258d940d 52 typedef enum _ctimer_capture_channel
Kojto 148:fd96258d940d 53 {
Kojto 148:fd96258d940d 54 kCTIMER_Capture_0 = 0U, /*!< Timer capture channel 0 */
Kojto 148:fd96258d940d 55 kCTIMER_Capture_1, /*!< Timer capture channel 1 */
Kojto 148:fd96258d940d 56 kCTIMER_Capture_2, /*!< Timer capture channel 2 */
Kojto 148:fd96258d940d 57 kCTIMER_Capture_3 /*!< Timer capture channel 3 */
Kojto 148:fd96258d940d 58 } ctimer_capture_channel_t;
Kojto 148:fd96258d940d 59
Kojto 148:fd96258d940d 60 /*! @brief List of capture edge options */
Kojto 148:fd96258d940d 61 typedef enum _ctimer_capture_edge
Kojto 148:fd96258d940d 62 {
Kojto 148:fd96258d940d 63 kCTIMER_Capture_RiseEdge = 1U, /*!< Capture on rising edge */
Kojto 148:fd96258d940d 64 kCTIMER_Capture_FallEdge = 2U, /*!< Capture on falling edge */
Kojto 148:fd96258d940d 65 kCTIMER_Capture_BothEdge = 3U, /*!< Capture on rising and falling edge */
Kojto 148:fd96258d940d 66 } ctimer_capture_edge_t;
Kojto 148:fd96258d940d 67
Kojto 148:fd96258d940d 68 /*! @brief List of Timer match registers */
Kojto 148:fd96258d940d 69 typedef enum _ctimer_match
Kojto 148:fd96258d940d 70 {
Kojto 148:fd96258d940d 71 kCTIMER_Match_0 = 0U, /*!< Timer match register 0 */
Kojto 148:fd96258d940d 72 kCTIMER_Match_1, /*!< Timer match register 1 */
Kojto 148:fd96258d940d 73 kCTIMER_Match_2, /*!< Timer match register 2 */
Kojto 148:fd96258d940d 74 kCTIMER_Match_3 /*!< Timer match register 3 */
Kojto 148:fd96258d940d 75 } ctimer_match_t;
Kojto 148:fd96258d940d 76
Kojto 148:fd96258d940d 77 /*! @brief List of output control options */
Kojto 148:fd96258d940d 78 typedef enum _ctimer_match_output_control
Kojto 148:fd96258d940d 79 {
Kojto 148:fd96258d940d 80 kCTIMER_Output_NoAction = 0U, /*!< No action is taken */
Kojto 148:fd96258d940d 81 kCTIMER_Output_Clear, /*!< Clear the EM bit/output to 0 */
Kojto 148:fd96258d940d 82 kCTIMER_Output_Set, /*!< Set the EM bit/output to 1 */
Kojto 148:fd96258d940d 83 kCTIMER_Output_Toggle /*!< Toggle the EM bit/output */
Kojto 148:fd96258d940d 84 } ctimer_match_output_control_t;
Kojto 148:fd96258d940d 85
Kojto 148:fd96258d940d 86 /*! @brief List of Timer modes */
Kojto 148:fd96258d940d 87 typedef enum _ctimer_timer_mode
Kojto 148:fd96258d940d 88 {
Kojto 148:fd96258d940d 89 kCTIMER_TimerMode = 0U, /* TC is incremented every rising APB bus clock edge */
Kojto 148:fd96258d940d 90 kCTIMER_IncreaseOnRiseEdge, /* TC is incremented on rising edge of input signal */
Kojto 148:fd96258d940d 91 kCTIMER_IncreaseOnFallEdge, /* TC is incremented on falling edge of input signal */
Kojto 148:fd96258d940d 92 kCTIMER_IncreaseOnBothEdge /* TC is incremented on both edges of input signal */
Kojto 148:fd96258d940d 93 } ctimer_timer_mode_t;
Kojto 148:fd96258d940d 94
Kojto 148:fd96258d940d 95 /*! @brief List of Timer interrupts */
Kojto 148:fd96258d940d 96 typedef enum _ctimer_interrupt_enable
Kojto 148:fd96258d940d 97 {
Kojto 148:fd96258d940d 98 kCTIMER_Match0InterruptEnable = CTIMER_MCR_MR0I_MASK, /*!< Match 0 interrupt */
Kojto 148:fd96258d940d 99 kCTIMER_Match1InterruptEnable = CTIMER_MCR_MR1I_MASK, /*!< Match 1 interrupt */
Kojto 148:fd96258d940d 100 kCTIMER_Match2InterruptEnable = CTIMER_MCR_MR2I_MASK, /*!< Match 2 interrupt */
Kojto 148:fd96258d940d 101 kCTIMER_Match3InterruptEnable = CTIMER_MCR_MR3I_MASK, /*!< Match 3 interrupt */
Kojto 148:fd96258d940d 102 kCTIMER_Capture0InterruptEnable = CTIMER_CCR_CAP0I_MASK, /*!< Capture 0 interrupt */
Kojto 148:fd96258d940d 103 kCTIMER_Capture1InterruptEnable = CTIMER_CCR_CAP1I_MASK, /*!< Capture 1 interrupt */
Kojto 148:fd96258d940d 104 kCTIMER_Capture2InterruptEnable = CTIMER_CCR_CAP2I_MASK, /*!< Capture 2 interrupt */
Kojto 148:fd96258d940d 105 kCTIMER_Capture3InterruptEnable = CTIMER_CCR_CAP3I_MASK, /*!< Capture 3 interrupt */
Kojto 148:fd96258d940d 106 } ctimer_interrupt_enable_t;
Kojto 148:fd96258d940d 107
Kojto 148:fd96258d940d 108 /*! @brief List of Timer flags */
Kojto 148:fd96258d940d 109 typedef enum _ctimer_status_flags
Kojto 148:fd96258d940d 110 {
Kojto 148:fd96258d940d 111 kCTIMER_Match0Flag = CTIMER_IR_MR0INT_MASK, /*!< Match 0 interrupt flag */
Kojto 148:fd96258d940d 112 kCTIMER_Match1Flag = CTIMER_IR_MR1INT_MASK, /*!< Match 1 interrupt flag */
Kojto 148:fd96258d940d 113 kCTIMER_Match2Flag = CTIMER_IR_MR2INT_MASK, /*!< Match 2 interrupt flag */
Kojto 148:fd96258d940d 114 kCTIMER_Match3Flag = CTIMER_IR_MR3INT_MASK, /*!< Match 3 interrupt flag */
Kojto 148:fd96258d940d 115 kCTIMER_Capture0Flag = CTIMER_IR_CR0INT_MASK, /*!< Capture 0 interrupt flag */
Kojto 148:fd96258d940d 116 kCTIMER_Capture1Flag = CTIMER_IR_CR1INT_MASK, /*!< Capture 1 interrupt flag */
Kojto 148:fd96258d940d 117 kCTIMER_Capture2Flag = CTIMER_IR_CR2INT_MASK, /*!< Capture 2 interrupt flag */
Kojto 148:fd96258d940d 118 kCTIMER_Capture3Flag = CTIMER_IR_CR3INT_MASK, /*!< Capture 3 interrupt flag */
Kojto 148:fd96258d940d 119 } ctimer_status_flags_t;
Kojto 148:fd96258d940d 120
Kojto 148:fd96258d940d 121 typedef void (*ctimer_callback_t)(uint32_t flags);
Kojto 148:fd96258d940d 122
Kojto 148:fd96258d940d 123 /*! @brief Callback type when registering for a callback. When registering a callback
Kojto 148:fd96258d940d 124 * an array of function pointers is passed the size could be 1 or 8, the callback
Kojto 148:fd96258d940d 125 * type will tell that.
Kojto 148:fd96258d940d 126 */
Kojto 148:fd96258d940d 127 typedef enum
Kojto 148:fd96258d940d 128 {
Kojto 148:fd96258d940d 129 kCTIMER_SingleCallback, /*!< Single Callback type where there is only one callback for the timer.
Kojto 148:fd96258d940d 130 based on the status flags different channels needs to be handled differently */
Kojto 148:fd96258d940d 131 kCTIMER_MultipleCallback /*!< Multiple Callback type where there can be 8 valid callbacks, one per channel.
Kojto 148:fd96258d940d 132 for both match/capture */
Kojto 148:fd96258d940d 133 } ctimer_callback_type_t;
Kojto 148:fd96258d940d 134
Kojto 148:fd96258d940d 135 /*!
Kojto 148:fd96258d940d 136 * @brief Match configuration
Kojto 148:fd96258d940d 137 *
Kojto 148:fd96258d940d 138 * This structure holds the configuration settings for each match register.
Kojto 148:fd96258d940d 139 */
Kojto 148:fd96258d940d 140 typedef struct _ctimer_match_config
Kojto 148:fd96258d940d 141 {
Kojto 148:fd96258d940d 142 uint32_t matchValue; /*!< This is stored in the match register */
Kojto 148:fd96258d940d 143 bool enableCounterReset; /*!< true: Match will reset the counter
Kojto 148:fd96258d940d 144 false: Match will not reser the counter */
Kojto 148:fd96258d940d 145 bool enableCounterStop; /*!< true: Match will stop the counter
Kojto 148:fd96258d940d 146 false: Match will not stop the counter */
Kojto 148:fd96258d940d 147 ctimer_match_output_control_t outControl; /*!< Action to be taken on a match on the EM bit/output */
Kojto 148:fd96258d940d 148 bool outPinInitState; /*!< Initial value of the EM bit/output */
Kojto 148:fd96258d940d 149 bool enableInterrupt; /*!< true: Generate interrupt upon match
Kojto 148:fd96258d940d 150 false: Do not generate interrupt on match */
Kojto 148:fd96258d940d 151
Kojto 148:fd96258d940d 152 } ctimer_match_config_t;
Kojto 148:fd96258d940d 153
Kojto 148:fd96258d940d 154 /*!
Kojto 148:fd96258d940d 155 * @brief Timer configuration structure
Kojto 148:fd96258d940d 156 *
Kojto 148:fd96258d940d 157 * This structure holds the configuration settings for the Timer peripheral. To initialize this
Kojto 148:fd96258d940d 158 * structure to reasonable defaults, call the CTIMER_GetDefaultConfig() function and pass a
Kojto 148:fd96258d940d 159 * pointer to the configuration structure instance.
Kojto 148:fd96258d940d 160 *
Kojto 148:fd96258d940d 161 * The configuration structure can be made constant so as to reside in flash.
Kojto 148:fd96258d940d 162 */
Kojto 148:fd96258d940d 163 typedef struct _ctimer_config
Kojto 148:fd96258d940d 164 {
Kojto 148:fd96258d940d 165 ctimer_timer_mode_t mode; /*!< Timer mode */
Kojto 148:fd96258d940d 166 ctimer_capture_channel_t input; /*!< Input channel to increment the timer, used only in timer
Kojto 148:fd96258d940d 167 modes that rely on this input signal to increment TC */
Kojto 148:fd96258d940d 168 uint32_t prescale; /*!< Prescale value */
Kojto 148:fd96258d940d 169 } ctimer_config_t;
Kojto 148:fd96258d940d 170
Kojto 148:fd96258d940d 171 /*******************************************************************************
Kojto 148:fd96258d940d 172 * API
Kojto 148:fd96258d940d 173 ******************************************************************************/
Kojto 148:fd96258d940d 174
Kojto 148:fd96258d940d 175 #if defined(__cplusplus)
Kojto 148:fd96258d940d 176 extern "C" {
Kojto 148:fd96258d940d 177 #endif
Kojto 148:fd96258d940d 178
Kojto 148:fd96258d940d 179 /*!
Kojto 148:fd96258d940d 180 * @name Initialization and deinitialization
Kojto 148:fd96258d940d 181 * @{
Kojto 148:fd96258d940d 182 */
Kojto 148:fd96258d940d 183
Kojto 148:fd96258d940d 184 /*!
Kojto 148:fd96258d940d 185 * @brief Ungates the clock and configures the peripheral for basic operation.
Kojto 148:fd96258d940d 186 *
Kojto 148:fd96258d940d 187 * @note This API should be called at the beginning of the application before using the driver.
Kojto 148:fd96258d940d 188 *
Kojto 148:fd96258d940d 189 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 190 * @param config Pointer to the user configuration structure.
Kojto 148:fd96258d940d 191 */
Kojto 148:fd96258d940d 192 void CTIMER_Init(CTIMER_Type *base, const ctimer_config_t *config);
Kojto 148:fd96258d940d 193
Kojto 148:fd96258d940d 194 /*!
Kojto 148:fd96258d940d 195 * @brief Gates the timer clock.
Kojto 148:fd96258d940d 196 *
Kojto 148:fd96258d940d 197 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 198 */
Kojto 148:fd96258d940d 199 void CTIMER_Deinit(CTIMER_Type *base);
Kojto 148:fd96258d940d 200
Kojto 148:fd96258d940d 201 /*!
Kojto 148:fd96258d940d 202 * @brief Fills in the timers configuration structure with the default settings.
Kojto 148:fd96258d940d 203 *
Kojto 148:fd96258d940d 204 * The default values are:
Kojto 148:fd96258d940d 205 * @code
Kojto 148:fd96258d940d 206 * config->mode = kCTIMER_TimerMode;
Kojto 148:fd96258d940d 207 * config->input = kCTIMER_Capture_0;
Kojto 148:fd96258d940d 208 * config->prescale = 0;
Kojto 148:fd96258d940d 209 * @endcode
Kojto 148:fd96258d940d 210 * @param config Pointer to the user configuration structure.
Kojto 148:fd96258d940d 211 */
Kojto 148:fd96258d940d 212 void CTIMER_GetDefaultConfig(ctimer_config_t *config);
Kojto 148:fd96258d940d 213
Kojto 148:fd96258d940d 214 /*! @}*/
Kojto 148:fd96258d940d 215
Kojto 148:fd96258d940d 216 /*!
Kojto 148:fd96258d940d 217 * @name PWM setup operations
Kojto 148:fd96258d940d 218 * @{
Kojto 148:fd96258d940d 219 */
Kojto 148:fd96258d940d 220
Kojto 148:fd96258d940d 221 /*!
Kojto 148:fd96258d940d 222 * @brief Configures the PWM signal parameters.
Kojto 148:fd96258d940d 223 *
Kojto 148:fd96258d940d 224 * Enables PWM mode on the match channel passed in and will then setup the match value
Kojto 148:fd96258d940d 225 * and other match parameters to generate a PWM signal.
Kojto 148:fd96258d940d 226 * This function will assign match channel 3 to set the PWM cycle.
Kojto 148:fd96258d940d 227 *
Kojto 148:fd96258d940d 228 * @note When setting PWM output from multiple output pins, all should use the same PWM
Kojto 148:fd96258d940d 229 * frequency
Kojto 148:fd96258d940d 230 *
Kojto 148:fd96258d940d 231 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 232 * @param matchChannel Match pin to be used to output the PWM signal
Kojto 148:fd96258d940d 233 * @param dutyCyclePercent PWM pulse width; the value should be between 0 to 100
Kojto 148:fd96258d940d 234 * @param pwmFreq_Hz PWM signal frequency in Hz
Kojto 148:fd96258d940d 235 * @param srcClock_Hz Timer counter clock in Hz
Kojto 148:fd96258d940d 236 * @param enableInt Enable interrupt when the timer value reaches the match value of the PWM pulse,
Kojto 148:fd96258d940d 237 * if it is 0 then no interrupt is generated
Kojto 148:fd96258d940d 238 *
Kojto 148:fd96258d940d 239 * @return kStatus_Success on success
Kojto 148:fd96258d940d 240 * kStatus_Fail If matchChannel passed in is 3; this channel is reserved to set the PWM cycle
Kojto 148:fd96258d940d 241 */
Kojto 148:fd96258d940d 242 status_t CTIMER_SetupPwm(CTIMER_Type *base,
Kojto 148:fd96258d940d 243 ctimer_match_t matchChannel,
Kojto 148:fd96258d940d 244 uint8_t dutyCyclePercent,
Kojto 148:fd96258d940d 245 uint32_t pwmFreq_Hz,
Kojto 148:fd96258d940d 246 uint32_t srcClock_Hz,
Kojto 148:fd96258d940d 247 bool enableInt);
Kojto 148:fd96258d940d 248
Kojto 148:fd96258d940d 249 /*!
Kojto 148:fd96258d940d 250 * @brief Updates the duty cycle of an active PWM signal.
Kojto 148:fd96258d940d 251 *
Kojto 148:fd96258d940d 252 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 253 * @param matchChannel Match pin to be used to output the PWM signal
Kojto 148:fd96258d940d 254 * @param dutyCyclePercent New PWM pulse width; the value should be between 0 to 100
Kojto 148:fd96258d940d 255 */
Kojto 148:fd96258d940d 256 void CTIMER_UpdatePwmDutycycle(CTIMER_Type *base, ctimer_match_t matchChannel, uint8_t dutyCyclePercent);
Kojto 148:fd96258d940d 257
Kojto 148:fd96258d940d 258 /*! @}*/
Kojto 148:fd96258d940d 259
Kojto 148:fd96258d940d 260 /*!
Kojto 148:fd96258d940d 261 * @brief Setup the match register.
Kojto 148:fd96258d940d 262 *
Kojto 148:fd96258d940d 263 * User configuration is used to setup the match value and action to be taken when a match occurs.
Kojto 148:fd96258d940d 264 *
Kojto 148:fd96258d940d 265 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 266 * @param matchChannel Match register to configure
Kojto 148:fd96258d940d 267 * @param config Pointer to the match configuration structure
Kojto 148:fd96258d940d 268 */
Kojto 148:fd96258d940d 269 void CTIMER_SetupMatch(CTIMER_Type *base, ctimer_match_t matchChannel, const ctimer_match_config_t *config);
Kojto 148:fd96258d940d 270
Kojto 148:fd96258d940d 271 /*!
Kojto 148:fd96258d940d 272 * @brief Setup the capture.
Kojto 148:fd96258d940d 273 *
Kojto 148:fd96258d940d 274 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 275 * @param capture Capture channel to configure
Kojto 148:fd96258d940d 276 * @param edge Edge on the channel that will trigger a capture
Kojto 148:fd96258d940d 277 * @param enableInt Flag to enable channel interrupts, if enabled then the registered call back
Kojto 148:fd96258d940d 278 * is called upon capture
Kojto 148:fd96258d940d 279 */
Kojto 148:fd96258d940d 280 void CTIMER_SetupCapture(CTIMER_Type *base,
Kojto 148:fd96258d940d 281 ctimer_capture_channel_t capture,
Kojto 148:fd96258d940d 282 ctimer_capture_edge_t edge,
Kojto 148:fd96258d940d 283 bool enableInt);
Kojto 148:fd96258d940d 284
Kojto 148:fd96258d940d 285 /*!
Kojto 148:fd96258d940d 286 * @brief Register callback.
Kojto 148:fd96258d940d 287 *
Kojto 148:fd96258d940d 288 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 289 * @param cb_func callback function
Kojto 148:fd96258d940d 290 * @param cb_type callback function type, singular or multiple
Kojto 148:fd96258d940d 291 */
Kojto 148:fd96258d940d 292 void CTIMER_RegisterCallBack(CTIMER_Type *base, ctimer_callback_t *cb_func, ctimer_callback_type_t cb_type);
Kojto 148:fd96258d940d 293
Kojto 148:fd96258d940d 294 /*!
Kojto 148:fd96258d940d 295 * @name Interrupt Interface
Kojto 148:fd96258d940d 296 * @{
Kojto 148:fd96258d940d 297 */
Kojto 148:fd96258d940d 298
Kojto 148:fd96258d940d 299 /*!
Kojto 148:fd96258d940d 300 * @brief Enables the selected Timer interrupts.
Kojto 148:fd96258d940d 301 *
Kojto 148:fd96258d940d 302 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 303 * @param mask The interrupts to enable. This is a logical OR of members of the
Kojto 148:fd96258d940d 304 * enumeration ::ctimer_interrupt_enable_t
Kojto 148:fd96258d940d 305 */
Kojto 148:fd96258d940d 306 static inline void CTIMER_EnableInterrupts(CTIMER_Type *base, uint32_t mask)
Kojto 148:fd96258d940d 307 {
Kojto 148:fd96258d940d 308 /* Enable match interrupts */
Kojto 148:fd96258d940d 309 base->MCR |= mask;
Kojto 148:fd96258d940d 310
Kojto 148:fd96258d940d 311 /* Enable capture interrupts */
Kojto 148:fd96258d940d 312 base->CCR |= mask;
Kojto 148:fd96258d940d 313 }
Kojto 148:fd96258d940d 314
Kojto 148:fd96258d940d 315 /*!
Kojto 148:fd96258d940d 316 * @brief Disables the selected Timer interrupts.
Kojto 148:fd96258d940d 317 *
Kojto 148:fd96258d940d 318 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 319 * @param mask The interrupts to enable. This is a logical OR of members of the
Kojto 148:fd96258d940d 320 * enumeration ::ctimer_interrupt_enable_t
Kojto 148:fd96258d940d 321 */
Kojto 148:fd96258d940d 322 static inline void CTIMER_DisableInterrupts(CTIMER_Type *base, uint32_t mask)
Kojto 148:fd96258d940d 323 {
Kojto 148:fd96258d940d 324 /* Disable match interrupts */
Kojto 148:fd96258d940d 325 base->MCR &= ~mask;
Kojto 148:fd96258d940d 326
Kojto 148:fd96258d940d 327 /* Disable capture interrupts */
Kojto 148:fd96258d940d 328 base->CCR &= ~mask;
Kojto 148:fd96258d940d 329 }
Kojto 148:fd96258d940d 330
Kojto 148:fd96258d940d 331 /*!
Kojto 148:fd96258d940d 332 * @brief Gets the enabled Timer interrupts.
Kojto 148:fd96258d940d 333 *
Kojto 148:fd96258d940d 334 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 335 *
Kojto 148:fd96258d940d 336 * @return The enabled interrupts. This is the logical OR of members of the
Kojto 148:fd96258d940d 337 * enumeration ::ctimer_interrupt_enable_t
Kojto 148:fd96258d940d 338 */
Kojto 148:fd96258d940d 339 static inline uint32_t CTIMER_GetEnabledInterrupts(CTIMER_Type *base)
Kojto 148:fd96258d940d 340 {
Kojto 148:fd96258d940d 341 uint32_t enabledIntrs = 0;
Kojto 148:fd96258d940d 342
Kojto 148:fd96258d940d 343 /* Get all the match interrupts enabled */
Kojto 148:fd96258d940d 344 enabledIntrs =
Kojto 148:fd96258d940d 345 base->MCR & (CTIMER_MCR_MR0I_SHIFT | CTIMER_MCR_MR1I_SHIFT | CTIMER_MCR_MR2I_SHIFT | CTIMER_MCR_MR3I_SHIFT);
Kojto 148:fd96258d940d 346
Kojto 148:fd96258d940d 347 /* Get all the capture interrupts enabled */
Kojto 148:fd96258d940d 348 enabledIntrs |=
Kojto 148:fd96258d940d 349 base->CCR & (CTIMER_CCR_CAP0I_SHIFT | CTIMER_CCR_CAP1I_SHIFT | CTIMER_CCR_CAP2I_SHIFT | CTIMER_CCR_CAP3I_SHIFT);
Kojto 148:fd96258d940d 350
Kojto 148:fd96258d940d 351 return enabledIntrs;
Kojto 148:fd96258d940d 352 }
Kojto 148:fd96258d940d 353
Kojto 148:fd96258d940d 354 /*! @}*/
Kojto 148:fd96258d940d 355
Kojto 148:fd96258d940d 356 /*!
Kojto 148:fd96258d940d 357 * @name Status Interface
Kojto 148:fd96258d940d 358 * @{
Kojto 148:fd96258d940d 359 */
Kojto 148:fd96258d940d 360
Kojto 148:fd96258d940d 361 /*!
Kojto 148:fd96258d940d 362 * @brief Gets the Timer status flags.
Kojto 148:fd96258d940d 363 *
Kojto 148:fd96258d940d 364 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 365 *
Kojto 148:fd96258d940d 366 * @return The status flags. This is the logical OR of members of the
Kojto 148:fd96258d940d 367 * enumeration ::ctimer_status_flags_t
Kojto 148:fd96258d940d 368 */
Kojto 148:fd96258d940d 369 static inline uint32_t CTIMER_GetStatusFlags(CTIMER_Type *base)
Kojto 148:fd96258d940d 370 {
Kojto 148:fd96258d940d 371 return base->IR;
Kojto 148:fd96258d940d 372 }
Kojto 148:fd96258d940d 373
Kojto 148:fd96258d940d 374 /*!
Kojto 148:fd96258d940d 375 * @brief Clears the Timer status flags.
Kojto 148:fd96258d940d 376 *
Kojto 148:fd96258d940d 377 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 378 * @param mask The status flags to clear. This is a logical OR of members of the
Kojto 148:fd96258d940d 379 * enumeration ::ctimer_status_flags_t
Kojto 148:fd96258d940d 380 */
Kojto 148:fd96258d940d 381 static inline void CTIMER_ClearStatusFlags(CTIMER_Type *base, uint32_t mask)
Kojto 148:fd96258d940d 382 {
Kojto 148:fd96258d940d 383 base->IR = mask;
Kojto 148:fd96258d940d 384 }
Kojto 148:fd96258d940d 385
Kojto 148:fd96258d940d 386 /*! @}*/
Kojto 148:fd96258d940d 387
Kojto 148:fd96258d940d 388 /*!
Kojto 148:fd96258d940d 389 * @name Counter Start and Stop
Kojto 148:fd96258d940d 390 * @{
Kojto 148:fd96258d940d 391 */
Kojto 148:fd96258d940d 392
Kojto 148:fd96258d940d 393 /*!
Kojto 148:fd96258d940d 394 * @brief Starts the Timer counter.
Kojto 148:fd96258d940d 395 *
Kojto 148:fd96258d940d 396 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 397 */
Kojto 148:fd96258d940d 398 static inline void CTIMER_StartTimer(CTIMER_Type *base)
Kojto 148:fd96258d940d 399 {
Kojto 148:fd96258d940d 400 base->TCR |= CTIMER_TCR_CEN_MASK;
Kojto 148:fd96258d940d 401 }
Kojto 148:fd96258d940d 402
Kojto 148:fd96258d940d 403 /*!
Kojto 148:fd96258d940d 404 * @brief Stops the Timer counter.
Kojto 148:fd96258d940d 405 *
Kojto 148:fd96258d940d 406 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 407 */
Kojto 148:fd96258d940d 408 static inline void CTIMER_StopTimer(CTIMER_Type *base)
Kojto 148:fd96258d940d 409 {
Kojto 148:fd96258d940d 410 base->TCR &= ~CTIMER_TCR_CEN_MASK;
Kojto 148:fd96258d940d 411 }
Kojto 148:fd96258d940d 412
Kojto 148:fd96258d940d 413 /*! @}*/
Kojto 148:fd96258d940d 414
Kojto 148:fd96258d940d 415 /*!
Kojto 148:fd96258d940d 416 * @brief Reset the counter.
Kojto 148:fd96258d940d 417 *
Kojto 148:fd96258d940d 418 * The timer counter and prescale counter are reset on the next positive edge of the APB clock.
Kojto 148:fd96258d940d 419 *
Kojto 148:fd96258d940d 420 * @param base Ctimer peripheral base address
Kojto 148:fd96258d940d 421 */
Kojto 148:fd96258d940d 422 static inline void CTIMER_Reset(CTIMER_Type *base)
Kojto 148:fd96258d940d 423 {
Kojto 148:fd96258d940d 424 base->TCR |= CTIMER_TCR_CRST_MASK;
Kojto 148:fd96258d940d 425 base->TCR &= ~CTIMER_TCR_CRST_MASK;
Kojto 148:fd96258d940d 426 }
Kojto 148:fd96258d940d 427
Kojto 148:fd96258d940d 428 #if defined(__cplusplus)
Kojto 148:fd96258d940d 429 }
Kojto 148:fd96258d940d 430 #endif
Kojto 148:fd96258d940d 431
Kojto 148:fd96258d940d 432 /*! @}*/
Kojto 148:fd96258d940d 433
Kojto 148:fd96258d940d 434 #endif /* _FSL_CTIMER_H_ */