Skip to content

Commit 30b257c

Browse files
committed
feat(ble_mesh): ble mesh queue support
1 parent 30c3427 commit 30b257c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _BLE_MESH_QUEUE_H_
8+
#define _BLE_MESH_QUEUE_H_
9+
10+
#include "mesh/kernel.h"
11+
#include "mesh/slist.h"
12+
#include "mesh/atomic.h"
13+
14+
#ifdef __cplusplus
15+
extern "C" {
16+
#endif
17+
18+
typedef struct {
19+
QueueHandle_t handle;
20+
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
21+
StaticQueue_t *buffer;
22+
uint8_t *storage;
23+
#endif
24+
} bt_mesh_queue_t;
25+
26+
int bt_mesh_queue_init(bt_mesh_queue_t *queue, uint8_t queue_size, uint8_t item_size);
27+
int bt_mesh_queue_deinit(bt_mesh_queue_t *queue);
28+
29+
#ifdef __cplusplus
30+
}
31+
#endif
32+
33+
#endif /* _BLE_MESH_QUEUE_H_ */
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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

Comments
 (0)