Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:59

0001 /*
0002  * Copyright (c) 2015, Freescale Semiconductor, Inc.
0003  * Copyright 2016-2017, 2020 NXP
0004  * All rights reserved.
0005  *
0006  * SPDX-License-Identifier: BSD-3-Clause
0007  */
0008 #ifndef _FSL_EWM_H_
0009 #define _FSL_EWM_H_
0010 
0011 #include "fsl_common.h"
0012 
0013 /*!
0014  * @addtogroup ewm
0015  * @{
0016  */
0017 
0018 /*******************************************************************************
0019  * Definitions
0020  *******************************************************************************/
0021 
0022 /*! @name Driver version */
0023 /*@{*/
0024 /*! @brief EWM driver version 2.0.3. */
0025 #define FSL_EWM_DRIVER_VERSION (MAKE_VERSION(2, 0, 3))
0026 /*@}*/
0027 
0028 /*! @brief Describes EWM clock source. */
0029 #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
0030 typedef enum _ewm_lpo_clock_source
0031 {
0032     kEWM_LpoClockSource0 = 0U, /*!< EWM clock sourced from lpo_clk[0]*/
0033     kEWM_LpoClockSource1 = 1U, /*!< EWM clock sourced from lpo_clk[1]*/
0034     kEWM_LpoClockSource2 = 2U, /*!< EWM clock sourced from lpo_clk[2]*/
0035     kEWM_LpoClockSource3 = 3U, /*!< EWM clock sourced from lpo_clk[3]*/
0036 } ewm_lpo_clock_source_t;
0037 #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
0038 
0039 /*!
0040  * @brief Data structure for EWM configuration.
0041  *
0042  * This structure is used to configure the EWM.
0043  */
0044 typedef struct _ewm_config
0045 {
0046     bool enableEwm;           /*!< Enable EWM module */
0047     bool enableEwmInput;      /*!< Enable EWM_in input */
0048     bool setInputAssertLogic; /*!< EWM_in signal assertion state */
0049     bool enableInterrupt;     /*!< Enable EWM interrupt */
0050 #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
0051     ewm_lpo_clock_source_t clockSource; /*!< Clock source select */
0052 #endif                                  /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT */
0053 #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
0054     uint8_t prescaler;        /*!< Clock prescaler value */
0055 #endif                        /* FSL_FEATURE_EWM_HAS_PRESCALER */
0056     uint8_t compareLowValue;  /*!< Compare low-register value */
0057     uint8_t compareHighValue; /*!< Compare high-register value */
0058 } ewm_config_t;
0059 
0060 /*!
0061  * @brief EWM interrupt configuration structure with default settings all disabled.
0062  *
0063  * This structure contains the settings for all of EWM interrupt configurations.
0064  */
0065 enum _ewm_interrupt_enable_t
0066 {
0067     kEWM_InterruptEnable = EWM_CTRL_INTEN_MASK, /*!< Enable the EWM to generate an interrupt*/
0068 };
0069 
0070 /*!
0071  * @brief EWM status flags.
0072  *
0073  * This structure contains the constants for the EWM status flags for use in the EWM functions.
0074  */
0075 enum _ewm_status_flags_t
0076 {
0077     kEWM_RunningFlag = EWM_CTRL_EWMEN_MASK, /*!< Running flag, set when EWM is enabled*/
0078 };
0079 
0080 /*******************************************************************************
0081  * API
0082  *******************************************************************************/
0083 
0084 #if defined(__cplusplus)
0085 extern "C" {
0086 #endif /* __cplusplus */
0087 
0088 /*!
0089  * @name EWM initialization and de-initialization
0090  * @{
0091  */
0092 
0093 /*!
0094  * @brief Initializes the EWM peripheral.
0095  *
0096  * This function is used to initialize the EWM. After calling, the EWM
0097  * runs immediately according to the configuration.
0098  * Note that, except for the interrupt enable control bit, other control bits and registers are write once after a
0099  * CPU reset. Modifying them more than once generates a bus transfer error.
0100  *
0101  * This is an example.
0102  * @code
0103  *   ewm_config_t config;
0104  *   EWM_GetDefaultConfig(&config);
0105  *   config.compareHighValue = 0xAAU;
0106  *   EWM_Init(ewm_base,&config);
0107  * @endcode
0108  *
0109  * @param base EWM peripheral base address
0110  * @param config The configuration of the EWM
0111  */
0112 void EWM_Init(EWM_Type *base, const ewm_config_t *config);
0113 
0114 /*!
0115  * @brief Deinitializes the EWM peripheral.
0116  *
0117  * This function is used to shut down the EWM.
0118  *
0119  * @param base EWM peripheral base address
0120  */
0121 void EWM_Deinit(EWM_Type *base);
0122 
0123 /*!
0124  * @brief Initializes the EWM configuration structure.
0125  *
0126  * This function initializes the EWM configuration structure to default values. The default
0127  * values are as follows.
0128  * @code
0129  *   ewmConfig->enableEwm = true;
0130  *   ewmConfig->enableEwmInput = false;
0131  *   ewmConfig->setInputAssertLogic = false;
0132  *   ewmConfig->enableInterrupt = false;
0133  *   ewmConfig->ewm_lpo_clock_source_t = kEWM_LpoClockSource0;
0134  *   ewmConfig->prescaler = 0;
0135  *   ewmConfig->compareLowValue = 0;
0136  *   ewmConfig->compareHighValue = 0xFEU;
0137  * @endcode
0138  *
0139  * @param config Pointer to the EWM configuration structure.
0140  * @see ewm_config_t
0141  */
0142 void EWM_GetDefaultConfig(ewm_config_t *config);
0143 
0144 /* @} */
0145 
0146 /*!
0147  * @name EWM functional Operation
0148  * @{
0149  */
0150 
0151 /*!
0152  * @brief Enables the EWM interrupt.
0153  *
0154  * This function enables the EWM interrupt.
0155  *
0156  * @param base EWM peripheral base address
0157  * @param mask The interrupts to enable
0158  *        The parameter can be combination of the following source if defined
0159  *        @arg kEWM_InterruptEnable
0160  */
0161 static inline void EWM_EnableInterrupts(EWM_Type *base, uint32_t mask)
0162 {
0163     base->CTRL |= (uint8_t)mask;
0164 }
0165 
0166 /*!
0167  * @brief Disables the EWM interrupt.
0168  *
0169  * This function enables the EWM interrupt.
0170  *
0171  * @param base EWM peripheral base address
0172  * @param mask The interrupts to disable
0173  *        The parameter can be combination of the following source if defined
0174  *        @arg kEWM_InterruptEnable
0175  */
0176 static inline void EWM_DisableInterrupts(EWM_Type *base, uint32_t mask)
0177 {
0178     base->CTRL &= (uint8_t)(~mask);
0179 }
0180 
0181 /*!
0182  * @brief Gets all status flags.
0183  *
0184  * This function gets all status flags.
0185  *
0186  * This is an example for getting the running flag.
0187  * @code
0188  *   uint32_t status;
0189  *   status = EWM_GetStatusFlags(ewm_base) & kEWM_RunningFlag;
0190  * @endcode
0191  * @param base        EWM peripheral base address
0192  * @return            State of the status flag: asserted (true) or not-asserted (false).@see _ewm_status_flags_t
0193  *                    - True: a related status flag has been set.
0194  *                    - False: a related status flag is not set.
0195  */
0196 static inline uint32_t EWM_GetStatusFlags(EWM_Type *base)
0197 {
0198     return ((uint32_t)base->CTRL & EWM_CTRL_EWMEN_MASK);
0199 }
0200 
0201 /*!
0202  * @brief Services the EWM.
0203  *
0204  * This function resets the EWM counter to zero.
0205  *
0206  * @param base EWM peripheral base address
0207  */
0208 void EWM_Refresh(EWM_Type *base);
0209 
0210 /*@}*/
0211 
0212 #if defined(__cplusplus)
0213 }
0214 #endif /* __cplusplus */
0215 
0216 /*! @}*/
0217 
0218 #endif /* _FSL_EWM_H_ */