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:
Thu Nov 08 11:45:42 2018 +0000
Revision:
171:3a7713b1edbc
Parent:
TARGET_RO359B/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K24F/drivers/fsl_cmt.h@143:86740a56073b
mbed library. Release version 164

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 143:86740a56073b 1 /*
AnnaBridge 143:86740a56073b 2 * Copyright (c) 2015, Freescale Semiconductor, Inc.
AnnaBridge 143:86740a56073b 3 * Copyright 2016-2017 NXP
AnnaBridge 143:86740a56073b 4 *
AnnaBridge 143:86740a56073b 5 * Redistribution and use in source and binary forms, with or without modification,
AnnaBridge 143:86740a56073b 6 * are permitted provided that the following conditions are met:
AnnaBridge 143:86740a56073b 7 *
AnnaBridge 143:86740a56073b 8 * o Redistributions of source code must retain the above copyright notice, this list
AnnaBridge 143:86740a56073b 9 * of conditions and the following disclaimer.
AnnaBridge 143:86740a56073b 10 *
AnnaBridge 143:86740a56073b 11 * o Redistributions in binary form must reproduce the above copyright notice, this
AnnaBridge 143:86740a56073b 12 * list of conditions and the following disclaimer in the documentation and/or
AnnaBridge 143:86740a56073b 13 * other materials provided with the distribution.
AnnaBridge 143:86740a56073b 14 *
AnnaBridge 143:86740a56073b 15 * o Neither the name of the copyright holder nor the names of its
AnnaBridge 143:86740a56073b 16 * contributors may be used to endorse or promote products derived from this
AnnaBridge 143:86740a56073b 17 * software without specific prior written permission.
AnnaBridge 143:86740a56073b 18 *
AnnaBridge 143:86740a56073b 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
AnnaBridge 143:86740a56073b 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
AnnaBridge 143:86740a56073b 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
AnnaBridge 143:86740a56073b 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
AnnaBridge 143:86740a56073b 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
AnnaBridge 143:86740a56073b 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
AnnaBridge 143:86740a56073b 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
AnnaBridge 143:86740a56073b 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
AnnaBridge 143:86740a56073b 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
AnnaBridge 143:86740a56073b 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
AnnaBridge 143:86740a56073b 29 */
AnnaBridge 143:86740a56073b 30 #ifndef _FSL_CMT_H_
AnnaBridge 143:86740a56073b 31 #define _FSL_CMT_H_
AnnaBridge 143:86740a56073b 32
AnnaBridge 143:86740a56073b 33 #include "fsl_common.h"
AnnaBridge 143:86740a56073b 34
AnnaBridge 143:86740a56073b 35 /*!
AnnaBridge 143:86740a56073b 36 * @addtogroup cmt
AnnaBridge 143:86740a56073b 37 * @{
AnnaBridge 143:86740a56073b 38 */
AnnaBridge 143:86740a56073b 39
AnnaBridge 143:86740a56073b 40
AnnaBridge 143:86740a56073b 41 /*******************************************************************************
AnnaBridge 143:86740a56073b 42 * Definitions
AnnaBridge 143:86740a56073b 43 ******************************************************************************/
AnnaBridge 143:86740a56073b 44
AnnaBridge 143:86740a56073b 45 /*! @name Driver version */
AnnaBridge 143:86740a56073b 46 /*@{*/
AnnaBridge 143:86740a56073b 47 /*! @brief CMT driver version 2.0.1. */
AnnaBridge 143:86740a56073b 48 #define FSL_CMT_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
AnnaBridge 143:86740a56073b 49 /*@}*/
AnnaBridge 143:86740a56073b 50
AnnaBridge 143:86740a56073b 51 /*!
AnnaBridge 143:86740a56073b 52 * @brief The modes of CMT.
AnnaBridge 143:86740a56073b 53 */
AnnaBridge 143:86740a56073b 54 typedef enum _cmt_mode
AnnaBridge 143:86740a56073b 55 {
AnnaBridge 143:86740a56073b 56 kCMT_DirectIROCtl = 0x00U, /*!< Carrier modulator is disabled and the IRO signal is directly in software control */
AnnaBridge 143:86740a56073b 57 kCMT_TimeMode = 0x01U, /*!< Carrier modulator is enabled in time mode. */
AnnaBridge 143:86740a56073b 58 kCMT_FSKMode = 0x05U, /*!< Carrier modulator is enabled in FSK mode. */
AnnaBridge 143:86740a56073b 59 kCMT_BasebandMode = 0x09U /*!< Carrier modulator is enabled in baseband mode. */
AnnaBridge 143:86740a56073b 60 } cmt_mode_t;
AnnaBridge 143:86740a56073b 61
AnnaBridge 143:86740a56073b 62 /*!
AnnaBridge 143:86740a56073b 63 * @brief The CMT clock divide primary prescaler.
AnnaBridge 143:86740a56073b 64 * The primary clock divider is used to divider the bus clock to
AnnaBridge 143:86740a56073b 65 * get the intermediate frequency to approximately equal to 8 MHZ.
AnnaBridge 143:86740a56073b 66 * When the bus clock is 8 MHZ, set primary prescaler to "kCMT_PrimaryClkDiv1".
AnnaBridge 143:86740a56073b 67 */
AnnaBridge 143:86740a56073b 68 typedef enum _cmt_primary_clkdiv
AnnaBridge 143:86740a56073b 69 {
AnnaBridge 143:86740a56073b 70 kCMT_PrimaryClkDiv1 = 0U, /*!< The intermediate frequency is the bus clock divided by 1. */
AnnaBridge 143:86740a56073b 71 kCMT_PrimaryClkDiv2 = 1U, /*!< The intermediate frequency is the bus clock divided by 2. */
AnnaBridge 143:86740a56073b 72 kCMT_PrimaryClkDiv3 = 2U, /*!< The intermediate frequency is the bus clock divided by 3. */
AnnaBridge 143:86740a56073b 73 kCMT_PrimaryClkDiv4 = 3U, /*!< The intermediate frequency is the bus clock divided by 4. */
AnnaBridge 143:86740a56073b 74 kCMT_PrimaryClkDiv5 = 4U, /*!< The intermediate frequency is the bus clock divided by 5. */
AnnaBridge 143:86740a56073b 75 kCMT_PrimaryClkDiv6 = 5U, /*!< The intermediate frequency is the bus clock divided by 6. */
AnnaBridge 143:86740a56073b 76 kCMT_PrimaryClkDiv7 = 6U, /*!< The intermediate frequency is the bus clock divided by 7. */
AnnaBridge 143:86740a56073b 77 kCMT_PrimaryClkDiv8 = 7U, /*!< The intermediate frequency is the bus clock divided by 8. */
AnnaBridge 143:86740a56073b 78 kCMT_PrimaryClkDiv9 = 8U, /*!< The intermediate frequency is the bus clock divided by 9. */
AnnaBridge 143:86740a56073b 79 kCMT_PrimaryClkDiv10 = 9U, /*!< The intermediate frequency is the bus clock divided by 10. */
AnnaBridge 143:86740a56073b 80 kCMT_PrimaryClkDiv11 = 10U, /*!< The intermediate frequency is the bus clock divided by 11. */
AnnaBridge 143:86740a56073b 81 kCMT_PrimaryClkDiv12 = 11U, /*!< The intermediate frequency is the bus clock divided by 12. */
AnnaBridge 143:86740a56073b 82 kCMT_PrimaryClkDiv13 = 12U, /*!< The intermediate frequency is the bus clock divided by 13. */
AnnaBridge 143:86740a56073b 83 kCMT_PrimaryClkDiv14 = 13U, /*!< The intermediate frequency is the bus clock divided by 14. */
AnnaBridge 143:86740a56073b 84 kCMT_PrimaryClkDiv15 = 14U, /*!< The intermediate frequency is the bus clock divided by 15. */
AnnaBridge 143:86740a56073b 85 kCMT_PrimaryClkDiv16 = 15U /*!< The intermediate frequency is the bus clock divided by 16. */
AnnaBridge 143:86740a56073b 86 } cmt_primary_clkdiv_t;
AnnaBridge 143:86740a56073b 87
AnnaBridge 143:86740a56073b 88 /*!
AnnaBridge 143:86740a56073b 89 * @brief The CMT clock divide secondary prescaler.
AnnaBridge 143:86740a56073b 90 * The second prescaler can be used to divide the 8 MHZ CMT clock
AnnaBridge 143:86740a56073b 91 * by 1, 2, 4, or 8 according to the specification.
AnnaBridge 143:86740a56073b 92 */
AnnaBridge 143:86740a56073b 93 typedef enum _cmt_second_clkdiv
AnnaBridge 143:86740a56073b 94 {
AnnaBridge 143:86740a56073b 95 kCMT_SecondClkDiv1 = 0U, /*!< The CMT clock is the intermediate frequency frequency divided by 1. */
AnnaBridge 143:86740a56073b 96 kCMT_SecondClkDiv2 = 1U, /*!< The CMT clock is the intermediate frequency frequency divided by 2. */
AnnaBridge 143:86740a56073b 97 kCMT_SecondClkDiv4 = 2U, /*!< The CMT clock is the intermediate frequency frequency divided by 4. */
AnnaBridge 143:86740a56073b 98 kCMT_SecondClkDiv8 = 3U /*!< The CMT clock is the intermediate frequency frequency divided by 8. */
AnnaBridge 143:86740a56073b 99 } cmt_second_clkdiv_t;
AnnaBridge 143:86740a56073b 100
AnnaBridge 143:86740a56073b 101 /*!
AnnaBridge 143:86740a56073b 102 * @brief The CMT infrared output polarity.
AnnaBridge 143:86740a56073b 103 */
AnnaBridge 143:86740a56073b 104 typedef enum _cmt_infrared_output_polarity
AnnaBridge 143:86740a56073b 105 {
AnnaBridge 143:86740a56073b 106 kCMT_IROActiveLow = 0U, /*!< The CMT infrared output signal polarity is active-low. */
AnnaBridge 143:86740a56073b 107 kCMT_IROActiveHigh = 1U /*!< The CMT infrared output signal polarity is active-high. */
AnnaBridge 143:86740a56073b 108 } cmt_infrared_output_polarity_t;
AnnaBridge 143:86740a56073b 109
AnnaBridge 143:86740a56073b 110 /*!
AnnaBridge 143:86740a56073b 111 * @brief The CMT infrared output signal state control.
AnnaBridge 143:86740a56073b 112 */
AnnaBridge 143:86740a56073b 113 typedef enum _cmt_infrared_output_state
AnnaBridge 143:86740a56073b 114 {
AnnaBridge 143:86740a56073b 115 kCMT_IROCtlLow = 0U, /*!< The CMT Infrared output signal state is controlled to low. */
AnnaBridge 143:86740a56073b 116 kCMT_IROCtlHigh = 1U /*!< The CMT Infrared output signal state is controlled to high. */
AnnaBridge 143:86740a56073b 117 } cmt_infrared_output_state_t;
AnnaBridge 143:86740a56073b 118
AnnaBridge 143:86740a56073b 119 /*!
AnnaBridge 143:86740a56073b 120 * @brief CMT interrupt configuration structure, default settings all disabled.
AnnaBridge 143:86740a56073b 121 *
AnnaBridge 143:86740a56073b 122 * This structure contains the settings for all of the CMT interrupt configurations.
AnnaBridge 143:86740a56073b 123 */
AnnaBridge 143:86740a56073b 124 enum _cmt_interrupt_enable
AnnaBridge 143:86740a56073b 125 {
AnnaBridge 143:86740a56073b 126 kCMT_EndOfCycleInterruptEnable = CMT_MSC_EOCIE_MASK, /*!< CMT end of cycle interrupt. */
AnnaBridge 143:86740a56073b 127 };
AnnaBridge 143:86740a56073b 128
AnnaBridge 143:86740a56073b 129 /*!
AnnaBridge 143:86740a56073b 130 * @brief CMT carrier generator and modulator configuration structure
AnnaBridge 143:86740a56073b 131 *
AnnaBridge 143:86740a56073b 132 */
AnnaBridge 143:86740a56073b 133 typedef struct _cmt_modulate_config
AnnaBridge 143:86740a56073b 134 {
AnnaBridge 143:86740a56073b 135 uint8_t highCount1; /*!< The high-time for carrier generator first register. */
AnnaBridge 143:86740a56073b 136 uint8_t lowCount1; /*!< The low-time for carrier generator first register. */
AnnaBridge 143:86740a56073b 137 uint8_t highCount2; /*!< The high-time for carrier generator second register for FSK mode. */
AnnaBridge 143:86740a56073b 138 uint8_t lowCount2; /*!< The low-time for carrier generator second register for FSK mode. */
AnnaBridge 143:86740a56073b 139 uint16_t markCount; /*!< The mark time for the modulator gate. */
AnnaBridge 143:86740a56073b 140 uint16_t spaceCount; /*!< The space time for the modulator gate. */
AnnaBridge 143:86740a56073b 141 } cmt_modulate_config_t;
AnnaBridge 143:86740a56073b 142
AnnaBridge 143:86740a56073b 143 /*! @brief CMT basic configuration structure. */
AnnaBridge 143:86740a56073b 144 typedef struct _cmt_config
AnnaBridge 143:86740a56073b 145 {
AnnaBridge 143:86740a56073b 146 bool isInterruptEnabled; /*!< Timer interrupt 0-disable, 1-enable. */
AnnaBridge 143:86740a56073b 147 bool isIroEnabled; /*!< The IRO output 0-disabled, 1-enabled. */
AnnaBridge 143:86740a56073b 148 cmt_infrared_output_polarity_t iroPolarity; /*!< The IRO polarity. */
AnnaBridge 143:86740a56073b 149 cmt_second_clkdiv_t divider; /*!< The CMT clock divide prescaler. */
AnnaBridge 143:86740a56073b 150 } cmt_config_t;
AnnaBridge 143:86740a56073b 151
AnnaBridge 143:86740a56073b 152 /*******************************************************************************
AnnaBridge 143:86740a56073b 153 * API
AnnaBridge 143:86740a56073b 154 ******************************************************************************/
AnnaBridge 143:86740a56073b 155
AnnaBridge 143:86740a56073b 156 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 157 extern "C" {
AnnaBridge 143:86740a56073b 158 #endif
AnnaBridge 143:86740a56073b 159
AnnaBridge 143:86740a56073b 160 /*!
AnnaBridge 143:86740a56073b 161 * @name Initialization and deinitialization
AnnaBridge 143:86740a56073b 162 * @{
AnnaBridge 143:86740a56073b 163 */
AnnaBridge 143:86740a56073b 164
AnnaBridge 143:86740a56073b 165 /*!
AnnaBridge 143:86740a56073b 166 * @brief Gets the CMT default configuration structure. This API
AnnaBridge 143:86740a56073b 167 * gets the default configuration structure for the CMT_Init().
AnnaBridge 143:86740a56073b 168 * Use the initialized structure unchanged in CMT_Init() or modify
AnnaBridge 143:86740a56073b 169 * fields of the structure before calling the CMT_Init().
AnnaBridge 143:86740a56073b 170 *
AnnaBridge 143:86740a56073b 171 * @param config The CMT configuration structure pointer.
AnnaBridge 143:86740a56073b 172 */
AnnaBridge 143:86740a56073b 173 void CMT_GetDefaultConfig(cmt_config_t *config);
AnnaBridge 143:86740a56073b 174
AnnaBridge 143:86740a56073b 175 /*!
AnnaBridge 143:86740a56073b 176 * @brief Initializes the CMT module.
AnnaBridge 143:86740a56073b 177 *
AnnaBridge 143:86740a56073b 178 * This function ungates the module clock and sets the CMT internal clock,
AnnaBridge 143:86740a56073b 179 * interrupt, and infrared output signal for the CMT module.
AnnaBridge 143:86740a56073b 180 *
AnnaBridge 143:86740a56073b 181 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 182 * @param config The CMT basic configuration structure.
AnnaBridge 143:86740a56073b 183 * @param busClock_Hz The CMT module input clock - bus clock frequency.
AnnaBridge 143:86740a56073b 184 */
AnnaBridge 143:86740a56073b 185 void CMT_Init(CMT_Type *base, const cmt_config_t *config, uint32_t busClock_Hz);
AnnaBridge 143:86740a56073b 186
AnnaBridge 143:86740a56073b 187 /*!
AnnaBridge 143:86740a56073b 188 * @brief Disables the CMT module and gate control.
AnnaBridge 143:86740a56073b 189 *
AnnaBridge 143:86740a56073b 190 * This function disables CMT modulator, interrupts, and gates the
AnnaBridge 143:86740a56073b 191 * CMT clock control. CMT_Init must be called to use the CMT again.
AnnaBridge 143:86740a56073b 192 *
AnnaBridge 143:86740a56073b 193 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 194 */
AnnaBridge 143:86740a56073b 195 void CMT_Deinit(CMT_Type *base);
AnnaBridge 143:86740a56073b 196
AnnaBridge 143:86740a56073b 197 /*! @}*/
AnnaBridge 143:86740a56073b 198
AnnaBridge 143:86740a56073b 199 /*!
AnnaBridge 143:86740a56073b 200 * @name Basic Control Operations
AnnaBridge 143:86740a56073b 201 * @{
AnnaBridge 143:86740a56073b 202 */
AnnaBridge 143:86740a56073b 203
AnnaBridge 143:86740a56073b 204 /*!
AnnaBridge 143:86740a56073b 205 * @brief Selects the mode for CMT.
AnnaBridge 143:86740a56073b 206 *
AnnaBridge 143:86740a56073b 207 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 208 * @param mode The CMT feature mode enumeration. See "cmt_mode_t".
AnnaBridge 143:86740a56073b 209 * @param modulateConfig The carrier generation and modulator configuration.
AnnaBridge 143:86740a56073b 210 */
AnnaBridge 143:86740a56073b 211 void CMT_SetMode(CMT_Type *base, cmt_mode_t mode, cmt_modulate_config_t *modulateConfig);
AnnaBridge 143:86740a56073b 212
AnnaBridge 143:86740a56073b 213 /*!
AnnaBridge 143:86740a56073b 214 * @brief Gets the mode of the CMT module.
AnnaBridge 143:86740a56073b 215 *
AnnaBridge 143:86740a56073b 216 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 217 * @return The CMT mode.
AnnaBridge 143:86740a56073b 218 * kCMT_DirectIROCtl Carrier modulator is disabled; the IRO signal is directly in software control.
AnnaBridge 143:86740a56073b 219 * kCMT_TimeMode Carrier modulator is enabled in time mode.
AnnaBridge 143:86740a56073b 220 * kCMT_FSKMode Carrier modulator is enabled in FSK mode.
AnnaBridge 143:86740a56073b 221 * kCMT_BasebandMode Carrier modulator is enabled in baseband mode.
AnnaBridge 143:86740a56073b 222 */
AnnaBridge 143:86740a56073b 223 cmt_mode_t CMT_GetMode(CMT_Type *base);
AnnaBridge 143:86740a56073b 224
AnnaBridge 143:86740a56073b 225 /*!
AnnaBridge 143:86740a56073b 226 * @brief Gets the actual CMT clock frequency.
AnnaBridge 143:86740a56073b 227 *
AnnaBridge 143:86740a56073b 228 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 229 * @param busClock_Hz CMT module input clock - bus clock frequency.
AnnaBridge 143:86740a56073b 230 * @return The CMT clock frequency.
AnnaBridge 143:86740a56073b 231 */
AnnaBridge 143:86740a56073b 232 uint32_t CMT_GetCMTFrequency(CMT_Type *base, uint32_t busClock_Hz);
AnnaBridge 143:86740a56073b 233
AnnaBridge 143:86740a56073b 234 /*!
AnnaBridge 143:86740a56073b 235 * @brief Sets the primary data set for the CMT carrier generator counter.
AnnaBridge 143:86740a56073b 236 *
AnnaBridge 143:86740a56073b 237 * This function sets the high-time and low-time of the primary data set for the
AnnaBridge 143:86740a56073b 238 * CMT carrier generator counter to control the period and the duty cycle of the
AnnaBridge 143:86740a56073b 239 * output carrier signal.
AnnaBridge 143:86740a56073b 240 * If the CMT clock period is Tcmt, the period of the carrier generator signal equals
AnnaBridge 143:86740a56073b 241 * (highCount + lowCount) * Tcmt. The duty cycle equals to highCount / (highCount + lowCount).
AnnaBridge 143:86740a56073b 242 *
AnnaBridge 143:86740a56073b 243 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 244 * @param highCount The number of CMT clocks for carrier generator signal high time,
AnnaBridge 143:86740a56073b 245 * integer in the range of 1 ~ 0xFF.
AnnaBridge 143:86740a56073b 246 * @param lowCount The number of CMT clocks for carrier generator signal low time,
AnnaBridge 143:86740a56073b 247 * integer in the range of 1 ~ 0xFF.
AnnaBridge 143:86740a56073b 248 */
AnnaBridge 143:86740a56073b 249 static inline void CMT_SetCarrirGenerateCountOne(CMT_Type *base, uint32_t highCount, uint32_t lowCount)
AnnaBridge 143:86740a56073b 250 {
AnnaBridge 143:86740a56073b 251 assert(highCount <= CMT_CGH1_PH_MASK);
AnnaBridge 143:86740a56073b 252 assert(highCount);
AnnaBridge 143:86740a56073b 253 assert(lowCount <= CMT_CGL1_PL_MASK);
AnnaBridge 143:86740a56073b 254 assert(lowCount);
AnnaBridge 143:86740a56073b 255
AnnaBridge 143:86740a56073b 256 base->CGH1 = highCount;
AnnaBridge 143:86740a56073b 257 base->CGL1 = lowCount;
AnnaBridge 143:86740a56073b 258 }
AnnaBridge 143:86740a56073b 259
AnnaBridge 143:86740a56073b 260 /*!
AnnaBridge 143:86740a56073b 261 * @brief Sets the secondary data set for the CMT carrier generator counter.
AnnaBridge 143:86740a56073b 262 *
AnnaBridge 143:86740a56073b 263 * This function is used for FSK mode setting the high-time and low-time of the secondary
AnnaBridge 143:86740a56073b 264 * data set CMT carrier generator counter to control the period and the duty cycle
AnnaBridge 143:86740a56073b 265 * of the output carrier signal.
AnnaBridge 143:86740a56073b 266 * If the CMT clock period is Tcmt, the period of the carrier generator signal equals
AnnaBridge 143:86740a56073b 267 * (highCount + lowCount) * Tcmt. The duty cycle equals highCount / (highCount + lowCount).
AnnaBridge 143:86740a56073b 268 *
AnnaBridge 143:86740a56073b 269 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 270 * @param highCount The number of CMT clocks for carrier generator signal high time,
AnnaBridge 143:86740a56073b 271 * integer in the range of 1 ~ 0xFF.
AnnaBridge 143:86740a56073b 272 * @param lowCount The number of CMT clocks for carrier generator signal low time,
AnnaBridge 143:86740a56073b 273 * integer in the range of 1 ~ 0xFF.
AnnaBridge 143:86740a56073b 274 */
AnnaBridge 143:86740a56073b 275 static inline void CMT_SetCarrirGenerateCountTwo(CMT_Type *base, uint32_t highCount, uint32_t lowCount)
AnnaBridge 143:86740a56073b 276 {
AnnaBridge 143:86740a56073b 277 assert(highCount <= CMT_CGH2_SH_MASK);
AnnaBridge 143:86740a56073b 278 assert(highCount);
AnnaBridge 143:86740a56073b 279 assert(lowCount <= CMT_CGL2_SL_MASK);
AnnaBridge 143:86740a56073b 280 assert(lowCount);
AnnaBridge 143:86740a56073b 281
AnnaBridge 143:86740a56073b 282 base->CGH2 = highCount;
AnnaBridge 143:86740a56073b 283 base->CGL2 = lowCount;
AnnaBridge 143:86740a56073b 284 }
AnnaBridge 143:86740a56073b 285
AnnaBridge 143:86740a56073b 286 /*!
AnnaBridge 143:86740a56073b 287 * @brief Sets the modulation mark and space time period for the CMT modulator.
AnnaBridge 143:86740a56073b 288 *
AnnaBridge 143:86740a56073b 289 * This function sets the mark time period of the CMT modulator counter
AnnaBridge 143:86740a56073b 290 * to control the mark time of the output modulated signal from the carrier generator output signal.
AnnaBridge 143:86740a56073b 291 * If the CMT clock frequency is Fcmt and the carrier out signal frequency is fcg:
AnnaBridge 143:86740a56073b 292 * - In Time and Baseband mode: The mark period of the generated signal equals (markCount + 1) / (Fcmt/8).
AnnaBridge 143:86740a56073b 293 * The space period of the generated signal equals spaceCount / (Fcmt/8).
AnnaBridge 143:86740a56073b 294 * - In FSK mode: The mark period of the generated signal equals (markCount + 1)/fcg.
AnnaBridge 143:86740a56073b 295 * The space period of the generated signal equals spaceCount / fcg.
AnnaBridge 143:86740a56073b 296 *
AnnaBridge 143:86740a56073b 297 * @param base Base address for current CMT instance.
AnnaBridge 143:86740a56073b 298 * @param markCount The number of clock period for CMT modulator signal mark period,
AnnaBridge 143:86740a56073b 299 * in the range of 0 ~ 0xFFFF.
AnnaBridge 143:86740a56073b 300 * @param spaceCount The number of clock period for CMT modulator signal space period,
AnnaBridge 143:86740a56073b 301 * in the range of the 0 ~ 0xFFFF.
AnnaBridge 143:86740a56073b 302 */
AnnaBridge 143:86740a56073b 303 void CMT_SetModulateMarkSpace(CMT_Type *base, uint32_t markCount, uint32_t spaceCount);
AnnaBridge 143:86740a56073b 304
AnnaBridge 143:86740a56073b 305 /*!
AnnaBridge 143:86740a56073b 306 * @brief Enables or disables the extended space operation.
AnnaBridge 143:86740a56073b 307 *
AnnaBridge 143:86740a56073b 308 * This function is used to make the space period longer
AnnaBridge 143:86740a56073b 309 * for time, baseband, and FSK modes.
AnnaBridge 143:86740a56073b 310 *
AnnaBridge 143:86740a56073b 311 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 312 * @param enable True enable the extended space, false disable the extended space.
AnnaBridge 143:86740a56073b 313 */
AnnaBridge 143:86740a56073b 314 static inline void CMT_EnableExtendedSpace(CMT_Type *base, bool enable)
AnnaBridge 143:86740a56073b 315 {
AnnaBridge 143:86740a56073b 316 if (enable)
AnnaBridge 143:86740a56073b 317 {
AnnaBridge 143:86740a56073b 318 base->MSC |= CMT_MSC_EXSPC_MASK;
AnnaBridge 143:86740a56073b 319 }
AnnaBridge 143:86740a56073b 320 else
AnnaBridge 143:86740a56073b 321 {
AnnaBridge 143:86740a56073b 322 base->MSC &= ~CMT_MSC_EXSPC_MASK;
AnnaBridge 143:86740a56073b 323 }
AnnaBridge 143:86740a56073b 324 }
AnnaBridge 143:86740a56073b 325
AnnaBridge 143:86740a56073b 326 /*!
AnnaBridge 143:86740a56073b 327 * @brief Sets the IRO (infrared output) signal state.
AnnaBridge 143:86740a56073b 328 *
AnnaBridge 143:86740a56073b 329 * Changes the states of the IRO signal when the kCMT_DirectIROMode mode is set
AnnaBridge 143:86740a56073b 330 * and the IRO signal is enabled.
AnnaBridge 143:86740a56073b 331 *
AnnaBridge 143:86740a56073b 332 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 333 * @param state The control of the IRO signal. See "cmt_infrared_output_state_t"
AnnaBridge 143:86740a56073b 334 */
AnnaBridge 143:86740a56073b 335 void CMT_SetIroState(CMT_Type *base, cmt_infrared_output_state_t state);
AnnaBridge 143:86740a56073b 336
AnnaBridge 143:86740a56073b 337 /*!
AnnaBridge 143:86740a56073b 338 * @brief Enables the CMT interrupt.
AnnaBridge 143:86740a56073b 339 *
AnnaBridge 143:86740a56073b 340 * This function enables the CMT interrupts according to the provided mask if enabled.
AnnaBridge 143:86740a56073b 341 * The CMT only has the end of the cycle interrupt - an interrupt occurs at the end
AnnaBridge 143:86740a56073b 342 * of the modulator cycle. This interrupt provides a means for the user
AnnaBridge 143:86740a56073b 343 * to reload the new mark/space values into the CMT modulator data registers
AnnaBridge 143:86740a56073b 344 * and verify the modulator mark and space.
AnnaBridge 143:86740a56073b 345 * For example, to enable the end of cycle, do the following.
AnnaBridge 143:86740a56073b 346 * @code
AnnaBridge 143:86740a56073b 347 * CMT_EnableInterrupts(CMT, kCMT_EndOfCycleInterruptEnable);
AnnaBridge 143:86740a56073b 348 * @endcode
AnnaBridge 143:86740a56073b 349 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 350 * @param mask The interrupts to enable. Logical OR of @ref _cmt_interrupt_enable.
AnnaBridge 143:86740a56073b 351 */
AnnaBridge 143:86740a56073b 352 static inline void CMT_EnableInterrupts(CMT_Type *base, uint32_t mask)
AnnaBridge 143:86740a56073b 353 {
AnnaBridge 143:86740a56073b 354 base->MSC |= mask;
AnnaBridge 143:86740a56073b 355 }
AnnaBridge 143:86740a56073b 356
AnnaBridge 143:86740a56073b 357 /*!
AnnaBridge 143:86740a56073b 358 * @brief Disables the CMT interrupt.
AnnaBridge 143:86740a56073b 359 *
AnnaBridge 143:86740a56073b 360 * This function disables the CMT interrupts according to the provided maskIf enabled.
AnnaBridge 143:86740a56073b 361 * The CMT only has the end of the cycle interrupt.
AnnaBridge 143:86740a56073b 362 * For example, to disable the end of cycle, do the following.
AnnaBridge 143:86740a56073b 363 * @code
AnnaBridge 143:86740a56073b 364 * CMT_DisableInterrupts(CMT, kCMT_EndOfCycleInterruptEnable);
AnnaBridge 143:86740a56073b 365 * @endcode
AnnaBridge 143:86740a56073b 366 *
AnnaBridge 143:86740a56073b 367 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 368 * @param mask The interrupts to enable. Logical OR of @ref _cmt_interrupt_enable.
AnnaBridge 143:86740a56073b 369 */
AnnaBridge 143:86740a56073b 370 static inline void CMT_DisableInterrupts(CMT_Type *base, uint32_t mask)
AnnaBridge 143:86740a56073b 371 {
AnnaBridge 143:86740a56073b 372 base->MSC &= ~mask;
AnnaBridge 143:86740a56073b 373 }
AnnaBridge 143:86740a56073b 374
AnnaBridge 143:86740a56073b 375 /*!
AnnaBridge 143:86740a56073b 376 * @brief Gets the end of the cycle status flag.
AnnaBridge 143:86740a56073b 377 *
AnnaBridge 143:86740a56073b 378 * The flag is set:
AnnaBridge 143:86740a56073b 379 * - When the modulator is not currently active and carrier and modulator
AnnaBridge 143:86740a56073b 380 * are set to start the initial CMT transmission.
AnnaBridge 143:86740a56073b 381 * - At the end of each modulation cycle when the counter is reloaded and
AnnaBridge 143:86740a56073b 382 * the carrier and modulator are enabled.
AnnaBridge 143:86740a56073b 383 * @param base CMT peripheral base address.
AnnaBridge 143:86740a56073b 384 * @return Current status of the end of cycle status flag
AnnaBridge 143:86740a56073b 385 * @arg non-zero: End-of-cycle has occurred.
AnnaBridge 143:86740a56073b 386 * @arg zero: End-of-cycle has not yet occurred since the flag last cleared.
AnnaBridge 143:86740a56073b 387 */
AnnaBridge 143:86740a56073b 388 static inline uint32_t CMT_GetStatusFlags(CMT_Type *base)
AnnaBridge 143:86740a56073b 389 {
AnnaBridge 143:86740a56073b 390 return base->MSC & CMT_MSC_EOCF_MASK;
AnnaBridge 143:86740a56073b 391 }
AnnaBridge 143:86740a56073b 392
AnnaBridge 143:86740a56073b 393 /*! @}*/
AnnaBridge 143:86740a56073b 394
AnnaBridge 143:86740a56073b 395 #if defined(__cplusplus)
AnnaBridge 143:86740a56073b 396 }
AnnaBridge 143:86740a56073b 397 #endif
AnnaBridge 143:86740a56073b 398
AnnaBridge 143:86740a56073b 399 /*! @}*/
AnnaBridge 143:86740a56073b 400
AnnaBridge 143:86740a56073b 401 #endif /* _FSL_CMT_H_*/