VSF Documented
esp_attr.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_attr.h".
20 *
21 * Provides function / variable / type attributes used across ESP-IDF.
22 * Covers two categories:
23 *
24 * 1. Universal compiler attributes (PACKED, ALIGN, INLINE, NOINLINE, etc.)
25 * — mapped to compiler built-ins, no platform dependency.
26 *
27 * 2. Platform-specific memory-region attributes (IRAM_ATTR, DRAM_ATTR,
28 * RTC_*, DMA_*, COREDUMP_*) — deferred. These require per-chip linker-
29 * script knowledge that VSF does not abstract at this layer. Application
30 * code that transitively includes these macros will hit a no-op stub.
31 *
32 * Baseline: ESP-IDF v5.1 public API.
33 */
34
35#ifndef __VSF_ESPIDF_ESP_ATTR_H__
36#define __VSF_ESPIDF_ESP_ATTR_H__
37
38#include "esp_assert.h"
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* ------------------------------------------------------------------ */
45/* 1. Universal compiler attributes */
46/* ------------------------------------------------------------------ */
47
48#define ROMFN_ATTR /* ESP-specific, no-op on VSF */
49
50/* Packed struct member */
51#ifndef PACKED_ATTR
52# define PACKED_ATTR __attribute__((packed))
53#endif
54
55/* Word (4-byte) alignment */
56#ifndef WORD_ALIGNED_ATTR
57# define WORD_ALIGNED_ATTR __attribute__((aligned(4)))
58#endif
59
60/* Force inlining */
61#ifndef FORCE_INLINE_ATTR
62# define FORCE_INLINE_ATTR static inline __attribute__((always_inline))
63#endif
64
65/* Prevent inlining */
66#ifndef NOINLINE_ATTR
67# define NOINLINE_ATTR __attribute__((noinline))
68#endif
69
70/* Mark a char array as not null-terminated (GCC 15+) */
71#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 15)
72# define NONSTRING_ATTR __attribute__((nonstring))
73#else
74# define NONSTRING_ATTR
75#endif
76
77/* C++: enum as bit-flag with operator overloads */
78#ifdef __cplusplus
79# define _FLAG_ATTR_IMPL(TYPE, INT_TYPE) \
80 FORCE_INLINE_ATTR constexpr TYPE operator~ (TYPE a) { return (TYPE)~(INT_TYPE)a; } \
81 FORCE_INLINE_ATTR constexpr TYPE operator| (TYPE a, TYPE b) { return (TYPE)((INT_TYPE)a | (INT_TYPE)b); } \
82 FORCE_INLINE_ATTR constexpr TYPE operator& (TYPE a, TYPE b) { return (TYPE)((INT_TYPE)a & (INT_TYPE)b); } \
83 FORCE_INLINE_ATTR constexpr TYPE operator^ (TYPE a, TYPE b) { return (TYPE)((INT_TYPE)a ^ (INT_TYPE)b); } \
84 FORCE_INLINE_ATTR constexpr TYPE operator>> (TYPE a, int b) { return (TYPE)((INT_TYPE)a >> b); } \
85 FORCE_INLINE_ATTR constexpr TYPE operator<< (TYPE a, int b) { return (TYPE)((INT_TYPE)a << b); } \
86 FORCE_INLINE_ATTR TYPE& operator|=(TYPE& a, TYPE b) { a = a | b; return a; } \
87 FORCE_INLINE_ATTR TYPE& operator&=(TYPE& a, TYPE b) { a = a & b; return a; } \
88 FORCE_INLINE_ATTR TYPE& operator^=(TYPE& a, TYPE b) { a = a ^ b; return a; } \
89 FORCE_INLINE_ATTR TYPE& operator>>=(TYPE& a, int b) { a = a >> b; return a; } \
90 FORCE_INLINE_ATTR TYPE& operator<<=(TYPE& a, int b) { a = a << b; return a; }
91# define _FLAG_ATTR_U32(TYPE) _FLAG_ATTR_IMPL(TYPE, uint32_t)
92# define FLAG_ATTR(TYPE) _FLAG_ATTR_U32(TYPE)
93#else
94# define FLAG_ATTR(TYPE)
95#endif
96
97/* Deprecation: active only in CI builds (controlled via sdkconfig.h) */
98#include "sdkconfig.h"
99#ifdef CONFIG_IDF_CI_BUILD
100# define IDF_DEPRECATED(REASON) __attribute__((deprecated(REASON)))
101#else
102# define IDF_DEPRECATED(REASON)
103#endif
104
105/* ------------------------------------------------------------------ */
106/* 2. Section-placement internal macros (used by platform attrs) */
107/* ------------------------------------------------------------------ */
108#define _ESP_COUNTER_STRINGIFY(COUNTER) #COUNTER
109
110#if defined(__APPLE__) && defined(__MACH__)
111# define _SECTION_ATTR_IMPL(SECTION, COUNTER)
112# define _SECTION_FORCE_ATTR_IMPL(SECTION, COUNTER)
113#else
114# define _SECTION_ATTR_IMPL(SECTION, COUNTER) \
115 __attribute__((section(SECTION "." _ESP_COUNTER_STRINGIFY(COUNTER))))
116# define _SECTION_FORCE_ATTR_IMPL(SECTION, COUNTER) \
117 __attribute__((noinline, section(SECTION "." _ESP_COUNTER_STRINGIFY(COUNTER))))
118#endif
119
120/* ------------------------------------------------------------------ */
121/* 3. Platform memory-region attributes (deferred — no-op stubs) */
122/* ------------------------------------------------------------------ */
123#define IRAM_ATTR
124#define FORCE_IRAM_ATTR
125#define DRAM_ATTR
126#define SPM_IRAM_ATTR
127#define FORCE_SPM_IRAM_ATTR
128#define SPM_DRAM_ATTR
129#define TCM_IRAM_ATTR
130#define FORCE_TCM_IRAM_ATTR
131#define TCM_DRAM_ATTR
132#define NOLOAD_ATTR
133#define IRAM_8BIT_ACCESSIBLE 0
134#define IRAM_DATA_ATTR
135#define COREDUMP_IRAM_DATA_ATTR
136#define IRAM_BSS_ATTR
137#define DMA_ATTR
138#define DRAM_DMA_ALIGNED_ATTR WORD_ALIGNED_ATTR
139#define DRAM_STR(str) (str)
140#define RTC_DATA_ATTR
141#define RTC_NOINIT_ATTR
142#define RTC_RODATA_ATTR
143#define COREDUMP_RTC_DATA_ATTR
144#define RTC_SLOW_ATTR
145#define RTC_IRAM_ATTR
146#define RTC_FAST_ATTR
147#define COREDUMP_RTC_FAST_ATTR
148#define COREDUMP_NOINIT_ATTR
149#define __NOINIT_ATTR
150#define EXT_RAM_BSS_ATTR
151#define COREDUMP_EXTRAM_ATTR
152#define EXT_RAM_NOINIT_ATTR
153#define COREDUMP_EXTRAM_NOINIT_ATTR
154#define COREDUMP_DRAM_ATTR
155
156#ifdef __cplusplus
157}
158#endif
159
160#endif // __VSF_ESPIDF_ESP_ATTR_H__
Generated from commit: vsfteam/vsf@c3767bf