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_SYSTEM_INTERFACES
9  * @defgroup ELC_API ELC Interface
10  * @brief Interface for the Event Link Controller.
11  *
12  *
13  *
14  * @{
15  **********************************************************************************************************************/
16 
17 #ifndef R_ELC_API_H
18 #define R_ELC_API_H
19 
20 /***********************************************************************************************************************
21  * Includes
22  **********************************************************************************************************************/
23 
24 /* Register definitions, common services and error codes. */
25 #include "bsp_api.h"
26 
27 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */
28 FSP_HEADER
29 
30 /**********************************************************************************************************************
31  * Macro definitions
32  **********************************************************************************************************************/
33 #ifndef ELC_PERIPHERAL_NUM
34  #define ELC_PERIPHERAL_NUM    (23U)
35 #endif
36 
37 /**********************************************************************************************************************
38  * Typedef definitions
39  **********************************************************************************************************************/
40 
41 #ifndef BSP_OVERRIDE_ELC_PERIPHERAL_T
42 
43 /** Possible peripherals to be linked to event signals (not all available on all MCUs) */
44 typedef enum e_elc_peripheral
45 {
46     ELC_PERIPHERAL_GPT_A   = (0),
47     ELC_PERIPHERAL_GPT_B   = (1),
48     ELC_PERIPHERAL_GPT_C   = (2),
49     ELC_PERIPHERAL_GPT_D   = (3),
50     ELC_PERIPHERAL_GPT_E   = (4),
51     ELC_PERIPHERAL_GPT_F   = (5),
52     ELC_PERIPHERAL_GPT_G   = (6),
53     ELC_PERIPHERAL_GPT_H   = (7),
54     ELC_PERIPHERAL_ADC0    = (8),
55     ELC_PERIPHERAL_ADC0_B  = (9),
56     ELC_PERIPHERAL_ADC1    = (10),
57     ELC_PERIPHERAL_ADC1_B  = (11),
58     ELC_PERIPHERAL_DAC0    = (12),
59     ELC_PERIPHERAL_DAC1    = (13),
60     ELC_PERIPHERAL_IOPORT1 = (14),
61     ELC_PERIPHERAL_IOPORT2 = (15),
62     ELC_PERIPHERAL_IOPORT3 = (16),
63     ELC_PERIPHERAL_IOPORT4 = (17),
64     ELC_PERIPHERAL_CTSU    = (18),
65     ELC_PERIPHERAL_DA8_0   = (19),
66     ELC_PERIPHERAL_DA8_1   = (20),
67     ELC_PERIPHERAL_SDADC0  = (22),
68 } elc_peripheral_t;
69 
70 #endif
71 
72 /** ELC control block.  Allocate an instance specific control block to pass into the ELC API calls.
73  */
74 typedef void elc_ctrl_t;
75 
76 /** Main configuration structure for the Event Link Controller */
77 typedef struct st_elc_cfg
78 {
79     elc_event_t const link[ELC_PERIPHERAL_NUM]; ///< Event link register settings
80     void const      * p_extend;                 ///< Extension parameter for hardware specific settings
81 } elc_cfg_t;
82 
83 #ifndef BSP_OVERRIDE_ELC_SOFTWARE_EVENT_T
84 
85 /** Software event number */
86 typedef enum e_elc_software_event
87 {
88     ELC_SOFTWARE_EVENT_0,              ///< Software event 0
89     ELC_SOFTWARE_EVENT_1,              ///< Software event 1
90 } elc_software_event_t;
91 
92 #endif
93 
94 /** ELC driver structure. General ELC functions implemented at the HAL layer follow this API. */
95 typedef struct st_elc_api
96 {
97     /** Initialize all links in the Event Link Controller.
98      *
99      * @param[in]   p_ctrl  Pointer to control structure.
100      * @param[in]   p_cfg   Pointer to configuration structure.
101      **/
102     fsp_err_t (* open)(elc_ctrl_t * const p_ctrl, elc_cfg_t const * const p_cfg);
103 
104     /** Disable all links in the Event Link Controller and close the API.
105      *
106      * @param[in]   p_ctrl  Pointer to control structure.
107      **/
108     fsp_err_t (* close)(elc_ctrl_t * const p_ctrl);
109 
110     /** Generate a software event in the Event Link Controller.
111      *
112      * @param[in]   p_ctrl  Pointer to control structure.
113      * @param[in]   eventNum           Software event number to be generated.
114      **/
115     fsp_err_t (* softwareEventGenerate)(elc_ctrl_t * const p_ctrl, elc_software_event_t event_num);
116 
117     /** Create a single event link.
118      *
119      * @param[in]   p_ctrl  Pointer to control structure.
120      * @param[in]   peripheral The peripheral block that will receive the event signal.
121      * @param[in]   signal     The event signal.
122      **/
123     fsp_err_t (* linkSet)(elc_ctrl_t * const p_ctrl, elc_peripheral_t peripheral, elc_event_t signal);
124 
125     /** Break an event link.
126      *
127      * @param[in]   p_ctrl  Pointer to control structure.
128      * @param[in]   peripheral   The peripheral that should no longer be linked.
129      **/
130     fsp_err_t (* linkBreak)(elc_ctrl_t * const p_ctrl, elc_peripheral_t peripheral);
131 
132     /** Enable the operation of the Event Link Controller.
133      *
134      * @param[in]   p_ctrl  Pointer to control structure.
135      **/
136     fsp_err_t (* enable)(elc_ctrl_t * const p_ctrl);
137 
138     /** Disable the operation of the Event Link Controller.
139      *
140      * @param[in]   p_ctrl  Pointer to control structure.
141      **/
142     fsp_err_t (* disable)(elc_ctrl_t * const p_ctrl);
143 } elc_api_t;
144 
145 /** This structure encompasses everything that is needed to use an instance of this interface. */
146 typedef struct st_elc_instance
147 {
148     elc_ctrl_t      * p_ctrl;          ///< Pointer to the control structure for this instance
149     elc_cfg_t const * p_cfg;           ///< Pointer to the configuration structure for this instance
150     elc_api_t const * p_api;           ///< Pointer to the API structure for this instance
151 } elc_instance_t;
152 
153 /* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */
154 FSP_FOOTER
155 
156 #endif
157 
158 /*******************************************************************************************************************//**
159  * @} (end defgroup ELC_API)
160  **********************************************************************************************************************/
161