改善了走时不准的问题,倒计时手动停止后转为正计时,增加了中英文切换的说明。
This commit is contained in:
parent
08a0e08f4d
commit
fedca16fb5
@ -33,8 +33,9 @@ void
|
||||
clock_init(void) {
|
||||
// set 8253 timer-chip
|
||||
outb(TIMER_MODE, TIMER_SEL0 | TIMER_RATEGEN | TIMER_16BIT);
|
||||
outb(IO_TIMER1, TIMER_DIV(1000) % 256);
|
||||
outb(IO_TIMER1, TIMER_DIV(1000) / 256);
|
||||
// 经过多次试验发现原始的10毫秒一次中断(即除以100)是最准时的,不要擅自改中断频率
|
||||
outb(IO_TIMER1, TIMER_DIV(100) % 256);
|
||||
outb(IO_TIMER1, TIMER_DIV(100) / 256);
|
||||
|
||||
// initialize time counter 'ticks' to zero
|
||||
ticks = 0;
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include <console.h>
|
||||
#include <kdebug.h>
|
||||
#include <string.h>
|
||||
#define TICK_NUM 100
|
||||
#define TICK_NUM 1
|
||||
|
||||
static void print_ticks() {
|
||||
cprintf("%d ticks\n",TICK_NUM);
|
||||
@ -167,7 +167,8 @@ trap_dispatch(struct trapframe *tf) {
|
||||
switch (state) {
|
||||
case STARTED:
|
||||
if (ticks % TICK_NUM == 0) {
|
||||
milliseconds += mode * TICK_NUM;
|
||||
// 10毫秒触发一次时钟中断,TICK_NUM次中断触发一次更新,所以毫秒数应该乘TICK_NUM * 10
|
||||
milliseconds += mode * TICK_NUM * 10;
|
||||
// 当时间倒计时到0时转成停止状态
|
||||
// 而正计时加了mode之后至少为1所以不会转换状态
|
||||
// 使用小于等于0而不是等于0是为了防止万一出现异常导致小于0的情况
|
||||
@ -239,6 +240,7 @@ trap_dispatch(struct trapframe *tf) {
|
||||
break;
|
||||
case 'e':
|
||||
state = STOPPED;
|
||||
mode = COUNTUP;
|
||||
cprintf(MSG_STOP, milliseconds / 1000, milliseconds % 1000);
|
||||
milliseconds = 0;
|
||||
break;
|
||||
|
@ -47,7 +47,8 @@
|
||||
#define T_SWITCH_TOU 120 // user/kernel switch
|
||||
#define T_SWITCH_TOK 121 // user/kernel switch
|
||||
|
||||
#define ENGLISH
|
||||
// 在VSCode中可以正常看到中文,但在QEMU中看到的是乱码
|
||||
#define ENGLISH // 使用中文则不需要这一行
|
||||
#ifndef ENGLISH
|
||||
|
||||
#define MSG_COUNTDOWN_STOP "倒计时到0了,停止,转到正计时。\n"
|
||||
|
Loading…
Reference in New Issue
Block a user