dataqueue.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * RT-Thread RuiChing
  3. *
  4. * COPYRIGHT (C) 2024-2025 Shanghai Real-Thread Electronic Technology Co., Ltd.
  5. * All rights reserved.
  6. *
  7. * The license and distribution terms for this file may be
  8. * found in the file LICENSE in this distribution.
  9. */
  10. #ifndef __DATAQUEUE_H__
  11. #define __DATAQUEUE_H__
  12. #include <kpi.h>
  13. #include <rtconfig.h>
  14. #include <rtdef.h>
  15. #define RT_DATAQUEUE_EVENT_UNKNOWN 0x00
  16. #define RT_DATAQUEUE_EVENT_POP 0x01
  17. #define RT_DATAQUEUE_EVENT_PUSH 0x02
  18. #define RT_DATAQUEUE_EVENT_LWM 0x03
  19. struct rt_data_item;
  20. /* data queue implementation */
  21. struct rt_data_queue
  22. {
  23. rt_uint32_t magic;
  24. rt_uint16_t size;
  25. rt_uint16_t lwm;
  26. rt_uint16_t get_index : 15;
  27. rt_uint16_t is_empty : 1;
  28. rt_uint16_t put_index : 15;
  29. rt_uint16_t is_full : 1;
  30. struct rt_data_item *queue;
  31. struct rt_spinlock spinlock;
  32. rt_list_t suspended_push_list;
  33. rt_list_t suspended_pop_list;
  34. /* event notify */
  35. void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event);
  36. };
  37. /**
  38. * DataQueue for DeviceDriver
  39. */
  40. typedef rt_err_t (*__kpi_rt_data_queue_init)(struct rt_data_queue *queue,
  41. rt_uint16_t size,
  42. rt_uint16_t lwm,
  43. void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event));
  44. typedef rt_err_t (*__kpi_rt_data_queue_push)(struct rt_data_queue *queue,
  45. const void *data_ptr,
  46. rt_size_t data_size,
  47. rt_int32_t timeout);
  48. typedef rt_err_t (*__kpi_rt_data_queue_pop)(struct rt_data_queue *queue,
  49. const void **data_ptr,
  50. rt_size_t *size,
  51. rt_int32_t timeout);
  52. typedef rt_err_t (*__kpi_rt_data_queue_peek)(
  53. struct rt_data_queue *queue, const void **data_ptr, rt_size_t *size);
  54. typedef void (*__kpi_rt_data_queue_reset)(struct rt_data_queue *queue);
  55. typedef rt_err_t (*__kpi_rt_data_queue_deinit)(struct rt_data_queue *queue);
  56. typedef rt_uint16_t (*__kpi_rt_data_queue_len)(struct rt_data_queue *queue);
  57. KPI_EXTERN(rt_data_queue_init);
  58. KPI_EXTERN(rt_data_queue_push);
  59. KPI_EXTERN(rt_data_queue_pop);
  60. KPI_EXTERN(rt_data_queue_peek);
  61. KPI_EXTERN(rt_data_queue_reset);
  62. KPI_EXTERN(rt_data_queue_deinit);
  63. KPI_EXTERN(rt_data_queue_len);
  64. #endif /* __DATAQUEUE_H__ */