|
|
@ -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; |
|
|
|