From 83257996571a200976cf390a94324379b2dda911 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Wed, 3 Aug 2022 14:52:42 +0800 Subject: [PATCH] =?UTF-8?q?uart=E5=A2=9E=E5=8A=A0=E5=8F=91=E9=80=81?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/driver/uart/uart.c | 21 ++++++++++++++++++++- kernel/driver/uart/uart.h | 10 +++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/kernel/driver/uart/uart.c b/kernel/driver/uart/uart.c index 2001d28b..c7d4450f 100644 --- a/kernel/driver/uart/uart.c +++ b/kernel/driver/uart/uart.c @@ -83,6 +83,25 @@ uchar uart_read(uint32_t port) { while (serial_received(port) == 0) pause(); - + return io_in8(port); +} + +/** + * @brief 通过串口发送整个字符串 + * + * @param port 串口端口 + * @param str 字符串 + */ +void uart_send_str(uint32_t port, const char *str) +{ + if ((unlikely(str == NULL))) + return; + while (1) + { + if (unlikely(*str == '\0')) + return; + uart_send(port, *str); + ++str; + } } \ No newline at end of file diff --git a/kernel/driver/uart/uart.h b/kernel/driver/uart/uart.h index c5442bd5..8a011685 100644 --- a/kernel/driver/uart/uart.h +++ b/kernel/driver/uart/uart.h @@ -61,4 +61,12 @@ void uart_send(uint32_t port, char c); * @param port 端口号 * @return uchar 接收到的数据 */ -uchar uart_read(uint32_t port); \ No newline at end of file +uchar uart_read(uint32_t port); + +/** + * @brief 通过串口发送整个字符串 + * + * @param port 串口端口 + * @param str 字符串 + */ +void uart_send_str(uint32_t port, const char *str); \ No newline at end of file