hv_vos_Memory.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * @file hv_vos_Memory.h
  3. * @brief Header file of I2C driver.
  4. *
  5. * @verbatim
  6. * ==============================================================================
  7. * ##### How to use #####
  8. * ==============================================================================
  9. * (+) Use ()
  10. *
  11. * @endverbatim
  12. * @author HiView SoC Software Team
  13. * @version 1.0.0
  14. * @date 2023-03-01
  15. */
  16. #ifndef _HV_VOS_MEMORY_H
  17. #define _HV_VOS_MEMORY_H
  18. #include "hv_vos_Types.h"
  19. VOS_EXTERN_C_BEGIN
  20. /** @defgroup VOS_MEMORY VOS_MEMORY
  21. * VOS memory related functions
  22. * @{
  23. */
  24. /** @brief malloc memory
  25. * @param size required memory size
  26. * @return allocated memory pointer, return NULL if failed
  27. */
  28. void *Hv_Vos_Malloc(UINT32 size);
  29. /** @brief malloc memory and clear it
  30. * @param nmemb memory count
  31. * @param size required memory size
  32. * @return allocated memory pointer, return NULL if failed
  33. */
  34. void *Hv_Vos_Calloc(UINT32 nmemb, UINT32 size);
  35. /** @brief change the size of allacated memory
  36. * @param p allocated pointer, same as \link Hv_Vos_MALLOC \endlink if p is NULL
  37. * @param size required memory size
  38. * @return allocated memory pointer, return NULL if failed
  39. */
  40. void *Hv_Vos_Realloc(void *p, UINT32 size);
  41. /** @brief free allacated memory
  42. * @param p allocated pointer
  43. */
  44. void Hv_Vos_Free(void *p);
  45. /** @brief copy memory area
  46. * @param dest destination memory
  47. * @param src source memory
  48. * @param n copying size
  49. * @return return pointer to dest
  50. */
  51. void *Hv_Vos_Memcpy(void *dest, const void *src, UINT32 n);
  52. void *Hv_Vos_VolatileMemcpy(void *dest, const volatile void *src, UINT32 n);
  53. /** @brief fill memory with a constant byte
  54. * @param s memory area to clear
  55. * @param c constant byte
  56. * @param n number of bytes
  57. * @return pointer to s
  58. */
  59. void *Hv_Vos_Memset(void *s, int c, UINT32 n);
  60. char *Hv_Vos_Strdup(const char *s);
  61. UINT32 Hv_Vos_MemoryRemaining();
  62. #define HV_MALLOC Hv_Vos_Malloc /* !< short form of Hv_Vos_MALLOC */
  63. #define HV_CALLOC Hv_Vos_Calloc /* !< short form of Hv_Vos_Calloc */
  64. #define HV_MEMCPY Hv_Vos_Memcpy /* !< short form of Hv_Vos_Memcpy */
  65. #define HV_MEMSET Hv_Vos_Memset /* !< short form of Hv_Vos_Memset */
  66. #define HV_FREE Hv_Vos_Free /* !< short form of Hv_Vos_Free */
  67. #define HV_STRDUP Hv_Vos_Strdup
  68. #define HV_FREE_EX(ptr, sz) HV_FREE(ptr) /* !< Hv_Vos_Free with size parameter */
  69. /* malloc stuct and clear it **/
  70. #define HV_MALLOC_OBJECT(type) ((type*)Hv_Vos_Calloc(1, sizeof(type)))
  71. /* malloc multiple struct and clear them */
  72. #define HV_MALLOC_OBJECT_ARRAY(type, count) ((type*)Hv_Vos_Calloc(count, sizeof(type)))
  73. /* free struct pointer and set as NULL */
  74. #define HV_FREE_OBJECT(obj) do { Hv_Vos_Free(obj); obj = NULL; } while (0)
  75. /* free struct array pointer and set as NULL */
  76. #define HV_FREE_OBJECT_ARRAY(obj) do { Hv_Vos_Free(obj); obj = NULL; } while (0)
  77. /* malloc buffer */
  78. #define HV_MALLOC_BUFFER(size) Hv_Vos_Calloc(1, size)
  79. /* free buffer */
  80. #define HV_FREE_BUFFER(p) do { Hv_Vos_Free(p); p = NULL; } while (0)
  81. /* macro for memory compare */
  82. #define HV_MEMCMP(a, b, n) memcmp(a, b, n)
  83. /* memory clean as 0 */
  84. #define HV_BZERO(a, n) HV_MEMSET(a, '\0', n)
  85. /** @} */
  86. VOS_EXTERN_C_END
  87. #endif