mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-02-05 02:53:19 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1142b3a5f | ||
|
|
792c8b7082 |
@@ -176,7 +176,7 @@ struct TIMER {
|
||||
unsigned char data;
|
||||
};
|
||||
struct TIMERCTL {
|
||||
unsigned int count;
|
||||
unsigned int count, next;
|
||||
struct TIMER timer[MAX_TIMER];
|
||||
};
|
||||
extern struct TIMERCTL timerctl;
|
||||
|
||||
@@ -16,6 +16,7 @@ void init_pit(void)
|
||||
io_out8(PIT_CNT0, 0x9c);
|
||||
io_out8(PIT_CNT0, 0x2e);
|
||||
timerctl.count = 0;
|
||||
timerctl.next = 0xffffffff; /* 因为最初没有正在运行的定时器 */
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
timerctl.timer[i].flags = 0; /* 未使用 */
|
||||
}
|
||||
@@ -49,8 +50,12 @@ void timer_init(struct TIMER *timer, struct FIFO8 *fifo, unsigned char data)
|
||||
|
||||
void timer_settime(struct TIMER *timer, unsigned int timeout)
|
||||
{
|
||||
timer->timeout = timeout;
|
||||
timer->timeout = timeout + timerctl.count;
|
||||
timer->flags = TIMER_FLAGS_USING;
|
||||
if (timerctl.next > timer->timeout) {
|
||||
/* 更新下一次的时刻 */
|
||||
timerctl.next = timer->timeout;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -59,13 +64,22 @@ void inthandler20(int *esp)
|
||||
int i;
|
||||
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
|
||||
timerctl.count++;
|
||||
if (timerctl.next > timerctl.count) {
|
||||
return; /* 还不到下一个时刻,所以结束*/
|
||||
}
|
||||
timerctl.next = 0xffffffff;
|
||||
for (i = 0; i < MAX_TIMER; i++) {
|
||||
if (timerctl.timer[i].flags == TIMER_FLAGS_USING) {
|
||||
timerctl.timer[i].timeout--;
|
||||
if (timerctl.timer[i].timeout == 0) {
|
||||
if (timerctl.timer[i].timeout <= timerctl.count) {
|
||||
/* 超时 */
|
||||
timerctl.timer[i].flags = TIMER_FLAGS_ALLOC;
|
||||
fifo8_put(timerctl.timer[i].fifo, timerctl.timer[i].data);
|
||||
}
|
||||
} else {
|
||||
/* 还没有超时 */
|
||||
if (timerctl.next > timerctl.timer[i].timeout) {
|
||||
timerctl.next = timerctl.timer[i].timeout;
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user