|
| 1 | +/* |
| 2 | + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include "mesh/common.h" |
| 8 | +#include "mesh/queue.h" |
| 9 | + |
| 10 | +int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size) |
| 11 | +{ |
| 12 | + __ASSERT(queue && queue_size && item_size, "Invalid queue init parameters"); |
| 13 | + |
| 14 | +#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC |
| 15 | + queue->handle = xQueueCreate(queue_size, item_size); |
| 16 | + __ASSERT(queue->handle, "Failed to create queue"); |
| 17 | +#else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ |
| 18 | +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL |
| 19 | + queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 20 | +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT |
| 21 | + queue->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 22 | +#endif |
| 23 | + __ASSERT(queue->buffer, "Failed to create queue buffer"); |
| 24 | +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL |
| 25 | + queue->storage = heap_caps_calloc_prefer(1, (queue_size * item_size), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 26 | +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT |
| 27 | + queue->storage = heap_caps_calloc_prefer(1, (queue_size * item_size), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 28 | +#endif |
| 29 | + __ASSERT(queue->storage, "Failed to create queue storage"); |
| 30 | + queue->handle = xQueueCreateStatic(queue_size, item_size, (uint8_t*)queue->storage, queue->buffer); |
| 31 | + __ASSERT(queue->handle, "Failed to create static queue"); |
| 32 | +#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ |
| 33 | + return 0; |
| 34 | +} |
| 35 | + |
| 36 | +int bt_mesh_queue_deinit(bt_mesh_queue_t *queue) |
| 37 | +{ |
| 38 | + __ASSERT(queue, "Invalid queue init parameters"); |
| 39 | + vQueueDelete(queue->handle); |
| 40 | + queue->handle = NULL; |
| 41 | +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC |
| 42 | + heap_caps_free(queue->buffer); |
| 43 | + queue->buffer = NULL; |
| 44 | + heap_caps_free(queue->storage); |
| 45 | + queue->storage = NULL; |
| 46 | +#endif |
| 47 | + return 0; |
| 48 | +} |
0 commit comments