From 44c9f8c22701107b11f15aafd235d1f7b44c95d0 Mon Sep 17 00:00:00 2001 From: Yourtion Date: Fri, 22 Apr 2016 17:12:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E4=BB=BB=E5=8A=A1=E8=BF=9B=E9=98=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 15_day/Makefile | 2 +- 15_day/bootpack.c | 21 ++++----------------- 15_day/bootpack.h | 5 +++++ 15_day/mtask.c | 27 +++++++++++++++++++++++++++ 15_day/timer.c | 10 +++++++++- 5 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 15_day/mtask.c diff --git a/15_day/Makefile b/15_day/Makefile index 174bccd..f05f580 100644 --- a/15_day/Makefile +++ b/15_day/Makefile @@ -1,5 +1,5 @@ OBJS_BOOTPACK = bootpack.obj naskfunc.obj hankaku.obj graphic.obj dsctbl.obj \ - int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj + int.obj fifo.obj keyboard.obj mouse.obj memory.obj sheet.obj timer.obj mtask.obj TOOLPATH = ../z_tools/ INCPATH = ../z_tools/haribote/ diff --git a/15_day/bootpack.c b/15_day/bootpack.c index 5d51fe4..85eb835 100644 --- a/15_day/bootpack.c +++ b/15_day/bootpack.c @@ -22,7 +22,7 @@ void HariMain(void) struct FIFO32 fifo; char s[40]; int fifobuf[128]; - struct TIMER *timer, *timer2, *timer3, *timer_ts; + struct TIMER *timer, *timer2, *timer3; int mx, my, i, cursor_x, cursor_c, task_b_esp; unsigned int memtotal; struct MOUSE_DEC mdec; @@ -60,9 +60,6 @@ void HariMain(void) timer3 = timer_alloc(); timer_init(timer3, &fifo, 1); timer_settime(timer3, 50); - timer_ts = timer_alloc(); - timer_init(timer_ts, &fifo, 2); - timer_settime(timer_ts, 2); memtotal = memtest(0x00400000, 0xbfffffff); memman_init(memman); @@ -124,6 +121,7 @@ void HariMain(void) tss_b.fs = 1 * 8; tss_b.gs = 1 * 8; *((int *) (task_b_esp + 4)) = (int) sht_back; + mt_init(); for (;;) { io_cli(); @@ -132,10 +130,7 @@ void HariMain(void) } else { i = fifo32_get(&fifo); io_sti(); - if (i == 2) { - farjmp(0, 4 * 8); - timer_settime(timer_ts, 2); - } else if (256 <= i && i <= 511) { /* 键盘数据*/ + if (256 <= i && i <= 511) { /* 键盘数据*/ sprintf(s, "%02X", i - 256); putfonts8_asc_sht(sht_back, 0, 16, COL8_FFFFFF, COL8_008484, s, 2); if (i < 0x54 + 256) { @@ -285,14 +280,11 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c) void task_b_main(struct SHEET *sht_back) { struct FIFO32 fifo; - struct TIMER *timer_ts, *timer_put, *timer_1s; + struct TIMER *timer_put, *timer_1s; int i, fifobuf[128], count = 0, count0 = 0; char s[12]; fifo32_init(&fifo, 128, fifobuf); - timer_ts = timer_alloc(); - timer_init(timer_ts, &fifo, 2); - timer_settime(timer_ts, 2); timer_put = timer_alloc(); timer_init(timer_put, &fifo, 1); timer_settime(timer_put, 1); @@ -302,8 +294,6 @@ void task_b_main(struct SHEET *sht_back) for (;;) { count++; - sprintf(s, "%10d", count); - putfonts8_asc_sht(sht_back, 0, 144, COL8_FFFFFF, COL8_008484, s, 10); io_cli(); if (fifo32_status(&fifo) == 0) { io_sti(); @@ -314,9 +304,6 @@ void task_b_main(struct SHEET *sht_back) sprintf(s, "%11d", count); putfonts8_asc_sht(sht_back, 0, 144, COL8_FFFFFF, COL8_008484, s, 11); timer_settime(timer_put, 1); - } else if (i == 2) { - farjmp(0, 3 * 8); - timer_settime(timer_ts, 2); } else if (i == 100) { sprintf(s, "%11d", count - count0); putfonts8_asc_sht(sht_back, 0, 128, COL8_FFFFFF, COL8_008484, s, 11); diff --git a/15_day/bootpack.h b/15_day/bootpack.h index 14fe41c..53e8840 100644 --- a/15_day/bootpack.h +++ b/15_day/bootpack.h @@ -183,3 +183,8 @@ void timer_free(struct TIMER *timer); void timer_init(struct TIMER *timer, struct FIFO32 *fifo, int data); void timer_settime(struct TIMER *timer, unsigned int timeout); void inthandler20(int *esp); + +/* mtask.c */ +extern struct TIMER *mt_timer; +void mt_init(void); +void mt_taskswitch(void); diff --git a/15_day/mtask.c b/15_day/mtask.c new file mode 100644 index 0000000..ccc5227 --- /dev/null +++ b/15_day/mtask.c @@ -0,0 +1,27 @@ +/* 多任务管理 */ + +#include "bootpack.h" + +struct TIMER *mt_timer; +int mt_tr; + +void mt_init(void) +{ + mt_timer = timer_alloc(); + /*这里没有必要使用timer_init */ + timer_settime(mt_timer, 2); + mt_tr = 3 * 8; + return; +} + +void mt_taskswitch(void) +{ + if (mt_tr == 3 * 8) { + mt_tr = 4 * 8; + } else { + mt_tr = 3 * 8; + } + timer_settime(mt_timer, 2); + farjmp(0, mt_tr); + return; +} \ No newline at end of file diff --git a/15_day/timer.c b/15_day/timer.c index 1f61776..85634b0 100644 --- a/15_day/timer.c +++ b/15_day/timer.c @@ -88,6 +88,7 @@ void timer_settime(struct TIMER *timer, unsigned int timeout) void inthandler20(int *esp) { struct TIMER *timer; + char ts = 0; io_out8(PIC0_OCW2, 0x60); /* 把IRQ-00接收信号结束的信息通知给PIC */ timerctl.count++; if (timerctl.next > timerctl.count) { @@ -101,10 +102,17 @@ void inthandler20(int *esp) } /* 超时 */ timer->flags = TIMER_FLAGS_ALLOC; - fifo32_put(timer->fifo, timer->data); + if (timer != mt_timer) { + fifo32_put(timer->fifo, timer->data); + } else { + ts = 1; /* mt_timer超时*/ + } timer = timer->next; /* 将下一个定时器的地址赋给timer*/ } timerctl.t0 = timer; timerctl.next = timer->timeout; + if (ts != 0) { + mt_taskswitch(); + } return; } \ No newline at end of file