Browse Source

:wrench: 更改目录结构,将定时器独立出来

将定时器独立出来
fslongjin 2 years ago
parent
commit
eb67b612c4

+ 2 - 1
.vscode/settings.json

@@ -102,7 +102,8 @@
         "wait_queue.h": "c",
         "stddef.h": "c",
         "spinlock.h": "c",
-        "stat.h": "c"
+        "stat.h": "c",
+        "video.h": "c"
     },
     "C_Cpp.errorSquiggles": "Enabled",
     "esbonio.sphinx.confDir": ""

+ 2 - 4
kernel/Makefile

@@ -18,7 +18,7 @@ LD_LIST := head.o
 OBJ_LIST := head.o
 
 
-kernel_subdirs := common driver process debug filesystem
+kernel_subdirs := common driver process debug filesystem time
 	
 
 
@@ -125,8 +125,6 @@ rtc.o: driver/timers/rtc/rtc.c
 HPET.o: driver/timers/HPET/HPET.c
 	gcc $(CFLAGS) -c driver/timers/HPET/HPET.c -o driver/timers/HPET/HPET.o
 
-timer.o: driver/timers/timer.c
-	gcc $(CFLAGS) -c driver/timers/timer.c -o driver/timers/timer.o
 
 OBJ_LIST += uart.o
 LD_LIST += driver/uart/uart.o
@@ -156,7 +154,7 @@ all: kernel
 	echo "Done."
 
 
-kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o sched.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o smp.o apu_boot.o rtc.o HPET.o softirq.o timer.o $(OBJ_LIST)
+kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o sched.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o smp.o apu_boot.o rtc.o HPET.o softirq.o $(OBJ_LIST)
 	
 	@list='$(kernel_subdirs)'; for subdir in $$list; do \
     		echo "make all in $$subdir";\

+ 8 - 4
kernel/driver/timers/HPET/HPET.c

@@ -3,7 +3,7 @@
 #include <mm/mm.h>
 #include <driver/interrupt/apic/apic.h>
 #include <exception/softirq.h>
-#include <driver/timers/timer.h>
+#include <time/timer.h>
 #include <process/process.h>
 #include <sched/sched.h>
 #include <smp/ipi.h>
@@ -149,6 +149,7 @@ int HPET_init()
     HPET_COUNTER_CLK_PERIOD = (tmp >> 32) & 0xffffffff;
     HPET_freq = 1.0 * 1e15 / HPET_COUNTER_CLK_PERIOD;
     HPET_NUM_TIM_CAP = (tmp >> 8) & 0x1f; // 读取计时器数量
+    kinfo("Total HPET timers: %d", HPET_NUM_TIM_CAP);
 
     // kinfo("HPET CLK_PERIOD=%#03lx Frequency=%f", HPET_COUNTER_CLK_PERIOD, (double)HPET_freq);
     // kdebug("HPET_freq=%ld", (long)HPET_freq);
@@ -167,15 +168,18 @@ int HPET_init()
         while (1)
             hlt();
     }
-
+    // kdebug("[HPET0] conf register=%#018lx  conf register[63:32]=%#06lx", (*(uint64_t *)(HPET_REG_BASE + TIM0_CONF)), ((*(uint64_t *)(HPET_REG_BASE + TIM0_CONF))>>32)&0xffffffff);
     *(uint64_t *)(HPET_REG_BASE + MAIN_CNT) = 0;
     io_mfence();
