nu_ecap.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**************************************************************************//**
  2. * @file ecap.c
  3. * @version V3.00
  4. * @brief Enhanced Input Capture Timer (ECAP) driver source file
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * @copyright (C) 2016-2020 Nuvoton Technology Corp. All rights reserved.
  8. *****************************************************************************/
  9. #include "NuMicro.h"
  10. /** @addtogroup Standard_Driver Standard Driver
  11. @{
  12. */
  13. /** @addtogroup ECAP_Driver ECAP Driver
  14. @{
  15. */
  16. /** @addtogroup ECAP_EXPORTED_FUNCTIONS ECAP Exported Functions
  17. @{
  18. */
  19. /**
  20. * @brief Enable ECAP function
  21. * @param[in] ecap The pointer of the specified ECAP module.
  22. * @param[in] u32FuncMask Input capture function select
  23. * - \ref ECAP_DISABLE_COMPARE
  24. * - \ref ECAP_COMPARE_FUNCTION
  25. * @return None
  26. * @details This macro enable input capture function and select compare and reload function.
  27. */
  28. void ECAP_Open(ECAP_T* ecap, uint32_t u32FuncMask)
  29. {
  30. /* Clear Input capture mode*/
  31. ecap->CTL0 = ecap->CTL0 & ~(ECAP_CTL0_CMPEN_Msk);
  32. /* Enable Input Capture and set mode */
  33. ecap->CTL0 |= ECAP_CTL0_CAPEN_Msk | (u32FuncMask);
  34. }
  35. /**
  36. * @brief Disable ECAP function
  37. * @param[in] ecap The pointer of the specified ECAP module.
  38. * @return None
  39. * @details This macro disable input capture function.
  40. */
  41. void ECAP_Close(ECAP_T* ecap)
  42. {
  43. /* Disable Input Capture*/
  44. ecap->CTL0 &= ~ECAP_CTL0_CAPEN_Msk;
  45. }
  46. /**
  47. * @brief This macro is used to enable input channel interrupt
  48. * @param[in] ecap Specify ECAP port
  49. * @param[in] u32Mask The input channel Mask
  50. * - \ref ECAP_CTL0_CAPIEN0_Msk
  51. * - \ref ECAP_CTL0_CAPIEN1_Msk
  52. * - \ref ECAP_CTL0_CAPIEN2_Msk
  53. * - \ref ECAP_CTL0_OVIEN_Msk
  54. * - \ref ECAP_CTL0_CMPIEN_Msk
  55. * @return None
  56. * @details This macro will enable the input channel_n interrupt.
  57. */
  58. void ECAP_EnableINT(ECAP_T* ecap, uint32_t u32Mask)
  59. {
  60. /* Enable input channel interrupt */
  61. ecap->CTL0 |= (u32Mask);
  62. /* Enable NVIC ECAP IRQ */
  63. if(ecap == (ECAP_T*)ECAP0)
  64. {
  65. NVIC_EnableIRQ((IRQn_Type)ECAP0_IRQn);
  66. }
  67. else
  68. {
  69. NVIC_EnableIRQ((IRQn_Type)ECAP1_IRQn);
  70. }
  71. }
  72. /**
  73. * @brief This macro is used to disable input channel interrupt
  74. * @param[in] ecap Specify ECAP port
  75. * @param[in] u32Mask The input channel number
  76. * - \ref ECAP_CTL0_CAPIEN0_Msk
  77. * - \ref ECAP_CTL0_CAPIEN1_Msk
  78. * - \ref ECAP_CTL0_CAPIEN2_Msk
  79. * - \ref ECAP_CTL0_OVIEN_Msk
  80. * - \ref ECAP_CTL0_CMPIEN_Msk
  81. * @return None
  82. * @details This macro will disable the input channel_n interrupt.
  83. */
  84. void ECAP_DisableINT(ECAP_T* ecap, uint32_t u32Mask)
  85. {
  86. /* Disable input channel interrupt */
  87. ecap->CTL0 &= ~(u32Mask);
  88. /* Disable NVIC ECAP IRQ */
  89. if(ecap == (ECAP_T*)ECAP0)
  90. {
  91. NVIC_DisableIRQ((IRQn_Type)ECAP0_IRQn);
  92. }
  93. else
  94. {
  95. NVIC_DisableIRQ((IRQn_Type)ECAP1_IRQn);
  96. }
  97. }
  98. /*@}*/ /* end of group ECAP_EXPORTED_FUNCTIONS */
  99. /*@}*/ /* end of group ECAP_Driver */
  100. /*@}*/ /* end of group Standard_Driver */
  101. /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/