esp_heap_alloc_caps.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 HEAP_ALLOC_CAPS_H
  14. #define HEAP_ALLOC_CAPS_H
  15. /**
  16. * @brief Flags to indicate the capabilities of the various memory systems
  17. */
  18. #define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code
  19. #define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses
  20. #define MALLOC_CAP_8BIT (1<<2) ///< Memory must allow for 8/16/...-bit data accesses
  21. #define MALLOC_CAP_DMA (1<<3) ///< Memory must be able to accessed by DMA
  22. #define MALLOC_CAP_PID2 (1<<4) ///< Memory must be mapped to PID2 memory space
  23. #define MALLOC_CAP_PID3 (1<<5) ///< Memory must be mapped to PID3 memory space
  24. #define MALLOC_CAP_PID4 (1<<6) ///< Memory must be mapped to PID4 memory space
  25. #define MALLOC_CAP_PID5 (1<<7) ///< Memory must be mapped to PID5 memory space
  26. #define MALLOC_CAP_PID6 (1<<8) ///< Memory must be mapped to PID6 memory space
  27. #define MALLOC_CAP_PID7 (1<<9) ///< Memory must be mapped to PID7 memory space
  28. #define MALLOC_CAP_SPISRAM (1<<10) ///< Memory must be in SPI SRAM
  29. #define MALLOC_CAP_INVALID (1<<31) ///< Memory can't be used / list end marker
  30. /**
  31. * @brief Initialize the capability-aware heap allocator.
  32. *
  33. * For the ESP32, this is called once in the startup code.
  34. */
  35. void heap_alloc_caps_init();
  36. /**
  37. * @brief Enable the memory region where the startup stacks are located for allocation
  38. *
  39. * On startup, the pro/app CPUs have a certain memory region they use as stack, so we
  40. * cannot do allocations in the regions these stack frames are. When FreeRTOS is
  41. * completely started, they do not use that memory anymore and allocation there can
  42. * be re-enabled.
  43. */
  44. void heap_alloc_enable_nonos_stack_tag();
  45. /**
  46. * @brief Allocate a chunk of memory which has the given capabilities
  47. *
  48. * @param xWantedSize Size, in bytes, of the amount of memory to allocate
  49. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  50. * of memory to be returned
  51. *
  52. * @return A pointer to the memory allocated on success, NULL on failure
  53. */
  54. void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps);
  55. /**
  56. * @brief Get the total free size of all the regions that have the given capabilities
  57. *
  58. * This function takes all regions capable of having the given capabilities allocated in them
  59. * and adds up the free space they have.
  60. *
  61. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  62. * of memory
  63. *
  64. * @return Amount of free bytes in the regions
  65. */
  66. size_t xPortGetFreeHeapSizeCaps( uint32_t caps );
  67. /**
  68. * @brief Get the total minimum free memory of all regions with the given capabilities
  69. *
  70. * This adds all the lowmarks of the regions capable of delivering the memory with the
  71. * given capabilities
  72. *
  73. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  74. * of memory
  75. *
  76. * @return Amount of free bytes in the regions
  77. */
  78. size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps );
  79. #endif