updates

Fork of nrf51-sdk by Lancaster University

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers section_vars.h Source File

section_vars.h

00001 /*
00002  * Copyright (c) Nordic Semiconductor ASA
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  *   1. Redistributions of source code must retain the above copyright notice, this
00009  *   list of conditions and the following disclaimer.
00010  *
00011  *   2. Redistributions in binary form must reproduce the above copyright notice, this
00012  *   list of conditions and the following disclaimer in the documentation and/or
00013  *   other materials provided with the distribution.
00014  *
00015  *   3. Neither the name of Nordic Semiconductor ASA nor the names of other
00016  *   contributors to this software may be used to endorse or promote products
00017  *   derived from this software without specific prior written permission.
00018  *
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
00024  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
00027  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030  *
00031  */
00032 
00033 #ifndef SECTION_VARS_H__
00034 #define SECTION_VARS_H__
00035 
00036 #include "app_util.h "
00037 
00038 #if defined __ICC_ARM__
00039 
00040 // turn on language extensions for iar
00041 #pragma language=extended
00042 
00043 #endif
00044 
00045 /**
00046  * @defgroup section_vars Section variables
00047  * @ingroup app_common
00048  * @{
00049  * @brief Section variables.
00050  */
00051 
00052 /**@brief Macro to delay macro expression of pragma
00053  *
00054  */
00055 #define NRF_PRAGMA(x) _Pragma(#x)
00056 
00057 
00058 /**@brief Macro to register section by name in code
00059  *
00060  * @param[in]   section_name    Name of the section to register
00061  **/
00062 #if defined __CC_ARM
00063 
00064 // Not required by this compiler
00065 #define NRF_SECTION_VARS_REGISTER_SECTION(section_name)
00066 
00067 #elif defined __GNUC__
00068 
00069 // Not required by this compiler
00070 #define NRF_SECTION_VARS_REGISTER_SECTION(section_name)
00071 
00072 #elif defined __ICCARM__
00073 
00074 #define NRF_SECTION_VARS_REGISTER_SECTION(section_name) NRF_PRAGMA(section = ## #section_name )
00075 
00076 #else
00077 
00078 #error TODO
00079 
00080 #endif
00081 
00082 /*lint -save -e27 */
00083 
00084 /**@brief Macro for accessing start of a named data section by symbol 
00085  *
00086  * @details     The symbol that this macro resolves to is used to access the section 
00087  *              by start address.
00088  *
00089  * @param[in]   section_name    Name of the section
00090  */
00091 #if defined __CC_ARM
00092 
00093 #define NRF_SECTION_VARS_START_SYMBOL(section_name)         section_name ## $$Base
00094 
00095 #elif defined __GNUC__
00096 
00097 #define NRF_SECTION_VARS_START_SYMBOL(section_name)         __start_ ## section_name
00098 
00099 #elif defined __ICCARM__
00100 
00101 #define NRF_SECTION_VARS_START_SYMBOL(section_name)         __section_begin(#section_name)
00102 
00103 #else
00104 
00105 #error TODO
00106 
00107 #endif
00108 
00109 
00110 /**@brief Macro for accessing end of a named data section by symbol
00111  *
00112  * @details     The symbol that this macro resolves to is used to access the section
00113  *              by end address.
00114  *
00115  * @param[in]   section_name    Name of the section    
00116  */
00117 #if defined __CC_ARM
00118 
00119 #define NRF_SECTION_VARS_END_SYMBOL(section_name)           section_name ## $$Limit
00120 
00121 #elif defined __GNUC__
00122 
00123 #define NRF_SECTION_VARS_END_SYMBOL(section_name)           __stop_ ## section_name
00124 
00125 #elif defined __ICCARM__
00126 
00127 #define NRF_SECTION_VARS_END_SYMBOL(section_name)           __section_end(#section_name)
00128 
00129 #endif
00130 
00131 /*lint -restore */
00132 
00133 
00134 /**@brief Macro for accessing Length of a named section
00135  *
00136  * @details     This macro is used to get the size of a named section.
00137  *
00138  * @param[in]   section_name    Name of the section
00139  */
00140 
00141 #if defined __CC_ARM
00142 
00143 #define NRF_SECTION_VARS_LENGTH(section_name) \
00144     ((uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name))
00145 
00146 #elif defined __GNUC__
00147 
00148  #define NRF_SECTION_VARS_LENGTH(section_name) \
00149     ((uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name))
00150 
00151 #elif defined __ICCARM__
00152 
00153  #define NRF_SECTION_VARS_LENGTH(section_name) \
00154     ((uint32_t)NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)NRF_SECTION_VARS_START_SYMBOL(section_name))
00155 
00156 #else
00157 
00158 #error TODO
00159 
00160 #endif
00161       
00162 
00163 /**@brief Macro for accessing the start address of a named section
00164  *
00165  * param[in]    section_name    Name of the section to get the start address from
00166  */
00167 #if defined __CC_ARM
00168 
00169 #define NRF_SECTION_VARS_START_ADDR(section_name)       (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name)
00170       
00171 #elif defined __GNUC__
00172       
00173 #define NRF_SECTION_VARS_START_ADDR(section_name)       (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name)
00174       
00175 #elif defined __ICCARM__
00176       
00177 #define NRF_SECTION_VARS_START_ADDR(section_name)       (uint32_t)iar_ ## section_name ## _start
00178 
00179 #else
00180       
00181 #error TODO
00182       
00183 #endif
00184 
00185       
00186 /*@brief Macro for accessing the end address of a named section
00187  *
00188  * @param[in]   section_name    Name of the section to get end address from
00189  */
00190 #if defined __CC_ARM
00191 
00192 #define NRF_SECTION_VARS_END_ADDR(section_name)         (uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name)
00193       
00194 #elif defined __GNUC__
00195 
00196 #define NRF_SECTION_VARS_END_ADDR(section_name)         (uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name)
00197       
00198 #elif defined __ICCARM__
00199 
00200 #define NRF_SECTION_VARS_END_ADDR(section_name)         (uint32_t)iar_ ## section_name ## _end
00201 
00202 #else
00203       
00204 #error TODO
00205       
00206 #endif
00207 
00208 
00209 /**@brief Macro for declaring symbols for named sections
00210  *
00211  * @note    These external declarations of section specific symbols are required for the linker in GCC and Keil (not IAR)
00212  *
00213  * @param[in]   type_name       Name of the type stored in the section
00214  * @param[in]   section_name    Name of the section
00215  */
00216 #if defined __CC_ARM
00217 
00218 #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name)      \
00219     extern type_name* NRF_SECTION_VARS_START_SYMBOL(section_name);      \
00220     extern void* NRF_SECTION_VARS_END_SYMBOL(section_name)
00221 
00222 #elif defined __GNUC__
00223 
00224 #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name)      \
00225     extern type_name* NRF_SECTION_VARS_START_SYMBOL(section_name);      \
00226     extern void* NRF_SECTION_VARS_END_SYMBOL(section_name)
00227 
00228 #elif defined __ICCARM__
00229 
00230 // No symbol registration required for IAR      
00231 #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name)                              \
00232     extern void*   iar_ ## section_name ## _start   = __section_begin(#section_name);            \
00233     extern void*   iar_ ## section_name ## _end     = __section_end(#section_name)
00234       
00235 #else
00236       
00237 #error TODO
00238 
00239 #endif
00240 
00241 
00242 /**@brief Macro to add symbols to a named section
00243  *
00244  * @details     The symbols are placed in a named section. All calls to this macro
00245  *              will result in symbols being placed in a contiguous manner in the named section. 
00246  *              This macro ensures that the symbol is not removed because of optimization level.
00247  *
00248  * @warning     There is no guarantee for ordering of placement. If ordering is required
00249  *
00250  * @warning     The symbols added in the named section must be word aligned to
00251  *              ensure that compilers do not pad the section during symbol placement.
00252  *
00253  * @param[in]   section_name    Name of the section
00254  * @param[in]   type_def        Datatype of the symbol to place in the given section
00255  */
00256 #if defined __CC_ARM
00257     
00258 #define NRF_SECTION_VARS_ADD(section_name, type_def) \
00259     static type_def __attribute__((section( #section_name ))) __attribute__((used))
00260 
00261 #elif defined __GNUC__
00262 
00263 #define NRF_SECTION_VARS_ADD(section_name, type_def) \
00264     static type_def __attribute__ ((section( #section_name ))) __attribute__ ((used))
00265 
00266 #elif defined __ICCARM__
00267 
00268 #define NRF_SECTION_VARS_ADD(section_name, type_def) \
00269     __root type_def @ #section_name
00270 
00271 #else
00272       
00273 #error    TODO
00274       
00275 #endif    
00276 
00277       
00278 /**@brief Macro to get symbol from named section
00279  *
00280  * @warning     The stored symbol can only be resolved using this macro if the 
00281  *              type of the data is word aligned. The operation of acquiring 
00282  *              the stored symbol relies on sizeof of the stored type, no 
00283  *              padding can exist in the named section in between individual 
00284  *              stored items or this macro will fail.
00285  *
00286  * @param[in]   i               Index of item in section
00287  * @param[in]   type_name       Type name of item in section
00288  * @param[in]   section_name    Name of the section
00289  */
00290       
00291 #if defined __CC_ARM
00292 
00293 #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
00294     (type_name*)(NRF_SECTION_VARS_START_ADDR(section_name) + i * sizeof(type_name))
00295       
00296 #elif defined __GNUC__
00297 
00298 #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
00299     (type_name*)(NRF_SECTION_VARS_START_ADDR(section_name) + i * sizeof(type_name))
00300       
00301 #elif defined __ICCARM__
00302 
00303 #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
00304       (type_name*)iar_ ## section_name ## _start + (i * sizeof(type_name))
00305 
00306 #else
00307 
00308 #error TODO
00309 
00310 #endif
00311 
00312 
00313 /**@brief Macro to get number of items in named section
00314  *
00315  * @param[in]   type_name       Type name of item in section
00316  * @param[in]   section_name    Name of the section
00317  */
00318 #define NRF_SECTION_VARS_COUNT(type_name, section_name) \
00319     NRF_SECTION_VARS_LENGTH(section_name) / sizeof(type_name)
00320 
00321 /** @} */
00322 
00323 #endif // SECTION_VARS_H__