summaryrefslogtreecommitdiff
path: root/components/drivers/include
diff options
context:
space:
mode:
Diffstat (limited to 'components/drivers/include')
-rw-r--r--components/drivers/include/drivers/bypass.h69
-rw-r--r--components/drivers/include/drivers/dev_serial.h8
-rw-r--r--components/drivers/include/rtdevice.h3
3 files changed, 77 insertions, 3 deletions
diff --git a/components/drivers/include/drivers/bypass.h b/components/drivers/include/drivers/bypass.h
new file mode 100644
index 0000000000..890c8947d1
--- /dev/null
+++ b/components/drivers/include/drivers/bypass.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2006-2024 RT-Thread Development Team
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Change Logs:
+ * Date Author Notes
+ * 2024-11-20 zhujiale the first version
+ */
+
+#ifndef __RTT_BYPASS_H__
+#define __RTT_BYPASS_H__
+#include <rtthread.h>
+#include <rttypes.h>
+#include <rtdevice.h>
+typedef rt_err_t(*bypass_function_t)(struct rt_serial_device* serial, char buf, void* data);
+
+#define RT_BYPASS_LEVEL_MAX 4
+#define RT_BYPASS_LEVEL_1 0
+#define RT_BYPASS_LEVEL_2 1
+#define RT_BYPASS_LEVEL_3 2
+#define RT_BYPASS_LEVEL_4 3
+#define RT_BYPASS_MAX_LEVEL 4
+
+/*The protect level can be register but can not be unregister we should use it carefully*/
+#define RT_BYPASS_PROTECT_LEVEL_1 10
+#define RT_BYPASS_PROTECT_LEVEL_2 11
+#define RT_BYPASS_PROTECT_LEVEL_3 12
+#define RT_BYPASS_PROTECT_LEVEL_4 13
+
+struct rt_serial_bypass_func {
+ /*The function pointer of the bypassed data processing*/
+ bypass_function_t bypass;
+ /*The smaller the array of levels, the higher the priority of execution*/
+ rt_uint8_t level;
+ rt_list_t node;
+ char name[RT_NAME_MAX];
+ void* data;
+};
+
+struct rt_serial_bypass_head
+{
+ rt_list_t head;
+ struct rt_spinlock spinlock;
+};
+
+struct rt_serial_bypass {
+ struct rt_work work;
+
+ struct rt_spinlock spinlock;
+ struct rt_workqueue* lower_workq;
+ struct rt_serial_bypass_head* upper_h;
+ struct rt_serial_bypass_head* lower_h;
+ rt_mutex_t mutex;
+ struct rt_ringbuffer* pipe;
+};
+
+int serial_bypass_list(int argc, char** argv);
+
+void rt_bypass_work_straight(struct rt_serial_device* serial);
+void rt_bypass_putchar(struct rt_serial_device* serial, rt_uint8_t ch);
+rt_size_t rt_bypass_getchar(struct rt_serial_device* serial, rt_uint8_t* ch);
+
+rt_err_t rt_bypass_upper_unregister(struct rt_serial_device* serial, rt_uint8_t level);
+rt_err_t rt_bypass_lower_unregister(struct rt_serial_device* serial, rt_uint8_t level);
+
+rt_err_t rt_bypass_upper_register(struct rt_serial_device* serial, const char* name, rt_uint8_t level, bypass_function_t func, void* data);
+rt_err_t rt_bypass_lower_register(struct rt_serial_device* serial, const char* name, rt_uint8_t level, bypass_function_t func, void* data);
+#endif
diff --git a/components/drivers/include/drivers/dev_serial.h b/components/drivers/include/drivers/dev_serial.h
index df2a62030a..b7f627e8cd 100644
--- a/components/drivers/include/drivers/dev_serial.h
+++ b/components/drivers/include/drivers/dev_serial.h
@@ -76,7 +76,7 @@
* if (!serial)
* {
* rt_kprintf("find %s failed!\n", uart_name);
- * return RT_ERROR;
+ * return -RT_ERROR;
* }
*
*
@@ -97,7 +97,7 @@
* }
* else
* {
- * ret = RT_ERROR;
+ * ret = -RT_ERROR;
* }
*
* return ret;
@@ -264,7 +264,9 @@ struct rt_serial_device
void *serial_tx;
struct rt_spinlock spinlock;
-
+#ifdef RT_USING_SERIAL_BYPASS
+ struct rt_serial_bypass* bypass;
+#endif
struct rt_device_notify rx_notify;
};
typedef struct rt_serial_device rt_serial_t;
diff --git a/components/drivers/include/rtdevice.h b/components/drivers/include/rtdevice.h
index 09f5e455f7..31ac538945 100644
--- a/components/drivers/include/rtdevice.h
+++ b/components/drivers/include/rtdevice.h
@@ -152,6 +152,9 @@ extern "C" {
#include "drivers/dev_serial_v2.h"
#else
#include "drivers/dev_serial.h"
+#ifdef RT_USING_SERIAL_BYPASS
+#include "drivers/bypass.h"
+#endif /* RT_USING_SERIAL_BYPASS */
#endif
#endif /* RT_USING_SERIAL */