boot_mem.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Copyright (C) 2017 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _BOOT_MEM_H_
  13. #define _BOOT_MEM_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * @brief initialize heap
  22. *
  23. * Initialize internal RAM heap and external RAM heap. Both heap can be
  24. * empty (size is 0).
  25. *
  26. * The default heap (for \a malloc and \a calloc) is internal RAM heap.
  27. *
  28. * @param iram_start internal RAM heap start address
  29. * @param iram_size internal RAM heap size (in bytes)
  30. * @param ext_ram_start external RAM heap start address
  31. * @param ext_ram_size external RAM heap size (in bytes)
  32. */
  33. void bootHeapInit(void *iram_start, unsigned iram_size,
  34. void *ext_ram_start, unsigned ext_ram_size);
  35. /**
  36. * @brief set internal RAM heap as default
  37. */
  38. void bootHeapDefaultIram(void);
  39. /**
  40. * @brief set external RAM heap as default
  41. */
  42. void bootHeapDefaultExtRam(void);
  43. /**
  44. * @brief allocate from internal RAM heap
  45. *
  46. * @param size request size (in bytes)
  47. * @return
  48. * - allocated memory pointer
  49. * - NULL is no space in internal RAM heap
  50. */
  51. void *bootIramMalloc(unsigned size);
  52. /**
  53. * @brief allocate from internal RAM heap and clear to zero
  54. *
  55. * @param nmemb number of blocks
  56. * @param size size (in bytes) for each block
  57. * @return
  58. * - allocated memory pointer
  59. * - NULL is no space in internal RAM heap
  60. */
  61. void *bootIramCalloc(unsigned nmemb, unsigned size);
  62. /**
  63. * @brief allocate from external RAM heap
  64. *
  65. * @param size request size (in bytes)
  66. * @return
  67. * - allocated memory pointer
  68. * - NULL is no space in internal RAM heap
  69. */
  70. void *bootExtRamMalloc(unsigned size);
  71. /**
  72. * @brief allocate from external RAM heap and clear to zero
  73. *
  74. * @param nmemb number of blocks
  75. * @param size size (in bytes) for each block
  76. * @return
  77. * - allocated memory pointer
  78. * - NULL is no space in internal RAM heap
  79. */
  80. void *bootExtRamCalloc(unsigned nmemb, unsigned size);
  81. /**
  82. * @brief free dynamic memory
  83. *
  84. * The memory should be dynamic allocated from either internal RAM heap
  85. * or external RAM heap.
  86. *
  87. * If \a ptr is NULL, no operation is performed.
  88. *
  89. * @param ptr pointer to be freed
  90. */
  91. void bootFree(void *ptr);
  92. /**
  93. * @brief show heap information in trace
  94. *
  95. * This is for debug purpose only.
  96. */
  97. void bootShowMemInfo(void);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif