Skip to content

Commit 8284d12

Browse files
committed
drivers: video: Add SMH option for video buffer
This commit enables the user to choose whether to allocate the video buffer from the video heap pool or use a memory region with specific extra capabilities, such as being cacheable/non-cacheable or using external memory. Signed-off-by: Lucas Tamborrino <[email protected]>
1 parent 632d6b9 commit 8284d12

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

drivers/video/Kconfig

+15
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ config VIDEO_BUFFER_POOL_ALIGN
3535
int "Alignment of the video pool’s buffer"
3636
default 64
3737

38+
config VIDEO_BUFFER_USE_SHARED_MULTI_HEAP
39+
bool "Use shared multi heap for video buffer"
40+
default n
41+
42+
config VIDEO_BUFFER_SMH_ATTRIBUTE
43+
int "Shared multi heap attribute for video buffer"
44+
depends on VIDEO_BUFFER_USE_SHARED_MULTI_HEAP
45+
default 0
46+
range 0 2
47+
help
48+
Shared multi heap attribute for video buffer:
49+
0: SMH_REG_ATTR_CACHEABLE
50+
1: SMH_REG_ATTR_NON_CACHEABLE
51+
2: SMH_REG_ATTR_EXTERNAL
52+
3853
source "drivers/video/Kconfig.esp32_dvp"
3954

4055
source "drivers/video/Kconfig.mcux_csi"

drivers/video/video_common.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@
77
#include <zephyr/kernel.h>
88
#include <zephyr/drivers/video.h>
99

10-
K_HEAP_DEFINE(video_buffer_pool,
11-
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX *
12-
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);
10+
#if defined(CONFIG_VIDEO_BUFFER_USE_SHARED_MULTI_HEAP)
11+
#include <zephyr/multi_heap/shared_multi_heap.h>
12+
13+
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
14+
shared_multi_heap_aligned_alloc(CONFIG_VIDEO_BUFFER_SMH_ATTRIBUTE, align, size)
15+
#define VIDEO_COMMON_FREE(block) shared_multi_heap_free(block)
16+
#else
17+
K_HEAP_DEFINE(video_buffer_pool, CONFIG_VIDEO_BUFFER_POOL_SZ_MAX*CONFIG_VIDEO_BUFFER_POOL_NUM_MAX);
18+
#define VIDEO_COMMON_HEAP_ALLOC(align, size, timeout) \
19+
k_heap_aligned_alloc(&video_buffer_pool, align, size, timeout);
20+
#define VIDEO_COMMON_FREE(block) k_heap_free(&video_buffer_pool, block)
21+
#endif
1322

1423
static struct video_buffer video_buf[CONFIG_VIDEO_BUFFER_POOL_NUM_MAX];
1524

@@ -39,7 +48,7 @@ struct video_buffer *video_buffer_aligned_alloc(size_t size, size_t align)
3948
}
4049

4150
/* Alloc buffer memory */
42-
block->data = k_heap_aligned_alloc(&video_buffer_pool, align, size, K_FOREVER);
51+
block->data = VIDEO_COMMON_HEAP_ALLOC(align, size, K_FOREVER);
4352
if (block->data == NULL) {
4453
return NULL;
4554
}
@@ -71,6 +80,6 @@ void video_buffer_release(struct video_buffer *vbuf)
7180

7281
vbuf->buffer = NULL;
7382
if (block) {
74-
k_heap_free(&video_buffer_pool, block->data);
83+
VIDEO_COMMON_FREE(block->data);
7584
}
7685
}

0 commit comments

Comments
 (0)