OSAL_Memory.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /**************************************************************************************************
  2. Phyplus Microelectronics Limited confidential and proprietary.
  3. All rights reserved.
  4. IMPORTANT: All rights of this software belong to Phyplus Microelectronics
  5. Limited ("Phyplus"). Your use of this Software is limited to those
  6. specific rights granted under the terms of the business contract, the
  7. confidential agreement, the non-disclosure agreement and any other forms
  8. of agreements as a customer or a partner of Phyplus. You may not use this
  9. Software unless you agree to abide by the terms of these agreements.
  10. You acknowledge that the Software may not be modified, copied,
  11. distributed or disclosed unless embedded on a Phyplus Bluetooth Low Energy
  12. (BLE) integrated circuit, either as a product or is integrated into your
  13. products. Other than for the aforementioned purposes, you may not use,
  14. reproduce, copy, prepare derivative works of, modify, distribute, perform,
  15. display or sell this Software and/or its documentation for any purposes.
  16. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  17. PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  18. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  19. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  20. PHYPLUS OR ITS SUBSIDIARIES BE LIABLE OR OBLIGATED UNDER CONTRACT,
  21. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  22. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  23. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  24. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  25. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  26. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  27. **************************************************************************************************/
  28. /**************************************************************************************************
  29. Filename: OSAL_Memory.h
  30. Revised:
  31. Revision:
  32. Description: This module defines the OSAL memory control functions.
  33. **************************************************************************************************/
  34. #ifndef OSAL_MEMORY_H
  35. #define OSAL_MEMORY_H
  36. #ifdef __cplusplus
  37. extern "C"
  38. {
  39. #endif
  40. /*********************************************************************
  41. * INCLUDES
  42. */
  43. #include "comdef.h"
  44. /*********************************************************************
  45. * CONSTANTS
  46. */
  47. #if !defined ( OSALMEM_METRICS )
  48. #define OSALMEM_METRICS FALSE
  49. #endif
  50. /*********************************************************************
  51. * MACROS
  52. */
  53. //#define osal_stack_used() OnBoard_stack_used()
  54. /*********************************************************************
  55. * TYPEDEFS
  56. */
  57. typedef struct {
  58. // The 15 LSB's of 'val' indicate the total item size, including the header, in 8-bit bytes.
  59. unsigned short len : 15; // unsigned short len : 15;
  60. // The 1 MSB of 'val' is used as a boolean to indicate in-use or freed.
  61. unsigned short inUse : 1; // unsigned short inUse : 1;
  62. } osalMemHdrHdr_t;
  63. typedef union {
  64. /* Dummy variable so compiler forces structure to alignment of largest element while not wasting
  65. * space on targets when the halDataAlign_t is smaller than a UINT16.
  66. */
  67. halDataAlign_t alignDummy;
  68. uint32 val; // uint16 // TODO: maybe due to 4 byte alignment requirement in M0, this union should be 4 byte, change from uint16 to uint32, investigate more later - 04-25
  69. osalMemHdrHdr_t hdr;
  70. } osalMemHdr_t;
  71. /*********************************************************************
  72. * GLOBAL VARIABLES
  73. */
  74. /*********************************************************************
  75. * FUNCTIONS
  76. */
  77. /*
  78. * Initialize memory manager.
  79. */
  80. void osal_mem_init( void );
  81. /*
  82. * Setup efficient search for the first free block of heap.
  83. */
  84. void osal_mem_kick( void );
  85. /*
  86. * Allocate a block of memory.
  87. */
  88. void *osal_mem_alloc( uint16 size );
  89. /*
  90. * Free a block of memory.
  91. */
  92. void osal_mem_free( void *ptr );
  93. // ====== A2 metal change add
  94. /*
  95. * Set osal memory buffer
  96. */
  97. void osal_mem_set_heap(osalMemHdr_t *hdr, uint32 size);
  98. #if ( OSALMEM_METRICS )
  99. /*
  100. * Return the maximum number of blocks ever allocated at once.
  101. */
  102. uint16 osal_heap_block_max( void );
  103. /*
  104. * Return the current number of blocks now allocated.
  105. */
  106. uint16 osal_heap_block_cnt( void );
  107. /*
  108. * Return the current number of free blocks.
  109. */
  110. uint16 osal_heap_block_free( void );
  111. /*
  112. * Return the current number of bytes allocated.
  113. */
  114. uint16 osal_heap_mem_used( void );
  115. #endif
  116. /*********************************************************************
  117. *********************************************************************/
  118. #ifdef __cplusplus
  119. }
  120. #endif
  121. #endif /* #ifndef OSAL_MEMORY_H */