Skip to content

Commit

Permalink
多任务进阶
Browse files Browse the repository at this point in the history
  • Loading branch information
yourtion committed Apr 22, 2016
1 parent 991f105 commit 44c9f8c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
2 changes: 1 addition & 1 deletion 15_day/Makefile
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
21 changes: 4 additions & 17 deletions 15_day/bootpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand All @@ -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();
Expand All @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions 15_day/bootpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
27 changes: 27 additions & 0 deletions 15_day/mtask.c
Original file line number Diff line number Diff line change
@@ -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;
}
10 changes: 9 additions & 1 deletion 15_day/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}

0 comments on commit 44c9f8c

Please sign in to comment.