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 * File Name : bsp_common.h 21 * Description : Contains common includes, typedefs, and macros used by the BSP. 22 ***********************************************************************************************************************/ 23 24 /*******************************************************************************************************************//** 25 * @ingroup BSP_Interface 26 * @defgroup BSP_MCU_COMMON Common BSP Code 27 * @brief Code common to all BSPs. 28 * 29 * Implements functions that are common to all BSPs. 30 * 31 * @{ 32 ***********************************************************************************************************************/ 33 34 #ifndef BSP_COMMON_H_ 35 #define BSP_COMMON_H_ 36 37 /*********************************************************************************************************************** 38 Includes <System Includes> , "Project Includes" 39 ***********************************************************************************************************************/ 40 /* C99 includes. */ 41 #include <stdint.h> 42 #include <stddef.h> 43 #include <stdbool.h> 44 #include <assert.h> 45 /* Different compiler support. */ 46 #include "../../inc/ssp_common_api.h" 47 #include "bsp_compiler_support.h" 48 #include "bsp_cfg.h" 49 50 /* Common macro for SSP header files. There is also a corresponding SSP_FOOTER macro at the end of this file. */ 51 SSP_HEADER 52 53 /*********************************************************************************************************************** 54 Macro definitions 55 ***********************************************************************************************************************/ 56 /** Used to signify that an ELC event is not able to be used as an interrupt. */ 57 #define BSP_IRQ_DISABLED (0xFFU) 58 59 /* Version of this module's code and API. */ 60 #define BSP_CODE_VERSION_MAJOR (1U) 61 #define BSP_CODE_VERSION_MINOR (16U) 62 #define BSP_API_VERSION_MAJOR (1U) 63 #define BSP_API_VERSION_MINOR (0U) 64 65 #if 1 == BSP_CFG_RTOS 66 #define SF_CONTEXT_SAVE tx_isr_start(__get_IPSR()); 67 #define SF_CONTEXT_RESTORE tx_isr_end(__get_IPSR()); 68 void tx_isr_start(unsigned long isr_id); 69 void tx_isr_end(unsigned long isr_id); 70 #else 71 #define SF_CONTEXT_SAVE 72 #define SF_CONTEXT_RESTORE 73 #endif 74 75 /** Function call to insert before returning assertion error. */ 76 #if (1 == BSP_CFG_ASSERT) 77 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */ 78 #define SSP_ASSERT_FAIL SSP_ERROR_LOG(SSP_ERR_ASSERTION, __FILE__, __LINE__); 79 #else 80 #define SSP_ASSERT_FAIL 81 #endif 82 83 /** This function is called before returning an error code. To stop on a runtime error, define ssp_error_log in 84 * user code and do required debugging (breakpoints, stack dump, etc) in this function.*/ 85 #if (1 == BSP_CFG_ERROR_LOG) 86 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */ 87 /*LDRA_INSPECTED 340 S. Function-like macro used here to allow usage of a standard error logger which extracts module name and line number in a module without adding "#if SSP_ERROR_LOG". */ 88 #ifndef SSP_ERROR_LOG 89 #define SSP_ERROR_LOG(err, module, version) SSP_PARAMETER_NOT_USED((version)); \ 90 ssp_error_log((err), (module), __LINE__); 91 #endif 92 #else 93 /*LDRA_INSPECTED 340 S. Function-like macro used here to allow usage of a standard error logger which extracts module name and line number in a module without adding "#if SSP_ERROR_LOG". */ 94 #define SSP_ERROR_LOG(err, module, version) 95 #endif 96 97 /** Default assertion calls ::SSP_ASSERT_FAIL if condition "a" is false. Used to identify incorrect use of API's in SSP 98 * functions. */ 99 #if (2 == BSP_CFG_ASSERT) 100 #define SSP_ASSERT(a) {assert(a);} 101 #else 102 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */ 103 #define SSP_ASSERT(a) \ 104 { \ 105 if ((a)) \ 106 { \ 107 (void) 0;/* Do nothing */ \ 108 } \ 109 else \ 110 { \ 111 SSP_ASSERT_FAIL; \ 112 return SSP_ERR_ASSERTION; \ 113 } \ 114 } 115 #endif // ifndef SSP_ASSERT 116 117 /** All SSP error codes are returned using this macro. Calls ::SSP_ERROR_LOG function if condition "a" is false. Used 118 * to identify runtime errors in SSP functions. */ 119 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */ 120 #define SSP_ERROR_RETURN(a, err, module, version) \ 121 { \ 122 if ((a)) \ 123 { \ 124 (void) 0; /* Do nothing */ \ 125 } \ 126 else \ 127 { \ 128 SSP_ERROR_LOG((err), (module), (version)); \ 129 return (err); \ 130 } \ 131 } 132 133 /** This check is performed to select suitable ASM API with respect to core */ 134 /* The macros __CORE__ , __ARM7EM__ and __ARM_ARCH_8M_BASE__ are undefined for GCC, but defined(__IAR_SYSTEMS_ICC__) is false for GCC, so 135 * the left half of the || expression evaluates to false for GCC regardless of the values of these macros. */ 136 /*LDRA_INSPECTED 337 S *//*LDRA_INSPECTED 337 S *//*LDRA_INSPECTED 337 S *//*LDRA_INSPECTED 337 S */ 137 #if (defined(__IAR_SYSTEMS_ICC__) && ((__CORE__ == __ARM7EM__) || (__CORE__ == __ARM_ARCH_8M_BASE__) ) ) || defined(__ARM_ARCH_7EM__) // CM4 138 #ifndef BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION 139 #define BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION (0U) 140 #endif 141 #else // CM0+ 142 #ifdef BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION 143 #undef BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION 144 #define BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION (0U) 145 #endif 146 #endif 147 148 /** This macro defines a variable for saving previous mask value */ 149 #ifndef SSP_CRITICAL_SECTION_DEFINE 150 /*LDRA_INSPECTED 77 S This macro does need to be surrounded by parentheses. */ 151 #define SSP_CRITICAL_SECTION_DEFINE uint32_t old_mask_level = 0U 152 #endif 153 154 /** This macro defined to get the mask value */ 155 /*LDRA_INSPECTED 337 S *//*LDRA_INSPECTED 337 S */ 156 #ifndef SSP_CRITICAL_SECTION_ENTER 157 #if(0 == BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION) 158 #define SSP_CRITICAL_SECTION_ENTER old_mask_level = __get_PRIMASK(); \ 159 __set_PRIMASK(1U) 160 #else 161 #define SSP_CRITICAL_SECTION_ENTER old_mask_level = (uint32_t) __get_BASEPRI(); \ 162 __set_BASEPRI((uint8_t) (BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION << (8U - __NVIC_PRIO_BITS))) 163 #endif 164 #endif 165 166 /** This macro defined to restore the old mask value */ 167 /*LDRA_INSPECTED 337 S *//*LDRA_INSPECTED 337 S */ 168 #ifndef SSP_CRITICAL_SECTION_EXIT 169 #if(0 == BSP_CFG_IRQ_MASK_LEVEL_FOR_CRITICAL_SECTION) 170 #define SSP_CRITICAL_SECTION_EXIT __set_PRIMASK(old_mask_level) 171 #else 172 #define SSP_CRITICAL_SECTION_EXIT __set_BASEPRI(old_mask_level) 173 #endif 174 #endif 175 176 /** @} (end defgroup BSP_MCU_COMMON) */ 177 178 /*********************************************************************************************************************** 179 Typedef definitions 180 ***********************************************************************************************************************/ 181 182 /** Different warm start entry locations in the BSP. */ 183 typedef enum e_bsp_warm_start_event 184 { 185 BSP_WARM_START_PRE_C = 0, ///< Called almost immediately after reset. No C runtime environment, clocks, or IRQs. 186 BSP_WARM_START_POST_C ///< Called after clocks and C runtime environment have been setup 187 } bsp_warm_start_event_t; 188 189 /*********************************************************************************************************************** 190 Exported global variables 191 ***********************************************************************************************************************/ 192 193 /*********************************************************************************************************************** 194 Exported global functions (to be accessed by other files) 195 ***********************************************************************************************************************/ 196 #if ((1 == BSP_CFG_ERROR_LOG) || (1 == BSP_CFG_ASSERT)) 197 /** Prototype of function called before errors are returned in SSP code if BSP_CFG_LOG_ERRORS is set to 1. */ 198 void ssp_error_log(ssp_err_t err, const char * module, int32_t line); 199 #endif 200 201 /** In the event of an unrecoverable error the BSP will by default call the __BKPT() intrinsic function which will 202 * alert the user of the error. The user can override this default behavior by defining their own 203 * BSP_CFG_HANDLE_UNRECOVERABLE_ERROR macro. 204 */ 205 #if !defined(BSP_CFG_HANDLE_UNRECOVERABLE_ERROR) 206 /*LDRA_INSPECTED 77 S This macro does not work when surrounded by parentheses. */ 207 #define BSP_CFG_HANDLE_UNRECOVERABLE_ERROR(x) __BKPT((x)) 208 #endif 209 210 211 /* Common macro for SSP header files. There is also a corresponding SSP_HEADER macro at the top of this file. */ 212 SSP_FOOTER 213 214 #endif /* BSP_COMMON_H_ */ 215