Browse Source

改善了走时不准的问题,倒计时手动停止后转为正计时,增加了中英文切换的说明。

x86-32
423A35C7 1 year ago
parent
commit
fedca16fb5
3 changed files with 9 additions and 5 deletions
  1. +3
    -2
      labcodes_answer/lab1_result/kern/driver/clock.c
  2. +4
    -2
      labcodes_answer/lab1_result/kern/trap/trap.c
  3. +2
    -1
      labcodes_answer/lab1_result/kern/trap/trap.h

+ 3
- 2
labcodes_answer/lab1_result/kern/driver/clock.c View File

@ -33,8 +33,9 @@ void
clock_init(void) { clock_init(void) {
// set 8253 timer-chip // set 8253 timer-chip
outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT); outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
outb(IO_TIMER1, TIMER_DIV(1000) % 256); // 10100
outb(IO_TIMER1, TIMER_DIV(1000) / 256); outb(IO_TIMER1, TIMER_DIV(100) % 256);
outb(IO_TIMER1, TIMER_DIV(100) / 256);
// initialize time counter 'ticks' to zero // initialize time counter 'ticks' to zero
ticks = 0; ticks = 0;

+ 4
- 2
labcodes_answer/lab1_result/kern/trap/trap.c View File

@ -9,7 +9,7 @@
#include <console.h> #include <console.h>
#include <kdebug.h> #include <kdebug.h>
#include <string.h> #include <string.h>
#define TICK_NUM 100 #define TICK_NUM 1
static void print_ticks() { static void print_ticks() {
cprintf("%d ticks\n",TICK_NUM); cprintf("%d ticks\n",TICK_NUM);
@ -167,7 +167,8 @@ trap_dispatch(struct trapframe *tf) {
switch (state) { switch (state) {
case STARTED: case STARTED:
if (ticks % TICK_NUM == 0) { if (ticks % TICK_NUM == 0) {
milliseconds += mode * TICK_NUM; // 10TICK_NUM次中断触发一次更新TICK_NUM * 10
milliseconds += mode * TICK_NUM * 10;
// 0 // 0
// mode之后至少为1所以不会转换状态 // mode之后至少为1所以不会转换状态
// 使000 // 使000
@ -239,6 +240,7 @@ trap_dispatch(struct trapframe *tf) {
break; break;
case 'e': case 'e':
state = STOPPED; state = STOPPED;
mode = COUNTUP;
cprintf(MSG_STOP, milliseconds / 1000, milliseconds % 1000); cprintf(MSG_STOP, milliseconds / 1000, milliseconds % 1000);
milliseconds = 0; milliseconds = 0;
break; break;

+ 2
- 1
labcodes_answer/lab1_result/kern/trap/trap.h View File

@ -47,7 +47,8 @@
#define T_SWITCH_TOU 120 // user/kernel switch #define T_SWITCH_TOU 120 // user/kernel switch
#define T_SWITCH_TOK 121 // user/kernel switch #define T_SWITCH_TOK 121 // user/kernel switch
#define ENGLISH // VSCode中可以正常看到中文QEMU中看到的是乱码
#define ENGLISH // 使用中文则不需要这一行
#ifndef ENGLISH #ifndef ENGLISH
#define MSG_COUNTDOWN_STOP "倒计时到0了,停止,转到正计时。\n" #define MSG_COUNTDOWN_STOP "倒计时到0了,停止,转到正计时。\n"

||||||
x
 
000:0
Loading…
Cancel
Save