35#ifndef __VSF_RING_BUFFER_H__
36#define __VSF_RING_BUFFER_H__
151#define __PLOOC_CLASS_USE_STRICT_TEMPLATE__
153#if defined(__VSF_QUEUE_CLASS_IMPLEMENT)
154# define __PLOOC_CLASS_IMPLEMENT__
155# undef __VSF_QUEUE_CLASS_IMPLEMENT
156#elif defined(__VSF_QUEUE_CLASS_INHERIT__)
157# define __PLOOC_CLASS_INHERIT__
158# undef __VSF_QUEUE_CLASS_INHERIT__
172#define __declare_vsf_rng_buf(__name) \
173 typedef struct __name __name; \
174 typedef struct __name##_cfg_t __name##_cfg_t;
175#define declare_vsf_rng_buf(__name) __declare_vsf_rng_buf(__name)
178#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
180# define NO_RNG_BUF_PROTECT(__CODE) __CODE
181# define no_rng_buf_protect(__code) __code
183# define __def_vsf_rng_buf(__name, __type) \
185 implement(vsf_rng_buf_t) \
186 __type *buffer_ptr; \
189 struct __name##_cfg_t { \
190 __type *buffer_ptr; \
192 bool is_init_as_full; \
196void __name##_init(__name* queue_ptr, __name##_cfg_t* cfg_ptr); \
199bool __name##_send_one(__name* queue_ptr, __type item); \
202bool __name##_get_one(__name* queue_ptr, __type* item_ptr); \
204VSF_CAL_SECTION(".text." #__name "_item_count") \
206uint_fast16_t __name##_item_count(__name* queue_ptr); \
208VSF_CAL_SECTION(".text." #__name "_send_multiple") \
210int32_t __name##_send_multiple(__name* queue_ptr, \
211 const __type* item_ptr, \
214VSF_CAL_SECTION(".text." #__name "_get_multiple") \
216int32_t __name##_get_multiple( __name* queue_ptr, \
220VSF_CAL_SECTION(".text." #__name "_peek_one") \
222bool __name##_peek_one(__name* queue_ptr, const __type** item_pptr); \
224VSF_CAL_SECTION(".text." #__name "_reset_peek") \
226void __name##_reset_peek(__name *queue_ptr); \
228VSF_CAL_SECTION(".text." #__name "_get_all_peeked") \
230void __name##_get_all_peeked(__name *queue_ptr); \
232VSF_CAL_SECTION(".text." #__name "_item_count_peekable") \
234uint_fast16_t __name##_item_count_peekable(__name* queue_ptr); \
236VSF_CAL_SECTION(".text." #__name "_peek_multiple") \
238int32_t __name##_peek_multiple( __name* queue_ptr, \
239 const __type** item_pptr, \
242# define def_vsf_rng_buf(__name, __type) \
243 __def_vsf_rng_buf(__name, __type)
246# define NO_RNG_BUF_PROTECT(...) __VA_ARGS__
247# define no_rng_buf_protect(...) __VA_ARGS__
249# define __def_vsf_rng_buf(__name, __type, ...) \
251 implement(vsf_rng_buf_t) \
252 __type *buffer_ptr; \
256 struct __name##_cfg_t { \
257 __type *buffer_ptr; \
259 bool is_init_as_full; \
263void __name##_init(__name* queue_ptr, __name##_cfg_t* cfg_ptr); \
266bool __name##_send_one(__name* queue_ptr, __type item); \
269bool __name##_get_one(__name* queue_ptr, __type* item_ptr); \
271VSF_CAL_SECTION(".text." #__name "_item_count") \
273uint_fast16_t __name##_item_count(__name* queue_ptr); \
275VSF_CAL_SECTION(".text." #__name "_send_multiple") \
277int32_t __name##_send_multiple(__name* queue_ptr, \
278 const __type* item_ptr, \
281VSF_CAL_SECTION(".text." #__name "_get_multiple") \
283int32_t __name##_get_multiple( __name* queue_ptr, \
287VSF_CAL_SECTION(".text." #__name "_peek_one") \
289bool __name##_peek_one(__name* queue_ptr, const __type** item_pptr); \
291VSF_CAL_SECTION(".text." #__name "_reset_peek") \
293void __name##_reset_peek(__name *queue_ptr); \
295VSF_CAL_SECTION(".text." #__name "_get_all_peeked") \
297void __name##_get_all_peeked(__name *queue_ptr); \
299VSF_CAL_SECTION(".text." #__name "_item_count_peekable") \
301uint_fast16_t __name##_item_count_peekable(__name* queue_ptr); \
303VSF_CAL_SECTION(".text." #__name "_peek_multiple") \
305int32_t __name##_peek_multiple( __name* queue_ptr, \
306 const __type** item_pptr, \
309# define def_vsf_rng_buf(__name, __type, ...) \
310 __def_vsf_rng_buf(__name, __type, __VA_ARGS__)
314#define __implement_vsf_rng_buf(__name, __type, __queue_protect) \
315void __name##_init(__name* queue_ptr, __name##_cfg_t* cfg_ptr) \
317 VSF_ASSERT(NULL != queue_ptr && NULL != cfg_ptr); \
318 VSF_ASSERT(NULL != cfg_ptr->buffer_ptr); \
319 VSF_ASSERT(cfg_ptr->size >= sizeof(__type)); \
320 queue_ptr->buffer_ptr = cfg_ptr->buffer_ptr; \
321 __vsf_rng_buf_init_ex(&(queue_ptr->use_as__vsf_rng_buf_t), \
322 cfg_ptr->size / sizeof(__type), \
323 cfg_ptr->is_init_as_full); \
326bool __name##_send_one(__name *queue_ptr, __type item) \
328 bool result = false; \
329 VSF_ASSERT(NULL != queue_ptr); \
333 __vsf_rng_buf_send_one(&(queue_ptr->use_as__vsf_rng_buf_t)); \
337 queue_ptr->buffer_ptr[index] = item; \
345bool __name##_get_one(__name * queue_ptr, __type *item_ptr) \
347 bool result = false; \
348 VSF_ASSERT(NULL != queue_ptr); \
352 __vsf_rng_buf_get_one(&(queue_ptr->use_as__vsf_rng_buf_t)); \
356 if (NULL != item_ptr) { \
357 *item_ptr = queue_ptr->buffer_ptr[index]; \
366VSF_CAL_SECTION(".text." #__name "_item_count") \
367uint_fast16_t __name##_item_count(__name * queue_ptr) \
369 VSF_ASSERT(NULL != queue_ptr); \
370 return __vsf_rng_buf_item_count(&(queue_ptr->use_as__vsf_rng_buf_t)); \
373VSF_CAL_SECTION(".text." #__name "_send_multiple") \
374int32_t __name##_send_multiple( __name * queue_ptr, \
375 const __type*item_ptr, \
378 int32_t result = -1, index = 0; \
379 VSF_ASSERT(NULL != queue_ptr); \
382 if (NULL == item_ptr || 0 == count) { \
386 __vsf_rng_buf_send_multiple(&(queue_ptr->use_as__vsf_rng_buf_t),\
392 memcpy( &(queue_ptr->buffer_ptr[index]), \
394 count * sizeof(__type)); \
401VSF_CAL_SECTION(".text." #__name "_get_multiple") \
402int32_t __name##_get_multiple( __name * queue_ptr, \
406 int32_t result = -1, index = 0; \
407 VSF_ASSERT(NULL != queue_ptr); \
410 if (NULL == item_ptr || 0 == count) { \
414 __vsf_rng_buf_get_multiple(&(queue_ptr->use_as__vsf_rng_buf_t), \
421 &(queue_ptr->buffer_ptr[index]), \
422 count * sizeof(__type)); \
429VSF_CAL_SECTION(".text." #__name "_peek_one") \
430bool __name##_peek_one(__name *queue_ptr, const __type** item_pptr) \
432 bool result = false; \
433 VSF_ASSERT(NULL != queue_ptr); \
436 int32_t index = __vsf_rng_buf_peek_one( \
437 &(queue_ptr->use_as__vsf_rng_buf_t)); \
441 if (NULL != item_pptr) { \
442 (*item_pptr) = (const __type*)&queue_ptr->buffer_ptr[index]; \
451VSF_CAL_SECTION(".text." #__name "_reset_peek") \
452void __name##_reset_peek(__name *queue_ptr) \
454 VSF_ASSERT(NULL != queue_ptr); \
456 __vsf_rng_buf_reset_peek(&(queue_ptr->use_as__vsf_rng_buf_t)); \
460VSF_CAL_SECTION(".text." #__name "_get_all_peeked") \
461void __name##_get_all_peeked(__name *queue_ptr) \
463 VSF_ASSERT(NULL != queue_ptr); \
465 __vsf_rng_buf_get_all_peeked(&(queue_ptr->use_as__vsf_rng_buf_t)); \
469VSF_CAL_SECTION(".text." #__name "_item_count_peekable") \
470uint_fast16_t __name##_item_count_peekable(__name *queue_ptr) \
472 VSF_ASSERT(NULL != queue_ptr); \
473 return __vsf_rng_buf_item_count_peekable(&queue_ptr->use_as__vsf_rng_buf_t);\
476VSF_CAL_SECTION(".text." #__name "_peek_multiple") \
477int32_t __name##_peek_multiple( __name * queue_ptr, \
478 const __type** item_pptr, \
481 int32_t result = -1, index = 0; \
482 VSF_ASSERT(NULL != queue_ptr); \
485 if (NULL == item_pptr || 0 == count) { \
489 __vsf_rng_buf_peek_multiple(&(queue_ptr->use_as__vsf_rng_buf_t),\
496 (*item_pptr) = (const __type*)&(queue_ptr->buffer_ptr[index]); \
504#define implement_vsf_rng_buf(__name, __type, __queue_protect) \
505 __implement_vsf_rng_buf(__name, __type, __queue_protect)
508#define __vsf_rng_buf_init(__name, __type, __qaddr, __item_count) \
510 VSF_CAL_NO_INIT static uint16_t __buffer[(__item_count)]; \
511 __name##_cfg_t cfg = { \
515 __name##_init((__qaddr), & cfg); \
518#define vsf_rng_buf_init(__name, __type, __qaddr, __item_count) \
519 __vsf_rng_buf_init(__name, __type, (__qaddr), (__item_count))
523#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
525#define __vsf_rng_buf_prepare(__name, __qaddr, __buffer, __size) \
527 __name##_cfg_t cfg = {0}; \
528 cfg.buffer_ptr = (__buffer); \
529 cfg.size = (__size); \
530 __name##_init((__qaddr), & cfg); \
533# define vsf_rng_buf_prepare(__name, __qaddr, __buffer, __size) \
534 __vsf_rng_buf_prepare(__name, (__qaddr), (__buffer), (__size))
537# define __vsf_rng_buf_prepare(__name, __qaddr, __buffer, __size, ...) \
539 __name##_cfg_t cfg = { \
544 __name##_init((__qaddr), & cfg); \
547# define vsf_rng_buf_prepare(__name, __qaddr, __buffer, __size, ...) \
548 __vsf_rng_buf_prepare( __name, \
555#define __vsf_rng_buf_send_1(__name, __qaddr, __item) \
556 __name##_send_one((__qaddr), __item)
558#define __vsf_rng_buf_send_2(__name, __qaddr, __buffer, __size) \
559 __name##_send_multiple((__qaddr), (__buffer), (__size))
561#define __vsf_rng_buf_get_1(__name, __qaddr, __item) \
562 __name##_get_one((__qaddr), __item)
564#define __vsf_rng_buf_get_2(__name, __qaddr, __buffer, __size) \
565 __name##_get_multiple((__qaddr), (__buffer), (__size))
567#define __vsf_rng_buf_peek_1(__name, __qaddr, __item) \
568 __name##_peek_one((__qaddr), __item)
570#define __vsf_rng_buf_peek_2(__name, __qaddr, __buffer, __size) \
571 __name##_peek_multiple((__qaddr), (__buffer), (__size))
573#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
574# define vsf_rng_buf_send(__name, __qaddr, ...) \
575 __PLOOC_EVAL(__VSF_RNG_BUF_SEND_, __VA_ARGS__) \
576 (__name, __qaddr, __VA_ARGS__)
578# define vsf_rng_buf_get(__name, __qaddr, ...) \
579 __PLOOC_EVAL(__vsf_rng_buf_get_, __VA_ARGS__) \
580 (__name, __qaddr, __VA_ARGS__)
582# define vsf_rng_buf_peek(__name, __qaddr, ...) \
583 __PLOOC_EVAL(__VSF_QUEUE_PEEK_, __VA_ARGS__) \
584 (__name, __qaddr, __VA_ARGS__)
587#define vsf_rng_buf_send_one(__name, __qaddr, __item) \
588 __vsf_rng_buf_send_1(__name, (__qaddr), (__item))
590#define vsf_rng_buf_send_buf(__name, __qaddr, __buffer, __size) \
591 __vsf_rng_buf_send_2(__name, (__qaddr), (__buffer), (__size))
593#define vsf_rng_buf_get_one(__name, __qaddr, __item) \
594 __vsf_rng_buf_get_1(__name, (__qaddr), (__item))
596#define vsf_rng_buf_get_buf(__name, __qaddr, __buffer, __size) \
597 __vsf_rng_buf_get_2(__name, (__qaddr), (__buffer), (__size))
599#define __vsf_rng_buf_count(__name, __qaddr) \
600 __name##_item_count((__qaddr))
601#define vsf_rng_buf_count(__name, __qaddr) \
602 __vsf_rng_buf_count(__name, __qaddr)
604#define ____vsf_rng_buf_reset_peek(__name, __qaddr) \
605 __name##_reset_peek((__qaddr))
606#define vsf_rng_buf_reset_peek(__name, __qaddr) \
607 ____vsf_rng_buf_reset_peek(__name, __qaddr)
609#define ____vsf_rng_buf_get_all_peeked(__name, __qaddr) \
610 __name##_get_all_peeked((__qaddr))
611#define vsf_rng_buf_get_all_peeked(__name, __qaddr) \
612 ____vsf_rng_buf_get_all_peeked(__name, __qaddr)
614#define __vsf_rng_buf_peekable_count(__name, __qaddr) \
615 __name##_item_count_peekable((__qaddr))
616#define vsf_rng_buf_peekable_count(__name, __qaddr) \
617 __vsf_rng_buf_peekable_count(__name, __qaddr)
#define VSF_CAL_SECTION(__SEC)
Definition __compiler.h:181
unsigned short uint16_t
Definition lvgl.h:41
signed int int32_t
Definition lvgl.h:44
unsigned short uint_fast16_t
Definition stdint.h:25
def_class(vsf_stream_fifo_t, which(vsf_stream_tx_t TX;vsf_stream_rx_t RX;), private:vsf_slist_queue_t union { vsf_stream_fifo_cfg_t cfg;struct { vsf_stream_dat_rdy_evt_t tDataReadyEventHandling;vsf_stream_dat_drn_evt_t tDataDrainEventHandling;vsf_stream_status_t Status;#if !defined(VSF_PBUF_QUEUE_CFG_ATOM_ACCESS) vsf_protect_region_t *pregion;#endif };};) end_def_class(vsf_stream_fifo_t) extern vsf_err_t vsf_stream_fifo_init(vsf_stream_fifo_t *obj_ptr
void __vsf_rng_buf_init_ex(vsf_rng_buf_t *obj_ptr, uint_fast16_t buffer_item_cnt, bool is_init_as_full)
Definition vsf_queue.c:52
int32_t __vsf_rng_buf_peek_one(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:199
uint16_t length
Definition vsf_queue.h:632
void __vsf_rng_buf_get_all_peeked(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:232
uint16_t buffer_item_cnt
Definition vsf_queue.h:632
int32_t __vsf_rng_buf_peek_multiple(vsf_rng_buf_t *obj_ptr, uint16_t *item_cnt_ptr)
Definition vsf_queue.c:255
uint16_t peek
Definition vsf_queue.h:632
int32_t __vsf_rng_buf_send_multiple(vsf_rng_buf_t *obj_ptr, uint16_t *item_cnt_ptr)
Definition vsf_queue.c:122
uint_fast16_t bool is_init_as_full
Definition vsf_queue.h:642
end_def_class(vsf_rng_buf_t) extern void __vsf_rng_buf_init_ex(vsf_rng_buf_t *obj_ptr
uint16_t peek_cnt
Definition vsf_queue.h:632
uint_fast16_t __vsf_rng_buf_item_count(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:112
uint_fast16_t __vsf_rng_buf_item_count_peekable(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:244
declare_class(vsf_rng_buf_t) def_class(vsf_rng_buf_t
void __vsf_rng_buf_reset_peek(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:222
uint16_t tail
Definition vsf_queue.h:632
int32_t __vsf_rng_buf_get_multiple(vsf_rng_buf_t *obj_ptr, uint16_t *item_cnt_ptr)
Definition vsf_queue.c:159
int32_t __vsf_rng_buf_get_one(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:84
uint16_t head
Definition vsf_queue.h:632
int32_t __vsf_rng_buf_send_one(vsf_rng_buf_t *obj_ptr)
Definition vsf_queue.c:62