fslongjin пре 2 година
родитељ
комит
98371a9b4a
6 измењених фајлова са 40 додато и 3 уклоњено
  1. 2 1
      .vscode/settings.json
  2. 8 0
      kernel/common/time.h
  3. 2 1
      kernel/main.c
  4. 4 0
      kernel/process/process.c
  5. 17 1
      kernel/time/sleep.c
  6. 7 0
      kernel/time/sleep.h

+ 2 - 1
.vscode/settings.json

@@ -108,7 +108,8 @@
         "ahci.h": "c",
         "slab.h": "c",
         "boot_info.h": "c",
-        "pci.h": "c"
+        "pci.h": "c",
+        "time.h": "c"
     },
     "C_Cpp.errorSquiggles": "Enabled",
     "esbonio.sphinx.confDir": ""

+ 8 - 0
kernel/common/time.h

@@ -37,6 +37,14 @@ struct timespec
  */
 extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
 
+/**
+ * @brief 睡眠指定时间
+ *
+ * @param usec 微秒
+ * @return int
+ */
+extern int usleep(useconds_t usec);
+
 /**
  * @brief 获取当前的CPU时间
  * 

+ 2 - 1
kernel/main.c

@@ -154,9 +154,10 @@ void system_initialize()
 
     // fat32_init();
     HPET_enable();
-    usb_init();
+    
     // 系统初始化到此结束,剩下的初始化功能应当放在初始内核线程中执行
     apic_timer_init();
+    
 }
 
 //操作系统内核从这里开始执行

+ 4 - 0
kernel/process/process.c

@@ -6,6 +6,7 @@
 #include <common/compiler.h>
 #include <common/libELF/elf.h>
 #include <driver/video/video.h>
+#include <driver/usb/usb.h>
 #include <exception/gate.h>
 #include <filesystem/fat32/fat32.h>
 #include <mm/slab.h>
@@ -410,7 +411,10 @@ ul initial_kernel_thread(ul arg)
     // kinfo("initial proc running...\targ:%#018lx", arg);
 
     fat32_init();
+    usb_init();
 
+
+    // 准备切换到用户态
     struct pt_regs *regs;
 
     current_pcb->thread->rip = (ul)ret_from_system_call;

+ 17 - 1
kernel/time/sleep.c

@@ -59,4 +59,20 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
     }
 
     return 0;
-}
+}
+
+/**
+ * @brief 睡眠指定时间
+ *
+ * @param usec 微秒
+ * @return int
+ */
+int usleep(useconds_t usec)
+{
+    struct timespec ts = {
+        tv_sec : (long int)(usec / 1000000),
+        tv_nsec : (long int)(usec % 1000000) * 1000UL
+    };
+
+    return nanosleep(&ts, NULL);
+}

+ 7 - 0
kernel/time/sleep.h

@@ -14,3 +14,10 @@
  */
 int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
 
+/**
+ * @brief 睡眠指定时间
+ *
+ * @param usec 微秒
+ * @return int
+ */
+int usleep(useconds_t usec);