From 08a0e08f4d6932f266459cf118997a121cc2bb05 Mon Sep 17 00:00:00 2001 From: 423A35C7 <609514299@qq.com> Date: Tue, 26 Mar 2024 15:26:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=BA=86=E8=AE=A1=E6=97=B6?= =?UTF-8?q?=E5=99=A8=E7=9A=84=E5=AE=9E=E6=97=B6=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- labcodes_answer/lab1_result/kern/trap/trap.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/labcodes_answer/lab1_result/kern/trap/trap.c b/labcodes_answer/lab1_result/kern/trap/trap.c index a3099ee..c209f08 100644 --- a/labcodes_answer/lab1_result/kern/trap/trap.c +++ b/labcodes_answer/lab1_result/kern/trap/trap.c @@ -166,11 +166,15 @@ trap_dispatch(struct trapframe *tf) { */ switch (state) { case STARTED: - milliseconds += mode; - // 当时间倒计时到0时转成停止状态 - // 而正计时加了mode之后至少为1所以不会转换状态 - // 使用小于等于0而不是等于0是为了防止万一出现异常导致小于0的情况 - state = READY_TO_OUTPUT * (milliseconds <= 0); // 为了减少分支才写成这样 + if (ticks % TICK_NUM == 0) { + milliseconds += mode * TICK_NUM; + // 当时间倒计时到0时转成停止状态 + // 而正计时加了mode之后至少为1所以不会转换状态 + // 使用小于等于0而不是等于0是为了防止万一出现异常导致小于0的情况 + state = READY_TO_OUTPUT * (milliseconds <= 0); // 为了减少分支才写成这样 + // print_ticks(); + cprintf("\r%d.%03d\t", milliseconds / 1000, milliseconds % 1000); + } break; case READY_TO_OUTPUT: state = STOPPED; @@ -182,9 +186,6 @@ trap_dispatch(struct trapframe *tf) { break; } ticks ++; - // if (ticks % TICK_NUM == 0) { - // print_ticks(); - // } break; case IRQ_OFFSET + IRQ_COM1: c = cons_getc();