nRF5 SDK for Mesh v5.0.0
nrf_mesh_section.h
1 /* Copyright (c) 2010 - 2020, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 #ifndef NRF_MESH_SECTION_H__
38 #define NRF_MESH_SECTION_H__
39 
40 #include "nrf_section.h"
41 #include "nrf_mesh_assert.h"
42 
52 #if defined(__GNUC__) && !defined(HOST)
53 
54 #define NRF_MESH_SECTION_START(section_name) CONCAT_2(__nrf_mesh_start_, section_name)
55 #define NRF_MESH_SECTION_END(section_name) CONCAT_2(__nrf_mesh_stop_, section_name)
56 
57 #define NRF_MESH_SECTION_ITEM_REGISTER_FLASH(section_name, section_var) section_var __attribute__ ((section(".nrf_mesh_flash." STRINGIFY(CONCAT_2(section_name, __1))))) __attribute__((used))
58 
59 #define NRF_MESH_SECTION_ITEM_REGISTER_RAM(section_name, section_var) section_var __attribute__ ((section(".nrf_mesh_ram." STRINGIFY(CONCAT_2(section_name, __1))))) __attribute__((used))
60 
61 
62 #define NRF_MESH_SECTION_DEF_FLASH(section_name, data_type) \
63  volatile data_type NRF_MESH_SECTION_START(section_name)[0] __attribute__ ((section(".nrf_mesh_flash." STRINGIFY(CONCAT_2(section_name, __0))))) __attribute__((used)); \
64  volatile data_type NRF_MESH_SECTION_END(section_name)[0] __attribute__ ((section(".nrf_mesh_flash." STRINGIFY(CONCAT_2(section_name, __2))))) __attribute__((used))
65 
66 #define NRF_MESH_SECTION_DEF_RAM(section_name, data_type) \
67  volatile data_type NRF_MESH_SECTION_START(section_name)[0] __attribute__ ((section(".nrf_mesh_ram." STRINGIFY(CONCAT_2(section_name, __0))))) __attribute__((used)); \
68  volatile data_type NRF_MESH_SECTION_END(section_name)[0] __attribute__ ((section(".nrf_mesh_ram." STRINGIFY(CONCAT_2(section_name, __2))))) __attribute__((used))
69 
70 
71 #define NRF_MESH_SECTION_LENGTH(section_name) \
72  ((size_t)&NRF_MESH_SECTION_END(section_name)[0] - \
73  (size_t)&NRF_MESH_SECTION_START(section_name)[0])
74 
75 #define NRF_MESH_SECTION_ITEM_GET(section_name, data_type, i) \
76  (data_type *) (NRF_MESH_SECTION_START(section_name) + i)
77 
78 #define NRF_MESH_SECTION_ITEM_COUNT(section_name, data_type) \
79  NRF_MESH_SECTION_LENGTH(section_name) / sizeof(data_type)
80 
81 #else
82 
83 #define NRF_MESH_SECTION_START(section_name) NRF_SECTION_START_ADDR(section_name)
84 #define NRF_MESH_SECTION_END(section_name) NRF_SECTION_END_ADDR(section_name)
85 
86 #define NRF_MESH_SECTION_ITEM_REGISTER_FLASH(section_name, section_var) NRF_SECTION_ITEM_REGISTER(section_name, section_var)
87 #define NRF_MESH_SECTION_ITEM_REGISTER_RAM(section_name, section_var) NRF_SECTION_ITEM_REGISTER(section_name, section_var)
88 
89 #define NRF_MESH_SECTION_DEF_FLASH(section_name, data_type) NRF_SECTION_DEF(section_name, data_type)
90 #define NRF_MESH_SECTION_DEF_RAM(section_name, data_type) NRF_SECTION_DEF(section_name, data_type)
91 
92 #define NRF_MESH_SECTION_LENGTH(section_name) NRF_SECTION_LENGTH(section_name)
93 
94 #define NRF_MESH_SECTION_ITEM_GET(section_name, data_type, i) NRF_SECTION_ITEM_GET(section_name, data_type, i)
95 #define NRF_MESH_SECTION_ITEM_COUNT(section_name, data_type) NRF_SECTION_ITEM_COUNT(section_name, data_type)
96 
97 #endif
98 
99 #define NRF_MESH_SECTION_FOR_EACH(section_name, data_type, variable) \
100  for (data_type * variable = (data_type *) NRF_MESH_SECTION_START(section_name); \
101  (intptr_t) variable != (intptr_t) NRF_MESH_SECTION_END(section_name); \
102  variable++)
103 
106 #endif /* NRF_MESH_SECTION_H__ */

Documentation feedback | Developer Zone | Subscribe | Updated