xref: /btstack/port/renesas-ek-ra6m4a-da14531/e2-project/ra/fsp/src/bsp/mcu/all/bsp_common.c (revision c30869498fb8e98c1408c9db0e7624f02f483b73)
1 /***********************************************************************************************************************
2  * Copyright [2020-2022] 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 /***********************************************************************************************************************
22  *
23  * Includes
24  **********************************************************************************************************************/
25 #include "bsp_api.h"
26 
27 /***********************************************************************************************************************
28  * Macro definitions
29  **********************************************************************************************************************/
30 #if defined(__ICCARM__)
31  #define WEAK_ERROR_ATTRIBUTE
32  #define WEAK_INIT_ATTRIBUTE
33  #pragma weak fsp_error_log                            = fsp_error_log_internal
34  #pragma weak bsp_init                                 = bsp_init_internal
35 #elif defined(__GNUC__)
36 
37  #define WEAK_ERROR_ATTRIBUTE    __attribute__((weak, alias("fsp_error_log_internal")))
38 
39  #define WEAK_INIT_ATTRIBUTE     __attribute__((weak, alias("bsp_init_internal")))
40 #endif
41 
42 #define FSP_SECTION_VERSION      ".version"
43 
44 /***********************************************************************************************************************
45  * Typedef definitions
46  **********************************************************************************************************************/
47 
48 /***********************************************************************************************************************
49  * Private function prototypes
50  **********************************************************************************************************************/
51 
52 /** Prototype of initialization function called before main.  This prototype sets the weak association of this
53  * function to an internal example implementation. If this function is defined in the application code, the
54  * application code version is used. */
55 
56 void bsp_init(void * p_args) WEAK_INIT_ATTRIBUTE;
57 
58 void bsp_init_internal(void * p_args); /// Default initialization function
59 
60 #if ((1 == BSP_CFG_ERROR_LOG) || (1 == BSP_CFG_ASSERT))
61 
62 /** Prototype of function called before errors are returned in FSP code if BSP_CFG_ERROR_LOG is set to 1.  This
63  * prototype sets the weak association of this function to an internal example implementation. */
64 
65 void fsp_error_log(fsp_err_t err, const char * file, int32_t line) WEAK_ERROR_ATTRIBUTE;
66 
67 void fsp_error_log_internal(fsp_err_t err, const char * file, int32_t line); /// Default error logger function
68 
69 #endif
70 
71 /***********************************************************************************************************************
72  * Exported global variables (to be accessed by other files)
73  **********************************************************************************************************************/
74 
75 /* FSP pack version structure. */
76 static BSP_DONT_REMOVE const fsp_pack_version_t g_fsp_version BSP_PLACE_IN_SECTION (FSP_SECTION_VERSION) =
77 {
78     .version_id_b =
79     {
80         .minor = FSP_VERSION_MINOR,
81         .major = FSP_VERSION_MAJOR,
82         .build = FSP_VERSION_BUILD,
83         .patch = FSP_VERSION_PATCH
84     }
85 };
86 
87 /* Public FSP version name. */
88 static BSP_DONT_REMOVE const uint8_t g_fsp_version_string[] BSP_PLACE_IN_SECTION(FSP_SECTION_VERSION) =
89     FSP_VERSION_STRING;
90 
91 /* Unique FSP version ID. */
92 static BSP_DONT_REMOVE const uint8_t g_fsp_version_build_string[] BSP_PLACE_IN_SECTION(FSP_SECTION_VERSION) =
93     FSP_VERSION_BUILD_STRING;
94 
95 /*******************************************************************************************************************//**
96  * @addtogroup BSP_MCU
97  * @{
98  **********************************************************************************************************************/
99 
100 /***********************************************************************************************************************
101  * Private global variables and functions
102  **********************************************************************************************************************/
103 
104 /*******************************************************************************************************************//**
105  * Get the FSP version based on compile time macros.
106  *
107  * @param[out] p_version        Memory address to return version information to.
108  *
109  * @retval FSP_SUCCESS          Version information stored.
110  * @retval FSP_ERR_ASSERTION    The parameter p_version is NULL.
111  **********************************************************************************************************************/
R_FSP_VersionGet(fsp_pack_version_t * const p_version)112 fsp_err_t R_FSP_VersionGet (fsp_pack_version_t * const p_version)
113 {
114 #if BSP_CFG_PARAM_CHECKING_ENABLE
115 
116     /** Verify parameters are valid */
117     FSP_ASSERT(NULL != p_version);
118 #endif
119 
120     *p_version = g_fsp_version;
121 
122     return FSP_SUCCESS;
123 }
124 
125 #if ((1 == BSP_CFG_ERROR_LOG) || (1 == BSP_CFG_ASSERT))
126 
127 /*******************************************************************************************************************//**
128  * Default error logger function, used only if fsp_error_log is not defined in the user application.
129  *
130  * @param[in]  err     The error code encountered.
131  * @param[in]  file    The file name in which the error code was encountered.
132  * @param[in]  line    The line number at which the error code was encountered.
133  **********************************************************************************************************************/
fsp_error_log_internal(fsp_err_t err,const char * file,int32_t line)134 void fsp_error_log_internal (fsp_err_t err, const char * file, int32_t line)
135 {
136     /** Do nothing. Do not generate any 'unused' warnings. */
137     FSP_PARAMETER_NOT_USED(err);
138     FSP_PARAMETER_NOT_USED(file);
139     FSP_PARAMETER_NOT_USED(line);
140 }
141 
142 #endif
143 
144 /** @} (end addtogroup BSP_MCU) */
145 
146 /*******************************************************************************************************************//**
147  * Default initialization function, used only if bsp_init is not defined in the user application.
148  **********************************************************************************************************************/
bsp_init_internal(void * p_args)149 void bsp_init_internal (void * p_args)
150 {
151     /* Do nothing. */
152     FSP_PARAMETER_NOT_USED(p_args);
153 }
154 
155 #if defined(__ARMCC_VERSION)
156 
157 /*******************************************************************************************************************//**
158  * Default implementation of assert for AC6.
159  **********************************************************************************************************************/
160 __attribute__((weak, noreturn))
__aeabi_assert(const char * expr,const char * file,int line)161 void __aeabi_assert (const char * expr, const char * file, int line)
162 {
163     FSP_PARAMETER_NOT_USED(expr);
164     FSP_PARAMETER_NOT_USED(file);
165     FSP_PARAMETER_NOT_USED(line);
166     __BKPT(0);
167     while (1)
168     {
169         /* Do nothing. */
170     }
171 }
172 
173 #elif defined(__GNUC__)
174 
175 /* The default assert implementation for GCC brings in printing/formatting code.  FSP overrides the default assert
176  * behavior to reduce code size. */
177 
178  #if !BSP_CFG_USE_STANDARD_ASSERT
179 
180 /*******************************************************************************************************************//**
181  * Default implementation of assert for GCC.
182  **********************************************************************************************************************/
__assert_func(const char * file,int line,const char * func,const char * expr)183 BSP_WEAK_REFERENCE void __assert_func (const char * file, int line, const char * func, const char * expr)
184 {
185     FSP_PARAMETER_NOT_USED(file);
186     FSP_PARAMETER_NOT_USED(line);
187     FSP_PARAMETER_NOT_USED(func);
188     FSP_PARAMETER_NOT_USED(expr);
189     __BKPT(0);
190     while (1)
191     {
192         /* Do nothing. */
193     }
194 }
195 
196  #endif
197 
198 #endif
199