em_prs.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /***************************************************************************//**
  2. * @file
  3. * @brief Peripheral Reflex System (PRS) Peripheral API
  4. * @author Energy Micro AS
  5. * @version 3.0.0
  6. *******************************************************************************
  7. * @section License
  8. * <b>(C) Copyright 2012 Energy Micro AS, http://www.energymicro.com</b>
  9. *******************************************************************************
  10. *
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. *
  15. * 1. The origin of this software must not be misrepresented; you must not
  16. * claim that you wrote the original software.
  17. * 2. Altered source versions must be plainly marked as such, and must not be
  18. * misrepresented as being the original software.
  19. * 3. This notice may not be removed or altered from any source distribution.
  20. *
  21. * DISCLAIMER OF WARRANTY/LIMITATION OF REMEDIES: Energy Micro AS has no
  22. * obligation to support this Software. Energy Micro AS is providing the
  23. * Software "AS IS", with no express or implied warranties of any kind,
  24. * including, but not limited to, any implied warranties of merchantability
  25. * or fitness for any particular purpose or warranties against infringement
  26. * of any proprietary rights of a third party.
  27. *
  28. * Energy Micro AS will not be liable for any consequential, incidental, or
  29. * special damages, or any other relief, or for any claim by any third party,
  30. * arising from your use of this Software.
  31. *
  32. ******************************************************************************/
  33. #include "em_prs.h"
  34. #include "em_assert.h"
  35. #include "em_bitband.h"
  36. /***************************************************************************//**
  37. * @addtogroup EM_Library
  38. * @{
  39. ******************************************************************************/
  40. /***************************************************************************//**
  41. * @addtogroup PRS
  42. * @brief Peripheral Reflex System (PRS) Peripheral API
  43. * @{
  44. ******************************************************************************/
  45. /*******************************************************************************
  46. ************************** GLOBAL FUNCTIONS *******************************
  47. ******************************************************************************/
  48. /***************************************************************************//**
  49. * @brief
  50. * Set source and signal to be used for a channel.
  51. *
  52. * @param[in] ch
  53. * Channel to define signal and source for.
  54. *
  55. * @param[in] source
  56. * Source to select for channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
  57. *
  58. * @param[in] signal
  59. * Signal (for selected @p source) to use. Use one of PRS_CH_CTRL_SIGSEL_x
  60. * defines.
  61. *
  62. * @param[in] edge
  63. * Edge (for selected source/signal) to generate pulse for.
  64. ******************************************************************************/
  65. void PRS_SourceSignalSet(unsigned int ch,
  66. uint32_t source,
  67. uint32_t signal,
  68. PRS_Edge_TypeDef edge)
  69. {
  70. EFM_ASSERT(ch < 8);
  71. PRS->CH[ch].CTRL = (source & _PRS_CH_CTRL_SOURCESEL_MASK) |
  72. (signal & _PRS_CH_CTRL_SIGSEL_MASK) |
  73. (uint32_t)edge;
  74. }
  75. #if ((defined _EFM32_TINY_FAMILY) || (defined _EFM32_GIANT_FAMILY))
  76. /***************************************************************************//**
  77. * @brief
  78. * Set source and asynchronous signal to be used for a channel.
  79. *
  80. * @details
  81. * Asynchronous reflexes are not clocked on HFPERCLK, and can be used even in
  82. * EM2/EM3.
  83. * There is a limitation to reflexes operating in asynchronous mode: they can
  84. * only be used by a subset of the reflex consumers. Please refer to PRS
  85. * chapter in the reference manual for the complete list of supported
  86. * asynchronous signals and consumers.
  87. *
  88. * @note
  89. * This function is only supported on the following device families:
  90. * @li Tiny Gecko (EFM32TGxxxFxx)
  91. * @li Giant Gecko (EFM32GGxxxFxxx)
  92. * In asynchronous mode, the edge detector only works in EM0, hence it shall
  93. * not be used. The EDSEL parameter in PRS_CHx_CTRL register is set to 0 (OFF)
  94. * by default.
  95. *
  96. * @param[in] ch
  97. * Channel to define source and asynchronous signal for.
  98. *
  99. * @param[in] source
  100. * Source to select for channel. Use one of PRS_CH_CTRL_SOURCESEL_x defines.
  101. *
  102. * @param[in] signal
  103. * Asynchronous signal (for selected @p source) to use. Use one of the
  104. * PRS_CH_CTRL_SIGSEL_x defines that support asynchronous operation.
  105. ******************************************************************************/
  106. void PRS_SourceAsyncSignalSet(unsigned int ch,
  107. uint32_t source,
  108. uint32_t signal)
  109. {
  110. EFM_ASSERT(ch < 8);
  111. PRS->CH[ch].CTRL = PRS_CH_CTRL_ASYNC |
  112. (source & _PRS_CH_CTRL_SOURCESEL_MASK) |
  113. (signal & _PRS_CH_CTRL_SIGSEL_MASK) |
  114. PRS_CH_CTRL_EDSEL_OFF;
  115. }
  116. #endif
  117. /** @} (end addtogroup PRS) */
  118. /** @} (end addtogroup EM_Library) */