esp_heap_alloc_caps.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 Allocate a chunk of memory which has the given capabilities
  38. *
  39. * @param xWantedSize Size, in bytes, of the amount of memory to allocate
  40. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  41. * of memory to be returned
  42. *
  43. * @return A pointer to the memory allocated on success, NULL on failure
  44. */
  45. void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps);
  46. /**
  47. * @brief Get the total free size of all the regions that have the given capabilities
  48. *
  49. * This function takes all regions capable of having the given capabilities allocated in them
  50. * and adds up the free space they have.
  51. *
  52. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  53. * of memory
  54. *
  55. * @return Amount of free bytes in the regions
  56. */
  57. size_t xPortGetFreeHeapSizeCaps( uint32_t caps );
  58. /**
  59. * @brief Get the total minimum free memory of all regions with the given capabilities
  60. *
  61. * This adds all the lowmarks of the regions capable of delivering the memory with the
  62. * given capabilities
  63. *
  64. * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
  65. * of memory
  66. *
  67. * @return Amount of free bytes in the regions
  68. */
  69. size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps );
  70. #endif