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