freertos_mpool.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* --------------------------------------------------------------------------
  2. * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * Name: freertos_mpool.h
  19. * Purpose: CMSIS RTOS2 wrapper for FreeRTOS
  20. *
  21. *---------------------------------------------------------------------------*/
  22. #ifndef FREERTOS_MPOOL_H_
  23. #define FREERTOS_MPOOL_H_
  24. #include <stdint.h>
  25. #include "FreeRTOS.h"
  26. #include "semphr.h"
  27. /* Memory Pool implementation definitions */
  28. #define MPOOL_STATUS 0x5EED0000U
  29. /* Memory Block header */
  30. typedef struct {
  31. void *next; /* Pointer to next block */
  32. } MemPoolBlock_t;
  33. /* Memory Pool control block */
  34. typedef struct MemPoolDef_t {
  35. MemPoolBlock_t *head; /* Pointer to head block */
  36. SemaphoreHandle_t sem; /* Pool semaphore handle */
  37. uint8_t *mem_arr; /* Pool memory array */
  38. uint32_t mem_sz; /* Pool memory array size */
  39. const char *name; /* Pointer to name string */
  40. uint32_t bl_sz; /* Size of a single block */
  41. uint32_t bl_cnt; /* Number of blocks */
  42. uint32_t n; /* Block allocation index */
  43. volatile uint32_t status; /* Object status flags */
  44. #if (configSUPPORT_STATIC_ALLOCATION == 1)
  45. StaticSemaphore_t mem_sem; /* Semaphore object memory */
  46. #endif
  47. } MemPool_t;
  48. /* No need to hide static object type, just align to coding style */
  49. #define StaticMemPool_t MemPool_t
  50. /* Define memory pool control block size */
  51. #define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t))
  52. /* Define size of the byte array required to create count of blocks of given size */
  53. #define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count))
  54. #endif /* FREERTOS_MPOOL_H_ */