esp_attr.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef __ESP_ATTR_H__
  14. #define __ESP_ATTR_H__
  15. #include "sdkconfig.h"
  16. #define ROMFN_ATTR
  17. //Normally, the linker script will put all code and rodata in flash,
  18. //and all variables in shared RAM. These macros can be used to redirect
  19. //particular functions/variables to other memory regions.
  20. // Forces code into IRAM instead of flash
  21. #define IRAM_ATTR _SECTION_ATTR_IMPL(".iram1", __COUNTER__)
  22. // Forces data into DRAM instead of flash
  23. #define DRAM_ATTR _SECTION_ATTR_IMPL(".dram1", __COUNTER__)
  24. // Forces data to be 4 bytes aligned
  25. #define WORD_ALIGNED_ATTR __attribute__((aligned(4)))
  26. // Forces data to be placed to DMA-capable places
  27. #define DMA_ATTR WORD_ALIGNED_ATTR DRAM_ATTR
  28. // Forces a string into DRAM instead of flash
  29. // Use as ets_printf(DRAM_STR("Hello world!\n"));
  30. #define DRAM_STR(str) (__extension__({static const DRAM_ATTR char __c[] = (str); (const char *)&__c;}))
  31. // Forces code into RTC fast memory. See "docs/deep-sleep-stub.rst"
  32. #define RTC_IRAM_ATTR _SECTION_ATTR_IMPL(".rtc.text", __COUNTER__)
  33. #if CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY
  34. // Forces bss variable into external memory. "
  35. #define EXT_RAM_ATTR _SECTION_ATTR_IMPL(".ext_ram.bss", __COUNTER__)
  36. #else
  37. #define EXT_RAM_ATTR
  38. #endif
  39. // Forces data into RTC slow memory. See "docs/deep-sleep-stub.rst"
  40. // Any variable marked with this attribute will keep its value
  41. // during a deep sleep / wake cycle.
  42. #define RTC_DATA_ATTR _SECTION_ATTR_IMPL(".rtc.data", __COUNTER__)
  43. // Forces read-only data into RTC memory. See "docs/deep-sleep-stub.rst"
  44. #define RTC_RODATA_ATTR _SECTION_ATTR_IMPL(".rtc.rodata", __COUNTER__)
  45. // Allows to place data into RTC_SLOW memory.
  46. #define RTC_SLOW_ATTR _SECTION_ATTR_IMPL(".rtc.force_slow", __COUNTER__)
  47. // Allows to place data into RTC_FAST memory.
  48. #define RTC_FAST_ATTR _SECTION_ATTR_IMPL(".rtc.force_fast", __COUNTER__)
  49. // Forces data into noinit section to avoid initialization after restart.
  50. #define __NOINIT_ATTR _SECTION_ATTR_IMPL(".noinit", __COUNTER__)
  51. // Forces data into RTC slow memory of .noinit section.
  52. // Any variable marked with this attribute will keep its value
  53. // after restart or during a deep sleep / wake cycle.
  54. #define RTC_NOINIT_ATTR _SECTION_ATTR_IMPL(".rtc_noinit", __COUNTER__)
  55. // Forces to not inline function
  56. #define NOINLINE_ATTR __attribute__((noinline))
  57. // Implementation for a unique custom section
  58. //
  59. // This prevents gcc producing "x causes a section type conflict with y"
  60. // errors if two variables in the same source file have different linkage (maybe const & non-const) but are placed in the same custom section
  61. //
  62. // Using unique sections also means --gc-sections can remove unused
  63. // data with a custom section type set
  64. #define _SECTION_ATTR_IMPL(SECTION, COUNTER) __attribute__((section(SECTION "." _COUNTER_STRINGIFY(COUNTER))))
  65. #define _COUNTER_STRINGIFY(COUNTER) #COUNTER
  66. #endif /* __ESP_ATTR_H__ */