mirror of
https://github.com/yourtion/30dayMakeOS.git
synced 2026-05-02 14:40:21 +08:00
超时功能
This commit is contained in:
@@ -9,10 +9,11 @@ struct TIMERCTL timerctl;
|
||||
|
||||
void init_pit(void)
|
||||
{
|
||||
io_out8(PIT_CTRL, 0x43);
|
||||
io_out8(PIT_CTRL, 0x34);
|
||||
io_out8(PIT_CNT0, 0x9c);
|
||||
io_out8(PIT_CNT0, 0x2e);
|
||||
timerctl.count = 0;
|
||||
timerctl.timeout = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,5 +21,23 @@ void inthandler20(int *esp)
|
||||
{
|
||||
io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00信号接收完了的信息通知给PIC */
|
||||
timerctl.count++;
|
||||
if (timerctl.timeout > 0) { /* 如果已经设定了超时 */
|
||||
timerctl.timeout--;
|
||||
if (timerctl.timeout == 0) {
|
||||
fifo8_put(timerctl.fifo, timerctl.data);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void settimer(unsigned int timeout, struct FIFO8 *fifo, unsigned char data)
|
||||
{
|
||||
int eflags;
|
||||
eflags = io_load_eflags();
|
||||
io_cli();
|
||||
timerctl.timeout = timeout;
|
||||
timerctl.fifo = fifo;
|
||||
timerctl.data = data;
|
||||
io_store_eflags(eflags);
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user