2018-10-14 19:37:18 +08:00
|
|
|
/*
|
2023-04-18 10:26:23 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2018-10-14 19:37:18 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
*/
|
2017-10-15 22:56:46 +08:00
|
|
|
#ifndef DATAQUEUE_H__
|
|
|
|
#define DATAQUEUE_H__
|
|
|
|
|
2023-07-29 06:26:51 +08:00
|
|
|
#include <rtdef.h>
|
|
|
|
#include <rtconfig.h>
|
2017-10-15 22:56:46 +08:00
|
|
|
|
|
|
|
#define RT_DATAQUEUE_EVENT_UNKNOWN 0x00
|
|
|
|
#define RT_DATAQUEUE_EVENT_POP 0x01
|
|
|
|
#define RT_DATAQUEUE_EVENT_PUSH 0x02
|
|
|
|
#define RT_DATAQUEUE_EVENT_LWM 0x03
|
|
|
|
|
|
|
|
struct rt_data_item;
|
2020-09-18 09:33:34 +08:00
|
|
|
|
2017-10-15 22:56:46 +08:00
|
|
|
/* data queue implementation */
|
|
|
|
struct rt_data_queue
|
|
|
|
{
|
2020-04-08 11:05:37 +08:00
|
|
|
rt_uint32_t magic;
|
|
|
|
|
2017-10-15 22:56:46 +08:00
|
|
|
rt_uint16_t size;
|
|
|
|
rt_uint16_t lwm;
|
|
|
|
|
2020-09-18 09:33:34 +08:00
|
|
|
rt_uint16_t get_index : 15;
|
|
|
|
rt_uint16_t is_empty : 1;
|
|
|
|
rt_uint16_t put_index : 15;
|
|
|
|
rt_uint16_t is_full : 1;
|
2017-10-15 22:56:46 +08:00
|
|
|
|
|
|
|
struct rt_data_item *queue;
|
|
|
|
|
|
|
|
rt_list_t suspended_push_list;
|
|
|
|
rt_list_t suspended_pop_list;
|
|
|
|
|
|
|
|
/* event notify */
|
|
|
|
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataQueue for DeviceDriver
|
|
|
|
*/
|
|
|
|
rt_err_t rt_data_queue_init(struct rt_data_queue *queue,
|
|
|
|
rt_uint16_t size,
|
|
|
|
rt_uint16_t lwm,
|
|
|
|
void (*evt_notify)(struct rt_data_queue *queue, rt_uint32_t event));
|
|
|
|
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
|
|
|
|
const void *data_ptr,
|
|
|
|
rt_size_t data_size,
|
|
|
|
rt_int32_t timeout);
|
|
|
|
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
|
|
|
|
const void **data_ptr,
|
|
|
|
rt_size_t *size,
|
|
|
|
rt_int32_t timeout);
|
2020-12-31 16:02:42 +08:00
|
|
|
rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
|
2017-10-15 22:56:46 +08:00
|
|
|
const void **data_ptr,
|
|
|
|
rt_size_t *size);
|
|
|
|
void rt_data_queue_reset(struct rt_data_queue *queue);
|
2020-04-07 13:35:09 +08:00
|
|
|
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue);
|
2020-09-18 09:33:34 +08:00
|
|
|
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue);
|
2017-10-15 22:56:46 +08:00
|
|
|
|
|
|
|
#endif
|