sys_slab_allocator.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. * Copyright (c) 2016 - 2020 Nordic Semiconductor ASA and Luxoft Global Operations Gmbh.
  3. *
  4. * All Rights Reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. *
  10. * 1. Redistributions of source code must retain the above copyright notice, this
  11. * list of conditions and the following disclaimer.
  12. *
  13. * 2. Redistributions in binary form, except as embedded into a Nordic
  14. * Semiconductor ASA integrated circuit in a product or a software update for
  15. * such product, must reproduce the above copyright notice, this list of
  16. * conditions and the following disclaimer in the documentation and/or other
  17. * materials provided with the distribution.
  18. *
  19. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  20. * contributors may be used to endorse or promote products derived from this
  21. * software without specific prior written permission.
  22. *
  23. * 4. This software, with or without modification, must only be used with a
  24. * Nordic Semiconductor ASA integrated circuit.
  25. *
  26. * 5. Any software provided in binary form under this license must not be reverse
  27. * engineered, decompiled, modified and/or disassembled.
  28. *
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  31. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  33. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  34. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  35. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  36. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  38. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  39. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. */
  42. #ifndef SYS_SLAB_ALLOCATOR_H_INCLUDED
  43. #define SYS_SLAB_ALLOCATOR_H_INCLUDED
  44. #include "phy_pd_data.h"
  45. #ifndef CONFIG_SLAB_FRAME_POOL_SIZE
  46. #define CONFIG_SLAB_FRAME_POOL_SIZE 4
  47. #warning "CONFIG_SLAB_FRAME_POOL_SIZE not set in .config, using default"
  48. #endif
  49. /** @file
  50. * This file contains declarations of the SLAB allocator API.
  51. *
  52. * @defgroup sys_slab_allocator SLAB Allocator API
  53. * @ingroup sys_15_4
  54. * @{
  55. * @brief Module for declaring the SLAB Allocator API
  56. */
  57. /**@brief The SLAB allocator buffer type (free or busy buffer).
  58. */
  59. typedef enum
  60. {
  61. SYS_SLAB_FREE_BUFFER, /**< The buffer is free */
  62. SYS_SLAB_BUSY_BUFFER, /**< The buffer is busy */
  63. } sys_slab_buffer_type_t;
  64. /**@brief Initializes the SLAB allocator.
  65. *
  66. * @details Preallocates the frame pool
  67. */
  68. void sys_sa_init(void);
  69. /**@brief Resets the SLAB allocator.
  70. *
  71. * @details Clear allocated the frame pools
  72. */
  73. void sys_sa_reset(void);
  74. /**@brief Inserts item into one of the queues of the SLAB allocator.
  75. *
  76. * @details This function is used to put the item into the SLAB allocator
  77. * queue. Type of buffer shall be chosen.
  78. *
  79. * @param[in] type Type of an inserted buffer (free or busy).
  80. * @param[in] p_item Pointer to an inserted buffer.
  81. */
  82. void sys_sa_buffer_put(sys_slab_buffer_type_t type, pd_data_ind_t * p_item);
  83. /**@brief Gets item from one of the queues of the SLAB allocator.
  84. *
  85. * @details This function is used to get the item from the SLAB allocator
  86. * queues. Type of buffer shall be chosen. The buffer is deleted
  87. * from the SLAB allocator
  88. *
  89. * @param[in] type Type of a gotten buffer (free or busy).
  90. *
  91. * @retval Pointer to a gotten buffer in case of success. NULL otherwise.
  92. */
  93. pd_data_ind_t * sys_sa_buffer_get(sys_slab_buffer_type_t type);
  94. /**@brief Deletes an allocated item from the heap.
  95. *
  96. * @details This function is used to delete allocated by SLAB allocator buffer
  97. * from the heap. Pointer to a frame memory of an allocated item shall be used.
  98. *
  99. * @param[in] p_frame Pointer to a frame memory of an allocated item.
  100. */
  101. void sys_sa_buffer_free(uint8_t * p_frame);
  102. /**@brief Returns buffer back to queue of free buffers.
  103. *
  104. * @details This function is used to return allocated buffer back to the queue
  105. * without allocation and deallocation.
  106. *
  107. * @param[in] p_item Pointer to an allocated item.
  108. */
  109. void sys_sa_buffer_release(pd_data_ind_t * p_item);
  110. /**@brief Allocates memory for the queue of free buffers.
  111. *
  112. * @details This function is used to allocate buffer from heap
  113. * and put them into the queue
  114. *
  115. * @retval True in case of success. False otherwise.
  116. */
  117. bool sys_sa_memory_allocate(void);
  118. /**@brief Checks if there are any buffers in the SLAB allocator queue or not.
  119. *
  120. * @details Type of checked buffers shall be passed.
  121. *
  122. * @param[in] type Type of an checked buffers (free or busy).
  123. *
  124. * @retval True in case of absence of buffers. False otherwise.
  125. */
  126. bool sys_sa_is_empty(sys_slab_buffer_type_t type);
  127. /** @} */
  128. #endif /* SYS_SLAB_ALLOCATOR_H_INCLUDED */