-    *(uint64_t *)(HPET_REG_BASE + TIM0_CONF) = 0x004c; // 设置定时器0为周期定时,边沿触发,投递到IO APIC的2号引脚(这里有点绕,写的是8259的引脚号,但是因为禁用了8259,因此会被路由到IO APIC的2号引脚)
+    *(uint64_t *)(HPET_REG_BASE + TIM0_CONF) = 0x004c; // 设置定时器0为周期定时,边沿触发,默认投递到IO APIC的2号引脚(看conf寄存器的高32bit,哪一位被置1,则可以投递到哪一个I/O apic引脚)
     io_mfence();
     *(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = clks_to_intr; // 5ms触发一次中断
-    //*(uint64_t *)(HPET_REG_BASE + TIM0_COMP) = HPET_freq; // 1s触发一次中断
+
     io_mfence();
 
+    // kdebug("[HPET0] conf register after modify=%#018lx", ((*(uint64_t *)(HPET_REG_BASE + TIM0_CONF))));
+    // kdebug("[HPET1] conf register =%#018lx", ((*(uint64_t *)(HPET_REG_BASE + TIM1_CONF))));
+
     rtc_get_cmos_time(&rtc_now);
 
     kinfo("HPET Initialized.");

+ 1 - 1
kernel/driver/video/video.c

@@ -2,7 +2,7 @@
 #include <mm/mm.h>
 #include <common/printk.h>
 #include <driver/multiboot2/multiboot2.h>
-#include <driver/timers/timer.h>
+#include <time/timer.h>
 #include <common/kprint.h>
 #include <mm/mm.h>
 #include <mm/slab.h>

+ 3 - 72
kernel/main.c

@@ -28,7 +28,7 @@
 #include "driver/disk/ahci/ahci.h"
 #include <driver/timers/rtc/rtc.h>
 #include <driver/timers/HPET/HPET.h>
-#include <driver/timers/timer.h>
+#include <time/timer.h>
 #include <driver/uart/uart.h>
 #include <driver/video/video.h>
 
@@ -38,24 +38,7 @@ ul bsp_idt_size, bsp_gdt_size;
 struct memory_desc memory_management_struct = {{0}, 0};
 // struct Global_Memory_Descriptor memory_management_struct = {{0}, 0};
 void test_slab();
-void show_welcome()
-{
-    /**
-     * @brief 打印欢迎页面
-     *
-     */
-
-    printk("\n\n");
-    for (int i = 0; i < 74; ++i)
-        printk(" ");
-    printk_color(0x00e0ebeb, 0x00e0ebeb, "                                \n");
-    for (int i = 0; i < 74; ++i)
-        printk(" ");
-    printk_color(BLACK, 0x00e0ebeb, "      Welcome to DragonOS !     \n");
-    for (int i = 0; i < 74; ++i)
-        printk(" ");
-    printk_color(0x00e0ebeb, 0x00e0ebeb, "                                \n\n");
-}
+
 
 struct gdtr gdtp;
 struct idtr idtp;
@@ -190,59 +173,7 @@ void Start_Kernel(void)
 
     system_initialize();
 
-    /*
-    // int part_id = fat32_register_partition(0, 0, 0);
-    struct vfs_dir_entry_t *dentry = vfs_path_walk("a.txt", 0);
-    if (dentry != NULL)
-        printk_color(ORANGE, BLACK, "Found a.txt\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
-    else
-        printk_color(ORANGE, BLACK, "Can`t find file\n");
-
-    dentry = vfs_path_walk("xx/12.png", 0);
-    if (dentry != NULL)
-        printk_color(ORANGE, BLACK, "Found xx/12.png\nDIR_FstClus:%#018lx\tDIR_FileSize:%#018lx\n", ((struct fat32_inode_info_t *)(dentry->dir_inode->private_inode_info))->first_clus, dentry->dir_inode->file_size);
-    else
-        printk_color(ORANGE, BLACK, "Can`t find file\n");
-    */
-    // show_welcome();
-    // test_mm();
-
-    /*
-        while (1)
-        {
-            ps2_keyboard_analyze_keycode();
-            struct ps2_mouse_packet_3bytes packet = {0};
-            // struct ps2_mouse_packet_4bytes packet = {0};
-            int errcode = 0;
-            errcode = ps2_mouse_get_packet(&packet);
-            if (errcode == 0)
-            {
-                printk_color(GREEN, BLACK, " (Mouse: byte0:%d, x:%3d, y:%3d)\n", packet.byte0, packet.movement_x, packet.movement_y);
-                // printk_color(GREEN, BLACK, " (Mouse: byte0:%d, x:%3d, y:%3d, byte3:%3d)\n", packet.byte0, packet.movement_x, packet.movement_y, (unsigned char)packet.byte3);
-            }
-        }
-    */
-    /*
-        while (1)
-        {
-            keyboard_analyze_keycode();
-            analyze_mousecode();
-        }
-    */
-
-    // ipi_send_IPI(DEST_PHYSICAL, IDLE, ICR_LEVEL_DE_ASSERT, EDGE_TRIGGER, 0xc8, ICR_APIC_FIXED, ICR_No_Shorthand, true, 1);  // 测试ipi
-
-    // int last_sec = rtc_now.second;
-    /*
-    while (1)
-    {
-        if (last_sec != rtc_now.second)
-        {
-            last_sec = rtc_now.second;
-            kinfo("Current Time: %04d/%02d/%02d %02d:%02d:%02d", rtc_now.year, rtc_now.month, rtc_now.day, rtc_now.hour, rtc_now.minute, rtc_now.second);
-        }
-    }
-    */
+    
     while (1)
         hlt();
 }

+ 10 - 0
kernel/time/Makefile

@@ -0,0 +1,10 @@
+
+all: timer.o 
+
+CFLAGS += -I .
+
+timer.o: timer.c
+	gcc $(CFLAGS) -c timer.c -o timer.o
+
+clean:
+	echo "Done."

+ 0 - 0
kernel/driver/timers/timer.c → kernel/time/timer.c


+ 2 - 2
kernel/driver/timers/timer.h → kernel/time/timer.h

@@ -1,8 +1,8 @@
 #pragma once
 
 #include <common/glib.h>
-#include "HPET/HPET.h"
-#include "rtc/rtc.h"
+#include <driver/timers/HPET/HPET.h>
+#include <driver/timers/rtc/rtc.h>
 
 uint64_t volatile timer_jiffies = 0; // 系统时钟计数