mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
完善设备驱动模型&调试串口驱动 (#379)
* 完成了基本架构重构,正在进行兼容 * 重构了所有 Device Driver ,还没有接上具体设备 * 基本把 Uart 接上了,还没有测试 * 初步完成系统设备初始化 * 初步重构 BlockDevice ,使其兼容新的 Device 结构 * 修改文件系统内的部分函数调用以满足重构后的接口 * 测试完 Uart 设备的功能 * 移除了自动添加的文件 * 修复了 warning 和部分格式 * 解决warning,并且修正sysfs初始化的位置 * Patch fix * 删除了 sysinfo 的默认实现 * 删除了字符设备读写的 offset 参数 * 修复了 warning 和一些小逻辑错误 --------- Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
32
user/apps/test_uart/main.c
Normal file
32
user/apps/test_uart/main.c
Normal file
@ -0,0 +1,32 @@
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
// 打开设备文件
|
||||
int fd = open("/dev/char/uart:1088", O_WRONLY | O_NONBLOCK);
|
||||
char buf[1] = {0};
|
||||
int n;
|
||||
memset(buf, 0, 1);
|
||||
while (1) {
|
||||
n = read(fd, buf, 1);
|
||||
close(fd);
|
||||
fd = open("/dev/char/uart:1088", O_WRONLY | O_NONBLOCK);
|
||||
if (n != 0) { // 添加字符串结束符
|
||||
printf("Received: %s\n", buf); // 打印接收到的数据
|
||||
if (buf[0] == 'g') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("fd: %ld", fd);
|
||||
// 写入字符串
|
||||
char *str = "------fuck-----";
|
||||
int len = write(fd, str, strlen(str));
|
||||
printf("len: %ld", len);
|
||||
// 关闭文件
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user