summaryrefslogtreecommitdiff
path: root/components/drivers/src
diff options
context:
space:
mode:
author192.168.1.134 <[email protected]>2021-12-09 19:18:24 +0800
committer192.168.1.134 <[email protected]>2021-12-09 19:18:24 +0800
commit6378f95f00fd51410d2715da55d728d4a40494de (patch)
treebb46a565875d538189e1c1dfc9b1cfddf6862a92 /components/drivers/src
parentd6b05287bbeaf9369546009e5af445f350b97fe9 (diff)
parent462f093cbd7531098de3b7aadb5f8d5f1b99b4a9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread
Diffstat (limited to 'components/drivers/src')
-rw-r--r--components/drivers/src/dataqueue.c84
-rw-r--r--components/drivers/src/pipe.c16
2 files changed, 92 insertions, 8 deletions
diff --git a/components/drivers/src/dataqueue.c b/components/drivers/src/dataqueue.c
index f32efa1849..4e52662c44 100644
--- a/components/drivers/src/dataqueue.c
+++ b/components/drivers/src/dataqueue.c
@@ -21,6 +21,23 @@ struct rt_data_item
rt_size_t data_size;
};
+/**
+ * @brief This function will initialize the data queue. Calling this function will
+ * initialize the data queue control block and set the notification callback function.
+ *
+ * @param queue is a pointer to the data queue object.
+ *
+ * @param size is the maximum number of data in the data queue.
+ *
+ * @param lwm is low water mark.
+ * When the number of data in the data queue is less than this value, this function will
+ * wake up the thread waiting for write data.
+ *
+ * @param evt_notify is the notification callback function.
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the initialization is successful.
+ * When the return value is RT_ENOMEM, it means insufficient memory allocation failed.
+ */
rt_err_t
rt_data_queue_init(struct rt_data_queue *queue,
rt_uint16_t size,
@@ -54,6 +71,21 @@ rt_data_queue_init(struct rt_data_queue *queue,
}
RTM_EXPORT(rt_data_queue_init);
+/**
+ * @brief This function will write data to the data queue. If the data queue is full,
+ * the thread will suspend for the specified amount of time.
+ *
+ * @param queue is a pointer to the data queue object.
+ * .
+ * @param data_ptr is the buffer pointer of the data to be written.
+ *
+ * @param size is the size in bytes of the data to be written.
+ *
+ * @param timeout is the waiting time.
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ * When the return value is RT_ETIMEOUT, it means the specified time out.
+ */
rt_err_t rt_data_queue_push(struct rt_data_queue *queue,
const void *data_ptr,
rt_size_t data_size,
@@ -153,6 +185,24 @@ __exit:
}
RTM_EXPORT(rt_data_queue_push);
+/**
+ * @brief This function will pop data from the data queue. If the data queue is empty,the thread
+ * will suspend for the specified amount of time.
+ *
+ * @note When the number of data in the data queue is less than lwm(low water mark), will
+ * wake up the thread waiting for write data.
+ *
+ * @param queue is a pointer to the data queue object.
+ *
+ * @param data_ptr is the buffer pointer of the data to be fetched.
+ *
+ * @param size is the size in bytes of the data to be fetched.
+ *
+ * @param timeout is the waiting time.
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ * When the return value is RT_ETIMEOUT, it means the specified time out.
+ */
rt_err_t rt_data_queue_pop(struct rt_data_queue *queue,
const void** data_ptr,
rt_size_t *size,
@@ -264,6 +314,18 @@ __exit:
}
RTM_EXPORT(rt_data_queue_pop);
+/**
+ * @brief This function will fetch but retaining data in the data queue.
+ *
+ * @param queue is a pointer to the data queue object.
+ *
+ * @param data_ptr is the buffer pointer of the data to be fetched.
+ *
+ * @param size is the size in bytes of the data to be fetched.
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ * When the return value is -RT_EEMPTY, it means the data queue is empty.
+ */
rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
const void** data_ptr,
rt_size_t *size)
@@ -289,6 +351,14 @@ rt_err_t rt_data_queue_peek(struct rt_data_queue *queue,
}
RTM_EXPORT(rt_data_queue_peek);
+/**
+ * @brief This function will reset the data queue.
+ *
+ * @note Calling this function will wake up all threads on the data queue
+ * that are hanging and waiting.
+ *
+ * @param queue is a pointer to the data queue object.
+ */
void rt_data_queue_reset(struct rt_data_queue *queue)
{
rt_ubase_t level;
@@ -362,6 +432,13 @@ void rt_data_queue_reset(struct rt_data_queue *queue)
}
RTM_EXPORT(rt_data_queue_reset);
+/**
+ * @brief This function will deinit the data queue.
+ *
+ * @param queue is a pointer to the data queue object.
+ *
+ * @return Return the operation status. When the return value is RT_EOK, the operation is successful.
+ */
rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
{
rt_ubase_t level;
@@ -382,6 +459,13 @@ rt_err_t rt_data_queue_deinit(struct rt_data_queue *queue)
}
RTM_EXPORT(rt_data_queue_deinit);
+/**
+ * @brief This function will get the number of data in the data queue.
+ *
+ * @param queue is a pointer to the data queue object.
+ *
+ * @return Return the number of data in the data queue.
+ */
rt_uint16_t rt_data_queue_len(struct rt_data_queue *queue)
{
rt_ubase_t level;
diff --git a/components/drivers/src/pipe.c b/components/drivers/src/pipe.c
index af90f13c6f..89b544bc4e 100644
--- a/components/drivers/src/pipe.c
+++ b/components/drivers/src/pipe.c
@@ -13,7 +13,7 @@
#include <stdint.h>
#include <sys/errno.h>
-#ifdef RT_USING_POSIX
+#ifdef RT_USING_POSIX_DEVIO
#include <dfs_file.h>
#include <dfs_posix.h>
#include <poll.h>
@@ -320,7 +320,7 @@ static const struct dfs_file_ops pipe_fops =
RT_NULL,
pipe_fops_poll,
};
-#endif /* end of RT_USING_POSIX */
+#endif /* RT_USING_POSIX_DEVIO */
rt_err_t rt_pipe_open(rt_device_t device, rt_uint16_t oflag)
{
@@ -439,7 +439,7 @@ const static struct rt_device_ops pipe_ops =
rt_pipe_write,
rt_pipe_control,
};
-#endif
+#endif /* RT_USING_DEVICE_OPS */
rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
{
@@ -451,7 +451,7 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
rt_memset(pipe, 0, sizeof(rt_pipe_t));
pipe->is_named = RT_TRUE; /* initialize as a named pipe */
- rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_FIFO);
+ rt_mutex_init(&(pipe->lock), name, RT_IPC_FLAG_PRIO);
rt_wqueue_init(&(pipe->reader_queue));
rt_wqueue_init(&(pipe->writer_queue));
@@ -479,9 +479,9 @@ rt_pipe_t *rt_pipe_create(const char *name, int bufsz)
rt_free(pipe);
return RT_NULL;
}
-#ifdef RT_USING_POSIX
+#ifdef RT_USING_POSIX_DEVIO
dev->fops = (void*)&pipe_fops;
-#endif
+#endif /* RT_USING_POSIX_DEVIO */
return pipe;
}
@@ -529,7 +529,7 @@ int rt_pipe_delete(const char *name)
return result;
}
-#ifdef RT_USING_POSIX
+#ifdef RT_USING_POSIX_DEVIO
int pipe(int fildes[2])
{
rt_pipe_t *pipe;
@@ -575,4 +575,4 @@ int mkfifo(const char *path, mode_t mode)
return 0;
}
-#endif
+#endif /* RT_USING_POSIX_DEVIO */