📄 root.c
字号:
/* root.c */#include "sys_conf.h"#include <psos.h>#include <prepc.h>#include <stdio.h>#include "misc.h"#include "appl.h"/* ROOT task */voidroot(){ void *dummy; ULONG ioretval, iopb[4], rc, args[4], tid, ignored, qid; struct message incoming; /* Initialize all drivers */ de_init(DEV_TIMER, 0, &ioretval, &dummy); de_init(DEV_SERIAL, 0, &ioretval, &dummy); bpinit(128*100); bprintf("\nRoot task begin\n"); /* Create the queue */ if (0 != (rc = q_create(Q_NAM, 10, Q_LIMIT, & qid))) fail(rc, "%s q_create(%s) failed", "ROOT", Q_NAM); /* Create and start the other task */ args[0] = (ULONG) T2_NAM; /* His name */ args[1] = (ULONG) "ROOT"; /* My name */ args[2] = qid; /* The Queue ID */ args[3] = 0; if (rc = t_create(T2_NAM, 128, 1024, 1024, 0, &tid)) fail(rc, "root: t_create(%s)", T2_NAM); if (rc = t_start(tid, 0, (void(*)()) tsk2, args)) fail(rc, "root: t_start(%s)", T2_NAM); /* Receive messages until EOF */ for (;;) { if (0 != (rc = q_receive(qid, Q_WAIT, 0, (ULONG *) &incoming))) fail(rc, "%s q_receive(%s) failed", "ROOT", Q_NAM); if (incoming.value == EOF) break; bprintf("%c", incoming.value); } bprintf("\n"); if (0 != (rc = q_delete(qid))) fail(rc, "%s q_delete(%s) failed", "ROOT", Q_NAM); /* Example finished */ bprintf("Root task end\n"); bpflush(); exit(0);}static char data[]="abcdefghijklmnopqrstuvwxyz";void tsk2(ULONG me, ULONG him, ULONG qid, ULONG l4){ ULONG rc; int data_size, loop_count; struct message outgoing; srand(123456781L); data_size = strlen(data); for (loop_count = 0; loop_count < LOOP_MAX; loop_count++) { outgoing.value = data[rand() % data_size]; if (0 != (rc = q_send(qid, (ULONG *) &outgoing))) fail(rc, "%s q_send(%s) failed", me, Q_NAM); tm_wkafter(1*TENTH); } outgoing.value = EOF; if (0 != (rc = q_send(qid, (ULONG *) &outgoing))) fail(rc, "%s q_send(%s) failed", me, Q_NAM); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -