18#ifndef __VSF_PBUF_POOL_H__
19#define __VSF_PBUF_POOL_H__
23#if VSF_USE_PBUF == ENABLED
33#define __declare_pbuf_pool(__NAME) \
34 typedef struct __NAME##_pool_item_t __NAME##_pool_item_t; \
35 typedef struct __NAME##_pool_t __NAME##_pool_t;
37#define __def_pbuf_pool(__NAME, __SIZE, ...) \
38 struct __NAME##_pool_item_t { \
39 implement(vsf_pbuf_t); \
40 uint8_t u8_buffer[__SIZE]; \
42 struct __NAME##_pool_t { \
43 implement(vsf_pbuf_pool_t) \
47#define __vsf_pbuf_pool_req_pbuf_evt(__NAME, __POOL) \
49 { .handler_fn = __NAME##_req_pbuf_evt_handler, \
50 .target_ptr = (__POOL), \
53#if VSF_STREAM_CFG_SUPPORT_RESOURCE_LIMITATION == ENABLED
54#define __implement_pbuf_pool(__NAME) \
55 vsf_pbuf_t *__NAME##_req_pbuf_evt_handler(void *target_ptr, \
56 int_fast32_t nNoLessThan, \
57 int_fast32_t nBestSize, \
58 uint_fast16_t hwReserve) \
60 vsf_pool(__NAME) *this_ptr = (vsf_pool(__NAME) *)target_ptr; \
61 VSF_SERVICE_ASSERT(NULL != this_ptr); \
62 if (vsf_pbuf_get_pool_item_count( \
63 &(this_ptr->use_as__vsf_pbuf_pool_t)) <= hwReserve) { \
66 return vsf_pbuf_pool_alloc(&(this_ptr->use_as__vsf_pbuf_pool_t)); \
69#define __implement_pbuf_pool(__NAME) \
70 vsf_pbuf_t *__NAME##_req_pbuf_evt_handler(void *target_ptr, \
71 int_fast32_t nNoLessThan, \
72 int_fast32_t nBestSize, \
73 uint_fast16_t hwReserve) \
75 vsf_pool(__NAME) *this_ptr = (vsf_pool(__NAME) *)target_ptr; \
76 VSF_SERVICE_ASSERT(NULL != this_ptr); \
77 return vsf_pbuf_pool_alloc(&(this_ptr->use_as__vsf_pbuf_pool_t)); \
81#define __init_pbuf_pool(__NAME, __POOL, __ID, __COUNT, ...) \
83 VSF_CAL_NO_INIT static vsf_pool_item(__NAME) \
84 __##__NAME##_data_buffer[__COUNT]; \
85 const vsf_pbuf_adapter_t *adapter_ptr = \
86 vsf_pbuf_adapter_get(__ID); \
87 vsf_pool_cfg_t cfg = { \
88 .target_ptr = (uintptr_t)adapter_ptr, \
89 .pool_name_ptr = #__NAME, \
93 vsf_pbuf_pool_init( &((__POOL)->use_as__vsf_pbuf_pool_t), \
94 sizeof(vsf_pool_item(__NAME)), \
95 VSF_CAL_ALIGN_OF(vsf_pool_item(__NAME)), \
97 vsf_pbuf_pool_add_buffer( &((__POOL)->use_as__vsf_pbuf_pool_t), \
98 __##__NAME##_data_buffer, \
99 sizeof(__##__NAME##_data_buffer), \
100 sizeof(vsf_pool_item(__NAME))); \
103#define init_pbuf_pool(__NAME, __POOL, __ID, __COUNT, ...) \
104 __init_pbuf_pool(__NAME, (__POOL), (__ID), (__COUNT), __VA_ARGS__)
106#define __prepare_pbuf_pool(__NAME, __POOL, __ID, ...) \
108 const vsf_pbuf_adapter_t *adapter_ptr = \
109 vsf_pbuf_adapter_get(__ID); \
110 vsf_pool_cfg_t cfg = { \
111 .target_ptr = (uintptr_t)adapter_ptr, \
112 .pool_name_ptr = #__NAME, \
113 .item_init_fn = &vsf_pbuf_pool_item_init_event_handler, \
117 vsf_pbuf_pool_init( &((__POOL)->use_as__vsf_pbuf_pool_t), \
118 sizeof(vsf_pool_item(__NAME)), \
119 VSF_CAL_ALIGN_OF(vsf_pool_item(__NAME)), \
123#define prepare_pbuf_pool(__NAME, __POOL, __ID, ...) \
124 __prepare_pbuf_pool(__NAME, (__POOL), (__ID), __VA_ARGS__)
127#define def_pbuf_pool(__NAME, __SIZE, ...) \
128 __def_pbuf_pool(__NAME, (__SIZE), __VA_ARGS__)
130#define declare_pbuf_pool(__NAME) __declare_pbuf_pool(__NAME)
132#define vsf_pbuf_pool_req_pbuf_evt(__NAME, __POOL) \
133 __vsf_pbuf_pool_req_pbuf_evt(__NAME, (__POOL))
135#define implement_pbuf_pool(...) __implement_pbuf_pool(__VA_ARGS__)
137#define vsf_pbuf_pool_adapter(__ID, __POOL) \
139 .target_ptr = (__POOL), \
141 .methods_ptr = &VSF_PBUF_ADAPTER_METHODS_STREAM_SRC, \
153 implement(vsf_pool_t)
#define VSF_CAL_SECTION(__SEC)
Definition __compiler.h:181
unsigned int uint32_t
Definition lvgl.h:43
uint32_t uintptr_t
Definition stdint.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
Definition vsf_pbuf_pool.h:152
Definition vsf_arch_abstraction.h:54
Definition vsf_list.h:872
Definition vsf_pbuf_pool.h:148
vsf_slist_t vsf_pbuf_t tMem
Definition vsf_pbuf_pool.h:150
void vsf_pbuf_pool_init(vsf_pbuf_pool_t *this_ptr, uint32_t u32_item_size, uint_fast16_t u16_align, vsf_pool_cfg_t *pcfg)
Definition vsf_pbuf_pool.c:44
vsf_protect_region_t * vsf_pbuf_pool_get_region(vsf_pbuf_pool_t *)
Definition vsf_pbuf_pool.c:92
uintptr_t vsf_pbuf_pool_get_target(vsf_pbuf_pool_t *)
Definition vsf_pbuf_pool.c:98
void vsf_pbuf_pool_free(vsf_pbuf_pool_t *, vsf_pbuf_t *)
Definition vsf_pbuf_pool.c:79
const i_pbuf_methods_t VSF_PBUF_ADAPTER_METHODS_STREAM_SRC
Definition vsf_pbuf_pool.c:31
uint_fast32_t vsf_pbuf_get_pool_item_count(vsf_pbuf_pool_t *)
Definition vsf_pbuf_pool.c:85
vsf_pbuf_t * vsf_pbuf_pool_alloc(vsf_pbuf_pool_t *)
Definition vsf_pbuf_pool.c:70
bool vsf_pbuf_pool_add_buffer(vsf_pbuf_pool_t *this_ptr, void *buffer_ptr, uint_fast32_t u32_size, uint_fast16_t u16_item_size)
Definition vsf_pbuf_pool.c:52
vsf_pool_cfg_t
Definition vsf_pool.h:539