first
This commit is contained in:
41
rt-thread/components/drivers/include/ipc/completion.h
Normal file
41
rt-thread/components/drivers/include/ipc/completion.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2024-04-28 Shell Add new wait_flags() & wakeup_by_errno() API
|
||||
*/
|
||||
#ifndef COMPLETION_H_
|
||||
#define COMPLETION_H_
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
/**
|
||||
* Completion - A tiny & rapid IPC primitive for resource-constrained scenarios
|
||||
*
|
||||
* It's an IPC using one CPU word with the encoding:
|
||||
*
|
||||
* BIT | MAX-1 ----------------- 1 | 0 |
|
||||
* CONTENT | suspended_thread & ~1 | completed flag |
|
||||
*/
|
||||
|
||||
struct rt_completion
|
||||
{
|
||||
/* suspended thread, and completed flag */
|
||||
rt_atomic_t susp_thread_n_flag;
|
||||
};
|
||||
|
||||
#define RT_COMPLETION_INIT(comp) {0}
|
||||
|
||||
void rt_completion_init(struct rt_completion *completion);
|
||||
rt_err_t rt_completion_wait(struct rt_completion *completion,
|
||||
rt_int32_t timeout);
|
||||
rt_err_t rt_completion_wait_flags(struct rt_completion *completion,
|
||||
rt_int32_t timeout, int suspend_flag);
|
||||
void rt_completion_done(struct rt_completion *completion);
|
||||
rt_err_t rt_completion_wakeup(struct rt_completion *completion);
|
||||
rt_err_t rt_completion_wakeup_by_errno(struct rt_completion *completion, rt_err_t error);
|
||||
#endif
|
38
rt-thread/components/drivers/include/ipc/condvar.h
Normal file
38
rt-thread/components/drivers/include/ipc/condvar.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-11-20 Shell Add cond var API in kernel
|
||||
*/
|
||||
|
||||
#ifndef IPC_CONDVAR_H__
|
||||
#define IPC_CONDVAR_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef struct rt_condvar
|
||||
{
|
||||
#ifdef USING_RT_OBJECT
|
||||
struct rt_object parent;
|
||||
#endif
|
||||
rt_atomic_t waiters_cnt;
|
||||
rt_atomic_t waiting_mtx;
|
||||
struct rt_wqueue event;
|
||||
} *rt_condvar_t;
|
||||
|
||||
void rt_condvar_init(rt_condvar_t cv, char *name);
|
||||
int rt_condvar_timedwait(rt_condvar_t cv, rt_mutex_t mtx, int suspend_flag,
|
||||
rt_tick_t timeout);
|
||||
int rt_condvar_signal(rt_condvar_t cv);
|
||||
int rt_condvar_broadcast(rt_condvar_t cv);
|
||||
|
||||
rt_inline void rt_condvar_detach(rt_condvar_t cv)
|
||||
{
|
||||
RT_UNUSED(cv);
|
||||
return ;
|
||||
}
|
||||
|
||||
#endif /* IPC_CONDVAR_H__ */
|
67
rt-thread/components/drivers/include/ipc/dataqueue.h
Normal file
67
rt-thread/components/drivers/include/ipc/dataqueue.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef DATAQUEUE_H__
|
||||
#define DATAQUEUE_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
#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;
|
||||
|
||||
/* data queue implementation */
|
||||
struct rt_data_queue
|
||||
{
|
||||
rt_uint32_t magic;
|
||||
|
||||
rt_uint16_t size;
|
||||
rt_uint16_t lwm;
|
||||
|
||||
rt_uint16_t get_index : 15;
|
||||
rt_uint16_t is_empty : 1;
|
||||
rt_uint16_t put_index : 15;
|
||||
rt_uint16_t is_full : 1;
|
||||
|
||||
struct rt_data_item *queue;
|
||||
struct rt_spinlock spinlock;
|
||||
|
||||
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);
|
||||
rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
|
||||
const void **data_ptr,
|
||||
rt_size_t *size);
|
||||
void rt_data_queue_reset(struct rt_data_queue *queue);
|
||||
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue);
|
||||
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue);
|
||||
|
||||
#endif
|
51
rt-thread/components/drivers/include/ipc/pipe.h
Normal file
51
rt-thread/components/drivers/include/ipc/pipe.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
#ifndef PIPE_H__
|
||||
#define PIPE_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
#include "condvar.h"
|
||||
|
||||
/**
|
||||
* Pipe Device
|
||||
*/
|
||||
|
||||
struct rt_pipe_device
|
||||
{
|
||||
struct rt_device parent;
|
||||
rt_bool_t is_named;
|
||||
#ifdef RT_USING_POSIX_DEVIO
|
||||
int pipeno; /* for unamed pipe */
|
||||
#endif
|
||||
|
||||
/* ring buffer in pipe device */
|
||||
struct rt_ringbuffer *fifo;
|
||||
rt_uint16_t bufsz;
|
||||
|
||||
rt_wqueue_t reader_queue;
|
||||
rt_wqueue_t writer_queue;
|
||||
int writer;
|
||||
int reader;
|
||||
|
||||
struct rt_condvar waitfor_parter;
|
||||
struct rt_mutex lock;
|
||||
};
|
||||
typedef struct rt_pipe_device rt_pipe_t;
|
||||
|
||||
rt_pipe_t *rt_pipe_create(const char *name, int bufsz);
|
||||
rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag);
|
||||
rt_ssize_t rt_pipe_read(rt_device_t device, rt_off_t pos, void *buffer, rt_size_t count);
|
||||
rt_ssize_t rt_pipe_write(rt_device_t device, rt_off_t pos, const void *buffer, rt_size_t count);
|
||||
rt_err_t rt_pipe_control(rt_device_t dev, int cmd, void *args);
|
||||
rt_err_t rt_pipe_close(rt_device_t device);
|
||||
int rt_pipe_delete(const char *name);
|
||||
|
||||
#endif /* PIPE_H__ */
|
42
rt-thread/components/drivers/include/ipc/poll.h
Normal file
42
rt-thread/components/drivers/include/ipc/poll.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2016-09-19 Heyuanjie The first version.
|
||||
* 2016-12-26 Bernard Update poll interface
|
||||
*/
|
||||
#ifndef IPC_POLL_H__
|
||||
#define IPC_POLL_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct rt_pollreq;
|
||||
typedef void (*poll_queue_proc)(rt_wqueue_t *, struct rt_pollreq *);
|
||||
|
||||
typedef struct rt_pollreq
|
||||
{
|
||||
poll_queue_proc _proc;
|
||||
short _key;
|
||||
} rt_pollreq_t;
|
||||
|
||||
rt_inline void rt_poll_add(rt_wqueue_t *wq, rt_pollreq_t *req)
|
||||
{
|
||||
if (req && req->_proc && wq)
|
||||
{
|
||||
req->_proc(wq, req);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
114
rt-thread/components/drivers/include/ipc/ringblk_buf.h
Normal file
114
rt-thread/components/drivers/include/ipc/ringblk_buf.h
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-08-25 armink the first version
|
||||
*/
|
||||
|
||||
#ifndef _RINGBLK_BUF_H_
|
||||
#define _RINGBLK_BUF_H_
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
/*
|
||||
* Introduction:
|
||||
* The rbb is the ring buffer which is composed with many blocks. It is different from the ring buffer.
|
||||
* The ring buffer is only composed with chars. The rbb put and get supported zero copies. So the rbb
|
||||
* is very suitable for put block and get block by a certain order. Such as DMA block transmit,
|
||||
* communicate frame send/recv, and so on.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum rt_rbb_status
|
||||
{
|
||||
/* unused status when first initialize or after blk_free() */
|
||||
RT_RBB_BLK_UNUSED,
|
||||
/* initialized status after blk_alloc() */
|
||||
RT_RBB_BLK_INITED,
|
||||
/* put status after blk_put() */
|
||||
RT_RBB_BLK_PUT,
|
||||
/* get status after blk_get() */
|
||||
RT_RBB_BLK_GET,
|
||||
};
|
||||
typedef enum rt_rbb_status rt_rbb_status_t;
|
||||
|
||||
/**
|
||||
* the block of rbb
|
||||
*/
|
||||
struct rt_rbb_blk
|
||||
{
|
||||
rt_rbb_status_t status :8;
|
||||
/* less then 2^24 */
|
||||
rt_size_t size :24;
|
||||
rt_uint8_t *buf;
|
||||
rt_slist_t list;
|
||||
};
|
||||
typedef struct rt_rbb_blk *rt_rbb_blk_t;
|
||||
|
||||
/**
|
||||
* Rbb block queue: the blocks (from block1->buf to blockn->buf) memory which on this queue is continuous.
|
||||
*/
|
||||
struct rt_rbb_blk_queue
|
||||
{
|
||||
rt_rbb_blk_t blocks;
|
||||
rt_size_t blk_num;
|
||||
};
|
||||
typedef struct rt_rbb_blk_queue *rt_rbb_blk_queue_t;
|
||||
|
||||
/**
|
||||
* ring block buffer
|
||||
*/
|
||||
struct rt_rbb
|
||||
{
|
||||
rt_uint8_t *buf;
|
||||
rt_size_t buf_size;
|
||||
/* all of blocks */
|
||||
rt_rbb_blk_t blk_set;
|
||||
rt_size_t blk_max_num;
|
||||
/* saved the initialized and put status blocks */
|
||||
rt_slist_t blk_list;
|
||||
/* point to tail node */
|
||||
rt_slist_t *tail;
|
||||
/* free node list */
|
||||
rt_slist_t free_list;
|
||||
struct rt_spinlock spinlock;
|
||||
};
|
||||
typedef struct rt_rbb *rt_rbb_t;
|
||||
|
||||
/* rbb (ring block buffer) API */
|
||||
void rt_rbb_init(rt_rbb_t rbb, rt_uint8_t *buf, rt_size_t buf_size, rt_rbb_blk_t block_set, rt_size_t blk_max_num);
|
||||
rt_size_t rt_rbb_get_buf_size(rt_rbb_t rbb);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_rbb_t rt_rbb_create(rt_size_t buf_size, rt_size_t blk_max_num);
|
||||
void rt_rbb_destroy(rt_rbb_t rbb);
|
||||
#endif
|
||||
|
||||
/* rbb block API */
|
||||
rt_rbb_blk_t rt_rbb_blk_alloc(rt_rbb_t rbb, rt_size_t blk_size);
|
||||
void rt_rbb_blk_put(rt_rbb_blk_t block);
|
||||
rt_rbb_blk_t rt_rbb_blk_get(rt_rbb_t rbb);
|
||||
rt_size_t rt_rbb_blk_size(rt_rbb_blk_t block);
|
||||
rt_uint8_t *rt_rbb_blk_buf(rt_rbb_blk_t block);
|
||||
void rt_rbb_blk_free(rt_rbb_t rbb, rt_rbb_blk_t block);
|
||||
|
||||
/* rbb block queue API */
|
||||
rt_size_t rt_rbb_blk_queue_get(rt_rbb_t rbb, rt_size_t queue_data_len, rt_rbb_blk_queue_t blk_queue);
|
||||
rt_size_t rt_rbb_blk_queue_len(rt_rbb_blk_queue_t blk_queue);
|
||||
rt_uint8_t *rt_rbb_blk_queue_buf(rt_rbb_blk_queue_t blk_queue);
|
||||
void rt_rbb_blk_queue_free(rt_rbb_t rbb, rt_rbb_blk_queue_t blk_queue);
|
||||
rt_size_t rt_rbb_next_blk_queue_len(rt_rbb_t rbb);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _RINGBLK_BUF_H_ */
|
104
rt-thread/components/drivers/include/ipc/ringbuffer.h
Normal file
104
rt-thread/components/drivers/include/ipc/ringbuffer.h
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-08-14 Jackistang add comments for function interface.
|
||||
*/
|
||||
#ifndef RINGBUFFER_H__
|
||||
#define RINGBUFFER_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* ring buffer */
|
||||
struct rt_ringbuffer
|
||||
{
|
||||
rt_uint8_t *buffer_ptr;
|
||||
/* use the msb of the {read,write}_index as mirror bit. You can see this as
|
||||
* if the buffer adds a virtual mirror and the pointers point either to the
|
||||
* normal or to the mirrored buffer. If the write_index has the same value
|
||||
* with the read_index, but in a different mirror, the buffer is full.
|
||||
* While if the write_index and the read_index are the same and within the
|
||||
* same mirror, the buffer is empty. The ASCII art of the ringbuffer is:
|
||||
*
|
||||
* mirror = 0 mirror = 1
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Full
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* read_idx-^ write_idx-^
|
||||
*
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 ||| 0 | 1 | 2 | 3 | 4 | 5 | 6 | Empty
|
||||
* +---+---+---+---+---+---+---+|+~~~+~~~+~~~+~~~+~~~+~~~+~~~+
|
||||
* read_idx-^ ^-write_idx
|
||||
*/
|
||||
|
||||
rt_uint32_t read_mirror : 1;
|
||||
rt_uint32_t read_index : 31;
|
||||
rt_uint32_t write_mirror : 1;
|
||||
rt_uint32_t write_index : 31;
|
||||
/* as we use msb of index as mirror bit, the size should be signed and
|
||||
* could only be positive. */
|
||||
rt_int32_t buffer_size;
|
||||
};
|
||||
|
||||
enum rt_ringbuffer_state
|
||||
{
|
||||
RT_RINGBUFFER_EMPTY,
|
||||
RT_RINGBUFFER_FULL,
|
||||
/* half full is neither full nor empty */
|
||||
RT_RINGBUFFER_HALFFULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* RingBuffer for DeviceDriver
|
||||
*
|
||||
* Please note that the ring buffer implementation of RT-Thread
|
||||
* has no thread wait or resume feature.
|
||||
*/
|
||||
void rt_ringbuffer_init(struct rt_ringbuffer *rb, rt_uint8_t *pool, rt_int32_t size);
|
||||
void rt_ringbuffer_reset(struct rt_ringbuffer *rb);
|
||||
rt_size_t rt_ringbuffer_put(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint32_t length);
|
||||
rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb, const rt_uint8_t *ptr, rt_uint32_t length);
|
||||
rt_size_t rt_ringbuffer_putchar(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_putchar_force(struct rt_ringbuffer *rb, const rt_uint8_t ch);
|
||||
rt_size_t rt_ringbuffer_get(struct rt_ringbuffer *rb, rt_uint8_t *ptr, rt_uint32_t length);
|
||||
rt_size_t rt_ringbuffer_peek(struct rt_ringbuffer *rb, rt_uint8_t **ptr);
|
||||
rt_size_t rt_ringbuffer_getchar(struct rt_ringbuffer *rb, rt_uint8_t *ch);
|
||||
rt_size_t rt_ringbuffer_data_len(struct rt_ringbuffer *rb);
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
struct rt_ringbuffer* rt_ringbuffer_create(rt_uint32_t length);
|
||||
void rt_ringbuffer_destroy(struct rt_ringbuffer *rb);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Get the buffer size of the ring buffer object.
|
||||
*
|
||||
* @param rb A pointer to the ring buffer object.
|
||||
*
|
||||
* @return Buffer size.
|
||||
*/
|
||||
rt_inline rt_uint32_t rt_ringbuffer_get_size(struct rt_ringbuffer *rb)
|
||||
{
|
||||
RT_ASSERT(rb != RT_NULL);
|
||||
return rb->buffer_size;
|
||||
}
|
||||
|
||||
/** return the size of empty space in rb */
|
||||
#define rt_ringbuffer_space_len(rb) ((rb)->buffer_size - rt_ringbuffer_data_len(rb))
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
64
rt-thread/components/drivers/include/ipc/waitqueue.h
Normal file
64
rt-thread/components/drivers/include/ipc/waitqueue.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018/06/26 Bernard Fix the wait queue issue when wakeup a soon
|
||||
* to blocked thread.
|
||||
*/
|
||||
|
||||
#ifndef WAITQUEUE_H__
|
||||
#define WAITQUEUE_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
#define RT_WQ_FLAG_CLEAN 0x00
|
||||
#define RT_WQ_FLAG_WAKEUP 0x01
|
||||
|
||||
struct rt_wqueue_node;
|
||||
typedef int (*rt_wqueue_func_t)(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
struct rt_wqueue_node
|
||||
{
|
||||
rt_thread_t polling_thread;
|
||||
rt_list_t list;
|
||||
|
||||
rt_wqueue_t *wqueue;
|
||||
rt_wqueue_func_t wakeup;
|
||||
rt_uint32_t key;
|
||||
};
|
||||
typedef struct rt_wqueue_node rt_wqueue_node_t;
|
||||
|
||||
int __wqueue_default_wake(struct rt_wqueue_node *wait, void *key);
|
||||
|
||||
rt_inline void rt_wqueue_init(rt_wqueue_t *queue)
|
||||
{
|
||||
RT_ASSERT(queue != RT_NULL);
|
||||
|
||||
queue->flag = RT_WQ_FLAG_CLEAN;
|
||||
rt_list_init(&(queue->waiting_list));
|
||||
rt_spin_lock_init(&(queue->spinlock));
|
||||
}
|
||||
|
||||
void rt_wqueue_add(rt_wqueue_t *queue, struct rt_wqueue_node *node);
|
||||
void rt_wqueue_remove(struct rt_wqueue_node *node);
|
||||
int rt_wqueue_wait(rt_wqueue_t *queue, int condition, int timeout);
|
||||
int rt_wqueue_wait_killable(rt_wqueue_t *queue, int condition, int timeout);
|
||||
int rt_wqueue_wait_interruptible(rt_wqueue_t *queue, int condition, int timeout);
|
||||
void rt_wqueue_wakeup(rt_wqueue_t *queue, void *key);
|
||||
void rt_wqueue_wakeup_all(rt_wqueue_t *queue, void *key);
|
||||
|
||||
#define DEFINE_WAIT_FUNC(name, function) \
|
||||
struct rt_wqueue_node name = { \
|
||||
rt_current_thread, \
|
||||
RT_LIST_OBJECT_INIT(((name).list)), \
|
||||
function, \
|
||||
0 \
|
||||
}
|
||||
|
||||
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, __wqueue_default_wake)
|
||||
|
||||
#endif
|
85
rt-thread/components/drivers/include/ipc/workqueue.h
Normal file
85
rt-thread/components/drivers/include/ipc/workqueue.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2023, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-08-01 Meco Man remove rt_delayed_work_init() and rt_delayed_work structure
|
||||
* 2021-08-14 Jackistang add comments for rt_work_init()
|
||||
*/
|
||||
#ifndef WORKQUEUE_H__
|
||||
#define WORKQUEUE_H__
|
||||
|
||||
#include <rtdef.h>
|
||||
#include <rtconfig.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
RT_WORK_STATE_PENDING = 0x0001, /* Work item pending state */
|
||||
RT_WORK_STATE_SUBMITTING = 0x0002, /* Work item submitting state */
|
||||
};
|
||||
|
||||
/**
|
||||
* work type definitions
|
||||
*/
|
||||
enum
|
||||
{
|
||||
RT_WORK_TYPE_DELAYED = 0x0001,
|
||||
};
|
||||
|
||||
/* workqueue implementation */
|
||||
struct rt_workqueue
|
||||
{
|
||||
rt_list_t work_list;
|
||||
rt_list_t delayed_list;
|
||||
struct rt_work *work_current; /* current work */
|
||||
|
||||
struct rt_semaphore sem;
|
||||
rt_thread_t work_thread;
|
||||
struct rt_spinlock spinlock;
|
||||
};
|
||||
|
||||
struct rt_work
|
||||
{
|
||||
rt_list_t list;
|
||||
|
||||
void (*work_func)(struct rt_work *work, void *work_data);
|
||||
void *work_data;
|
||||
rt_uint16_t flags;
|
||||
rt_uint16_t type;
|
||||
struct rt_timer timer;
|
||||
struct rt_workqueue *workqueue;
|
||||
};
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
/**
|
||||
* WorkQueue for DeviceDriver
|
||||
*/
|
||||
void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data);
|
||||
struct rt_workqueue *rt_workqueue_create(const char *name, rt_uint16_t stack_size, rt_uint8_t priority);
|
||||
rt_err_t rt_workqueue_destroy(struct rt_workqueue *queue);
|
||||
rt_err_t rt_workqueue_dowork(struct rt_workqueue *queue, struct rt_work *work);
|
||||
rt_err_t rt_workqueue_submit_work(struct rt_workqueue *queue, struct rt_work *work, rt_tick_t ticks);
|
||||
rt_err_t rt_workqueue_cancel_work(struct rt_workqueue *queue, struct rt_work *work);
|
||||
rt_err_t rt_workqueue_cancel_work_sync(struct rt_workqueue *queue, struct rt_work *work);
|
||||
rt_err_t rt_workqueue_cancel_all_work(struct rt_workqueue *queue);
|
||||
rt_err_t rt_workqueue_urgent_work(struct rt_workqueue *queue, struct rt_work *work);
|
||||
|
||||
#ifdef RT_USING_SYSTEM_WORKQUEUE
|
||||
rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t ticks);
|
||||
rt_err_t rt_work_urgent(struct rt_work *work);
|
||||
rt_err_t rt_work_cancel(struct rt_work *work);
|
||||
#endif /* RT_USING_SYSTEM_WORKQUEUE */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RT_USING_HEAP */
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user