| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- /* Copyright (c) 2016 Nordic Semiconductor. All Rights Reserved.
- *
- * The information contained herein is property of Nordic Semiconductor ASA.
- * Terms and conditions of usage are described in detail in NORDIC
- * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
- *
- * Licensees are granted free, non-transferable use of the information. NO
- * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
- * the file.
- *
- */
- #ifndef SECTION_VARS_H__
- #define SECTION_VARS_H__
- /**
- * @defgroup section_vars Section variables
- * @ingroup app_common
- * @{
- *
- * @brief Section variables.
- */
- #if defined(__ICCARM__)
- // Enable IAR language extensions
- #pragma language=extended
- #endif
- // Macro to delay macro expansion.
- #define NRF_PRAGMA(x) _Pragma(#x)
- /**@brief Macro to register a named section.
- *
- * @param[in] section_name Name of the section to register.
- */
- #if defined(__CC_ARM)
- // Not required by this compiler.
- #define NRF_SECTION_VARS_REGISTER_SECTION(section_name)
- #elif defined(__GNUC__)
- // Not required by this compiler.
- #define NRF_SECTION_VARS_REGISTER_SECTION(section_name)
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_REGISTER_SECTION(section_name) NRF_PRAGMA(section = #section_name)
- #endif
- /*lint -save -e27 */
- /**@brief Macro to obtain the linker symbol for the beginning of a given section.
- *
- * @details The symbol that this macro resolves to is used to obtain a section start address.
- *
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_START_SYMBOL(section_name) section_name ## $$Base
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_START_SYMBOL(section_name) __start_ ## section_name
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_START_SYMBOL(section_name) __section_begin(#section_name)
- #endif
- /**@brief Macro to obtain the linker symbol for the end of a given section.
- *
- * @details The symbol that this macro resolves to is used to obtain a section end address.
- *
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_END_SYMBOL(section_name) section_name ## $$Limit
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_END_SYMBOL(section_name) __stop_ ## section_name
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_END_SYMBOL(section_name) __section_end(#section_name)
- #endif
- /*lint -restore */
- /**@brief Macro for retrieving the length of a given section, in bytes.
- *
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_LENGTH(section_name) \
- ((uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name))
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_LENGTH(section_name) \
- ((uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name))
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_LENGTH(section_name) \
- ((uint32_t)NRF_SECTION_VARS_END_SYMBOL(section_name) - (uint32_t)NRF_SECTION_VARS_START_SYMBOL(section_name))
- #endif
-
- /**@brief Macro to obtain the start address of a named section.
- *
- * param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_START_ADDR(section_name) (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name)
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_START_ADDR(section_name) (uint32_t)&NRF_SECTION_VARS_START_SYMBOL(section_name)
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_START_ADDR(section_name) (uint32_t)iar_ ## section_name ## _start
- #endif
-
- /*@brief Macro to obtain the end address of a named section.
- *
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_END_ADDR(section_name) (uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name)
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_END_ADDR(section_name) (uint32_t)&NRF_SECTION_VARS_END_SYMBOL(section_name)
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_END_ADDR(section_name) (uint32_t)iar_ ## section_name ## _end
- #endif
- /**@brief Macro to extern a named section start and stop symbols.
- *
- * @note These declarations are required for GCC and Keil linkers (but not for IAR's).
- *
- * @param[in] type_name Name of the type stored in the section.
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name) \
- extern type_name * NRF_SECTION_VARS_START_SYMBOL(section_name); \
- extern void * NRF_SECTION_VARS_END_SYMBOL(section_name)
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name) \
- extern type_name * NRF_SECTION_VARS_START_SYMBOL(section_name); \
- extern void * NRF_SECTION_VARS_END_SYMBOL(section_name)
- #elif defined(__ICCARM__)
- // No symbol registration required for IAR.
- #define NRF_SECTION_VARS_REGISTER_SYMBOLS(type_name, section_name) \
- extern void * iar_ ## section_name ## _start = __section_begin(#section_name); \
- extern void * iar_ ## section_name ## _end = __section_end(#section_name)
- #endif
- /**@brief Macro to declare a variable to be placed in a named section.
- *
- * @details Declares a variable to be placed in a named section. This macro ensures that its symbol
- * is not stripped by the linker because of optimizations.
- *
- * @warning The order with which variables are placed in a section is implementation dependant.
- * Generally, variables are placed in a section depending on the order with which they
- * are found by the linker.
- *
- * @warning The symbols added in the named section must be word aligned to prevent padding.
- *
- * @param[in] section_name Name of the section.
- * @param[in] type_def Datatype of the variable to place in the given section.
- */
- #if defined(__CC_ARM)
-
- #define NRF_SECTION_VARS_ADD(section_name, type_def) \
- static type_def __attribute__ ((section(#section_name))) __attribute__((used))
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_ADD(section_name, type_def) \
- static type_def __attribute__ ((section("."#section_name))) __attribute__((used))
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_ADD(section_name, type_def) \
- __root type_def @ #section_name
- #endif
- /**@brief Macro to get symbol from named section.
- *
- * @warning The stored symbol can only be resolved using this macro if the
- * type of the data is word aligned. The operation of acquiring
- * the stored symbol relies on sizeof of the stored type, no
- * padding can exist in the named section in between individual
- * stored items or this macro will fail.
- *
- * @param[in] i Index of item in section.
- * @param[in] type_name Type name of item in section.
- * @param[in] section_name Name of the section.
- */
- #if defined(__CC_ARM)
- #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
- (type_name*)(NRF_SECTION_VARS_START_ADDR(section_name) + i * sizeof(type_name))
-
- #elif defined(__GNUC__)
- #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
- (type_name*)(NRF_SECTION_VARS_START_ADDR(section_name) + i * sizeof(type_name))
-
- #elif defined(__ICCARM__)
- #define NRF_SECTION_VARS_GET(i, type_name, section_name) \
- (type_name*)(NRF_SECTION_VARS_START_ADDR(section_name) + i * sizeof(type_name))
- #endif
- /**@brief Macro to get number of items in named section.
- *
- * @param[in] type_name Type name of item in section.
- * @param[in] section_name Name of the section.
- */
- #define NRF_SECTION_VARS_COUNT(type_name, section_name) \
- NRF_SECTION_VARS_LENGTH(section_name) / sizeof(type_name)
- /** @} */
- #endif // SECTION_VARS_H__
|