Compare commits

..

5 Commits

Author SHA1 Message Date
Yourtion
44c9f8c227 多任务进阶 2016-04-22 17:12:03 +08:00
Yourtion
991f1056ad 测试运行速度 2016-04-22 16:58:18 +08:00
Yourtion
dc8c366fc0 提高运行速度 2016-04-22 16:53:40 +08:00
Yourtion
30c62ffbd0 做个简单的多任务(2) 2016-04-22 16:08:08 +08:00
Yourtion
8534999b7b 做个简单的多任务(1) 2016-04-22 14:57:05 +08:00
6 changed files with 73 additions and 24 deletions

View File

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

View File

@@ -14,7 +14,7 @@ struct TSS32 {
int ldtr, iomap;
};
void task_b_main(void);
void task_b_main(struct SHEET *sht_back);
void HariMain(void)
{
@@ -103,7 +103,7 @@ void HariMain(void)
set_segmdesc(gdt + 3, 103, (int) &tss_a, AR_TSS32);
set_segmdesc(gdt + 4, 103, (int) &tss_b, AR_TSS32);
load_tr(3 * 8);
task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024;
task_b_esp = memman_alloc_4k(memman, 64 * 1024) + 64 * 1024 - 8;
tss_b.eip = (int) &task_b_main;
tss_b.eflags = 0x00000202; /* IF = 1; */
tss_b.eax = 0;
@@ -120,6 +120,8 @@ void HariMain(void)
tss_b.ds = 1 * 8;
tss_b.fs = 1 * 8;
tss_b.gs = 1 * 8;
*((int *) (task_b_esp + 4)) = (int) sht_back;
mt_init();
for (;;) {
io_cli();
@@ -185,7 +187,6 @@ void HariMain(void)
}
} else if (i == 10) { /* 10秒定时器 */
putfonts8_asc_sht(sht_back, 0, 64, COL8_FFFFFF, COL8_008484, "10[sec]", 7);
taskswitch4();
} else if (i == 3) { /* 3秒定时器 */
putfonts8_asc_sht(sht_back, 0, 80, COL8_FFFFFF, COL8_008484, "3[sec]", 6);
} else if (i <= 1) { /* 光标用定时器*/
@@ -276,25 +277,38 @@ void make_textbox8(struct SHEET *sht, int x0, int y0, int sx, int sy, int c)
return;
}
void task_b_main(void)
void task_b_main(struct SHEET *sht_back)
{
struct FIFO32 fifo;
struct TIMER *timer;
int i, fifobuf[128];
struct TIMER *timer_put, *timer_1s;
int i, fifobuf[128], count = 0, count0 = 0;
char s[12];
fifo32_init(&fifo, 128, fifobuf);
timer = timer_alloc();
timer_init(timer, &fifo, 1);
timer_settime(timer, 500);
timer_put = timer_alloc();
timer_init(timer_put, &fifo, 1);
timer_settime(timer_put, 1);
timer_1s = timer_alloc();
timer_init(timer_1s, &fifo, 100);
timer_settime(timer_1s, 100);
for (;;) {
count++;
io_cli();
if (fifo32_status(&fifo) == 0) {
io_stihlt();
io_sti();
} else {
i = fifo32_get(&fifo);
io_sti();
if (i == 1) { /*超时时间为5秒 */
taskswitch3(); /*返回任务A */
if (i == 1) {
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 == 100) {
sprintf(s, "%11d", count - count0);
putfonts8_asc_sht(sht_back, 0, 128, COL8_FFFFFF, COL8_008484, s, 11);
count0 = count;
timer_settime(timer_1s, 100);
}
}
}

View File

@@ -28,8 +28,7 @@ void asm_inthandler21(void);
void asm_inthandler27(void);
void asm_inthandler2c(void);
unsigned int memtest_sub(unsigned int start, unsigned int end);
void taskswitch3(void);
void taskswitch4(void);
void farjmp(int eip, int cs);
/* fifo.c */
struct FIFO32 {
@@ -184,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
15_day/mtask.c Normal file
View File

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

View File

@@ -16,7 +16,7 @@
GLOBAL _asm_inthandler20, _asm_inthandler21
GLOBAL _asm_inthandler27, _asm_inthandler2c
GLOBAL _memtest_sub
GLOBAL _taskswitch3, _taskswitch4
GLOBAL _farjmp
EXTERN _inthandler20, _inthandler21
EXTERN _inthandler27, _inthandler2c
@@ -207,10 +207,6 @@ mts_fin:
POP EDI
RET
_taskswitch3: ; void taskswitch3(void);
JMP 3*8:0
RET
_taskswitch4: ; void taskswitch4(void);
JMP 4*8:0
RET
_farjmp: ; void farjmp(int eip, int cs);
JMP FAR [ESP+4] ; eip, cs
RET

View File

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