|
| 1 | +/* |
| 2 | +* Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates |
| 3 | +* |
| 4 | +* SPDX-License-Identifier: BSD-3-Clause |
| 5 | +*/ |
| 6 | + |
| 7 | +/*******************************************************************************************************************//** |
| 8 | + * @ingroup RENESAS_INTERFACES |
| 9 | + * @defgroup EXTERNAL_IRQ_API External IRQ Interface |
| 10 | + * @brief Interface for detecting external interrupts. |
| 11 | + * |
| 12 | + * @section EXTERNAL_IRQ_API_Summary Summary |
| 13 | + * The External IRQ Interface is for configuring interrupts to fire when a trigger condition is detected on an |
| 14 | + * external IRQ pin. |
| 15 | + * |
| 16 | + * The External IRQ Interface can be implemented by: |
| 17 | + * - @ref INTC_NMI |
| 18 | + * - @ref INTC_IRQ |
| 19 | + * |
| 20 | + * @{ |
| 21 | + **********************************************************************************************************************/ |
| 22 | + |
| 23 | +#ifndef R_EXTERNAL_IRQ_API_H |
| 24 | +#define R_EXTERNAL_IRQ_API_H |
| 25 | + |
| 26 | +/*********************************************************************************************************************** |
| 27 | + * Includes |
| 28 | + **********************************************************************************************************************/ |
| 29 | + |
| 30 | +/* Includes board and MCU related header files. */ |
| 31 | +#include "bsp_api.h" |
| 32 | + |
| 33 | +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ |
| 34 | +FSP_HEADER |
| 35 | + |
| 36 | +/********************************************************************************************************************** |
| 37 | + * Macro definitions |
| 38 | + *********************************************************************************************************************/ |
| 39 | + |
| 40 | +/********************************************************************************************************************* |
| 41 | + * Typedef definitions |
| 42 | + *********************************************************************************************************************/ |
| 43 | + |
| 44 | +/** Callback function parameter data */ |
| 45 | +typedef struct st_external_irq_callback_args |
| 46 | +{ |
| 47 | + /** Placeholder for user data. Set in @ref external_irq_api_t::open function in @ref external_irq_cfg_t. */ |
| 48 | + void const * p_context; |
| 49 | + uint32_t channel; ///< The physical hardware channel that caused the interrupt. |
| 50 | +} external_irq_callback_args_t; |
| 51 | + |
| 52 | +/** Condition that will trigger an interrupt when detected. */ |
| 53 | +typedef enum e_external_irq_trigger |
| 54 | +{ |
| 55 | + EXTERNAL_IRQ_TRIG_FALLING = 0, ///< Falling edge trigger |
| 56 | + EXTERNAL_IRQ_TRIG_RISING = 1, ///< Rising edge trigger |
| 57 | + EXTERNAL_IRQ_TRIG_BOTH_EDGE = 2, ///< Both edges trigger |
| 58 | + EXTERNAL_IRQ_TRIG_LEVEL_LOW = 3, ///< Low level trigger |
| 59 | +} external_irq_trigger_t; |
| 60 | + |
| 61 | +/** External IRQ input pin digital filtering sample clock divisor settings. The digital filter rejects trigger |
| 62 | + * conditions that are shorter than 3 periods of the filter clock. |
| 63 | + */ |
| 64 | +typedef enum e_external_irq_pclk_div |
| 65 | +{ |
| 66 | + EXTERNAL_IRQ_PCLK_DIV_BY_1 = 0, ///< Filter using PCLK divided by 1 |
| 67 | + EXTERNAL_IRQ_PCLK_DIV_BY_8 = 1, ///< Filter using PCLK divided by 8 |
| 68 | + EXTERNAL_IRQ_PCLK_DIV_BY_32 = 2, ///< Filter using PCLK divided by 32 |
| 69 | + EXTERNAL_IRQ_PCLK_DIV_BY_64 = 3, ///< Filter using PCLK divided by 64 |
| 70 | +} external_irq_pclk_div_t; |
| 71 | + |
| 72 | +/** User configuration structure, used in open function */ |
| 73 | +typedef struct st_external_irq_cfg |
| 74 | +{ |
| 75 | + uint8_t channel; ///< Hardware channel used. |
| 76 | + uint8_t ipl; ///< Interrupt priority |
| 77 | + IRQn_Type irq; ///< NVIC interrupt number assigned to this instance |
| 78 | + external_irq_trigger_t trigger; ///< Trigger setting. |
| 79 | + external_irq_pclk_div_t pclk_div; ///< Digital filter clock divisor setting. |
| 80 | + bool filter_enable; ///< Digital filter enable/disable setting. |
| 81 | + |
| 82 | + /** Callback provided external input trigger occurs. */ |
| 83 | + void (* p_callback)(external_irq_callback_args_t * p_args); |
| 84 | + |
| 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 | + |
| 90 | +/** External IRQ control block. Allocate an instance specific control block to pass into the external IRQ API calls. |
| 91 | + * @par Implemented as |
| 92 | + * - intc_nmi_instance_ctrl_t |
| 93 | + * - intc_irq_instance_ctrl_t |
| 94 | + */ |
| 95 | +typedef void external_irq_ctrl_t; |
| 96 | + |
| 97 | +/** External interrupt driver structure. External interrupt functions implemented at the HAL layer will follow this API. */ |
| 98 | +typedef struct st_external_irq_api |
| 99 | +{ |
| 100 | + /** Initial configuration. |
| 101 | + * @par Implemented as |
| 102 | + * - @ref R_INTC_NMI_ExternalIrqOpen() |
| 103 | + * - @ref R_INTC_IRQ_ExternalIrqOpen() |
| 104 | + * |
| 105 | + * @param[out] p_ctrl Pointer to control block. Must be declared by user. Value set here. |
| 106 | + * @param[in] p_cfg Pointer to configuration structure. All elements of the structure must be set by user. |
| 107 | + */ |
| 108 | + fsp_err_t (* open)(external_irq_ctrl_t * const p_ctrl, external_irq_cfg_t const * const p_cfg); |
| 109 | + |
| 110 | + /** Enable callback when an external trigger condition occurs. |
| 111 | + * @par Implemented as |
| 112 | + * - @ref R_INTC_NMI_ExternalIrqEnable() |
| 113 | + * - @ref R_INTC_IRQ_ExternalIrqEnable() |
| 114 | + * |
| 115 | + * @param[in] p_ctrl Control block set in Open call for this external interrupt. |
| 116 | + */ |
| 117 | + fsp_err_t (* enable)(external_irq_ctrl_t * const p_ctrl); |
| 118 | + |
| 119 | + /** Disable callback when external trigger condition occurs. |
| 120 | + * @par Implemented as |
| 121 | + * - @ref R_INTC_NMI_ExternalIrqDisable() |
| 122 | + * - @ref R_INTC_IRQ_ExternalIrqDisable() |
| 123 | + * |
| 124 | + * @param[in] p_ctrl Control block set in Open call for this external interrupt. |
| 125 | + */ |
| 126 | + fsp_err_t (* disable)(external_irq_ctrl_t * const p_ctrl); |
| 127 | + |
| 128 | + /** |
| 129 | + * Specify callback function and optional context pointer and working memory pointer. |
| 130 | + * @par Implemented as |
| 131 | + * - R_INTC_NMI_ExternalIrqCallbackSet() |
| 132 | + * - R_INTC_IRQ_ExternalIrqCallbackSet() |
| 133 | + * |
| 134 | + * @param[in] p_ctrl Pointer to the Extneral IRQ control block. |
| 135 | + * @param[in] p_callback Callback function |
| 136 | + * @param[in] p_context Pointer to send to callback function |
| 137 | + * @param[in] p_working_memory Pointer to volatile memory where callback structure can be allocated. |
| 138 | + * Callback arguments allocated here are only valid during the callback. |
| 139 | + */ |
| 140 | + fsp_err_t (* callbackSet)(external_irq_ctrl_t * const p_api_ctrl, |
| 141 | + void ( * p_callback)(external_irq_callback_args_t *), |
| 142 | + void const * const p_context, |
| 143 | + external_irq_callback_args_t * const p_callback_memory); |
| 144 | + |
| 145 | + /** Allow driver to be reconfigured. May reduce power consumption. |
| 146 | + * @par Implemented as |
| 147 | + * - @ref R_INTC_NMI_ExternalIrqClose() |
| 148 | + * - @ref R_INTC_IRQ_ExternalIrqClose() |
| 149 | + * |
| 150 | + * @param[in] p_ctrl Control block set in Open call for this external interrupt. |
| 151 | + */ |
| 152 | + fsp_err_t (* close)(external_irq_ctrl_t * const p_ctrl); |
| 153 | +} external_irq_api_t; |
| 154 | + |
| 155 | +/** This structure encompasses everything that is needed to use an instance of this interface. */ |
| 156 | +typedef struct st_external_irq_instance |
| 157 | +{ |
| 158 | + external_irq_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance |
| 159 | + external_irq_cfg_t const * p_cfg; ///< Pointer to the configuration structure for this instance |
| 160 | + external_irq_api_t const * p_api; ///< Pointer to the API structure for this instance |
| 161 | +} external_irq_instance_t; |
| 162 | + |
| 163 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 164 | +FSP_FOOTER |
| 165 | + |
| 166 | +/*******************************************************************************************************************//** |
| 167 | + * @} (end defgroup EXTERNAL_IRQ_API) |
| 168 | + **********************************************************************************************************************/ |
| 169 | + |
| 170 | +#endif |
0 commit comments