fsl_ewm.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * The Clear BSD License
  3. * Copyright (c) 2015, Freescale Semiconductor, Inc.
  4. * Copyright 2016-2017 NXP
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without modification,
  8. * are permitted (subject to the limitations in the disclaimer below) provided
  9. * that the following conditions are met:
  10. *
  11. * o Redistributions of source code must retain the above copyright notice, this list
  12. * of conditions and the following disclaimer.
  13. *
  14. * o Redistributions in binary form must reproduce the above copyright notice, this
  15. * list of conditions and the following disclaimer in the documentation and/or
  16. * other materials provided with the distribution.
  17. *
  18. * o Neither the name of the copyright holder nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE.
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  24. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  25. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  26. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  27. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  28. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  29. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  30. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  31. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  32. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include "fsl_ewm.h"
  35. /* Component ID definition, used by tools. */
  36. #ifndef FSL_COMPONENT_ID
  37. #define FSL_COMPONENT_ID "platform.drivers.ewm"
  38. #endif
  39. /*******************************************************************************
  40. * Code
  41. ******************************************************************************/
  42. void EWM_Init(EWM_Type *base, const ewm_config_t *config)
  43. {
  44. assert(config);
  45. uint32_t value = 0U;
  46. #if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
  47. (defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
  48. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  49. CLOCK_EnableClock(kCLOCK_Ewm0);
  50. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  51. #endif
  52. value = EWM_CTRL_EWMEN(config->enableEwm) | EWM_CTRL_ASSIN(config->setInputAssertLogic) |
  53. EWM_CTRL_INEN(config->enableEwmInput) | EWM_CTRL_INTEN(config->enableInterrupt);
  54. #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
  55. base->CLKPRESCALER = config->prescaler;
  56. #endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
  57. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  58. base->CLKCTRL = config->clockSource;
  59. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
  60. base->CMPL = config->compareLowValue;
  61. base->CMPH = config->compareHighValue;
  62. base->CTRL = value;
  63. }
  64. void EWM_Deinit(EWM_Type *base)
  65. {
  66. EWM_DisableInterrupts(base, kEWM_InterruptEnable);
  67. #if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
  68. (defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
  69. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  70. CLOCK_DisableClock(kCLOCK_Ewm0);
  71. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  72. #endif /* FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE */
  73. }
  74. void EWM_GetDefaultConfig(ewm_config_t *config)
  75. {
  76. assert(config);
  77. config->enableEwm = true;
  78. config->enableEwmInput = false;
  79. config->setInputAssertLogic = false;
  80. config->enableInterrupt = false;
  81. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  82. config->clockSource = kEWM_LpoClockSource0;
  83. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
  84. #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
  85. config->prescaler = 0U;
  86. #endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
  87. config->compareLowValue = 0U;
  88. config->compareHighValue = 0xFEU;
  89. }
  90. void EWM_Refresh(EWM_Type *base)
  91. {
  92. uint32_t primaskValue = 0U;
  93. /* Disable the global interrupt to protect refresh sequence */
  94. primaskValue = DisableGlobalIRQ();
  95. base->SERV = (uint8_t)0xB4U;
  96. base->SERV = (uint8_t)0x2CU;
  97. EnableGlobalIRQ(primaskValue);
  98. }