mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 19:36:47 +00:00
完成了tty设备在devfs中的注册
This commit is contained in:
parent
518ce3818c
commit
fcdd6f5fa9
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -138,7 +138,8 @@
|
||||
"devfs.h": "c",
|
||||
"devfs-types.h": "c",
|
||||
"chardev.h": "c",
|
||||
"rootfs.h": "c"
|
||||
"rootfs.h": "c",
|
||||
"tty.h": "c"
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "Enabled",
|
||||
"esbonio.sphinx.confDir": ""
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
CFLAGS += -I .
|
||||
|
||||
kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers
|
||||
kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers tty
|
||||
|
||||
ECHO:
|
||||
@echo "$@"
|
||||
|
8
kernel/driver/tty/Makefile
Normal file
8
kernel/driver/tty/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
all: tty.o
|
||||
|
||||
CFLAGS += -I .
|
||||
|
||||
|
||||
tty.o: tty.c
|
||||
gcc $(CFLAGS) -c tty.c -o tty.o
|
92
kernel/driver/tty/tty.c
Normal file
92
kernel/driver/tty/tty.c
Normal file
@ -0,0 +1,92 @@
|
||||
#include <filesystem/devfs/devfs.h>
|
||||
#include <filesystem/VFS/VFS.h>
|
||||
#include "tty.h"
|
||||
|
||||
static int tty_private_data;
|
||||
|
||||
/**
|
||||
* @brief 打开tty文件
|
||||
*
|
||||
* @param inode 所在的inode
|
||||
* @param filp 文件指针
|
||||
* @return long
|
||||
*/
|
||||
long tty_open(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
|
||||
{
|
||||
filp->private_data = &tty_private_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 关闭tty文件
|
||||
*
|
||||
* @param inode 所在的inode
|
||||
* @param filp 文件指针
|
||||
* @return long
|
||||
*/
|
||||
long tty_close(struct vfs_index_node_t *inode, struct vfs_file_t *filp)
|
||||
{
|
||||
filp->private_data = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tty控制接口
|
||||
*
|
||||
* @param inode 所在的inode
|
||||
* @param filp tty文件指针
|
||||
* @param cmd 命令
|
||||
* @param arg 参数
|
||||
* @return long
|
||||
*/
|
||||
long tty_ioctl(struct vfs_index_node_t *inode, struct vfs_file_t *filp, uint64_t cmd, uint64_t arg)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取tty文件的操作接口
|
||||
*
|
||||
* @param filp 文件指针
|
||||
* @param buf 输出缓冲区
|
||||
* @param count 要读取的字节数
|
||||
* @param position 读取的位置
|
||||
* @return long 读取的字节数
|
||||
*/
|
||||
long tty_read(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief tty文件写入接口(无作用,空)
|
||||
*
|
||||
* @param filp
|
||||
* @param buf
|
||||
* @param count
|
||||
* @param position
|
||||
* @return long
|
||||
*/
|
||||
long tty_write(struct vfs_file_t *filp, char *buf, int64_t count, long *position)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct vfs_file_operations_t tty_fops={
|
||||
.open = tty_open,
|
||||
.close = tty_close,
|
||||
.ioctl = tty_ioctl,
|
||||
.read = tty_read,
|
||||
.write = tty_write,
|
||||
};
|
||||
|
||||
void tty_init(){
|
||||
//注册devfs
|
||||
devfs_register_device(DEV_TYPE_CHAR, CHAR_DEV_STYPE_TTY, &tty_fops);
|
||||
kinfo("tty driver registered.");
|
||||
}
|
3
kernel/driver/tty/tty.h
Normal file
3
kernel/driver/tty/tty.h
Normal file
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void tty_init();
|
@ -22,6 +22,7 @@ static char chardev_name_prefix[CHAR_DEV_STYPE_END + 1][32] = {
|
||||
[CHAR_DEV_STYPE_USB_KEYBOARD] = "usb.kb",
|
||||
[CHAR_DEV_STYPE_BLUETOOTH_MOUSE] = "bt.mse",
|
||||
[CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD] = "bt.kb",
|
||||
[CHAR_DEV_STYPE_TTY] = "vdev.tty",
|
||||
[CHAR_DEV_STYPE_END] = "",
|
||||
};
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ enum
|
||||
CHAR_DEV_STYPE_USB_MOUSE,
|
||||
CHAR_DEV_STYPE_BLUETOOTH_MOUSE,
|
||||
CHAR_DEV_STYPE_BLUETOOTH_KEYBOARD,
|
||||
CHAR_DEV_STYPE_TTY,
|
||||
CHAR_DEV_STYPE_END, // 结束标志
|
||||
};
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "driver/multiboot2/multiboot2.h"
|
||||
#include "driver/acpi/acpi.h"
|
||||
#include "driver/keyboard/ps2_keyboard.h"
|
||||
#include "driver/tty/tty.h"
|
||||
#include "driver/mouse/ps2_mouse.h"
|
||||
#include "driver/disk/ata.h"
|
||||
#include "driver/pci/pci.h"
|
||||
@ -145,6 +146,7 @@ void system_initialize()
|
||||
devfs_init();
|
||||
cpu_init();
|
||||
ps2_keyboard_init();
|
||||
tty_init();
|
||||
// ps2_mouse_init();
|
||||
// ata_init();
|
||||
pci_init();
|
||||
|
Loading…
x
Reference in New Issue
Block a user