fsl_ewm.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /*******************************************************************************
  36. * Code
  37. ******************************************************************************/
  38. void EWM_Init(EWM_Type *base, const ewm_config_t *config)
  39. {
  40. assert(config);
  41. uint32_t value = 0U;
  42. #if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
  43. (defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
  44. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  45. CLOCK_EnableClock(kCLOCK_Ewm0);
  46. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  47. #endif
  48. value = EWM_CTRL_EWMEN(config->enableEwm) | EWM_CTRL_ASSIN(config->setInputAssertLogic) |
  49. EWM_CTRL_INEN(config->enableEwmInput) | EWM_CTRL_INTEN(config->enableInterrupt);
  50. #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
  51. base->CLKPRESCALER = config->prescaler;
  52. #endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
  53. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  54. base->CLKCTRL = config->clockSource;
  55. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
  56. base->CMPL = config->compareLowValue;
  57. base->CMPH = config->compareHighValue;
  58. base->CTRL = value;
  59. }
  60. void EWM_Deinit(EWM_Type *base)
  61. {
  62. EWM_DisableInterrupts(base, kEWM_InterruptEnable);
  63. #if !((defined(FSL_FEATURE_SOC_PCC_COUNT) && FSL_FEATURE_SOC_PCC_COUNT) && \
  64. (defined(FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE) && FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE))
  65. #if !(defined(FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL) && FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL)
  66. CLOCK_DisableClock(kCLOCK_Ewm0);
  67. #endif /* FSL_SDK_DISABLE_DRIVER_CLOCK_CONTROL */
  68. #endif /* FSL_FEATURE_PCC_SUPPORT_EWM_CLOCK_REMOVE */
  69. }
  70. void EWM_GetDefaultConfig(ewm_config_t *config)
  71. {
  72. assert(config);
  73. config->enableEwm = true;
  74. config->enableEwmInput = false;
  75. config->setInputAssertLogic = false;
  76. config->enableInterrupt = false;
  77. #if defined(FSL_FEATURE_EWM_HAS_CLOCK_SELECT) && FSL_FEATURE_EWM_HAS_CLOCK_SELECT
  78. config->clockSource = kEWM_LpoClockSource0;
  79. #endif /* FSL_FEATURE_EWM_HAS_CLOCK_SELECT*/
  80. #if defined(FSL_FEATURE_EWM_HAS_PRESCALER) && FSL_FEATURE_EWM_HAS_PRESCALER
  81. config->prescaler = 0U;
  82. #endif /* FSL_FEATURE_EWM_HAS_PRESCALER */
  83. config->compareLowValue = 0U;
  84. config->compareHighValue = 0xFEU;
  85. }
  86. void EWM_Refresh(EWM_Type *base)
  87. {
  88. uint32_t primaskValue = 0U;
  89. /* Disable the global interrupt to protect refresh sequence */
  90. primaskValue = DisableGlobalIRQ();
  91. base->SERV = (uint8_t)0xB4U;
  92. base->SERV = (uint8_t)0x2CU;
  93. EnableGlobalIRQ(primaskValue);
  94. }