xref: /btstack/port/renesas-tb-s1ja-cc256x/template/btstack_example/synergy/ssp/src/driver/r_elc/r_elc.c (revision 3b5c872a8c45689e8cc17891f01530f5aa5e911c)
1 /***********************************************************************************************************************
2  * Copyright [2015-2017] Renesas Electronics Corporation and/or its licensors. All Rights Reserved.
3  *
4  * This file is part of Renesas SynergyTM Software Package (SSP)
5  *
6  * The contents of this file (the "contents") are proprietary and confidential to Renesas Electronics Corporation
7  * and/or its licensors ("Renesas") and subject to statutory and contractual protections.
8  *
9  * This file is subject to a Renesas SSP license agreement. Unless otherwise agreed in an SSP license agreement with
10  * Renesas: 1) you may not use, copy, modify, distribute, display, or perform the contents; 2) you may not use any name
11  * or mark of Renesas for advertising or publicity purposes or in connection with your use of the contents; 3) RENESAS
12  * MAKES NO WARRANTY OR REPRESENTATIONS ABOUT THE SUITABILITY OF THE CONTENTS FOR ANY PURPOSE; THE CONTENTS ARE PROVIDED
13  * "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT; AND 4) RENESAS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, OR
15  * CONSEQUENTIAL DAMAGES, INCLUDING DAMAGES RESULTING FROM LOSS OF USE, DATA, OR PROJECTS, WHETHER IN AN ACTION OF
16  * CONTRACT OR TORT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE CONTENTS. Third-party contents
17  * included in this file may be subject to different terms.
18  **********************************************************************************************************************/
19 
20 /**********************************************************************************************************************
21  * File Name    : r_elc.c
22  * Description  : HAL API code for the Event Link Controller module
23  **********************************************************************************************************************/
24 
25 
26 /***********************************************************************************************************************
27  * Includes
28  **********************************************************************************************************************/
29 #include "r_elc.h"
30 #include "r_elc_private.h"
31 #include "r_elc_private_api.h"
32 
33 /***********************************************************************************************************************
34  * Macro definitions
35  **********************************************************************************************************************/
36 /** Macro for error logger. */
37 #ifndef ELC_ERROR_RETURN
38 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */
39 #define ELC_ERROR_RETURN(a, err) SSP_ERROR_RETURN((a), (err), &g_module_name[0], &s_elc_version)
40 #endif
41 
42 /***********************************************************************************************************************
43  * Typedef definitions
44  **********************************************************************************************************************/
45 
46 /***********************************************************************************************************************
47  * Private function prototypes
48  **********************************************************************************************************************/
49 
50 /***********************************************************************************************************************
51  * Private global variables
52  **********************************************************************************************************************/
53 #if defined(__GNUC__)
54 /* This structure is affected by warnings from the GCC compiler bug gcc.gnu.org/bugzilla/show_bug.cgi?id=60784
55  * This pragma suppresses the warnings in this structure only, and will be removed when the SSP compiler is updated to
56  * v5.3.*/
57 /*LDRA_INSPECTED 69 S */
58 #pragma GCC diagnostic ignored "-Wmissing-field-initializers"
59 #endif
60 /** Version data structure used by error logger macro. */
61 static const ssp_version_t s_elc_version =
62 {
63     .api_version_minor  = ELC_API_VERSION_MINOR,
64     .api_version_major  = ELC_API_VERSION_MAJOR,
65     .code_version_major = ELC_CODE_VERSION_MAJOR,
66     .code_version_minor = ELC_CODE_VERSION_MINOR
67 };
68 #if defined(__GNUC__)
69 /* Restore warning settings for 'missing-field-initializers' to as specified on command line. */
70 /*LDRA_INSPECTED 69 S */
71 #pragma GCC diagnostic pop
72 #endif
73 
74 static R_ELC_Type * gp_elc_reg = NULL;
75 
76 /** Name of module used by error logger macro */
77 #if BSP_CFG_ERROR_LOG != 0
78 static const char          g_module_name[] = "elc";
79 #endif
80 
81 /***********************************************************************************************************************
82  * Global Variables
83  **********************************************************************************************************************/
84 
85 /** ELC API structure.  */
86 /*LDRA_INSPECTED 27 D This structure must be accessible in user code. It cannot be static. */
87 const elc_api_t g_elc_on_elc =
88 {
89     .init                  = R_ELC_Init,
90     .softwareEventGenerate = R_ELC_SoftwareEventGenerate,
91     .linkSet               = R_ELC_LinkSet,
92     .linkBreak             = R_ELC_LinkBreak,
93     .enable                = R_ELC_Enable,
94     .disable               = R_ELC_Disable,
95     .versionGet            = R_ELC_VersionGet
96 };
97 
98 /*******************************************************************************************************************//**
99  * @addtogroup ELC
100  * @{
101  **********************************************************************************************************************/
102 
103 /***********************************************************************************************************************
104  * Functions
105  **********************************************************************************************************************/
106 
107 /*******************************************************************************************************************//**
108  * @brief  Initialize all the links in the Event Link Controller.
109  *
110  *  Implements elc_api_t::init
111  *
112  * The configuration structure passed in to this function includes
113  * links for every event source included in the ELC and sets them
114  * all at once. To set an individual link use R_ELC_LinkSet()
115  *
116  * @retval SSP_SUCCESS             Initialization was successful
117  * @retval SSP_ERR_ASSERTION       p_config was NULL
118  * @return                         See @ref Common_Error_Codes or functions called by this function for other possible
119  *                                 return codes. This function calls:
120  *                                     * fmi_api_t::productFeatureGet
121  **********************************************************************************************************************/
R_ELC_Init(elc_cfg_t const * const p_cfg)122 ssp_err_t R_ELC_Init (elc_cfg_t const * const p_cfg)
123 {
124     ssp_err_t err;
125     uint32_t  i;
126 
127 #if ELC_CFG_PARAM_CHECKING_ENABLE
128     SSP_ASSERT(p_cfg);
129 #endif
130 
131     ssp_feature_t ssp_feature = {{(ssp_ip_t) 0U}};
132     ssp_feature.channel = 0U;
133     ssp_feature.unit = 0U;
134     ssp_feature.id = SSP_IP_ELC;
135     fmi_feature_info_t info = {0U};
136     err = g_fmi_on_fmi.productFeatureGet(&ssp_feature, &info);
137     ELC_ERROR_RETURN(SSP_SUCCESS == err, err);
138     gp_elc_reg = (R_ELC_Type *) info.ptr;
139 
140     /** Power on ELC */
141     R_BSP_ModuleStart(&ssp_feature);
142 
143     /* Loop through all links in the config structure and set them in the ELC block */
144     for (i = (uint32_t)0; i < p_cfg->link_count; i++)
145     {
146         R_ELC_LinkSet(p_cfg->link_list[i].peripheral, p_cfg->link_list[i].event);
147     }
148 
149     /** Enable the operation of the Event Link Controller */
150     if (p_cfg->autostart)
151     {
152         R_ELC_Enable();
153     }
154 
155     return SSP_SUCCESS;
156 }
157 
158 /*******************************************************************************************************************//**
159  * @brief  Generate a software event in the Event Link Controller.
160  *
161  *  Implements elc_api_t::softwareEventGenerate
162  *
163  * @retval SSP_SUCCESS             Initialization was successful
164  * @retval SSP_ERR_ASSERTION       Invalid event number
165  **********************************************************************************************************************/
R_ELC_SoftwareEventGenerate(elc_software_event_t event_number)166 ssp_err_t R_ELC_SoftwareEventGenerate (elc_software_event_t event_number)
167 {
168     /** Generate a software event in the Event Link Controller. */
169     switch (event_number)
170     {
171         case ELC_SOFTWARE_EVENT_0:
172             HW_ELC_SoftwareEvent0Generate(gp_elc_reg);
173             break;
174 
175         case ELC_SOFTWARE_EVENT_1:
176             HW_ELC_SoftwareEvent1Generate(gp_elc_reg);
177             break;
178 
179         default:
180             SSP_ASSERT(0);
181     }
182 
183     return SSP_SUCCESS;
184 }
185 
186 /*******************************************************************************************************************//**
187  * @brief  Create a single event link.
188  *
189  *  Implements elc_api_t::linkSet
190  *
191  * @retval SSP_SUCCESS             Initialization was successful
192  *
193  **********************************************************************************************************************/
R_ELC_LinkSet(elc_peripheral_t peripheral,elc_event_t signal)194 ssp_err_t R_ELC_LinkSet (elc_peripheral_t peripheral, elc_event_t signal)
195 {
196     /** Make a link between a signal and a peripheral. */
197     HW_ELC_LinkSet(gp_elc_reg, (uint32_t) peripheral, (uint16_t) signal);
198     return SSP_SUCCESS;
199 }
200 
201 /*******************************************************************************************************************//**
202  * @brief  Break an event link.
203  *
204  *  Implements elc_api_t::linkBreak
205  *
206  * @retval SSP_SUCCESS             Event link broken
207  *
208  **********************************************************************************************************************/
R_ELC_LinkBreak(elc_peripheral_t peripheral)209 ssp_err_t R_ELC_LinkBreak (elc_peripheral_t peripheral)
210 {
211     /** Break a link between a signal and a peripheral. */
212     HW_ELC_LinkBreak(gp_elc_reg, (uint32_t) peripheral);
213     return SSP_SUCCESS;
214 }
215 
216 /*******************************************************************************************************************//**
217  * @brief  Enable the operation of the Event Link Controller.
218  *
219  *  Implements elc_api_t::enable
220  *
221  * @retval SSP_SUCCESS           ELC enabled.
222  *
223  **********************************************************************************************************************/
R_ELC_Enable(void)224 ssp_err_t R_ELC_Enable (void)
225 {
226     /** Enable the Event Link Controller block. */
227     HW_ELC_Enable(gp_elc_reg);
228     return SSP_SUCCESS;
229 }
230 
231 /*******************************************************************************************************************//**
232  * @brief  Disable the operation of the Event Link Controller.
233  *
234  *  Implements elc_api_t::disable
235  *
236  * @retval SSP_SUCCESS           ELC disabled.
237  *
238  **********************************************************************************************************************/
R_ELC_Disable(void)239 ssp_err_t R_ELC_Disable (void)
240 {
241     /** Disable the Event Link Controller block. */
242     HW_ELC_Disable(gp_elc_reg);
243     return SSP_SUCCESS;
244 }
245 
246 /*******************************************************************************************************************//**
247  * @brief      Get the driver version based on compile time macros.
248  *
249  *  Implements elc_api_t::versionGet
250  *
251  * @retval     SSP_SUCCESS          Successful close.
252  * @retval     SSP_ERR_ASSERTION    p_version is NULL.
253  *
254  **********************************************************************************************************************/
R_ELC_VersionGet(ssp_version_t * const p_version)255 ssp_err_t R_ELC_VersionGet (ssp_version_t * const p_version)
256 {
257 #if ELC_CFG_PARAM_CHECKING_ENABLE
258     SSP_ASSERT(p_version);
259 #endif
260 
261     p_version->version_id = s_elc_version.version_id;
262 
263     return SSP_SUCCESS;
264 }
265 
266 /***********************************************************************************************************************
267  * Private Functions
268  **********************************************************************************************************************/
269 
270 /*******************************************************************************************************************//**
271  * @} (end addtogroup ELC)
272  **********************************************************************************************************************/
273