r_external_irq_api.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /***********************************************************************************************************************
  2. * Copyright [2020-2021] Renesas Electronics Corporation and/or its affiliates. All Rights Reserved.
  3. *
  4. * This software and documentation are supplied by Renesas Electronics America Inc. and may only be used with products
  5. * of Renesas Electronics Corp. and its affiliates ("Renesas"). No other uses are authorized. Renesas products are
  6. * sold pursuant to Renesas terms and conditions of sale. Purchasers are solely responsible for the selection and use
  7. * of Renesas products and Renesas assumes no liability. No license, express or implied, to any intellectual property
  8. * right is granted by Renesas. This software is protected under all applicable laws, including copyright laws. Renesas
  9. * reserves the right to change or discontinue this software and/or this documentation. THE SOFTWARE AND DOCUMENTATION
  10. * IS DELIVERED TO YOU "AS IS," AND RENESAS MAKES NO REPRESENTATIONS OR WARRANTIES, AND TO THE FULLEST EXTENT
  11. * PERMISSIBLE UNDER APPLICABLE LAW, DISCLAIMS ALL WARRANTIES, WHETHER EXPLICITLY OR IMPLICITLY, INCLUDING WARRANTIES
  12. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT, WITH RESPECT TO THE SOFTWARE OR
  13. * DOCUMENTATION. RENESAS SHALL HAVE NO LIABILITY ARISING OUT OF ANY SECURITY VULNERABILITY OR BREACH. TO THE MAXIMUM
  14. * EXTENT PERMITTED BY LAW, IN NO EVENT WILL RENESAS BE LIABLE TO YOU IN CONNECTION WITH THE SOFTWARE OR DOCUMENTATION
  15. * (OR ANY PERSON OR ENTITY CLAIMING RIGHTS DERIVED FROM YOU) FOR ANY LOSS, DAMAGES, OR CLAIMS WHATSOEVER, INCLUDING,
  16. * WITHOUT LIMITATION, ANY DIRECT, CONSEQUENTIAL, SPECIAL, INDIRECT, PUNITIVE, OR INCIDENTAL DAMAGES; ANY LOST PROFITS,
  17. * OTHER ECONOMIC DAMAGE, PROPERTY DAMAGE, OR PERSONAL INJURY; AND EVEN IF RENESAS HAS BEEN ADVISED OF THE POSSIBILITY
  18. * OF SUCH LOSS, DAMAGES, CLAIMS OR COSTS.
  19. **********************************************************************************************************************/
  20. /*******************************************************************************************************************//**
  21. * @ingroup RENESAS_INTERFACES
  22. * @defgroup EXTERNAL_IRQ_API External IRQ Interface
  23. * @brief Interface for detecting external interrupts.
  24. *
  25. * @section EXTERNAL_IRQ_API_Summary Summary
  26. * The External IRQ Interface is for configuring interrupts to fire when a trigger condition is detected on an
  27. * external IRQ pin.
  28. *
  29. * The External IRQ Interface can be implemented by:
  30. * - @ref ICU
  31. *
  32. * @{
  33. **********************************************************************************************************************/
  34. #ifndef R_EXTERNAL_IRQ_API_H
  35. #define R_EXTERNAL_IRQ_API_H
  36. /***********************************************************************************************************************
  37. * Includes
  38. **********************************************************************************************************************/
  39. /* Includes board and MCU related header files. */
  40. #include "bsp_api.h"
  41. /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
  42. FSP_HEADER
  43. /**********************************************************************************************************************
  44. * Macro definitions
  45. *********************************************************************************************************************/
  46. /*********************************************************************************************************************
  47. * Typedef definitions
  48. *********************************************************************************************************************/
  49. /** Callback function parameter data */
  50. typedef struct st_external_irq_callback_args
  51. {
  52. /** Placeholder for user data. Set in @ref external_irq_api_t::open function in @ref external_irq_cfg_t. */
  53. void const * p_context;
  54. uint32_t channel; ///< The physical hardware channel that caused the interrupt.
  55. } external_irq_callback_args_t;
  56. /** Condition that will trigger an interrupt when detected. */
  57. typedef enum e_external_irq_trigger
  58. {
  59. EXTERNAL_IRQ_TRIG_FALLING = 0, ///< Falling edge trigger
  60. EXTERNAL_IRQ_TRIG_RISING = 1, ///< Rising edge trigger
  61. EXTERNAL_IRQ_TRIG_BOTH_EDGE = 2, ///< Both edges trigger
  62. EXTERNAL_IRQ_TRIG_LEVEL_LOW = 3, ///< Low level trigger
  63. } external_irq_trigger_t;
  64. /** External IRQ input pin digital filtering sample clock divisor settings. The digital filter rejects trigger
  65. * conditions that are shorter than 3 periods of the filter clock.
  66. */
  67. typedef enum e_external_irq_pclk_div
  68. {
  69. EXTERNAL_IRQ_PCLK_DIV_BY_1 = 0, ///< Filter using PCLK divided by 1
  70. EXTERNAL_IRQ_PCLK_DIV_BY_8 = 1, ///< Filter using PCLK divided by 8
  71. EXTERNAL_IRQ_PCLK_DIV_BY_32 = 2, ///< Filter using PCLK divided by 32
  72. EXTERNAL_IRQ_PCLK_DIV_BY_64 = 3, ///< Filter using PCLK divided by 64
  73. } external_irq_pclk_div_t;
  74. /** User configuration structure, used in open function */
  75. typedef struct st_external_irq_cfg
  76. {
  77. uint8_t channel; ///< Hardware channel used.
  78. uint8_t ipl; ///< Interrupt priority
  79. IRQn_Type irq; ///< NVIC interrupt number assigned to this instance
  80. external_irq_trigger_t trigger; ///< Trigger setting.
  81. external_irq_pclk_div_t pclk_div; ///< Digital filter clock divisor setting.
  82. bool filter_enable; ///< Digital filter enable/disable setting.
  83. /** Callback provided external input trigger occurs. */
  84. void (* p_callback)(external_irq_callback_args_t * p_args);
  85. /** Placeholder for user data. Passed to the user callback in @ref external_irq_callback_args_t. */
  86. void const * p_context;
  87. void const * p_extend; ///< External IRQ hardware dependent configuration.
  88. } external_irq_cfg_t;
  89. /** External IRQ control block. Allocate an instance specific control block to pass into the external IRQ API calls.
  90. * @par Implemented as
  91. * - icu_instance_ctrl_t
  92. */
  93. typedef void external_irq_ctrl_t;
  94. /** External interrupt driver structure. External interrupt functions implemented at the HAL layer will follow this API. */
  95. typedef struct st_external_irq_api
  96. {
  97. /** Initial configuration.
  98. * @par Implemented as
  99. * - @ref R_ICU_ExternalIrqOpen()
  100. *
  101. * @param[out] p_ctrl Pointer to control block. Must be declared by user. Value set here.
  102. * @param[in] p_cfg Pointer to configuration structure. All elements of the structure must be set by user.
  103. */
  104. fsp_err_t (* open)(external_irq_ctrl_t * const p_ctrl, external_irq_cfg_t const * const p_cfg);
  105. /** Enable callback when an external trigger condition occurs.
  106. * @par Implemented as
  107. * - @ref R_ICU_ExternalIrqEnable()
  108. *
  109. * @param[in] p_ctrl Control block set in Open call for this external interrupt.
  110. */
  111. fsp_err_t (* enable)(external_irq_ctrl_t * const p_ctrl);
  112. /** Disable callback when external trigger condition occurs.
  113. * @par Implemented as
  114. * - @ref R_ICU_ExternalIrqDisable()
  115. *
  116. * @param[in] p_ctrl Control block set in Open call for this external interrupt.
  117. */
  118. fsp_err_t (* disable)(external_irq_ctrl_t * const p_ctrl);
  119. /**
  120. * Specify callback function and optional context pointer and working memory pointer.
  121. * @par Implemented as
  122. * - R_ICU_ExternalIrqCallbackSet()
  123. *
  124. * @param[in] p_ctrl Pointer to the Extneral IRQ control block.
  125. * @param[in] p_callback Callback function
  126. * @param[in] p_context Pointer to send to callback function
  127. * @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated.
  128. * Callback arguments allocated here are only valid during the callback.
  129. */
  130. fsp_err_t (* callbackSet)(external_irq_ctrl_t * const p_api_ctrl,
  131. void ( * p_callback)(external_irq_callback_args_t *),
  132. void const * const p_context,
  133. external_irq_callback_args_t * const p_callback_memory);
  134. /** Allow driver to be reconfigured. May reduce power consumption.
  135. * @par Implemented as
  136. * - @ref R_ICU_ExternalIrqClose()
  137. *
  138. * @param[in] p_ctrl Control block set in Open call for this external interrupt.
  139. */
  140. fsp_err_t (* close)(external_irq_ctrl_t * const p_ctrl);
  141. } external_irq_api_t;
  142. /** This structure encompasses everything that is needed to use an instance of this interface. */
  143. typedef struct st_external_irq_instance
  144. {
  145. external_irq_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
  146. external_irq_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance
  147. external_irq_api_t const * p_api; ///< Pointer to the API structure for this instance
  148. } external_irq_instance_t;
  149. /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
  150. FSP_FOOTER
  151. /*******************************************************************************************************************//**
  152. * @} (end defgroup EXTERNAL_IRQ_API)
  153. **********************************************************************************************************************/
  154. #endif