1 /***************************************************************************//**
2  * @file
3  * @brief RAM code support.
4  *******************************************************************************
5  * # License
6  * <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
7  *******************************************************************************
8  *
9  * SPDX-License-Identifier: Zlib
10  *
11  * The licensor of this software is Silicon Laboratories Inc.
12  *
13  * This software is provided 'as-is', without any express or implied
14  * warranty. In no event will the authors be held liable for any damages
15  * arising from the use of this software.
16  *
17  * Permission is granted to anyone to use this software for any purpose,
18  * including commercial applications, and to alter it and redistribute it
19  * freely, subject to the following restrictions:
20  *
21  * 1. The origin of this software must not be misrepresented; you must not
22  *    claim that you wrote the original software. If you use this software
23  *    in a product, an acknowledgment in the product documentation would be
24  *    appreciated but is not required.
25  * 2. Altered source versions must be plainly marked as such, and must not be
26  *    misrepresented as being the original software.
27  * 3. This notice may not be removed or altered from any source distribution.
28  *
29  ******************************************************************************/
30 
31 #ifndef EM_RAMFUNC_H
32 #define EM_RAMFUNC_H
33 
34 #include "sl_code_classification.h"
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 /* *INDENT-OFF* */
41 /***************************************************************************//**
42  * @addtogroup ramfunc RAMFUNC - RAM Function Support
43  * @brief RAM code support
44  * @details
45  *  Provides support for executing code from RAM.
46  *  Provides a unified method to manage RAM code across all supported tools.
47  * @{
48 
49   @note
50    Other cross-compiler support macros are implemented in [COMMON](../../common/api/group-common).
51 
52   @note
53     Functions executing from RAM should not be declared as static.
54 
55   @warning
56     Standard library facilities are available to the tool with GCC in hosted
57 	mode (default), regardless of the section attribute. Calls to standard
58     libraries placed in the default section may therefore occur. To disable
59     hosted mode, add '-ffreestanding' to the build command line. This is the
60     only way to guarantee no calls to standard libraries with GCC.
61     Read more at www.gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Standards.html
62 
63   @warning
64     Keil/ARM uVision users must add a section named "ram_code" in their linker
65     scatter file. This section must be in RAM memory. Look in the MCU SDK for
66     example scatter files (ram_code.sct).
67 
68   @n @section ramfunc_usage Usage
69 
70   In your .h file:
71   @verbatim
72   #include "em_ramfunc.h"
73 
74   SL_RAMFUNC_DECLARATOR
75   void MyPrint(const char* string);
76   @endverbatim
77 
78   Issues have been observed with ARM GCC when there is no declarator. It is
79   recommended to have a declarator also for internal functions but move the
80   declarator to the .c file.
81 
82   In your .c file:
83   @verbatim
84   #include "em_ramfunc.h"
85 
86   SL_RAMFUNC_DEFINITION_BEGIN
87   void MyPrint(const char* string)
88   {
89   ...
90   }
91   SL_RAMFUNC_DEFINITION_END
92   @endverbatim
93 
94  ******************************************************************************/
95 /* *INDENT-ON* */
96 
97 /*******************************************************************************
98  ******************************   DEFINES    ***********************************
99  ******************************************************************************/
100 
101 /**
102  * @brief
103  *    This define is not present by default. By compiling with define
104  *    @ref SL_RAMFUNC_DISABLE, code placed in RAM by SL_RAMFUNC macros
105  *    will be placed in default code space (Flash) instead.
106  *
107  * @note
108  *    This define is not present by default.
109  */
110 #if defined(DOXY_DOC_ONLY)
111 #define SL_RAMFUNC_DISABLE
112 #endif
113 
114 #if defined(SL_RAMFUNC_DISABLE)
115 /** @brief Compiler ported function declarator for RAM code. */
116 #define SL_RAMFUNC_DECLARATOR
117 
118 /** @brief Compiler ported function definition begin marker for RAM code. */
119 #define SL_RAMFUNC_DEFINITION_BEGIN
120 
121 /** @brief Compiler ported function definition end marker for RAM code. */
122 #define SL_RAMFUNC_DEFINITION_END
123 
124 #elif defined(__CC_ARM)
125 /* MDK-ARM compiler */
126 #define SL_RAMFUNC_DECLARATOR
127 #define SL_RAMFUNC_DEFINITION_BEGIN    _Pragma("arm section code=\"ram_code\"")
128 #define SL_RAMFUNC_DEFINITION_END      _Pragma("arm section code")
129 
130 #elif defined(__ICCARM__)
131 /* IAR Embedded Workbench */
132 #define SL_RAMFUNC_DECLARATOR          SL_CODE_RAM
133 #define SL_RAMFUNC_DEFINITION_BEGIN    SL_RAMFUNC_DECLARATOR
134 #define SL_RAMFUNC_DEFINITION_END
135 
136 #elif defined(__GNUC__) && (defined(__CROSSWORKS_ARM) || defined(__SES_ARM))
137 /* Rowley Crossworks and Segger Embedded Studio */
138 #define SL_RAMFUNC_DECLARATOR          SL_CODE_RAM
139 #define SL_RAMFUNC_DEFINITION_BEGIN    SL_RAMFUNC_DECLARATOR
140 #define SL_RAMFUNC_DEFINITION_END
141 
142 #elif defined(__GNUC__) && defined(__ZEPHYR__)
143 /* Zephyr environment */
144 #define SL_RAMFUNC_DECLARATOR          SL_CODE_RAM
145 #define SL_RAMFUNC_DEFINITION_BEGIN    SL_RAMFUNC_DECLARATOR
146 #define SL_RAMFUNC_DEFINITION_END
147 
148 #elif defined(__GNUC__)
149 /* Simplicity Studio, Atollic and Vanilla armgcc */
150 #define SL_RAMFUNC_DECLARATOR          SL_CODE_RAM
151 #define SL_RAMFUNC_DEFINITION_BEGIN    SL_RAMFUNC_DECLARATOR
152 #define SL_RAMFUNC_DEFINITION_END
153 
154 #endif
155 
156 /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */
157 /* Deprecated macro names */
158 #define RAMFUNC_DECLARATOR          SL_RAMFUNC_DECLARATOR
159 #define RAMFUNC_DEFINITION_BEGIN    SL_RAMFUNC_DEFINITION_BEGIN
160 #define RAMFUNC_DEFINITION_END      SL_RAMFUNC_DEFINITION_END
161 /** @endcond */
162 
163 /** @} (end addtogroup ramfunc) */
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* EM_RAMFUNC_H */
170