|
@ -166,11 +166,15 @@ trap_dispatch(struct trapframe *tf) { |
|
|
*/ |
|
|
*/ |
|
|
switch (state) { |
|
|
switch (state) { |
|
|
case STARTED: |
|
|
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; |
|
|
break; |
|
|
case READY_TO_OUTPUT: |
|
|
case READY_TO_OUTPUT: |
|
|
state = STOPPED; |
|
|
state = STOPPED; |
|
@ -182,9 +186,6 @@ trap_dispatch(struct trapframe *tf) { |
|
|
break; |
|
|
break; |
|
|
} |
|
|
} |
|
|
ticks ++; |
|
|
ticks ++; |
|
|
// if (ticks % TICK_NUM == 0) { |
|
|
|
|
|
// print_ticks(); |
|
|
|
|
|
// } |
|
|
|
|
|
break; |
|
|
break; |
|
|
case IRQ_OFFSET + IRQ_COM1: |
|
|
case IRQ_OFFSET + IRQ_COM1: |
|
|
c = cons_getc(); |
|
|
c = cons_getc(); |
|
|